6 from launcher import Launcher
13 def __init__(self, launcher, application_settings, network_settings, parent_window):
14 self._application_settings = application_settings
15 self._network_settings = network_settings
16 self._parent = parent_window
17 self._launcher = launcher
18 self._popup = self._application_settings.getUsePopup()
21 def connectionEstablished(self, ssid):
22 settings = self._network_settings.get(ssid)
24 if self.showDecisionDialog(ssid):
25 defaults = self._network_settings.getDefaultSettings()
26 self.launchBrowser(defaults)
29 if settings.getLaunchingOfBrowserEnabled():
30 self.launchBrowser(settings)
33 def launchBrowser(self, settings):
34 browser_name = settings.getNameOfBrowserToLaunch()
35 browser_options = settings.getBrowserOptions()
36 if 'url' in browser_options:
37 self._launcher.launchBrowser(browser_name, browser_options)
38 # the following line is the backwards compatible line
40 settings = self._network_settings.getDefaultSettings()
41 self.launchBrowser(settings)
43 def showDecisionDialog(self, ssid):
47 dialog = self._createDialog(ssid)
53 launch_browser = (result == gtk.RESPONSE_YES)
54 if checkbox.get_active():
55 setting = NetworkSetting()
56 setting.setNetworkName(ssid)
57 setting.setLaunchingOfBrowserEnabled(launch_browser)
58 self._network_settings.save(setting)
64 self._connection = conic.Connection()
65 self._connection.connect("connection-event", self._connectionEventCallback)
66 self._connection.set_property("automatic-connection-events", True)
67 self._application_settings.registerUsePopupListener(self._usePopupEventCallback)
72 self._application_settings.unregisterUsePopupListener(self._usePopupEventCallback)
73 self._connection.set_property("automatic-connection-events", False)
76 def _createDialog(self, ssid):
77 dialog = gtk.Dialog(ssid, self._parent)
78 dialog.vbox.set_homogeneous(False)
80 dialog.add_button(_('No'), gtk.RESPONSE_NO)
81 dialog.add_button(_('Yes'), gtk.RESPONSE_YES)
83 label = gtk.Label(_('New network connection established - do you wish to launch a browser?'))
84 label.set_line_wrap(True)
85 #label.set_justify(gtk.JUSTIFY_LEFT)
86 #label.set_alignment(0, 0.5)
87 dialog.vbox.add(label)
89 checkbox = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
90 checkbox.set_label(_('Remember this decision'))
91 checkbox.set_active(True)
92 dialog.vbox.add(checkbox)
97 def _connectionEventCallback(self, connection, event):
98 status = event.get_status()
99 if status == conic.STATUS_CONNECTED:
100 # assemble id > name dict
102 iaps = connection.get_all_iaps()
104 iap_id = iap.get_id()
105 iap_name = iap.get_name()
106 iap_id_to_name[iap_id] = iap_name
108 # get name of network
109 iap_id = event.get_iap_id()
111 if (iap_id_to_name.has_key(iap_id)):
112 iap_name = iap_id_to_name[iap_id]
113 self.connectionEstablished(iap_name)
116 def _usePopupEventCallback(self, gconfClient, id, gconfEntry, x):
117 self._popup = gconfEntry.get_value().get_bool()
120 def _startLoop(self):