From 20b17d0c3ab26b6e924e35489c7022a2c17620bf Mon Sep 17 00:00:00 2001 From: silvan Date: Thu, 28 Apr 2011 10:57:22 +0200 Subject: [PATCH] Check session to prevent multiple processes at startup --- src/mambatray | 17 ++++--- src/mambatray~ | 123 ------------------------------------------------- 2 files changed, 10 insertions(+), 130 deletions(-) delete mode 100755 src/mambatray~ diff --git a/src/mambatray b/src/mambatray index 50a9e9e..6da0541 100755 --- a/src/mambatray +++ b/src/mambatray @@ -111,13 +111,16 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon): def main(): app = QtGui.QApplication(sys.argv) - app.setQuitOnLastWindowClosed(0) - gettext.install('mambatray', '/usr/share/locale', unicode=1) - w = QtGui.QWidget() - w.setWindowIcon(QtGui.QIcon.fromTheme("mambatray",QtGui.QIcon("/usr/share/icons/hicolor/64x64/apps/mambatray.png"))) - trayIcon = SystemTrayIcon(QtGui.QIcon.fromTheme("mambatray", QtGui.QIcon("/usr/share/icons/hicolor/32x32/apps/mambatray.png")), w) - trayIcon.show() - sys.exit(app.exec_()) + if (app.isSessionRestored()): + app.exit(1) + else: + app.setQuitOnLastWindowClosed(0) + gettext.install('mambatray', '/usr/share/locale', unicode=1) + w = QtGui.QWidget() + w.setWindowIcon(QtGui.QIcon.fromTheme("mambatray",QtGui.QIcon("/usr/share/icons/hicolor/64x64/apps/mambatray.png"))) + trayIcon = SystemTrayIcon(QtGui.QIcon.fromTheme("mambatray", QtGui.QIcon("/usr/share/icons/hicolor/32x32/apps/mambatray.png")), w) + trayIcon.show() + sys.exit(app.exec_()) if __name__ == '__main__': main() diff --git a/src/mambatray~ b/src/mambatray~ deleted file mode 100755 index 239adc7..0000000 --- a/src/mambatray~ +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/python -# mambatray2 -# Copyright (C) 2011 by Silvan Calarco -# Distributed under the terms of the GPL version 3 FLOSS License -# -import sys -import gettext -from PyQt4.QtCore import SIGNAL -from PyQt4 import QtGui -from PyQt4 import QtCore - -class SystemTrayIcon(QtGui.QSystemTrayIcon): - - def __init__(self, icon, parent=None): - global w, menu - w = parent - QtGui.QSystemTrayIcon.__init__(self, icon, parent) - menu = QtGui.QMenu(parent) - - # software menu - global softwareManagerProcess, softwareCheckUpgradesProcess, softwareBaseInstallsProcess, dcopServerProcess - softwareManagerProcess = QtCore.QProcess(self) - softwareCheckUpgradesProcess = QtCore.QProcess(self) - softwareBaseInstallsProcess = QtCore.QProcess(self) - dcopServerProcess = QtCore.QProcess(self) - - softwareMenu = menu.addMenu(QtGui.QIcon.fromTheme("applications-system"),_("Software")) - softwareManageAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("applications-other"),_("Add/Remove software packages...")) - self.connect(softwareManageAction, SIGNAL("triggered()"), self.softwareManager) - - softwareCheckUpgradesAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("system-software-update"),_("Check for updates now...")) - self.connect(softwareCheckUpgradesAction, SIGNAL("triggered()"), self.softwareCheckUpgrades) - - softwareBaseInstallsAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("openmamba"),_("openmamba components...")) - self.connect(softwareBaseInstallsAction, SIGNAL("triggered()"), self.softwareBaseInstalls) - - # network menu - global networkFirewallDisableProcess, networkFirewallEnableProcess, networkFirewallConfigureProcess, networkProxyProcess - networkFirewallDisableProcess = QtCore.QProcess(self) - networkFirewallEnableProcess = QtCore.QProcess(self) - networkFirewallConfigureProcess = QtCore.QProcess(self) - networkProxyProcess = QtCore.QProcess(self) - - networkMenu = menu.addMenu(QtGui.QIcon.fromTheme("preferences-system-network"),_("Network")) - networkFirewallMenu = networkMenu.addMenu(QtGui.QIcon.fromTheme("security-medium"),_("Firewall")) - networkFirewallDisableAction = networkFirewallMenu.addAction(QtGui.QIcon.fromTheme("security-low"),_("Disable")) - self.connect(networkFirewallDisableAction, SIGNAL("triggered()"), self.networkFirewallDisable) - self.connect(networkFirewallDisableProcess, SIGNAL("finished(int,QProcess::ExitStatus)"), self.networkFirewallDisableMessage) - networkFirewallEnableAction = networkFirewallMenu.addAction(QtGui.QIcon.fromTheme("security-high"),_("Enable")) - self.connect(networkFirewallEnableAction, SIGNAL("triggered()"), self.networkFirewallEnable) - self.connect(networkFirewallEnableProcess, SIGNAL("finished(int,QProcess::ExitStatus)"), self.networkFirewallEnableMessage) - networkFirewallConfigureAction = networkFirewallMenu.addAction(QtGui.QIcon("/opt/kde3/share/icons/locolor/32x32/apps/guarddog.png"),_("Configure...")) - self.connect(networkFirewallConfigureAction, SIGNAL("triggered()"), self.networkFirewallConfigure) - networkProxyAction = networkMenu.addAction(QtGui.QIcon.fromTheme("network-server"),_("Proxy...")) - self.connect(networkProxyAction, SIGNAL("triggered()"), self.networkProxy) - - # about box - aboutAction = menu.addSeparator() - aboutAction = menu.addAction(QtGui.QIcon.fromTheme("help-about"),_("About")) - self.connect(aboutAction, SIGNAL("triggered()"), self.about) - - self.setContextMenu(menu) - self.setToolTip(_("openmamba control center")) - self.activated.connect(self.iconActivated) - - def iconActivated(self, reason): - if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick): - menu.popup(self.geometry().center()) - - def about(self): - QtGui.QMessageBox.about(menu, "About", - "
"+_("openmamba control center")+"" - "

Copyright(c) 2011 by Silvan Calarco" - "

http://www.openmamba.org
") - - def softwareManager(self): - softwareManagerProcess.execute("/opt/kde/bin/kpackagekit") - - def softwareCheckUpgrades(self): - softwareCheckUpgradesProcess.execute("/opt/kde/bin/kpackagekit", QtCore.QStringList(list(set(['--updates'])))) - - def softwareBaseInstalls(self): - dcopServerProcess.startDetached("/opt/kde3/bin/dcopserver") - softwareBaseInstallsProcess.start("/opt/kde3/bin/kmdr-executor", ['/usr/share/openmamba/mambabase/mambabase.kmdr']) - - def networkFirewallDisable(self): - networkFirewallDisableProcess.start("sudo",['/sbin/service','iptables','stop']) - - def networkFirewallDisableMessage(self,status): - if (status == QtCore.QProcess.NormalExit): - self.showMessage("Firewall", _("Firewall disabled in current session")) - else: - self.showMessage("Firewall", _("Could not disable firewall")) - - def networkFirewallEnable(self): - networkFirewallEnableProcess.start("sudo",['/sbin/service','iptables','start']) - - def networkFirewallEnableMessage(self,status): - if (status == QtCore.QProcess.NormalExit): - self.showMessage("Firewall", _("Firewall enabled in current session")) - else: - self.showMessage("Firewall", _("Could not enable firewall")) - - def networkFirewallConfigure(self): - networkFirewallConfigureProcess.execute("sudo", - QtCore.QStringList(list(set(['/opt/kde3/bin/guarddog'])))) - - def networkProxy(self): - networkProxyProcess.execute("/opt/kde/bin/kcmshell4", - QtCore.QStringList(list(set(['proxy'])))) - -def main(): - app = QtGui.QApplication(sys.argv) - app.setQuitOnLastWindowClosed(0) - gettext.install('mambatray', '/usr/share/locale', unicode=1) - w = QtGui.QWidget() - w.setWindowIcon(QtGui.QIcon.fromTheme("mambatray",QtGui.QIcon("/usr/share/icons/hicolor/64x64/apps/mambatray.png"))) - trayIcon = SystemTrayIcon(QtGui.QIcon.fromTheme("mambatray", QtGui.QIcon("/usr/share/icons/hicolor/32x32/apps/mambatray.png")), w) - trayIcon.show() - sys.exit(app.exec_()) - -if __name__ == '__main__': - main()