[X2Go-Commits] [x2godesktopsharing] 01/13: Add possibility to have a system-wide settings file in /etc/x2godesktopsharing/settings.
git-admin at x2go.org
git-admin at x2go.org
Mon Nov 12 14:32:31 CET 2018
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository x2godesktopsharing.
commit 3657d1d62d097c98ffca3b47de1d8ecba7127d59
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date: Sun Nov 11 18:08:13 2018 +0100
Add possibility to have a system-wide settings file in /etc/x2godesktopsharing/settings.
The user preferences always supersede the system-wide settings, so
system-wide settings can act as a default set of settings, but not as a
limitation to the user.
---
debian/changelog | 4 +++
sharetray.cpp | 93 ++++++++++++++++++++++++++++++++++++++++----------------
sharetray.h | 12 +++++---
3 files changed, 79 insertions(+), 30 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index b61b68c..2505da0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -13,6 +13,10 @@ x2godesktopsharing (3.1.1.5-0x2go1) UNRELEASED; urgency=medium
- simplelocalsocket.cpp: Stop using deprecated QString::toAscii() function
(replace it by toLatin1()).
- Drop build cruft (moc_listdialog.cpp).
+ - Add possibility to have a system-wide settings file in
+ /etc/x2godesktopsharing/settings. The user preferences always
+ supersede the system-wide settings, so system-wide settings can
+ act as a default set of settings, but not as a limitation to the user.
* debian/*:
+ Convert to DH packaging style. Build against Qt5.
* debian/control:
diff --git a/sharetray.cpp b/sharetray.cpp
index 0a9acfe..445eb7c 100644
--- a/sharetray.cpp
+++ b/sharetray.cpp
@@ -5,6 +5,7 @@
//
//
// Author: Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>, (C) 2009-2015
+// Mike Gabriel <mike.gabriel at das-netzwerkteam.de>, (C) 2011-2018
//
// Copyright: See COPYING file that comes with this distribution
//
@@ -34,6 +35,7 @@
#include <QDateTime>
#include <grp.h>
#include <QProcess>
+#include <QFileInfo>
#include <stdint.h>
#define STAT_ACT_COUNT 10
@@ -45,6 +47,16 @@ int ShareTray::sigtermFd[2];
int ShareTray::sigabortFd[2];
int ShareTray::sighupFd[2];
+bool fileExists(QString path) {
+ QFileInfo check_file(path);
+ // check if file exists and if yes: Is it really a file and no directory?
+ if (check_file.exists() && check_file.isFile()) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
ShareTray::ShareTray()
: QMainWindow()
{
@@ -212,7 +224,8 @@ ShareTray::ShareTray()
}
}
- loadSettings();
+ loadSystemSettings();
+ loadUserSettings();
setTrayIcon();
trayIcon->show();
}
@@ -225,7 +238,7 @@ ShareTray::~ShareTray()
if ( QFile::exists ( lockFname ) )
QFile::remove ( lockFname );
qDebug() <<"lock file removed";
- saveSettings();
+ saveUserSettings();
qDebug() <<"settings saved";
}
@@ -457,21 +470,29 @@ void ShareTray::slotCloseConnection ( AccessAction* action )
int ShareTray::getAccess ( QString remote_user, QString host )
{
- if ( whiteList.contains ( remote_user ) )
+
+ // user preferences always supercede system-wide preferences
+ if ( userWhiteList.contains ( remote_user ) )
return QMessageBox::Yes;
- if ( blackList.contains ( remote_user ) )
+ if ( userBlackList.contains ( remote_user ) )
return QMessageBox::No;
+ // system-wide preferences act as defaults for all users, but can be overriden by the user...
+ if ( systemwideWhiteList.contains ( remote_user ) )
+ return QMessageBox::Yes;
+ if ( systemwideBlackList.contains ( remote_user ) )
+ return QMessageBox::Yes;
+
MessageBox m ( remote_user, host, this );
m.activateWindow();
m.raise();
int res=m.exec();
if ( m.isChecked() &&res==QMessageBox::Yes )
- whiteList<<remote_user;
+ userWhiteList<<remote_user;
if ( m.isChecked() &&res==QMessageBox::No )
- blackList<<remote_user;
- actBlack->setEnabled ( blackList.size() >0 );
- actWhite->setEnabled ( whiteList.size() >0 );
+ userBlackList<<remote_user;
+ actBlack->setEnabled ( userBlackList.size() >0 );
+ actWhite->setEnabled ( userWhiteList.size() >0 );
return res;
}
@@ -488,7 +509,7 @@ void ShareTray::closeEvent ( QCloseEvent* ev )
if ( QFile::exists ( lockFname ) )
QFile::remove ( lockFname );
qDebug() <<"lock file removed";
- saveSettings();
+ saveUserSettings();
qDebug() <<"settings saved";
}
@@ -560,36 +581,56 @@ void ShareTray::showList()
QStringList* lst;
if ( current_list==BLACK )
- lst=&blackList;
+ lst=&userBlackList;
else
- lst=&whiteList;
+ lst=&userWhiteList;
lst->sort();
ui.box->clear();
ui.box->insertItems ( 0,*lst );
}
-void ShareTray::loadSettings()
+void ShareTray::loadSystemSettings()
{
- QSettings st ( QDir::homePath() +"/.x2godesktopsharing/settings",
- QSettings::NativeFormat );
+ if (fileExists ("/etc/x2godesktopsharing/settings") ) {
+
+ QSettings st ( "/etc/x2godesktopsharing/settings",
+ QSettings::NativeFormat );
+
+ systemwideBlackList= st.value ( "blacklist" ).toStringList();
+ systemwideWhiteList= st.value ( "whitelist" ).toStringList();
- blackList= st.value ( "blacklist" ).toStringList();
- whiteList= st.value ( "whitelist" ).toStringList();
+ actBlack->setEnabled ( systemwideBlackList.size() >0 );
+ actWhite->setEnabled ( systemwideWhiteList.size() >0 );
- actBlack->setEnabled ( blackList.size() >0 );
- actWhite->setEnabled ( whiteList.size() >0 );
+ }
}
-void ShareTray::saveSettings()
+void ShareTray::loadUserSettings()
+{
+
+ if (fileExists (QDir::homePath() + +"/.x2godesktopsharing/settings") ) {
+
+ QSettings st ( QDir::homePath() +"/.x2godesktopsharing/settings",
+ QSettings::NativeFormat );
+
+ userBlackList= st.value ( "blacklist" ).toStringList();
+ userWhiteList= st.value ( "whitelist" ).toStringList();
+
+ actBlack->setEnabled ( userBlackList.size() >0 );
+ actWhite->setEnabled ( userWhiteList.size() >0 );
+
+ }
+}
+
+void ShareTray::saveUserSettings()
{
QSettings st ( QDir::homePath() +"/.x2godesktopsharing/settings",
QSettings::NativeFormat );
- st.setValue ( "blacklist",blackList );
- st.setValue ( "whitelist",whiteList );
+ st.setValue ( "blacklist",userBlackList );
+ st.setValue ( "whitelist",userWhiteList );
}
-
void ShareTray::setTrayIcon()
{
if ( !acceptConnections() )
@@ -633,17 +674,17 @@ void ShareTray::slotMsgOkCancel ( QAbstractButton* button )
{
QStringList* lst;
if ( current_list==BLACK )
- lst=&blackList;
+ lst=&userBlackList;
else
- lst=&whiteList;
+ lst=&userWhiteList;
lst->clear();
for ( int i=ui.box->count()-1;i>=0;--i )
{
*lst<<ui.box->item ( i )->text();
}
}
- actBlack->setEnabled ( blackList.size() >0 );
- actWhite->setEnabled ( whiteList.size() >0 );
+ actBlack->setEnabled ( userBlackList.size() >0 );
+ actWhite->setEnabled ( userWhiteList.size() >0 );
hide();
}
diff --git a/sharetray.h b/sharetray.h
index 2b54022..e96a2bb 100644
--- a/sharetray.h
+++ b/sharetray.h
@@ -5,6 +5,7 @@
//
//
// Author: Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>, (C) 2009-2015
+// Mike Gabriel <mike.gabriel at das-netzwerkteam.de>, (C) 2011-2018
//
// Copyright: See COPYING file that comes with this distribution
//
@@ -56,8 +57,10 @@ private:
QString socketFname;
QString lockFname;
MessageBox* mbox;
- QStringList whiteList;
- QStringList blackList;
+ QStringList userWhiteList;
+ QStringList userBlackList;
+ QStringList systemwideWhiteList;
+ QStringList systemwideBlackList;
Ui::mwnd ui;
bool menuClose;
protected:
@@ -88,8 +91,9 @@ private:
int getAccess(QString user, QString host);
void trayMessage(QString title, QString text);
bool isProcessRunning(QString pid);
- void loadSettings();
- void saveSettings();
+ void loadSystemSettings();
+ void loadUserSettings();
+ void saveUserSettings();
void setTrayIcon();
void showList();
// unix file sockets for signal handler communication (unix <-> Qt)
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2godesktopsharing.git
More information about the x2go-commits
mailing list