Merge lp:~stefan-schwarzburg/qreator/wifi_sorting into lp:qreator

Proposed by Schwarzburg
Status: Merged
Merged at revision: 136
Proposed branch: lp:~stefan-schwarzburg/qreator/wifi_sorting
Merge into: lp:qreator
Diff against target: 129 lines (+48/-14)
2 files modified
data/ui/QrCodeWifi.ui (+2/-3)
qreator/qrcodes/QRCodeWifiGtk.py (+46/-11)
To merge this branch: bzr merge lp:~stefan-schwarzburg/qreator/wifi_sorting
Reviewer Review Type Date Requested Status
Schwarzburg Approve
Review via email: mp+150805@code.launchpad.net

Description of the change

This branch adds a sorting feature to the Wifi signals. The wifi signals are updated, sorted and now also feature an icon.

To post a comment you must log in.
Revision history for this message
Schwarzburg (stefan-schwarzburg) wrote :

David already stated that he had looked at this branch, and is ok with merging.
So I will go ahead and merge it.

review: Approve
Revision history for this message
David Planella (dpm) wrote :

Al 28/02/13 14:02, En/na Schwarzburg ha escrit:
> Review: Approve
>
> David already stated that he had looked at this branch, and is ok with merging.
> So I will go ahead and merge it.
>

Thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/ui/QrCodeWifi.ui'
2--- data/ui/QrCodeWifi.ui 2012-12-01 16:17:02 +0000
3+++ data/ui/QrCodeWifi.ui 2013-02-27 14:13:42 +0000
4@@ -121,13 +121,12 @@
5 </packing>
6 </child>
7 <child>
8- <object class="GtkComboBoxText" id="comboboxtextSSID">
9+ <object class="GtkComboBox" id="comboboxSSID">
10 <property name="visible">True</property>
11 <property name="can_focus">False</property>
12 <property name="has_entry">True</property>
13 <property name="entry_text_column">0</property>
14- <property name="id_column">1</property>
15- <signal name="changed" handler="on_comboboxtextSSID_changed" swapped="no"/>
16+ <signal name="changed" handler="on_comboboxSSID_changed" swapped="no"/>
17 <child internal-child="entry">
18 <object class="GtkEntry" id="entrySSID">
19 <property name="can_focus">True</property>
20
21=== modified file 'qreator/qrcodes/QRCodeWifiGtk.py'
22--- qreator/qrcodes/QRCodeWifiGtk.py 2012-11-22 12:37:55 +0000
23+++ qreator/qrcodes/QRCodeWifiGtk.py 2013-02-27 14:13:42 +0000
24@@ -17,7 +17,7 @@
25 from GtkHelpers import clear_text_entry, show_clear_icon
26 from qreator_lib.i18n import _
27 from qreator_lib.helpers import get_data_file
28-from gi.repository import Gtk, NetworkManager, NMClient
29+from gi.repository import Gtk, NetworkManager, NMClient, GLib, GdkPixbuf
30
31
32 class QRCodeWifiGtk(object):
33@@ -32,9 +32,27 @@
34
35 self.comboboxtextSecurity = self.builder.get_object(
36 'comboboxtextSecurity')
37+ self.entryPassword = self.builder.get_object('entryPassword')
38+
39+ # SSID
40 self.entrySSID = self.builder.get_object('entrySSID')
41- self.entryPassword = self.builder.get_object('entryPassword')
42- self.comboboxtextSSID = self.builder.get_object('comboboxtextSSID')
43+ self.comboboxSSID = self.builder.get_object('comboboxSSID')
44+ self.SSIDmodel = Gtk.ListStore(str, GdkPixbuf.Pixbuf)
45+ self.comboboxSSID.set_model(self.SSIDmodel)
46+
47+ # create the renderers for the strength
48+ # for some reason, the text renderer already works
49+ strengthcell = Gtk.CellRendererPixbuf()
50+ self.comboboxSSID.pack_start(strengthcell, False)
51+ self.comboboxSSID.add_attribute(strengthcell, 'pixbuf', 1)
52+
53+ icontheme = Gtk.IconTheme.get_default()
54+ size = 24
55+ self.strength_pixbufs = []
56+ for strength in ["weak", "ok", "good", "excellent"]:
57+ self.strength_pixbufs.append(icontheme.load_icon(
58+ "network-wireless-signal-{0}-symbolic".format(strength),
59+ size, Gtk.IconLookupFlags.USE_BUILTIN))
60
61 # Initialize combo boxes (Glade seems not to do it for us)
62 self.comboboxtextSecurity.set_active(0)
63@@ -46,10 +64,24 @@
64 self.entryPassword.set_placeholder_text(_('[Network password]'))
65
66 def update_ssids(self):
67+ # check if there are already ssids in the combobox
68+ ssidlistmodel = self.comboboxSSID.get_model()
69+ ssidelements = []
70+ item = ssidlistmodel.get_iter_first()
71+ while not item is None:
72+ ssidelements.append(ssidlistmodel.get_value(item, 0))
73+ item = ssidlistmodel.iter_next(item)
74+
75+ # get the new ssids from the network manager
76+ # and add them to combobox
77 ssids = get_ssids()
78 for ssid in ssids:
79- # TODO: clear combobox
80- self.comboboxtextSSID.append_text(ssid)
81+ if not ssid[1] in ssidelements:
82+ p = self.strength_pixbufs[ssid[0] // 25]
83+ self.SSIDmodel.append([ssid[1], p])
84+ self.comboboxSSID.set_model(self.SSIDmodel)
85+
86+ return True # -> repeat the timeout calls
87
88 def update_wifi_qr_code(self, security=None, ssid=None, password=None):
89 if not security:
90@@ -72,9 +104,9 @@
91 def on_entrySSID_icon_press(self, widget, icon, mouse_button):
92 clear_text_entry(widget, icon)
93
94- def on_comboboxtextSSID_changed(self, widget, data=None):
95+ def on_comboboxSSID_changed(self, widget, data=None):
96 show_clear_icon(self.entrySSID)
97- self.update_wifi_qr_code(ssid=widget.get_active_text())
98+ self.update_wifi_qr_code(ssid=widget.get_child().get_text())
99
100 def on_entryPassword_icon_press(self, widget, icon, mouse_button):
101 clear_text_entry(widget, icon)
102@@ -90,13 +122,15 @@
103 self.entryPassword.set_visibility(False)
104
105 def on_activated(self):
106- self.update_ssids()
107+ pass
108
109 def on_prepared(self):
110- pass
111+ # check for new ssids every 5 seconds
112+ GLib.timeout_add_seconds(5, self.update_ssids)
113
114
115 def get_ssids():
116+ """Returns a list of ssids sorted by the signal strength."""
117 nmc = NMClient.Client.new()
118 devs = nmc.get_devices()
119
120@@ -104,6 +138,7 @@
121 for dev in devs:
122 if dev.get_device_type() == NetworkManager.DeviceType.WIFI:
123 for ap in dev.get_access_points():
124- ssids.append(ap.get_ssid())
125-
126+ ssids.append((ap.get_strength(), ap.get_ssid()))
127+ ssids.sort()
128+ ssids.reverse() # strongest has the highest number -> should be first
129 return ssids

Subscribers

People subscribed via source and target branches

to all changes: