Merge lp:~kvalo/indicator-network/settings-backend-begin into lp:~indicator-applet-developers/indicator-network/indicator-network

Proposed by Kalle Valo on 2010-12-13
Status: Merged
Merged at revision: 122
Proposed branch: lp:~kvalo/indicator-network/settings-backend-begin
Merge into: lp:~indicator-applet-developers/indicator-network/indicator-network
Diff against target: 767 lines (+565/-80)
8 files modified
src/settings/indicatorNetworkSettings/app.py (+4/-0)
src/settings/indicatorNetworkSettings/backend/connection.py (+0/-18)
src/settings/indicatorNetworkSettings/backend/connmanmanager.py (+160/-0)
src/settings/indicatorNetworkSettings/backend/device.py (+31/-42)
src/settings/indicatorNetworkSettings/backend/devicemanager.py (+153/-0)
src/settings/indicatorNetworkSettings/backend/service.py (+195/-0)
src/settings/indicatorNetworkSettings/frontend/pages/connections.py (+5/-5)
src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wireless.py (+17/-15)
To merge this branch: bzr merge lp:~kvalo/indicator-network/settings-backend-begin
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve on 2010-12-14
Alex Launi (community) 2010-12-13 Needs Fixing on 2010-12-13
Review via email: mp+43548@code.launchpad.net

Description of the Change

Beginnings of backend implementation for the new settings window.

To post a comment you must log in.
Alex Launi (alexlauni) wrote :

1. Make check fails due to an out of date POTFILES.in file. Probably will want to fix this for translators' sake (and for make check's sake).

2. line 239 in 'src/settings/indicatorNetworkSettings/backend/device.py' looks like a good place to define a custom Exception, maybe UnknownDeviceTypeError (type)

3. I don't really like the prints. Is there a python version of g_debug? If this is how you've done the rest of the project then keep going, but a lot of it looks like

review: Needs Fixing
Kalle Valo (kvalo) wrote :

On 12/13/2010 10:22 PM, Alex Launi wrote:
> Review: Needs Fixing
>
> 1. Make check fails due to an out of date POTFILES.in file. Probably will want to fix this for translators' sake (and for make check's sake).

That was actually fixed already on trunk, I just forgot to merge trunk.
I did that now and the issue is fixed.

> 2. line 239 in 'src/settings/indicatorNetworkSettings/backend/device.py' looks like a good place to define a custom Exception, maybe UnknownDeviceTypeError (type)

Added.

> 3. I don't really like the prints. Is there a python version of g_debug? If this is how you've done the rest of the project then keep going, but a lot of it looks like

Currently there is no proper logging framework in
indicator-network-settings. I'm planning to implement such in the
feature, but not right now due to other tasks. But actually there were
two accidental prints from a debuggin session, I removed those now.

I have now pushed fixes to the branch. Please take a look. Thank you for
the review.

Kalle

Regarding logging you can use the build in 'logging' module of Python. It's highly run-time configurable. But that can wait to another merge request of course.

Looks good to me otherwise.

I can see why you wanna bind libconnman since you have a lot of sync DBus calls in here - it's less catastrophic for an app of course, but it may still lock up the ui.

review: Approve
Kalle Valo (kvalo) wrote :

Mikkel Kamstrup Erlandsen <email address hidden> writes:

> I can see why you wanna bind libconnman since you have a lot of sync
> DBus calls in here - it's less catastrophic for an app of course, but
> it may still lock up the ui.

Yes, it's driving me crazy to write basically same code twice, first in
C and then in python. My current plan is to write a quick sync dbus
implementation first and then move to libconnman and have proper async
calls.

--
Kalle Valo

129. By Kalle Valo on 2010-12-13

settings: simplify device states. Remove offline state, and rename other
states to off, on and connected.

130. By Kalle Valo on 2010-12-13

settings: fix mobile to use new states

131. By Kalle Valo on 2010-12-13

settings: remove leftover fixme

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/settings/indicatorNetworkSettings/app.py'
2--- src/settings/indicatorNetworkSettings/app.py 2010-12-07 15:07:37 +0000
3+++ src/settings/indicatorNetworkSettings/app.py 2010-12-13 21:15:34 +0000
4@@ -25,6 +25,8 @@
5 from indicatorNetworkSettings.version import *
6 from indicatorNetworkSettings.frontend.pages.connections import \
7 ConnectionsPage
8+from indicatorNetworkSettings.backend.devicemanager import \
9+ DeviceManager
10 from indicatorNetworkSettings.SimpleGtkbuilderApp import \
11 SimpleGtkbuilderApp
12
13@@ -41,6 +43,8 @@
14 # Setup Translations
15 self._setup_translations()
16
17+ self.devicemanager = DeviceManager()
18+
19 # Setup Pages
20 self.page_connections = ConnectionsPage(self, datadir)
21 self.pages = [self.page_connections]
22
23=== modified file 'src/settings/indicatorNetworkSettings/backend/connection.py'
24--- src/settings/indicatorNetworkSettings/backend/connection.py 2010-12-09 12:26:46 +0000
25+++ src/settings/indicatorNetworkSettings/backend/connection.py 2010-12-13 21:15:34 +0000
26@@ -29,21 +29,3 @@
27
28 def connect_(self, key):
29 print "Connecting to %s" % self.network
30-
31-def get_remembered_wireless_connections(device):
32- ### Dummy Connections (temporary)
33- connection1 = WifiConnection()
34- connection1.network = "BTHomeHub-193209"
35- connection1.signal = "0.75"
36- connection1.last_used = datetime.date(2010, 11, 3)
37- connection2 = WifiConnection()
38- connection2.network = "SKY-001"
39- connection2.signal = "0.55"
40- connection2.last_used = datetime.date(2010, 5, 22)
41- connection3 = WifiConnection()
42- connection3.network = "Starbucks OpenAccess"
43- connection3.signal = "0.2"
44- connection3.last_used = None
45- ###
46- connections = (connection1, connection2, connection3)
47- return connections
48
49=== added file 'src/settings/indicatorNetworkSettings/backend/connmanmanager.py'
50--- src/settings/indicatorNetworkSettings/backend/connmanmanager.py 1970-01-01 00:00:00 +0000
51+++ src/settings/indicatorNetworkSettings/backend/connmanmanager.py 2010-12-13 21:15:34 +0000
52@@ -0,0 +1,160 @@
53+#!/usr/bin/env python
54+# -*- coding: utf-8 -*-
55+#
56+# Copyright (C) 2010 Canonical
57+#
58+# Authors:
59+# Kalle Valo
60+#
61+# This program is free software; you can redistribute it and/or modify it under
62+# the terms of the GNU General Public License as published by the Free Software
63+# Foundation; version 3.
64+#
65+# This program is distributed in the hope that it will be useful, but WITHOUT
66+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
67+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
68+# details.
69+#
70+# You should have received a copy of the GNU General Public License along with
71+# this program; if not, write to the Free Software Foundation, Inc.,
72+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
73+
74+import gobject
75+import dbus
76+import dbus.mainloop.glib
77+
78+from indicatorNetworkSettings.backend.service import create_service
79+
80+class ConnmanManager(gobject.GObject):
81+ def get_properties(self):
82+ return self.properties
83+
84+ def is_available(self, technology):
85+ if technology in self.properties["AvailableTechnologies"]:
86+ return True
87+
88+ return False
89+
90+ def is_enabled(self, technology):
91+ if technology in self.properties["EnabledTechnologies"]:
92+ return True
93+
94+ return False
95+
96+ def is_connected(self, technology):
97+ if technology in self.properties["ConnectedTechnologies"]:
98+ return True
99+
100+ return False
101+
102+ def enable_technology(self, technology):
103+ if not self.is_available(technology):
104+ return
105+
106+ if self.is_enabled(technology):
107+ return
108+
109+ self.manager.EnableTechnology(technology)
110+
111+ def disable_technology(self, technology):
112+ if not self.is_available(technology):
113+ return
114+
115+ if not self.is_enabled(technology):
116+ return
117+
118+ self.manager.DisableTechnology(technology)
119+
120+ def get_available_technologies(self):
121+ return self.properties["AvailableTechnologies"]
122+
123+ def get_enabled_technologies(self):
124+ return self.properties["EnabledTechnologies"]
125+
126+ def get_connected_technologies(self):
127+ return self.properties["ConnectedTechnologies"]
128+
129+ def request_scan(self, technology=""):
130+ self.manager.RequestScan(technology)
131+
132+ def service_property_changed(self, name, value, path, interface):
133+ service = self.get_service(path)
134+
135+ if not service:
136+ return
137+
138+ service.update_property(name, value)
139+
140+ def manager_property_changed(self, name, value, path, interface):
141+ self.properties[name] = value
142+
143+ if name == "Services":
144+ self.update_services()
145+ self.emit("services-changed")
146+ elif name in ["AvailableTechnologies", "EnabledTechnologies",
147+ "ConnectedTechnologies"]:
148+ self.emit("technologies-changed")
149+
150+ def add_service(self, service):
151+ self.services[service.get_path()] = service
152+
153+ def get_services(self):
154+ return self.services.values()
155+
156+ def get_services_by_technology(self, technology):
157+ result = []
158+ for service in self.get_services():
159+ if service.get_type() == technology:
160+ result.append(service)
161+
162+ return result
163+
164+ def get_service(self, path):
165+ if path not in self.services:
166+ return None
167+
168+ return self.services[path]
169+
170+ def update_services(self):
171+ self.services = {}
172+
173+ for path in self.properties["Services"]:
174+ service = create_service(path)
175+ self.add_service(service)
176+
177+ def __init__(self):
178+ self.__gobject_init__()
179+ self.services = {}
180+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
181+ self.bus = dbus.SystemBus()
182+
183+ self.bus.add_signal_receiver(self.service_property_changed,
184+ bus_name="net.connman",
185+ dbus_interface="net.connman.Service",
186+ signal_name = "PropertyChanged",
187+ path_keyword="path",
188+ interface_keyword="interface")
189+
190+ self.manager = dbus.Interface(self.bus.get_object("net.connman",
191+ "/"),
192+ "net.connman.Manager")
193+ self.bus.add_signal_receiver(self.manager_property_changed,
194+ bus_name="net.connman",
195+ dbus_interface="net.connman.Manager",
196+ signal_name = "PropertyChanged",
197+ path_keyword="path",
198+ interface_keyword="interface")
199+
200+ self.properties = self.manager.GetProperties()
201+
202+ # FIXME: handle if connmand disappears
203+ # FIXME: how to handle ordering and other changes in service list?
204+
205+ self.update_services()
206+
207+
208+gobject.type_register(ConnmanManager)
209+gobject.signal_new("technologies-changed", ConnmanManager,
210+ gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
211+gobject.signal_new("services-changed", ConnmanManager,
212+ gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
213
214=== modified file 'src/settings/indicatorNetworkSettings/backend/device.py'
215--- src/settings/indicatorNetworkSettings/backend/device.py 2010-12-09 12:26:46 +0000
216+++ src/settings/indicatorNetworkSettings/backend/device.py 2010-12-13 21:15:34 +0000
217@@ -23,6 +23,13 @@
218
219 from indicatorNetworkSettings.enums import *
220
221+class UnknownDeviceTypeError(Exception):
222+ def __init__(self, devicetype):
223+ self.devicetype
224+
225+ def __str__(self):
226+ return self.devicetype
227+
228 class Device(gobject.GObject):
229
230 __gsignals__ = {
231@@ -33,54 +40,36 @@
232 }
233
234
235- def __init__(self):
236+ def __init__(self, devicetype, connman):
237 super(Device, self).__init__()
238- self.type = None
239- self.state = None
240+ self.type = devicetype
241+ self.state = DEVICE_STATE_OFF
242+ self.connman = connman
243+
244+ if self.type == DEVICE_TYPE_WIRED:
245+ self.typestring = "ethernet"
246+ elif self.type == DEVICE_TYPE_WIRELESS:
247+ self.typestring = "wifi"
248+ elif self.type == DEVICE_TYPE_MOBILE:
249+ self.typestring = "cellular"
250+ elif self.type == DEVICE_TYPE_BLUETOOTH:
251+ self.typestring = "bluetooth"
252+ else:
253+ raise UnknownDeviceTypeError(self.type)
254
255 def set_state(self, state):
256+
257+ if self.state == state:
258+ return
259+
260 self.state = state
261 self.emit("state-changed", self.state)
262
263 def get_state(self):
264 return self.state
265
266-def get_wired_devices():
267- ### Populate Device View (temporary)
268- device1 = Device()
269- device1.type = DEVICE_TYPE_WIRED
270- device1.state = DEVICE_STATE_OFFLINE
271- ###
272- devices = (device1,)
273- return devices
274-
275-def get_wireless_devices():
276- ### Populate Device View (temporary)
277- device1 = Device()
278- device1.type = DEVICE_TYPE_WIRELESS
279- device1.state = DEVICE_STATE_ONLINE
280- device2 = Device()
281- device2.type = DEVICE_TYPE_WIRELESS
282- device2.state = DEVICE_STATE_OFF
283- ###
284- devices = (device1, device2)
285- return devices
286-
287-def get_mobile_devices():
288- ### Populate Device View (temporary)
289- device3 = Device()
290- device3.type = DEVICE_TYPE_MOBILE
291- device3.state = DEVICE_STATE_CONNECTED
292- ###
293- devices = (device3,)
294- return devices
295-
296-def get_bluetooth_devices():
297- ### Populate Device View (temporary)
298- device4 = Device()
299- device4.type = DEVICE_TYPE_BLUETOOTH
300- device4.state = DEVICE_STATE_OFF
301- ###
302- devices = (device4,)
303- return devices
304-
305+ def enable(self):
306+ self.connman.enable_technology(self.typestring)
307+
308+ def disable(self):
309+ self.connman.disable_technology(self.typestring)
310
311=== added file 'src/settings/indicatorNetworkSettings/backend/devicemanager.py'
312--- src/settings/indicatorNetworkSettings/backend/devicemanager.py 1970-01-01 00:00:00 +0000
313+++ src/settings/indicatorNetworkSettings/backend/devicemanager.py 2010-12-13 21:15:34 +0000
314@@ -0,0 +1,153 @@
315+#!/usr/bin/env python
316+# -*- coding: utf-8 -*-
317+#
318+# Copyright (C) 2010 Canonical
319+#
320+# Authors:
321+# Andrew Higginson
322+# Kalle Valo
323+#
324+# This program is free software; you can redistribute it and/or modify it under
325+# the terms of the GNU General Public License as published by the Free Software
326+# Foundation; version 3.
327+#
328+# This program is distributed in the hope that it will be useful, but WITHOUT
329+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
330+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
331+# details.
332+#
333+# You should have received a copy of the GNU General Public License along with
334+# this program; if not, write to the Free Software Foundation, Inc.,
335+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
336+
337+import gobject
338+
339+from indicatorNetworkSettings.backend.device import Device
340+from indicatorNetworkSettings.backend.connmanmanager import ConnmanManager
341+from indicatorNetworkSettings.enums import *
342+
343+class DeviceManager(gobject.GObject):
344+
345+ __gsignals__ = {
346+ "devices-changed" : (gobject.SIGNAL_RUN_LAST,
347+ gobject.TYPE_NONE,
348+ (),
349+ ),
350+ }
351+
352+ def __init__(self):
353+ super(DeviceManager, self).__init__()
354+ self.connman = ConnmanManager()
355+
356+ self.ethernet_device = Device(DEVICE_TYPE_WIRED, self.connman)
357+ self.wifi_device = Device(DEVICE_TYPE_WIRELESS, self.connman)
358+ self.cellular_device = Device(DEVICE_TYPE_MOBILE, self.connman)
359+ self.bluetooth_device = Device(DEVICE_TYPE_BLUETOOTH, self.connman)
360+
361+ self.ethernet_available = False
362+ self.wifi_available = False
363+ self.cellular_available = False
364+ self.bluetooth_available = False
365+
366+ self.connman.connect("technologies-changed", self.technologies_updated)
367+ self.technologies_updated(self.connman)
368+
369+ def update_availability(self):
370+ techs = self.connman.get_available_technologies()
371+ changed = False
372+
373+ avail = "ethernet" in techs
374+ if avail != self.ethernet_available:
375+ self.ethernet_available = avail
376+ changed = True
377+
378+ avail = "wifi" in techs
379+ if avail != self.wifi_available:
380+ self.wifi_available = avail
381+ changed = True
382+
383+ avail = "cellular" in techs
384+ if avail != self.cellular_available:
385+ self.cellular_available = avail
386+ changed = True
387+
388+ avail = "bluetooth" in techs
389+ if avail != self.bluetooth_available:
390+ self.bluetooth_available = avail
391+ changed = True
392+
393+ if not changed:
394+ return
395+
396+ self.emit("devices-changed")
397+
398+ def update_state(self):
399+ enabled = self.connman.get_enabled_technologies()
400+ connected = self.connman.get_connected_technologies()
401+
402+ if "ethernet" in connected:
403+ self.ethernet_device.set_state(DEVICE_STATE_ONLINE)
404+ elif "ethernet" in enabled:
405+ self.ethernet_device.set_state(DEVICE_STATE_OFFLINE)
406+ else:
407+ self.ethernet_device.set_state(DEVICE_STATE_OFF)
408+
409+ if "wifi" in connected:
410+ self.wifi_device.set_state(DEVICE_STATE_ONLINE)
411+ elif "wifi" in enabled:
412+ self.wifi_device.set_state(DEVICE_STATE_OFFLINE)
413+ else:
414+ self.wifi_device.set_state(DEVICE_STATE_OFF)
415+
416+ if "cellular" in connected:
417+ self.cellular_device.set_state(DEVICE_STATE_ONLINE)
418+ elif "cellular" in enabled:
419+ self.cellular_device.set_state(DEVICE_STATE_OFFLINE)
420+ else:
421+ self.cellular_device.set_state(DEVICE_STATE_OFF)
422+
423+ if "bluetooth" in connected:
424+ self.bluetooth_device.set_state(DEVICE_STATE_ONLINE)
425+ elif "bluetooth" in enabled:
426+ self.bluetooth_device.set_state(DEVICE_STATE_OFFLINE)
427+ else:
428+ self.bluetooth_device.set_state(DEVICE_STATE_OFF)
429+
430+ def technologies_updated(self, connman):
431+ self.update_availability()
432+ self.update_state()
433+
434+ def get_wired_devices(self):
435+ devices = []
436+
437+ if self.ethernet_available:
438+ devices.append(self.ethernet_device)
439+
440+ return devices
441+
442+ def get_wireless_devices(self):
443+ devices = []
444+
445+ if self.wifi_available:
446+ devices.append(self.wifi_device)
447+
448+ return devices
449+
450+ def get_mobile_devices(self):
451+ devices = []
452+
453+ if self.cellular_available:
454+ devices.append(self.cellular_device)
455+
456+ return devices
457+
458+ def get_bluetooth_devices(self):
459+ devices = []
460+
461+ if self.bluetooth_available:
462+ devices.append(self.bluetooth_device)
463+
464+ return devices
465+
466+ def get_remembered_wireless_connections(self):
467+ return self.connman.get_services_by_technology("wifi")
468
469=== added file 'src/settings/indicatorNetworkSettings/backend/service.py'
470--- src/settings/indicatorNetworkSettings/backend/service.py 1970-01-01 00:00:00 +0000
471+++ src/settings/indicatorNetworkSettings/backend/service.py 2010-12-13 21:15:34 +0000
472@@ -0,0 +1,195 @@
473+#!/usr/bin/env python
474+# -*- coding: utf-8 -*-
475+#
476+# Copyright (C) 2010 Canonical
477+#
478+# Authors:
479+# Kalle Valo
480+#
481+# This program is free software; you can redistribute it and/or modify it under
482+# the terms of the GNU General Public License as published by the Free Software
483+# Foundation; version 3.
484+#
485+# This program is distributed in the hope that it will be useful, but WITHOUT
486+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
487+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
488+# details.
489+#
490+# You should have received a copy of the GNU General Public License along with
491+# this program; if not, write to the Free Software Foundation, Inc.,
492+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
493+
494+import dbus
495+
496+# FIXME: translate these
497+IPV4_METHOD_DHCP = "dhcp"
498+IPV4_METHOD_MANUAL = "manual"
499+
500+def create_service(path):
501+ bus = dbus.SystemBus()
502+ proxy = dbus.Interface(bus.get_object("net.connman", path),
503+ "net.connman.Service")
504+
505+ try:
506+ properties = proxy.GetProperties()
507+ except dbus.exceptions.DBusException as e:
508+ print "GetProperties failed for service %s: %s" % (path, e)
509+ return
510+
511+ service_type = properties["Type"]
512+ if service_type == "ethernet":
513+ service = EthernetService(proxy, path, properties)
514+ elif service_type == "wifi":
515+ service = WifiService(proxy, path, properties)
516+ elif service_type == "bluetooth":
517+ service = BluetoothService(proxy, path, properties)
518+ elif service_type == "cellular":
519+ service = CellularService(proxy, path, properties)
520+ else:
521+ s = "unknown service type '%s': %s" % (service_type, path)
522+ raise Exception(s)
523+
524+ return service
525+
526+class Service():
527+
528+ def get_name(self):
529+ return self.properties["Name"]
530+
531+ def get_path(self):
532+ return self.path
533+
534+ def get_strength(self):
535+ if "Strength" not in self.properties:
536+ return 0
537+
538+ return int(self.properties["Strength"])
539+
540+ def get_autoconnect(self):
541+ return self.properties["AutoConnect"] == dbus.Boolean(1)
542+
543+ def set_autoconnect(self, autoconnect):
544+ if autoconnect:
545+ value = dbus.Boolean(True)
546+ else:
547+ value = dbus.Boolean(False)
548+
549+ self.service.SetProperty("AutoConnect", value);
550+
551+ def get_nameservers_configuration(self):
552+ val = self.properties["Nameservers.Configuration"]
553+ if val != None:
554+ return " ".join(val)
555+ else:
556+ return ""
557+
558+ def set_nameservers_configuration(self, nameservers):
559+ value = nameservers.split()
560+ self.service.SetProperty("Nameservers.Configuration",
561+ dbus.Array(value, signature="s"))
562+
563+ def get_domains_configuration(self):
564+ val = self.properties["Domains.Configuration"]
565+ if val != None:
566+ return " ".join(val)
567+ else:
568+ return ""
569+
570+ def set_domains_configuration(self, domains):
571+ value = domains.split()
572+ self.service.SetProperty("Domains.Configuration",
573+ dbus.Array(value, signature="s"))
574+
575+ def get_ipv4_configuration_method(self):
576+ d = self.properties["IPv4.Configuration"]
577+ if d.has_key('Method'):
578+ return d['Method']
579+ else:
580+ return ""
581+
582+ def get_ipv4_configuration_address(self):
583+ d = self.properties["IPv4.Configuration"]
584+ if d.has_key('Address'):
585+ return d['Address']
586+ else:
587+ return ""
588+
589+ def get_ipv4_configuration_netmask(self):
590+ d = self.properties["IPv4.Configuration"]
591+ if d.has_key('Netmask'):
592+ return d['Netmask']
593+ else:
594+ return ""
595+
596+ def get_ipv4_configuration_gateway(self):
597+ d = self.properties["IPv4.Configuration"]
598+ if d.has_key('Gateway'):
599+ return d['Gateway']
600+ else:
601+ return ""
602+
603+ def set_ipv4_configuration(self, ipv4):
604+ self.service.SetProperty("IPv4.Configuration", ipv4)
605+
606+ def remove(self):
607+ if not self.is_favorite():
608+ return
609+
610+ self.service.Remove()
611+
612+ def is_favorite(self):
613+ if not "Favorite" in self.properties:
614+ return False
615+
616+ return self.properties["Favorite"] == dbus.Boolean(1)
617+
618+ def connect(self):
619+ self.service.Connect()
620+
621+ def update_property(self, name, value):
622+ self.properties[name] = value
623+ # FIXME: emit property-changed signal
624+
625+ def __init__(self, service, path, properties):
626+ self.service = service
627+ self.path = path
628+ self.properties = properties
629+
630+class EthernetService(Service):
631+
632+ def get_type(self):
633+ return "ethernet"
634+
635+class WifiService(Service):
636+
637+ def get_type(self):
638+ return "wifi"
639+
640+ def uses_passphrase(self):
641+ return self.properties["Security"] != "none"
642+
643+ def get_passphrase(self):
644+ if "Passphrase" not in self.properties:
645+ return ""
646+
647+ return self.properties["Passphrase"]
648+
649+ def set_passphrase(self, passphrase):
650+ self.service.SetProperty("Passphrase", passphrase);
651+
652+class BluetoothService(Service):
653+
654+ def get_type(self):
655+ return "bluetooth"
656+
657+class CellularService(Service):
658+
659+ def get_type(self):
660+ return "cellular"
661+
662+ def get_apn(self):
663+ return self.properties["APN"]
664+
665+ def set_apn(self, apn):
666+ self.service.SetProperty("APN", apn);
667+
668
669=== modified file 'src/settings/indicatorNetworkSettings/frontend/pages/connections.py'
670--- src/settings/indicatorNetworkSettings/frontend/pages/connections.py 2010-12-07 15:07:37 +0000
671+++ src/settings/indicatorNetworkSettings/frontend/pages/connections.py 2010-12-13 21:15:34 +0000
672@@ -52,10 +52,10 @@
673 self.treeview_devices.connect("reordered",
674 self._on_treeview_devices_reordered)
675
676- wired_devices = get_wired_devices()
677- wireless_devices = get_wireless_devices()
678- mobile_devices = get_mobile_devices()
679- bluetooth_devices = get_bluetooth_devices()
680+ wired_devices = app.devicemanager.get_wired_devices()
681+ wireless_devices = app.devicemanager.get_wireless_devices()
682+ mobile_devices = app.devicemanager.get_mobile_devices()
683+ bluetooth_devices = app.devicemanager.get_bluetooth_devices()
684
685 for device in wired_devices:
686 box = WiredBox(device, datadir)
687@@ -63,7 +63,7 @@
688 self.add_device(device, box)
689
690 for device in wireless_devices:
691- box = WirelessBox(device, datadir)
692+ box = WirelessBox(device, app, datadir)
693 self.app.notebook_c_right.append_page(box)
694 self.add_device(device, box)
695
696
697=== modified file 'src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wireless.py'
698--- src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wireless.py 2010-12-07 15:07:37 +0000
699+++ src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wireless.py 2010-12-13 21:15:34 +0000
700@@ -25,9 +25,6 @@
701 import WirelessConnectionView, WirelessConnectionStore
702 from indicatorNetworkSettings.frontend.widgets.toggleswitch \
703 import InfoBox, ToggleSwitch
704-
705-from indicatorNetworkSettings.backend.connection \
706- import get_remembered_wireless_connections
707
708 from indicatorNetworkSettings.enums import *
709 import indicatorNetworkSettings.frontend.utils as utils
710@@ -42,7 +39,7 @@
711 WirelessConnectionView to connect to and remember details for
712 wireless networks."""
713
714- def __init__(self, device, datadir):
715+ def __init__(self, device, app, datadir):
716 super(WirelessBox, self).__init__(device, datadir)
717
718 # Infobox and Togglswitch
719@@ -73,7 +70,8 @@
720 ## Packing
721 self.scrolledwindow_connections.add(self.treeview_connections)
722 ## Population
723- connections = get_remembered_wireless_connections(device)
724+ # FIXME
725+ connections = app.devicemanager.get_remembered_wireless_connections()
726 for connection in connections:
727 self._add_connection(connection)
728
729@@ -108,13 +106,17 @@
730 self.label_status.set_text(status_text)
731
732 def _add_connection(self, connection):
733- network = connection.network
734- signal = connection.signal
735- if connection.last_used:
736- date_format = locale.nl_langinfo(locale.D_FMT)
737- last_used = connection.last_used.strftime(date_format)
738- else:
739- last_used = _("Never")
740+ network = connection.get_name()
741+ signal = float(connection.get_strength()) / 100
742+
743+ # FIXME: implement
744+ # if connection.last_used:
745+ # date_format = locale.nl_langinfo(locale.D_FMT)
746+ # last_used = connection.last_used.strftime(date_format)
747+ # else:
748+ # last_used = _("Never")
749+
750+ last_used = _("N/A")
751
752 liststore = self.treeview_connections.get_model()
753 liststore.append(connection, network, signal, last_used)
754@@ -125,10 +127,10 @@
755
756 def _on_toggleswitch_toggled(self, widget):
757 if widget.get_active():
758- self.device.set_state(DEVICE_STATE_CONNECTED)
759+ self.device.disable()
760 else:
761- self.device.set_state(DEVICE_STATE_OFFLINE)
762+ self.device.enable()
763
764 def _on_button_connect_clicked(self, widget):
765 connection = self.treeview_connections.get_selected_connection()
766- connection.connect_("password")
767+ connection.connect()

Subscribers

People subscribed via source and target branches