From 85aaf2ea874c9f4e2bb0e66f37cc61217a781b7e Mon Sep 17 00:00:00 2001 From: Jordan McCarthy Date: Fri, 25 Oct 2013 21:25:41 -0400 Subject: [PATCH] Added context-aware menu items for fns that should only be available when connected to mesh; fixed bug in position of commotionc init --- commotion_applet_support.py | 50 +++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/commotion_applet_support.py b/commotion_applet_support.py index a59851b..c26b9ad 100755 --- a/commotion_applet_support.py +++ b/commotion_applet_support.py @@ -218,9 +218,9 @@ class CommotionMeshApplet(): nm_icon_dir = '/usr/share/icons/hicolor/22x22/apps' def __init__(self, portinghacks): + self.commotion = commotionc.CommotionCore('commotion-mesh-applet') self.port = portinghacks self.meshstatus = MeshStatus(portinghacks) - self.commotion = commotionc.CommotionCore('commotion-mesh-applet') self.menu = Gtk.Menu() # update the menu whenever NetworkManager changes NetworkManager.NetworkManager.connect_to_signal('StateChanged', self.create_menu) @@ -315,6 +315,7 @@ def choose_profile(self, *arguments): devices = NetworkManager.NetworkManager.GetDevices() for dev in devices: if dev.DeviceType == NetworkManager.NM_DEVICE_TYPE_WIFI and dev.State > 20: #dev.State values 0, 10, and 20 indicate that interface is in an unusable state + #dev.Interface, dev.Driver break else: @@ -355,6 +356,11 @@ def create_menu(self, ignored=None): self.add_menu_label('BSSID: ' + profile[1]) self.add_menu_label('Channel: ' + str(profile[2])) self.add_menu_separator() + self.add_menu_item('Browse Local Apps...', self.launch_app_browser) + self.add_menu_item('Show Mesh Status', self.show_mesh_status) + self.add_menu_item('Save Mesh Status To File...', self.save_mesh_status_to_file) + self.add_menu_item('Disconnect From Mesh', self.disconnect) + self.add_menu_separator() self.add_menu_label('Available Profiles') for profile in profiles: @@ -366,25 +372,41 @@ def create_menu(self, ignored=None): else: self.add_menu_item(profile[0], self.choose_profile) + self.add_menu_item('Edit Mesh Network Profiles...', self.edit_profiles) + #self.add_menu_item('Show Debug Log', self.show_debug_log) + if not header_added: + self.add_menu_label('Browse Local Apps...') + self.add_menu_label('Show Mesh Status') + self.add_menu_label('Save Mesh Status To File...') + self.add_menu_label('Disconnect From Mesh') self.add_menu_separator() - self.add_menu_item('Show Mesh Status', self.show_mesh_status) - self.add_menu_item('Show Debug Log', self.show_debug_log) - self.add_menu_item('Save Mesh Status To File...', self.save_mesh_status_to_file) - self.add_menu_item('Disconnect From Mesh', self.disconnect) - self.add_menu_separator() - self.add_menu_item('Edit Mesh Network Profiles', self.edit_profiles) self.add_menu_about() self.add_menu_quit() return True + def edit_profiles(self, *arguments): + subprocess.Popen(['gksudo', 'xterm -e vi ' + self.commotion.profiledir]) + instructions = Gtk.MessageDialog(toplevel, + self.port.DIALOG_DESTROY_WITH_PARENT, + self.port.MESSAGE_INFO, + (Gtk.BUTTONS_OK), + 'All mesh profile files are stored in this folder. Make any desired changes to any of the profiles (as the root user), and then close the file browser.') + instructions.run() + instructions.destroy() + + + def launch_app_browser(self, *arguments): + os.system('xdg-open http://localhost:8080 &') + + def show_mesh_status(self, *arguments): self.meshstatus.show() - def show_debug_log(self, *arguments): - os.system('xdg-open /tmp/nm-dispatcher-olsrd.log &') + #def show_debug_log(self, *arguments): + # os.system('xdg-open /tmp/nm-dispatcher-olsrd.log &') def save_mesh_status_to_file(self, *arguments): @@ -436,16 +458,6 @@ def disconnect(self, *arguments): if d.Managed and d.DeviceType == NetworkManager.NM_DEVICE_TYPE_WIFI: NetworkManager.NetworkManager.DeactivateConnection(ac) - def edit_profiles(self, *arguments): - subprocess.Popen(['gksudo', 'xterm -e vi ' + self.commotion.profiledir]) - instructions = Gtk.MessageDialog(toplevel, - self.port.DIALOG_DESTROY_WITH_PARENT, - self.port.MESSAGE_INFO, - (Gtk.BUTTONS_OK), - 'All mesh profile files are stored in this folder. Make any desired changes to any of the profiles (as the root user), and then close the file browser.') - instructions.run() - instructions.destroy() - def show_about(self, *arguments): about_dialog = Gtk.AboutDialog() about_dialog.set_destroy_with_parent(True)