2020-07-22 17:35:36 +02:00
|
|
|
#!/usr/bin/python3
|
2013-04-24 18:43:15 +02:00
|
|
|
# mambatray 2
|
2024-02-25 15:16:46 +01:00
|
|
|
# Copyright (C) 2011-2024 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
|
2011-07-01 17:57:47 +02:00
|
|
|
import os
|
2011-04-26 21:25:03 +02:00
|
|
|
import gettext
|
2022-06-19 13:03:22 +02:00
|
|
|
import distro
|
2024-02-25 15:16:46 +01:00
|
|
|
from PyQt5.QtCore import Qt
|
2019-04-02 19:51:25 +02:00
|
|
|
from PyQt5.QtGui import QIcon, QCursor
|
2024-02-25 15:39:30 +01:00
|
|
|
from PyQt5.QtWidgets import QSystemTrayIcon, QApplication, QMenu, QMessageBox
|
2019-04-02 19:51:25 +02:00
|
|
|
from PyQt5.QtCore import QTimer, QProcess
|
2011-04-26 21:25:03 +02:00
|
|
|
|
2022-06-19 19:05:43 +02:00
|
|
|
DATADIR = os.path.dirname(os.path.realpath((__file__))) + "/"
|
|
|
|
|
2019-04-02 18:01:40 +02:00
|
|
|
|
2019-04-02 19:51:25 +02:00
|
|
|
class SystemTrayIcon(QSystemTrayIcon):
|
2011-04-26 21:25:03 +02:00
|
|
|
|
2019-07-12 13:08:41 +02:00
|
|
|
menu = None
|
2024-08-06 17:20:15 +02:00
|
|
|
contatore = 0
|
|
|
|
NetsrpmsArg = "-c"
|
|
|
|
lista = []
|
|
|
|
nOre = 2
|
|
|
|
srpm = [
|
|
|
|
"skype", "win32codecs", "msttcorefonts", "b43-firmware",
|
|
|
|
"virtualbox-extension-pack", "chromium-widevine", "spotify"
|
|
|
|
]
|
|
|
|
desktop_session = 'default'
|
|
|
|
xdg_session_type = 'x11'
|
|
|
|
|
|
|
|
refreshPackagesTimer = None
|
|
|
|
checkSRPMSUpdatesTimer = None
|
|
|
|
refreshPackagesCacheProcess = None
|
|
|
|
SRPMUpdateProcess = None
|
|
|
|
|
|
|
|
softwareManagerProcess = None
|
|
|
|
softwareCheckUpgradesProcess = None
|
|
|
|
softwareBaseInstallsProcess = None
|
|
|
|
|
|
|
|
networkOnlineProcess = None
|
|
|
|
networkFirewallDisableProcess = None
|
|
|
|
networkFirewallEnableProcess = None
|
|
|
|
networkFirewallConfigureProcess = None
|
|
|
|
networkProxyProcess = None
|
2019-07-12 13:08:41 +02:00
|
|
|
|
2024-02-25 16:39:08 +01:00
|
|
|
def __init__(self, icon):
|
|
|
|
QSystemTrayIcon.__init__(self, icon)
|
2019-04-02 19:51:25 +02:00
|
|
|
|
2024-02-25 16:39:08 +01:00
|
|
|
self.menu = QMenu()
|
2018-02-10 18:19:32 +01:00
|
|
|
|
2019-03-31 19:43:46 +02:00
|
|
|
try:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION'))
|
2019-03-31 19:43:46 +02:00
|
|
|
except:
|
2024-08-06 17:20:15 +02:00
|
|
|
None
|
2011-10-11 00:57:31 +02:00
|
|
|
|
2024-08-06 17:20:15 +02:00
|
|
|
try:
|
|
|
|
self.xdg_session_type = os.path.basename(os.getenv('XDG_SESSION_TYPE'))
|
|
|
|
except:
|
|
|
|
None
|
|
|
|
|
|
|
|
if self.desktop_session == 'default':
|
|
|
|
self.desktop_session = 'plasma'
|
|
|
|
elif self.desktop_session[:3] == 'kde':
|
|
|
|
self.desktop_session = 'kde'
|
2011-10-11 00:57:31 +02:00
|
|
|
|
2011-05-04 22:10:55 +02:00
|
|
|
# refresh packages cache timer
|
2024-08-06 17:20:15 +02:00
|
|
|
self.refreshPackagesTimer = QTimer(self)
|
|
|
|
self.checkSRPMSUpdatesTimer = QTimer(self)
|
|
|
|
self.refreshPackagesCacheProcess = QProcess(self)
|
|
|
|
self.SRPMUpdateProcess = QProcess(self)
|
|
|
|
self.networkOnlineProcess = QProcess(self)
|
|
|
|
self.refreshPackagesTimer.timeout.connect(self.refreshPackagesCache)
|
|
|
|
self.refreshPackagesCacheProcess.finished.connect(self.restartRefreshPackagesTimer)
|
|
|
|
self.checkSRPMSUpdatesTimer.timeout.connect(self.SRPMSCheckUpgradeList)
|
2019-03-31 19:43:46 +02:00
|
|
|
|
2011-04-26 21:25:03 +02:00
|
|
|
# software menu
|
2024-08-06 17:20:15 +02:00
|
|
|
self.softwareManagerProcess = QProcess(self)
|
|
|
|
self.softwareCheckUpgradesProcess = QProcess(self)
|
|
|
|
self.softwareBaseInstallsProcess = QProcess(self)
|
2011-04-26 21:25:03 +02:00
|
|
|
|
2024-08-06 17:20:15 +02:00
|
|
|
self.softwareMenu = self.menu.addMenu(QIcon.fromTheme("applications-system"),_("Software"))
|
2024-02-25 16:39:08 +01:00
|
|
|
|
2024-08-06 17:20:15 +02:00
|
|
|
self.softwareManageAction = self.softwareMenu.addAction(QIcon.fromTheme("applications-other"),_("Add/Remove software packages..."))
|
|
|
|
self.softwareManageAction.triggered.connect(self.softwareManager)
|
2011-04-26 21:25:03 +02:00
|
|
|
|
2024-08-06 17:20:15 +02:00
|
|
|
self.softwareCheckUpgradesAction = self.softwareMenu.addAction(QIcon.fromTheme("system-software-update"),_("Check for updates now..."))
|
|
|
|
self.softwareCheckUpgradesAction.triggered.connect(self.softwareCheckUpgrades)
|
2011-04-26 21:25:03 +02:00
|
|
|
|
2024-08-06 17:20:15 +02:00
|
|
|
self.softwareBaseInstallsAction = self.softwareMenu.addAction(QIcon.fromTheme("mambabase"),_("{} components...").format(distro.name()))
|
|
|
|
self.softwareBaseInstallsAction.triggered.connect(self.softwareBaseInstalls)
|
2019-03-31 19:43:46 +02:00
|
|
|
|
2011-04-26 21:25:03 +02:00
|
|
|
# network menu
|
2024-08-06 17:20:15 +02:00
|
|
|
self.networkFirewallDisableProcess = QProcess(self)
|
|
|
|
self.networkFirewallEnableProcess = QProcess(self)
|
|
|
|
self.networkFirewallConfigureProcess = QProcess(self)
|
|
|
|
self.networkProxyProcess = QProcess(self)
|
|
|
|
|
|
|
|
self.networkMenu = self.menu.addMenu(QIcon.fromTheme("preferences-system-network"), _("Network"))
|
|
|
|
|
|
|
|
self.networkFirewallMenu = self.networkMenu.addMenu(QIcon.fromTheme("security-medium"),_("Firewall"))
|
|
|
|
self.networkFirewallDisableAction = self.networkFirewallMenu.addAction(QIcon.fromTheme("security-low"),_("Disable"))
|
|
|
|
self.networkFirewallDisableAction.triggered.connect(self.networkFirewallDisable)
|
|
|
|
self.networkFirewallDisableProcess.finished.connect(self.networkFirewallDisableMessage)
|
|
|
|
self.networkFirewallEnableAction = self.networkFirewallMenu.addAction(QIcon.fromTheme("security-high"),_("Enable"))
|
|
|
|
self.networkFirewallEnableAction.triggered.connect(self.networkFirewallEnable)
|
|
|
|
self.networkFirewallEnableProcess.finished.connect(self.networkFirewallEnableMessage)
|
|
|
|
self.networkFirewallConfigureAction = self.networkFirewallMenu.addAction(QIcon.fromTheme("security-medium"),_("Configure..."))
|
|
|
|
self.networkFirewallConfigureAction.triggered.connect(self.networkFirewallConfigure)
|
|
|
|
self.networkProxyAction = self.networkMenu.addAction(QIcon.fromTheme("network-server"),_("Proxy..."))
|
|
|
|
self.networkProxyAction.triggered.connect(self.networkProxy)
|
|
|
|
self.SRPMUpdateProcess.finished.connect(self.SRPMSCheckUpgrade)
|
2011-06-30 06:25:36 +02:00
|
|
|
|
2011-04-26 21:25:03 +02:00
|
|
|
# about box
|
2024-08-06 17:20:15 +02:00
|
|
|
self.aboutAction = self.menu.addSeparator()
|
|
|
|
self.aboutAction = self.menu.addAction(QIcon.fromTheme("system-logo"),_("About"))
|
|
|
|
self.aboutAction.triggered.connect(self.about)
|
2019-03-31 19:43:46 +02:00
|
|
|
|
2022-06-19 13:03:22 +02:00
|
|
|
self.setToolTip(_("{} control center").format(distro.name()))
|
2011-04-26 21:25:03 +02:00
|
|
|
self.activated.connect(self.iconActivated)
|
2019-07-12 13:08:41 +02:00
|
|
|
self.setContextMenu(self.menu)
|
2011-05-04 22:10:55 +02:00
|
|
|
|
|
|
|
# the first time refresh packages cache after 5 minutes
|
2024-08-06 17:20:15 +02:00
|
|
|
self.refreshPackagesTimer.start( 5 * 60000 )
|
2011-10-11 00:11:06 +02:00
|
|
|
# the first time check for SRPMS updates after 4 minutes
|
2024-08-06 17:20:15 +02:00
|
|
|
self.checkSRPMSUpdatesTimer.start( 4 * 60000 )
|
2011-05-04 22:10:55 +02:00
|
|
|
|
2011-04-26 21:25:03 +02:00
|
|
|
def iconActivated(self, reason):
|
2019-04-02 19:51:25 +02:00
|
|
|
if reason in (QSystemTrayIcon.Trigger, QSystemTrayIcon.DoubleClick, QSystemTrayIcon.Context):
|
2024-02-25 16:39:08 +01:00
|
|
|
# FIXME: on plasma wayland and left click menu will popup in the center of the screen
|
|
|
|
# disabling and only supporting right click.
|
2024-08-06 17:20:15 +02:00
|
|
|
if self.xdg_session_type != 'wayland':
|
2024-02-25 16:39:08 +01:00
|
|
|
self.contextMenu().popup(QCursor.pos())
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def about(self):
|
2022-06-19 19:05:43 +02:00
|
|
|
aboutBox = QMessageBox(self.menu)
|
|
|
|
aboutBox.setWindowIcon(QIcon.fromTheme("mambatray"))
|
|
|
|
aboutBox.setWindowTitle(_("About"))
|
|
|
|
aboutBox.setText(
|
2022-06-19 13:03:22 +02:00
|
|
|
"<center><b>"+_("{} control center").format(distro.name()+"</b>"
|
2022-06-19 19:05:43 +02:00
|
|
|
"<br/><br/>"+distro.name(pretty=True)+
|
|
|
|
"<br/><br/><a href=\""+distro.os_release_info()['home_url']+
|
|
|
|
"\">" + distro.os_release_info()['home_url'] + "</a>"
|
|
|
|
"</center>"))
|
|
|
|
aboutBox.setTextFormat(Qt.RichText)
|
|
|
|
aboutBox.setIconPixmap(QIcon.fromTheme("system-logo").pixmap(32));
|
|
|
|
aboutBox.setWindowModality(Qt.NonModal);
|
|
|
|
aboutBox.exec()
|
2011-04-26 21:25:03 +02:00
|
|
|
|
2013-05-14 15:42:02 +02:00
|
|
|
def networkOnline(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
return self.networkOnlineProcess.execute("/usr/bin/nm-online",['-q','-x'])
|
2013-05-14 15:42:02 +02:00
|
|
|
|
2011-04-26 21:25:03 +02:00
|
|
|
def softwareManager(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
self.softwareManagerProcess.execute("/usr/bin/plasma-discover")
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def softwareCheckUpgrades(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
self.softwareCheckUpgradesProcess.start("/usr/bin/pkcon", ['refresh', 'force'])
|
2013-04-24 18:43:15 +02:00
|
|
|
|
2011-05-04 22:10:55 +02:00
|
|
|
def refreshPackagesCache(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
self.refreshPackagesTimer.stop()
|
|
|
|
self.refreshPackagesCacheProcess.start("/usr/bin/pkcon", ['refresh', 'force'])
|
2011-05-04 22:10:55 +02:00
|
|
|
|
|
|
|
def restartRefreshPackagesTimer(self,status):
|
|
|
|
# check every 4 hours and 31 minutes */
|
2024-08-06 17:20:15 +02:00
|
|
|
self.refreshPackagesTimer.start( (4 * 60 + 31) * 60000)
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def softwareBaseInstalls(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
self.softwareBaseInstallsProcess.start("/usr/bin/mambabase")
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def networkFirewallDisable(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
self.networkFirewallDisableProcess.start("sudo",['/usr/sbin/ufw','disable'])
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def networkFirewallDisableMessage(self,status):
|
2019-04-02 19:51:25 +02:00
|
|
|
if (status == QProcess.NormalExit):
|
2011-04-26 21:25:03 +02:00
|
|
|
self.showMessage("Firewall", _("Firewall disabled in current session"))
|
|
|
|
else:
|
2019-04-02 18:01:40 +02:00
|
|
|
self.showMessage("Firewall", _("Could not disable firewall"))
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def networkFirewallEnable(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
self.networkFirewallEnableProcess.start("sudo",['/usr/sbin/ufw','enable'])
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def networkFirewallEnableMessage(self,status):
|
2019-04-02 19:51:25 +02:00
|
|
|
if (status == QProcess.NormalExit):
|
2011-04-26 21:25:03 +02:00
|
|
|
self.showMessage("Firewall", _("Firewall enabled in current session"))
|
|
|
|
else:
|
2012-11-08 01:44:10 +01:00
|
|
|
self.showMessage("Firewall", _("Could not enable firewall"))
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def networkFirewallConfigure(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
if self.desktop_session == 'kde' or self.desktop_session.startswith('plasma'):
|
|
|
|
self.networkFirewallConfigureProcess.execute("/usr/bin/kcmshell5", list(set(['firewall'])))
|
2019-03-31 19:43:46 +02:00
|
|
|
else:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.networkFirewallConfigureProcess.execute("/usr/bin/gufw")
|
2011-04-26 21:25:03 +02:00
|
|
|
|
|
|
|
def networkProxy(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
if self.desktop_session.startswith('plasma'):
|
|
|
|
self.networkProxyProcess.execute("/usr/bin/kcmshell5", list(set(['proxy'])))
|
|
|
|
elif self.desktop_session == 'kde':
|
|
|
|
self.networkProxyProcess.execute("/opt/kde/bin/kcmshell4", list(set(['proxy'])))
|
|
|
|
elif self.desktop_session == 'gnome':
|
|
|
|
self.networkProxyProcess.execute("/usr/bin/gnome-control-center", "network")
|
2011-04-26 21:25:03 +02:00
|
|
|
|
2011-06-30 06:25:36 +02:00
|
|
|
def SRPMSCheckUpgradeList(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
self.checkSRPMSUpdatesTimer.stop()
|
2019-03-31 19:43:46 +02:00
|
|
|
if (self.networkOnline() == 0):
|
|
|
|
try:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.SRPMUpdateProcess.start("/usr/bin/openmamba-netsrpms",[self.NetsrpmsArg,self.srpm[self.contatore]])
|
2024-02-25 15:39:30 +01:00
|
|
|
except:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.contatore = 0
|
|
|
|
if self.NetsrpmsArg == '-c':
|
2019-03-31 19:43:46 +02:00
|
|
|
self.SRPMSAskAndInstall()
|
|
|
|
else:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.lista = []
|
|
|
|
self.NetsrpmsArg = '-c'
|
|
|
|
self.checkSRPMSUpdatesTimer.start((self.nOre * 60) * 60000)
|
2013-05-14 15:42:02 +02:00
|
|
|
|
2024-02-25 15:39:30 +01:00
|
|
|
# run for each netsrpm at the end of SRPMUpdateProcess
|
2011-06-30 06:25:36 +02:00
|
|
|
def SRPMSCheckUpgrade(self, status):
|
2019-03-31 19:43:46 +02:00
|
|
|
if status == 1:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.lista.append(self.srpm[self.contatore])
|
|
|
|
self.contatore += 1
|
2019-03-31 19:43:46 +02:00
|
|
|
self.SRPMSCheckUpgradeList()
|
2011-06-30 06:25:36 +02:00
|
|
|
|
2024-02-25 15:39:30 +01:00
|
|
|
# netsrpm updates ask and install
|
2011-06-30 06:25:36 +02:00
|
|
|
def SRPMSAskAndInstall(self):
|
2024-08-06 17:20:15 +02:00
|
|
|
if not self.lista == []:
|
|
|
|
self.Lista = self.PrintLista()
|
2024-02-25 15:39:30 +01:00
|
|
|
msg = QMessageBox.question(self.menu,
|
|
|
|
(_("Not Open Source {} components").format(distro.name())),
|
|
|
|
(_("The following components are available for update: ") +
|
2024-08-06 17:20:15 +02:00
|
|
|
"\n\n" + self.Lista + "\n\n" + _("Ok to proceed?")),
|
2024-02-25 15:39:30 +01:00
|
|
|
QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
|
2019-04-02 18:01:40 +02:00
|
|
|
if msg == QMessageBox.Yes:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.NetsrpmsArg = '-u'
|
2019-03-31 19:43:46 +02:00
|
|
|
self.SRPMSCheckUpgradeList()
|
|
|
|
else:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.lista = []
|
|
|
|
self.checkSRPMSUpdatesTimer.start((self.nOre * 60) * 60000)
|
2019-03-31 19:43:46 +02:00
|
|
|
else:
|
2024-08-06 17:20:15 +02:00
|
|
|
self.checkSRPMSUpdatesTimer.start((self.nOre * 60) * 60000)
|
2019-03-31 19:43:46 +02:00
|
|
|
|
2024-02-25 15:39:30 +01:00
|
|
|
# starting from the list "lista" returns the list in readable format
|
|
|
|
# FIXME: make this code more clear and clean
|
2024-08-06 17:20:15 +02:00
|
|
|
def PrintLista(self):
|
2019-03-31 19:43:46 +02:00
|
|
|
testo = ''
|
2024-08-06 17:20:15 +02:00
|
|
|
for a in self.lista:
|
2022-06-19 19:05:43 +02:00
|
|
|
testo = testo + a + ', '
|
2019-03-31 19:43:46 +02:00
|
|
|
return testo[0:len(testo)-2]
|
2011-06-30 06:25:36 +02:00
|
|
|
|
2019-04-02 18:01:40 +02:00
|
|
|
|
2024-02-25 16:39:08 +01:00
|
|
|
if __name__ == '__main__':
|
2019-04-02 18:01:40 +02:00
|
|
|
app = QApplication(sys.argv)
|
2024-08-06 17:20:15 +02:00
|
|
|
app.setDesktopFileName("mambatray")
|
|
|
|
|
2019-04-02 19:51:25 +02:00
|
|
|
if app.isSessionRestored():
|
2011-04-28 10:57:22 +02:00
|
|
|
app.exit(1)
|
|
|
|
else:
|
|
|
|
app.setQuitOnLastWindowClosed(0)
|
2019-03-31 19:43:46 +02:00
|
|
|
gettext.install('mambatray', '/usr/share/locale')
|
2024-02-25 16:39:08 +01:00
|
|
|
trayIcon = SystemTrayIcon(QIcon.fromTheme("mambatray"))
|
|
|
|
trayIcon.show()
|
|
|
|
sys.exit(app.exec())
|