Skip to content

Commit

Permalink
Show notify when the connection status changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tualatrix committed May 23, 2011
1 parent 6a971ff commit eb6f37c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions vpn-indicator
Expand Up @@ -7,6 +7,7 @@ import time
import dbus
import gobject
import gtk
import pynotify
import appindicator


Expand Down Expand Up @@ -78,8 +79,13 @@ class LogWindow(gtk.Window, GuiBuilder):
class VpnIndicator(appindicator.Indicator):
INTERFACE = "me.imtx.vpndaemon"

(STATUS_CONNECTING,
STATUS_CONNECTED,
STATUS_DISCONNECTED) = range(3)

_window = None
_current_config = None
_current_status = None
# animate_seq = ['changes-allow-symbolic', 'nm-vpn-standalone-lock']
animate_seq = ['nm-signal-00-secure', 'nm-signal-25-secure', 'nm-signal-50-secure', 'nm-signal-75-secure', 'nm-signal-100-secure']

Expand All @@ -93,6 +99,7 @@ class VpnIndicator(appindicator.Indicator):

self._init_daemon()
self._create_menu()
self._current_status = self.STATUS_CONNECTING

gobject.timeout_add(1000, self.checkvpn_status)

Expand All @@ -103,8 +110,14 @@ class VpnIndicator(appindicator.Indicator):
self.set_icon(animate_icon)
elif not self.is_vpn_connected() and not self.is_vpn_runned():
self.set_icon("changes-allow-symbolic")
if self._current_status != self.STATUS_DISCONNECTED:
pynotify.Notification(self._current_config, 'VPN disconnected', 'vpn-indicator').show()
self._current_status = self.STATUS_DISCONNECTED
elif self.is_vpn_connected() and self.is_vpn_runned():
if self._current_status != self.STATUS_CONNECTED:
pynotify.Notification(self._current_config, 'VPN Connection Established', 'vpn-indicator').show()
self.set_icon('nm-vpn-standalone-lock')
self._current_status = self.STATUS_CONNECTED
return True

def is_vpn_connected(self):
Expand Down Expand Up @@ -212,5 +225,6 @@ class VpnIndicator(appindicator.Indicator):


if __name__ == "__main__":
pynotify.init('vpn-indicator')
VpnIndicator()
gtk.main()

0 comments on commit eb6f37c

Please sign in to comment.