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 --- QtSingleApplication-2.6.1/src/qtlocalpeer.cpp~ 2015-02-23 00:06:20.000000000 +0200
9 +++ QtSingleApplication-2.6.1/src/qtlocalpeer.cpp 2015-02-23 00:08:51.179884397 +0200
11 #include "qtlocalpeer.h"
12 #include <QCoreApplication>
20 bool QtLocalPeer::sendMessage(const QString &message, int timeout)
22 + return sendMessage(message.toUtf8(), timeout);
25 +bool QtLocalPeer::sendMessage(const QByteArray &message, int timeout)
34 - QByteArray uMsg(message.toUtf8());
35 QDataStream ds(&socket);
36 - ds.writeBytes(uMsg.constData(), uMsg.size());
37 + ds.writeBytes(message.constData(), message.size());
38 bool res = socket.waitForBytesWritten(timeout);
39 res &= socket.waitForReadyRead(timeout); // wait for ack
40 res &= (socket.read(qstrlen(ack)) == ack);
45 - QString message(QString::fromUtf8(uMsg));
46 socket->write(ack, qstrlen(ack));
47 socket->waitForBytesWritten(1000);
48 socket->waitForDisconnected(1000); // make sure client reads ack
50 - emit messageReceived(message); //### (might take a long time to return)
51 + emit messageReceived(uMsg); //### (might take a long time to return)
52 + emit messageReceived(QString::fromUtf8(uMsg));
54 --- QtSingleApplication-2.6.1/src/qtlocalpeer.h~ 2015-02-23 00:12:20.000000000 +0200
55 +++ QtSingleApplication-2.6.1/src/qtlocalpeer.h 2015-02-23 00:19:44.407242485 +0200
57 QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
59 bool sendMessage(const QString &message, int timeout);
60 + bool sendMessage(const QByteArray &message, int timeout);
61 QString applicationId() const
65 void messageReceived(const QString &message);
66 + void messageReceived(const QByteArray &message);
69 void receiveConnection();
70 --- qtsingleapplication-2.6_1-opensource/src/qtlockedfile_win.cpp 2009-12-16 10:43:33.000000000 +0000
71 +++ qtsingleapplication/qtlockedfile_win.cpp 2010-07-10 16:26:33.000000000 +0100
76 - QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); },
77 + QT_WA( { mutex = CreateMutexW(NULL, FALSE, (WCHAR*)mname.utf16()); },
78 { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } );
80 qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
85 - QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); },
86 + QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (WCHAR*)mname.utf16()); },
87 { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } );
89 if (GetLastError() != ERROR_FILE_NOT_FOUND)
90 --- qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.cpp 2009-12-16 10:43:33.000000000 +0000
91 +++ qtsingleapplication/qtsingleapplication.cpp 2010-07-10 16:23:53.000000000 +0100
94 peer = new QtLocalPeer(this, appId);
95 connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
96 + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
101 return peer->sendMessage(message, timeout);
104 +bool QtSingleApplication::sendMessage(const QByteArray &message, int timeout)
106 + return peer->sendMessage(message, timeout);
111 Returns the application identifier. Two processes with the same
112 @@ -291,10 +297,14 @@
113 void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage)
116 - if (activateOnMessage)
117 + if (activateOnMessage) {
118 connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
120 + connect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow()));
123 disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
124 + disconnect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow()));
129 --- qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.h 2009-12-16 10:43:33.000000000 +0000
130 +++ qtsingleapplication/qtsingleapplication.h 2010-07-10 16:23:53.000000000 +0100
134 bool sendMessage(const QString &message, int timeout = 5000);
135 + bool sendMessage(const QByteArray &message, int timeout = 5000);
136 void activateWindow();
140 void messageReceived(const QString &message);
141 + void messageReceived(const QByteArray &message);
145 --- qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.cpp 2009-12-16 10:43:33.000000000 +0000
146 +++ qtsingleapplication/qtsinglecoreapplication.cpp 2010-07-10 16:32:33.000000000 +0100
149 peer = new QtLocalPeer(this);
150 connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
151 + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
157 peer = new QtLocalPeer(this, appId);
158 connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
159 + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
164 return peer->sendMessage(message, timeout);
167 +bool QtSingleCoreApplication::sendMessage(const QByteArray &message, int timeout)
169 + return peer->sendMessage(message, timeout);
174 Returns the application identifier. Two processes with the same
175 --- qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.h 2009-12-16 10:43:33.000000000 +0000
176 +++ qtsingleapplication/qtsinglecoreapplication.h 2010-07-10 16:32:33.000000000 +0100
180 bool sendMessage(const QString &message, int timeout = 5000);
181 + bool sendMessage(const QByteArray &message, int timeout = 5000);
185 void messageReceived(const QString &message);
186 + void messageReceived(const QByteArray &message);