Merge lp:~kvalo/indicator-network/settings-vala-convert into lp:~indicator-applet-developers/indicator-network/indicator-network

Proposed by Kalle Valo
Status: Merged
Merged at revision: 127
Proposed branch: lp:~kvalo/indicator-network/settings-vala-convert
Merge into: lp:~indicator-applet-developers/indicator-network/indicator-network
Diff against target: 5821 lines (+2864/-2574)
63 files modified
.bzrignore (+21/-0)
configure.ac (+1/-7)
po/POTFILES.in (+3/-4)
src/settings/Makefile.am (+44/-13)
src/settings/app.vala (+76/-0)
src/settings/backend/connection.vala (+63/-0)
src/settings/backend/device.vala (+78/-0)
src/settings/enums.vala (+115/-0)
src/settings/frontend/pages/connections.vala (+120/-0)
src/settings/frontend/utils.vala (+199/-0)
src/settings/frontend/widgets/cellrenderers.vala (+224/-0)
src/settings/frontend/widgets/device-boxes/base.vala (+26/-0)
src/settings/frontend/widgets/device-boxes/bluetooth.vala (+35/-0)
src/settings/frontend/widgets/device-boxes/mobile.vala (+151/-0)
src/settings/frontend/widgets/device-boxes/wired.vala (+35/-0)
src/settings/frontend/widgets/device-boxes/wireless.vala (+183/-0)
src/settings/frontend/widgets/dialogs/edit-connection.vala (+165/-0)
src/settings/frontend/widgets/infobox.vala (+63/-0)
src/settings/frontend/widgets/stores.vala (+143/-0)
src/settings/frontend/widgets/toggleswitch.vala (+356/-0)
src/settings/frontend/widgets/treeviews.vala (+133/-0)
src/settings/indicator-network-settings (+0/-61)
src/settings/indicatorNetworkSettings/Makefile.am (+0/-13)
src/settings/indicatorNetworkSettings/SimpleGtkbuilderApp.py (+0/-58)
src/settings/indicatorNetworkSettings/__init__.py (+0/-1)
src/settings/indicatorNetworkSettings/app.py (+0/-78)
src/settings/indicatorNetworkSettings/backend/Makefile.am (+0/-6)
src/settings/indicatorNetworkSettings/backend/__init__.py (+0/-1)
src/settings/indicatorNetworkSettings/backend/connection.py (+0/-31)
src/settings/indicatorNetworkSettings/backend/connmanmanager.py (+0/-160)
src/settings/indicatorNetworkSettings/backend/device.py (+0/-75)
src/settings/indicatorNetworkSettings/backend/devicemanager.py (+0/-153)
src/settings/indicatorNetworkSettings/backend/service.py (+0/-195)
src/settings/indicatorNetworkSettings/enums.py (+0/-42)
src/settings/indicatorNetworkSettings/frontend/Makefile.am (+0/-9)
src/settings/indicatorNetworkSettings/frontend/__init__.py (+0/-1)
src/settings/indicatorNetworkSettings/frontend/pages/Makefile.am (+0/-5)
src/settings/indicatorNetworkSettings/frontend/pages/connections.py (+0/-111)
src/settings/indicatorNetworkSettings/frontend/utils.py (+0/-34)
src/settings/indicatorNetworkSettings/frontend/widgets/Makefile.am (+0/-6)
src/settings/indicatorNetworkSettings/frontend/widgets/__init__.py (+0/-1)
src/settings/indicatorNetworkSettings/frontend/widgets/cellrenderers.py (+0/-210)
src/settings/indicatorNetworkSettings/frontend/widgets/connectionview.py (+0/-78)
src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/Makefile.am (+0/-3)
src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/__init__.py (+0/-30)
src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/bluetooth.py (+0/-35)
src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/mobile.py (+0/-116)
src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wired.py (+0/-35)
src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wireless.py (+0/-130)
src/settings/indicatorNetworkSettings/frontend/widgets/deviceview.py (+0/-153)
src/settings/indicatorNetworkSettings/frontend/widgets/toggleswitch.py (+0/-529)
src/settings/indicatorNetworkSettings/utils.py (+0/-18)
src/settings/indicatorNetworkSettings/version.py (+0/-5)
src/settings/logger.vala (+44/-0)
src/settings/main.vala (+68/-0)
src/settings/ui/Makefile.am (+3/-1)
src/settings/ui/edit_connection_dialog.ui (+378/-0)
src/settings/ui/indicator-network-settings.ui (+0/-163)
src/settings/ui/main.ui (+99/-0)
src/settings/ui/mobile_box.ui (+1/-1)
src/settings/ui/sample.ui (+12/-0)
src/settings/ui/wireless_box.ui (+17/-2)
src/settings/vapi/config.vapi (+8/-0)
To merge this branch: bzr merge lp:~kvalo/indicator-network/settings-vala-convert
Reviewer Review Type Date Requested Status
Andrew (community) Approve
Mikkel Kamstrup Erlandsen (community) code review Approve
Review via email: mp+45244@code.launchpad.net

Description of the change

Replace pygtk version of indicator-network-settings with a similar vala version. Currently frontend only works, backend needs to be implemented still. The backend will use libconnman.

Original author of the vala code is and471. I did the merge to indicator-network and autotools part.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

* src/settings/app.vala:

 - Can NetworkSettings.get_widgets() check that this.builder is a Gtk.Builder, as this kinda code always tends to regress when you refactor it...

 - Why is [CCode (instance_pos = -1)] needed on the callbacks? If it's really needed, can it get a comment in the code?

* src/settings/backend/connection.vala:

 - Why are all the fields on WifiConnection not properties? That would give change notifications for free.

* src/settings/backend/device.vala

 - Why does the Device class not use properties for it's two fields - given that, it would need the change notification signal, but could just you the standard GObject 'notify' signal (with details for the state).

* src/settings/frontend/utils.vala

 - Please make sure that you (Andrew) have the copyrights on this code (and not the Clutter project), so that you can legally contribute it

* ToggleSwitch and InfoBox. Can you add a quick comment in the class headers on why you are not using the Gtk counterparts?

Approved conditionally - given that there are good answers to the questions.

Super impressive work Andrew! This is an awesome first stab at a network dialog! :-D

review: Approve (code review)
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

I just went over the points with Andrew on IRC and everything should be cleared up. About the copyright issue we need some sort of reimplementation as Andrew said it was mostly copy-paste. I gathered from other discussions today that we may have something in lp:unity we can replace it with.

So; kvalo should merge and471's newest changes and pull in the unity color stuff and we should be good

Revision history for this message
Kalle Valo (kvalo) wrote :

Mikkel Kamstrup Erlandsen <email address hidden> writes:

> I just went over the points with Andrew on IRC and everything should
> be cleared up.

Excellent, thank you for that.

> About the copyright issue we need some sort of reimplementation as
> Andrew said it was mostly copy-paste. I gathered from other
> discussions today that we may have something in lp:unity we can
> replace it with.
>
> So; kvalo should merge and471's newest changes and pull in the unity
> color stuff and we should be good

Ok. I'll do so that I'll find a replacement implementation and update
this merge request.

Thanks.

--
Kalle Valo

135. By Kalle Valo

settings: replace rgb to hsl functions with copies from libunity

The author for the functions is Gordon Allot.

The original implementation used hsl, but the new functions use instead hsv.
Hopefully this isn't a problem, at least I didn't notice any difference
in testing.

Revision history for this message
Kalle Valo (kvalo) wrote :

I now pushed new functions for the rgb transformations. Please note the hsv/hsl difference, I hope I didn't break anything.

136. By Kalle Valo

settings: add missing glade files to potfiles to fix distcheck

Revision history for this message
Andrew (and471) wrote :

All looks good I approve!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2010-12-09 09:03:43 +0000
+++ .bzrignore 2011-01-07 16:06:25 +0000
@@ -89,3 +89,24 @@
89tests/libconnman-tool89tests/libconnman-tool
90src/libconnman/libconnman_la-connman-service.lo90src/libconnman/libconnman_la-connman-service.lo
91py-compile91py-compile
92src/settings/app.c
93src/settings/enums.c
94src/settings/indicator-network-settings-2
95src/settings/indicator_network_settings_2_vala.stamp
96src/settings/logger.c
97src/settings/main.c
98src/settings/backend/connection.c
99src/settings/backend/device.c
100src/settings/frontend/utils.c
101src/settings/frontend/pages/connections.c
102src/settings/frontend/widgets/cellrenderers.c
103src/settings/frontend/widgets/infobox.c
104src/settings/frontend/widgets/stores.c
105src/settings/frontend/widgets/toggleswitch.c
106src/settings/frontend/widgets/treeviews.c
107src/settings/frontend/widgets/device-boxes/base.c
108src/settings/frontend/widgets/device-boxes/bluetooth.c
109src/settings/frontend/widgets/device-boxes/mobile.c
110src/settings/frontend/widgets/device-boxes/wired.c
111src/settings/frontend/widgets/device-boxes/wireless.c
112src/settings/frontend/widgets/dialogs/edit-connection.c
92113
=== modified file 'configure.ac'
--- configure.ac 2010-12-16 19:30:22 +0000
+++ configure.ac 2011-01-07 16:06:25 +0000
@@ -17,9 +17,9 @@
17AM_PROG_CC_C_O17AM_PROG_CC_C_O
18AC_STDC_HEADERS18AC_STDC_HEADERS
19AC_PROG_LIBTOOL19AC_PROG_LIBTOOL
20AM_PATH_PYTHON
21AC_PROG_LN_S20AC_PROG_LN_S
22AC_PROG_MKDIR_P21AC_PROG_MKDIR_P
22AM_PROG_VALAC
2323
24AC_SUBST(VERSION)24AC_SUBST(VERSION)
25AC_CONFIG_MACRO_DIR([m4])25AC_CONFIG_MACRO_DIR([m4])
@@ -154,12 +154,6 @@
154src/agent/Makefile154src/agent/Makefile
155src/settings/Makefile155src/settings/Makefile
156src/settings/ui/Makefile156src/settings/ui/Makefile
157src/settings/indicatorNetworkSettings/Makefile
158src/settings/indicatorNetworkSettings/backend/Makefile
159src/settings/indicatorNetworkSettings/frontend/Makefile
160src/settings/indicatorNetworkSettings/frontend/pages/Makefile
161src/settings/indicatorNetworkSettings/frontend/widgets/Makefile
162src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/Makefile
163data/Makefile157data/Makefile
164po/Makefile.in158po/Makefile.in
165scripts/Makefile159scripts/Makefile
166160
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2010-12-13 14:04:06 +0000
+++ po/POTFILES.in 2011-01-07 16:06:25 +0000
@@ -8,9 +8,8 @@
8src/agent/pin-dialog.c8src/agent/pin-dialog.c
9scripts/indicator-network-settings9scripts/indicator-network-settings
10scripts/indicator-network-mobile-wizard10scripts/indicator-network-mobile-wizard
11src/settings/indicatorNetworkSettings/enums.py11src/settings/ui/edit_connection_dialog.ui
12src/settings/indicatorNetworkSettings/frontend/widgets/connectionview.py12src/settings/ui/main.ui
13src/settings/indicatorNetworkSettings/frontend/widgets/deviceview.py
14src/settings/ui/indicator-network-settings.ui
15src/settings/ui/mobile_box.ui13src/settings/ui/mobile_box.ui
14src/settings/ui/sample.ui
16src/settings/ui/wireless_box.ui15src/settings/ui/wireless_box.ui
1716
=== modified file 'src/settings/Makefile.am'
--- src/settings/Makefile.am 2010-12-13 13:55:55 +0000
+++ src/settings/Makefile.am 2011-01-07 16:06:25 +0000
@@ -1,16 +1,47 @@
1SUBDIRS = \1SUBDIRS = \
2 indicatorNetworkSettings \
3 ui2 ui
43
5dist_pkgdata_SCRIPTS = \4bin_PROGRAMS = indicator-network-settings-2
6 indicator-network-settings5
76indicator_network_settings_2_SOURCES = \
8# create a symbolic link to bindir7 main.vala \
9# FIXME: it will have suffix -2 until new settings window is usable8 app.vala \
10#9 enums.vala \
11# Note: ln -f is not portable10 logger.vala \
12install-exec-hook:11 backend/device.vala \
13 $(MKDIR_P) $(DESTDIR)$(bindir) && \12 backend/connection.vala \
14 cd $(DESTDIR)$(bindir) && \13 frontend/utils.vala \
15 $(LN_S) -f $(pkgdatadir)/indicator-network-settings \14 frontend/pages/connections.vala \
16 indicator-network-settings-215 frontend/widgets/cellrenderers.vala \
16 frontend/widgets/stores.vala \
17 frontend/widgets/treeviews.vala \
18 frontend/widgets/infobox.vala \
19 frontend/widgets/toggleswitch.vala \
20 frontend/widgets/device-boxes/base.vala \
21 frontend/widgets/device-boxes/mobile.vala \
22 frontend/widgets/device-boxes/bluetooth.vala \
23 frontend/widgets/device-boxes/wired.vala \
24 frontend/widgets/device-boxes/wireless.vala \
25 frontend/widgets/dialogs/edit-connection.vala
26
27VALAFLAGS = \
28 --vapidir=$(srcdir)/vapi \
29 --pkg=gmodule-2.0 \
30 --pkg=gtk+-2.0 \
31 --pkg=gdk-2.0 \
32 --pkg=gio-2.0 \
33 --pkg=gee-1.0 \
34 --pkg=pango \
35 --pkg=cairo \
36 --pkg=config \
37 --fatal-warnings
38
39# -w is needed to disable gcc warnings because of valac
40indicator_network_settings_2_CFLAGS = \
41 $(GTK_CFLAGS) \
42 -w \
43 -DLOCALEDIR=\""$(localedir)"\" \
44 -DPKGDATADIR=\""$(pkgdatadir)"\"
45
46indicator_network_settings_2_LDADD = \
47 $(GTK_LIBS)
1748
=== added file 'src/settings/app.vala'
--- src/settings/app.vala 1970-01-01 00:00:00 +0000
+++ src/settings/app.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,76 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public class NetworkSettings : Object {
22
23 // Widgets from GTKBuilder
24 private Gtk.Window window_main;
25 private Gtk.Notebook notebook_main;
26 private Gtk.Alignment alignment_connections;
27 private Gtk.ScrolledWindow scrolledwindow_c_devices;
28 private Gtk.Notebook notebook_c_right;
29
30 private Gtk.IconTheme icons = Gtk.IconTheme.get_default();
31 private ConnectionsPage[] pages;
32 public Gtk.Builder builder;
33
34 public NetworkSettings(string datadir) {
35 this.builder = Utils.Gui.new_builder(datadir + "/ui/main.ui");
36
37 this.get_widgets();
38
39 var page_connection = new ConnectionsPage(datadir, this.icons,
40 this.alignment_connections,
41 this.scrolledwindow_c_devices,
42 this.notebook_c_right);
43
44 this.pages = {page_connection};
45
46 this.window_main.show_all();
47 this.on_notebook_main_page_switched(null, 0);
48 }
49
50 /* Private Functions */
51 private void get_widgets() {
52 this.window_main = this.builder.get_object("window_main") as Gtk.Window;
53 this.notebook_main = this.builder.get_object("notebook_main") as Gtk.Notebook;
54 this.alignment_connections = this.builder.get_object("alignment_connections") as Gtk.Alignment;
55 this.scrolledwindow_c_devices = this.builder.get_object("scrolledwindow_c_devices") as Gtk.ScrolledWindow;
56 this.notebook_c_right = this.builder.get_object("notebook_c_right") as Gtk.Notebook;
57 }
58
59 /* Callbacks */
60 [CCode (instance_pos = -1)]
61 public bool on_window_main_delete_event(Gdk.Event event) {
62 Gtk.main_quit();
63 return true;
64 }
65
66 [CCode (instance_pos = -1)]
67 public void on_notebook_main_page_switched(Gtk.NotebookPage? notebook_page, int page_num) {
68 var page_alignment = this.notebook_main.get_nth_page(page_num);
69
70 foreach (ConnectionsPage page in this.pages) {
71 if (page.alignment == page_alignment && page.viewed == false) {
72 page.on_first_expose();
73 }
74 }
75 }
76}
077
=== added directory 'src/settings/backend'
=== added file 'src/settings/backend/connection.vala'
--- src/settings/backend/connection.vala 1970-01-01 00:00:00 +0000
+++ src/settings/backend/connection.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,63 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public class WifiConnection : GLib.Object {
22 public string network;
23 public double signal;
24 public string last_used;
25 public string name;
26 public string ssid;
27 public string? bssid;
28 public WirelessMode mode = WirelessMode.INFRASTRUCTURE;
29 public bool autoconnect = false;
30 public bool share_settings = false;
31
32 public void connect_(string key) {
33 var network = this.network;
34 stdout.printf(@"Connecting to $network\n");
35 }
36}
37
38public WifiConnection[] get_remembered_wireless_connections(Device device) {
39 // Dummy Connections (temporary)
40 var connection1 = new WifiConnection();
41 connection1.name = "Downstairs Router (above the biscuit tin)";
42 connection1.signal = (double) 0.75;
43 connection1.last_used = "1/1/1";
44 connection1.ssid = "BTHomeHub-193209";
45 connection1.bssid = "BBTHomeHub-193209";
46 connection1.mode = WirelessMode.INFRASTRUCTURE;
47 connection1.autoconnect = true;
48 connection1.share_settings = true;
49
50 var connection2 = new WifiConnection();
51 connection2.name = "SKY-001";
52 connection2.signal = (double) 0.55;
53 connection2.last_used = "1/1/1";
54 connection2.ssid = "SKY-001";
55
56 var connection3 = new WifiConnection();
57 connection3.name = "Starbucks OpenAccess";
58 connection3.signal = (double) 0.2;
59 connection3.last_used = "1/1/1";
60 connection3.ssid = "Starbucks-1223Open";
61 //
62 return {connection1, connection2, connection3};
63}
064
=== added file 'src/settings/backend/device.vala'
--- src/settings/backend/device.vala 1970-01-01 00:00:00 +0000
+++ src/settings/backend/device.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,78 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public class Device : GLib.Object {
22
23 public signal void state_changed(DeviceState selected);
24
25 public DeviceType type;
26 public DeviceState state;
27
28 public Device() {
29 }
30
31 public void set_state(DeviceState state) {
32 this.state = state;
33 this.state_changed(this.state);
34 }
35
36 public DeviceState get_state() {
37 return this.state;
38 }
39}
40
41public static Device[] get_wired_devices() {
42 // Populate Device View (temporary)
43 var device1 = new Device();
44 device1.type = DeviceType.WIRED;
45 device1.state = DeviceState.OFFLINE;
46 //
47 return {device1};
48}
49
50public static Device[] get_wireless_devices() {
51 // Populate Device View (temporary)
52 var device1 = new Device();
53 device1.type = DeviceType.WIRELESS;
54 device1.state = DeviceState.ONLINE;
55 var device2 = new Device();
56 device2.type = DeviceType.WIRELESS;
57 device2.state = DeviceState.OFF;
58 //
59 return {device1, device2};
60}
61
62public static Device[] get_mobile_devices() {
63 // Populate Device View (temporary)
64 var device3 = new Device();
65 device3.type = DeviceType.MOBILE;
66 device3.state = DeviceState.CONNECTED;
67 //
68 return {device3};
69}
70
71public static Device[] get_bluetooth_devices() {
72 // Populate Device View (temporary)
73 var device4 = new Device();
74 device4.type = DeviceType.BLUETOOTH;
75 device4.state = DeviceState.OFF;
76 //
77 return {device4};
78}
079
=== added file 'src/settings/enums.vala'
--- src/settings/enums.vala 1970-01-01 00:00:00 +0000
+++ src/settings/enums.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,115 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public enum DeviceType {
22 WIRED,
23 WIRELESS,
24 BLUETOOTH,
25 MOBILE,
26 GENERIC; // Shouldn't be used manually
27
28 public string get_name() {
29 switch (this) {
30 case WIRED:
31 return ("Wired");
32 case WIRELESS:
33 return ("Wireless");
34 case BLUETOOTH:
35 return ("Bluetooth");
36 case MOBILE:
37 return ("Mobile Broadband");
38 case GENERIC:
39 return ("Wired");
40 default:
41 assert_not_reached();
42 }
43 }
44
45 public string get_lname() {
46 switch (this) {
47 case WIRED:
48 return "wired";
49 case WIRELESS:
50 return "wireless";
51 case BLUETOOTH:
52 return "bluetooth";
53 case MOBILE:
54 return "mobile";
55 default:
56 assert_not_reached();
57 }
58 }
59
60 public string get_icon_name() {
61 switch (this) {
62 case WIRED:
63 return "network-wired";
64 case WIRELESS:
65 return "network-wireless";
66 case BLUETOOTH:
67 return "bluetooth-active";
68 case MOBILE:
69 return "gsm-3g-high";
70 case GENERIC:
71 return "network-wired";
72 default:
73 assert_not_reached();
74 }
75 }
76}
77
78public enum DeviceState {
79 OFF,
80 OFFLINE,
81 CONNECTED,
82 ONLINE;
83
84 public string get_name() {
85 switch (this) {
86 case OFF:
87 return ("Off");
88 case OFFLINE:
89 return ("Offline");
90 case CONNECTED:
91 return ("Connected");
92 case ONLINE:
93 return ("Online");
94 default:
95 assert_not_reached();
96 }
97 }
98}
99
100public enum WirelessMode {
101 INFRASTRUCTURE,
102 ADHOC;
103
104 public string get_name() {
105 switch (this) {
106 case INFRASTRUCTURE:
107 return ("Infrastructure");
108 case ADHOC:
109 return ("Ad-hoc");
110 default:
111 assert_not_reached();
112 }
113 }
114
115}
0116
=== added directory 'src/settings/frontend'
=== added directory 'src/settings/frontend/pages'
=== added file 'src/settings/frontend/pages/connections.vala'
--- src/settings/frontend/pages/connections.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/pages/connections.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,120 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public class ConnectionsPage : Object {
22
23 public Gtk.Alignment alignment;
24 public Gtk.Notebook notebook_right;
25 public bool viewed = false;
26
27 private DeviceView treeview_devices;
28
29 public ConnectionsPage(string datadir, Gtk.IconTheme icons,
30 Gtk.Alignment alignment,
31 Gtk.ScrolledWindow scrolledwindow_devices,
32 Gtk.Notebook notebook_right) {
33
34 this.alignment = alignment;
35 this.notebook_right = notebook_right;
36
37 // Create LHS
38 /// Create device view
39 var device_store = new DeviceStore(icons);
40 this.treeview_devices = new DeviceView(device_store);
41 /// Pack it
42 scrolledwindow_devices.add(this.treeview_devices);
43 /// Connect signals to callbacks
44 this.treeview_devices.get_selection().changed.connect(
45 this.on_treeview_devices_selection_changed);
46 this.treeview_devices.reordered.connect(
47 this.on_treeview_devices_reordered);
48
49 Device[] wired_devices = get_wired_devices();
50 Device[] wireless_devices = get_wireless_devices();
51 Device[] mobile_devices = get_mobile_devices();
52 Device[] bluetooth_devices = get_bluetooth_devices();
53
54 foreach (var device in wireless_devices) {
55 var box = new WirelessBox(device, datadir);
56 notebook_right.append_page(box, null);
57 this.add_device(device, box);
58 }
59
60 foreach (var device in mobile_devices) {
61 var box = new MobileBox(device, datadir);
62 notebook_right.append_page(box, null);
63 this.add_device(device, box);
64 }
65
66 foreach (var device in wired_devices) {
67 var box = new WiredBox(device, datadir);
68 notebook_right.append_page(box, null);
69 this.add_device(device, box);
70 }
71
72 foreach (var device in bluetooth_devices) {
73 var box = new BluetoothBox(device, datadir);
74 notebook_right.append_page(box, null);
75 this.add_device(device, box);
76 }
77
78 // Order the RHS notebook pages inaccordance with the deviceview
79 this.on_treeview_devices_reordered();
80
81 }
82
83 public void add_device(Device device, DeviceBox box) {
84 var liststore = this.treeview_devices.get_model() as DeviceStore;
85 liststore.add_device(device, box);
86 }
87
88 public void on_first_expose() {
89 if (!this.viewed) {
90 this.treeview_devices.get_selection().select_path(new Gtk.TreePath.first());
91 this.viewed = true;
92 }
93 }
94
95 private void on_treeview_devices_selection_changed() {
96 var selection = this.treeview_devices.get_selection();
97 Gtk.TreeModel model;
98 Gtk.TreeIter? iter;
99 selection.get_selected(out model, out iter);
100
101 if (iter != null) {
102 int i = model.get_path(iter).get_indices()[0];
103 this.notebook_right.set_current_page(i);
104 }
105 }
106
107 private void on_treeview_devices_reordered() {
108 var i = 0;
109 var model = this.treeview_devices.get_model();
110 model.foreach((model, path, iter) => {
111 GLib.Value value;
112 model.get_value(iter, DeviceStoreCol.SETTINGS_BOX, out value);
113 Gtk.VBox page = value.get_object() as Gtk.VBox;
114 this.notebook_right.reorder_child(page, i);
115 i += 1;
116 return false;
117 });
118 }
119
120}
0121
=== added file 'src/settings/frontend/utils.vala'
--- src/settings/frontend/utils.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/utils.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,199 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 * Gordon Allott <gord.allott@canonical.com>
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 3, as published
11 * by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranties of
15 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22namespace Utils.Color {
23 /* from libunity */
24 public static void rgb_to_hsv (float r, float g, float b,
25 out float hue, out float sat, out float val)
26 {
27 float min, max = 0.0f;
28 if (r > g)
29 max = (r > b) ? r : b;
30 else
31 max = (g > b) ? g : b;
32 if (r < g)
33 min = (r < b) ? r : b;
34 else
35 min = (g < b) ? g : b;
36
37 val = max;
38
39 float delta = max - min;
40 if (delta > 0.000001)
41 {
42 sat = delta / max;
43 hue = 0.0f;
44 if (r == max)
45 {
46 hue = (g - b) / delta;
47 if (hue < 0.0f)
48 hue += 6.0f;
49 }
50 else if (g == max)
51 {
52 hue = 2.0f + (b - r) / delta;
53 }
54 else if (b == max)
55 {
56 hue = 4.0f + (r - g) / delta;
57 }
58 hue /= 6.0f;
59 }
60 else
61 {
62 sat = 0.0f;
63 hue = 0.0f;
64 }
65 }
66
67 /* from libunity */
68 public static void hsv_to_rgb (float hue, float sat, float val,
69 out float r, out float g, out float b)
70 {
71 int i;
72 float f, w, q, t;
73
74 if (sat == 0.0)
75 {
76 r = g = b = val;
77 }
78 else
79 {
80 if (hue == 1.0)
81 hue = 0.0f;
82
83 hue *= 6.0f;
84
85 i = (int) hue;
86 f = hue - i;
87 w = val * (1.0f - sat);
88 q = val * (1.0f - (sat * f));
89 t = val * (1.0f - (sat * (1.0f - f)));
90
91 switch (i)
92 {
93 case 0:
94 r = val;
95 g = t;
96 b = w;
97 break;
98 case 1:
99 r = q;
100 g = val;
101 b = w;
102 break;
103 case 2:
104 r = w;
105 g = val;
106 b = t;
107 break;
108 case 3:
109 r = w;
110 g = q;
111 b = val;
112 break;
113 case 4:
114 r = t;
115 g = w;
116 b = val;
117 break;
118 case 5:
119 r = val;
120 g = w;
121 b = q;
122 break;
123 }
124 }
125 }
126
127 static void color_to_hls(Gdk.Color color, out float hue, out float luminance, out float saturation) {
128 float red, green, blue;
129 float h, l, v;
130
131 red = color.red / 65535.0f;
132 green = color.green / 65535.0f;
133 blue = color.blue / 65535.0f;
134
135 rgb_to_hsv(red, green, blue, out h, out l, out v);
136
137 hue = h;
138 luminance = l;
139 saturation = v;
140 }
141
142 static void color_from_hls(float hue, float luminance, float saturation, out Gdk.Color color) {
143 float red, green, blue;
144
145 hsv_to_rgb(hue, luminance, saturation, out red, out green, out blue);
146
147 color.red = (uint16) Math.floorf(red * 65535.0f + 0.5f);
148 color.green = (uint16) Math.floorf(green * 65535.0f + 0.5f);
149 color.blue = (uint16) Math.floorf(blue * 65535.0f + 0.5f);
150 }
151
152 static Gdk.Color shade(Gdk.Color color) {
153 float h;
154 float l;
155 float s;
156 float factor;
157 Utils.Color.color_to_hls(color, out h, out l, out s);
158
159 if (l > 0.5) {
160 // Colour is light, lets darken it
161 factor = 0.6f;
162 } else {
163 // Colour is dark, lets lighten it
164 factor = 1.4f;
165 }
166
167 l *= factor;
168 if (l > 1.0f) {
169 l = 1.0f;
170 } else if (l < 0) {
171 l = 0;
172 }
173
174 s*= factor;
175 if (s > 1.0f) {
176 s= 1.0f;
177 } else if (s < 0) {
178 s = 0;
179 }
180
181 Gdk.Color new_color;
182 Utils.Color.color_from_hls(h, l, s, out new_color);
183
184 return new_color;
185 }
186}
187
188namespace Utils.Gui {
189 static Gtk.Builder new_builder(string path) {
190 var builder = new Gtk.Builder();
191 try {
192 builder.add_from_file(path);
193 } catch (Error e) {
194 logger.debug(@"Can't find $path.");
195 }
196 builder.set_translation_domain("indicator-network-settings");
197 return builder;
198 }
199}
0200
=== added directory 'src/settings/frontend/widgets'
=== added file 'src/settings/frontend/widgets/cellrenderers.vala'
--- src/settings/frontend/widgets/cellrenderers.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/cellrenderers.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,224 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public const double PI = 3.1415926535897931;
22public const double PI_OVER_180 = 0.017453292519943295;
23
24class PinCellRenderer : Gtk.CellRenderer {
25
26 public string color { get; set; }
27
28 private const string RED_FILL = "#ef2929";
29 private const string RED_STROKE = "#a40000";
30 private const string GREEN_FILL = "#8ae234";
31 private const string GREEN_STROKE = "#4e9a06";
32 private const string YELLOW_FILL = "#fce94f";
33 private const string YELLOW_STROKE = "#c4a000";
34 private const string GREY_FILL = "#d3d7cf";
35 private const string GREY_STROKE = "#555753";
36
37 // Minimum size + (minimum padding times 2)
38 private const int MIN_CELL_WIDTH = 8 + (4 * 2);
39 private const int MIN_CELL_HEIGHT = 8 + (4 * 2);
40
41 // Ratio of radius of pin to width/height of cell
42 private const double PIN_RADIUS = 0.5;
43
44 public PinCellRenderer() {
45 GLib.Object ();
46 }
47
48 public override void get_size(Gtk.Widget widget, Gdk.Rectangle? cell_area,
49 out int x_offset, out int y_offset,
50 out int width, out int height) {
51 if (&x_offset != null) x_offset = 0;
52 if (&y_offset != null) y_offset = 0;
53 if (&width != null) width = this.MIN_CELL_WIDTH;
54 if (&height != null) height = this.MIN_CELL_HEIGHT;
55 }
56
57 public override void render(Gdk.Window window, Gtk.Widget widget,
58 Gdk.Rectangle background_area,
59 Gdk.Rectangle cell_area,
60 Gdk.Rectangle expose_area,
61 Gtk.CellRendererState flags) {
62
63 var cr = Gdk.cairo_create(window);
64
65 var x = cell_area.x;
66 var y = cell_area.y;
67 var width = cell_area.width;
68 var height = cell_area.height;
69
70 var lower_dimension = this.get_lower_dimension(width, height);
71 var pin_radius = (int) lower_dimension * this.PIN_RADIUS;
72
73 var x_offset = (width - lower_dimension) / 2;
74 var y_offset = (height - lower_dimension) / 2;
75
76 cr.arc(x+x_offset+pin_radius, y+y_offset+pin_radius, pin_radius/2, 0, 2 * Math.PI);
77
78 var stroke_string = "";
79 var fill_string = "";
80
81 switch (this.color) {
82 case "red":
83 stroke_string = this.RED_STROKE;
84 fill_string = this.RED_FILL;
85 break;
86 case "green":
87 stroke_string = this.GREEN_STROKE;
88 fill_string = this.GREEN_FILL;
89 break;
90 case "yellow":
91 stroke_string = this.YELLOW_STROKE;
92 fill_string = this.YELLOW_FILL;
93 break;
94 case "grey":
95 stroke_string = this.GREY_STROKE;
96 fill_string = this.GREY_FILL;
97 break;
98 }
99
100 var stroke = Gdk.Color();
101 stroke.parse(stroke_string, out stroke);
102 var fill = Gdk.Color();
103 fill.parse(fill_string, out fill);
104
105 cr.set_source_rgb((double) stroke.red / 65535.0,
106 (double) stroke.green / 65535.0,
107 (double) stroke.blue / 65535.0);
108 cr.stroke_preserve();
109
110 cr.set_source_rgb((double) fill.red / 65535.0,
111 (double) fill.green / 65535.0,
112 (double) fill.blue / 65535.0);
113 cr.fill();
114 }
115
116 private float get_lower_dimension(float n1, float n2) {
117 if (n1 > n2) {
118 return n2;
119 }
120 return n1;
121 }
122}
123
124
125class SignalStrengthCellRenderer : Gtk.CellRenderer {
126
127 public double strength { get; set; }
128
129 private Gtk.Widget style_widget;
130 private Gtk.Widget state_widget;
131
132 // Minimum size + (minimum padding times 2)
133 private const int MIN_CELL_WIDTH = 20 + (5 * 2);
134 private const int MIN_CELL_HEIGHT = 8 + (6 * 2);
135
136 // Ratio of width/height of bar to width/height of cell
137 private const double BAR_WIDTH = 0.8;
138 private const double BAR_HEIGHT = 0.45;
139
140 private const int CORNER_RADIUS = 3;
141
142 public SignalStrengthCellRenderer(Gtk.Widget style_widget, Gtk.Widget state_widget) {
143 GLib.Object();
144 this.style_widget = style_widget;
145 this.state_widget = state_widget;
146 }
147
148 public override void get_size(Gtk.Widget widget, Gdk.Rectangle? cell_area,
149 out int x_offset, out int y_offset,
150 out int width, out int height) {
151 if (&x_offset != null) x_offset = 0;
152 if (&y_offset != null) y_offset = 0;
153 if (&width != null) width = this.MIN_CELL_WIDTH;
154 if (&height != null) height = this.MIN_CELL_HEIGHT;
155 }
156
157 public override void render(Gdk.Window window, Gtk.Widget widget,
158 Gdk.Rectangle background_area,
159 Gdk.Rectangle cell_area,
160 Gdk.Rectangle expose_area,
161 Gtk.CellRendererState flags) {
162
163 var cr = Gdk.cairo_create(window);
164
165 var x = (int) cell_area.x;
166 var y = (int) cell_area.y;
167 var width = (int) cell_area.width;
168 var height = (int) cell_area.height;
169
170 var bar_width = (int) (width * this.BAR_WIDTH);
171 var bar_height = (int) (height * this.BAR_HEIGHT);
172
173 var x_offset = (int) ((width - bar_width) / 2);
174 var y_offset = (int) ((height - bar_height) / 2);
175
176 var state = this.state_widget.state;
177
178 var bg_fill = this.style_widget.style.bg[state];
179 var bg_stroke = this.style_widget.style.dark[state];
180
181 var fg_fill = this.style_widget.style.mid[state];
182 var fg_stroke = this.style_widget.style.dark[state];
183
184 this.draw_rounded_rectangle(cr, x+x_offset, y+y_offset,
185 x+x_offset+bar_width, y+y_offset+bar_height,
186 bg_fill, bg_stroke);
187
188 if (this.strength == 0) {
189 stdout.printf("strength = 0\n\n");
190 }
191
192
193 this.draw_rounded_rectangle(cr, x+x_offset, y+y_offset,
194 x+x_offset+((int) (bar_width*this.strength)), y+y_offset+bar_height,
195 fg_fill, fg_stroke);
196 }
197
198 private void draw_rounded_rectangle(Cairo.Context cr, int x, int y,
199 int w, int h, Gdk.Color fill, Gdk.Color stroke) {
200 this.layout_rounded_rectangle(cr, x, y, w, h);
201
202 cr.set_source_rgb((double) stroke.red / 65535.0,
203 (double) stroke.green / 65535.0,
204 (double) stroke.blue / 65535.0);
205 cr.stroke_preserve();
206
207 cr.set_source_rgb((double) fill.red / 65535.0,
208 (double) fill.green / 65535.0,
209 (double) fill.blue / 65535.0);
210 cr.fill();
211 }
212
213 private void layout_rounded_rectangle(Cairo.Context cr, int x, int y,
214 int w, int h) {
215 var r = this.CORNER_RADIUS;
216
217 cr.new_sub_path();
218 cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180);
219 cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0);
220 cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180);
221 cr.arc(r+x, h-r, r, 90*PI_OVER_180, PI);
222 cr.close_path();
223 }
224}
0225
=== added directory 'src/settings/frontend/widgets/device-boxes'
=== added file 'src/settings/frontend/widgets/device-boxes/base.vala'
--- src/settings/frontend/widgets/device-boxes/base.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/device-boxes/base.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,26 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public abstract class DeviceBox : Gtk.VBox {
22 /* A gtk.VBox which holds all of the widgets to control a device */
23
24 public DeviceBox() {}
25 public abstract void on_device_state_changed(DeviceState state);
26}
027
=== added file 'src/settings/frontend/widgets/device-boxes/bluetooth.vala'
--- src/settings/frontend/widgets/device-boxes/bluetooth.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/device-boxes/bluetooth.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,35 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21class BluetoothBox : DeviceBox {
22
23 /* A Gtk.VBox which holds all of the widgets to control a bluetooth
24 device. */
25
26 private Device device;
27
28 public BluetoothBox(Device device, string datadir) {
29 this.set_spacing(12);
30 this.device = device;
31 this.device.state_changed.connect(this.on_device_state_changed);
32 }
33
34 public override void on_device_state_changed(DeviceState state) {}
35}
036
=== added file 'src/settings/frontend/widgets/device-boxes/mobile.vala'
--- src/settings/frontend/widgets/device-boxes/mobile.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/device-boxes/mobile.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,151 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21class MobileBox : DeviceBox {
22
23 /* A Gtk.VBox which holds all of the widgets to control a mobile
24 device. It contains an InfoBox and ToggleSwitch to control and
25 monitor the state of the mobile device, and a set of widgets
26 to enter details about the mobile network to connect to. */
27
28 private Device device;
29 private InfoBox infobox;
30 private ToggleSwitch toggleswitch;
31 private Gtk.Label label_status;
32 private Gtk.Builder builder;
33 private Gtk.Table table_settings;
34 private Gtk.Entry entry_pin;
35 private Gtk.CheckButton checkbutton_show_pin;
36
37 private bool device_editable;
38 private bool settings_editable;
39
40 private const string[] sensitive_widgets = {"label_apn_place", "label_apn",
41 "label_pin_auth", "checkbutton_show_pin"};
42
43 public MobileBox(Device device, string datadir) {
44 this.set_spacing(12);
45 this.device = device;
46 this.device.state_changed.connect(this.on_device_state_changed);
47
48 // Infobox and Togglswitch
49 /// Creation
50 this.infobox = new InfoBox(false, 12);
51 this.toggleswitch = new ToggleSwitch();
52 this.label_status = new Gtk.Label(null);
53 /// Padding and alignment
54 this.label_status.set_alignment(0, 0.5f);
55 this.infobox.set_border_width(10);
56 /// Packing
57 this.infobox.pack_start(this.label_status, true, true);
58 this.infobox.pack_start(this.toggleswitch, false, true);
59 this.pack_start(this.infobox, false, false);
60 /// Connect signals;
61 this.toggleswitch.toggled.connect(this.on_toggleswitch_toggled);
62
63 // Network Settings
64 /// Creation
65 this.builder = Utils.Gui.new_builder(datadir+"ui/mobile_box.ui");
66 this.get_widgets();
67 this.connect_signals();
68 /// Packing
69 this.pack_start(this.table_settings, true, true);
70
71 this.update_widget_states(this.device.get_state());
72 this.on_checkbutton_show_pin_toggled();
73 }
74
75 private void get_widgets() {
76 this.table_settings = this.builder.get_object("table_settings") as Gtk.Table;
77 this.entry_pin = this.builder.get_object("entry_pin") as Gtk.Entry;
78 this.checkbutton_show_pin = this.builder.get_object("checkbutton_show_pin") as Gtk.CheckButton;
79 }
80
81 private void connect_signals() {
82 this.checkbutton_show_pin.toggled.connect(this.on_checkbutton_show_pin_toggled);
83 }
84
85 private void update_widget_states(DeviceState state) {
86 bool toggleswitch_state = false;
87 string status_text = "";
88
89 switch (state) {
90 case DeviceState.CONNECTED:
91 this.device_editable = true;
92 this.settings_editable = false;
93 toggleswitch_state = true;
94 status_text = ("Connected to “Vodafone UK”.");
95 break;
96 case DeviceState.ONLINE:
97 this.device_editable = true;
98 this.settings_editable = false;
99 toggleswitch_state = true;
100 status_text = ("Connected to the Internet on “Vodafone UK”.");
101 break;
102 case DeviceState.OFF:
103 this.device_editable = false;
104 this.settings_editable = true;
105 toggleswitch_state = false;
106 status_text = ("The Mobile Broadband device is powered off.");
107 break;
108 case DeviceState.OFFLINE:
109 this.device_editable = true;
110 this.settings_editable = true;
111 toggleswitch_state = false;
112 status_text = ("Mobile Broadband is offline.");
113 break;
114 }
115
116 this.toggleswitch.set_sensitive(this.device_editable);
117 this.toggleswitch.set_active(toggleswitch_state);
118 this.label_status.set_text(status_text);
119
120 this.table_settings.foreach(this.sensitise_widgets);
121 }
122
123 private void sensitise_widgets(Gtk.Widget widget) {
124
125 var name = widget.get_name();
126 if (name in this.sensitive_widgets) {
127 widget.set_sensitive(this.device_editable);
128 } else if (!(widget is Gtk.Box)) {
129 widget.set_sensitive(this.settings_editable);
130 } else {
131 var container = widget as Gtk.Container;
132 container.foreach(this.sensitise_widgets);
133 }
134 }
135
136 public override void on_device_state_changed(DeviceState state) {
137 this.update_widget_states(state);
138 }
139
140 private void on_toggleswitch_toggled() {
141 if (this.toggleswitch.get_active()) {
142 this.device.set_state(DeviceState.CONNECTED);
143 } else {
144 this.device.set_state(DeviceState.OFFLINE);
145 }
146 }
147
148 private void on_checkbutton_show_pin_toggled() {
149 this.entry_pin.set_visibility(this.checkbutton_show_pin.get_active());
150 }
151}
0152
=== added file 'src/settings/frontend/widgets/device-boxes/wired.vala'
--- src/settings/frontend/widgets/device-boxes/wired.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/device-boxes/wired.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,35 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21class WiredBox : DeviceBox {
22
23 /* A Gtk.VBox which holds all of the widgets to control a wired
24 device. */
25
26 private Device device;
27
28 public WiredBox(Device device, string datadir) {
29 this.set_spacing(12);
30 this.device = device;
31 this.device.state_changed.connect(this.on_device_state_changed);
32 }
33
34 public override void on_device_state_changed(DeviceState state) {}
35}
036
=== added file 'src/settings/frontend/widgets/device-boxes/wireless.vala'
--- src/settings/frontend/widgets/device-boxes/wireless.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/device-boxes/wireless.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,183 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public class WirelessBox : DeviceBox {
22
23 /* A Gtk.VBox which holds all of the widgets to control a wireless
24 device. It contains an InfoBox and ToggleSwitch to control and
25 monitor the state of the wireless device, and a
26 WirelessConnectionView to connect to and remember details for
27 wireless networks. */
28
29 private string datadir;
30 private Device device;
31 private InfoBox infobox;
32 private ToggleSwitch toggleswitch;
33 private Gtk.Label label_status;
34 private Gtk.Builder builder;
35 private WirelessConnectionView treeview_connections;
36 private Gtk.VBox vbox_connections;
37 private Gtk.Button button_connect;
38 private Gtk.Button button_forget;
39 private Gtk.Button button_edit;
40 private Gtk.ScrolledWindow scrolledwindow_connections;
41
42 public WirelessBox(Device device, string datadir) {
43 this.set_spacing(12);
44 this.datadir = datadir;
45 this.device = device;
46 this.device.state_changed.connect(this.on_device_state_changed);
47
48 // Infobox and Togglswitch
49 /// Creation
50 this.infobox = new InfoBox(false, 12);
51 this.toggleswitch = new ToggleSwitch();
52 this.label_status = new Gtk.Label(null);
53 /// Padding and alignment
54 this.label_status.set_alignment(0, 0.5f);
55 this.infobox.set_border_width(10);
56 /// Packing
57 this.infobox.pack_start(this.label_status, true, true);
58 this.infobox.pack_start(this.toggleswitch, false, true);
59 this.pack_start(this.infobox, false, false);
60 /// Connect signals;
61 this.toggleswitch.toggled.connect(this.on_toggleswitch_toggled);
62
63 // Network Settings
64 /// Creation
65 this.builder = Utils.Gui.new_builder(datadir+"ui/wireless_box.ui");
66 this.get_widgets();
67 this.connect_signals();
68 /// Packing
69 this.pack_start(this.vbox_connections, true, true);
70
71 // Connection View
72 /// Creation
73 var connection_store = new WirelessConnectionStore();
74 this.treeview_connections = new WirelessConnectionView(connection_store,
75 this.button_connect);
76 /// Packing
77 this.scrolledwindow_connections.add(this.treeview_connections);
78 /// Connect signals
79 this.treeview_connections.get_selection().changed.connect(this.on_treeview_connections_selection_changed);
80 /// Population
81 var connections = get_remembered_wireless_connections(device);
82 foreach (var connection in connections) {
83 this.add_connection(connection);
84 }
85
86 this.update_widget_states(this.device.get_state());
87 this.on_treeview_connections_selection_changed();
88 }
89
90 private void get_widgets() {
91 this.vbox_connections = this.builder.get_object("vbox_connections") as Gtk.VBox;
92 this.button_connect = this.builder.get_object("button_connect") as Gtk.Button;
93 this.button_forget = this.builder.get_object("button_forget") as Gtk.Button;
94 this.button_edit = this.builder.get_object("button_edit") as Gtk.Button;
95 this.scrolledwindow_connections = this.builder.get_object("scrolledwindow_connections") as Gtk.ScrolledWindow;
96 }
97
98 private void connect_signals() {
99 this.button_connect.clicked.connect(this.on_button_connect_clicked);
100 this.button_edit.clicked.connect(this.on_button_edit_clicked);
101 }
102
103 private void update_widget_states(DeviceState state) {
104 bool device_editable = false;
105 bool settings_editable = false;
106 bool toggleswitch_state = false;
107 string status_text = "";
108
109 switch (state) {
110 case DeviceState.CONNECTED:
111 device_editable = true;
112 settings_editable = true;
113 toggleswitch_state = true;
114 status_text = ("Wi-fi is on but not connected to the Internet.");
115 break;
116 case DeviceState.ONLINE:
117 device_editable = true;
118 settings_editable = true;
119 toggleswitch_state = true;
120 status_text = ("Wi-fi is on and connected to the Internet.");
121 break;
122 case DeviceState.OFF:
123 device_editable = false;
124 settings_editable = false;
125 toggleswitch_state = false;
126 status_text = ("The Wi-fi device is powered off.");
127 break;
128 case DeviceState.OFFLINE:
129 device_editable = true;
130 settings_editable = false;
131 toggleswitch_state = false;
132 status_text = ("Wi-fi is offline.");
133 break;
134 }
135
136 this.vbox_connections.set_sensitive(settings_editable);
137 this.toggleswitch.set_sensitive(device_editable);
138 this.toggleswitch.set_active(toggleswitch_state);
139 this.label_status.set_text(status_text);
140 }
141
142 private void add_connection(WifiConnection connection) {
143 var name = connection.name;
144 var signal = connection.signal;
145 var last_used = connection.last_used;
146
147 var liststore = this.treeview_connections.get_model() as WirelessConnectionStore;
148 liststore.add_connection(connection, name, signal, last_used);
149 }
150
151 public override void on_device_state_changed(DeviceState state) {
152 this.update_widget_states(state);
153 }
154
155 private void on_toggleswitch_toggled() {
156 if (this.toggleswitch.get_active()) {
157 this.device.set_state(DeviceState.CONNECTED);
158 } else {
159 this.device.set_state(DeviceState.OFFLINE);
160 }
161 }
162
163 private void on_button_connect_clicked() {
164 var connection = this.treeview_connections.get_selected_connection();
165 connection.connect_("password");
166 }
167
168 private void on_button_edit_clicked() {
169 var connection = this.treeview_connections.get_selected_connection();
170 var dialog = new EditConnectionDialog(connection, this.datadir);
171 //FIXME: make this work
172 //dialog.response.connect(() => { delete dialog; });
173 dialog.run();
174 }
175
176 private void on_treeview_connections_selection_changed() {
177 bool path_is_selected = (this.treeview_connections.get_selected_connection() != null);
178
179 this.button_connect.set_sensitive(path_is_selected);
180 this.button_forget.set_sensitive(path_is_selected);
181 this.button_edit.set_sensitive(path_is_selected);
182 }
183}
0184
=== added directory 'src/settings/frontend/widgets/dialogs'
=== added file 'src/settings/frontend/widgets/dialogs/edit-connection.vala'
--- src/settings/frontend/widgets/dialogs/edit-connection.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/dialogs/edit-connection.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,165 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public class EditConnectionDialog : GLib.Object {
22
23 public signal void response(int type);
24
25 private WifiConnection connection;
26 private Gtk.Builder builder;
27
28 private Gtk.Window dialog;
29 private Gtk.Table table_main;
30 private Gtk.Button button_save;
31 private Gtk.Button button_cancel;
32 private Gtk.Entry entry_name;
33 private Gtk.Entry entry_ssid;
34 private Gtk.Entry entry_bssid;
35 private Gtk.ComboBox combobox_mode;
36 private Gtk.CheckButton checkbutton_autoconnect;
37 private Gtk.CheckButton checkbutton_share_settings;
38
39 private string[] hint_labels = {"label_hint_name", "label_hint_ssid",
40 "label_hint_bssid","label_hint_mode"};
41
42 public EditConnectionDialog(WifiConnection connection, string datadir) {
43 this.connection = connection;
44
45 /// Creation
46 this.builder = Utils.Gui.new_builder(datadir+"ui/edit_connection_dialog.ui");
47 this.get_widgets();
48 this.create_extra_widgets();
49
50 this.connect_signals();
51 this.update_widget_values();
52 }
53
54 private void create_extra_widgets() {
55 // Creation
56 this.combobox_mode = new Gtk.ComboBox.text();
57
58 // Population
59 WirelessMode[] wireless_modes = {WirelessMode.INFRASTRUCTURE, WirelessMode.ADHOC};
60 foreach (var mode in wireless_modes) {
61 this.combobox_mode.append_text(mode.get_name());
62 }
63
64 // Packing
65 this.table_main.attach(this.combobox_mode, 1, 2, 6, 7, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL, 0, 0);
66
67 // Setup hint labels
68 foreach (var hint_label in this.hint_labels) {
69 var hint_label_widget = this.builder.get_object(hint_label) as Gtk.Label;
70 hint_label_widget.realize.connect(() => {
71 var state = hint_label_widget.get_state();
72 var color = hint_label_widget.style.fg[state];
73 var new_color = Utils.Color.shade(color);
74 hint_label_widget.modify_fg(state, new_color);
75 });
76 }
77 }
78
79 private void get_widgets() {
80 this.dialog = this.builder.get_object("window_main") as Gtk.Window;
81 this.table_main = this.builder.get_object("table_main") as Gtk.Table;
82 this.button_save = this.builder.get_object("button_save") as Gtk.Button;
83 this.button_cancel = this.builder.get_object("button_cancel") as Gtk.Button;
84
85 this.entry_name = this.builder.get_object("entry_name") as Gtk.Entry;
86 this.entry_ssid = this.builder.get_object("entry_ssid") as Gtk.Entry;
87 this.entry_bssid = this.builder.get_object("entry_bssid") as Gtk.Entry;
88 this.checkbutton_autoconnect = this.builder.get_object("checkbutton_autoconnect") as Gtk.CheckButton;
89 this.checkbutton_share_settings = this.builder.get_object("checkbutton_share_settings") as Gtk.CheckButton;
90 }
91
92 private void connect_signals() {
93 this.button_save.clicked.connect(this.on_button_save_clicked);
94 this.button_cancel.clicked.connect(this.on_button_cancel_clicked);
95 }
96
97 private void update_widget_values() {
98 var name = this.connection.name;
99 var ssid = this.connection.ssid;
100 var bssid = this.connection.bssid;
101 var mode = this.connection.mode;
102 var autoconnect = this.connection.autoconnect;
103 var share_settings = this.connection.share_settings;
104
105 if (name == null) {
106 this.entry_name.set_text("");
107 } else {
108 this.entry_name.set_text(name);
109 }
110 if (ssid == null) {
111 this.entry_ssid.set_text("");
112 } else {
113 this.entry_ssid.set_text(ssid);
114 }
115 if (bssid == null) {
116 this.entry_bssid.set_text("");
117 } else {
118 this.entry_bssid.set_text(bssid);
119 }
120
121 this.combobox_mode.set_active(mode);
122 this.checkbutton_autoconnect.set_active(autoconnect);
123 this.checkbutton_share_settings.set_active(share_settings);
124 }
125
126 private void save_widget_values() {
127 string? name = this.entry_name.get_text();
128 string? ssid = this.entry_ssid.get_text();
129 string? bssid = this.entry_bssid.get_text();
130 WirelessMode mode = (WirelessMode) this.combobox_mode.get_active();
131 var autoconnect = this.checkbutton_autoconnect.get_active();
132 var share_settings = this.checkbutton_share_settings.get_active();
133
134 if (name == "") {
135 name = null;
136 } if (ssid == "") {
137 ssid = null;
138 } if (bssid == "") {
139 bssid = null;
140 }
141
142 this.connection.name = name;
143 this.connection.ssid = ssid;
144 this.connection.bssid = bssid;
145 this.connection.mode = mode;
146 this.connection.autoconnect = autoconnect;
147 this.connection.share_settings = share_settings;
148 }
149
150 private void on_button_save_clicked() {
151 this.save_widget_values();
152 this.dialog.destroy();
153 this.response(Gtk.ResponseType.APPLY);
154 }
155
156 private void on_button_cancel_clicked() {
157 this.dialog.destroy();
158 this.response(Gtk.ResponseType.CANCEL);
159 }
160
161 public int run() {
162 this.dialog.show_all();
163 return 0;
164 }
165}
0166
=== added file 'src/settings/frontend/widgets/infobox.vala'
--- src/settings/frontend/widgets/infobox.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/infobox.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,63 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21class InfoBox : Gtk.HBox {
22
23 /* A gtk.HBox that is filled with the mid-colour and stroked with
24 the dark colour from a user's gtk theme so that it stands out. */
25
26 private const int YPAD = 1;
27 private const int XPAD = 1;
28
29 public InfoBox(bool homogeneous=false, int spacing=0) {
30 this.set_homogeneous(homogeneous);
31 this.set_spacing(spacing);
32 this.expose_event.connect(this.on_expose_event);
33 }
34
35 public bool on_expose_event(Gdk.EventExpose event) {
36 var cr = Gdk.cairo_create(window);
37
38 // Get geometry
39 var x = (int) (this.allocation.x + this.XPAD);
40 var y = (int) (this.allocation.y + this.YPAD);
41 var width = (int) (this.allocation.width - (this.XPAD * 2));
42 var height = (int) (this.allocation.height - (this.YPAD * 2));
43
44 // Fill with the mid color from the current gtk theme
45 var fill = this.style.mid[this.state];
46 // Fill with the dark color from the current gtk theme
47 var stroke = this.style.dark[this.state];
48
49 // Layout the rectangle
50 cr.rectangle(x, y, width, height);
51 // Stroke the outline
52 cr.set_source_rgb((double) stroke.red / 65535.0,
53 (double) stroke.green / 65535.0,
54 (double) stroke.blue / 65535.0);
55 cr.stroke_preserve();
56 // Fill it in
57 cr.set_source_rgb((double) fill.red / 65535.0,
58 (double) fill.green / 65535.0,
59 (double) fill.blue / 65535.0);
60 cr.fill();
61 return false;
62 }
63}
064
=== added file 'src/settings/frontend/widgets/stores.vala'
--- src/settings/frontend/widgets/stores.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/stores.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,143 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public enum DeviceStoreCol {
22 DEVICE_OBJ,
23 SETTINGS_BOX,
24 PIN,
25 ICON,
26 LABEL
27}
28
29class DeviceStore : Gtk.ListStore {
30
31 private Gtk.IconTheme icons;
32
33 private Gtk.TreeIter? device_iter;
34
35 public DeviceStore(Gtk.IconTheme icons) {
36 Type[] column_types;
37 column_types = {typeof(Device), typeof(Gtk.VBox),
38 typeof(string), typeof(Gdk.Pixbuf),
39 typeof(string)};
40 this.set_column_types(column_types);
41 this.icons = icons;
42 }
43
44 public void add_device(Device device, Gtk.VBox settings_box) {
45 device.state_changed.connect(this.on_device_state_changed);
46
47 var pin_color = this.get_pin_color(device.state);
48 var caption = device.state.get_name();
49 var label = device.type.get_name();
50 var icon = device.type.get_icon_name();
51 var markup = this.get_markup(label, caption);
52
53 Gdk.Pixbuf icon_pixbuf = null;
54 try {
55 icon_pixbuf = this.icons.load_icon(icon, 16, Gtk.IconLookupFlags.USE_BUILTIN);
56 } catch (Error e) {
57 var fallback_icon = DeviceType.GENERIC.get_icon_name();
58 logger.debug(@"Can't find '$icon' icon in your Gtk IconTheme, using '$fallback_icon' instead.");
59 try {
60 icon_pixbuf = this.icons.load_icon(fallback_icon, 16,
61 Gtk.IconLookupFlags.USE_BUILTIN);
62 } catch (Error e) {
63 logger.info("Failed to load fallback icon.");
64 }
65 }
66
67 Gtk.TreeIter iter;
68 this.append(out iter);
69 this.set(iter, 0, device, 1, settings_box, 2, pin_color, 3, icon_pixbuf, 4, markup);
70 }
71
72 private void on_device_state_changed(Device device, DeviceState state) {
73 var iter = this.get_iter_for_device(device);
74 var pin_color = this.get_pin_color(state);
75 var caption = state.get_name();
76 var label = device.type.get_name();
77
78 var markup = this.get_markup(label, caption);
79
80 this.set_value(iter, DeviceStoreCol.PIN, pin_color);
81 this.set_value(iter, DeviceStoreCol.LABEL, markup);
82 }
83
84 private Gtk.TreeIter get_iter_for_device(Device device) {
85 this.device_iter = null;
86 this.foreach((model, path, iter) => {
87 GLib.Value value;
88 model.get_value(iter, DeviceStoreCol.DEVICE_OBJ, out value);
89 if ((value.get_object() as Device) == device) {
90 this.device_iter = iter;
91 return true;
92 }
93 return false;
94 });
95 return this.device_iter;
96 }
97
98 private string get_pin_color(DeviceState state) {
99 switch (state) {
100 case DeviceState.OFF:
101 return "grey";
102 case DeviceState.OFFLINE:
103 return "red";
104 case DeviceState.CONNECTED:
105 return "yellow";
106 case DeviceState.ONLINE:
107 return "green";
108 default:
109 assert_not_reached();
110 }
111 }
112
113 private string get_markup(string label, string caption) {
114 return @"$label\n<span font_size='small'>$caption</span>";
115 }
116}
117
118
119public enum WirelessConnectionStoreCol {
120 CONNECTION_OBJ,
121 NETWORK,
122 SIGNAL,
123 LAST_USED
124}
125
126class WirelessConnectionStore : Gtk.ListStore {
127
128 public WirelessConnectionStore() {
129 Type[] column_types;
130 column_types = {typeof(WifiConnection), typeof(string),
131 typeof(double), typeof(string)};
132 this.set_column_types(column_types);
133 }
134
135 public void add_connection(WifiConnection obj, string network,
136 double signal, string last_used) {
137 Gtk.TreeIter iter;
138 this.append(out iter);
139 this.set(iter, 0, obj, 1, network, 2, signal, 3, last_used);
140 }
141}
142
143
0144
=== added file 'src/settings/frontend/widgets/toggleswitch.vala'
--- src/settings/frontend/widgets/toggleswitch.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/toggleswitch.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,356 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public class ToggleSwitch : Gtk.EventBox {
22
23 // A switch containing the values ON and OFF (or user-inputed) that
24 // hides the inactive value. It can be clicked or dragged to change
25 // state, or through an enter/return keypress.
26
27 public signal void clicked();
28 public signal void toggled();
29
30 // (In relation to the height of the slider)
31 private double LINE_HEIGHT_RATIO = 9.0/25.0;
32 private double LINE_SPACING_RATIO = 5.0/38.0;
33 private double CORNER_RADIUS = 3.0;
34
35 // (In relation to the width/height of the text)
36 private double TEXT_XPAD = 0.4;
37 private double TEXT_YPAD = 0.35;
38
39 private string[] values={"ON", "OFF"};
40 private Pango.Layout? layout = null;
41 private Atk.Object? atk = null;
42
43 public bool active = false;
44
45 public ToggleSwitch() {
46 this.set_visible_window(false);
47 this.app_paintable = true;
48 this.double_buffered = false;
49
50 // Set events for the widget to receive
51 this.set_can_focus(true);
52 this.set_events(Gdk.EventMask.KEY_PRESS_MASK|
53 Gdk.EventMask.ENTER_NOTIFY_MASK|
54 Gdk.EventMask.LEAVE_NOTIFY_MASK|
55 Gdk.EventMask.BUTTON_PRESS_MASK|
56 Gdk.EventMask.BUTTON_RELEASE_MASK);
57
58 // Connect signls and callbacks
59 this.style_set.connect(this.on_style_set);
60 this.expose_event.connect(this.on_expose_event);
61 this.button_press_event.connect(this.on_press);
62 this.button_release_event.connect(this.on_release);
63 this.key_release_event.connect(this.on_key_release);
64 this.enter_notify_event.connect(this.on_enter);
65 this.leave_notify_event.connect(this.on_leave);
66 this.motion_notify_event.connect(this.on_motion_notify_event);
67
68 // Calculate the best size
69 int calc_width;
70 int calc_height;
71 this.calculate_size(out calc_width, out calc_height);
72 this.set_size_request(calc_width, calc_height);
73
74 this.update_atk();
75 }
76
77 private void calculate_size(out int width, out int height) {
78 // Calculate the best size for the toggleswitch based on the
79 // dimensions of the user's default font.
80 this.layout = this.create_pango_layout(null);
81
82 this.layout.set_text(this.values[0], -1);
83
84 Pango.Rectangle extents;
85
86 this.layout.get_pixel_extents(null, out extents);
87 var text_width = extents.width;
88 var text_height = extents.height;
89
90 width = (int) ((text_width+(text_width*this.TEXT_XPAD*2))*2);
91 height = (int) (text_height+(text_height*this.TEXT_YPAD*2));
92 }
93
94
95 private void draw_widget() {
96 // Do the drawing of the actual widget.
97 var cr = Gdk.cairo_create(this.window);
98
99 // Draw the main background
100 this.draw_background(cr);
101
102 // Draw the text
103 this.draw_text();
104
105 // Draw the slider
106 this.draw_slider(cr);
107 }
108
109 private void draw_background(Cairo.Context cr) {
110 int x = this.allocation.x;
111 int y = this.allocation.y;
112 int width = this.allocation.width;
113 int height = this.allocation.height;
114
115 var state = this.state;
116 // Don't change colour of main background on hover or press
117 if ((this.state == Gtk.StateType.PRELIGHT) | (this.state == Gtk.StateType.ACTIVE)) {
118 state = Gtk.StateType.NORMAL;
119 }
120
121 // Get colours from theme
122 var bg_fill = this.style.base[state];
123 var bg_stroke = this.style.dark[state];
124 var left_fill = this.style.light[Gtk.StateType.SELECTED];
125 var left_stroke = this.style.mid[Gtk.StateType.SELECTED];
126 var right_fill = this.style.base[state];
127 var right_stroke = this.style.dark[state];
128
129 // Draw the background of the whole widget
130 this.draw_flat_rounded_rectangle(cr, x, y, width, height, bg_stroke, bg_fill);
131
132 // Draw the left (highlighted) part
133 this.draw_flat_rounded_rectangle(cr, x, y, width/2, height, left_stroke, left_fill);
134
135 // Draw the right (normal) part
136 this.draw_flat_rounded_rectangle(cr, x+width/2, y, width/2, height, right_stroke, right_fill);
137 }
138
139 private void draw_slider(Cairo.Context cr) {
140 int x = this.allocation.x;
141 int y = this.allocation.y;
142 int width = this.allocation.width;
143 int height = this.allocation.height;
144 int x_offset = 0;
145
146 if (this.active) {
147 x_offset = width/2;
148 }
149
150 var stroke = this.style.dark[this.state];
151 Gdk.Color fill1_rectangle;
152 Gdk.Color fill2_rectangle;
153
154 // Don't draw a gradient if insensitive
155 if (this.state == Gtk.StateType.INSENSITIVE) {
156 fill1_rectangle = this.style.bg[this.state];
157 fill2_rectangle = this.style.bg[this.state];
158 } else {
159 fill1_rectangle = this.style.light[this.state];
160 fill2_rectangle = this.style.mid[this.state];
161 }
162
163 // Draw the slider
164 this.draw_rounded_rectangle(cr, x+x_offset, y, width/2, height, stroke, fill1_rectangle, fill2_rectangle);
165
166 // Draw the vertical lines
167 this.draw_vertical_lines(cr, x+x_offset, y, width, height);
168
169 }
170
171 private void draw_vertical_lines(Cairo.Context cr, int x, int y, int width, int height) {
172 var fill_line_dark = this.style.dark[this.state];
173 var fill_line_light = this.style.light[this.state];
174 var line_height = (int) height*this.LINE_HEIGHT_RATIO;
175 var line_spacing = (int) (this.LINE_SPACING_RATIO * (width / 2));
176
177 var x_offset = ((width / 2) - (6+(line_spacing*2)))/2 + 2;
178 var y_offset = (height - line_height)/2;
179
180 double c_spacing = 0;
181 for (int i=0; i<3; i++) {
182 cr.rectangle(x+x_offset+c_spacing+1, y+y_offset, 1, line_height);
183 cr.set_source_rgb((double) fill_line_dark.red / 65535.0,
184 (double) fill_line_dark.green / 65535.0,
185 (double) fill_line_dark.blue / 65535.0);
186 cr.fill();
187 cr.rectangle(x+x_offset+c_spacing, y+y_offset, 1, line_height);
188 cr.set_source_rgb((double) fill_line_light.red / 65535.0,
189 (double) fill_line_light.green / 65535.0,
190 (double) fill_line_light.blue / 65535.0);
191 cr.fill();
192 c_spacing += line_spacing;
193 }
194 }
195
196 private void draw_text() {
197 this.draw_centered_text(this.values[0], "left");
198 this.draw_centered_text(this.values[1], "right");
199 }
200
201 private void draw_centered_text(string text, string gravity) {
202 if (this.layout == null) {
203 this.layout = this.create_pango_layout(null);
204 }
205
206 int x = this.allocation.x;
207 int y = this.allocation.y;
208 int width = this.allocation.width;
209 int height = this.allocation.height;
210
211 int x_offset;
212 int y_offset;
213 Pango.Rectangle extents;
214
215 this.layout.set_text(text, -1);
216 this.layout.get_pixel_extents(null, out extents);
217 var text_width = extents.width;
218 var text_height = extents.height;
219
220 x_offset = (width/2 - text_width) / 2;
221
222 if (gravity == "right") {
223 x_offset += width/2;
224 }
225
226 y_offset = (height - text_height) / 2;
227
228 this.style.draw_layout(this.window, this.get_state(), true,
229 {x, y, width, height},
230 this, "", x+x_offset, y+y_offset,
231 this.layout);
232 }
233
234
235 private void draw_rounded_rectangle(Cairo.Context cr, double x,
236 double y, double w, double h, Gdk.Color stroke, Gdk.Color fill1, Gdk.Color fill2) {
237
238 var r = this.CORNER_RADIUS;
239 cr.new_sub_path();
240 cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180);
241 cr.arc(x+w-r, r+y, r, 270*PI_OVER_180, 0);
242 cr.arc(x+w-r, y+h-r, r, 0, 90*PI_OVER_180);
243 cr.arc(r+x, y+h-r, r, 90*PI_OVER_180, PI);
244 cr.close_path();
245
246 cr.set_source_rgb((double) stroke.red / 65535.0,
247 (double) stroke.green / 65535.0,
248 (double) stroke.blue / 65535.0);
249 cr.stroke_preserve();
250
251 var linear = new Cairo.Pattern.linear(x, y, x, y+h);
252 linear.add_color_stop_rgba(0.00, (double) fill1.red / 65535.0,
253 (double) fill1.green / 65535.0, (double) fill1.blue / 65535.0, 1);
254 linear.add_color_stop_rgba(0.8, (double) fill2.red / 65535.0,
255 (double) fill2.green / 65535.0, (double) fill2.blue / 65535.0, 1);
256 cr.set_source(linear);
257 cr.fill();
258 }
259
260 private void draw_flat_rounded_rectangle(Cairo.Context cr, double x,
261 double y, double w, double h, Gdk.Color stroke, Gdk.Color fill) {
262
263 var r = this.CORNER_RADIUS;
264 cr.new_sub_path();
265 cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180);
266 cr.arc(x+w-r, r+y, r, 270*PI_OVER_180, 0);
267 cr.arc(x+w-r, y+h-r, r, 0, 90*PI_OVER_180);
268 cr.arc(r+x, y+h-r, r, 90*PI_OVER_180, PI);
269 cr.close_path();
270
271 cr.set_source_rgb((double) stroke.red / 65535.0,
272 (double) stroke.green / 65535.0,
273 (double) stroke.blue / 65535.0);
274 cr.stroke_preserve();
275
276 cr.set_source_rgb((double) fill.red / 65535.0,
277 (double) fill.green / 65535.0,
278 (double) fill.blue / 65535.0);
279 cr.fill();
280 }
281
282 private void update_atk() {
283 // Accessibility info
284 if (this.atk == null) {
285 this.atk = this.get_accessible();
286 this.atk.set_role(Atk.Role.CHECK_BOX);
287 }
288
289 // Update ATK description, based on state
290 if (this.active) {
291 this.atk.set_name(this.values[0]);
292 } else {
293 this.atk.set_name(this.values[1]);
294 }
295 }
296
297 private void on_style_set(Gtk.Style? style) {
298 int calc_width;
299 int calc_height;
300
301 this.calculate_size(out calc_width, out calc_height);
302 this.set_size_request(calc_width, calc_height);
303 }
304
305 private bool on_expose_event(Gdk.EventExpose event) {
306 this.draw_widget();
307 return true;
308 }
309
310 private bool on_press(Gdk.EventButton event) {
311 this.set_state(Gtk.StateType.ACTIVE);
312 this.grab_focus();
313 return false;
314 }
315
316 private bool on_release(Gdk.EventButton event) {
317 this.set_state(Gtk.StateType.PRELIGHT);
318 this.active = !this.active;
319 this.toggled();
320 return false;
321 }
322
323 private bool on_motion_notify_event(Gdk.EventMotion event) {
324 this.queue_draw();
325 return false;
326 }
327
328 private bool on_key_release(Gdk.EventKey event) {
329 if (this.has_focus) {
330 if ((Gdk.keyval_name(event.keyval) == "Return") | (Gdk.keyval_name(event.keyval) == "Enter")) {
331 this.toggled();
332 }
333 }
334 return false;
335 }
336
337 private bool on_enter(Gdk.EventCrossing event) {
338 this.set_state(Gtk.StateType.PRELIGHT);
339 return false;
340 }
341
342 private bool on_leave(Gdk.EventCrossing event) {
343 this.set_state(Gtk.StateType.NORMAL);
344 return false;
345 }
346
347 public bool get_active() {
348 return this.active;
349 }
350
351 public void set_active(bool active) {
352 this.active = active;
353 this.queue_draw();
354 }
355
356}
0357
=== added file 'src/settings/frontend/widgets/treeviews.vala'
--- src/settings/frontend/widgets/treeviews.vala 1970-01-01 00:00:00 +0000
+++ src/settings/frontend/widgets/treeviews.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,133 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21class DeviceView : Gtk.TreeView {
22
23 public signal void reordered();
24
25 private bool dragging = false;
26
27 public DeviceView (DeviceStore store) {
28 this.set_model(store);
29
30 // Device (main) Column (contains pin icon, type icon and label)
31 var column = new Gtk.TreeViewColumn();
32 column.set_title(("Device"));
33 var cr_pin = new PinCellRenderer();
34 var cr_icon = new Gtk.CellRendererPixbuf();
35 var cr_label = new Gtk.CellRendererText();
36 column.pack_start(cr_pin, false);
37 column.set_attributes(cr_pin, "color", DeviceStoreCol.PIN);
38 column.pack_start(cr_icon, false);
39 column.set_attributes(cr_icon, "pixbuf", DeviceStoreCol.ICON);
40 column.pack_start(cr_label, true);
41 column.set_attributes(cr_label, "markup", DeviceStoreCol.LABEL);
42 cr_label.set_property("ellipsize", Pango.EllipsizeMode.END);
43 this.append_column(column);
44
45 this.set_headers_visible(false);
46 /* FIXME: when get gtk errors if we enable reordering and
47 try to get the selected path
48 this.set_reorderable(true);*/
49
50 this.drag_begin.connect(this.on_drag_begin);
51 this.drag_end.connect(this.on_drag_end);
52 this.drag_failed.connect(this.on_drag_failed);
53 }
54
55 private void on_drag_begin(Gdk.DragContext drag_context) {
56 this.dragging = true;
57 }
58
59 private bool on_drag_failed(Gdk.DragContext drag_context, Gtk.DragResult drag_result) {
60 this.dragging = false;
61 return true;
62 }
63
64 private void on_drag_end(Gdk.DragContext drag_context) {
65 if (this.dragging) {
66 this.reordered();
67 }
68 }
69
70/* FIXME: unused for now so comment it out
71
72 public Device? get_selected_device() {
73 Gtk.TreeModel model;
74 Gtk.TreeIter? iter;
75 this.get_selection().get_selected(out model, out iter);
76 if (iter == null) {
77 return null;
78 } else {
79 GLib.Value value;
80 model.get_value(iter, 0, out value);
81 return value.get_object() as Device;
82 }
83
84 }
85*/
86
87}
88
89class WirelessConnectionView : Gtk.TreeView {
90
91 public WirelessConnectionView(WirelessConnectionStore store, Gtk.Widget style_widget) {
92 this.set_model(store);
93
94 // Network Column (contains label)
95 var network_column = new Gtk.TreeViewColumn();
96 network_column.set_title(("Network"));
97 var cr_label_network = new Gtk.CellRendererText();
98 network_column.pack_start(cr_label_network, true);
99 network_column.set_attributes(cr_label_network, "markup", WirelessConnectionStoreCol.NETWORK);
100 network_column.set_expand(true);
101 this.append_column(network_column);
102
103 // Signal Column (contains signal indicator)
104 var signal_column = new Gtk.TreeViewColumn();
105 signal_column.set_title(("Signal"));
106 var cr_signal = new SignalStrengthCellRenderer(style_widget, this);
107 signal_column.pack_start(cr_signal, true);
108 signal_column.set_attributes(cr_signal, "strength", 2);
109 signal_column.set_clickable(true);
110 signal_column.set_sort_column_id(2);
111 this.append_column(signal_column);
112
113 // Last Used Column (contains label)
114 var last_used_column = new Gtk.TreeViewColumn();
115 last_used_column.set_title(("Last Used"));
116 var cr_label_last_used = new Gtk.CellRendererText();
117 last_used_column.pack_start(cr_label_last_used, true);
118 last_used_column.set_attributes(cr_label_last_used, "markup", WirelessConnectionStoreCol.LAST_USED);
119 this.append_column(last_used_column);
120 }
121
122 public WifiConnection? get_selected_connection() {
123 Gtk.TreeModel model;
124 Gtk.TreeIter? iter;
125 this.get_selection().get_selected(out model, out iter);
126 if (iter != null) {
127 GLib.Value value;
128 model.get_value(iter, WirelessConnectionStoreCol.CONNECTION_OBJ, out value);
129 return value.get_object() as WifiConnection;
130 }
131 return null;
132 }
133}
0134
=== removed file 'src/settings/indicator-network-settings'
--- src/settings/indicator-network-settings 2010-12-13 13:44:21 +0000
+++ src/settings/indicator-network-settings 1970-01-01 00:00:00 +0000
@@ -1,61 +0,0 @@
1#!/usr/bin/python
2# Copyright (C) 2010 Canonical
3#
4# Authors:
5# Andrew Higginson
6#
7# This program is free software; you can redistribute it and/or modify it under
8# the terms of the GNU General Public License as published by the Free Software
9# Foundation; version 3.
10#
11# This program is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14# details.
15#
16# You should have received a copy of the GNU General Public License along with
17# this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20import pygtk
21pygtk.require ("2.0")
22import gtk
23
24import gettext
25import logging
26import os
27import sys
28
29from optparse import OptionParser
30from indicatorNetworkSettings.enums import *
31from indicatorNetworkSettings.version import *
32
33if __name__ == "__main__":
34 parser = OptionParser("usage: %prog [options]", version="%prog "+VERSION)
35 parser.add_option("--debug", action="store_true",
36 help="enable debug mode", default=False)
37 parser.add_option("--force-rtl", action="store_true",
38 help="force rtl mode (useful for debugging)",
39 default=False)
40 (options, args) = parser.parse_args()
41
42 if options.debug:
43 logging.basicConfig(level=logging.DEBUG)
44 else:
45 logging.basicConfig(level=logging.INFO)
46
47 # Override text direction for testing purposes
48 if options.force_rtl:
49 gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL)
50
51 if os.path.exists("./ui/indicator-network-settings.ui"):
52 logging.info("Running locally")
53 datadir = "./"
54 else:
55 datadir = "/usr/share/indicator-network/"
56
57 from indicatorNetworkSettings.app import NetworkSettingsApp
58
59 app = NetworkSettingsApp(datadir)
60 app.run()
61
620
=== removed directory 'src/settings/indicatorNetworkSettings'
=== removed file 'src/settings/indicatorNetworkSettings/Makefile.am'
--- src/settings/indicatorNetworkSettings/Makefile.am 2010-12-13 13:55:55 +0000
+++ src/settings/indicatorNetworkSettings/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
1SUBDIRS = \
2 backend \
3 frontend
4
5# indicator-network-settings
6insdir = $(pkgdatadir)/indicatorNetworkSettings
7ins_PYTHON = \
8 app.py \
9 enums.py \
10 __init__.py \
11 SimpleGtkbuilderApp.py \
12 utils.py \
13 version.py
140
=== removed file 'src/settings/indicatorNetworkSettings/SimpleGtkbuilderApp.py'
--- src/settings/indicatorNetworkSettings/SimpleGtkbuilderApp.py 2010-12-13 13:45:08 +0000
+++ src/settings/indicatorNetworkSettings/SimpleGtkbuilderApp.py 1970-01-01 00:00:00 +0000
@@ -1,58 +0,0 @@
1"""
2 SimpleGtkbuilderApp.py
3 Module that provides an object oriented abstraction to pygtk and gtkbuilder
4 Copyright (C) 2009 Canonical
5 Author Michael Vogt
6 based on ideas from SimpleGladeBuilder by Sandino Flores Moreno
7"""
8
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; version 3.
12#
13# This library is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public
19# License along with this library; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21# USA
22
23import sys
24import gtk
25
26class SimpleGtkbuilderApp(object):
27 def __init__(self, path, domain):
28 self.builder = gtk.Builder()
29 self.builder.set_translation_domain(domain)
30 self.builder.add_from_file(path)
31 self.builder.connect_signals(self)
32 for o in self.builder.get_objects():
33 if issubclass(type(o), gtk.Buildable):
34 name = gtk.Buildable.get_name(o)
35 setattr(self, name, o)
36 else:
37 print >> sys.stderr, "WARNING: can not get name for '%s'" % o
38
39 def run(self):
40 """
41 Starts the main loop of processing events checking for Control-C.
42
43 The default implementation checks wheter a Control-C is pressed,
44 then calls on_keyboard_interrupt().
45
46 Use this method for starting programs.
47 """
48 try:
49 gtk.main()
50 except KeyboardInterrupt:
51 self.on_keyboard_interrupt()
52
53 def on_keyboard_interrupt(self):
54 """
55 This method is called by the default implementation of run()
56 after a program is finished by pressing Control-C.
57 """
58 pass
590
=== removed file 'src/settings/indicatorNetworkSettings/__init__.py'
--- src/settings/indicatorNetworkSettings/__init__.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1
20
=== removed file 'src/settings/indicatorNetworkSettings/app.py'
--- src/settings/indicatorNetworkSettings/app.py 2010-12-13 14:18:58 +0000
+++ src/settings/indicatorNetworkSettings/app.py 1970-01-01 00:00:00 +0000
@@ -1,78 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import locale
20import gtk
21import os
22import gettext
23
24from indicatorNetworkSettings.enums import *
25from indicatorNetworkSettings.version import *
26from indicatorNetworkSettings.frontend.pages.connections import \
27 ConnectionsPage
28from indicatorNetworkSettings.backend.devicemanager import \
29 DeviceManager
30from indicatorNetworkSettings.SimpleGtkbuilderApp import \
31 SimpleGtkbuilderApp
32
33class NetworkSettingsApp(SimpleGtkbuilderApp):
34 def __init__(self, datadir):
35 SimpleGtkbuilderApp.__init__(self,
36 os.path.join(datadir, "ui", "indicator-network-settings.ui"),
37 "indicator-network-settings")
38
39 # Useful variables
40 self.datadir = datadir
41 self.icons = gtk.icon_theme_get_default()
42
43 # Setup Translations
44 self._setup_translations()
45
46 self.devicemanager = DeviceManager()
47
48 # Setup Pages
49 self.page_connections = ConnectionsPage(self, datadir)
50 self.pages = [self.page_connections]
51
52 self.on_notebook_main_page_switched(None, None, 0)
53
54 # Callbacks
55 def on_window_main_delete_event(self, widget, event):
56 gtk.main_quit()
57
58 def on_notebook_main_page_switched(self, widget, move_focus, page_num):
59 page_alignment = self.notebook_main.get_nth_page(page_num)
60
61 for page in self.pages:
62 if page.alignment == page_alignment:
63 page.on_first_expose()
64
65 # Private Functions
66 def _setup_translations(self):
67 gettext.bindtextdomain("indicator-network-settings",
68 "/usr/share/locale")
69 gettext.textdomain("indicator-network-settings")
70 try:
71 locale.setlocale(locale.LC_ALL, "")
72 except Exception:
73 print "setlocale failed"
74
75 # Public Functions
76 def run(self):
77 self.window_main.show_all()
78 super(NetworkSettingsApp, self).run()
790
=== removed directory 'src/settings/indicatorNetworkSettings/backend'
=== removed file 'src/settings/indicatorNetworkSettings/backend/Makefile.am'
--- src/settings/indicatorNetworkSettings/backend/Makefile.am 2010-12-13 13:55:55 +0000
+++ src/settings/indicatorNetworkSettings/backend/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
1# indicator-network-settings
2insdir = $(pkgdatadir)/indicatorNetworkSettings/backend
3ins_PYTHON = \
4 connection.py \
5 device.py \
6 __init__.py
70
=== removed file 'src/settings/indicatorNetworkSettings/backend/__init__.py'
--- src/settings/indicatorNetworkSettings/backend/__init__.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/backend/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1
20
=== removed file 'src/settings/indicatorNetworkSettings/backend/connection.py'
--- src/settings/indicatorNetworkSettings/backend/connection.py 2010-12-13 14:18:58 +0000
+++ src/settings/indicatorNetworkSettings/backend/connection.py 1970-01-01 00:00:00 +0000
@@ -1,31 +0,0 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2010 Canonical
5#
6# Authors:
7# Andrew Higginson
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; version 3.
12#
13# This program is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16# details.
17#
18# You should have received a copy of the GNU General Public License along with
19# this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22import datetime
23
24class WifiConnection(object):
25 def __init__(self):
26 self.network = None
27 self.signal = None
28 self.last_used = None
29
30 def connect_(self, key):
31 print "Connecting to %s" % self.network
320
=== removed file 'src/settings/indicatorNetworkSettings/backend/connmanmanager.py'
--- src/settings/indicatorNetworkSettings/backend/connmanmanager.py 2010-12-13 18:48:43 +0000
+++ src/settings/indicatorNetworkSettings/backend/connmanmanager.py 1970-01-01 00:00:00 +0000
@@ -1,160 +0,0 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2010 Canonical
5#
6# Authors:
7# Kalle Valo
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; version 3.
12#
13# This program is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16# details.
17#
18# You should have received a copy of the GNU General Public License along with
19# this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22import gobject
23import dbus
24import dbus.mainloop.glib
25
26from indicatorNetworkSettings.backend.service import create_service
27
28class ConnmanManager(gobject.GObject):
29 def get_properties(self):
30 return self.properties
31
32 def is_available(self, technology):
33 if technology in self.properties["AvailableTechnologies"]:
34 return True
35
36 return False
37
38 def is_enabled(self, technology):
39 if technology in self.properties["EnabledTechnologies"]:
40 return True
41
42 return False
43
44 def is_connected(self, technology):
45 if technology in self.properties["ConnectedTechnologies"]:
46 return True
47
48 return False
49
50 def enable_technology(self, technology):
51 if not self.is_available(technology):
52 return
53
54 if self.is_enabled(technology):
55 return
56
57 self.manager.EnableTechnology(technology)
58
59 def disable_technology(self, technology):
60 if not self.is_available(technology):
61 return
62
63 if not self.is_enabled(technology):
64 return
65
66 self.manager.DisableTechnology(technology)
67
68 def get_available_technologies(self):
69 return self.properties["AvailableTechnologies"]
70
71 def get_enabled_technologies(self):
72 return self.properties["EnabledTechnologies"]
73
74 def get_connected_technologies(self):
75 return self.properties["ConnectedTechnologies"]
76
77 def request_scan(self, technology=""):
78 self.manager.RequestScan(technology)
79
80 def service_property_changed(self, name, value, path, interface):
81 service = self.get_service(path)
82
83 if not service:
84 return
85
86 service.update_property(name, value)
87
88 def manager_property_changed(self, name, value, path, interface):
89 self.properties[name] = value
90
91 if name == "Services":
92 self.update_services()
93 self.emit("services-changed")
94 elif name in ["AvailableTechnologies", "EnabledTechnologies",
95 "ConnectedTechnologies"]:
96 self.emit("technologies-changed")
97
98 def add_service(self, service):
99 self.services[service.get_path()] = service
100
101 def get_services(self):
102 return self.services.values()
103
104 def get_services_by_technology(self, technology):
105 result = []
106 for service in self.get_services():
107 if service.get_type() == technology:
108 result.append(service)
109
110 return result
111
112 def get_service(self, path):
113 if path not in self.services:
114 return None
115
116 return self.services[path]
117
118 def update_services(self):
119 self.services = {}
120
121 for path in self.properties["Services"]:
122 service = create_service(path)
123 self.add_service(service)
124
125 def __init__(self):
126 self.__gobject_init__()
127 self.services = {}
128 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
129 self.bus = dbus.SystemBus()
130
131 self.bus.add_signal_receiver(self.service_property_changed,
132 bus_name="net.connman",
133 dbus_interface="net.connman.Service",
134 signal_name = "PropertyChanged",
135 path_keyword="path",
136 interface_keyword="interface")
137
138 self.manager = dbus.Interface(self.bus.get_object("net.connman",
139 "/"),
140 "net.connman.Manager")
141 self.bus.add_signal_receiver(self.manager_property_changed,
142 bus_name="net.connman",
143 dbus_interface="net.connman.Manager",
144 signal_name = "PropertyChanged",
145 path_keyword="path",
146 interface_keyword="interface")
147
148 self.properties = self.manager.GetProperties()
149
150 # FIXME: handle if connmand disappears
151 # FIXME: how to handle ordering and other changes in service list?
152
153 self.update_services()
154
155
156gobject.type_register(ConnmanManager)
157gobject.signal_new("technologies-changed", ConnmanManager,
158 gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
159gobject.signal_new("services-changed", ConnmanManager,
160 gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
1610
=== removed file 'src/settings/indicatorNetworkSettings/backend/device.py'
--- src/settings/indicatorNetworkSettings/backend/device.py 2010-12-13 21:12:32 +0000
+++ src/settings/indicatorNetworkSettings/backend/device.py 1970-01-01 00:00:00 +0000
@@ -1,75 +0,0 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2010 Canonical
5#
6# Authors:
7# Andrew Higginson
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; version 3.
12#
13# This program is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16# details.
17#
18# You should have received a copy of the GNU General Public License along with
19# this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22import gobject
23
24from indicatorNetworkSettings.enums import *
25
26class UnknownDeviceTypeError(Exception):
27 def __init__(self, devicetype):
28 self.devicetype
29
30 def __str__(self):
31 return self.devicetype
32
33class Device(gobject.GObject):
34
35 __gsignals__ = {
36 "state-changed" : (gobject.SIGNAL_RUN_LAST,
37 gobject.TYPE_NONE,
38 ([gobject.TYPE_PYOBJECT]),
39 ),
40 }
41
42
43 def __init__(self, devicetype, connman):
44 super(Device, self).__init__()
45 self.type = devicetype
46 self.state = DEVICE_STATE_OFF
47 self.connman = connman
48
49 if self.type == DEVICE_TYPE_WIRED:
50 self.typestring = "ethernet"
51 elif self.type == DEVICE_TYPE_WIRELESS:
52 self.typestring = "wifi"
53 elif self.type == DEVICE_TYPE_MOBILE:
54 self.typestring = "cellular"
55 elif self.type == DEVICE_TYPE_BLUETOOTH:
56 self.typestring = "bluetooth"
57 else:
58 raise UnknownDeviceTypeError(self.type)
59
60 def set_state(self, state):
61
62 if self.state == state:
63 return
64
65 self.state = state
66 self.emit("state-changed", self.state)
67
68 def get_state(self):
69 return self.state
70
71 def enable(self):
72 self.connman.enable_technology(self.typestring)
73
74 def disable(self):
75 self.connman.disable_technology(self.typestring)
760
=== removed file 'src/settings/indicatorNetworkSettings/backend/devicemanager.py'
--- src/settings/indicatorNetworkSettings/backend/devicemanager.py 2010-12-14 12:24:54 +0000
+++ src/settings/indicatorNetworkSettings/backend/devicemanager.py 1970-01-01 00:00:00 +0000
@@ -1,153 +0,0 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2010 Canonical
5#
6# Authors:
7# Andrew Higginson
8# Kalle Valo
9#
10# This program is free software; you can redistribute it and/or modify it under
11# the terms of the GNU General Public License as published by the Free Software
12# Foundation; version 3.
13#
14# This program is distributed in the hope that it will be useful, but WITHOUT
15# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17# details.
18#
19# You should have received a copy of the GNU General Public License along with
20# this program; if not, write to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
23import gobject
24
25from indicatorNetworkSettings.backend.device import Device
26from indicatorNetworkSettings.backend.connmanmanager import ConnmanManager
27from indicatorNetworkSettings.enums import *
28
29class DeviceManager(gobject.GObject):
30
31 __gsignals__ = {
32 "devices-changed" : (gobject.SIGNAL_RUN_LAST,
33 gobject.TYPE_NONE,
34 (),
35 ),
36 }
37
38 def __init__(self):
39 super(DeviceManager, self).__init__()
40 self.connman = ConnmanManager()
41
42 self.ethernet_device = Device(DEVICE_TYPE_WIRED, self.connman)
43 self.wifi_device = Device(DEVICE_TYPE_WIRELESS, self.connman)
44 self.cellular_device = Device(DEVICE_TYPE_MOBILE, self.connman)
45 self.bluetooth_device = Device(DEVICE_TYPE_BLUETOOTH, self.connman)
46
47 self.ethernet_available = False
48 self.wifi_available = False
49 self.cellular_available = False
50 self.bluetooth_available = False
51
52 self.connman.connect("technologies-changed", self.technologies_updated)
53 self.technologies_updated(self.connman)
54
55 def update_availability(self):
56 techs = self.connman.get_available_technologies()
57 changed = False
58
59 avail = "ethernet" in techs
60 if avail != self.ethernet_available:
61 self.ethernet_available = avail
62 changed = True
63
64 avail = "wifi" in techs
65 if avail != self.wifi_available:
66 self.wifi_available = avail
67 changed = True
68
69 avail = "cellular" in techs
70 if avail != self.cellular_available:
71 self.cellular_available = avail
72 changed = True
73
74 avail = "bluetooth" in techs
75 if avail != self.bluetooth_available:
76 self.bluetooth_available = avail
77 changed = True
78
79 if not changed:
80 return
81
82 self.emit("devices-changed")
83
84 def update_state(self):
85 enabled = self.connman.get_enabled_technologies()
86 connected = self.connman.get_connected_technologies()
87
88 if "ethernet" in connected:
89 self.ethernet_device.set_state(DEVICE_STATE_CONNECTED)
90 elif "ethernet" in enabled:
91 self.ethernet_device.set_state(DEVICE_STATE_ON)
92 else:
93 self.ethernet_device.set_state(DEVICE_STATE_OFF)
94
95 if "wifi" in connected:
96 self.wifi_device.set_state(DEVICE_STATE_CONNECTED)
97 elif "wifi" in enabled:
98 self.wifi_device.set_state(DEVICE_STATE_ON)
99 else:
100 self.wifi_device.set_state(DEVICE_STATE_OFF)
101
102 if "cellular" in connected:
103 self.cellular_device.set_state(DEVICE_STATE_CONNECTED)
104 elif "cellular" in enabled:
105 self.cellular_device.set_state(DEVICE_STATE_ON)
106 else:
107 self.cellular_device.set_state(DEVICE_STATE_OFF)
108
109 if "bluetooth" in connected:
110 self.bluetooth_device.set_state(DEVICE_STATE_CONNECTED)
111 elif "bluetooth" in enabled:
112 self.bluetooth_device.set_state(DEVICE_STATE_ON)
113 else:
114 self.bluetooth_device.set_state(DEVICE_STATE_OFF)
115
116 def technologies_updated(self, connman):
117 self.update_availability()
118 self.update_state()
119
120 def get_wired_devices(self):
121 devices = []
122
123 if self.ethernet_available:
124 devices.append(self.ethernet_device)
125
126 return devices
127
128 def get_wireless_devices(self):
129 devices = []
130
131 if self.wifi_available:
132 devices.append(self.wifi_device)
133
134 return devices
135
136 def get_mobile_devices(self):
137 devices = []
138
139 if self.cellular_available:
140 devices.append(self.cellular_device)
141
142 return devices
143
144 def get_bluetooth_devices(self):
145 devices = []
146
147 if self.bluetooth_available:
148 devices.append(self.bluetooth_device)
149
150 return devices
151
152 def get_remembered_wireless_connections(self):
153 return self.connman.get_services_by_technology("wifi")
1540
=== removed file 'src/settings/indicatorNetworkSettings/backend/service.py'
--- src/settings/indicatorNetworkSettings/backend/service.py 2010-12-13 18:48:43 +0000
+++ src/settings/indicatorNetworkSettings/backend/service.py 1970-01-01 00:00:00 +0000
@@ -1,195 +0,0 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2010 Canonical
5#
6# Authors:
7# Kalle Valo
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; version 3.
12#
13# This program is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16# details.
17#
18# You should have received a copy of the GNU General Public License along with
19# this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22import dbus
23
24# FIXME: translate these
25IPV4_METHOD_DHCP = "dhcp"
26IPV4_METHOD_MANUAL = "manual"
27
28def create_service(path):
29 bus = dbus.SystemBus()
30 proxy = dbus.Interface(bus.get_object("net.connman", path),
31 "net.connman.Service")
32
33 try:
34 properties = proxy.GetProperties()
35 except dbus.exceptions.DBusException as e:
36 print "GetProperties failed for service %s: %s" % (path, e)
37 return
38
39 service_type = properties["Type"]
40 if service_type == "ethernet":
41 service = EthernetService(proxy, path, properties)
42 elif service_type == "wifi":
43 service = WifiService(proxy, path, properties)
44 elif service_type == "bluetooth":
45 service = BluetoothService(proxy, path, properties)
46 elif service_type == "cellular":
47 service = CellularService(proxy, path, properties)
48 else:
49 s = "unknown service type '%s': %s" % (service_type, path)
50 raise Exception(s)
51
52 return service
53
54class Service():
55
56 def get_name(self):
57 return self.properties["Name"]
58
59 def get_path(self):
60 return self.path
61
62 def get_strength(self):
63 if "Strength" not in self.properties:
64 return 0
65
66 return int(self.properties["Strength"])
67
68 def get_autoconnect(self):
69 return self.properties["AutoConnect"] == dbus.Boolean(1)
70
71 def set_autoconnect(self, autoconnect):
72 if autoconnect:
73 value = dbus.Boolean(True)
74 else:
75 value = dbus.Boolean(False)
76
77 self.service.SetProperty("AutoConnect", value);
78
79 def get_nameservers_configuration(self):
80 val = self.properties["Nameservers.Configuration"]
81 if val != None:
82 return " ".join(val)
83 else:
84 return ""
85
86 def set_nameservers_configuration(self, nameservers):
87 value = nameservers.split()
88 self.service.SetProperty("Nameservers.Configuration",
89 dbus.Array(value, signature="s"))
90
91 def get_domains_configuration(self):
92 val = self.properties["Domains.Configuration"]
93 if val != None:
94 return " ".join(val)
95 else:
96 return ""
97
98 def set_domains_configuration(self, domains):
99 value = domains.split()
100 self.service.SetProperty("Domains.Configuration",
101 dbus.Array(value, signature="s"))
102
103 def get_ipv4_configuration_method(self):
104 d = self.properties["IPv4.Configuration"]
105 if d.has_key('Method'):
106 return d['Method']
107 else:
108 return ""
109
110 def get_ipv4_configuration_address(self):
111 d = self.properties["IPv4.Configuration"]
112 if d.has_key('Address'):
113 return d['Address']
114 else:
115 return ""
116
117 def get_ipv4_configuration_netmask(self):
118 d = self.properties["IPv4.Configuration"]
119 if d.has_key('Netmask'):
120 return d['Netmask']
121 else:
122 return ""
123
124 def get_ipv4_configuration_gateway(self):
125 d = self.properties["IPv4.Configuration"]
126 if d.has_key('Gateway'):
127 return d['Gateway']
128 else:
129 return ""
130
131 def set_ipv4_configuration(self, ipv4):
132 self.service.SetProperty("IPv4.Configuration", ipv4)
133
134 def remove(self):
135 if not self.is_favorite():
136 return
137
138 self.service.Remove()
139
140 def is_favorite(self):
141 if not "Favorite" in self.properties:
142 return False
143
144 return self.properties["Favorite"] == dbus.Boolean(1)
145
146 def connect(self):
147 self.service.Connect()
148
149 def update_property(self, name, value):
150 self.properties[name] = value
151 # FIXME: emit property-changed signal
152
153 def __init__(self, service, path, properties):
154 self.service = service
155 self.path = path
156 self.properties = properties
157
158class EthernetService(Service):
159
160 def get_type(self):
161 return "ethernet"
162
163class WifiService(Service):
164
165 def get_type(self):
166 return "wifi"
167
168 def uses_passphrase(self):
169 return self.properties["Security"] != "none"
170
171 def get_passphrase(self):
172 if "Passphrase" not in self.properties:
173 return ""
174
175 return self.properties["Passphrase"]
176
177 def set_passphrase(self, passphrase):
178 self.service.SetProperty("Passphrase", passphrase);
179
180class BluetoothService(Service):
181
182 def get_type(self):
183 return "bluetooth"
184
185class CellularService(Service):
186
187 def get_type(self):
188 return "cellular"
189
190 def get_apn(self):
191 return self.properties["APN"]
192
193 def set_apn(self, apn):
194 self.service.SetProperty("APN", apn);
195
1960
=== removed file 'src/settings/indicatorNetworkSettings/enums.py'
--- src/settings/indicatorNetworkSettings/enums.py 2010-12-13 19:38:26 +0000
+++ src/settings/indicatorNetworkSettings/enums.py 1970-01-01 00:00:00 +0000
@@ -1,42 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19from gettext import gettext as _
20
21DEVICE_TYPES = (DEVICE_TYPE_WIRED, DEVICE_TYPE_WIRELESS, \
22 DEVICE_TYPE_BLUETOOTH, DEVICE_TYPE_MOBILE) = range(4)
23
24DEVICE_TYPE_NAMES = {DEVICE_TYPE_WIRED:_("Wired"),
25 DEVICE_TYPE_WIRELESS:_("Wireless"),
26 DEVICE_TYPE_BLUETOOTH:_("Bluetooth"),
27 DEVICE_TYPE_MOBILE:_("Mobile Broadband")}
28
29DEVICE_TYPE_LNAMES = {DEVICE_TYPE_WIRED:"wired",
30 DEVICE_TYPE_WIRELESS:"wireless",
31 DEVICE_TYPE_BLUETOOTH:"bluetooth",
32 DEVICE_TYPE_MOBILE:"mobile"}
33
34DEVICE_TYPE_ICONS = {DEVICE_TYPE_WIRED:"network-wired",
35 DEVICE_TYPE_WIRELESS:"network-wireless",
36 DEVICE_TYPE_BLUETOOTH:"bluetooth-active",
37 DEVICE_TYPE_MOBILE:"gsm-3g-high"}
38
39DEVICE_STATE_OFF, DEVICE_STATE_ON, DEVICE_STATE_CONNECTED, = range(3)
40
41
42GENERIC_DEVICE_ICON = DEVICE_TYPE_ICONS[DEVICE_TYPE_WIRED]
430
=== removed directory 'src/settings/indicatorNetworkSettings/frontend'
=== removed file 'src/settings/indicatorNetworkSettings/frontend/Makefile.am'
--- src/settings/indicatorNetworkSettings/frontend/Makefile.am 2010-12-13 13:55:55 +0000
+++ src/settings/indicatorNetworkSettings/frontend/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
1SUBDIRS = \
2 pages \
3 widgets
4
5# indicator-network-settings
6insdir = $(pkgdatadir)/indicatorNetworkSettings/frontend
7ins_PYTHON = \
8 __init__.py \
9 utils.py
100
=== removed file 'src/settings/indicatorNetworkSettings/frontend/__init__.py'
--- src/settings/indicatorNetworkSettings/frontend/__init__.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1
20
=== removed directory 'src/settings/indicatorNetworkSettings/frontend/pages'
=== removed file 'src/settings/indicatorNetworkSettings/frontend/pages/Makefile.am'
--- src/settings/indicatorNetworkSettings/frontend/pages/Makefile.am 2010-12-13 13:55:55 +0000
+++ src/settings/indicatorNetworkSettings/frontend/pages/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,5 +0,0 @@
1# indicator-network-settings
2insdir = $(pkgdatadir)/indicatorNetworkSettings/frontend/pages
3ins_PYTHON = \
4 connections.py \
5 __init__.py
60
=== removed file 'src/settings/indicatorNetworkSettings/frontend/pages/__init__.py'
=== removed file 'src/settings/indicatorNetworkSettings/frontend/pages/connections.py'
--- src/settings/indicatorNetworkSettings/frontend/pages/connections.py 2010-12-13 14:18:58 +0000
+++ src/settings/indicatorNetworkSettings/frontend/pages/connections.py 1970-01-01 00:00:00 +0000
@@ -1,111 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import gobject
20
21from indicatorNetworkSettings.frontend.widgets.device_boxes.wired \
22 import WiredBox
23from indicatorNetworkSettings.frontend.widgets.device_boxes.wireless \
24 import WirelessBox
25from indicatorNetworkSettings.frontend.widgets.device_boxes.bluetooth \
26 import BluetoothBox
27from indicatorNetworkSettings.frontend.widgets.device_boxes.mobile \
28 import MobileBox
29from indicatorNetworkSettings.frontend.widgets.deviceview \
30 import DeviceView, DeviceStore
31
32from indicatorNetworkSettings.backend.device import *
33from indicatorNetworkSettings.enums import *
34
35class ConnectionsPage(gobject.GObject):
36 def __init__(self, app, datadir):
37 super(ConnectionsPage, self).__init__()
38
39 self.app = app
40 self.alignment = app.alignment_connections
41 self.viewed = False
42
43 # Create LHS
44 ## Create device view
45 device_store = DeviceStore(app.icons)
46 self.treeview_devices = DeviceView(device_store)
47 ## Pack it
48 app.scrolledwindow_c_devices.add(self.treeview_devices)
49 ## Connect signals to callbacks
50 self.treeview_devices.connect("selection-changed",
51 self._on_treeview_devices_selection_changed)
52 self.treeview_devices.connect("reordered",
53 self._on_treeview_devices_reordered)
54
55 wired_devices = app.devicemanager.get_wired_devices()
56 wireless_devices = app.devicemanager.get_wireless_devices()
57 mobile_devices = app.devicemanager.get_mobile_devices()
58 bluetooth_devices = app.devicemanager.get_bluetooth_devices()
59
60 for device in wired_devices:
61 box = WiredBox(device, datadir)
62 self.app.notebook_c_right.append_page(box)
63 self.add_device(device, box)
64
65 for device in wireless_devices:
66 box = WirelessBox(device, app, datadir)
67 self.app.notebook_c_right.append_page(box)
68 self.add_device(device, box)
69
70 for device in mobile_devices:
71 box = MobileBox(device, datadir)
72 self.app.notebook_c_right.append_page(box)
73 self.add_device(device, box)
74
75 for device in bluetooth_devices:
76 box = BluetoothBox(device, datadir)
77 self.app.notebook_c_right.append_page(box)
78 self.add_device(device, box)
79
80 # Order the RHS notebook pages inaccordance with the deviceview
81 self._on_treeview_devices_reordered(self.treeview_devices)
82
83 # Private Functions
84
85 # Public Functions
86
87 def add_device(self, device, box):
88 liststore = self.treeview_devices.get_model()
89 liststore.append(device, box)
90
91 # Callbacks
92
93 def on_first_expose(self):
94 if not self.viewed:
95 self.treeview_devices.get_selection().select_path((0,))
96 self.viewed = True
97
98 def _on_treeview_devices_selection_changed(self, widget, selection):
99 (model, iter_) = selection.get_selected()
100
101 if iter_:
102 i = model.get_path(iter_)[0]
103 self.app.notebook_c_right.set_current_page(i)
104
105 def _on_treeview_devices_reordered(self, widget):
106 i = 0
107 model = widget.get_model()
108 for device in model:
109 page = device[DeviceStore.COL_SETTINGS_BOX]
110 self.app.notebook_c_right.reorder_child(page, i)
111 i += 1
1120
=== removed file 'src/settings/indicatorNetworkSettings/frontend/utils.py'
--- src/settings/indicatorNetworkSettings/frontend/utils.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/utils.py 1970-01-01 00:00:00 +0000
@@ -1,34 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import os
20import sys
21import gtk
22
23def setup_ui(self, datadir, name):
24 builder = gtk.Builder()
25 builder.set_translation_domain("indicator-network-settings")
26 path = os.path.join(datadir, "ui", "%s.ui" % name)
27 builder.add_from_file(path)
28 builder.connect_signals(self)
29 for object_ in builder.get_objects():
30 if issubclass(type(object_), gtk.Buildable):
31 name = gtk.Buildable.get_name(object_)
32 setattr(self, name, object_)
33 else:
34 print >> sys.stderr, "WARNING: can not get name for '%s'" % object_
350
=== removed directory 'src/settings/indicatorNetworkSettings/frontend/widgets'
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/Makefile.am'
--- src/settings/indicatorNetworkSettings/frontend/widgets/Makefile.am 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
1SUBDIRS = device_boxes
2
3# indicator-network-settings
4insdir = $(pkgdatadir)/indicatorNetworkSettings/frontend/widgets
5ins_PYTHON = cellrenderers.py deviceview.py toggleswitch.py connectionview.py __init__.py
6
70
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/__init__.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/__init__.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1
20
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/cellrenderers.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/cellrenderers.py 2010-12-09 12:26:46 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/cellrenderers.py 1970-01-01 00:00:00 +0000
@@ -1,210 +0,0 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2010 Canonical
5#
6# Authors:
7# Andrew Higginson
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; version 3.
12#
13# This program is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16# details.
17#
18# You should have received a copy of the GNU General Public License along with
19# this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22import gtk
23import gobject
24
25from math import pi
26
27PI = 3.1415926535897931
28PI_OVER_180 = 0.017453292519943295
29
30class PinCellRenderer(gtk.GenericCellRenderer):
31 __gproperties__ = {
32 'color': (gobject.TYPE_STRING,
33 'The color of the pin.',
34 'The color of the pin.',
35 '#FFFFFF',
36 gobject.PARAM_READWRITE
37 ),
38 }
39
40 RED_FILL = "#ef2929"
41 RED_STROKE = "#a40000"
42 GREEN_FILL = "#8ae234"
43 GREEN_STROKE = "#4e9a06"
44 YELLOW_FILL = "#fce94f"
45 YELLOW_STROKE = "#c4a000"
46 GREY_FILL = "#d3d7cf"
47 GREY_STROKE = "#555753"
48
49 PIN_WIDTH = 8
50 PIN_HEIGHT = 8
51
52 PIN_XPAD = 8
53 PIN_YPAD = 8
54
55 CELL_WIDTH = PIN_WIDTH + PIN_XPAD
56 CELL_HEIGHT = PIN_HEIGHT + PIN_YPAD
57
58 def __init__(self):
59 super(PinCellRenderer, self).__init__()
60
61 def on_get_size(self, widget, cell_area):
62 return 0, 0, self.CELL_WIDTH, self.CELL_HEIGHT
63
64 def do_set_property(self, pspec, value):
65 setattr(self, pspec.name, value)
66
67 def do_get_property(self, pspec):
68 return getattr(self, pspec.name)
69
70 def on_render(self, window, widget, background_area, cell_area,
71 expose_area, flags):
72 cr = window.cairo_create()
73
74 x = cell_area.x
75 y = cell_area.y
76
77 y_offset = (cell_area.height - self.CELL_HEIGHT) / 2
78
79 cr.arc(self.CELL_WIDTH/2+x, self.CELL_HEIGHT/2+y+y_offset,
80 self.PIN_WIDTH/2, 0, 2 * pi)
81
82 stroke_string = getattr(self, "%s_STROKE" % self.color.upper())
83 stroke = gtk.gdk.Color(stroke_string)
84 fill_string = getattr(self, "%s_FILL" % self.color.upper())
85 fill = gtk.gdk.Color(fill_string)
86
87 cr.set_source_rgb(stroke.red / 65535.,
88 stroke.green / 65535.,
89 stroke.blue / 65535.)
90 cr.stroke_preserve()
91 cr.set_source_rgb(fill.red / 65535.,
92 fill.green / 65535.,
93 fill.blue / 65535.)
94 cr.fill()
95
96class SignalStrengthCellRenderer(gtk.GenericCellRenderer):
97 __gproperties__ = {
98 'signal': (gobject.TYPE_STRING,
99 'The color of the pin.',
100 'The color of the pin.',
101 '#FFFFFF',
102 gobject.PARAM_READWRITE
103 ),
104 }
105
106 BG_FILL = "#f2f1f0"
107 BG_STROKE = "#ada9a4"
108 FG_FILL = "#d6d4d2"
109 FG_STROKE = "#ada9a4"
110
111 BAR_WIDTH = 50
112 BAR_HEIGHT = 12
113
114 BAR_XPAD = 4
115 BAR_YPAD = 5
116
117 CELL_WIDTH = BAR_WIDTH + BAR_XPAD * 2
118 CELL_HEIGHT = BAR_HEIGHT + BAR_YPAD * 2
119
120 CORNER_RADIUS = 3
121
122 def __init__(self):
123 super(SignalStrengthCellRenderer, self).__init__()
124
125 def on_get_size(self, widget, cell_area):
126 return (0, 0, self.CELL_WIDTH, self.CELL_HEIGHT)
127
128 def do_set_property(self, pspec, value):
129 setattr(self, pspec.name, value)
130
131 def do_get_property(self, pspec):
132 return getattr(self, pspec.name)
133
134 def on_render(self, window, widget, background_area, cell_area,
135 expose_area, flags):
136 cr = window.cairo_create()
137
138 x = cell_area.x
139 y = cell_area.y
140
141 x_offset = self.BAR_XPAD
142 y_offset = self.BAR_YPAD
143
144 self._draw_rounded_rectangle(cr, x+x_offset, y+y_offset,
145 x+x_offset+self.BAR_WIDTH, y+y_offset+self.BAR_HEIGHT,
146 self.BG_FILL, self.BG_STROKE)
147
148 self._draw_rounded_rectangle(cr, x+x_offset, y+y_offset,
149 x+x_offset+(int(self.BAR_WIDTH*float(self.signal))), y+y_offset+self.BAR_HEIGHT,
150 self.FG_FILL, self.FG_STROKE)
151
152 def _draw_rounded_rectangle(self, cr, x, y, w, h, fill, stroke):
153 self._layout_rounded_rectangle(cr, x, y, w, h)
154
155 stroke = gtk.gdk.Color(stroke)
156 fill = gtk.gdk.Color(fill)
157
158 cr.set_source_rgb(stroke.red / 65535.,
159 stroke.green / 65535.,
160 stroke.blue / 65535.)
161 cr.stroke_preserve()
162
163 cr.set_source_rgb(fill.red / 65535.,
164 fill.green / 65535.,
165 fill.blue / 65535.)
166 cr.fill()
167
168 def _layout_rounded_rectangle(self, cr, x, y, w, h):
169 r = self.CORNER_RADIUS
170 cr.new_sub_path()
171 cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180)
172 cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0)
173 cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180)
174 cr.arc(r+x, h-r, r, 90*PI_OVER_180, PI)
175 cr.close_path()
176
177
178
179gobject.type_register(PinCellRenderer)
180gobject.type_register(SignalStrengthCellRenderer)
181
182if __name__ == "__main__":
183 window = gtk.Window()
184
185 treeview = gtk.TreeView()
186
187 # Main Column
188 column = gtk.TreeViewColumn("Main")
189 cr = PinCellRenderer()
190 crs = SignalStrengthCellRenderer()
191 crt = gtk.CellRendererText()
192 column.pack_start(cr)
193 column.pack_start(crs)
194 column.pack_start(crt)
195 column.set_attributes(cr, color=0)
196 column.set_attributes(crs, signal=1)
197 column.set_attributes(crt, text=2)
198 treeview.append_column(column)
199
200 store = gtk.ListStore(str, float, str)
201 store.append(["green", 0.25, "Hey"])
202 store.append(["red", 0.5, "hi"])
203 store.append(["yellow", 0.75, "ho"])
204 store.append(["grey", 1.0, "ha"])
205 treeview.set_model(store)
206
207 window.add(treeview)
208 window.show_all()
209 gtk.main()
210
2110
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/connectionview.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/connectionview.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/connectionview.py 1970-01-01 00:00:00 +0000
@@ -1,78 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import gtk
20import gobject
21
22from indicatorNetworkSettings.enums import *
23from indicatorNetworkSettings.frontend.widgets.cellrenderers \
24 import SignalStrengthCellRenderer
25
26from gettext import gettext as _
27
28class WirelessConnectionView(gtk.TreeView):
29 def __init__(self, store):
30 super(WirelessConnectionView, self).__init__()
31 self.set_model(store)
32
33 # Network Column (contains label)
34 column = gtk.TreeViewColumn(_("Network"))
35 cr_label = gtk.CellRendererText()
36 column.pack_start(cr_label, True)
37 column.set_attributes(cr_label,
38 markup=WirelessConnectionStore.COL_NETWORK)
39 column.set_expand(True)
40 self.append_column(column)
41
42 # Signal Column (contains signal indicator)
43 column = gtk.TreeViewColumn(_("Signal"))
44 cr_signal = SignalStrengthCellRenderer()
45 column.pack_start(cr_signal, True)
46 column.set_attributes(cr_signal,
47 signal=WirelessConnectionStore.COL_SIGNAL)
48 column.set_clickable(True)
49 column.set_sort_column_id(WirelessConnectionStore.COL_SIGNAL)
50 self.append_column(column)
51
52 # Last Used Column (contains label)
53 column = gtk.TreeViewColumn(_("Last Used"))
54 cr_label = gtk.CellRendererText()
55 column.pack_start(cr_label, True)
56 column.set_attributes(cr_label,
57 markup=WirelessConnectionStore.COL_LAST_USED)
58 self.append_column(column)
59
60 def get_selected_connection(self):
61 (model, iter_) = self.get_selection().get_selected()
62 if iter_:
63 return model.get_value(iter_, 0)
64 return None
65
66
67class WirelessConnectionStore(gtk.ListStore):
68
69 (COL_OBJ, COL_NETWORK, COL_SIGNAL, COL_LAST_USED) = range(4)
70
71 def __init__(self):
72 super(WirelessConnectionStore, self).__init__(
73 gobject.TYPE_PYOBJECT, str, str, str)
74
75 def append(self, obj, network, signal, last_used):
76 row_data = [obj, network, signal, last_used]
77 return super(WirelessConnectionStore, self).append(row_data)
78
790
=== removed directory 'src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes'
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/Makefile.am'
--- src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/Makefile.am 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
1# indicator-network-settings
2insdir = $(pkgdatadir)/indicatorNetworkSettings/frontend/widgets/device_boxes
3ins_PYTHON = bluetooth.py __init__.py mobile.py wired.py wireless.py
40
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/__init__.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/__init__.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,30 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import gtk
20
21class DeviceBox(gtk.VBox):
22 """A gtk.VBox which holds all of the widgets to control a device."""
23
24 def __init__(self, device, datadir):
25 super(DeviceBox, self).__init__(spacing=12)
26 self.device = device
27 self.device.connect("state-changed", self._on_device_state_changed)
28
29 def _on_device_state_changed(self, device, state):
30 pass
310
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/bluetooth.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/bluetooth.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/bluetooth.py 1970-01-01 00:00:00 +0000
@@ -1,35 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import gtk
20import locale
21
22from indicatorNetworkSettings.enums import *
23
24from gettext import gettext as _
25
26class BluetoothBox(gtk.VBox):
27
28 """A gtk.VBox which holds all of thw widgets to control a bluetooth
29 device."""
30
31 def __init__(self, device, datadir):
32 super(BluetoothBox, self).__init__(spacing=12)
33 self.device = device
34
35 # Callbacks
360
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/mobile.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/mobile.py 2010-12-13 19:53:47 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/mobile.py 1970-01-01 00:00:00 +0000
@@ -1,116 +0,0 @@
1# -*- coding: utf-8 -*-
2# Copyright (C) 2010 Canonical
3#
4# Authors:
5# Andrew Higginson
6#
7# This program is free software; you can redistribute it and/or modify it under
8# the terms of the GNU General Public License as published by the Free Software
9# Foundation; version 3.
10#
11# This program is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14# details.
15#
16# You should have received a copy of the GNU General Public License along with
17# this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20import gtk
21
22from indicatorNetworkSettings.frontend.widgets.device_boxes \
23 import DeviceBox
24from indicatorNetworkSettings.frontend.widgets.toggleswitch \
25 import InfoBox, ToggleSwitch
26
27from indicatorNetworkSettings.enums import *
28import indicatorNetworkSettings.frontend.utils as utils
29
30from gettext import gettext as _
31
32class MobileBox(DeviceBox):
33
34 """A gtk.VBox which holds all of the widgets to control a mobile
35 device. It contains an InfoBox and ToggleSwitch to control and
36 monitor the state of the mobile device, and a set of widgets
37 to enter details about the mobile network to connect to."""
38
39 SENSITIVE_WIDGETS = ["label_apn_place", "label_apn",
40 "label_pin_auth", "checkbutton_show_pin"]
41
42 def __init__(self, device, datadir):
43 super(MobileBox, self).__init__(device, datadir)
44
45 # Infobox and Togglswitch
46 ## Creation
47 self.infobox = InfoBox(spacing=12)
48 self.toggleswitch = ToggleSwitch((_("ON"), _("OFF")))
49 self.label_status = gtk.Label()
50 ## Padding and alignment
51 self.label_status.set_alignment(0, 0.5)
52 self.infobox.set_border_width(10)
53 ## Packing
54 self.infobox.pack_start(self.label_status, True, True)
55 self.infobox.pack_start(self.toggleswitch, False, True)
56 self.pack_start(self.infobox, False, False)
57 ## Connect signals
58 self.toggleswitch.connect("toggled", self._on_toggleswitch_toggled)
59
60 # Network Settings
61 ## Creation
62 utils.setup_ui(self, datadir, "mobile_box")
63 ## Packing
64 self.pack_start(self.table_settings, True, True)
65
66 self._update_widget_states(self.device.get_state())
67 self._on_checkbutton_show_pin_toggled(self.checkbutton_show_pin)
68
69 # Private Functions
70 def _update_widget_states(self, state):
71 if state == DEVICE_STATE_CONNECTED:
72 device_editable = True
73 settings_editable = False
74 toggleswitch_state = True
75 status_text = _("Connected to “Vodafone UK”.")
76 elif state == DEVICE_STATE_ON:
77 device_editable = True
78 settings_editable = False
79 toggleswitch_state = True
80 status_text = _("Not connected.")
81 elif state == DEVICE_STATE_OFF:
82 device_editable = False
83 settings_editable = True
84 toggleswitch_state = False
85 status_text = _("The Mobile Broadband device is powered off.")
86
87 self.toggleswitch.set_sensitive(device_editable)
88 self.toggleswitch.set_active(toggleswitch_state)
89 self.label_status.set_text(status_text)
90
91 self.table_settings.foreach(self._sensitise_widgets,
92 (device_editable, settings_editable))
93
94 def _sensitise_widgets(self, widget, data):
95 (device_editable, settings_editable) = data
96 name = gtk.Buildable.get_name(widget)
97 if name in self.SENSITIVE_WIDGETS:
98 widget.set_sensitive(device_editable)
99 elif not isinstance(widget, gtk.Box):
100 widget.set_sensitive(settings_editable)
101 else:
102 widget.foreach(self._sensitise_widgets,
103 (device_editable, settings_editable))
104
105 # Callbacks
106 def _on_device_state_changed(self, device, state):
107 self._update_widget_states(state)
108
109 def _on_toggleswitch_toggled(self, widget):
110 if widget.get_active():
111 self.device.enable()
112 else:
113 self.device.disable()
114
115 def _on_checkbutton_show_pin_toggled(self, widget):
116 self.entry_pin.set_visibility(widget.get_active())
1170
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wired.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wired.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wired.py 1970-01-01 00:00:00 +0000
@@ -1,35 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import gtk
20import locale
21
22from indicatorNetworkSettings.enums import *
23
24from gettext import gettext as _
25
26class WiredBox(gtk.VBox):
27
28 """A gtk.VBox which holds all of the widgets to control a wired
29 device."""
30
31 def __init__(self, device, datadir):
32 super(WiredBox, self).__init__(spacing=12)
33 self.device = device
34
35 # Callbacks
360
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wireless.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wireless.py 2010-12-13 20:01:43 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/device_boxes/wireless.py 1970-01-01 00:00:00 +0000
@@ -1,130 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import gtk
20import locale
21
22from indicatorNetworkSettings.frontend.widgets.device_boxes \
23 import DeviceBox
24from indicatorNetworkSettings.frontend.widgets.connectionview \
25 import WirelessConnectionView, WirelessConnectionStore
26from indicatorNetworkSettings.frontend.widgets.toggleswitch \
27 import InfoBox, ToggleSwitch
28
29from indicatorNetworkSettings.enums import *
30import indicatorNetworkSettings.frontend.utils as utils
31
32from gettext import gettext as _
33
34class WirelessBox(DeviceBox):
35
36 """A gtk.VBox which holds all of the widgets to control a wireless
37 device. It contains an InfoBox and ToggleSwitch to control and
38 monitor the state of the wireless device, and a
39 WirelessConnectionView to connect to and remember details for
40 wireless networks."""
41
42 def __init__(self, device, app, datadir):
43 super(WirelessBox, self).__init__(device, datadir)
44
45 # Infobox and Togglswitch
46 ## Creation
47 self.infobox = InfoBox(spacing=12)
48 self.toggleswitch = ToggleSwitch((_("ON"), _("OFF")))
49 self.label_status = gtk.Label()
50 ## Padding and alignment
51 self.label_status.set_alignment(0, 0.5)
52 self.infobox.set_border_width(10)
53 ## Packing
54 self.infobox.pack_start(self.label_status, True, True)
55 self.infobox.pack_start(self.toggleswitch, False, True)
56 self.pack_start(self.infobox, False, False)
57 ## Connect signals
58 self.toggleswitch.connect("toggled", self._on_toggleswitch_toggled)
59
60 # Network Settings
61 ## Creation
62 utils.setup_ui(self, datadir, "wireless_box")
63 ## Packing
64 self.pack_start(self.vbox_connections, True, True)
65
66 # Connection View
67 ## Creation
68 connection_store = WirelessConnectionStore()
69 self.treeview_connections = WirelessConnectionView(connection_store)
70 ## Packing
71 self.scrolledwindow_connections.add(self.treeview_connections)
72 ## Population
73 connections = app.devicemanager.get_remembered_wireless_connections()
74 for connection in connections:
75 self._add_connection(connection)
76
77 self._update_widget_states(self.device.get_state())
78
79 # Private Functions
80 def _update_widget_states(self, state):
81 if state == DEVICE_STATE_ON:
82 device_editable = True
83 settings_editable = True
84 toggleswitch_state = True
85 status_text = _("Wi-fi is on but not connected to the Internet.")
86 elif state == DEVICE_STATE_CONNECTED:
87 device_editable = True
88 settings_editable = True
89 toggleswitch_state = True
90 status_text = _("Wi-fi is on and connected to the Internet.")
91 elif state == DEVICE_STATE_OFF:
92 device_editable = False
93 settings_editable = False
94 toggleswitch_state = False
95 status_text = _("The Wi-fi device is powered off.")
96
97 self.vbox_connections.set_sensitive(settings_editable)
98 self.toggleswitch.set_sensitive(device_editable)
99 self.toggleswitch.set_active(toggleswitch_state)
100 self.label_status.set_text(status_text)
101
102 def _add_connection(self, connection):
103 network = connection.get_name()
104 signal = float(connection.get_strength()) / 100
105
106 # FIXME: implement
107 # if connection.last_used:
108 # date_format = locale.nl_langinfo(locale.D_FMT)
109 # last_used = connection.last_used.strftime(date_format)
110 # else:
111 # last_used = _("Never")
112
113 last_used = _("N/A")
114
115 liststore = self.treeview_connections.get_model()
116 liststore.append(connection, network, signal, last_used)
117
118 # Callbacks
119 def _on_device_state_changed(self, device, state):
120 self._update_widget_states(state)
121
122 def _on_toggleswitch_toggled(self, widget):
123 if widget.get_active():
124 self.device.disable()
125 else:
126 self.device.enable()
127
128 def _on_button_connect_clicked(self, widget):
129 connection = self.treeview_connections.get_selected_connection()
130 connection.connect()
1310
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/deviceview.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/deviceview.py 2010-12-13 19:38:26 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/deviceview.py 1970-01-01 00:00:00 +0000
@@ -1,153 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import gtk
20import glib
21import gobject
22import pango
23
24from indicatorNetworkSettings.enums import *
25from indicatorNetworkSettings.frontend.widgets.cellrenderers \
26 import PinCellRenderer
27
28from gettext import gettext as _
29
30class DeviceView(gtk.TreeView):
31
32 __gsignals__ = {
33 "selection-changed" : (gobject.SIGNAL_RUN_LAST,
34 gobject.TYPE_NONE,
35 ([gobject.TYPE_PYOBJECT]),
36 ),
37 "reordered" : (gobject.SIGNAL_RUN_LAST,
38 gobject.TYPE_NONE,
39 (),
40 ),
41 }
42
43 def __init__(self, store):
44 super(DeviceView, self).__init__()
45 self.set_model(store)
46
47 # Device (main) Column (contains pin icon, type icon and label)
48 column = gtk.TreeViewColumn("Device")
49 cr_pin = PinCellRenderer()
50 cr_icon = gtk.CellRendererPixbuf()
51 cr_label = gtk.CellRendererText()
52 column.pack_start(cr_pin, False)
53 column.set_attributes(cr_pin, color=DeviceStore.COL_PIN)
54 column.pack_start(cr_icon, False)
55 column.set_attributes(cr_icon, pixbuf=DeviceStore.COL_ICON)
56 column.pack_start(cr_label, True)
57 column.set_attributes(cr_label, markup=DeviceStore.COL_LABEL)
58 cr_label.set_property("ellipsize", pango.ELLIPSIZE_END)
59 self.append_column(column)
60
61 self.set_headers_visible(False)
62 self.set_reorderable(True)
63
64 self._dragging = False
65
66 self.get_selection().connect("changed", self._on_selection_changed)
67 self.connect("drag-begin", self._on_drag_begin)
68 self.connect("drag-end", self._on_drag_end)
69 self.connect("drag-failed", self._on_drag_failed)
70
71 def _on_selection_changed(self, selection):
72 self.emit("selection-changed", selection)
73
74 def _on_drag_begin(self, drag_context, *data):
75 self._dragging = True
76
77 def _on_drag_failed(self, drag_context, *data):
78 self._dragging = False
79
80 def _on_drag_end(self, drag_context, *data):
81 if self._dragging:
82 self.emit("reordered")
83
84 def get_selected_device(self):
85 (model, iter_) = self.get_selection().get_selected()
86 if iter_:
87 return model.get_value(iter_, 0)
88 return None
89
90class DeviceStore(gtk.ListStore):
91
92 (COL_DEVICE_OBJ, COL_SETTINGS_BOX, COL_PIN, COL_ICON, COL_LABEL) = range(5)
93
94 def __init__(self, icons):
95 super(DeviceStore, self).__init__(gobject.TYPE_PYOBJECT,
96 gobject.TYPE_PYOBJECT, str,
97 gtk.gdk.Pixbuf, str)
98 self.icons = icons
99
100 def append(self, device, settings_box):
101 device.connect("state-changed", self._on_device_state_changed)
102
103 pin_color = self._get_pin_color(device.state)
104 caption = self._get_device_caption(device.state)
105 label = DEVICE_TYPE_NAMES[device.type]
106 icon = DEVICE_TYPE_ICONS[device.type]
107
108 markup = self._get_markup(label, caption)
109 try:
110 icon_pixbuf = self.icons.load_icon(icon, 16, 16)
111 except glib.GError:
112 icon_pixbuf = self.icons.load_icon(GENERIC_DEVICE_ICON, 16, 16)
113
114 row_data = [device, settings_box, pin_color, icon_pixbuf, markup]
115
116 return super(DeviceStore, self).append(row_data)
117
118 def _on_device_state_changed(self, device, state):
119 iter_ = self._get_iter_for_device(device)
120 pin_color = self._get_pin_color(state)
121 caption = self._get_device_caption(state)
122 label = DEVICE_TYPE_NAMES[device.type]
123
124 markup = self._get_markup(label, caption)
125
126 self.set_value(iter_, self.COL_PIN, pin_color)
127 self.set_value(iter_, self.COL_LABEL, markup)
128
129 def _get_iter_for_device(self, device):
130 for row in self:
131 if row[0] == device:
132 return row.iter
133
134 def _get_pin_color(self, state):
135 if state == DEVICE_STATE_OFF:
136 return "grey"
137 elif state == DEVICE_STATE_ON:
138 return "yellow"
139 elif state == DEVICE_STATE_CONNECTED:
140 return "green"
141
142 def _get_device_caption(self, state):
143 if state == DEVICE_STATE_OFF:
144 return _("Off")
145 elif state == DEVICE_STATE_ON:
146 return _("Not Connected")
147 elif state == DEVICE_STATE_CONNECTED:
148 return _("Connected")
149
150 def _get_markup(self, label, caption):
151 return "%s\n<span font_size=\"small\">%s</span>" % (label, caption)
152
153
1540
=== removed file 'src/settings/indicatorNetworkSettings/frontend/widgets/toggleswitch.py'
--- src/settings/indicatorNetworkSettings/frontend/widgets/toggleswitch.py 2010-12-09 12:26:46 +0000
+++ src/settings/indicatorNetworkSettings/frontend/widgets/toggleswitch.py 1970-01-01 00:00:00 +0000
@@ -1,529 +0,0 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2010 Canonical
5#
6# Authors:
7# Andrew Higginson
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; version 3.
12#
13# This program is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16# details.
17#
18# You should have received a copy of the GNU General Public License along with
19# this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22import atk
23import gtk
24import gobject
25import cairo
26
27from gettext import gettext as _
28
29PI = 3.1415926535897931
30PI_OVER_180 = 0.017453292519943295
31
32class ToggleSwitch(gtk.EventBox):
33
34 """A switch containing the values ON and OFF (or user-inputed) that
35 hides the inactive value. It can be clicked or dragged to change
36 state, or through an enter/return keypress."""
37
38 __gsignals__ = {
39 "clicked" : (gobject.SIGNAL_RUN_LAST,
40 gobject.TYPE_NONE,
41 (),
42 ),
43 "toggled" : (gobject.SIGNAL_RUN_LAST,
44 gobject.TYPE_NONE,
45 (),
46 ),
47 }
48
49 # (In relation to the height of the covering rectangle)
50 LINE_HEIGHT_RATIO = 9/25.0
51 LINE_SPACING_RATIO = 5/38.0
52 CORNER_RADIUS = 3
53
54 ANIMATION_DURATION = 800
55
56 STATE_ACTIVE, STATE_INACTIVE = (True, False)
57
58 # (In relation to the width/height of the text)
59 TEXT_XPAD = 0.5
60 TEXT_YPAD = 0.55
61
62 # Used for storing Geometry of Widget
63 GEO = {}
64
65 def __init__(self, values=(_("ON"), _("OFF")), active=False):
66 super(ToggleSwitch, self).__init__()
67
68 self.set_visible_window(False)
69
70 # Accessibility info
71 self.atk = self.get_accessible()
72 self.atk.set_role(atk.ROLE_CHECK_BOX)
73
74 # Set events for the widget to receive
75 self.set_flags(gtk.CAN_FOCUS)
76 self.set_events(gtk.gdk.KEY_PRESS_MASK|
77 gtk.gdk.ENTER_NOTIFY_MASK|
78 gtk.gdk.LEAVE_NOTIFY_MASK|
79 gtk.gdk.BUTTON_PRESS_MASK|
80 gtk.gdk.BUTTON_RELEASE_MASK)
81
82 # Connect signls and callbacks
83 self.connect('style-set', self._on_style_set)
84 self.connect('expose-event', self._on_expose_event)
85 self.connect('button-press-event', self._on_press)
86 self.connect('button-release-event', self._on_release)
87 self.connect('key-release-event', self._on_key_release)
88 self.connect('enter-notify-event', self._on_enter)
89 self.connect('leave-notify-event', self._on_leave)
90 self.connect('motion-notify-event', self._on_motion_notify_event)
91
92 # Set values of the widget
93 self.set_values(values)
94 # Set default state of widget
95 self.state_ = active
96 # Allocate variables that will be used later
97 self._layout = None
98 self._animating = False
99 self._pressed = False
100
101 # If the covering rectangle needs to start on the right
102 # set the offset to -1
103 if self.state_ == self.STATE_ACTIVE:
104 self.x_movement_offset = -1
105 else:
106 self.x_movement_offset = 0
107
108 # Calculate the best size
109 calc_width, calc_height = self._calculate_size()
110 self.set_size_request(calc_width, calc_height)
111
112 # Private functions
113
114 def _calculate_size(self):
115 """Calculate the best size for the toggleswitch based on the
116 dimensions of the user's default font."""
117 self._layout = self.create_pango_layout('')
118
119 self._layout.set_text("ON")
120 text_width, text_height = self._layout.get_pixel_extents()[1][2:]
121
122 width = (text_width+(text_width*self.TEXT_XPAD*2))*2
123 height = text_height+(text_height*self.TEXT_YPAD*2)
124
125 return (int(width), int(height))
126
127
128 def _draw_widget(self, widget):
129 """Do the drawing of the actual widget."""
130 cr = widget.window.cairo_create()
131
132 # Store the dimensions of the widget for access throughout
133 self.GEO["x"] = widget.allocation.x
134 self.GEO["y"] = widget.allocation.y
135 self.GEO["x1"] = widget.allocation.x + 1
136 self.GEO["y1"] = widget.allocation.y + 1
137 self.GEO["width"] = widget.allocation.width - 3
138 self.GEO["height"] = widget.allocation.height - 3
139 self.GEO["x2"] = widget.allocation.x + 1 + widget.allocation.width - 5
140 self.GEO["y2"] = widget.allocation.y + 1 + widget.allocation.height - 5
141
142 # Draw clipping rectangle
143 self._layout_rounded_rectangle(cr, self.GEO["x"],
144 self.GEO["y"],
145 self.GEO["x"] + widget.allocation.width,
146 self.GEO["y"] + widget.allocation.height)
147 cr.clip()
148
149 # Draw the main background
150 self._draw_main_background(cr)
151
152 # Draw the text
153 self._draw_on_text()
154 self._draw_off_text()
155
156 # Draw the covering rectangle
157 self._draw_covering_rectangle(cr)
158
159 # Update ATK description, based on state
160 if self.state_ == self.STATE_ACTIVE:
161 self.atk.set_name(self.values[0])
162 else:
163 self.atk.set_name(self.values[1])
164
165 def _draw_main_background(self, cr):
166 x1 = self.GEO["x1"]
167 y1 = self.GEO["y1"]
168 x2 = self.GEO["x2"]
169 y2 = self.GEO["y2"]
170
171 # Don't change colour of background on hover or press
172 if self.state == gtk.STATE_PRELIGHT or self.state == gtk.STATE_ACTIVE:
173 state = gtk.STATE_NORMAL
174 else:
175 state = self.state
176
177 # Layout the outline of the whole widget
178 self._layout_rounded_rectangle(cr, x1, y1, x2, y2)
179 ## Select colours
180 fill = self.style.base[state]
181 stroke = self.style.dark[state]
182 ## Stroke and then fill it in
183 self._stroke_rounded_rectangle(cr, stroke)
184 self._fill_rounded_rectangle(cr, fill)
185
186 # Layout the left (highlighted) part
187 x1 = self.GEO["x1"]
188 x2 = self.GEO["x1"] + (self.GEO["width"]/2)
189 self._layout_rounded_rectangle(cr, x1, y1, x2, y2)
190 ## Select colours
191 fill = self.style.light[gtk.STATE_SELECTED]
192 stroke = self.style.mid[gtk.STATE_SELECTED]
193 ## Stroke and then fill it in
194 self._stroke_rounded_rectangle(cr, stroke)
195 self._fill_rounded_rectangle(cr, fill)
196
197 # Layout the right (normal) part
198 x1 = self.GEO["x2"] - (self.GEO["width"]/2)
199 x2 = self.GEO["x2"]
200 self._layout_rounded_rectangle(cr, x1, y1, x2, y2)
201 ## Select colours
202 fill = self.style.base[state]
203 stroke = self.style.dark[state]
204 ## Stroke and then fill it in
205 self._stroke_rounded_rectangle(cr, stroke)
206 self._fill_rounded_rectangle(cr, fill)
207
208
209 def _draw_covering_rectangle(self, cr, x_offset=0):
210 if self.x_movement_offset == -1:
211 self.x_movement_offset = self.GEO["width"] / 2 - 1
212 x1 = self.GEO["x1"] + self.x_movement_offset
213 x2 = (self.GEO["width"] / 2) + self.GEO["x1"] + self.x_movement_offset
214
215 y1 = self.GEO["y1"]
216 y2 = self.GEO["y2"]
217
218 stroke = self.style.dark[self.state]
219 self._layout_rounded_rectangle(cr, x1, y1, x2, y2)
220 self._stroke_rounded_rectangle(cr, stroke)
221
222 if self.state == gtk.STATE_INSENSITIVE:
223 fill = self.style.bg[self.state]
224 self._fill_rounded_rectangle(cr, fill)
225 else:
226 fill1 = self.style.light[self.state]
227 fill2 = self.style.mid[self.state]
228 linear = self._create_vertical_gradient(fill1, fill2, x1, x2, y1, y2)
229 self._fill_gradient_rounded_rectangle(cr, linear)
230
231 # Draw the vertical lines
232 fill_dark = self.style.dark[self.state]
233 fill_light = self.style.light[self.state]
234 height = round(self.GEO["height"]*self.LINE_HEIGHT_RATIO)
235 width = 1
236
237 spacing = int(self.LINE_SPACING_RATIO * (self.GEO["width"] / 2))
238 c_spacing = 0
239
240 x_offset = ((self.GEO["width"] / 2) - (6+(spacing*2)))/2 + 2
241 y_offset = (self.GEO["height"] - height)/2
242
243 for i in range(3):
244 self._draw_vertical_line(cr, x1+x_offset+c_spacing,
245 y1+y_offset, width, height, fill_dark)
246 self._draw_vertical_line(cr, x1+x_offset+c_spacing+1,
247 y1+y_offset, width, height, fill_light)
248 c_spacing += spacing
249
250
251 def _draw_vertical_line(self, cr, x1, y1, width, height, fill):
252 """Draw a vertical line on the covering rectangle"""
253 cr.rectangle(x1, y1, width, height)
254 cr.set_source_rgb(fill.red_float, fill.green_float, fill.blue_float)
255 cr.fill()
256
257 def _draw_on_text(self):
258 """Draw the ON (or otherwise) text"""
259 text = self.values[0]
260 gravity = "left"
261 self._draw_text_centered_text(text, gravity)
262
263 def _draw_off_text(self):
264 """Draw the OFF (or otherwise) text"""
265 text = self.values[1]
266 gravity = "right"
267 self._draw_text_centered_text(text, gravity)
268
269 def _draw_text_centered_text(self, text, gravity):
270 if not self._layout:
271 self._layout = self.create_pango_layout('')
272
273 self._layout.set_text(text)
274 text_width, text_height = self._layout.get_pixel_extents()[1][2:]
275
276 if self.x_movement_offset == -1:
277 if gravity == "right":
278 text_x_offset = (((self.GEO["width"]/2) - text_width) / 2) + (self.GEO["width"]/2)
279 elif gravity == "left":
280 text_x_offset = (((self.GEO["width"]/2) - text_width) / 2) + self.x_movement_offset
281 else:
282 if gravity == "right":
283 text_x_offset = (((self.GEO["width"]/2) - text_width) / 2) + (self.GEO["width"]/2) + self.x_movement_offset
284 elif gravity == "left":
285 text_x_offset = (((self.GEO["width"]/2) - text_width) / 2) + (self.x_movement_offset-(self.GEO["width"]/2))
286
287 text_y_offset = ((self.GEO["height"] - text_height) / 2)
288
289 self.style.paint_layout(self.window, self.state, True,
290 (self.GEO["x"], self.GEO["y"],
291 self.GEO["width"], self.GEO["height"]),
292 self, '',
293 int(self.GEO["x1"]+text_x_offset),
294 int(self.GEO["y1"]+text_y_offset),
295 self._layout)
296
297
298 def _layout_rounded_rectangle(self, cr, x, y, w, h):
299 r = self.CORNER_RADIUS
300 cr.new_sub_path()
301 cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180)
302 cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0)
303 cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180)
304 cr.arc(r+x, h-r, r, 90*PI_OVER_180, PI)
305 cr.close_path()
306
307 def _fill_rounded_rectangle(self, cr, fill):
308 cr.set_source_rgb(fill.red_float,
309 fill.green_float,
310 fill.blue_float)
311 cr.fill()
312
313 def _fill_gradient_rounded_rectangle(self, cr, fill):
314 cr.set_source(fill)
315 cr.fill()
316
317 def _stroke_rounded_rectangle(self, cr, stroke):
318 cr.set_source_rgb(stroke.red_float,
319 stroke.green_float,
320 stroke.blue_float)
321 cr.stroke_preserve()
322
323 def _create_vertical_gradient(self, color1, color2, x1, x2, y1, y2):
324 linear = cairo.LinearGradient(x1, y1, x1, y2)
325 linear.add_color_stop_rgba(0.00, color1.red_float,
326 color1.green_float,
327 color1.blue_float, 1)
328 linear.add_color_stop_rgba(0.8, color2.red_float,
329 color2.green_float,
330 color2.blue_float, 1)
331 return linear
332
333 def _increment_movement(self, state):
334 if state == self.STATE_ACTIVE:
335 increment = 1
336 criterion = self.x_movement_offset == (self.GEO["x2"] - (self.GEO["width"]/2) - self.GEO["x1"])
337 else:
338 increment = -1
339 criterion = self.x_movement_offset == 0
340
341 if criterion:
342 self._animating = False
343 self.queue_draw()
344 return False
345 else:
346 self.x_movement_offset += increment
347 self.queue_draw()
348 return True
349
350 # Callbacks
351 def _on_style_set(self, widget, event):
352 # Re-calculate the best size
353 calc_width, calc_height = self._calculate_size()
354 self.set_size_request(calc_width, calc_height)
355
356 def _on_expose_event(self, widget, event):
357 self._draw_widget(widget)
358
359 def _on_press(self, widget, event):
360 self.set_state(gtk.STATE_ACTIVE)
361 if event.x < self.GEO["width"]/2:
362 self.offset = event.x
363 elif event.x > self.GEO["width"]/2:
364 self.offset = event.x - self.GEO["width"]/2
365
366 def _on_release(self, widget, event):
367 if not self._animating:
368 if self._pressed:
369 if self.x_movement_offset <= self.GEO["width"] / 4:
370 gobject.timeout_add(5, self._increment_movement,
371 self.STATE_INACTIVE)
372 self.state_ = self.STATE_INACTIVE
373 self.emit('toggled')
374 elif self.x_movement_offset >= self.GEO["width"] / 4:
375 gobject.timeout_add(5, self._increment_movement,
376 self.STATE_ACTIVE)
377 self.state_ = self.STATE_ACTIVE
378 self.emit('toggled')
379 self._pressed = False
380 self.offset = 0
381 else:
382 self.set_state(gtk.STATE_PRELIGHT)
383 self.state_ = not self.state_
384 self.emit('clicked')
385 self.emit('toggled')
386 gobject.timeout_add(5, self._increment_movement,
387 self.state_)
388 self._pressed = False
389 self._animating = True
390
391 def _on_motion_notify_event(self, widget, event):
392 self._pressed = True
393 if event.x - self.offset < 0:
394 self.x_movement_offset = 0
395 elif event.x - self.offset >= (self.GEO["width"]/2 - 1):
396 self.x_movement_offset = self.GEO["width"]/2 -1
397 else:
398 self.x_movement_offset = event.x - self.offset
399 self.queue_draw()
400
401 def _on_key_release(self, widget, event):
402 if widget.has_focus():
403 if event.keyval == gtk.keysyms.Return or \
404 event.keyval == gtk.keysyms.KP_Enter:
405 self.toggled()
406
407 def _on_enter(self, widget, event):
408 self.set_state(gtk.STATE_PRELIGHT)
409
410 def _on_leave(self, widget, event):
411 self.set_state(gtk.STATE_NORMAL)
412
413 # Public functions
414
415 def get_active(self):
416 return self.state_
417
418 def set_active(self, state):
419 # If the widget is not yet realized, don't bother animating
420 if self.get_window() == None:
421 if state:
422 self.x_movement_offset = -1
423 else:
424 self.x_movement_offset = 0
425 self.queue_draw()
426 self.state_ = state
427 # Otherwise if we are not already animating, change the state
428 elif not self._animating:
429 self._animating = True
430 self._on_release(self, None)
431
432 def set_values(self, values):
433 # If the variable values is a tuple of length 2, and type string
434 # set the widget's values property to it.
435 if (len(values) == 2) and (type(values) == tuple):
436 if (type(values[0]) == str) and (type(values[1]) == str):
437 self.values = values
438 return
439 # Otherwise raise a Type error
440 raise TypeError("ToggleSwitch.set_values() argument 1 must be " + \
441 "String Tuple of length 2, not %s." % type(values))
442
443 def toggled(self):
444 self._on_release(self, None)
445
446 def pressed(self):
447 self._on_press(self, None)
448
449 def clicked(self):
450 self._on_release(self, None)
451
452 def enter(self):
453 self._on_enter(self, None)
454
455 def leave(self):
456 self._on_leave(self, None)
457
458class InfoBox(gtk.HBox):
459 """A gtk.HBox that is filled with the mid-colour and stroked with
460 the dark colour from a user's gtk theme so that it stands out."""
461
462 YPAD = 1
463 XPAD = 1
464
465 def __init__(self, homogeneous=False, spacing=0):
466 super(InfoBox, self).__init__(homogeneous, spacing)
467 self.connect('expose-event', self._on_expose_event)
468
469 def _on_expose_event(self, widget, event):
470 cr = widget.window.cairo_create()
471
472 # Get geometry
473 x = widget.allocation.x + self.XPAD
474 y = widget.allocation.y + self.YPAD
475 width = widget.allocation.width - (self.XPAD * 2)
476 height = widget.allocation.height - (self.YPAD * 2)
477
478 # Fill with the mid color from the current gtk theme
479 fill = self.style.mid[self.state]
480 # Fill with the dark color from the current gtk theme
481 stroke = self.style.dark[self.state]
482
483 # Layout the rectangle
484 cr.rectangle(x, y, width, height)
485 # Stroke the outline
486 cr.set_source_rgb(stroke.red_float, stroke.green_float,
487 stroke.blue_float)
488 cr.stroke_preserve()
489 # Fill it in
490 cr.set_source_rgb(fill.red_float, fill.green_float,
491 fill.blue_float)
492 cr.fill()
493
494if __name__ == "__main__":
495 def on_toggle_switch_clicked(widget):
496 print widget.get_active()
497
498 def do():
499 s.toggled()
500 return True
501
502 w = gtk.Window()
503 v = gtk.VBox()
504 h = gtk.HBox()
505 i = InfoBox(spacing=12)
506 s = ToggleSwitch()
507 si = ToggleSwitch()
508 si.set_sensitive(False)
509 l = gtk.Label("Wi-fi is on and connected to the Internet.")
510
511 gobject.timeout_add(3000, do)
512
513 w.connect("delete-event", gtk.main_quit)
514 s.connect("clicked", on_toggle_switch_clicked)
515
516 v.set_border_width(10)
517 w.set_default_size(200, 200)
518
519 i.pack_start(l, False)
520 i.pack_start(s, False, False)
521 i.pack_start(si, False, False)
522 i.set_border_width(12)
523 h.pack_start(i)
524 v.pack_start(h, False, False)
525 w.add(v)
526
527 w.show_all()
528 gtk.main()
529
5300
=== removed file 'src/settings/indicatorNetworkSettings/utils.py'
--- src/settings/indicatorNetworkSettings/utils.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/utils.py 1970-01-01 00:00:00 +0000
@@ -1,18 +0,0 @@
1# Copyright (C) 2010 Canonical
2#
3# Authors:
4# Andrew Higginson
5#
6# This program is free software; you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free Software
8# Foundation; version 3.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
190
=== removed file 'src/settings/indicatorNetworkSettings/version.py'
--- src/settings/indicatorNetworkSettings/version.py 2010-12-07 15:07:37 +0000
+++ src/settings/indicatorNetworkSettings/version.py 1970-01-01 00:00:00 +0000
@@ -1,5 +0,0 @@
1
2VERSION = '0.01'
3CODENAME = 'UNRELEASED'
4DISTRO = 'Ubuntu'
5RELEASE = '11.04'
60
=== added file 'src/settings/logger.vala'
--- src/settings/logger.vala 1970-01-01 00:00:00 +0000
+++ src/settings/logger.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,44 @@
1/*
2 * indicator-network - user interface for connman
3 * Copyright 2010-2011 Canonical Ltd.
4 *
5 * Authors:
6 * Andrew Higginson
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21public enum LogLevel {
22 NONE,
23 INFO,
24 DEBUG
25}
26
27public class Logger : Object {
28
29 public LogLevel level {get; set;}
30
31 public void debug(string text) {
32 if (this.level >= LogLevel.DEBUG) {
33 var msg = @"DEBUG: $text\n";
34 stdout.printf(msg);
35 }
36 }
37
38 public void info(string text) {
39 if (this.level >= LogLevel.INFO) {
40 var msg = @"INFO: $text\n";
41 stdout.printf(msg);
42 }
43 }
44}
045
=== added file 'src/settings/main.vala'
--- src/settings/main.vala 1970-01-01 00:00:00 +0000
+++ src/settings/main.vala 2011-01-07 16:06:25 +0000
@@ -0,0 +1,68 @@
1/*
2 * indicator-network - user interface for connman
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches