diff --git a/src/mambatray b/src/mambatray index 980c329..b0b66af 100755 --- a/src/mambatray +++ b/src/mambatray @@ -1,6 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/python3.6 # mambatray 2 -# Copyright (C) 2011-2018 by Silvan Calarco +# Copyright (C) 2011-2019 by Silvan Calarco # Copyright (C) 2011 by michiamophil # Distributed under the terms of the GPL version 3 FLOSS License # @@ -17,33 +17,36 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): def __init__(self, icon, parent=None): global w, menu, contatore, srpm, lista, NetsrpmsArg, nOre, desktop_session - nOre = 2 - srpm = ["skype", "flashplugin", "win32codecs", "msttcorefonts", "b43-firmware", "sun-java7", "sun-java8", "virtualbox-extension-pack", "chromium-pepper-flash", "spotify"] - NetsrpmsArg = "-c" - lista = [] - contatore = 0 + nOre = 2 + srpm = ["skype", "flashplugin", "win32codecs", "msttcorefonts", "b43-firmware", "sun-java7", "sun-java8", "virtualbox-extension-pack", "chromium-pepper-flash", "spotify"] + NetsrpmsArg = "-c" + lista = [] + contatore = 0 w = parent QtWidgets.QSystemTrayIcon.__init__(self, icon, parent) menu = QtWidgets.QMenu(parent) - desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION')) + try: + desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION')) + except: + desktop_session = 'default' if desktop_session == 'default': - desktop_session = 'plasma' + desktop_session = 'plasma' elif desktop_session[:3] == 'kde': - desktop_session = 'kde' + desktop_session = 'kde' # refresh packages cache timer global refreshPackagesTimer, refreshPackagesCacheProcess, checkSRPMSUpdatesTimer, SRPMUpdateProcess, networkOnlineProcess refreshPackagesTimer = QtCore.QTimer(self) - checkSRPMSUpdatesTimer = QtCore.QTimer(self) + checkSRPMSUpdatesTimer = QtCore.QTimer(self) refreshPackagesCacheProcess = QtCore.QProcess(self) - SRPMUpdateProcess = QtCore.QProcess(self) + SRPMUpdateProcess = QtCore.QProcess(self) networkOnlineProcess = QtCore.QProcess(self) refreshPackagesTimer.timeout.connect(self.refreshPackagesCache) refreshPackagesCacheProcess.finished.connect(self.restartRefreshPackagesTimer) - checkSRPMSUpdatesTimer.timeout.connect(self.SRPMSCheckUpgradeList) - + checkSRPMSUpdatesTimer.timeout.connect(self.SRPMSCheckUpgradeList) + # software menu global softwareManagerProcess, softwareCheckUpgradesProcess, softwareBaseInstallsProcess, dcopServerProcess softwareManagerProcess = QtCore.QProcess(self) @@ -60,14 +63,14 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): softwareBaseInstallsAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("openmamba"),_("openmamba components...")) softwareBaseInstallsAction.triggered.connect(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")) @@ -87,7 +90,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): aboutAction = menu.addSeparator() aboutAction = menu.addAction(QtGui.QIcon.fromTheme("help-about"),_("About")) aboutAction.triggered.connect(self.about) - + self.setContextMenu(menu) self.setToolTip(_("openmamba control center")) self.activated.connect(self.iconActivated) @@ -95,76 +98,76 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): # the first time refresh packages cache after 5 minutes refreshPackagesTimer.start( 5 * 60000 ) # the first time check for SRPMS updates after 4 minutes - checkSRPMSUpdatesTimer.start( 4 * 60000 ) + checkSRPMSUpdatesTimer.start( 4 * 60000 ) def setProxyForSmart(self): setProxyProcess = QtCore.QProcess(self) pf = libproxy.ProxyFactory() for protocol in ["http","https","ftp"]: - proxies = pf.getProxies("%s://openmamba.org" % protocol) - for proxy in proxies: - if proxy == "direct://": - setProxyProcess.execute("smart",['config','--remove','%s_proxy' % protocol]) - break - else: - setProxyProcess.execute("smart",['config','--set','%s_proxy=%s' %(protocol,proxy)]) - break + proxies = pf.getProxies("%s://openmamba.org" % protocol) + for proxy in proxies: + if proxy == "direct://": + setProxyProcess.execute("smart",['config','--remove','%s_proxy' % protocol]) + break + else: + setProxyProcess.execute("smart",['config','--set','%s_proxy=%s' %(protocol,proxy)]) + break def iconActivated(self, reason): if reason in (QtWidgets.QSystemTrayIcon.Trigger, QtWidgets.QSystemTrayIcon.DoubleClick): menu.popup(self.geometry().center()) def about(self): - global version - path = '/etc/openmamba-release' - if os.path.exists(path): - v = open(path, 'r') - version = v.read() - a = self.FormattaInfo() - version = "" - v.close() - else: - version = _("Error: Unable to find /etc/openmamba-release") + global version + path = '/etc/openmamba-release' + if os.path.exists(path): + v = open(path, 'r') + version = v.read() + a = self.FormattaInfo() + version = "" + v.close() + else: + version = _("Error: Unable to find /etc/openmamba-release") QtWidgets.QMessageBox.about(menu, _("About"), "
"+_("openmamba control center")+"" - "

Copyright(c) 2011-2018 by Silvan Calarco" - "
Copyright(c) 2011 by michiamophil" - "

"+_("System info:")+"
" - ""+_(version)+"
http://openmamba.org
") + "

Copyright(c) 2011-2019 by Silvan Calarco" + "
Copyright(c) 2011 by michiamophil" + "

"+_("System info:")+"" + ""+_(version)+"
http://openmamba.org
") - def FormattaInfo(self): - result = [] - v = version - #result[0]=versione - result.append(v[ v.find("openmamba release ")+18 : v.find(" for") ] + " " + v[ v.find("(") : v.find(")")+1 ]) - #result[1] = piattaforma - result.append(v[ v.find("for")+4 : v.find("(") ]) - return result + def FormattaInfo(self): + result = [] + v = version + #result[0]=versione + result.append(v[ v.find("openmamba release ")+18 : v.find(" for") ] + " " + v[ v.find("(") : v.find(")")+1 ]) + #result[1] = piattaforma + result.append(v[ v.find("for")+4 : v.find("(") ]) + return result def networkOnline(self): - return networkOnlineProcess.execute("/usr/bin/nm-online",['-q','-x']) + return networkOnlineProcess.execute("/usr/bin/nm-online",['-q','-x']) def softwareManager(self): - self.setProxyForSmart() - if desktop_session == 'plasma': - softwareManagerProcess.execute("/usr/bin/plasma-discover", ['--mode', 'Browsing']) - elif desktop_session == 'kde': - softwareManagerProcess.execute("/opt/kde/bin/apper") - else: - softwareManagerProcess.execute("/usr/bin/gpk-application") + self.setProxyForSmart() + if desktop_session == 'plasma': + softwareManagerProcess.execute("/usr/bin/plasma-discover", ['--mode', 'Browsing']) + elif desktop_session == 'kde': + softwareManagerProcess.execute("/opt/kde/bin/apper") + else: + softwareManagerProcess.execute("/usr/bin/gpk-application") def softwareCheckUpgrades(self): - self.setProxyForSmart() - if desktop_session == 'plasma': - softwareCheckUpgradesProcess.start("/usr/bin/plasma-discover", ['--mode', 'Update']) - elif desktop_session == 'kde': - softwareCheckUpgradesProcess.start("/opt/kde/bin/apper", ['--updates']) + self.setProxyForSmart() + if desktop_session == 'plasma': + softwareCheckUpgradesProcess.start("/usr/bin/plasma-discover", ['--mode', 'Update']) + elif desktop_session == 'kde': + softwareCheckUpgradesProcess.start("/opt/kde/bin/apper", ['--updates']) else: - softwareCheckUpgradesProcess.start("/usr/bin/gpk-update-viewer") + softwareCheckUpgradesProcess.start("/usr/bin/gpk-update-viewer") def refreshPackagesCache(self): - self.setProxyForSmart() + self.setProxyForSmart() refreshPackagesTimer.stop() refreshPackagesCacheProcess.start("/usr/bin/pkcon", ['refresh']) @@ -195,74 +198,72 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): self.showMessage("Firewall", _("Could not enable firewall")) def networkFirewallConfigure(self): - if desktop_session == 'kde' or desktop_session == 'plasma': - networkFirewallConfigureProcess.execute("/opt/kde/bin/kcmshell4", list(set(['ufw']))) - else: - networkFirewallConfigureProcess.execute("/usr/bin/gufw") + if desktop_session == 'kde' or desktop_session == 'plasma': + networkFirewallConfigureProcess.execute("/opt/kde/bin/kcmshell4", list(set(['ufw']))) + else: + networkFirewallConfigureProcess.execute("/usr/bin/gufw") def networkProxy(self): - if desktop_session == 'plasma': - networkProxyProcess.execute("/usr/bin/kcmshell5", list(set(['proxy']))) - elif desktop_session == 'kde': - networkProxyProcess.execute("/opt/kde/bin/kcmshell4", list(set(['proxy']))) - elif desktop_session == 'gnome': - networkProxyProcess.execute("/usr/bin/gnome-control-center", "network") - self.setProxyForSmart() + if desktop_session == 'plasma': + networkProxyProcess.execute("/usr/bin/kcmshell5", list(set(['proxy']))) + elif desktop_session == 'kde': + networkProxyProcess.execute("/opt/kde/bin/kcmshell4", list(set(['proxy']))) + elif desktop_session == 'gnome': + networkProxyProcess.execute("/usr/bin/gnome-control-center", "network") + self.setProxyForSmart() def SRPMSCheckUpgradeList(self): - checkSRPMSUpdatesTimer.stop() - global contatore, lista, NetsrpmsArg - if (self.networkOnline() == 0): - 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) + checkSRPMSUpdatesTimer.stop() + global contatore, lista, NetsrpmsArg + if (self.networkOnline() == 0): + 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() + 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, (_("Not Open Source openmamba components")), (_("The following components are available for update: ") + "\n\n" + Lista + "\n\n" + _("Ok to proceed?")), 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) - + global NetsrpmsArg, lista + if not lista == []: + Lista = self.Lista() + msg = QtGui.QMessageBox.question(menu, (_("Not Open Source openmamba components")), (_("The following components are available for update: ") + "\n\n" + Lista + "\n\n" + _("Ok to proceed?")), 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] + testo = '' + for a in lista: + testo = testo + a + ', ' + return testo[0:len(testo)-2] - - def main(): app = QtWidgets.QApplication(sys.argv) if (app.isSessionRestored()): app.exit(1) else: app.setQuitOnLastWindowClosed(0) - gettext.install('mambatray', '/usr/share/locale', unicode=1) + gettext.install('mambatray', '/usr/share/locale') w = QtWidgets.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)