From 63bcd293e78ceacab40451b595b3ed2556fea9ab Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Tue, 19 Apr 2011 00:33:11 +0200 Subject: [PVS] * System/User scope configuration (/etc/xdg/openslx/ and ~/.config/openslx/) * Restricted mode available --- src/gui/mainWindow.cpp | 6 ----- src/pvs.cpp | 61 +++++++++++++++++++++----------------------------- src/pvs.h | 6 ++--- src/pvsDaemon.cpp | 7 +----- src/pvsgui.cpp | 39 ++++++++++++++++---------------- src/pvsgui.h | 1 + 6 files changed, 48 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/gui/mainWindow.cpp b/src/gui/mainWindow.cpp index 4eae44e..7e2efc3 100644 --- a/src/gui/mainWindow.cpp +++ b/src/gui/mainWindow.cpp @@ -46,12 +46,6 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : { ui->setupUi(this); - - if (!QFile::exists(_settings.fileName())) - { - QDir::root().mkpath(QFileInfo(_settings.fileName()).path()); - QFile::copy("/etc/openslx/pvsmgr.conf", _settings.fileName()); - } myself = this; #ifdef MAINWINDOW_USE_NORMALGUI diff --git a/src/pvs.cpp b/src/pvs.cpp index 39bacb0..5621c64 100644 --- a/src/pvs.cpp +++ b/src/pvs.cpp @@ -44,22 +44,20 @@ PVS::PVS() : _locked = false; _vncAllowed = false; _vncRequested = false; - readPolicyFiles(); - loadCommands(); _blankScreen = NULL; _vncPort = -1; - _masterMcastConfig = new McastConfiguration(this); - _masterMcastConfig->loadFrom(&_settings, "multicast"); + QSettings tmp(QSettings::SystemScope, "openslx", "pvs"); + if (tmp.value("restricted").toBool()) + _settings = new QSettings(QSettings::SystemScope, "openslx", "pvs", this); + else + _settings = new QSettings(QSettings::UserScope, "openslx", "pvs", this); - // add a notify to the allow file, so we get informed when the file is changed - QString watchPath(getPolicyDir()); - watchPath.append(QString(".allow")); - _notify = new QFileSystemWatcher(this); - _notify->addPath(QString(watchPath.toUtf8().data())); + readPolicyFiles(); + loadCommands(); - connect(_notify, SIGNAL(fileChanged(const QString &)), this, - SLOT(fileChanged(const QString &))); + _masterMcastConfig = new McastConfiguration(this); + _masterMcastConfig->loadFrom(_settings, "multicast"); // connect to D-Bus new PvsAdaptor(this); @@ -94,10 +92,10 @@ PVS::PVS() : initializeInputEventHandling(); // Read Config and try to autoconnect to given host - QHostAddress host(_settings.value("Connection/host").toString()); - int port = _settings.value("Connection/port").toInt(); - QByteArray fingerprint = QByteArray::fromHex(_settings.value("Connection/fingerprint").toByteArray()); - QString name = _settings.value("Connection/sessionname").toString(); + QHostAddress host(_settings->value("Connection/host").toString()); + int port = _settings->value("Connection/port").toInt(); + QByteArray fingerprint = QByteArray::fromHex(_settings->value("Connection/fingerprint").toByteArray()); + QString name = _settings->value("Connection/sessionname").toString(); if (!host.isNull() && port > 0 && fingerprint != "" && name != "") { qDebug() << "Autoconnecting to " << host.toString(); @@ -110,10 +108,6 @@ PVS::PVS() : PVS::~PVS() { - // make sure we dont leave a locked computer - if (_notify) - disconnect(_notify, SIGNAL(fileChanged(const QString &)), this, - SLOT(fileChanged(const QString &))); unlock(); delete _sdClient; } @@ -423,11 +417,6 @@ void PVS::timerEvent(QTimerEvent *event) killTimer(event->timerId()); } -bool PVS::allowExists() -{ - return policyFileExists(QString(".allow")); -} - /** * check whether we want to allow vnc connections to this client */ @@ -474,14 +463,6 @@ void PVS::readPolicyFiles() // Add more policyfiles here if any } -/** - * callback which gets invoked when the watched file is changed - */ -void PVS::fileChanged(const QString& path) -{ - getVNCAllow(); -} - /** * lock the client */ @@ -665,6 +646,11 @@ QString PVS::isConnected() return _pvsServerConnection->getServerName(); } +bool PVS::isRestricted() +{ + return (_settings->scope() == QSettings::SystemScope); +} + QString PVS::chat_getNickname() { return _chat->getSource(); @@ -922,14 +908,17 @@ void PVS::loadMcastConfig(QString const& message) void PVS::setConfigValue(QString key, QString value) { - _settings.setValue(key, value); - _settings.sync(); - getVNCAllow(); + if (!isRestricted()) + { + _settings->setValue(key, value); + _settings->sync(); + getVNCAllow(); + } } QString PVS::getConfigValue(QString key) { - return _settings.value(key).toString(); + return _settings->value(key).toString(); } void PVS::showProc(QString filter) diff --git a/src/pvs.h b/src/pvs.h index b2a84cf..e6e91ed 100644 --- a/src/pvs.h +++ b/src/pvs.h @@ -80,10 +80,10 @@ public Q_SLOTS: void chat_send(QString nick_to, QString nick_from, QString msg); QString chat_getNickname(); QStringList chat_getNicknames(); - void fileChanged(const QString& path); void pvsConnect(QString host, QString passwd); void pvsDisconnect(); QString isConnected(); + bool isRestricted(); QStringList getAvailableHosts(); QString getIpByNick(QString nick); @@ -126,7 +126,6 @@ protected: private: // own - bool allowExists(); ///< whether the .allow file exists bool getVNCAllow(); ///< whether vnc-connections to this client are allowed void readPolicyFiles(); ///< pars the policy files @@ -141,7 +140,6 @@ private: bool _vncAllowed; ///< whether vncConnections to this client are allowed (dup?) BlankScreen *_blankScreen;///< object to blank the screen - QFileSystemWatcher* _notify; ///< used to get notifies about file changes //vnc-server QString _vncScriptPath; ///< path to the vnc script file QString _vncScriptName; ///< name of the vnc script file @@ -193,6 +191,6 @@ private Q_SLOTS: void processStopErrorOccured(QProcess::ProcessError error); private: - QSettings _settings; + QSettings *_settings; }; #endif /* PVSCLIENT_H_ */ diff --git a/src/pvsDaemon.cpp b/src/pvsDaemon.cpp index 9f2572c..6dd30ec 100644 --- a/src/pvsDaemon.cpp +++ b/src/pvsDaemon.cpp @@ -75,12 +75,7 @@ int main(int argc, char** argv) app.installTranslator(&translator); QFileInfo script; - QSettings settings; - if (!QFile::exists(settings.fileName())) - { - QDir::root().mkpath(QFileInfo(settings.fileName()).path()); - QFile::copy("/etc/openslx/pvs.conf", settings.fileName()); - } + QSettings settings(QSettings::SystemScope, "openslx", "pvs"); QString s = settings.value("VNC/script").toString(); script.setFile(s); if (!script.exists()) diff --git a/src/pvsgui.cpp b/src/pvsgui.cpp index 4294206..5359449 100644 --- a/src/pvsgui.cpp +++ b/src/pvsgui.cpp @@ -26,12 +26,6 @@ PVSGUI::PVSGUI(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"); @@ -48,8 +42,6 @@ PVSGUI::PVSGUI(QWidget *parent) : _hostMenu->setEnabled(false); hostButton->setEnabled(false); - setupMenu(); - _trayIcon = new QSystemTrayIcon(QIcon(":cam_off32.svg"), this); _trayIcon->setContextMenu(_menu); _trayIcon->setVisible(true); @@ -72,19 +64,26 @@ PVSGUI::PVSGUI(QWidget *parent) : else qDebug("[%s] ERROR: Could not connect to PVS daemon!", metaObject()->className()); - // get available hosts - QDBusPendingReply reply1 = _ifaceDBus->getAvailableHosts(); + // ask if restricted mode is on + QDBusPendingReply reply1 = _ifaceDBus->isRestricted(); reply1.waitForFinished(); - QStringList hosts = reply1.value(); - if (reply1.isValid() && !hosts.isEmpty()) + _restricted = reply1.value(); + + setupMenu(); + + // get available hosts + QDBusPendingReply reply2 = _ifaceDBus->getAvailableHosts(); + reply2.waitForFinished(); + QStringList hosts = reply2.value(); + if (reply2.isValid() && !hosts.isEmpty()) foreach (QString host, hosts) addHost(host); // already connected? - QDBusPendingReply reply2 = _ifaceDBus->isConnected(); - reply2.waitForFinished(); - QString host = reply2.value(); - if (reply2.isValid() && host != "") + QDBusPendingReply reply3 = _ifaceDBus->isConnected(); + reply3.waitForFinished(); + QString host = reply3.value(); + if (reply3.isValid() && host != "") connected(host); else disconnected(); @@ -239,17 +238,17 @@ void PVSGUI::setupMenu() // setup menu _menu->addAction(_showAction); - _menu->addMenu(_hostMenu); - _menu->addAction(_disconnectAction); + if (!_restricted) _menu->addMenu(_hostMenu); + if (!_restricted) _menu->addAction(_disconnectAction); _menu->addAction(_showInfoAction); _menu->addSeparator(); _menu->addAction(_startChatAction); _menu->addAction(_sendFileAction); _menu->addSeparator(); - _menu->addAction(_configAction); + if (!_restricted) _menu->addAction(_configAction); _menu->addAction(_aboutAction); _menu->addSeparator(); - _menu->addAction(_quitAction); + if (!_restricted) _menu->addAction(_quitAction); pvsButton->setMenu(_menu); hostButton->setMenu(_hostMenu); diff --git a/src/pvsgui.h b/src/pvsgui.h index b96d73c..f87b328 100644 --- a/src/pvsgui.h +++ b/src/pvsgui.h @@ -93,6 +93,7 @@ private: QAction *_quitAction; int _position; + bool _restricted; QPoint _clickPoint; QString _passwd; -- cgit v1.2.3-55-g7522