aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.com>2011-01-16 15:20:13 -0200
committerEugeni Dodonov <eugeni@mandriva.com>2011-01-16 15:20:13 -0200
commitac555d6b7644776b4351eb4981dab3aedc135883 (patch)
tree936a4150e8047a9f03f8082f672bd15c4ae4142f
parented4ded0fb539b3a689ff5f9329770ed57b0c573c (diff)
downloadnet_monitor-ac555d6b7644776b4351eb4981dab3aedc135883.tar
net_monitor-ac555d6b7644776b4351eb4981dab3aedc135883.tar.gz
net_monitor-ac555d6b7644776b4351eb4981dab3aedc135883.tar.bz2
net_monitor-ac555d6b7644776b4351eb4981dab3aedc135883.tar.xz
net_monitor-ac555d6b7644776b4351eb4981dab3aedc135883.zip
added initial plasma prototype
-rw-r--r--plasma/Makefile7
-rw-r--r--plasma/contents/code/main.py70
-rw-r--r--plasma/metadata.desktop17
3 files changed, 94 insertions, 0 deletions
diff --git a/plasma/Makefile b/plasma/Makefile
new file mode 100644
index 0000000..ba9252b
--- /dev/null
+++ b/plasma/Makefile
@@ -0,0 +1,7 @@
+all: plasmapkg
+
+plasmapkg:
+ zip -r ../net_monitor_plasma.zip contents/ metadata.desktop
+
+clean:
+ rm -f ../net_monitor_plasma.zip
diff --git a/plasma/contents/code/main.py b/plasma/contents/code/main.py
new file mode 100644
index 0000000..45f7fec
--- /dev/null
+++ b/plasma/contents/code/main.py
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+# Net_monitor plasma interface
+#
+# Copyright, (C) Eugeni Dodonov <eugeni@mandriva.com>, 2011
+#
+
+from PyQt4.QtCore import Qt
+from PyKDE4.plasma import Plasma
+from PyKDE4 import plasmascript
+
+# localization
+import gettext
+try:
+ gettext.install("net_monitor")
+except IOError:
+ _ = str
+
+from net_monitor import Monitor
+
+class NetMonitor(plasmascript.Applet):
+ def __init__(self,parent,args=None):
+ plasmascript.Applet.__init__(self,parent)
+
+ self.monitor = Monitor()
+ self.ifaces = self.monitor.readnet()
+
+ self.enabled_ifaces = []
+ self.wireless_ifaces = filter(self.monitor.has_wireless, self.ifaces.keys())
+
+ sorted_ifaces = self.ifaces.keys()
+ sorted_ifaces.sort()
+
+ net=self.monitor.readnet()
+
+ for iface in sorted_ifaces:
+ device_exists, data_in, data_out = self.monitor.get_traffic(iface,net)
+ self.ifaces[iface] = {'data_in': 0,
+ 'data_out': 0,
+ 'total_in': 0,
+ 'total_out': 0,
+ 'graph': None,
+ 'histogram': [],
+ 'address': "",
+ }
+ if self.monitor.has_network_accounting(iface):
+ self.enabled_ifaces.append(iface)
+
+ self.refresh_connections()
+
+ def refresh_connections(self):
+ """Updates connections"""
+ for proto in ["tcp", "udp"]:
+ connections = self.monitor.get_connections(proto=proto)
+ for loc_addr, loc_port, rem_addr, rem_port, status in connections:
+ print "%s - %s - %s - %s - %s - %s" % (proto, loc_addr, loc_port, rem_addr, rem_port, status)
+
+
+ def init(self):
+ self.setHasConfigurationInterface(False)
+ self.resize(125, 125)
+ self.setAspectRatioMode(Plasma.Square)
+
+ def paintInterface(self, painter, option, rect):
+ painter.save()
+ painter.setPen(Qt.black)
+ painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter, "Hello net_monitor!")
+ painter.restore()
+
+def CreateApplet(parent):
+ return NetMonitor(parent)
diff --git a/plasma/metadata.desktop b/plasma/metadata.desktop
new file mode 100644
index 0000000..87c2db8
--- /dev/null
+++ b/plasma/metadata.desktop
@@ -0,0 +1,17 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=Network Monitor
+Type=Service
+ServiceTypes=Plasma/Applet
+Icon=chronometer
+X-Plasma-API=python
+X-Plasma-MainScript=code/main.py
+X-KDE-PluginInfo-Author=Eugeni Dodonov
+X-KDE-PluginInfo-Email=eugeni@mandriva.com
+X-KDE-PluginInfo-Name=net_monitor
+X-KDE-PluginInfo-Version=1.0
+X-KDE-PluginInfo-Website=http://git.mandriva.com/
+X-KDE-PluginInfo-Category=Network
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true