Additional API from clementine: https://github.com/clementine-player/Clementine/blob/master/3rdparty/qtsingleapplication/qtsingleapplication.patch https://github.com/clementine-player/Clementine/issues/291#issuecomment-29984507 qtsingleapplication: "Open With" on the file browser, and passing filenames as arguments in the command line Controlling playback with the commandline as well (--pause, --play, etc.) --- QtSingleApplication-2.6.1/src/qtlocalpeer.cpp~ 2015-02-23 00:06:20.000000000 +0200 +++ QtSingleApplication-2.6.1/src/qtlocalpeer.cpp 2015-02-23 00:08:51.179884397 +0200 @@ -42,6 +42,7 @@ #include "qtlocalpeer.h" #include #include +#include #if defined(Q_OS_WIN) #include @@ -138,6 +137,11 @@ bool QtLocalPeer::sendMessage(const QString &message, int timeout) { + return sendMessage(message.toUtf8(), timeout); +} + +bool QtLocalPeer::sendMessage(const QByteArray &message, int timeout) +{ if (!isClient()) return false; @@ -160,9 +164,8 @@ if (!connOk) return false; - QByteArray uMsg(message.toUtf8()); QDataStream ds(&socket); - ds.writeBytes(uMsg.constData(), uMsg.size()); + ds.writeBytes(message.constData(), message.size()); bool res = socket.waitForBytesWritten(timeout); res &= socket.waitForReadyRead(timeout); // wait for ack res &= (socket.read(qstrlen(ack)) == ack); @@ -189,10 +190,10 @@ delete socket; return; } - QString message(QString::fromUtf8(uMsg)); socket->write(ack, qstrlen(ack)); socket->waitForBytesWritten(1000); socket->waitForDisconnected(1000); // make sure client reads ack delete socket; - emit messageReceived(message); //### (might take a long time to return) + emit messageReceived(uMsg); //### (might take a long time to return) + emit messageReceived(QString::fromUtf8(uMsg)); } --- QtSingleApplication-2.6.1/src/qtlocalpeer.h~ 2015-02-23 00:12:20.000000000 +0200 +++ QtSingleApplication-2.6.1/src/qtlocalpeer.h 2015-02-23 00:19:44.407242485 +0200 @@ -55,11 +55,13 @@ QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); bool isClient(); bool sendMessage(const QString &message, int timeout); + bool sendMessage(const QByteArray &message, int timeout); QString applicationId() const { return id; } Q_SIGNALS: void messageReceived(const QString &message); + void messageReceived(const QByteArray &message); protected Q_SLOTS: void receiveConnection(); --- qtsingleapplication-2.6_1-opensource/src/qtlockedfile_win.cpp 2009-12-16 10:43:33.000000000 +0000 +++ qtsingleapplication/qtlockedfile_win.cpp 2010-07-10 16:26:33.000000000 +0100 @@ -65,7 +65,7 @@ Qt::HANDLE mutex; if (doCreate) { - QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, + QT_WA( { mutex = CreateMutexW(NULL, FALSE, (WCHAR*)mname.utf16()); }, { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } ); if (!mutex) { qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); @@ -73,7 +73,7 @@ } } else { - QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, + QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (WCHAR*)mname.utf16()); }, { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } ); if (!mutex) { if (GetLastError() != ERROR_FILE_NOT_FOUND) --- qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.cpp 2009-12-16 10:43:33.000000000 +0000 +++ qtsingleapplication/qtsingleapplication.cpp 2010-07-10 16:23:53.000000000 +0100 @@ -144,6 +144,7 @@ actWin = 0; peer = new QtLocalPeer(this, appId); connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&))); } @@ -265,6 +266,11 @@ return peer->sendMessage(message, timeout); } +bool QtSingleApplication::sendMessage(const QByteArray &message, int timeout) +{ + return peer->sendMessage(message, timeout); +} + /*! Returns the application identifier. Two processes with the same @@ -291,10 +297,14 @@ void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) { actWin = aw; - if (activateOnMessage) + if (activateOnMessage) { connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); - else + connect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow())); + } + else { disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); + disconnect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow())); + } } --- qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.h 2009-12-16 10:43:33.000000000 +0000 +++ qtsingleapplication/qtsingleapplication.h 2010-07-10 16:23:53.000000000 +0100 @@ -91,11 +91,13 @@ public Q_SLOTS: bool sendMessage(const QString &message, int timeout = 5000); + bool sendMessage(const QByteArray &message, int timeout = 5000); void activateWindow(); Q_SIGNALS: void messageReceived(const QString &message); + void messageReceived(const QByteArray &message); private: --- qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.cpp 2009-12-16 10:43:33.000000000 +0000 +++ qtsingleapplication/qtsinglecoreapplication.cpp 2010-07-10 16:32:33.000000000 +0100 @@ -81,6 +81,7 @@ { peer = new QtLocalPeer(this); connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&))); } @@ -94,6 +95,7 @@ { peer = new QtLocalPeer(this, appId); connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); + connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&))); } @@ -133,6 +135,11 @@ return peer->sendMessage(message, timeout); } +bool QtSingleCoreApplication::sendMessage(const QByteArray &message, int timeout) +{ + return peer->sendMessage(message, timeout); +} + /*! Returns the application identifier. Two processes with the same --- qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.h 2009-12-16 10:43:33.000000000 +0000 +++ qtsingleapplication/qtsinglecoreapplication.h 2010-07-10 16:32:33.000000000 +0100 @@ -62,10 +62,12 @@ public Q_SLOTS: bool sendMessage(const QString &message, int timeout = 5000); + bool sendMessage(const QByteArray &message, int timeout = 5000); Q_SIGNALS: void messageReceived(const QString &message); + void messageReceived(const QByteArray &message); private: