Merge lp:~donadigo/switchboard-plug-sharing/network-disconnected into lp:~elementary-apps/switchboard-plug-sharing/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
Approved revision: 64
Merged at revision: 61
Proposed branch: lp:~donadigo/switchboard-plug-sharing/network-disconnected
Merge into: lp:~elementary-apps/switchboard-plug-sharing/trunk
Diff against target: 100 lines (+50/-6)
1 file modified
src/Plug.vala (+50/-6)
To merge this branch: bzr merge lp:~donadigo/switchboard-plug-sharing/network-disconnected
Reviewer Review Type Date Requested Status
Danielle Foré Needs Fixing
Review via email: mp+297104@code.launchpad.net

Commit message

* Fix bug #1528346: "Show a message when network is disconnected".

Description of the change

Fixes bug #1528346: "Show a message when network is disconnected".

This branch adds a simple AlertView when the network is disconnected, it uses already available NetworkMonitor from GIO so no need for additional libraries.

* Strings may be a little bit weird, please comment here to propose something better.
* Although the bug involved changing the page status to NOT_AVAILABLE, I've chosen a simpler method to present it directly in the root of the plug content.

To post a comment you must log in.
62. By Adam Bieńkowski

Actually use the container as root widget

63. By Adam Bieńkowski

Fix the child name

Revision history for this message
Danielle Foré (danrabbit) wrote :

Looks good except a few things:

For the secondary text maybe "While disconnected from the network, sharing services are not available."

When reconnected, the message is not removed.

I believe that alertview as a built-in link button you can use

review: Needs Fixing
64. By Adam Bieńkowski

Fix the description string; check if network is metered

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Plug.vala'
2--- src/Plug.vala 2016-05-07 18:11:46 +0000
3+++ src/Plug.vala 2016-06-10 20:45:37 +0000
4@@ -18,10 +18,12 @@
5 */
6
7 public class Sharing.Plug : Switchboard.Plug {
8- private Gtk.Paned? main_container = null;
9+ private Gtk.Stack? content = null;
10
11+ private Gtk.Paned main_container;
12 private Widgets.Sidebar sidebar;
13 private Widgets.SettingsView settings_view;
14+ private Gtk.LinkButton link_button;
15
16 public Plug () {
17 Object (category : Category.NETWORK,
18@@ -32,12 +34,13 @@
19 }
20
21 public override Gtk.Widget get_widget () {
22- if (main_container == null) {
23+ if (content == null) {
24 build_ui ();
25 connect_signals ();
26+ update_content_view ();
27 }
28
29- return main_container;
30+ return content;
31 }
32
33 public override void shown () {
34@@ -55,23 +58,64 @@
35 }
36
37 private void build_ui () {
38+ content = new Gtk.Stack ();
39+
40 main_container = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
41-
42 sidebar = new Widgets.Sidebar ();
43-
44 settings_view = new Widgets.SettingsView ();
45
46+ var network_alert_view = new Granite.Widgets.AlertView (_("Network Is Not Available"),
47+ _("While disconnected from the network, sharing services are not available."),
48+ "network-error");
49+ network_alert_view.get_style_context ().remove_class (Gtk.STYLE_CLASS_VIEW);
50+
51+ link_button = new Gtk.LinkButton (_("Network settings…"));
52+ link_button.halign = Gtk.Align.END;
53+ link_button.valign = Gtk.Align.END;
54+ link_button.vexpand = true;
55+
56+ var network_grid_view = new Gtk.Grid ();
57+ network_grid_view.margin = 24;
58+ network_grid_view.attach (network_alert_view, 0, 0, 1, 1);
59+ network_grid_view.attach (link_button, 0, 1, 1, 1);
60+
61 foreach (Widgets.SettingsPage settings_page in settings_view.get_settings_pages ()) {
62 sidebar.add_service_entry (settings_page.get_service_entry ());
63 }
64
65 main_container.pack1 (sidebar, false, false);
66 main_container.pack2 (settings_view, true, false);
67- main_container.show_all ();
68+
69+ content.add_named (main_container, "main-container");
70+ content.add_named (network_grid_view, "network-alert-view");
71+ content.show_all ();
72 }
73
74 private void connect_signals () {
75+ NetworkMonitor.get_default ().network_changed.connect (() => update_content_view ());
76 sidebar.selected_service_changed.connect (settings_view.show_service_settings);
77+
78+ link_button.activate_link.connect (() => {
79+ var list = new List<string> ();
80+ list.append ("network");
81+
82+ try {
83+ var appinfo = AppInfo.create_from_commandline ("switchboard", null, AppInfoCreateFlags.SUPPORTS_URIS);
84+ appinfo.launch_uris (list, null);
85+ } catch (Error e) {
86+ warning (e.message);
87+ }
88+
89+ return true;
90+ });
91+ }
92+
93+ private void update_content_view () {
94+ if (NetworkMonitor.get_default ().get_network_available () || NetworkMonitor.get_default ().get_network_metered ()) {
95+ content.visible_child_name = "main-container";
96+ } else {
97+ content.visible_child_name = "network-alert-view";
98+ }
99 }
100 }
101

Subscribers

People subscribed via source and target branches