23
23
/* A Gtk.VBox which holds all of the widgets to control a wired
26
private string datadir;
26
27
private Connman.Manager connman;
28
private InfoBox infobox;
29
private ToggleSwitch toggleswitch;
30
private Gtk.Label label_status;
31
private Gtk.Builder builder;
32
private Gtk.VBox vbox_connections;
33
private Gtk.Button button_connect;
34
private Gtk.Button button_forget;
35
private Gtk.Button button_edit;
36
private Gtk.ScrolledWindow scrolledwindow_connections;
37
private Connman.Service service;
28
39
public WiredBox(Connman.Manager connman, string datadir) {
29
40
this.set_spacing(12);
41
this.datadir = datadir;
30
42
this.connman = connman;
44
this.connman.notify["ethernet-state"].connect(this.ethernet_state_changed);
45
// Infobox and Togglswitch
47
this.infobox = new InfoBox(false, 12);
48
this.toggleswitch = new ToggleSwitch();
49
this.label_status = new Gtk.Label(null);
50
/// Padding and alignment
51
this.label_status.set_alignment(0, 0.5f);
52
this.infobox.set_border_width(10);
54
this.infobox.pack_start(this.label_status, true, true);
55
this.infobox.pack_start(this.toggleswitch, false, true);
56
this.pack_start(this.infobox, false, false);
58
this.toggleswitch.toggled.connect(this.on_toggleswitch_toggled);
62
this.builder = Utils.Gui.new_builder(datadir + "ui/wired_box.ui");
64
this.connect_signals();
66
this.pack_start(this.vbox_connections, true, true);
69
var services = connman.get_services();
70
foreach (var service in services) {
71
if (service.get_service_type() == Connman.ServiceType.ETHERNET) {
72
/* we support only one ethernet service for now */
73
this.service = service;
74
service.notify["state"].connect(this.service_state_changed);
79
this.update_widget_states(this.connman.get_ethernet_state());
82
private void get_widgets() {
83
this.vbox_connections = this.builder.get_object("vbox_connections") as Gtk.VBox;
84
this.button_connect = this.builder.get_object("button_connect") as Gtk.Button;
85
this.button_forget = this.builder.get_object("button_forget") as Gtk.Button;
86
this.button_edit = this.builder.get_object("button_edit") as Gtk.Button;
87
this.scrolledwindow_connections = this.builder.get_object("scrolledwindow_connections") as Gtk.ScrolledWindow;
90
private void connect_signals() {
91
this.button_connect.clicked.connect(this.on_button_connect_clicked);
92
this.button_edit.clicked.connect(this.on_button_edit_clicked);
95
private void update_widget_states(Connman.TechnologyState state) {
96
bool device_editable = false;
97
bool settings_editable = false;
98
bool toggleswitch_state = false;
99
string status_text = "", connect = "";
102
case Connman.TechnologyState.ENABLED:
103
device_editable = true;
104
settings_editable = true;
105
toggleswitch_state = true;
106
status_text = ("Wired is on but not connected to the Internet.");
108
case Connman.TechnologyState.CONNECTED:
109
device_editable = true;
110
settings_editable = true;
111
toggleswitch_state = true;
112
status_text = ("Wired is on and connected to the Internet.");
114
case Connman.TechnologyState.AVAILABLE:
115
device_editable = true;
116
settings_editable = false;
117
toggleswitch_state = false;
118
status_text = ("The Wired device is powered off.");
120
case Connman.TechnologyState.OFFLINE:
121
device_editable = true;
122
settings_editable = false;
123
toggleswitch_state = false;
124
status_text = ("Wired is offline.");
128
this.vbox_connections.set_sensitive(settings_editable);
129
this.toggleswitch.set_sensitive(device_editable);
130
this.toggleswitch.set_active(toggleswitch_state);
131
this.label_status.set_text(status_text);
133
switch (this.service.get_state()) {
134
case Connman.ServiceState.ASSOCIATION:
135
case Connman.ServiceState.CONFIGURATION:
136
case Connman.ServiceState.READY:
137
case Connman.ServiceState.ONLINE:
138
connect = "Disconnect";
145
this.button_connect.set_label(connect);
148
private void ethernet_state_changed(ParamSpec p) {
149
this.update_widget_states(this.connman.get_ethernet_state());
152
private void service_state_changed() {
153
this.update_widget_states(this.connman.get_ethernet_state());
156
private void on_toggleswitch_toggled() {
157
if (this.toggleswitch.get_active()) {
158
this.connman.enable_technology(Connman.TechnologyType.ETHERNET, null);
160
this.connman.disable_technology(Connman.TechnologyType.ETHERNET, null);
164
private void on_button_connect_clicked() {
165
switch (this.service.get_state()) {
166
case Connman.ServiceState.ASSOCIATION:
167
case Connman.ServiceState.CONFIGURATION:
168
case Connman.ServiceState.READY:
169
case Connman.ServiceState.ONLINE:
170
this.service.disconnect();
173
this.service.connect();
178
private void on_button_edit_clicked() {
179
var dialog = new EditConnectionDialog(this.service, this.datadir);
180
//FIXME: make this work
181
// //dialog.response.connect(() => { delete dialog; });