Kaydet (Commit) 58cef1c2 authored tarafından Bahadır Kandemir's avatar Bahadır Kandemir

Network-Applet: Tell network status to KDE

üst 42c87ed4
...@@ -10,6 +10,7 @@ from dbus.mainloop.qt3 import DBusQtMainLoop ...@@ -10,6 +10,7 @@ from dbus.mainloop.qt3 import DBusQtMainLoop
from qt import * from qt import *
from kdeui import * from kdeui import *
from kdecore import * from kdecore import *
import dcopext
class ConnectionItem(QCustomMenuItem): class ConnectionItem(QCustomMenuItem):
...@@ -55,8 +56,7 @@ class NetTray(KSystemTray): ...@@ -55,8 +56,7 @@ class NetTray(KSystemTray):
self.menuitems = {} self.menuitems = {}
# Build menus # Build menus
menu = self.contextMenu() self.updateMenu()
parent.setMenu(menu)
# Listen Net.Link signals # Listen Net.Link signals
self.link.listenSignals("Net.Link", self.handleSignals) self.link.listenSignals("Net.Link", self.handleSignals)
...@@ -65,6 +65,10 @@ class NetTray(KSystemTray): ...@@ -65,6 +65,10 @@ class NetTray(KSystemTray):
self.updateIcon() self.updateIcon()
self.show() self.show()
def updateMenu(self):
menu = self.contextMenu()
self.parent.setMenu(menu)
def updateIcon(self): def updateIcon(self):
state = "down" state = "down"
type_ = None type_ = None
...@@ -77,9 +81,13 @@ class NetTray(KSystemTray): ...@@ -77,9 +81,13 @@ class NetTray(KSystemTray):
if device_id not in devices: if device_id not in devices:
devices.append(device_id) devices.append(device_id)
profileName = profileInfo["name"]
state = profileInfo["state"].split()[0] state = profileInfo["state"].split()[0]
type_ = self.parent.info[package]["type"].split()[0] type_ = self.parent.info[package]["type"].split()[0]
if state == "up":
self.parent.updateStatus(profileName, "up")
if state in ("up", "connecting"): if state in ("up", "connecting"):
break break
...@@ -145,11 +153,14 @@ class NetTray(KSystemTray): ...@@ -145,11 +153,14 @@ class NetTray(KSystemTray):
profile = profileInfo profile = profileInfo
break break
if profile: if profile:
self.parent.updateStatus(profileName, "down")
self.profiles.remove(profile) self.profiles.remove(profile)
elif signal == "stateChanged": elif signal == "stateChanged":
profileName, action, data = args profileName, action, data = args
for profileInfo in self.profiles: for profileInfo in self.profiles:
if profileInfo["name"] == profileName: if profileInfo["name"] == profileName:
if action != "up":
self.parent.updateStatus(profileName, "down")
if len(data): if len(data):
profileInfo["state"] = "%s %s" % (action, data) profileInfo["state"] = "%s %s" % (action, data)
else: else:
...@@ -186,6 +197,7 @@ class Applet: ...@@ -186,6 +197,7 @@ class Applet:
self.info = {} self.info = {}
self.devices = {} self.devices = {}
self.profiles = {} self.profiles = {}
self.profiles_up = []
# KDE configuration # KDE configuration
self.config = KConfig("network-appletrc") self.config = KConfig("network-appletrc")
...@@ -193,6 +205,7 @@ class Applet: ...@@ -193,6 +205,7 @@ class Applet:
self.autoConnect = self.config.readBoolEntry("AutoConnect", True) self.autoConnect = self.config.readBoolEntry("AutoConnect", True)
self.showNotifications = self.config.readBoolEntry("ShowNotifications", True) self.showNotifications = self.config.readBoolEntry("ShowNotifications", True)
self.iconPerDevice = self.config.readBoolEntry("IconPerDevice", True) self.iconPerDevice = self.config.readBoolEntry("IconPerDevice", True)
self.notifyKDE = self.config.readBoolEntry("NotifyKDE", True)
# Load icons # Load icons
self.loadIcons() self.loadIcons()
...@@ -242,6 +255,21 @@ class Applet: ...@@ -242,6 +255,21 @@ class Applet:
tray = NetTray(self, self.link, profiles) tray = NetTray(self, self.link, profiles)
self.trays.append(tray) self.trays.append(tray)
def updateStatus(self, profile, status):
if status == "up":
if profile not in self.profiles_up:
self.profiles_up.append(profile)
elif status == "down":
if profile in self.profiles_up:
self.profiles_up.remove(profile)
dcop = self.app.dcopClient()
kded = dcopext.DCOPApp("kded", dcop)
if len(self.profiles_up) > 0:
kded.networkstatus.setNetworkStatus("COMARNetworkStatus", 8)
else:
kded.networkstatus.setNetworkStatus("COMARNetworkStatus", 3)
def loadIcons(self): def loadIcons(self):
def pix(name): def pix(name):
path = locate("data", "network-manager/" + name) path = locate("data", "network-manager/" + name)
...@@ -273,18 +301,20 @@ class Applet: ...@@ -273,18 +301,20 @@ class Applet:
KAction(i18n("Edit Connections..."), "configure", KShortcut.null(), self.startManager, menu).plug(menu) KAction(i18n("Edit Connections..."), "configure", KShortcut.null(), self.startManager, menu).plug(menu)
KAction(i18n("Connect Automatically"), "connect_creating", KShortcut.null(), self.scanAndConnect, menu).plug(menu) KAction(i18n("Connect Automatically"), "connect_creating", KShortcut.null(), self.scanAndConnect, menu).plug(menu)
menu.insertSeparator(1) menu.insertSeparator(1)
show_notify = menu.insertItem(i18n("Show Notifications"), self.setNotify, 0, -1, 1) self.show_notify = menu.insertItem(i18n("Show Notifications"), self.setNotify, 0, -1, 1)
menu.insertSeparator(1) menu.insertSeparator(1)
device_mid = menu.insertItem(i18n("Icon Per Device"), self.deviceGroup, 0, -1, 1) self.device_mid = menu.insertItem(i18n("Icon Per Device"), self.deviceGroup, 0, -1, 1)
single_mid = menu.insertItem(i18n("Single Icon"), self.noGroup, 0, -1, 1) self.single_mid = menu.insertItem(i18n("Single Icon"), self.noGroup, 0, -1, 1)
if self.iconPerDevice: if self.iconPerDevice:
menu.setItemChecked(device_mid, True) menu.setItemChecked(self.device_mid, True)
else: else:
menu.setItemChecked(single_mid, True) menu.setItemChecked(self.single_mid, True)
if self.showNotifications: if self.showNotifications:
menu.setItemChecked(show_notify, True) menu.setItemChecked(self.show_notify, True)
self.menu = menu
def startFirewall(self): def startFirewall(self):
os.system("firewall-config") os.system("firewall-config")
...@@ -296,8 +326,14 @@ class Applet: ...@@ -296,8 +326,14 @@ class Applet:
pass pass
def setNotify(self): def setNotify(self):
self.showNotifications = True if self.showNotifications:
self.config.writeEntry("ShowNotifications", True) self.showNotifications = False
self.config.writeEntry("ShowNotifications", False)
menu.setItemChecked(self.show_notify, False)
else:
self.showNotifications = True
self.config.writeEntry("ShowNotifications", True)
menu.setItemChecked(self.show_notify, True)
self.config.sync() self.config.sync()
def deviceGroup(self): def deviceGroup(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment