]>
Commit | Line | Data |
---|---|---|
d71b6f81 ER |
1 | Additional API from clementine: |
2 | https://github.com/clementine-player/Clementine/blob/master/3rdparty/qtsingleapplication/qtsingleapplication.patch | |
3 | ||
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.) | |
7 | ||
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 | |
11 | @@ -48,6 +48,7 @@ | |
ec2fcb4a | 12 | #include "qtlocalpeer.h" |
d71b6f81 ER |
13 | #include <QtCore/QCoreApplication> |
14 | #include <QtCore/QTime> | |
ec2fcb4a ER |
15 | +#include <QtDebug> |
16 | ||
17 | #if defined(Q_OS_WIN) | |
d71b6f81 ER |
18 | #include <QtCore/QLibrary> |
19 | @@ -59,14 +60,12 @@ | |
20 | #include <time.h> | |
21 | #endif | |
22 | ||
23 | -namespace QtLP_Private { | |
24 | #include "qtlockedfile.cpp" | |
25 | #if defined(Q_OS_WIN) | |
26 | #include "qtlockedfile_win.cpp" | |
27 | #else | |
28 | #include "qtlockedfile_unix.cpp" | |
29 | #endif | |
30 | -} | |
31 | ||
32 | const char* QtLocalPeer::ack = "ack"; | |
33 | ||
34 | @@ -118,7 +117,7 @@ | |
35 | if (lockFile.isLocked()) | |
36 | return false; | |
37 | ||
38 | - if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) | |
39 | + if (!lockFile.lock(QtLockedFile::WriteLock, false)) | |
40 | return true; | |
41 | ||
42 | bool res = server->listen(socketName); | |
ec2fcb4a ER |
43 | @@ -138,6 +137,11 @@ |
44 | ||
45 | bool QtLocalPeer::sendMessage(const QString &message, int timeout) | |
46 | { | |
47 | + return sendMessage(message.toUtf8(), timeout); | |
48 | +} | |
49 | + | |
50 | +bool QtLocalPeer::sendMessage(const QByteArray &message, int timeout) | |
51 | +{ | |
52 | if (!isClient()) | |
53 | return false; | |
54 | ||
55 | @@ -160,9 +164,8 @@ | |
56 | if (!connOk) | |
57 | return false; | |
58 | ||
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); | |
d71b6f81 | 66 | @@ -195,9 +198,9 @@ |
ec2fcb4a ER |
67 | delete socket; |
68 | return; | |
69 | } | |
70 | - QString message(QString::fromUtf8(uMsg)); | |
71 | socket->write(ack, qstrlen(ack)); | |
72 | socket->waitForBytesWritten(1000); | |
73 | delete socket; | |
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)); | |
77 | } | |
d71b6f81 ER |
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 | |
81 | @@ -49,9 +49,7 @@ | |
82 | #include <QtNetwork/QLocalSocket> | |
83 | #include <QtCore/QDir> | |
84 | ||
85 | -namespace QtLP_Private { | |
86 | #include "qtlockedfile.h" | |
87 | -} | |
88 | ||
89 | class QtLocalPeer : public QObject | |
90 | { | |
ec2fcb4a ER |
91 | @@ -61,11 +59,13 @@ |
92 | QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); | |
93 | bool isClient(); | |
94 | bool sendMessage(const QString &message, int timeout); | |
95 | + bool sendMessage(const QByteArray &message, int timeout); | |
96 | QString applicationId() const | |
97 | { return id; } | |
98 | ||
99 | Q_SIGNALS: | |
100 | void messageReceived(const QString &message); | |
101 | + void messageReceived(const QByteArray &message); | |
102 | ||
103 | protected Q_SLOTS: | |
104 | void receiveConnection(); | |
d71b6f81 ER |
105 | @@ -74,7 +74,7 @@ |
106 | QString id; | |
107 | QString socketName; | |
108 | QLocalServer* server; | |
109 | - QtLP_Private::QtLockedFile lockFile; | |
110 | + QtLockedFile lockFile; | |
111 | ||
112 | private: | |
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 | |
ec2fcb4a ER |
117 | @@ -65,7 +65,7 @@ |
118 | ||
119 | Qt::HANDLE mutex; | |
120 | if (doCreate) { | |
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()); } ); | |
124 | if (!mutex) { | |
125 | qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); | |
126 | @@ -73,7 +73,7 @@ | |
127 | } | |
128 | } | |
129 | else { | |
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()); } ); | |
133 | if (!mutex) { | |
134 | if (GetLastError() != ERROR_FILE_NOT_FOUND) | |
d71b6f81 ER |
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 | |
ec2fcb4a ER |
138 | @@ -144,6 +144,7 @@ |
139 | actWin = 0; | |
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&))); | |
143 | } | |
144 | ||
145 | ||
146 | @@ -265,6 +266,11 @@ | |
147 | return peer->sendMessage(message, timeout); | |
148 | } | |
149 | ||
150 | +bool QtSingleApplication::sendMessage(const QByteArray &message, int timeout) | |
151 | +{ | |
152 | + return peer->sendMessage(message, timeout); | |
153 | +} | |
154 | + | |
155 | ||
156 | /*! | |
157 | Returns the application identifier. Two processes with the same | |
158 | @@ -291,10 +297,14 @@ | |
159 | void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) | |
160 | { | |
161 | actWin = aw; | |
162 | - if (activateOnMessage) | |
163 | + if (activateOnMessage) { | |
164 | connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); | |
165 | - else | |
166 | + connect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow())); | |
167 | + } | |
168 | + else { | |
169 | disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); | |
170 | + disconnect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow())); | |
171 | + } | |
172 | } | |
173 | ||
174 | ||
d71b6f81 ER |
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 | |
ec2fcb4a ER |
178 | @@ -91,11 +91,13 @@ |
179 | ||
180 | public Q_SLOTS: | |
181 | bool sendMessage(const QString &message, int timeout = 5000); | |
182 | + bool sendMessage(const QByteArray &message, int timeout = 5000); | |
183 | void activateWindow(); | |
184 | ||
185 | ||
186 | Q_SIGNALS: | |
187 | void messageReceived(const QString &message); | |
188 | + void messageReceived(const QByteArray &message); | |
189 | ||
190 | ||
191 | private: | |
d71b6f81 ER |
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 | |
ec2fcb4a ER |
195 | @@ -81,6 +81,7 @@ |
196 | { | |
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&))); | |
200 | } | |
201 | ||
202 | ||
203 | @@ -94,6 +95,7 @@ | |
204 | { | |
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&))); | |
208 | } | |
209 | ||
210 | ||
211 | @@ -133,6 +135,11 @@ | |
212 | return peer->sendMessage(message, timeout); | |
213 | } | |
214 | ||
215 | +bool QtSingleCoreApplication::sendMessage(const QByteArray &message, int timeout) | |
216 | +{ | |
217 | + return peer->sendMessage(message, timeout); | |
218 | +} | |
219 | + | |
220 | ||
221 | /*! | |
222 | Returns the application identifier. Two processes with the same | |
d71b6f81 ER |
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 | |
ec2fcb4a ER |
226 | @@ -62,10 +62,12 @@ |
227 | ||
228 | public Q_SLOTS: | |
229 | bool sendMessage(const QString &message, int timeout = 5000); | |
230 | + bool sendMessage(const QByteArray &message, int timeout = 5000); | |
231 | ||
232 | ||
233 | Q_SIGNALS: | |
234 | void messageReceived(const QString &message); | |
235 | + void messageReceived(const QByteArray &message); | |
236 | ||
237 | ||
238 | private: |