summaryrefslogtreecommitdiffstats
path: root/src/pvsgui.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-10-05 22:57:48 +0200
committerSebastien Braun2010-10-05 22:57:48 +0200
commit0cb19c0a597bfb7a6cac416fb5c0b0a89043081e (patch)
tree1c076c798ae6ce960bccde2e0aea675143d961d8 /src/pvsgui.cpp
parentFix SIGSEGV-generating lookup bug when incoming multicast transfers are retried (diff)
parent[PVSGUI] parsing cmdargs fixed (diff)
downloadpvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.tar.gz
pvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.tar.xz
pvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.zip
Merge remote branch 'openslx/master' into mcastft
Conflicts: CMakeLists.txt pvsmgr.qrc src/gui/clientConfigDialog.cpp src/gui/mainWindow.cpp src/gui/ui/mainwindow.ui src/gui/ui/mainwindowtouch.ui src/pvs.cpp src/pvs.h src/pvsDaemon.cpp src/pvsgui.cpp
Diffstat (limited to 'src/pvsgui.cpp')
-rw-r--r--src/pvsgui.cpp263
1 files changed, 162 insertions, 101 deletions
diff --git a/src/pvsgui.cpp b/src/pvsgui.cpp
index 40112b4..eb1383b 100644
--- a/src/pvsgui.cpp
+++ b/src/pvsgui.cpp
@@ -17,13 +17,25 @@
# -----------------------------------------------------------------------------
*/
+#include <getopt.h>
#include "pvsgui.h"
+#include "version.h"
PVSGUI::PVSGUI(QWidget *parent) :
QWidget(parent)
{
setupUi(this);
+ if (!QFile::exists(_settings.fileName()))
+ {
+ QDir::root().mkpath(QFileInfo(_settings.fileName()).path());
+ QFile::copy("/etc/openslx/pvsgui.conf", _settings.fileName());
+ }
+
+ // stop running pvs
+ qDebug("[%s] Stopping pvs daemon.", metaObject()->className());
+ QProcess::execute("pvs -c stop");
+
_menu = new QMenu(this);
_hostMenu = new QMenu(tr("Connect"), this);
_hosts = new QHash<QString, QAction*> ();
@@ -38,62 +50,52 @@ PVSGUI::PVSGUI(QWidget *parent) :
setupMenu();
- if (QSystemTrayIcon::isSystemTrayAvailable())
- {
- qDebug("[%s] System tray available.", metaObject()->className());
- _trayIcon = new QSystemTrayIcon(QIcon(":cam_off32.svg"), this);
- _trayIcon->setContextMenu(_menu);
- _trayIcon->setVisible(true);
- _chatDialog->setTrayIcon(_trayIcon);
- }
- else
- _trayIcon = NULL;
+ _trayIcon = new QSystemTrayIcon(QIcon(":cam_off32.svg"), this);
+ _trayIcon->setContextMenu(_menu);
+ _trayIcon->setVisible(true);
+ _chatDialog->setTrayIcon(_trayIcon);
// connect to D-Bus and get interface
QDBusConnection dbus = QDBusConnection::sessionBus();
- dbus.registerObject("/", this);
- dbus.registerService("org.openslx.pvsgui");
_ifaceDBus = new OrgOpenslxPvsInterface("org.openslx.pvs", "/", dbus, this);
- _ifaceDBus->start(); // start pvs if not running
+ if (dbus.isConnected())
+ qDebug("[%s] Connection to DBus successful.", metaObject()->className());
+ else
+ qDebug("[%s] ERROR: Could not connect to DBus!", metaObject()->className());
- // get available hosts
- QDBusPendingReply<QStringList> reply0 = _ifaceDBus->getAvailableHosts();
+ // start pvs daemon
+ qDebug("[%s] Starting pvs daemon.", metaObject()->className());
+ QDBusPendingReply<bool> reply0 = _ifaceDBus->start();
reply0.waitForFinished();
- QStringList hosts = reply0.value();
- if (reply0.isValid() && !hosts.isEmpty())
+ if (reply0.isValid() && reply0.value())
+ qDebug("[%s] Connection to PVS daemon successful.", metaObject()->className());
+ else
+ qDebug("[%s] ERROR: Could not connect to PVS daemon!", metaObject()->className());
+
+ // get available hosts
+ QDBusPendingReply<QStringList> reply1 = _ifaceDBus->getAvailableHosts();
+ reply1.waitForFinished();
+ QStringList hosts = reply1.value();
+ if (reply1.isValid() && !hosts.isEmpty())
foreach (QString host, hosts)
addHost(host);
// already connected?
- QDBusPendingReply<QString> reply1 = _ifaceDBus->isConnected();
- reply1.waitForFinished();
- QString host = reply1.value();
- if (reply1.isValid() && host != "")
+ QDBusPendingReply<QString> reply2 = _ifaceDBus->isConnected();
+ reply2.waitForFinished();
+ QString host = reply2.value();
+ if (reply2.isValid() && host != "")
connected(host);
else
disconnected();
- if (dbus.isConnected())
- qDebug("[%s] Connection to DBus successful!", metaObject()->className());
-
- // TODO: perhaps this can go if fadi does his work
- // check if vnc is allowed and setup checkbox
- QFile file(QDir::toNativeSeparators(QDir::homePath() + "/.pvs/.allow"));
- if (file.open(QIODevice::ReadOnly | QIODevice::Text))
- {
- QTextStream in(&file);
- QString line = in.readLine();
- if (line == "1")
- vncCheckBox->setChecked(true);
- file.close();
- }
-
// listen on port 29481 for incoming file transfers
_serverSocket = new QTcpServer();
_serverSocket->listen(QHostAddress::Any, 29481);
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()));
@@ -108,8 +110,6 @@ PVSGUI::PVSGUI(QWidget *parent) :
connect(_hostMenu, SIGNAL(aboutToHide()), this, SLOT(hide()));
connect(_hostMenu, SIGNAL(triggered(QAction*)), this,
SLOT(pvsConnect(QAction*)));
- connect(vncCheckBox, SIGNAL(stateChanged(int)), this,
- SLOT(setVncAllow(int)));
// signals & slots - dbus
connect(_ifaceDBus, SIGNAL(showMessage(QString, QString, bool)), this,
@@ -122,11 +122,8 @@ PVSGUI::PVSGUI(QWidget *parent) :
connect(_ifaceDBus, SIGNAL(incomingMulticastTransferNew(qulonglong, QString, QString, qulonglong)), SLOT(incomingMulticastFile(qulonglong, QString, QString, qulonglong)));
// show toolbar
- setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
+ setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint);
setAttribute(Qt::WA_AlwaysShowToolTips);
- updateConfig();
- setVisible(true);
- hide();
}
PVSGUI::~PVSGUI()
@@ -140,12 +137,52 @@ 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());
+}
- if (!_settings.value("Multicast/interface").isNull())
- _ifaceDBus->setMulticastInterface(_settings.value("Multicast/interface").toString());
+
+void PVSGUI::setVisible(bool visible)
+{
+ QWidget::setVisible(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);
}
////////////////////////////////////////////////////////////////////////////////
@@ -190,6 +227,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);
@@ -199,6 +238,7 @@ void PVSGUI::setupMenu()
_quitAction = new QAction(tr("&Quit"), this);
// setup menu
+ _menu->addAction(_showAction);
_menu->addMenu(_hostMenu);
_menu->addAction(_disconnectAction);
_menu->addAction(_showInfoAction);
@@ -215,60 +255,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();
@@ -396,22 +400,6 @@ void PVSGUI::delHost(QString host)
}
}
-// TODO: perhaps this can go if fadi does his work
-void PVSGUI::setVncAllow(int i)
-{
- QFile file(QDir::toNativeSeparators(QDir::homePath() + "/.pvs/.allow"));
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
- return;
-
- QTextStream out(&file);
- if (i == 0)
- out << 0;
- else
- out << 1;
-
- file.close();
-}
-
void PVSGUI::sendFile()
{
ClientFileSendDialog *d = new ClientFileSendDialog();
@@ -436,19 +424,92 @@ void PVSGUI::incomingMulticastFile(qulonglong transferID, QString sender, QStrin
////////////////////////////////////////////////////////////////////////////////
// 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 << "-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);
+}
+
+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);
+ QtSingleApplication app(argc, argv);
+ 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");
app.installTranslator(&translator);
+ bool visible = false;
+ int position = -1;
+
+ // 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", no_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;
+ pvsgui.setPosition(position);
+ pvsgui.setVisible(visible);
+ pvsgui.hide();
return app.exec();
}