mambatray: configure smart through libproxy (requires python-libproxy)

This commit is contained in:
Silvan Calarco 2013-04-24 18:43:15 +02:00
parent 77e45e4e2b
commit cac69a870d

View File

@ -1,12 +1,13 @@
#!/usr/bin/python
# mambatray 2
# Copyright (C) 2011 by Silvan Calarco
# Copyright (C) 2011-2013 by Silvan Calarco
# Copyright (C) 2011 by michiamophil
# Distributed under the terms of the GPL version 3 FLOSS License
#
import sys
import os
import gettext
import libproxy
from PyQt4.QtCore import SIGNAL
from PyQt4 import QtGui
from PyQt4 import QtCore
@ -93,6 +94,19 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
# the first time check for SRPMS updates after 4 minutes
checkSRPMSUpdatesTimer.start( 4 * 60000 )
def setProxyForSmart(self):
setProxyProcess = QtCore.QProcess(self)
pf = libproxy.ProxyFactory()
for protocol in ["http","https","ftp"]:
proxies = pf.getProxies("%s://www.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 (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick):
menu.popup(self.geometry().center())
@ -110,7 +124,7 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
version = _("Error: Unable to find /etc/openmamba-release")
QtGui.QMessageBox.about(menu, _("About"),
"<center><b>"+_("openmamba control center")+"</b>"
"<br><br>Copyright(c) 2011 by Silvan Calarco"
"<br><br>Copyright(c) 2011-2013 by Silvan Calarco"
"<br>Copyright(c) 2011 by michiamophil"
"<br><br><b>"+_("System info:")+"</b></center>"
""+_(version)+"<center><a href=\"http://www.openmamba.org\">http://www.openmamba.org</a></center>")
@ -125,17 +139,21 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
return result
def softwareManager(self):
self.setProxyForSmart()
if desktop_session == 'kde':
softwareManagerProcess.execute("/opt/kde/bin/apper")
else:
softwareManagerProcess.execute("/usr/bin/gpk-application")
def softwareCheckUpgrades(self):
self.setProxyForSmart()
if desktop_session == 'kde':
softwareCheckUpgradesProcess.start("/opt/kde/bin/apper", ['--updates'])
else:
softwareCheckUpgradesProcess.start("/usr/bin/gpk-update-viewer")
def refreshPackagesCache(self):
self.setProxyForSmart()
refreshPackagesTimer.stop()
refreshPackagesCacheProcess.start("/usr/bin/pkcon", ['refresh'])
@ -176,6 +194,7 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
networkProxyProcess.execute("/opt/kde/bin/kcmshell4", QtCore.QStringList(list(set(['proxy']))))
elif desktop_session == 'gnome':
networkProxyProcess.execute("/usr/bin/gnome-control-center", "network")
self.setProxyForSmart()
def SRPMSCheckUpgradeList(self):
checkSRPMSUpdatesTimer.stop()