2010-07-10 17:34:15 +02:00
|
|
|
diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtlocalpeer.cpp qtsingleapplication/qtlocalpeer.cpp
|
|
|
|
--- /home/david/qtsingleapplication-2.6_1-opensource/src/qtlocalpeer.cpp 2009-12-16 10:43:33.000000000 +0000
|
|
|
|
+++ qtsingleapplication/qtlocalpeer.cpp 2010-07-10 16:26:50.000000000 +0100
|
|
|
|
@@ -48,6 +48,7 @@
|
|
|
|
#include "qtlocalpeer.h"
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
#include <QtCore/QTime>
|
|
|
|
+#include <QtDebug>
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include <QtCore/QLibrary>
|
|
|
|
@@ -59,14 +60,12 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
-namespace QtLP_Private {
|
|
|
|
#include "qtlockedfile.cpp"
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include "qtlockedfile_win.cpp"
|
|
|
|
#else
|
|
|
|
#include "qtlockedfile_unix.cpp"
|
|
|
|
#endif
|
|
|
|
-}
|
|
|
|
|
|
|
|
const char* QtLocalPeer::ack = "ack";
|
|
|
|
|
2010-07-10 17:34:15 +02:00
|
|
|
@@ -118,7 +117,7 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
if (lockFile.isLocked())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
- if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
|
|
|
|
+ if (!lockFile.lock(QtLockedFile::WriteLock, false))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
bool res = server->listen(socketName);
|
2010-07-10 17:34:15 +02:00
|
|
|
@@ -138,6 +137,11 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
|
2010-07-10 17:34:15 +02:00
|
|
|
bool QtLocalPeer::sendMessage(const QString &message, int timeout)
|
2010-05-07 13:43:49 +02:00
|
|
|
{
|
2010-07-10 17:34:15 +02:00
|
|
|
+ return sendMessage(message.toUtf8(), timeout);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool QtLocalPeer::sendMessage(const QByteArray &message, int timeout)
|
|
|
|
+{
|
2010-05-07 13:43:49 +02:00
|
|
|
if (!isClient())
|
|
|
|
return false;
|
2010-07-10 17:34:15 +02:00
|
|
|
|
|
|
|
@@ -160,9 +164,8 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
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);
|
2010-07-10 17:34:15 +02:00
|
|
|
@@ -195,9 +198,9 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
delete socket;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
- QString message(QString::fromUtf8(uMsg));
|
|
|
|
socket->write(ack, qstrlen(ack));
|
|
|
|
socket->waitForBytesWritten(1000);
|
|
|
|
delete socket;
|
|
|
|
- emit messageReceived(message); //### (might take a long time to return)
|
|
|
|
+ emit messageReceived(uMsg); //### (might take a long time to return)
|
2010-07-10 17:34:15 +02:00
|
|
|
+ emit messageReceived(QString::fromUtf8(uMsg));
|
2010-05-07 13:43:49 +02:00
|
|
|
}
|
2010-07-10 17:34:15 +02:00
|
|
|
diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtlocalpeer.h qtsingleapplication/qtlocalpeer.h
|
|
|
|
--- /home/david/qtsingleapplication-2.6_1-opensource/src/qtlocalpeer.h 2009-12-16 10:43:33.000000000 +0000
|
|
|
|
+++ qtsingleapplication/qtlocalpeer.h 2010-07-10 16:26:16.000000000 +0100
|
2010-05-07 13:43:49 +02:00
|
|
|
@@ -49,9 +49,7 @@
|
|
|
|
#include <QtNetwork/QLocalSocket>
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
|
|
|
-namespace QtLP_Private {
|
|
|
|
#include "qtlockedfile.h"
|
|
|
|
-}
|
|
|
|
|
|
|
|
class QtLocalPeer : public QObject
|
|
|
|
{
|
2010-07-10 17:34:15 +02:00
|
|
|
@@ -61,11 +59,13 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
|
|
|
|
bool isClient();
|
2010-07-10 17:34:15 +02:00
|
|
|
bool sendMessage(const QString &message, int timeout);
|
2010-05-07 13:43:49 +02:00
|
|
|
+ bool sendMessage(const QByteArray &message, int timeout);
|
|
|
|
QString applicationId() const
|
|
|
|
{ return id; }
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2010-07-10 17:34:15 +02:00
|
|
|
void messageReceived(const QString &message);
|
2010-05-07 13:43:49 +02:00
|
|
|
+ void messageReceived(const QByteArray &message);
|
|
|
|
|
|
|
|
protected Q_SLOTS:
|
|
|
|
void receiveConnection();
|
2010-07-10 17:34:15 +02:00
|
|
|
@@ -74,7 +74,7 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
QString id;
|
|
|
|
QString socketName;
|
|
|
|
QLocalServer* server;
|
|
|
|
- QtLP_Private::QtLockedFile lockFile;
|
|
|
|
+ QtLockedFile lockFile;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const char* ack;
|
2010-07-10 17:34:15 +02:00
|
|
|
diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtlockedfile_win.cpp qtsingleapplication/qtlockedfile_win.cpp
|
|
|
|
--- /home/david/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
|
2010-05-07 13:43:49 +02:00
|
|
|
@@ -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)
|
2010-07-10 17:34:15 +02:00
|
|
|
diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.cpp qtsingleapplication/qtsingleapplication.cpp
|
|
|
|
--- /home/david/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 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
actWin = 0;
|
|
|
|
peer = new QtLocalPeer(this, appId);
|
2010-07-10 17:34:15 +02:00
|
|
|
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
|
2010-05-07 13:43:49 +02:00
|
|
|
+ connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-10 17:34:15 +02:00
|
|
|
@@ -265,6 +266,11 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
return peer->sendMessage(message, timeout);
|
|
|
|
}
|
2010-07-10 17:34:15 +02:00
|
|
|
|
|
|
|
+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)
|
2010-05-07 13:43:49 +02:00
|
|
|
{
|
|
|
|
actWin = aw;
|
2010-07-10 17:34:15 +02:00
|
|
|
- if (activateOnMessage)
|
|
|
|
+ if (activateOnMessage) {
|
|
|
|
connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
|
|
|
|
- else
|
2010-05-07 13:43:49 +02:00
|
|
|
+ connect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow()));
|
2010-07-10 17:34:15 +02:00
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
|
2010-05-07 13:43:49 +02:00
|
|
|
+ disconnect(peer, SIGNAL(messageReceived(const QByteArray&)), this, SLOT(activateWindow()));
|
2010-07-10 17:34:15 +02:00
|
|
|
+ }
|
2010-05-07 13:43:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-10 17:34:15 +02:00
|
|
|
diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtsingleapplication.h qtsingleapplication/qtsingleapplication.h
|
|
|
|
--- /home/david/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 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2010-07-10 17:34:15 +02:00
|
|
|
bool sendMessage(const QString &message, int timeout = 5000);
|
2010-05-07 13:43:49 +02:00
|
|
|
+ bool sendMessage(const QByteArray &message, int timeout = 5000);
|
|
|
|
void activateWindow();
|
|
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2010-07-10 17:34:15 +02:00
|
|
|
void messageReceived(const QString &message);
|
2010-05-07 13:43:49 +02:00
|
|
|
+ void messageReceived(const QByteArray &message);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2010-07-10 17:34:15 +02:00
|
|
|
diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.cpp qtsingleapplication/qtsinglecoreapplication.cpp
|
|
|
|
--- /home/david/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 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
{
|
|
|
|
peer = new QtLocalPeer(this);
|
2010-07-10 17:34:15 +02:00
|
|
|
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
|
2010-05-07 13:43:49 +02:00
|
|
|
+ connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-10 17:34:15 +02:00
|
|
|
@@ -94,6 +95,7 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
{
|
|
|
|
peer = new QtLocalPeer(this, appId);
|
2010-07-10 17:34:15 +02:00
|
|
|
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
|
2010-05-07 13:43:49 +02:00
|
|
|
+ connect(peer, SIGNAL(messageReceived(const QByteArray&)), SIGNAL(messageReceived(const QByteArray&)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-10 17:34:15 +02:00
|
|
|
@@ -133,6 +135,11 @@
|
2010-05-07 13:43:49 +02:00
|
|
|
return peer->sendMessage(message, timeout);
|
|
|
|
}
|
2010-07-10 17:34:15 +02:00
|
|
|
|
|
|
|
+bool QtSingleCoreApplication::sendMessage(const QByteArray &message, int timeout)
|
|
|
|
+{
|
|
|
|
+ return peer->sendMessage(message, timeout);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the application identifier. Two processes with the same
|
|
|
|
diff -ur /home/david/qtsingleapplication-2.6_1-opensource/src/qtsinglecoreapplication.h qtsingleapplication/qtsinglecoreapplication.h
|
|
|
|
--- /home/david/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:
|