Compare commits

...

4 Commits

2 changed files with 29 additions and 47 deletions

View File

@ -1 +1 @@
VERSION=5.1 VERSION=5.2

View File

@ -1,19 +1,16 @@
#!/usr/bin/python3 #!/usr/bin/python3
# mambatray 2 # mambatray 2
# Copyright (C) 2011-2022 by Silvan Calarco # Copyright (C) 2011-2024 by Silvan Calarco
# Copyright (C) 2011 by michiamophil # Copyright (C) 2011 by michiamophil
# Distributed under the terms of the GPL version 3 FLOSS License # Distributed under the terms of the GPL version 3 FLOSS License
# #
import sys import sys
import os import os
import gettext import gettext
import libproxy
import distro import distro
from PyQt5 import uic from PyQt5.QtCore import Qt
from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtGui import QIcon, QCursor from PyQt5.QtGui import QIcon, QCursor
from PyQt5.QtWidgets import QSystemTrayIcon, QApplication, QMenu, QMainWindow,\ from PyQt5.QtWidgets import QSystemTrayIcon, QApplication, QMenu, QMessageBox
QMessageBox, QWidget
from PyQt5.QtCore import QTimer, QProcess from PyQt5.QtCore import QTimer, QProcess
DATADIR = os.path.dirname(os.path.realpath((__file__))) + "/" DATADIR = os.path.dirname(os.path.realpath((__file__))) + "/"
@ -23,8 +20,8 @@ class SystemTrayIcon(QSystemTrayIcon):
menu = None menu = None
def __init__(self, icon, parent=None): def __init__(self, icon):
QSystemTrayIcon.__init__(self, icon, parent) QSystemTrayIcon.__init__(self, icon)
global w, contatore, srpm, lista, NetsrpmsArg, nOre, desktop_session global w, contatore, srpm, lista, NetsrpmsArg, nOre, desktop_session
nOre = 2 nOre = 2
@ -35,8 +32,7 @@ class SystemTrayIcon(QSystemTrayIcon):
NetsrpmsArg = "-c" NetsrpmsArg = "-c"
lista = [] lista = []
contatore = 0 contatore = 0
w = parent self.menu = QMenu()
self.menu = QMenu(parent)
try: try:
desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION')) desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION'))
@ -68,6 +64,7 @@ class SystemTrayIcon(QSystemTrayIcon):
softwareBaseInstallsProcess = QProcess(self) softwareBaseInstallsProcess = QProcess(self)
softwareMenu = self.menu.addMenu(QIcon.fromTheme("applications-system"),_("Software")) softwareMenu = self.menu.addMenu(QIcon.fromTheme("applications-system"),_("Software"))
softwareManageAction = softwareMenu.addAction(QIcon.fromTheme("applications-other"),_("Add/Remove software packages...")) softwareManageAction = softwareMenu.addAction(QIcon.fromTheme("applications-other"),_("Add/Remove software packages..."))
softwareManageAction.triggered.connect(self.softwareManager) softwareManageAction.triggered.connect(self.softwareManager)
@ -87,6 +84,7 @@ class SystemTrayIcon(QSystemTrayIcon):
networkMenu = self.menu.addMenu(QIcon.fromTheme("preferences-system-network"), networkMenu = self.menu.addMenu(QIcon.fromTheme("preferences-system-network"),
_("Network")) _("Network"))
networkFirewallMenu = networkMenu.addMenu(QIcon.fromTheme("security-medium"),_("Firewall")) networkFirewallMenu = networkMenu.addMenu(QIcon.fromTheme("security-medium"),_("Firewall"))
networkFirewallDisableAction = networkFirewallMenu.addAction(QIcon.fromTheme("security-low"),_("Disable")) networkFirewallDisableAction = networkFirewallMenu.addAction(QIcon.fromTheme("security-low"),_("Disable"))
networkFirewallDisableAction.triggered.connect(self.networkFirewallDisable) networkFirewallDisableAction.triggered.connect(self.networkFirewallDisable)
@ -108,30 +106,18 @@ class SystemTrayIcon(QSystemTrayIcon):
self.setToolTip(_("{} control center").format(distro.name())) self.setToolTip(_("{} control center").format(distro.name()))
self.activated.connect(self.iconActivated) self.activated.connect(self.iconActivated)
self.setContextMenu(self.menu) self.setContextMenu(self.menu)
self.show()
# the first time refresh packages cache after 5 minutes # the first time refresh packages cache after 5 minutes
refreshPackagesTimer.start( 5 * 60000 ) refreshPackagesTimer.start( 5 * 60000 )
# the first time check for SRPMS updates after 4 minutes # the first time check for SRPMS updates after 4 minutes
checkSRPMSUpdatesTimer.start( 4 * 60000 ) checkSRPMSUpdatesTimer.start( 4 * 60000 )
def setProxyForSmart(self):
setProxyProcess = 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
def iconActivated(self, reason): def iconActivated(self, reason):
if reason in (QSystemTrayIcon.Trigger, QSystemTrayIcon.DoubleClick, QSystemTrayIcon.Context): if reason in (QSystemTrayIcon.Trigger, QSystemTrayIcon.DoubleClick, QSystemTrayIcon.Context):
self.contextMenu().popup(QCursor.pos()) # FIXME: on plasma wayland and left click menu will popup in the center of the screen
# disabling and only supporting right click.
if desktop_session != 'plasmawayland':
self.contextMenu().popup(QCursor.pos())
def about(self): def about(self):
aboutBox = QMessageBox(self.menu) aboutBox = QMessageBox(self.menu)
@ -152,15 +138,12 @@ class SystemTrayIcon(QSystemTrayIcon):
return networkOnlineProcess.execute("/usr/bin/nm-online",['-q','-x']) return networkOnlineProcess.execute("/usr/bin/nm-online",['-q','-x'])
def softwareManager(self): def softwareManager(self):
#self.setProxyForSmart()
softwareManagerProcess.execute("/usr/bin/plasma-discover") softwareManagerProcess.execute("/usr/bin/plasma-discover")
def softwareCheckUpgrades(self): def softwareCheckUpgrades(self):
#self.setProxyForSmart()
softwareCheckUpgradesProcess.start("/usr/bin/pkcon", ['refresh', 'force']) softwareCheckUpgradesProcess.start("/usr/bin/pkcon", ['refresh', 'force'])
def refreshPackagesCache(self): def refreshPackagesCache(self):
#self.setProxyForSmart()
refreshPackagesTimer.stop() refreshPackagesTimer.stop()
refreshPackagesCacheProcess.start("/usr/bin/pkcon", ['refresh', 'force']) refreshPackagesCacheProcess.start("/usr/bin/pkcon", ['refresh', 'force'])
@ -190,19 +173,18 @@ class SystemTrayIcon(QSystemTrayIcon):
self.showMessage("Firewall", _("Could not enable firewall")) self.showMessage("Firewall", _("Could not enable firewall"))
def networkFirewallConfigure(self): def networkFirewallConfigure(self):
if desktop_session == 'kde' or desktop_session == 'plasma': if desktop_session == 'kde' or desktop_session.startswith('plasma'):
networkFirewallConfigureProcess.execute("/usr/bin/kcmshell5", list(set(['firewall']))) networkFirewallConfigureProcess.execute("/usr/bin/kcmshell5", list(set(['firewall'])))
else: else:
networkFirewallConfigureProcess.execute("/usr/bin/gufw") networkFirewallConfigureProcess.execute("/usr/bin/gufw")
def networkProxy(self): def networkProxy(self):
if desktop_session == 'plasma': if desktop_session.startswith('plasma'):
networkProxyProcess.execute("/usr/bin/kcmshell5", list(set(['proxy']))) networkProxyProcess.execute("/usr/bin/kcmshell5", list(set(['proxy'])))
elif desktop_session == 'kde': elif desktop_session == 'kde':
networkProxyProcess.execute("/opt/kde/bin/kcmshell4", list(set(['proxy']))) networkProxyProcess.execute("/opt/kde/bin/kcmshell4", list(set(['proxy'])))
elif desktop_session == 'gnome': elif desktop_session == 'gnome':
networkProxyProcess.execute("/usr/bin/gnome-control-center", "network") networkProxyProcess.execute("/usr/bin/gnome-control-center", "network")
#self.setProxyForSmart()
def SRPMSCheckUpgradeList(self): def SRPMSCheckUpgradeList(self):
checkSRPMSUpdatesTimer.stop() checkSRPMSUpdatesTimer.stop()
@ -210,7 +192,7 @@ class SystemTrayIcon(QSystemTrayIcon):
if (self.networkOnline() == 0): if (self.networkOnline() == 0):
try: try:
SRPMUpdateProcess.start("/usr/bin/openmamba-netsrpms",[NetsrpmsArg,srpm[contatore]]) SRPMUpdateProcess.start("/usr/bin/openmamba-netsrpms",[NetsrpmsArg,srpm[contatore]])
except: #supera il limite dell'indice nella lista except:
contatore = 0 contatore = 0
if NetsrpmsArg == '-c': if NetsrpmsArg == '-c':
self.SRPMSAskAndInstall() self.SRPMSAskAndInstall()
@ -219,7 +201,7 @@ class SystemTrayIcon(QSystemTrayIcon):
NetsrpmsArg = '-c' NetsrpmsArg = '-c'
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000) checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
#viene eseguita per ogni SRPM al termine del processo SRPMUpdateProcess # run for each netsrpm at the end of SRPMUpdateProcess
def SRPMSCheckUpgrade(self, status): def SRPMSCheckUpgrade(self, status):
global contatore, lista global contatore, lista
if status == 1: if status == 1:
@ -227,13 +209,16 @@ class SystemTrayIcon(QSystemTrayIcon):
contatore += 1 contatore += 1
self.SRPMSCheckUpgradeList() self.SRPMSCheckUpgradeList()
#viene eseguita una volta terminata la fase di controllo degli aggiornamenti # netsrpm updates ask and install
def SRPMSAskAndInstall(self): def SRPMSAskAndInstall(self):
global NetsrpmsArg, lista global NetsrpmsArg, lista
if not lista == []: if not lista == []:
Lista = self.Lista() Lista = self.Lista()
msg = QMessageBox.question(self.menu,(_("Not Open Source {} components").format(distro.name())), msg = QMessageBox.question(self.menu,
(_("The following components are available for update: ") + "\n\n" + Lista + "\n\n" + _("Ok to proceed?")), QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) (_("Not Open Source {} components").format(distro.name())),
(_("The following components are available for update: ") +
"\n\n" + Lista + "\n\n" + _("Ok to proceed?")),
QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if msg == QMessageBox.Yes: if msg == QMessageBox.Yes:
NetsrpmsArg = '-u' NetsrpmsArg = '-u'
self.SRPMSCheckUpgradeList() self.SRPMSCheckUpgradeList()
@ -243,7 +228,8 @@ class SystemTrayIcon(QSystemTrayIcon):
else: else:
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000) checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
#partendo dalla lista lista (scusate il gioco di parole :) ) restituisce la lista in modo 'leggibile' # starting from the list "lista" returns the list in readable format
# FIXME: make this code more clear and clean
def Lista(self): def Lista(self):
testo = '' testo = ''
for a in lista: for a in lista:
@ -251,17 +237,13 @@ class SystemTrayIcon(QSystemTrayIcon):
return testo[0:len(testo)-2] return testo[0:len(testo)-2]
def main(): if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)
if app.isSessionRestored(): if app.isSessionRestored():
app.exit(1) app.exit(1)
else: else:
app.setQuitOnLastWindowClosed(0) app.setQuitOnLastWindowClosed(0)
gettext.install('mambatray', '/usr/share/locale') gettext.install('mambatray', '/usr/share/locale')
trayIcon = SystemTrayIcon(QIcon.fromTheme("mambatray") trayIcon = SystemTrayIcon(QIcon.fromTheme("mambatray"))
) trayIcon.show()
sys.exit(app.exec_()) sys.exit(app.exec())
if __name__ == '__main__':
main()