~kvalo/indicator-network/bug-739312

« back to all changes in this revision

Viewing changes to src/settings/frontend/widgets/device-boxes/wired.vala

  • Committer: Kalle Valo
  • Date: 2011-03-08 17:46:05 UTC
  • mfrom: (158.1.4 settings-more-tech)
  • Revision ID: kalle.valo@canonical.com-20110308174605-5aedkmoityta4yo2
MergeĀ lp:~kvalo/indicator-network/settings-more-tech

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    /* A Gtk.VBox which holds all of the widgets to control a wired
24
24
       device. */
25
25
 
 
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;
27
38
 
28
39
    public WiredBox(Connman.Manager connman, string datadir) {
29
40
        this.set_spacing(12);
 
41
        this.datadir = datadir;
30
42
        this.connman = connman;
 
43
 
 
44
        this.connman.notify["ethernet-state"].connect(this.ethernet_state_changed);
 
45
        // Infobox and Togglswitch
 
46
        /// Creation
 
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);
 
53
        /// Packing
 
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);
 
57
        /// Connect signals;
 
58
        this.toggleswitch.toggled.connect(this.on_toggleswitch_toggled);
 
59
 
 
60
        // Network Settings
 
61
        /// Creation
 
62
        this.builder = Utils.Gui.new_builder(datadir + "ui/wired_box.ui");
 
63
        this.get_widgets();
 
64
        this.connect_signals();
 
65
        /// Packing
 
66
        this.pack_start(this.vbox_connections, true, true);
 
67
 
 
68
        /// Population
 
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);
 
75
                break;
 
76
            }
 
77
        }
 
78
 
 
79
        this.update_widget_states(this.connman.get_ethernet_state());
 
80
    }
 
81
 
 
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;
 
88
    }
 
89
 
 
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);
 
93
    }
 
94
 
 
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 = "";
 
100
 
 
101
        switch (state) {
 
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.");
 
107
            break;
 
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.");
 
113
            break;
 
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.");
 
119
            break;
 
120
        case Connman.TechnologyState.OFFLINE:
 
121
            device_editable = true;
 
122
            settings_editable = false;
 
123
            toggleswitch_state = false;
 
124
            status_text = ("Wired is offline.");
 
125
            break;
 
126
        }
 
127
 
 
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);
 
132
 
 
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";
 
139
            break;
 
140
        default:
 
141
            connect = "Connect";
 
142
            break;
 
143
        }
 
144
 
 
145
        this.button_connect.set_label(connect);
 
146
    }
 
147
 
 
148
    private void ethernet_state_changed(ParamSpec p) {
 
149
        this.update_widget_states(this.connman.get_ethernet_state());
 
150
    }
 
151
 
 
152
    private void service_state_changed() {
 
153
        this.update_widget_states(this.connman.get_ethernet_state());
 
154
    }
 
155
 
 
156
    private void on_toggleswitch_toggled() {
 
157
        if (this.toggleswitch.get_active()) {
 
158
            this.connman.enable_technology(Connman.TechnologyType.ETHERNET, null);
 
159
        } else {
 
160
            this.connman.disable_technology(Connman.TechnologyType.ETHERNET, null);
 
161
        }
 
162
    }
 
163
 
 
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();
 
171
            break;
 
172
        default:
 
173
            this.service.connect();
 
174
            break;
 
175
        }
 
176
    }
 
177
 
 
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; });
 
182
        dialog.run();
31
183
    }
32
184
}