summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-09-12 21:29:49 +0000
committerkali <kali@leap.se>2012-09-12 08:42:29 +0900
commit18109193b239be6e7ecc4c2d07c9c999e33081f8 (patch)
tree6346f7251578a0c0e7375a4ce7c2c22ea8e3f6bd /src/leap
parent3fa754c39bcdea355a4ec6b0ddfaeead2040a86a (diff)
checks for systray in unity
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/app.py3
-rw-r--r--src/leap/base/constants.py1
-rw-r--r--src/leap/baseapp/dialogs.py12
-rw-r--r--src/leap/baseapp/unitychecks.py79
4 files changed, 95 insertions, 0 deletions
diff --git a/src/leap/app.py b/src/leap/app.py
index 5849848c..322118c5 100644
--- a/src/leap/app.py
+++ b/src/leap/app.py
@@ -1,3 +1,4 @@
+# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
import logging
# This is only needed for Python v2 but is harmless for Python v3.
import sip
@@ -5,6 +6,7 @@ sip.setapi('QVariant', 2)
from PyQt4.QtGui import (QApplication, QSystemTrayIcon, QMessageBox)
from leap.baseapp.mainwindow import LeapWindow
+from leap.baseapp import unitychecks
def main():
@@ -45,6 +47,7 @@ def main():
logger.info('Starting app')
app = QApplication(sys.argv)
+ unitychecks.do_check()
if not QSystemTrayIcon.isSystemTrayAvailable():
QMessageBox.critical(None, "Systray",
diff --git a/src/leap/base/constants.py b/src/leap/base/constants.py
index 991a1dfe..0ec3e016 100644
--- a/src/leap/base/constants.py
+++ b/src/leap/base/constants.py
@@ -1,4 +1,5 @@
"""constants to be used in base module"""
+APP_NAME = "leap"
# default provider placeholder
# using `example.org` we make sure that this
diff --git a/src/leap/baseapp/dialogs.py b/src/leap/baseapp/dialogs.py
index d4acb09d..af531154 100644
--- a/src/leap/baseapp/dialogs.py
+++ b/src/leap/baseapp/dialogs.py
@@ -1,3 +1,4 @@
+# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
import logging
from PyQt4.QtGui import (QDialog, QFrame, QPushButton, QLabel, QMessageBox)
@@ -31,6 +32,7 @@ class ErrorDialog(QDialog):
# closing the dialog. we can pass that
# in the constructor
+
def criticalMessage(self, msg, label):
msgBox = QMessageBox(QMessageBox.Critical,
"QMessageBox.critical()", msg,
@@ -45,3 +47,13 @@ class ErrorDialog(QDialog):
logger.info('Quitting')
import sys
sys.exit()
+
+ def confirmMessage(self, msg, label, action):
+ msgBox = QMessageBox(QMessageBox.Critical,
+ "QMessageBox.critical()", msg,
+ QMessageBox.NoButton, self)
+ msgBox.addButton("&Ok", QMessageBox.AcceptRole)
+ msgBox.addButton("&Cancel", QMessageBox.RejectRole)
+
+ if msgBox.exec_() == QMessageBox.AcceptRole:
+ action()
diff --git a/src/leap/baseapp/unitychecks.py b/src/leap/baseapp/unitychecks.py
new file mode 100644
index 00000000..aa644c5f
--- /dev/null
+++ b/src/leap/baseapp/unitychecks.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python2
+# vim: tabstop=8 expandtab shiftwidth=5 softtabstop=4
+"""
+modified from code from the starcal2 project
+copyright Saeed Rasooli
+License: GPL
+"""
+import logging
+import platform
+import sys
+from subprocess import Popen, PIPE
+
+logging.basicConfig()
+logger = logging.getLogger(__name__)
+logger.setLevel('DEBUG')
+
+from leap.base.constants import APP_NAME
+from leap.baseapp.dialogs import ErrorDialog
+
+get_whitelist = lambda: eval(Popen(['gsettings', 'get', 'com.canonical.Unity.Panel', 'systray-whitelist'], stdout=PIPE).communicate()[0])
+
+set_whitelist = lambda ls: Popen(['gsettings', 'set', 'com.canonical.Unity.Panel', 'systray-whitelist', repr(ls)])
+
+def add_to_whitelist():
+ ls = get_whitelist()
+ if not APP_NAME in ls:
+ ls.append(APP_NAME)
+ set_whitelist(ls)
+
+def remove_from_whitelist():
+ ls = get_whitelist()
+ if APP_NAME in ls:
+ ls.remove(APP_NAME)
+ set_whitelist(ls)
+
+def is_unity_running():
+ (output, error) = Popen('ps aux | grep [u]nity-panel-service', stdout=PIPE, shell=True).communicate()
+ output = bool(str(output))
+ if not output:
+ (output, error) = Popen('ps aux | grep [u]nity-2d-panel', stdout=PIPE, shell=True).communicate()
+ output = bool(str(output))
+ return output
+
+def need_to_add():
+ if is_unity_running():
+ wlist = get_whitelist()
+ if not (APP_NAME in wlist or 'all' in wlist):
+ logger.debug('need to add')
+ return True
+ return False
+
+def add_and_restart():
+ add_to_whitelist()
+ Popen('LANG=en_US.UTF-8 unity', shell=True)
+
+MSG = "Seems that you are using a Unity desktop and Leap is not allowed to use Tray icon. Press OK to add Leap to Unity's white list and then restart Unity"
+
+def do_check():
+ if platform.system() == "Linux" and need_to_add():
+ dialog = ErrorDialog()
+ dialog.confirmMessage(
+ MSG,
+ "add to systray?",
+ add_and_restart)
+
+if __name__=='__main__':
+ if len(sys.argv)>1:
+ cmd = sys.argv[1]
+ if cmd=='add':
+ add_to_whitelist()
+ elif cmd=='rm':
+ remove_from_whitelist()
+ elif cmd=='print':
+ print get_whitelist()
+ elif cmd=="check":
+ from PyQt4.QtGui import QApplication
+ app = QApplication(sys.argv)
+ do_check()
+