mambatray/src/mambatray

205 lines
9.2 KiB
Plaintext
Raw Normal View History

2011-04-26 21:25:03 +02:00
#!/usr/bin/python
# mambatray2
# Copyright (C) 2011 by Silvan Calarco
2011-06-30 06:25:36 +02:00
# Copyright (C) 2011 by michiamophil
2011-04-26 21:25:03 +02:00
# 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):
2011-06-30 06:25:36 +02:00
global w, menu, contatore, srpm, lista, NetsrpmsArg, nOre
nOre = 2
srpm = ["skype", "flashplugin", "win32codecs"]
NetsrpmsArg = "-c"
lista = []
contatore = 0
2011-04-26 21:25:03 +02:00
w = parent
QtGui.QSystemTrayIcon.__init__(self, icon, parent)
menu = QtGui.QMenu(parent)
# refresh packages cache timer
2011-06-30 06:25:36 +02:00
global refreshPackagesTimer, refreshPackagesCacheProcess, checkSRPMSUpdatesTimer, SRPMUpdateProcess
refreshPackagesTimer = QtCore.QTimer(self)
2011-06-30 06:25:36 +02:00
checkSRPMSUpdatesTimer = QtCore.QTimer(self)
refreshPackagesCacheProcess = QtCore.QProcess(self)
2011-06-30 06:25:36 +02:00
SRPMUpdateProcess = QtCore.QProcess(self)
self.connect(refreshPackagesTimer, SIGNAL("timeout()"), self.refreshPackagesCache)
self.connect(refreshPackagesCacheProcess, SIGNAL("finished(int,QProcess::ExitStatus)"), self.restartRefreshPackagesTimer)
2011-06-30 06:25:36 +02:00
self.connect(checkSRPMSUpdatesTimer, SIGNAL("timeout()"), self.SRPMSCheckUpgradeList)
2011-04-26 21:25:03 +02:00
# 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)
2011-06-30 06:25:36 +02:00
self.connect(SRPMUpdateProcess, SIGNAL("finished(int,QProcess::ExitStatus)"), self.SRPMSCheckUpgrade)
2011-04-26 21:25:03 +02:00
# 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)
# the first time refresh packages cache after 5 minutes
refreshPackagesTimer.start( 5 * 60000 )
2011-06-30 06:25:36 +02:00
checkSRPMSUpdatesTimer.start( 6000 )
2011-04-26 21:25:03 +02:00
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"),
"<center><b>"+_("openmamba control center")+"</b>"
"<br><br>Copyright(c) 2011 by Silvan Calarco"
"<br><br><a href=\"http://www.openmamba.org\">http://www.openmamba.org</a></center>")
def softwareManager(self):
softwareManagerProcess.execute("/opt/kde/bin/kpackagekit")
def softwareCheckUpgrades(self):
softwareCheckUpgradesProcess.start("/opt/kde/bin/kpackagekit", ['--updates'])
def refreshPackagesCache(self):
refreshPackagesTimer.stop()
refreshPackagesCacheProcess.start("/usr/bin/pkcon", ['refresh'])
def restartRefreshPackagesTimer(self,status):
# check every 4 hours and 31 minutes */
refreshPackagesTimer.start( (4 * 60 + 31) * 60000)
2011-04-26 21:25:03 +02:00
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']))))
2011-06-30 06:25:36 +02:00
def SRPMSCheckUpgradeList(self):
checkSRPMSUpdatesTimer.stop()
global contatore, lista, NetsrpmsArg
try:
SRPMUpdateProcess.start("/usr/bin/openmamba-netsrpms",[NetsrpmsArg,srpm[contatore]])
except: #supera il limite dell'indice nella lista
contatore = 0
if NetsrpmsArg == '-c':
self.SRPMSAskAndInstall()
else:
lista = []
NetsrpmsArg = '-c'
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
#viene eseguita per ogni SRPM al termine del processo SRPMUpdateProcess
def SRPMSCheckUpgrade(self, status):
global contatore, lista
if status == 1:
lista.append(srpm[contatore])
contatore += 1
self.SRPMSCheckUpgradeList()
#viene eseguita una volta terminata la fase di controllo degli aggiornamenti
def SRPMSAskAndInstall(self):
global NetsrpmsArg, lista
if not lista == []:
Lista = self.Lista()
msg = QtGui.QMessageBox.question(menu, ("Updates"), (_("I seguenti pacchetti saranno aggiornati: ") + Lista + ".\n" + _("Sei d'accordo?")), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes)
if msg == QtGui.QMessageBox.Yes:
NetsrpmsArg = '-u'
self.SRPMSCheckUpgradeList()
else:
lista = []
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
else:
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
#partendo dalla lista lista (scusate il gioco di parole :) ) restituisce la lista in modo 'leggibile'
def Lista(self):
testo = ''
for a in lista:
testo = testo + a + ', '
return testo[0:len(testo)-2]
2011-04-26 21:25:03 +02:00
def main():
app = QtGui.QApplication(sys.argv)
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_())
2011-04-26 21:25:03 +02:00
if __name__ == '__main__':
main()