From 25305a6ef01120bf3b0d929bae0ba7693f41c46b Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Sat, 10 Jul 2010 01:54:35 +0200 Subject: Configuration by pvs via D-Bus. Old .allow ist now deprecated, config file: .config/openslx/pvs.conf --- src/pvsgui.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/pvsgui.h') diff --git a/src/pvsgui.h b/src/pvsgui.h index f9a0ab8..90fe50e 100644 --- a/src/pvsgui.h +++ b/src/pvsgui.h @@ -62,7 +62,6 @@ private Q_SLOTS: void delHost(QString host); void pvsConnect(QAction *action); void pvsDisconnect(); - void setVncAllow(int i); void sendFile(); void receiveFile(); -- cgit v1.2.3-55-g7522 From 88dbb997a823ff77f752ac08105d12474345dfcb Mon Sep 17 00:00:00 2001 From: Sebastien Braun Date: Wed, 4 Aug 2010 17:24:21 +0200 Subject: Implement GUI for receiving incoming multicast transfers --- src/gui/clientFileReceiveDialog.cpp | 83 +++++++++++++++++++++++++++++++- src/gui/clientFileReceiveDialog.h | 14 ++++++ src/gui/ui/clientFileReceiveDialog.ui | 11 ++++- src/net/pvsIncomingMulticastTransfer.cpp | 37 +++++++------- src/net/pvsIncomingMulticastTransfer.h | 6 +-- src/pvs.cpp | 19 +++++++- src/pvs.h | 5 +- src/pvsgui.cpp | 7 +++ src/pvsgui.h | 1 + 9 files changed, 154 insertions(+), 29 deletions(-) (limited to 'src/pvsgui.h') diff --git a/src/gui/clientFileReceiveDialog.cpp b/src/gui/clientFileReceiveDialog.cpp index 669ca81..ff3226a 100644 --- a/src/gui/clientFileReceiveDialog.cpp +++ b/src/gui/clientFileReceiveDialog.cpp @@ -16,6 +16,9 @@ */ #include "clientFileReceiveDialog.h" +#include +#include +#include ClientFileReceiveDialog::ClientFileReceiveDialog(QTcpSocket *socket, QWidget *parent) : QDialog(parent) @@ -37,9 +40,44 @@ ClientFileReceiveDialog::ClientFileReceiveDialog(QTcpSocket *socket, QWidget *pa connect(this, SIGNAL(finished(int)), this, SLOT(deleteLater())); } +ClientFileReceiveDialog::ClientFileReceiveDialog(QString const& sender, qulonglong transferID, + QString const& filename, qulonglong size, OrgOpenslxPvsInterface* ifaceDBus, QWidget* parent) +{ + setupUi(this); + + _transferID = transferID; + _filename = filename; + _ifaceDBus = ifaceDBus; + _bytesToRead = size; + _socket = 0; + _file = 0; + div = 1; + while((size / div) > INT_MAX) + { + div <<= 1; + } + + connect(ifaceDBus, SIGNAL(incomingMulticastTransferStarted(qulonglong)), SLOT(mcastTransferStarted(qulonglong))); + connect(ifaceDBus, SIGNAL(incomingMulticastTransferProgress(qulonglong, qulonglong, qulonglong)), + SLOT(mcastTransferProgress(qulonglong, qulonglong, qulonglong))); + connect(ifaceDBus, SIGNAL(incomingMulticastTransferFinished(qulonglong)), SLOT(mcastTransferFinished(qulonglong))); + connect(ifaceDBus, SIGNAL(incomingMulticastTransferFailed(qulonglong, QString)), SLOT(mcastTransferFailed(qulonglong, QString))); + connect(cancelButton, SIGNAL(clicked()), SLOT(cancelTransfer())); + + qDebug("[%s] New multicast incoming transfer: %s from %s", metaObject()->className(), + filename.toLocal8Bit().constData(), sender.toLocal8Bit().constData()); + + + filenameLabel->setText(QFileInfo(filename).baseName()); + labelNick->setText(sender); + progressBar->setRange(0, 0); +} + + ClientFileReceiveDialog::~ClientFileReceiveDialog() { - _socket->deleteLater(); + if(_socket) + _socket->deleteLater(); qDebug("[%s] Deleted!", metaObject()->className()); } @@ -168,6 +206,49 @@ void ClientFileReceiveDialog::error(QAbstractSocket::SocketError error) close(); } +void ClientFileReceiveDialog::mcastTransferStarted(qulonglong transferID) +{ + if(transferID != _transferID) + return; +} + +void ClientFileReceiveDialog::mcastTransferProgress(qulonglong transferID, qulonglong bytes, qulonglong of) +{ + if(transferID != _transferID) + return; + + progressBar->setRange(0, of); + progressBar->setValue(bytes); +} + +void ClientFileReceiveDialog::mcastTransferFinished(qulonglong transferID) +{ + if(transferID != _transferID) + return; + + QString filename = QFileDialog::getSaveFileName(this, tr("Where should I save %1?").arg(_filename), _filename); + QFile* file = new QFile(_filename); + if(!file->rename(filename)) + { + QMessageBox::warning(this, tr("Could not rename file"), tr("Failed to rename %1 to %2").arg(_filename).arg(filename)); + } + accept(); +} + +void ClientFileReceiveDialog::mcastTransferFailed(qulonglong transferID, QString reason) +{ + if(transferID != _transferID) + return; + + QMessageBox::warning(this, tr("File transfer failed"), tr("File transfer failed for the following reason:\n%1").arg(reason)); + reject(); +} + +void ClientFileReceiveDialog::cancelTransfer() +{ + _ifaceDBus->cancelIncomingMulticastTransfer(_transferID); +} + QString ClientFileReceiveDialog::formatSize(qint64 size) { if (size >= 1000000000) // GB diff --git a/src/gui/clientFileReceiveDialog.h b/src/gui/clientFileReceiveDialog.h index c13d7b7..c9ed220 100644 --- a/src/gui/clientFileReceiveDialog.h +++ b/src/gui/clientFileReceiveDialog.h @@ -18,6 +18,8 @@ #include #include "ui_clientFileReceiveDialog.h" +class OrgOpenslxPvsInterface; + class ClientFileReceiveDialog: public QDialog, private Ui::ClientFileReceiveDialogClass { @@ -25,6 +27,7 @@ Q_OBJECT public: ClientFileReceiveDialog(QTcpSocket *socket, QWidget *parent = 0); + ClientFileReceiveDialog(QString const& sender, qulonglong transferID, QString const& basename, qulonglong size, OrgOpenslxPvsInterface* ifaceDBus, QWidget* parent = 0); ~ClientFileReceiveDialog(); private Q_SLOTS: @@ -33,6 +36,13 @@ private Q_SLOTS: void close(); void error(QAbstractSocket::SocketError error); + // multicast: + void mcastTransferStarted(qulonglong transferID); + void mcastTransferProgress(qulonglong transferID, qulonglong bytes, qulonglong of); + void mcastTransferFinished(qulonglong transferID); + void mcastTransferFailed(qulonglong transferID, QString reason); + void cancelTransfer(); + private: void sendAck(bool b); QString formatSize(qint64 size); @@ -42,6 +52,10 @@ private: qint64 _bytesToRead; int div; + // multicast: + OrgOpenslxPvsInterface* _ifaceDBus; + QString _filename; + qulonglong _transferID; }; #endif /* CLIENTFILERECEIVEDIALOG_H_ */ diff --git a/src/gui/ui/clientFileReceiveDialog.ui b/src/gui/ui/clientFileReceiveDialog.ui index af3a135..a137def 100644 --- a/src/gui/ui/clientFileReceiveDialog.ui +++ b/src/gui/ui/clientFileReceiveDialog.ui @@ -6,8 +6,8 @@ 0 0 - 208 - 108 + 528 + 117 @@ -61,6 +61,13 @@ + + + + + + + diff --git a/src/net/pvsIncomingMulticastTransfer.cpp b/src/net/pvsIncomingMulticastTransfer.cpp index 01507a9..10b5307 100644 --- a/src/net/pvsIncomingMulticastTransfer.cpp +++ b/src/net/pvsIncomingMulticastTransfer.cpp @@ -21,7 +21,7 @@ #include "pvsIncomingMulticastTransfer.h" #include -PVSIncomingMulticastTransfer::PVSIncomingMulticastTransfer(QString const& sender, qulonglong transferID, qulonglong size, +PVSIncomingMulticastTransfer::PVSIncomingMulticastTransfer(QString const& sender, qulonglong transferID, qulonglong size, QString const& filename, ushort port, McastConfiguration const* configTemplate, QObject* parent) : QObject(parent), _sender(sender), @@ -29,19 +29,21 @@ PVSIncomingMulticastTransfer::PVSIncomingMulticastTransfer(QString const& sender _bytes(0), _size(size), _port(port), - _temporaryFile(new QTemporaryFile(QFileInfo(QDir::homePath(), "incoming.mcastft.XXXXXX").absolutePath(), this)), - _finalFile(0), + _file(new QFile(filename, this)), _receiver(0), _config(configTemplate ? new McastConfiguration(*configTemplate) : new McastConfiguration()), _progressTimer(new QTimer(this)) { + _file->open(QIODevice::WriteOnly); + _config->multicastUDPPortBase(port); - _config->multicastDPort(port); - _config->multicastSPort(port); + // _config->multicastDPort(port+1); + // _config->multicastSPort(port+2); connect(_progressTimer, SIGNAL(timeout()), SLOT(updateProgress())); + connect(this, SIGNAL(failed(qulonglong, QString const&)), SLOT(removeFile())); } PVSIncomingMulticastTransfer::~PVSIncomingMulticastTransfer() @@ -51,10 +53,10 @@ PVSIncomingMulticastTransfer::~PVSIncomingMulticastTransfer() bool PVSIncomingMulticastTransfer::start() { - QFile *dest = _finalFile ? _finalFile : _temporaryFile; - _receiver = new McastReceiver(dest, new McastConfiguration(*_config), this); + _file->open(QIODevice::WriteOnly); + _receiver = new McastReceiver(_file, new McastConfiguration(*_config), this); connect(_receiver, SIGNAL(finished(int)), SLOT(receiverFinished(int))); - connect(_receiver, SIGNAL(progress(quint64)), SLOT(receiverProgress(quint64))); + connect(_receiver, SIGNAL(progress(quint64)), SLOT(receiverProgressed(quint64))); if (!_receiver->start()) { @@ -76,17 +78,8 @@ void PVSIncomingMulticastTransfer::abort() delete _progressTimer; _progressTimer = 0; - if (_temporaryFile) - { - _temporaryFile->remove(); - } - delete _temporaryFile; - - if (_finalFile) - { - _finalFile->remove(); - } - delete _finalFile; + if(_file) + delete _file; } void PVSIncomingMulticastTransfer::updatePort(ushort port) @@ -124,6 +117,12 @@ void PVSIncomingMulticastTransfer::receiverFinished(int how) } } +void PVSIncomingMulticastTransfer::removeFile() +{ + if(_file) + _file->remove(); +} + void PVSIncomingMulticastTransfer::updateProgress() { if (!_started) diff --git a/src/net/pvsIncomingMulticastTransfer.h b/src/net/pvsIncomingMulticastTransfer.h index 9a33348..f96e176 100644 --- a/src/net/pvsIncomingMulticastTransfer.h +++ b/src/net/pvsIncomingMulticastTransfer.h @@ -31,7 +31,7 @@ class PVSIncomingMulticastTransfer : public QObject { Q_OBJECT public: - PVSIncomingMulticastTransfer(QString const& sender, qulonglong transferID, qulonglong size, ushort port, + PVSIncomingMulticastTransfer(QString const& sender, qulonglong transferID, qulonglong size, QString const& filename, ushort port, McastConfiguration const* configTemplate, QObject* parent = 0); virtual ~PVSIncomingMulticastTransfer(); @@ -53,6 +53,7 @@ private slots: void receiverProgressed(quint64 bytes); void receiverFinished(int reason); void updateProgress(); + void removeFile(); private: QString _sender; @@ -60,8 +61,7 @@ private: qulonglong _bytes; qulonglong _size; ushort _port; - QFile* _temporaryFile; - QFile* _finalFile; + QFile* _file; McastReceiver* _receiver; McastConfiguration* _config; bool _started; diff --git a/src/pvs.cpp b/src/pvs.cpp index 0e5aaf5..852c9f4 100644 --- a/src/pvs.cpp +++ b/src/pvs.cpp @@ -716,9 +716,23 @@ void PVS::cancelOutgoingMulticastTransfer(quint64 transferID) } } +void PVS::cancelIncomingMulticastTransfer(qulonglong transferID) +{ + PVSIncomingMulticastTransfer* transfer = _incomingTransfers.value(transferID, 0); + + if(transfer) + { + _incomingTransfers.remove(transferID); + delete transfer; + } +} + void PVS::onIncomingMulticastTransfer(QString const& sender, qulonglong transferID, QString const& basename, qulonglong size, ushort port) { + if (_outgoingTransfers.contains(transferID)) + return; + PVSIncomingMulticastTransfer* transfer; if (_incomingTransfers.value(transferID, 0)) { @@ -727,7 +741,8 @@ void PVS::onIncomingMulticastTransfer(QString const& sender, qulonglong transfer } else { - transfer = new PVSIncomingMulticastTransfer(sender, transferID, size, port, _masterMcastConfig, this); + QString filename = QFileInfo(QDir::home(), QString("%1.part.%2").arg(basename).arg(transferID, 0, 16)).absoluteFilePath(); + transfer = new PVSIncomingMulticastTransfer(sender, transferID, size, filename, port, _masterMcastConfig, this); _incomingTransfers.insert(transferID, transfer); connect(transfer, SIGNAL(retry(QString const&, qulonglong)), SLOT(onIncomingMulticastTransferRetry(QString const&, qulonglong))); @@ -738,7 +753,7 @@ void PVS::onIncomingMulticastTransfer(QString const& sender, qulonglong transfer connect(transfer, SIGNAL(finished(qulonglong)), SLOT(incomingMulticastTransferDelete(qulonglong))); connect(transfer, SIGNAL(failed(qulonglong, QString const&)), SLOT(incomingMulticastTransferDelete(qulonglong))); - emit incomingMulticastTransferNew(transferID, sender, basename, size); + emit incomingMulticastTransferNew(transferID, sender, filename, size); QTimer::singleShot(0, transfer, SLOT(start())); } } diff --git a/src/pvs.h b/src/pvs.h index dc272f0..ef6454e 100644 --- a/src/pvs.h +++ b/src/pvs.h @@ -86,6 +86,7 @@ public Q_SLOTS: // Multicast File Transfer bool createMulticastTransfer(QString const& objectPath, quint64& transferID, QString& errorReason); void cancelOutgoingMulticastTransfer(quint64 transferID); + void cancelIncomingMulticastTransfer(qulonglong transferID); Q_SIGNALS: @@ -106,7 +107,7 @@ Q_SIGNALS: void outgoingMulticastTransferProgress(qulonglong transferID, qulonglong bytes, qulonglong of); void outgoingMulticastTransferFinished(qulonglong transferID); void outgoingMulticastTransferFailed(qulonglong transferID, QString reason); - void incomingMulticastTransferNew(qulonglong transferID, QString sender, QString basename, qulonglong size); + void incomingMulticastTransferNew(qulonglong transferID, QString sender, QString filename, qulonglong size); void incomingMulticastTransferStarted(qulonglong transferID); void incomingMulticastTransferProgress(qulonglong transferID, qulonglong bytes, qulonglong of); void incomingMulticastTransferFinished(qulonglong transferID); @@ -166,12 +167,12 @@ private: QHash _incomingTransfers; void onIncomingMulticastTransfer(QString const& sender, qulonglong transferID, QString const& basename, qulonglong size, ushort port); - void onIncomingMulticastTransferRetry(QString const& sender, qulonglong transferID); static quint64 generateMcastTransferID(); private Q_SLOTS: // housekeeping void outgoingMulticastTransferDelete(qulonglong transferID); void incomingMulticastTransferDelete(qulonglong transferID); + void onIncomingMulticastTransferRetry(QString const& sender, qulonglong transferID); }; #endif /* PVSCLIENT_H_ */ diff --git a/src/pvsgui.cpp b/src/pvsgui.cpp index 25f1cd6..e949d5b 100644 --- a/src/pvsgui.cpp +++ b/src/pvsgui.cpp @@ -119,6 +119,7 @@ PVSGUI::PVSGUI(QWidget *parent) : connect(_ifaceDBus, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(_ifaceDBus, SIGNAL(addHost(QString)), this, SLOT(addHost(QString))); connect(_ifaceDBus, SIGNAL(delHost(QString)), this, SLOT(delHost(QString))); + connect(_ifaceDBus, SIGNAL(incomingMulticastTransferNew(qulonglong, QString, QString, qulonglong)), SLOT(incomingMulticastFile(qulonglong, QString, QString, qulonglong))); // show toolbar setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); @@ -421,6 +422,12 @@ void PVSGUI::receiveFile() d->open(); } +void PVSGUI::incomingMulticastFile(qulonglong transferID, QString sender, QString basename, qulonglong size) +{ + ClientFileReceiveDialog *d = new ClientFileReceiveDialog(sender, transferID, basename, size, _ifaceDBus, this); + d->open(); +} + //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// diff --git a/src/pvsgui.h b/src/pvsgui.h index f9a0ab8..2883b60 100644 --- a/src/pvsgui.h +++ b/src/pvsgui.h @@ -65,6 +65,7 @@ private Q_SLOTS: void setVncAllow(int i); void sendFile(); void receiveFile(); + void incomingMulticastFile(qulonglong, QString sender, QString basename, qulonglong size); private: void setupMenu(); -- cgit v1.2.3-55-g7522 From ca61d21c6defb9553234c1fa5b0979c46542c676 Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Sat, 28 Aug 2010 03:17:08 +0200 Subject: Enhancement #587 --- CMakeLists.txt | 2 +- i18n/pvs_ar_JO.ts | 139 ++++++++++++++++++++++++++++++++++++-- i18n/pvs_de_DE.ts | 141 +++++++++++++++++++++++++++++++++++++-- i18n/pvs_es_MX.ts | 139 ++++++++++++++++++++++++++++++++++++-- i18n/pvs_fr_FR.ts | 139 ++++++++++++++++++++++++++++++++++++-- i18n/pvs_pl_PL.ts | 139 ++++++++++++++++++++++++++++++++++++-- i18n/pvsgui_ar_JO.ts | 66 +++++++++--------- i18n/pvsgui_de_DE.ts | 66 +++++++++--------- i18n/pvsgui_es_MX.ts | 66 +++++++++--------- i18n/pvsgui_fr_FR.ts | 66 +++++++++--------- i18n/pvsgui_pl_PL.ts | 66 +++++++++--------- org.openslx.pvs.service | 2 +- src/gui/clientChatDialog.cpp | 2 - src/gui/clientConfigDialog.cpp | 2 - src/gui/clientFileSendDialog.cpp | 2 - src/gui/clientVNCViewer.cpp | 2 - src/pvs.cpp | 9 ++- src/pvs.h | 2 +- src/pvsDaemon.cpp | 132 ++++++++++++++++-------------------- src/pvsgui.cpp | 34 ++++++---- src/pvsgui.h | 1 - src/version.h | 4 +- 22 files changed, 931 insertions(+), 290 deletions(-) (limited to 'src/pvsgui.h') diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ac01c9..e364528 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -381,7 +381,7 @@ SET( CPACK_SET_DESTDIR "ON" ) SET( CPACK_PACKAGE_NAME "pvs" ) SET( CPACK_PACKAGE_VERSION_MAJOR "2" ) SET( CPACK_PACKAGE_VERSION_MINOR "0" ) -SET( CPACK_PACKAGE_VERSION_PATCH "1" ) +SET( CPACK_PACKAGE_VERSION_PATCH "3" ) SET( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Pool Video Switch" ) SET( CPACK_PACKAGE_DESCRIPTION "") SET( CPACK_PACKAGE_CONTACT "Simon Wittenberg " ) diff --git a/i18n/pvs_ar_JO.ts b/i18n/pvs_ar_JO.ts index 38bf578..a57e4bd 100644 --- a/i18n/pvs_ar_JO.ts +++ b/i18n/pvs_ar_JO.ts @@ -4,24 +4,155 @@ PVS - + Message - + VNC connection - + The host - + requested your screen! + + QObject + + + Version: + + + + + Usage: + + + + + <<option> <value>, ... > + + + + + Options: + + + + + -vncScriptFile <fullpath\filename> + + + + + Specifies a custom location for the vnc-start/stop-script. + + + + + If not specified, /usr/bin/pvs-vncsrv is expected. + + + + + -freq <seconds> + + + + + Specifies how long to wait until a reconnection attempt is made. + + + + + Default is 5. + + + + + -port <port> + + + + + Specifies on which port to run. + + + + + Default is + + + + + -h or --help + + + + + Shows this help text and exits. + + + + + -v or --version + + + + + Shows the current version and exits. + + + + + -d or --daemon + + + + + Start as daemon. + + + + + -c <string command>:<string value> + + + + + Sends the command and the optional value to a running PVS-Client. + + + + + Command and value may not contain spaces or colons. + + + + + The dividing colon is mandatory. + + + + + Prints out available commands to use with -c. + + + + + Use -h or --help to get a listing of all options. +-v or --version gives you the current version. + + + + + diff --git a/i18n/pvs_de_DE.ts b/i18n/pvs_de_DE.ts index 38bf578..a58199c 100644 --- a/i18n/pvs_de_DE.ts +++ b/i18n/pvs_de_DE.ts @@ -1,27 +1,158 @@ - + PVS - + Message - + VNC connection - + The host - + requested your screen! + + QObject + + + Version: + + + + + Usage: + + + + + <<option> <value>, ... > + + + + + Options: + + + + + -vncScriptFile <fullpath\filename> + + + + + Specifies a custom location for the vnc-start/stop-script. + + + + + If not specified, /usr/bin/pvs-vncsrv is expected. + + + + + -freq <seconds> + + + + + Specifies how long to wait until a reconnection attempt is made. + + + + + Default is 5. + + + + + -port <port> + + + + + Specifies on which port to run. + + + + + Default is + + + + + -h or --help + + + + + Shows this help text and exits. + + + + + -v or --version + + + + + Shows the current version and exits. + + + + + -d or --daemon + + + + + Start as daemon. + + + + + -c <string command>:<string value> + + + + + Sends the command and the optional value to a running PVS-Client. + + + + + Command and value may not contain spaces or colons. + + + + + The dividing colon is mandatory. + + + + + Prints out available commands to use with -c. + + + + + Use -h or --help to get a listing of all options. +-v or --version gives you the current version. + + + + + diff --git a/i18n/pvs_es_MX.ts b/i18n/pvs_es_MX.ts index 38bf578..a57e4bd 100644 --- a/i18n/pvs_es_MX.ts +++ b/i18n/pvs_es_MX.ts @@ -4,24 +4,155 @@ PVS - + Message - + VNC connection - + The host - + requested your screen! + + QObject + + + Version: + + + + + Usage: + + + + + <<option> <value>, ... > + + + + + Options: + + + + + -vncScriptFile <fullpath\filename> + + + + + Specifies a custom location for the vnc-start/stop-script. + + + + + If not specified, /usr/bin/pvs-vncsrv is expected. + + + + + -freq <seconds> + + + + + Specifies how long to wait until a reconnection attempt is made. + + + + + Default is 5. + + + + + -port <port> + + + + + Specifies on which port to run. + + + + + Default is + + + + + -h or --help + + + + + Shows this help text and exits. + + + + + -v or --version + + + + + Shows the current version and exits. + + + + + -d or --daemon + + + + + Start as daemon. + + + + + -c <string command>:<string value> + + + + + Sends the command and the optional value to a running PVS-Client. + + + + + Command and value may not contain spaces or colons. + + + + + The dividing colon is mandatory. + + + + + Prints out available commands to use with -c. + + + + + Use -h or --help to get a listing of all options. +-v or --version gives you the current version. + + + + + diff --git a/i18n/pvs_fr_FR.ts b/i18n/pvs_fr_FR.ts index 38bf578..a57e4bd 100644 --- a/i18n/pvs_fr_FR.ts +++ b/i18n/pvs_fr_FR.ts @@ -4,24 +4,155 @@ PVS - + Message - + VNC connection - + The host - + requested your screen! + + QObject + + + Version: + + + + + Usage: + + + + + <<option> <value>, ... > + + + + + Options: + + + + + -vncScriptFile <fullpath\filename> + + + + + Specifies a custom location for the vnc-start/stop-script. + + + + + If not specified, /usr/bin/pvs-vncsrv is expected. + + + + + -freq <seconds> + + + + + Specifies how long to wait until a reconnection attempt is made. + + + + + Default is 5. + + + + + -port <port> + + + + + Specifies on which port to run. + + + + + Default is + + + + + -h or --help + + + + + Shows this help text and exits. + + + + + -v or --version + + + + + Shows the current version and exits. + + + + + -d or --daemon + + + + + Start as daemon. + + + + + -c <string command>:<string value> + + + + + Sends the command and the optional value to a running PVS-Client. + + + + + Command and value may not contain spaces or colons. + + + + + The dividing colon is mandatory. + + + + + Prints out available commands to use with -c. + + + + + Use -h or --help to get a listing of all options. +-v or --version gives you the current version. + + + + + diff --git a/i18n/pvs_pl_PL.ts b/i18n/pvs_pl_PL.ts index 38bf578..a57e4bd 100644 --- a/i18n/pvs_pl_PL.ts +++ b/i18n/pvs_pl_PL.ts @@ -4,24 +4,155 @@ PVS - + Message - + VNC connection - + The host - + requested your screen! + + QObject + + + Version: + + + + + Usage: + + + + + <<option> <value>, ... > + + + + + Options: + + + + + -vncScriptFile <fullpath\filename> + + + + + Specifies a custom location for the vnc-start/stop-script. + + + + + If not specified, /usr/bin/pvs-vncsrv is expected. + + + + + -freq <seconds> + + + + + Specifies how long to wait until a reconnection attempt is made. + + + + + Default is 5. + + + + + -port <port> + + + + + Specifies on which port to run. + + + + + Default is + + + + + -h or --help + + + + + Shows this help text and exits. + + + + + -v or --version + + + + + Shows the current version and exits. + + + + + -d or --daemon + + + + + Start as daemon. + + + + + -c <string command>:<string value> + + + + + Sends the command and the optional value to a running PVS-Client. + + + + + Command and value may not contain spaces or colons. + + + + + The dividing colon is mandatory. + + + + + Prints out available commands to use with -c. + + + + + Use -h or --help to get a listing of all options. +-v or --version gives you the current version. + + + + + diff --git a/i18n/pvsgui_ar_JO.ts b/i18n/pvsgui_ar_JO.ts index 04d9717..83560ba 100644 --- a/i18n/pvsgui_ar_JO.ts +++ b/i18n/pvsgui_ar_JO.ts @@ -40,47 +40,47 @@ ClientChatDialog - + &Send File... - + has joined the chat. - + has left the chat. - + PVS File Transfer - + Send file ' - + ' to - + Connected. - + Disconnected. - + Message from < @@ -260,23 +260,23 @@ ClientFileSendDialog - + Open File - - + + PVS - File Transfer - + File Transfer complete. - + File Transfer canceled! @@ -399,77 +399,77 @@ p, li { white-space: pre-wrap; } - + &Disconnect - + C&hat - + &Send File - + &Config - + &Information - + &About - + &Quit - - - + + + PVS Connection - + Please enter password (If not needed leave blank): - + Are you sure you want to disconnect? - - + + PVS connection - - + + Connected to - - + + Disconnected - + New host available: diff --git a/i18n/pvsgui_de_DE.ts b/i18n/pvsgui_de_DE.ts index 544ebff..d49306a 100644 --- a/i18n/pvsgui_de_DE.ts +++ b/i18n/pvsgui_de_DE.ts @@ -40,47 +40,47 @@ ClientChatDialog - + &Send File... Datei &Senden... - + has joined the chat. ist dem Chat beigetreten. - + has left the chat. hat den Chat verlassen. - + PVS File Transfer PVS Dateiübertragung - + Send file ' Datei senden ' - + ' to ' an - + Connected. Verbunden. - + Disconnected. Getrennt. - + Message from < Nachricht von < @@ -260,23 +260,23 @@ ClientFileSendDialog - + Open File Datei Öffnen - - + + PVS - File Transfer PBS -Dateiübertragung - + File Transfer complete. Dateiübertragung beendet. - + File Transfer canceled! Dateiübertragung abgebrochen! @@ -407,77 +407,77 @@ p, li { white-space: pre-wrap; } Verbinden - + &Disconnect &Trennen - + C&hat - + &Send File Datei &Senden - + &Config &Konfiguration - + &Information &Information - + &About &Über - + &Quit &Beenden - - - + + + PVS Connection PVS Verbindung - + Please enter password (If not needed leave blank): Bitte geben sie ein Passwor ein (Falls nicht erforderlich einfach leer lassen): - + Are you sure you want to disconnect? Sind sie sicher dass sie die Verbindung trennen möchten? - - + + PVS connection PVS Verbindung - - + + Connected to Verbunden mit - - + + Disconnected Getrennt - + New host available: Neuer Host verfügbar: diff --git a/i18n/pvsgui_es_MX.ts b/i18n/pvsgui_es_MX.ts index 855ee9b..92db9d7 100644 --- a/i18n/pvsgui_es_MX.ts +++ b/i18n/pvsgui_es_MX.ts @@ -40,47 +40,47 @@ ClientChatDialog - + &Send File... Enviar archivo... - + has joined the chat. ha ingresado al chat. - + has left the chat. ha abandonado el chat - + PVS File Transfer PVS Transferencia de datos - + Send file ' Enviar archivo ' - + ' to ' a - + Connected. Conectado. - + Disconnected. Desconectado. - + Message from < Mensaje de < @@ -260,23 +260,23 @@ ClientFileSendDialog - + Open File Abrir archivo - - + + PVS - File Transfer PVS - Transferencia de datos - + File Transfer complete. La transferencia de datos ha sido completada. - + File Transfer canceled! La transferencia de datos ha sido cancelada! @@ -419,77 +419,77 @@ p, li { white-space: pre-wrap; } Conectar - + &Disconnect &Desconectar - + C&hat ??? - + &Send File &Enviar archivo - + &Config &Configuración - + &Information &Información - + &About &Acerca de - + &Quit &Cerrar - - - + + + PVS Connection PVS Connección - + Please enter password (If not needed leave blank): Porfavor ingrese una contraseña (Deje la seccion vacia si no lo necesita): - + Are you sure you want to disconnect? Realmente desea desconectarse? - - + + PVS connection PVS Connección - - + + Connected to Connectar a - - + + Disconnected Desconectado - + New host available: Nuevo Host disponible: diff --git a/i18n/pvsgui_fr_FR.ts b/i18n/pvsgui_fr_FR.ts index 04d9717..83560ba 100644 --- a/i18n/pvsgui_fr_FR.ts +++ b/i18n/pvsgui_fr_FR.ts @@ -40,47 +40,47 @@ ClientChatDialog - + &Send File... - + has joined the chat. - + has left the chat. - + PVS File Transfer - + Send file ' - + ' to - + Connected. - + Disconnected. - + Message from < @@ -260,23 +260,23 @@ ClientFileSendDialog - + Open File - - + + PVS - File Transfer - + File Transfer complete. - + File Transfer canceled! @@ -399,77 +399,77 @@ p, li { white-space: pre-wrap; } - + &Disconnect - + C&hat - + &Send File - + &Config - + &Information - + &About - + &Quit - - - + + + PVS Connection - + Please enter password (If not needed leave blank): - + Are you sure you want to disconnect? - - + + PVS connection - - + + Connected to - - + + Disconnected - + New host available: diff --git a/i18n/pvsgui_pl_PL.ts b/i18n/pvsgui_pl_PL.ts index 04d9717..83560ba 100644 --- a/i18n/pvsgui_pl_PL.ts +++ b/i18n/pvsgui_pl_PL.ts @@ -40,47 +40,47 @@ ClientChatDialog - + &Send File... - + has joined the chat. - + has left the chat. - + PVS File Transfer - + Send file ' - + ' to - + Connected. - + Disconnected. - + Message from < @@ -260,23 +260,23 @@ ClientFileSendDialog - + Open File - - + + PVS - File Transfer - + File Transfer complete. - + File Transfer canceled! @@ -399,77 +399,77 @@ p, li { white-space: pre-wrap; } - + &Disconnect - + C&hat - + &Send File - + &Config - + &Information - + &About - + &Quit - - - + + + PVS Connection - + Please enter password (If not needed leave blank): - + Are you sure you want to disconnect? - - + + PVS connection - - + + Connected to - - + + Disconnected - + New host available: diff --git a/org.openslx.pvs.service b/org.openslx.pvs.service index 0398081..91a3e67 100644 --- a/org.openslx.pvs.service +++ b/org.openslx.pvs.service @@ -1,4 +1,4 @@ [D-BUS Service] Name=org.openslx.pvs -Exec=@CMAKE_INSTALL_PREFIX@/bin/pvs +Exec=@CMAKE_INSTALL_PREFIX@/bin/pvs -d diff --git a/src/gui/clientChatDialog.cpp b/src/gui/clientChatDialog.cpp index 7c32790..163ac92 100644 --- a/src/gui/clientChatDialog.cpp +++ b/src/gui/clientChatDialog.cpp @@ -29,8 +29,6 @@ ClientChatDialog::ClientChatDialog(QWidget *parent) : // connect to D-Bus and get interface QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerObject("/chat", this); - dbus.registerService("org.openslx.pvsgui"); _ifaceDBus = new OrgOpenslxPvsInterface("org.openslx.pvs", "/", dbus, this); connect(_ifaceDBus, SIGNAL(chat_receive(QString, QString, QString)), this, SLOT(receive(QString, QString, QString))); diff --git a/src/gui/clientConfigDialog.cpp b/src/gui/clientConfigDialog.cpp index 3e1ee50..0ee5908 100644 --- a/src/gui/clientConfigDialog.cpp +++ b/src/gui/clientConfigDialog.cpp @@ -28,8 +28,6 @@ ClientConfigDialog::ClientConfigDialog(QWidget *parent) : // connect to D-Bus and get interface QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerObject("/config", this); - dbus.registerService("org.openslx.pvsgui"); _ifaceDBus = new OrgOpenslxPvsInterface("org.openslx.pvs", "/", dbus, this); } diff --git a/src/gui/clientFileSendDialog.cpp b/src/gui/clientFileSendDialog.cpp index ccb44b3..b4512c0 100644 --- a/src/gui/clientFileSendDialog.cpp +++ b/src/gui/clientFileSendDialog.cpp @@ -28,8 +28,6 @@ ClientFileSendDialog::ClientFileSendDialog(QWidget *parent) : // connect to D-Bus and get interface QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerObject("/filesend", this); - dbus.registerService("org.openslx.pvsgui"); _ifaceDBus = new OrgOpenslxPvsInterface("org.openslx.pvs", "/", dbus, this); // get current users name from backend diff --git a/src/gui/clientVNCViewer.cpp b/src/gui/clientVNCViewer.cpp index d6a218b..d794b0b 100644 --- a/src/gui/clientVNCViewer.cpp +++ b/src/gui/clientVNCViewer.cpp @@ -22,8 +22,6 @@ ClientVNCViewer::ClientVNCViewer(QWidget *parent) : { // connect to D-Bus and get interface QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerObject("/vnc", this); - dbus.registerService("org.openslx.pvsgui"); _ifaceDBus = new OrgOpenslxPvsInterface("org.openslx.pvs", "/", dbus, this); connect(_ifaceDBus, SIGNAL(project(QString, int, QString, bool, bool, int)), this, SLOT(open(QString, int, QString, bool, bool, int))); diff --git a/src/pvs.cpp b/src/pvs.cpp index 1c08be5..21b7bdf 100755 --- a/src/pvs.cpp +++ b/src/pvs.cpp @@ -53,8 +53,10 @@ PVS::PVS() : // connect to D-Bus new PvsAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerObject("/", this); - dbus.registerService("org.openslx.pvs"); + if (!dbus.registerObject("/", this)) + qDebug("[ERROR] DBus: Could not register object"); + if (!dbus.registerService("org.openslx.pvs")) + qDebug("[ERROR] DBus: Could not register service"); _sdClient = new PVSServiceDiscovery(this); @@ -552,9 +554,10 @@ int PVS::stopVNCScript() } } -void PVS::start() +bool PVS::start() { _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROJECTING", "YES")); + return true; } void PVS::onConnected(QString name) diff --git a/src/pvs.h b/src/pvs.h index b6b5e65..1bb0747 100755 --- a/src/pvs.h +++ b/src/pvs.h @@ -69,7 +69,7 @@ public: void guiDelHost(QString host); public Q_SLOTS: - void start(); + bool start(); void quit(); void chat_send(QString nick_to, QString nick_from, QString msg); QString chat_getNickname(); diff --git a/src/pvsDaemon.cpp b/src/pvsDaemon.cpp index e9479df..b23bc57 100755 --- a/src/pvsDaemon.cpp +++ b/src/pvsDaemon.cpp @@ -9,14 +9,12 @@ #include "src/core/pvsChatClient.h" PVS *mainClient = NULL; - -// This define works as a switch whether to run as deamon or regular app -#define as_daemon +QTextStream qout(stdout); /// VERSION_STRING is defined in src/version.h void printVersion(bool doExit) { - + QTextStream qout(stdout); printf("Version:\t"VERSION_STRING"\n"); if (doExit) exit(0); @@ -25,30 +23,31 @@ void printVersion(bool doExit) /// outputs the full help text void printHelp() { - printf("**************************************************************\n"); - printf("\nPool Video Switch Client\n"); - printf("**************************************************************\n"); - printVersion(false); - printf("**************************************************************\n"); - printf("Usage:\tpoolVSClient < @@ -402,84 +402,127 @@ p, li { white-space: pre-wrap; } PVSGUI - + Connect Verbinden - + + Show &toolbar + &Werkzeugleiste anzeigen + + + &Disconnect &Trennen - + C&hat - + &Send File Datei &Senden - + &Config &Konfiguration - + &Information &Information - + &About &Über - + &Quit &Beenden - - - + + + PVS Connection PVS Verbindung - + Please enter password (If not needed leave blank): Bitte geben sie ein Passwor ein (Falls nicht erforderlich einfach leer lassen): - + Are you sure you want to disconnect? Sind sie sicher dass sie die Verbindung trennen möchten? - - + + PVS connection PVS Verbindung - - + + Connected to Verbunden mit - - + + Disconnected Getrennt - + New host available: Neuer Host verfügbar: + + QObject + + + Usage: pvsgui [OPTIONS]... + Aufruf: pvsgui [OPTIONEN]... + + + + Start the Pool Video Switch GUI. + Startet die Pool Video Switch GUI. + + + + Options: + Optionen: + + + + Start only with systray icon. + Starte nur mit Symbol in Systray. + + + + Show this help text and quit. + Zeige diesen Hilfetext an und beende. + + + + Show version and quit. + Zeige Versionsinformationen an und beende. + + + + Version: + Version: + + diff --git a/i18n/pvsgui_es_MX.ts b/i18n/pvsgui_es_MX.ts index 5720604..d3cb2d6 100644 --- a/i18n/pvsgui_es_MX.ts +++ b/i18n/pvsgui_es_MX.ts @@ -414,84 +414,127 @@ p, li { white-space: pre-wrap; } PVSGUI - + Connect Conectar - + + Show &toolbar + + + + &Disconnect &Desconectar - + C&hat ??? - + &Send File &Enviar archivo - + &Config &Configuración - + &Information &Información - + &About &Acerca de - + &Quit &Cerrar - - - + + + PVS Connection PVS Connección - + Please enter password (If not needed leave blank): Porfavor ingrese una contraseña (Deje la seccion vacia si no lo necesita): - + Are you sure you want to disconnect? Realmente desea desconectarse? - - + + PVS connection PVS Connección - - + + Connected to Connectar a - - + + Disconnected Desconectado - + New host available: Nuevo Host disponible: + + QObject + + + Usage: pvsgui [OPTIONS]... + + + + + Start the Pool Video Switch GUI. + + + + + Options: + + + + + Start only with systray icon. + + + + + Show this help text and quit. + + + + + Show version and quit. + + + + + Version: + Version: + + diff --git a/i18n/pvsgui_fr_FR.ts b/i18n/pvsgui_fr_FR.ts index 3cda399..59b40b9 100644 --- a/i18n/pvsgui_fr_FR.ts +++ b/i18n/pvsgui_fr_FR.ts @@ -394,84 +394,127 @@ p, li { white-space: pre-wrap; } PVSGUI - + Connect - + + Show &toolbar + + + + &Disconnect - + C&hat - + &Send File - + &Config - + &Information - + &About - + &Quit - - - + + + PVS Connection - + Please enter password (If not needed leave blank): - + Are you sure you want to disconnect? - - + + PVS connection - - + + Connected to - - + + Disconnected - + New host available: + + QObject + + + Usage: pvsgui [OPTIONS]... + + + + + Start the Pool Video Switch GUI. + + + + + Options: + + + + + Start only with systray icon. + + + + + Show this help text and quit. + + + + + Show version and quit. + + + + + Version: + + + diff --git a/i18n/pvsgui_pl_PL.ts b/i18n/pvsgui_pl_PL.ts index 3cda399..59b40b9 100644 --- a/i18n/pvsgui_pl_PL.ts +++ b/i18n/pvsgui_pl_PL.ts @@ -394,84 +394,127 @@ p, li { white-space: pre-wrap; } PVSGUI - + Connect - + + Show &toolbar + + + + &Disconnect - + C&hat - + &Send File - + &Config - + &Information - + &About - + &Quit - - - + + + PVS Connection - + Please enter password (If not needed leave blank): - + Are you sure you want to disconnect? - - + + PVS connection - - + + Connected to - - + + Disconnected - + New host available: + + QObject + + + Usage: pvsgui [OPTIONS]... + + + + + Start the Pool Video Switch GUI. + + + + + Options: + + + + + Start only with systray icon. + + + + + Show this help text and quit. + + + + + Show version and quit. + + + + + Version: + + + diff --git a/src/pvsgui.cpp b/src/pvsgui.cpp index 5f2ac60..c2ac3cb 100644 --- a/src/pvsgui.cpp +++ b/src/pvsgui.cpp @@ -18,6 +18,7 @@ */ #include "pvsgui.h" +#include "version.h" PVSGUI::PVSGUI(QWidget *parent) : QWidget(parent) @@ -88,6 +89,7 @@ PVSGUI::PVSGUI(QWidget *parent) : connect(_serverSocket, SIGNAL(newConnection()), this, SLOT(receiveFile())); // signals & slots - menu + connect(_showAction, SIGNAL(toggled(bool)), this, SLOT(setVisible(bool))); connect(_disconnectAction, SIGNAL(triggered()), this, SLOT(pvsDisconnect())); connect(_startChatAction, SIGNAL(triggered()), _chatDialog, SLOT(open())); connect(_sendFileAction, SIGNAL(triggered()), this, SLOT(sendFile())); @@ -116,7 +118,6 @@ PVSGUI::PVSGUI(QWidget *parent) : setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); setAttribute(Qt::WA_AlwaysShowToolTips); updateConfig(); - setVisible(true); hide(); } @@ -136,6 +137,13 @@ void PVSGUI::updateConfig() setLocation(_settings.value("Display/location").toInt()); } + +void PVSGUI::setVisible(bool visible) +{ + QWidget::setVisible(visible); + _showAction->setChecked(isVisible()); +} + //////////////////////////////////////////////////////////////////////////////// // Protected @@ -178,6 +186,8 @@ void PVSGUI::mouseMoveEvent(QMouseEvent *event) void PVSGUI::setupMenu() { // setup actions + _showAction = new QAction(tr("Show &toolbar"), this); + _showAction->setCheckable(true); _disconnectAction = new QAction(tr("&Disconnect"), this); _startChatAction = new QAction(tr("C&hat"), this); _sendFileAction = new QAction(tr("&Send File"), this); @@ -187,6 +197,7 @@ void PVSGUI::setupMenu() _quitAction = new QAction(tr("&Quit"), this); // setup menu + _menu->addAction(_showAction); _menu->addMenu(_hostMenu); _menu->addAction(_disconnectAction); _menu->addAction(_showInfoAction); @@ -402,9 +413,34 @@ void PVSGUI::receiveFile() //////////////////////////////////////////////////////////////////////////////// // Main +void printHelp() +{ + QTextStream qout(stdout); + qout << QObject::tr("Usage: pvsgui [OPTIONS]...") << endl; + qout << QObject::tr("Start the Pool Video Switch GUI.") << endl; + qout << QObject::tr("Options:") << endl << endl; + qout << "-n or --nobar" << "\t" << QObject::tr("Start only with systray icon.") << endl; + qout << "-h or --help" << "\t" << QObject::tr("Show this help text and quit.") << endl; + qout << "-v or --version" << "\t" << QObject::tr("Show version and quit.") << endl; + qout << endl; + qout.flush(); + exit(0); +} + +void printVersion() +{ + QTextStream qout(stdout); + qout << QObject::tr("Version: ") << VERSION_STRING << endl; + qout << endl; + qout.flush(); + exit(0); +} + int main(int argc, char *argv[]) { QApplication app(argc, argv); + QStringList args = app.arguments(); + app.setQuitOnLastWindowClosed(false); app.setOrganizationName("openslx"); app.setOrganizationDomain("openslx.org"); app.setApplicationName("pvsgui"); @@ -414,7 +450,16 @@ int main(int argc, char *argv[]) translator.load(":pvsgui"); app.installTranslator(&translator); + if (args.contains("-h") || args.contains("--help")) + printHelp(); + + if (args.contains("-v") || args.contains("--version")) + printVersion(); + PVSGUI pvsgui; + if (!args.contains("-n") && !args.contains("--nobar")) + pvsgui.setVisible(true); + return app.exec(); } diff --git a/src/pvsgui.h b/src/pvsgui.h index ec7c6d7..171f6bd 100644 --- a/src/pvsgui.h +++ b/src/pvsgui.h @@ -44,6 +44,7 @@ public: public Q_SLOTS: void updateConfig(); + void setVisible(bool visible); protected: void enterEvent(QEvent *e); @@ -80,6 +81,7 @@ private: ClientVNCViewer *_vncViewer; AboutDialog *_aboutDialog; + QAction *_showAction; QAction *_disconnectAction; QAction *_startChatAction; QAction *_sendFileAction; -- cgit v1.2.3-55-g7522 From da5372e49f47271f000d1f51887a93556fd0cda2 Mon Sep 17 00:00:00 2001 From: jjl Date: Thu, 23 Sep 2010 04:41:19 +0200 Subject: [PVSGUI] Only one instance should be allowed now --- 3rdparty/qtsingleapplication/CMakeLists.txt | 31 ++ 3rdparty/qtsingleapplication/QtLockedFile | 1 + 3rdparty/qtsingleapplication/QtSingleApplication | 1 + 3rdparty/qtsingleapplication/qtlocalpeer.cpp | 203 ++++++++++++ 3rdparty/qtsingleapplication/qtlocalpeer.h | 81 +++++ 3rdparty/qtsingleapplication/qtlockedfile.cpp | 199 ++++++++++++ 3rdparty/qtsingleapplication/qtlockedfile.h | 101 ++++++ 3rdparty/qtsingleapplication/qtlockedfile_unix.cpp | 121 +++++++ 3rdparty/qtsingleapplication/qtlockedfile_win.cpp | 213 +++++++++++++ .../qtsingleapplication/qtsingleapplication.cpp | 351 +++++++++++++++++++++ 3rdparty/qtsingleapplication/qtsingleapplication.h | 105 ++++++ .../qtsinglecoreapplication.cpp | 155 +++++++++ .../qtsingleapplication/qtsinglecoreapplication.h | 73 +++++ 3rdparty/qtsingleapplication/version | 1 + CMakeLists.txt | 16 +- pvs.qrc | 31 +- pvsgui.qrc | 30 -- pvsmgr.qrc | 28 -- src/pvsgui.cpp | 9 +- src/pvsgui.h | 1 + 20 files changed, 1658 insertions(+), 93 deletions(-) create mode 100644 3rdparty/qtsingleapplication/CMakeLists.txt create mode 100644 3rdparty/qtsingleapplication/QtLockedFile create mode 100644 3rdparty/qtsingleapplication/QtSingleApplication create mode 100644 3rdparty/qtsingleapplication/qtlocalpeer.cpp create mode 100644 3rdparty/qtsingleapplication/qtlocalpeer.h create mode 100644 3rdparty/qtsingleapplication/qtlockedfile.cpp create mode 100644 3rdparty/qtsingleapplication/qtlockedfile.h create mode 100644 3rdparty/qtsingleapplication/qtlockedfile_unix.cpp create mode 100644 3rdparty/qtsingleapplication/qtlockedfile_win.cpp create mode 100644 3rdparty/qtsingleapplication/qtsingleapplication.cpp create mode 100644 3rdparty/qtsingleapplication/qtsingleapplication.h create mode 100644 3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp create mode 100644 3rdparty/qtsingleapplication/qtsinglecoreapplication.h create mode 100644 3rdparty/qtsingleapplication/version (limited to 'src/pvsgui.h') diff --git a/3rdparty/qtsingleapplication/CMakeLists.txt b/3rdparty/qtsingleapplication/CMakeLists.txt new file mode 100644 index 0000000..313054e --- /dev/null +++ b/3rdparty/qtsingleapplication/CMakeLists.txt @@ -0,0 +1,31 @@ +################################################################################ +# Variables +################################################################################ + +IF(UNIX) +SET( QTSINGLEAPPLICATION_SRCS + 3rdparty/qtsingleapplication/qtlocalpeer.cpp + 3rdparty/qtsingleapplication/qtlockedfile.cpp + 3rdparty/qtsingleapplication/qtlockedfile_unix.cpp + 3rdparty/qtsingleapplication/qtsingleapplication.cpp + 3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp + PARENT_SCOPE +) +ELSEIF(WIN32) +SET( QTSINGLEAPPLICATION_SRCS + 3rdparty/qtsingleapplication/qtlocalpeer.cpp + 3rdparty/qtsingleapplication/qtlockedfile.cpp + 3rdparty/qtsingleapplication/qtlockedfile_win.cpp + 3rdparty/qtsingleapplication/qtsingleapplication.cpp + 3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp + PARENT_SCOPE +) +ENDIF(UNIX) + +SET( QTSINGLEAPPLICATION_MOC_HDRS + 3rdparty/qtsingleapplication/qtlocalpeer.h + 3rdparty/qtsingleapplication/qtlockedfile.h + 3rdparty/qtsingleapplication/qtsingleapplication.h + 3rdparty/qtsingleapplication/qtsinglecoreapplication.h + PARENT_SCOPE +) diff --git a/3rdparty/qtsingleapplication/QtLockedFile b/3rdparty/qtsingleapplication/QtLockedFile new file mode 100644 index 0000000..16b48ba --- /dev/null +++ b/3rdparty/qtsingleapplication/QtLockedFile @@ -0,0 +1 @@ +#include "qtlockedfile.h" diff --git a/3rdparty/qtsingleapplication/QtSingleApplication b/3rdparty/qtsingleapplication/QtSingleApplication new file mode 100644 index 0000000..d111bf7 --- /dev/null +++ b/3rdparty/qtsingleapplication/QtSingleApplication @@ -0,0 +1 @@ +#include "qtsingleapplication.h" diff --git a/3rdparty/qtsingleapplication/qtlocalpeer.cpp b/3rdparty/qtsingleapplication/qtlocalpeer.cpp new file mode 100644 index 0000000..f531956 --- /dev/null +++ b/3rdparty/qtsingleapplication/qtlocalpeer.cpp @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + + +#include "qtlocalpeer.h" +#include +#include + +#if defined(Q_OS_WIN) +#include +#include +typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*); +static PProcessIdToSessionId pProcessIdToSessionId = 0; +#endif +#if defined(Q_OS_UNIX) +#include +#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"; + +QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) + : QObject(parent), id(appId) +{ + QString prefix = id; + if (id.isEmpty()) { + id = QCoreApplication::applicationFilePath(); +#if defined(Q_OS_WIN) + id = id.toLower(); +#endif + prefix = id.section(QLatin1Char('/'), -1); + } + prefix.remove(QRegExp("[^a-zA-Z]")); + prefix.truncate(6); + + QByteArray idc = id.toUtf8(); + quint16 idNum = qChecksum(idc.constData(), idc.size()); + socketName = QLatin1String("qtsingleapp-") + prefix + + QLatin1Char('-') + QString::number(idNum, 16); + +#if defined(Q_OS_WIN) + if (!pProcessIdToSessionId) { + QLibrary lib("kernel32"); + pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId"); + } + if (pProcessIdToSessionId) { + DWORD sessionId = 0; + pProcessIdToSessionId(GetCurrentProcessId(), &sessionId); + socketName += QLatin1Char('-') + QString::number(sessionId, 16); + } +#else + socketName += QLatin1Char('-') + QString::number(::getuid(), 16); +#endif + + server = new QLocalServer(this); + QString lockName = QDir(QDir::tempPath()).absolutePath() + + QLatin1Char('/') + socketName + + QLatin1String("-lockfile"); + lockFile.setFileName(lockName); + lockFile.open(QIODevice::ReadWrite); +} + + + +bool QtLocalPeer::isClient() +{ + if (lockFile.isLocked()) + return false; + + if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) + return true; + + bool res = server->listen(socketName); +#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) + // ### Workaround + if (!res && server->serverError() == QAbstractSocket::AddressInUseError) { + QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName); + res = server->listen(socketName); + } +#endif + if (!res) + qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); + QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection())); + return false; +} + + +bool QtLocalPeer::sendMessage(const QString &message, int timeout) +{ + if (!isClient()) + return false; + + QLocalSocket socket; + bool connOk = false; + for(int i = 0; i < 2; i++) { + // Try twice, in case the other instance is just starting up + socket.connectToServer(socketName); + connOk = socket.waitForConnected(timeout/2); + if (connOk || i) + break; + int ms = 250; +#if defined(Q_OS_WIN) + Sleep(DWORD(ms)); +#else + struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; + nanosleep(&ts, NULL); +#endif + } + if (!connOk) + return false; + + QByteArray uMsg(message.toUtf8()); + QDataStream ds(&socket); + ds.writeBytes(uMsg.constData(), uMsg.size()); + bool res = socket.waitForBytesWritten(timeout); + res &= socket.waitForReadyRead(timeout); // wait for ack + res &= (socket.read(qstrlen(ack)) == ack); + return res; +} + + +void QtLocalPeer::receiveConnection() +{ + QLocalSocket* socket = server->nextPendingConnection(); + if (!socket) + return; + + while (socket->bytesAvailable() < (int)sizeof(quint32)) + socket->waitForReadyRead(); + QDataStream ds(socket); + QByteArray uMsg; + quint32 remaining; + ds >> remaining; + uMsg.resize(remaining); + int got = 0; + char* uMsgBuf = uMsg.data(); + do { + got = ds.readRawData(uMsgBuf, remaining); + remaining -= got; + uMsgBuf += got; + } while (remaining && got >= 0 && socket->waitForReadyRead(2000)); + if (got < 0) { + qWarning() << "QtLocalPeer: Message reception failed" << socket->errorString(); + 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) +} diff --git a/3rdparty/qtsingleapplication/qtlocalpeer.h b/3rdparty/qtsingleapplication/qtlocalpeer.h new file mode 100644 index 0000000..8a54a9b --- /dev/null +++ b/3rdparty/qtsingleapplication/qtlocalpeer.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + + +#include +#include +#include + +namespace QtLP_Private { +#include "qtlockedfile.h" +} + +class QtLocalPeer : public QObject +{ + Q_OBJECT + +public: + QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); + bool isClient(); + bool sendMessage(const QString &message, int timeout); + QString applicationId() const + { return id; } + +Q_SIGNALS: + void messageReceived(const QString &message); + +protected Q_SLOTS: + void receiveConnection(); + +protected: + QString id; + QString socketName; + QLocalServer* server; + QtLP_Private::QtLockedFile lockFile; + +private: + static const char* ack; +}; diff --git a/3rdparty/qtsingleapplication/qtlockedfile.cpp b/3rdparty/qtsingleapplication/qtlockedfile.cpp new file mode 100644 index 0000000..2cf0805 --- /dev/null +++ b/3rdparty/qtsingleapplication/qtlockedfile.cpp @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + +#include "qtlockedfile.h" + +/*! + \class QtLockedFile + + \brief The QtLockedFile class extends QFile with advisory locking + functions. + + A file may be locked in read or write mode. Multiple instances of + \e QtLockedFile, created in multiple processes running on the same + machine, may have a file locked in read mode. Exactly one instance + may have it locked in write mode. A read and a write lock cannot + exist simultaneously on the same file. + + The file locks are advisory. This means that nothing prevents + another process from manipulating a locked file using QFile or + file system functions offered by the OS. Serialization is only + guaranteed if all processes that access the file use + QLockedFile. Also, while holding a lock on a file, a process + must not open the same file again (through any API), or locks + can be unexpectedly lost. + + The lock provided by an instance of \e QtLockedFile is released + whenever the program terminates. This is true even when the + program crashes and no destructors are called. +*/ + +/*! \enum QtLockedFile::LockMode + + This enum describes the available lock modes. + + \value ReadLock A read lock. + \value WriteLock A write lock. + \value NoLock Neither a read lock nor a write lock. +*/ + +/*! + Constructs an unlocked \e QtLockedFile object. This constructor + behaves in the same way as \e QFile::QFile(). + + \sa QFile::QFile() +*/ +QtLockedFile::QtLockedFile() + : QFile() +{ +#ifdef Q_OS_WIN + wmutex = 0; + rmutex = 0; +#endif + m_lock_mode = NoLock; +} + +/*! + Constructs an unlocked QtLockedFile object with file \a name. This + constructor behaves in the same way as \e QFile::QFile(const + QString&). + + \sa QFile::QFile() +*/ +QtLockedFile::QtLockedFile(const QString &name) + : QFile(name) +{ +#ifdef Q_OS_WIN + wmutex = 0; + rmutex = 0; +#endif + m_lock_mode = NoLock; +} + +/*! + Opens the file in OpenMode \a mode. + + This is identical to QFile::open(), with the one exception that the + Truncate mode flag is disallowed. Truncation would conflict with the + advisory file locking, since the file would be modified before the + write lock is obtained. If truncation is required, use resize(0) + after obtaining the write lock. + + Returns true if successful; otherwise false. + + \sa QFile::open(), QFile::resize() +*/ +bool QtLockedFile::open(OpenMode mode) +{ + if (mode & QIODevice::Truncate) { + qWarning("QtLockedFile::open(): Truncate mode not allowed."); + return false; + } + return QFile::open(mode); +} + +/*! + Returns \e true if this object has a in read or write lock; + otherwise returns \e false. + + \sa lockMode() +*/ +bool QtLockedFile::isLocked() const +{ + return m_lock_mode != NoLock; +} + +/*! + Returns the type of lock currently held by this object, or \e + QtLockedFile::NoLock. + + \sa isLocked() +*/ +QtLockedFile::LockMode QtLockedFile::lockMode() const +{ + return m_lock_mode; +} + +/*! + \fn bool QtLockedFile::lock(LockMode mode, bool block = true) + + Obtains a lock of type \a mode. The file must be opened before it + can be locked. + + If \a block is true, this function will block until the lock is + aquired. If \a block is false, this function returns \e false + immediately if the lock cannot be aquired. + + If this object already has a lock of type \a mode, this function + returns \e true immediately. If this object has a lock of a + different type than \a mode, the lock is first released and then a + new lock is obtained. + + This function returns \e true if, after it executes, the file is + locked by this object, and \e false otherwise. + + \sa unlock(), isLocked(), lockMode() +*/ + +/*! + \fn bool QtLockedFile::unlock() + + Releases a lock. + + If the object has no lock, this function returns immediately. + + This function returns \e true if, after it executes, the file is + not locked by this object, and \e false otherwise. + + \sa lock(), isLocked(), lockMode() +*/ + +/*! + \fn QtLockedFile::~QtLockedFile() + + Destroys the \e QtLockedFile object. If any locks were held, they + are released. +*/ diff --git a/3rdparty/qtsingleapplication/qtlockedfile.h b/3rdparty/qtsingleapplication/qtlockedfile.h new file mode 100644 index 0000000..1d3b918 --- /dev/null +++ b/3rdparty/qtsingleapplication/qtlockedfile.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + +#ifndef QTLOCKEDFILE_H +#define QTLOCKEDFILE_H + +#include +#ifdef Q_OS_WIN +#include +#endif + +#if defined(Q_WS_WIN) +# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT) +# define QT_QTLOCKEDFILE_EXPORT +# elif defined(QT_QTLOCKEDFILE_IMPORT) +# if defined(QT_QTLOCKEDFILE_EXPORT) +# undef QT_QTLOCKEDFILE_EXPORT +# endif +# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport) +# elif defined(QT_QTLOCKEDFILE_EXPORT) +# undef QT_QTLOCKEDFILE_EXPORT +# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport) +# endif +#else +# define QT_QTLOCKEDFILE_EXPORT +#endif + +class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile +{ +public: + enum LockMode { NoLock = 0, ReadLock, WriteLock }; + + QtLockedFile(); + QtLockedFile(const QString &name); + ~QtLockedFile(); + + bool open(OpenMode mode); + + bool lock(LockMode mode, bool block = true); + bool unlock(); + bool isLocked() const; + LockMode lockMode() const; + +private: +#ifdef Q_OS_WIN + Qt::HANDLE wmutex; + Qt::HANDLE rmutex; + QVector rmutexes; + QString mutexname; + + Qt::HANDLE getMutexHandle(int idx, bool doCreate); + bool waitMutex(Qt::HANDLE mutex, bool doBlock); + +#endif + LockMode m_lock_mode; +}; + +#endif diff --git a/3rdparty/qtsingleapplication/qtlockedfile_unix.cpp b/3rdparty/qtsingleapplication/qtlockedfile_unix.cpp new file mode 100644 index 0000000..2881bdd --- /dev/null +++ b/3rdparty/qtsingleapplication/qtlockedfile_unix.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + +#include +#include +#include +#include + +#include "qtlockedfile.h" + +bool QtLockedFile::lock(LockMode mode, bool block) +{ + if (!isOpen()) { + qWarning("QtLockedFile::lock(): file is not opened"); + return false; + } + + if (mode == NoLock) + return unlock(); + + if (mode == m_lock_mode) + return true; + + if (m_lock_mode != NoLock) + unlock(); + + struct flock fl; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; + int cmd = block ? F_SETLKW : F_SETLK; + int ret = fcntl(handle(), cmd, &fl); + + if (ret == -1) { + if (errno != EINTR && errno != EAGAIN) + qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); + return false; + } + + + m_lock_mode = mode; + return true; +} + + +bool QtLockedFile::unlock() +{ + if (!isOpen()) { + qWarning("QtLockedFile::unlock(): file is not opened"); + return false; + } + + if (!isLocked()) + return true; + + struct flock fl; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + fl.l_type = F_UNLCK; + int ret = fcntl(handle(), F_SETLKW, &fl); + + if (ret == -1) { + qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); + return false; + } + + m_lock_mode = NoLock; + return true; +} + +QtLockedFile::~QtLockedFile() +{ + if (isOpen()) + unlock(); +} + diff --git a/3rdparty/qtsingleapplication/qtlockedfile_win.cpp b/3rdparty/qtsingleapplication/qtlockedfile_win.cpp new file mode 100644 index 0000000..d4bf9e1 --- /dev/null +++ b/3rdparty/qtsingleapplication/qtlockedfile_win.cpp @@ -0,0 +1,213 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + +#include "qtlockedfile.h" +#include +#include + +#define MUTEX_PREFIX "QtLockedFile mutex " +// Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS +#define MAX_READERS MAXIMUM_WAIT_OBJECTS + +Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) +{ + if (mutexname.isEmpty()) { + QFileInfo fi(*this); + mutexname = QString::fromLatin1(MUTEX_PREFIX) + + fi.absoluteFilePath().toLower(); + } + QString mname(mutexname); + if (idx >= 0) + mname += QString::number(idx); + + Qt::HANDLE mutex; + if (doCreate) { + QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, + { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } ); + if (!mutex) { + qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); + return 0; + } + } + else { + QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, + { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } ); + if (!mutex) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) + qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); + return 0; + } + } + return mutex; +} + +bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock) +{ + Q_ASSERT(mutex); + DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0); + switch (res) { + case WAIT_OBJECT_0: + case WAIT_ABANDONED: + return true; + break; + case WAIT_TIMEOUT: + break; + default: + qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed"); + } + return false; +} + + + +bool QtLockedFile::lock(LockMode mode, bool block) +{ + if (!isOpen()) { + qWarning("QtLockedFile::lock(): file is not opened"); + return false; + } + + if (mode == NoLock) + return unlock(); + + if (mode == m_lock_mode) + return true; + + if (m_lock_mode != NoLock) + unlock(); + + if (!wmutex && !(wmutex = getMutexHandle(-1, true))) + return false; + + if (!waitMutex(wmutex, block)) + return false; + + if (mode == ReadLock) { + int idx = 0; + for (; idx < MAX_READERS; idx++) { + rmutex = getMutexHandle(idx, false); + if (!rmutex || waitMutex(rmutex, false)) + break; + CloseHandle(rmutex); + } + bool ok = true; + if (idx >= MAX_READERS) { + qWarning("QtLockedFile::lock(): too many readers"); + rmutex = 0; + ok = false; + } + else if (!rmutex) { + rmutex = getMutexHandle(idx, true); + if (!rmutex || !waitMutex(rmutex, false)) + ok = false; + } + if (!ok && rmutex) { + CloseHandle(rmutex); + rmutex = 0; + } + ReleaseMutex(wmutex); + if (!ok) + return false; + } + else { + Q_ASSERT(rmutexes.isEmpty()); + for (int i = 0; i < MAX_READERS; i++) { + Qt::HANDLE mutex = getMutexHandle(i, false); + if (mutex) + rmutexes.append(mutex); + } + if (rmutexes.size()) { + DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(), + TRUE, block ? INFINITE : 0); + if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) { + if (res != WAIT_TIMEOUT) + qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed"); + m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky + unlock(); + return false; + } + } + } + + m_lock_mode = mode; + return true; +} + +bool QtLockedFile::unlock() +{ + if (!isOpen()) { + qWarning("QtLockedFile::unlock(): file is not opened"); + return false; + } + + if (!isLocked()) + return true; + + if (m_lock_mode == ReadLock) { + ReleaseMutex(rmutex); + CloseHandle(rmutex); + rmutex = 0; + } + else { + foreach(Qt::HANDLE mutex, rmutexes) { + ReleaseMutex(mutex); + CloseHandle(mutex); + } + rmutexes.clear(); + ReleaseMutex(wmutex); + } + + m_lock_mode = QtLockedFile::NoLock; + return true; +} + +QtLockedFile::~QtLockedFile() +{ + if (isOpen()) + unlock(); + if (wmutex) + CloseHandle(wmutex); +} diff --git a/3rdparty/qtsingleapplication/qtsingleapplication.cpp b/3rdparty/qtsingleapplication/qtsingleapplication.cpp new file mode 100644 index 0000000..a3a1fd7 --- /dev/null +++ b/3rdparty/qtsingleapplication/qtsingleapplication.cpp @@ -0,0 +1,351 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + + +#include "qtsingleapplication.h" +#include "qtlocalpeer.h" +#include + + +/*! + \class QtSingleApplication qtsingleapplication.h + \brief The QtSingleApplication class provides an API to detect and + communicate with running instances of an application. + + This class allows you to create applications where only one + instance should be running at a time. I.e., if the user tries to + launch another instance, the already running instance will be + activated instead. Another usecase is a client-server system, + where the first started instance will assume the role of server, + and the later instances will act as clients of that server. + + By default, the full path of the executable file is used to + determine whether two processes are instances of the same + application. You can also provide an explicit identifier string + that will be compared instead. + + The application should create the QtSingleApplication object early + in the startup phase, and call isRunning() or sendMessage() to + find out if another instance of this application is already + running. Startup parameters (e.g. the name of the file the user + wanted this new instance to open) can be passed to the running + instance in the sendMessage() function. + + If isRunning() or sendMessage() returns false, it means that no + other instance is running, and this instance has assumed the role + as the running instance. The application should continue with the + initialization of the application user interface before entering + the event loop with exec(), as normal. The messageReceived() + signal will be emitted when the application receives messages from + another instance of the same application. + + If isRunning() or sendMessage() returns true, another instance is + already running, and the application should terminate or enter + client mode. + + If a message is received it might be helpful to the user to raise + the application so that it becomes visible. To facilitate this, + QtSingleApplication provides the setActivationWindow() function + and the activateWindow() slot. + + Here's an example that shows how to convert an existing + application to use QtSingleApplication. It is very simple and does + not make use of all QtSingleApplication's functionality (see the + examples for that). + + \code + // Original + int main(int argc, char **argv) + { + QApplication app(argc, argv); + + MyMainWidget mmw; + + mmw.show(); + return app.exec(); + } + + // Single instance + int main(int argc, char **argv) + { + QtSingleApplication app(argc, argv); + + if (app.isRunning()) + return 0; + + MyMainWidget mmw; + + app.setActivationWindow(&mmw); + + mmw.show(); + return app.exec(); + } + \endcode + + Once this QtSingleApplication instance is destroyed(for example, + when the user quits), when the user next attempts to run the + application this instance will not, of course, be encountered. The + next instance to call isRunning() or sendMessage() will assume the + role as the new running instance. + + For console (non-GUI) applications, QtSingleCoreApplication may be + used instead of this class, to avoid the dependency on the QtGui + library. + + \sa QtSingleCoreApplication +*/ + + +void QtSingleApplication::sysInit(const QString &appId) +{ + actWin = 0; + peer = new QtLocalPeer(this, appId); + connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); +} + + +/*! + Creates a QtSingleApplication object. The application identifier + will be QCoreApplication::applicationFilePath(). \a argc, \a + argv, and \a GUIenabled are passed on to the QAppliation constructor. + + If you are creating a console application (i.e. setting \a + GUIenabled to false), you may consider using + QtSingleCoreApplication instead. +*/ + +QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled) + : QApplication(argc, argv, GUIenabled) +{ + sysInit(); +} + + +/*! + Creates a QtSingleApplication object with the application + identifier \a appId. \a argc and \a argv are passed on to the + QAppliation constructor. +*/ + +QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv) + : QApplication(argc, argv) +{ + sysInit(appId); +} + + +/*! + Creates a QtSingleApplication object. The application identifier + will be QCoreApplication::applicationFilePath(). \a argc, \a + argv, and \a type are passed on to the QAppliation constructor. +*/ +QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) + : QApplication(argc, argv, type) +{ + sysInit(); +} + + +#if defined(Q_WS_X11) +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be QCoreApplication::applicationFilePath(). \a dpy, \a visual, + and \a cmap are passed on to the QApplication constructor. +*/ +QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, visual, cmap) +{ + sysInit(); +} + +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a + argv, \a visual, and \a cmap are passed on to the QApplication + constructor. +*/ +QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, argc, argv, visual, cmap) +{ + sysInit(); +} + +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be \a appId. \a dpy, \a argc, \a + argv, \a visual, and \a cmap are passed on to the QApplication + constructor. +*/ +QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, argc, argv, visual, cmap) +{ + sysInit(appId); +} +#endif + + +/*! + Returns true if another instance of this application is running; + otherwise false. + + This function does not find instances of this application that are + being run by a different user (on Windows: that are running in + another session). + + \sa sendMessage() +*/ + +bool QtSingleApplication::isRunning() +{ + return peer->isClient(); +} + + +/*! + Tries to send the text \a message to the currently running + instance. The QtSingleApplication object in the running instance + will emit the messageReceived() signal when it receives the + message. + + This function returns true if the message has been sent to, and + processed by, the current instance. If there is no instance + currently running, or if the running instance fails to process the + message within \a timeout milliseconds, this function return false. + + \sa isRunning(), messageReceived() +*/ +bool QtSingleApplication::sendMessage(const QString &message, int timeout) +{ + return peer->sendMessage(message, timeout); +} + + +/*! + Returns the application identifier. Two processes with the same + identifier will be regarded as instances of the same application. +*/ +QString QtSingleApplication::id() const +{ + return peer->applicationId(); +} + + +/*! + Sets the activation window of this application to \a aw. The + activation window is the widget that will be activated by + activateWindow(). This is typically the application's main window. + + If \a activateOnMessage is true (the default), the window will be + activated automatically every time a message is received, just prior + to the messageReceived() signal being emitted. + + \sa activateWindow(), messageReceived() +*/ + +void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) +{ + actWin = aw; + if (activateOnMessage) + connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); + else + disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); +} + + +/*! + Returns the applications activation window if one has been set by + calling setActivationWindow(), otherwise returns 0. + + \sa setActivationWindow() +*/ +QWidget* QtSingleApplication::activationWindow() const +{ + return actWin; +} + + +/*! + De-minimizes, raises, and activates this application's activation window. + This function does nothing if no activation window has been set. + + This is a convenience function to show the user that this + application instance has been activated when he has tried to start + another instance. + + This function should typically be called in response to the + messageReceived() signal. By default, that will happen + automatically, if an activation window has been set. + + \sa setActivationWindow(), messageReceived(), initialize() +*/ +void QtSingleApplication::activateWindow() +{ + if (actWin) { + actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized); + actWin->raise(); + actWin->activateWindow(); + } +} + + +/*! + \fn void QtSingleApplication::messageReceived(const QString& message) + + This signal is emitted when the current instance receives a \a + message from another instance of this application. + + \sa sendMessage(), setActivationWindow(), activateWindow() +*/ + + +/*! + \fn void QtSingleApplication::initialize(bool dummy = true) + + \obsolete +*/ diff --git a/3rdparty/qtsingleapplication/qtsingleapplication.h b/3rdparty/qtsingleapplication/qtsingleapplication.h new file mode 100644 index 0000000..5df9165 --- /dev/null +++ b/3rdparty/qtsingleapplication/qtsingleapplication.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + + +#include + +class QtLocalPeer; + +#if defined(Q_WS_WIN) +# if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) +# define QT_QTSINGLEAPPLICATION_EXPORT +# elif defined(QT_QTSINGLEAPPLICATION_IMPORT) +# if defined(QT_QTSINGLEAPPLICATION_EXPORT) +# undef QT_QTSINGLEAPPLICATION_EXPORT +# endif +# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport) +# elif defined(QT_QTSINGLEAPPLICATION_EXPORT) +# undef QT_QTSINGLEAPPLICATION_EXPORT +# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport) +# endif +#else +# define QT_QTSINGLEAPPLICATION_EXPORT +#endif + +class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication +{ + Q_OBJECT + +public: + QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); + QtSingleApplication(const QString &id, int &argc, char **argv); + QtSingleApplication(int &argc, char **argv, Type type); +#if defined(Q_WS_X11) + QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); + QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); + QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); +#endif + + bool isRunning(); + QString id() const; + + void setActivationWindow(QWidget* aw, bool activateOnMessage = true); + QWidget* activationWindow() const; + + // Obsolete: + void initialize(bool dummy = true) + { isRunning(); Q_UNUSED(dummy) } + +public Q_SLOTS: + bool sendMessage(const QString &message, int timeout = 5000); + void activateWindow(); + + +Q_SIGNALS: + void messageReceived(const QString &message); + + +private: + void sysInit(const QString &appId = QString()); + QtLocalPeer *peer; + QWidget *actWin; +}; diff --git a/3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp b/3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp new file mode 100644 index 0000000..307e255 --- /dev/null +++ b/3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + + +#include "qtsinglecoreapplication.h" +#include "qtlocalpeer.h" + +/*! + \class QtSingleCoreApplication qtsinglecoreapplication.h + \brief A variant of the QtSingleApplication class for non-GUI applications. + + This class is a variant of QtSingleApplication suited for use in + console (non-GUI) applications. It is an extension of + QCoreApplication (instead of QApplication). It does not require + the QtGui library. + + The API and usage is identical to QtSingleApplication, except that + functions relating to the "activation window" are not present, for + obvious reasons. Please refer to the QtSingleApplication + documentation for explanation of the usage. + + A QtSingleCoreApplication instance can communicate to a + QtSingleApplication instance if they share the same application + id. Hence, this class can be used to create a light-weight + command-line tool that sends commands to a GUI application. + + \sa QtSingleApplication +*/ + +/*! + Creates a QtSingleCoreApplication object. The application identifier + will be QCoreApplication::applicationFilePath(). \a argc and \a + argv are passed on to the QCoreAppliation constructor. +*/ + +QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv) + : QCoreApplication(argc, argv) +{ + peer = new QtLocalPeer(this); + connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); +} + + +/*! + Creates a QtSingleCoreApplication object with the application + identifier \a appId. \a argc and \a argv are passed on to the + QCoreAppliation constructor. +*/ +QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv) + : QCoreApplication(argc, argv) +{ + peer = new QtLocalPeer(this, appId); + connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); +} + + +/*! + Returns true if another instance of this application is running; + otherwise false. + + This function does not find instances of this application that are + being run by a different user (on Windows: that are running in + another session). + + \sa sendMessage() +*/ + +bool QtSingleCoreApplication::isRunning() +{ + return peer->isClient(); +} + + +/*! + Tries to send the text \a message to the currently running + instance. The QtSingleCoreApplication object in the running instance + will emit the messageReceived() signal when it receives the + message. + + This function returns true if the message has been sent to, and + processed by, the current instance. If there is no instance + currently running, or if the running instance fails to process the + message within \a timeout milliseconds, this function return false. + + \sa isRunning(), messageReceived() +*/ + +bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout) +{ + return peer->sendMessage(message, timeout); +} + + +/*! + Returns the application identifier. Two processes with the same + identifier will be regarded as instances of the same application. +*/ + +QString QtSingleCoreApplication::id() const +{ + return peer->applicationId(); +} + + +/*! + \fn void QtSingleCoreApplication::messageReceived(const QString& message) + + This signal is emitted when the current instance receives a \a + message from another instance of this application. + + \sa sendMessage() +*/ diff --git a/3rdparty/qtsingleapplication/qtsinglecoreapplication.h b/3rdparty/qtsingleapplication/qtsinglecoreapplication.h new file mode 100644 index 0000000..8e2fda6 --- /dev/null +++ b/3rdparty/qtsingleapplication/qtsinglecoreapplication.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of a Qt Solutions component. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Solutions Commercial License Agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** Please note Third Party Software included with Qt Solutions may impose +** additional restrictions and it is the user's responsibility to ensure +** that they have met the licensing requirements of the GPL, LGPL, or Qt +** Solutions Commercial license and the relevant license of the Third +** Party Software they are using. +** +** If you are unsure which license is appropriate for your use, please +** contact Nokia at qt-info@nokia.com. +** +****************************************************************************/ + + +#include + +class QtLocalPeer; + +class QtSingleCoreApplication : public QCoreApplication +{ + Q_OBJECT + +public: + QtSingleCoreApplication(int &argc, char **argv); + QtSingleCoreApplication(const QString &id, int &argc, char **argv); + + bool isRunning(); + QString id() const; + +public Q_SLOTS: + bool sendMessage(const QString &message, int timeout = 5000); + + +Q_SIGNALS: + void messageReceived(const QString &message); + + +private: + QtLocalPeer* peer; +}; diff --git a/3rdparty/qtsingleapplication/version b/3rdparty/qtsingleapplication/version new file mode 100644 index 0000000..0ff835c --- /dev/null +++ b/3rdparty/qtsingleapplication/version @@ -0,0 +1 @@ +2.6_1-opensource \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index f53422e..61574cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,12 @@ ELSEIF(UNIX) SET(sysdep_suffix _X11) ENDIF(WIN32) +################################################################################ +# Build third-party libraries +################################################################################ +ADD_SUBDIRECTORY(3rdparty/qtsingleapplication) + + ################################################################################ # Variables ################################################################################ @@ -92,6 +98,7 @@ SET( PVS_SRCS # pvsgui SET( PVSGUI_SRCS + ${QTSINGLEAPPLICATION_SRCS} src/pvsgui.cpp src/gui/clientConfigDialog.cpp src/gui/clientFileSendDialog.cpp @@ -184,6 +191,7 @@ SET( PVS_MOC_HDRS ) SET( PVSGUI_MOC_HDRS + ${QTSINGLEAPPLICATION_MOC_HDRS} src/pvsgui.h src/gui/clientConfigDialog.h src/gui/clientFileSendDialog.h @@ -256,9 +264,9 @@ QT4_ADD_DBUS_ADAPTOR( PVS_SRCS ${CMAKE_BINARY_DIR}/org.openslx.pvs.xml src/pvs.h QT4_ADD_DBUS_INTERFACE( PVSGUI_SRCS ${CMAKE_BINARY_DIR}/org.openslx.pvs.xml pvsinterface ) # i18n, run lupdate and lrelease) -QT4_CREATE_TRANSLATION( PVSMGR_QMS ${PVSMGR_SRCS} ${PVSMGR_UI_HDRS} ${PVSMGR_TSS} ) -QT4_CREATE_TRANSLATION( PVS_QMS ${PVS_SRCS} ${PVS_TSS} ) -QT4_CREATE_TRANSLATION( PVSGUI_QMS ${PVSGUI_SRCS} ${PVSGUI_UI_HDRS} ${PVSGUI_TSS} ) +#QT4_CREATE_TRANSLATION( PVSMGR_QMS ${PVSMGR_SRCS} ${PVSMGR_UI_HDRS} ${PVSMGR_TSS} ) +#QT4_CREATE_TRANSLATION( PVS_QMS ${PVS_SRCS} ${PVS_TSS} ) +#QT4_CREATE_TRANSLATION( PVSGUI_QMS ${PVSGUI_SRCS} ${PVSGUI_UI_HDRS} ${PVSGUI_TSS} ) ################################################################################ # Build @@ -283,7 +291,7 @@ ADD_EXECUTABLE( pvsmgrtouch ) ENDIF(UNIX) -ADD_EXECUTABLE( pvs +ADD_EXECUTABLE( pvs ${PVS_SRCS} ${PVS_MOC_SRCS} ${PVS_RC_SRCS} diff --git a/pvs.qrc b/pvs.qrc index 039be52..63d37d1 100644 --- a/pvs.qrc +++ b/pvs.qrc @@ -1,32 +1,3 @@ - - build/pvs_de_DE.qm - - - build/pvs_de_DE.qm - - - build/pvs_fr_FR.qm - - - build/pvs_fr_FR.qm - - - build/pvs_es_MX.qm - - - build/pvs_es_MX.qm - - - build/pvs_ar_JO.qm - - - build/pvs_ar_JO.qm - - - build/pvs_pl_PL.qm - - - build/pvs_pl_PL.qm - + diff --git a/pvsgui.qrc b/pvsgui.qrc index e8f76e5..31e7e50 100644 --- a/pvsgui.qrc +++ b/pvsgui.qrc @@ -10,34 +10,4 @@ AUTHORS TRANSLATION - - build/pvsgui_de_DE.qm - - - build/pvsgui_de_DE.qm - - - build/pvsgui_fr_FR.qm - - - build/pvsgui_fr_FR.qm - - - build/pvsgui_es_MX.qm - - - build/pvsgui_es_MX.qm - - - build/pvsgui_ar_JO.qm - - - build/pvsgui_ar_JO.qm - - - build/pvsgui_pl_PL.qm - - - build/pvsgui_pl_PL.qm - diff --git a/pvsmgr.qrc b/pvsmgr.qrc index b917ca3..683ef89 100644 --- a/pvsmgr.qrc +++ b/pvsmgr.qrc @@ -27,33 +27,5 @@ icons/unprojection.png icons/unlocksingle.png icons/locksingle.png - build/pvsmgr_de_DE.qm - - - build/pvsmgr_de_DE.qm - - - build/pvsmgr_fr_FR.qm - - - build/pvsmgr_fr_FR.qm - - - build/pvsmgr_es_MX.qm - - - build/pvsmgr_es_MX.qm - - - build/pvsmgr_ar_JO.qm - - - build/pvsmgr_ar_JO.qm - - - build/pvsmgr_pl_PL.qm - - - build/pvsmgr_pl_PL.qm diff --git a/src/pvsgui.cpp b/src/pvsgui.cpp index c2ac3cb..5b11104 100644 --- a/src/pvsgui.cpp +++ b/src/pvsgui.cpp @@ -438,13 +438,20 @@ void printVersion() int main(int argc, char *argv[]) { - QApplication app(argc, argv); + QtSingleApplication app(argc, argv); QStringList args = app.arguments(); app.setQuitOnLastWindowClosed(false); app.setOrganizationName("openslx"); app.setOrganizationDomain("openslx.org"); app.setApplicationName("pvsgui"); + // only one instance should be allowed + if (app.sendMessage("")) + { + qDebug("[PVSGUI] ERROR: Already running. Exiting"); + return 0; + } + // use system locale as language to translate gui QTranslator translator; translator.load(":pvsgui"); diff --git a/src/pvsgui.h b/src/pvsgui.h index 171f6bd..bab340a 100644 --- a/src/pvsgui.h +++ b/src/pvsgui.h @@ -16,6 +16,7 @@ #include #include +#include "3rdparty/qtsingleapplication/qtsingleapplication.h" #include "ui_clientToolbar.h" #include "src/gui/clientConfigDialog.h" #include "src/gui/clientChatDialog.h" -- cgit v1.2.3-55-g7522 From 1e1b61682158b8925a17e0a22ad18b51abde24c6 Mon Sep 17 00:00:00 2001 From: jjl Date: Wed, 29 Sep 2010 19:43:30 +0200 Subject: [PVSGUI] set toolbar position via cmd-switch --- src/pvsgui.cpp | 137 +++++++++++++++++++++++++++++++++++---------------------- src/pvsgui.h | 6 +-- src/version.h | 4 +- 3 files changed, 89 insertions(+), 58 deletions(-) (limited to 'src/pvsgui.h') diff --git a/src/pvsgui.cpp b/src/pvsgui.cpp index 30ba4ed..0ed0801 100644 --- a/src/pvsgui.cpp +++ b/src/pvsgui.cpp @@ -17,6 +17,7 @@ # ----------------------------------------------------------------------------- */ +#include #include "pvsgui.h" #include "version.h" @@ -122,8 +123,6 @@ PVSGUI::PVSGUI(QWidget *parent) : // show toolbar setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); setAttribute(Qt::WA_AlwaysShowToolTips); - updateConfig(); - hide(); } PVSGUI::~PVSGUI() @@ -137,9 +136,9 @@ PVSGUI::~PVSGUI() void PVSGUI::updateConfig() { if (_settings.value("Display/location").isNull()) - setLocation(POSITION_TOP_CENTER); + setPosition(POSITION_TOP_CENTER); else - setLocation(_settings.value("Display/location").toInt()); + setPosition(_settings.value("Display/location").toInt()); } @@ -149,6 +148,42 @@ void PVSGUI::setVisible(bool visible) _showAction->setChecked(isVisible()); } +void PVSGUI::setPosition(int position) +{ + _position = position; + switch (_position) + { + case POSITION_TOP_LEFT: + move(0, 0); + break; + case POSITION_TOP_CENTER: + move((QApplication::desktop()->width() - width()) / 2, 0); + break; + case POSITION_TOP_RIGHT: + move(QApplication::desktop()->width() - width(), 0); + break; + case POSITION_BOTTOM_LEFT: + move(0, QApplication::desktop()->height() - height()); + break; + case POSITION_BOTTOM_CENTER: + move((QApplication::desktop()->width() - width()) / 2, + QApplication::desktop()->height() - height()); + break; + case POSITION_BOTTOM_RIGHT: + move(QApplication::desktop()->width() - width(), + QApplication::desktop()->height() - height()); + break; + default: + updateConfig(); + } +} + +void PVSGUI::hide() +{ + if (!_menu->isVisible() && !_hostMenu->isVisible()) + hide(true); +} + //////////////////////////////////////////////////////////////////////////////// // Protected @@ -219,60 +254,24 @@ void PVSGUI::setupMenu() hostButton->setMenu(_hostMenu); } -void PVSGUI::setLocation(int location) -{ - _location = location; - switch (_location) - { - case POSITION_TOP_LEFT: - move(0, 0); - break; - case POSITION_TOP_CENTER: - move((QApplication::desktop()->width() - width()) / 2, 0); - break; - case POSITION_TOP_RIGHT: - move(QApplication::desktop()->width() - width(), 0); - break; - case POSITION_BOTTOM_LEFT: - move(0, QApplication::desktop()->height() - height()); - break; - case POSITION_BOTTOM_CENTER: - move((QApplication::desktop()->width() - width()) / 2, - QApplication::desktop()->height() - height()); - break; - case POSITION_BOTTOM_RIGHT: - move(QApplication::desktop()->width() - width(), - QApplication::desktop()->height() - height()); - break; - default: - break; - } -} - void PVSGUI::hide(bool b) { if (b) { - if (_location <= POSITION_TOP_RIGHT) + if (_position <= POSITION_TOP_RIGHT) move(x(), 2 - height()); else move(x(), QApplication::desktop()->height() - 2); } else { - if (_location <= POSITION_TOP_RIGHT) + if (_position <= POSITION_TOP_RIGHT) move(x(), 0); else move(x(), QApplication::desktop()->height() - height()); } } -void PVSGUI::hide() -{ - if (!_menu->isVisible() && !_hostMenu->isVisible()) - hide(true); -} - void PVSGUI::pvsConnect(QAction *action) { QString host = action->text(); @@ -424,9 +423,10 @@ void printHelp() qout << QObject::tr("Usage: pvsgui [OPTIONS]...") << endl; qout << QObject::tr("Start the Pool Video Switch GUI.") << endl; qout << QObject::tr("Options:") << endl << endl; - qout << "-n or --nobar" << "\t" << QObject::tr("Start only with systray icon.") << endl; - qout << "-h or --help" << "\t" << QObject::tr("Show this help text and quit.") << endl; - qout << "-v or --version" << "\t" << QObject::tr("Show version and quit.") << endl; + qout << "-b or --toolbar" << "\t\t" << QObject::tr("Start with toolbar.") << endl; + qout << "-p or --position" << "\t" << QObject::tr("Set toolbar position (0-5)") << endl; + qout << "-h or --help" << "\t\t" << QObject::tr("Show this help text and quit.") << endl; + qout << "-v or --version" << "\t\t" << QObject::tr("Show version and quit.") << endl; qout << endl; qout.flush(); exit(0); @@ -444,7 +444,6 @@ void printVersion() int main(int argc, char *argv[]) { QtSingleApplication app(argc, argv); - QStringList args = app.arguments(); app.setQuitOnLastWindowClosed(false); app.setOrganizationName("openslx"); app.setOrganizationDomain("openslx.org"); @@ -462,16 +461,48 @@ int main(int argc, char *argv[]) translator.load(":pvsgui"); app.installTranslator(&translator); - if (args.contains("-h") || args.contains("--help")) - printHelp(); + bool visible = false; + int position = -1; - if (args.contains("-v") || args.contains("--version")) - printVersion(); + // parse command line arguments + int opt = 0; + int longIndex = 0; + static const char *optString = "hvp:b?"; + static const struct option longOpts[] = + { + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, + { "position", required_argument, NULL, 'p' }, + { "toolbar", required_argument, NULL, 'b' } + }; + + opt = getopt_long( argc, argv, optString, longOpts, &longIndex ); + while( opt != -1 ) + { + switch( opt ) + { + case 'h': + printHelp(); + break; + case 'v': + printVersion(); + break; + case 'p': + position = atoi(optarg); + break; + case 'b': + visible = true; + break; + case '?': + exit(1); + } + opt = getopt_long( argc, argv, optString, longOpts, &longIndex ); + } PVSGUI pvsgui; - - if (!args.contains("-n") && !args.contains("--nobar")) - pvsgui.setVisible(true); + pvsgui.setPosition(position); + pvsgui.setVisible(visible); + pvsgui.hide(); return app.exec(); } diff --git a/src/pvsgui.h b/src/pvsgui.h index bab340a..85a129b 100644 --- a/src/pvsgui.h +++ b/src/pvsgui.h @@ -46,6 +46,8 @@ public: public Q_SLOTS: void updateConfig(); void setVisible(bool visible); + void setPosition(int position); + void hide(); protected: void enterEvent(QEvent *e); @@ -56,7 +58,6 @@ protected: private Q_SLOTS: void showMessage(QString title, QString msg, bool useDialog = false); - void hide(); void connected(QString host); void disconnected(); void addHost(QString host); @@ -68,7 +69,6 @@ private Q_SLOTS: private: void setupMenu(); - void setLocation(int location); void hide(bool b); QMenu *_menu; @@ -91,7 +91,7 @@ private: QAction *_aboutAction; QAction *_quitAction; - int _location; + int _position; QPoint _clickPoint; QString _passwd; diff --git a/src/version.h b/src/version.h index 9f1450d..d05a693 100644 --- a/src/version.h +++ b/src/version.h @@ -1,2 +1,2 @@ -#define VERSION_STRING "2.0.3" -#define VERSION_NUMBER 203 +#define VERSION_STRING "2.0.4" +#define VERSION_NUMBER 204 -- cgit v1.2.3-55-g7522