1 Additional API from clementine:
2 https://github.com/clementine-player/Clementine/blob/master/3rdparty/qtsingleapplication/qtsingleapplication.patch
4 https://github.com/clementine-player/Clementine/issues/291#issuecomment-29984507
5 qtsingleapplication: "Open With" on the file browser, and passing filenames as arguments in the command line
6 Controlling playback with the commandline as well (--pause, --play, etc.)
8 diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtlocalpeer.cpp qtsingleapplication/qtlocalpeer.cpp
9 --- /home/david/qtsingleapplication-2.6_1-opensource/src/qtlocalpeer.cpp 2009-12-16 10:43:33.000000000 +0000
10 +++ qtsingleapplication/qtlocalpeer.cpp 2010-07-10 16:26:50.000000000 +0100
12 #include "qtlocalpeer.h"
13 #include <QtCore/QCoreApplication>
14 #include <QtCore/QTime>
18 #include <QtCore/QLibrary>
23 -namespace QtLP_Private {
24 #include "qtlockedfile.cpp"
26 #include "qtlockedfile_win.cpp"
28 #include "qtlockedfile_unix.cpp"
32 const char* QtLocalPeer::ack = "ack";
35 if (lockFile.isLocked())
38 - if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
39 + if (!lockFile.lock(QtLockedFile::WriteLock, false))
42 bool res = server->listen(socketName);
45 bool QtLocalPeer::sendMessage(const QString &message, int timeout)
47 + return sendMessage(message.toUtf8(), timeout);
50 +bool QtLocalPeer::sendMessage(const QByteArray &message, int timeout)
59 - QByteArray uMsg(message.toUtf8());
60 QDataStream ds(&socket);
61 - ds.writeBytes(uMsg.constData(), uMsg.size());
62 + ds.writeBytes(message.constData(), message.size());
63 bool res = socket.waitForBytesWritten(timeout);
64 res &= socket.waitForReadyRead(timeout); // wait for ack
65 res &= (socket.read(qstrlen(ack)) == ack);
70 - QString message(QString::fromUtf8(uMsg));
71 socket->write(ack, qstrlen(ack));
72 socket->waitForBytesWritten(1000);
74 - emit messageReceived(message); //### (might take a long time to return)
75 + emit messageReceived(uMsg); //### (might take a long time to return)
76 + emit messageReceived(QString::fromUtf8(uMsg));
78 diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtlocalpeer.h qtsingleapplication/qtlocalpeer.h
79 --- /home/david/qtsingleapplication-2.6_1-opensource/src/qtlocalpeer.h 2009-12-16 10:43:33.000000000 +0000
80 +++ qtsingleapplication/qtlocalpeer.h 2010-07-10 16:26:16.000000000 +0100
82 #include <QtNetwork/QLocalSocket>
83 #include <QtCore/QDir>
85 -namespace QtLP_Private {
86 #include "qtlockedfile.h"
89 class QtLocalPeer : public QObject
92 QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
94 bool sendMessage(const QString &message, int timeout);
95 + bool sendMessage(const QByteArray &message, int timeout);
96 QString applicationId() const
100 void messageReceived(const QString &message);
101 + void messageReceived(const QByteArray &message);
104 void receiveConnection();
108 QLocalServer* server;
109 - QtLP_Private::QtLockedFile lockFile;
110 + QtLockedFile lockFile;
113 static const char* ack;
114 diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtlockedfile_win.cpp qtsingleapplication/qtlockedfile_win.cpp
115 --- /home/david/qtsingleapplication-2.6_1-opensource/src/qtlockedfile_win.cpp 2009-12-16 10:43:33.000000000 +0000
116 +++ qtsingleapplication/qtlockedfile_win.cpp 2010-07-10 16:26:33.000000000 +0100
121 - QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); },
122 + QT_WA( { mutex = CreateMutexW(NULL, FALSE, (WCHAR*)mname.utf16()); },
123 { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } );
125 qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
130 - QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); },
131 + QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (WCHAR*)mname.utf16()); },
132 { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } );
134 if (GetLastError() != ERROR_FILE_NOT_FOUND)
135 diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.cpp qtsingleapplication/qtsingleapplication.cpp
136 --- /home/david/qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.cpp 2009-12-16 10:43:33.000000000 +0000
137 +++ qtsingleapplication/qtsingleapplication.cpp 2010-07-10 16:23:53.000000000 +0100
140 peer = new QtLocalPeer(this, appId);
141 connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
142 + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
147 return peer->sendMessage(message, timeout);
150 +bool QtSingleApplication::sendMessage(const QByteArray &message, int timeout)
152 + return peer->sendMessage(message, timeout);
157 Returns the application identifier. Two processes with the same
158 @@ -291,10 +297,14 @@
159 void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage)
162 - if (activateOnMessage)
163 + if (activateOnMessage) {
164 connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
166 + connect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow()));
169 disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
170 + disconnect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow()));
175 diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.h qtsingleapplication/qtsingleapplication.h
176 --- /home/david/qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.h 2009-12-16 10:43:33.000000000 +0000
177 +++ qtsingleapplication/qtsingleapplication.h 2010-07-10 16:23:53.000000000 +0100
181 bool sendMessage(const QString &message, int timeout = 5000);
182 + bool sendMessage(const QByteArray &message, int timeout = 5000);
183 void activateWindow();
187 void messageReceived(const QString &message);
188 + void messageReceived(const QByteArray &message);
192 diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.cpp qtsingleapplication/qtsinglecoreapplication.cpp
193 --- /home/david/qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.cpp 2009-12-16 10:43:33.000000000 +0000
194 +++ qtsingleapplication/qtsinglecoreapplication.cpp 2010-07-10 16:32:33.000000000 +0100
197 peer = new QtLocalPeer(this);
198 connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
199 + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
205 peer = new QtLocalPeer(this, appId);
206 connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
207 + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
212 return peer->sendMessage(message, timeout);
215 +bool QtSingleCoreApplication::sendMessage(const QByteArray &message, int timeout)
217 + return peer->sendMessage(message, timeout);
222 Returns the application identifier. Two processes with the same
223 diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.h qtsingleapplication/qtsinglecoreapplication.h
224 --- /home/david/qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.h 2009-12-16 10:43:33.000000000 +0000
225 +++ qtsingleapplication/qtsinglecoreapplication.h 2010-07-10 16:32:33.000000000 +0100
229 bool sendMessage(const QString &message, int timeout = 5000);
230 + bool sendMessage(const QByteArray &message, int timeout = 5000);
234 void messageReceived(const QString &message);
235 + void messageReceived(const QByteArray &message);