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
=== modified file 'src/Plug.vala'
--- src/Plug.vala 2016-05-07 18:11:46 +0000
+++ src/Plug.vala 2016-06-10 20:45:37 +0000
@@ -18,10 +18,12 @@
18 */18 */
1919
20public class Sharing.Plug : Switchboard.Plug {20public class Sharing.Plug : Switchboard.Plug {
21 private Gtk.Paned? main_container = null;21 private Gtk.Stack? content = null;
2222
23 private Gtk.Paned main_container;
23 private Widgets.Sidebar sidebar;24 private Widgets.Sidebar sidebar;
24 private Widgets.SettingsView settings_view;25 private Widgets.SettingsView settings_view;
26 private Gtk.LinkButton link_button;
2527
26 public Plug () {28 public Plug () {
27 Object (category : Category.NETWORK,29 Object (category : Category.NETWORK,
@@ -32,12 +34,13 @@
32 }34 }
3335
34 public override Gtk.Widget get_widget () {36 public override Gtk.Widget get_widget () {
35 if (main_container == null) {37 if (content == null) {
36 build_ui ();38 build_ui ();
37 connect_signals ();39 connect_signals ();
40 update_content_view ();
38 }41 }
3942
40 return main_container;43 return content;
41 }44 }
4245
43 public override void shown () {46 public override void shown () {
@@ -55,23 +58,64 @@
55 }58 }
5659
57 private void build_ui () {60 private void build_ui () {
61 content = new Gtk.Stack ();
62
58 main_container = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);63 main_container = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
59
60 sidebar = new Widgets.Sidebar ();64 sidebar = new Widgets.Sidebar ();
61
62 settings_view = new Widgets.SettingsView ();65 settings_view = new Widgets.SettingsView ();
6366
67 var network_alert_view = new Granite.Widgets.AlertView (_("Network Is Not Available"),
68 _("While disconnected from the network, sharing services are not available."),
69 "network-error");
70 network_alert_view.get_style_context ().remove_class (Gtk.STYLE_CLASS_VIEW);
71
72 link_button = new Gtk.LinkButton (_("Network settings…"));
73 link_button.halign = Gtk.Align.END;
74 link_button.valign = Gtk.Align.END;
75 link_button.vexpand = true;
76
77 var network_grid_view = new Gtk.Grid ();
78 network_grid_view.margin = 24;
79 network_grid_view.attach (network_alert_view, 0, 0, 1, 1);
80 network_grid_view.attach (link_button, 0, 1, 1, 1);
81
64 foreach (Widgets.SettingsPage settings_page in settings_view.get_settings_pages ()) {82 foreach (Widgets.SettingsPage settings_page in settings_view.get_settings_pages ()) {
65 sidebar.add_service_entry (settings_page.get_service_entry ());83 sidebar.add_service_entry (settings_page.get_service_entry ());
66 }84 }
6785
68 main_container.pack1 (sidebar, false, false);86 main_container.pack1 (sidebar, false, false);
69 main_container.pack2 (settings_view, true, false);87 main_container.pack2 (settings_view, true, false);
70 main_container.show_all ();88
89 content.add_named (main_container, "main-container");
90 content.add_named (network_grid_view, "network-alert-view");
91 content.show_all ();
71 }92 }
7293
73 private void connect_signals () {94 private void connect_signals () {
95 NetworkMonitor.get_default ().network_changed.connect (() => update_content_view ());
74 sidebar.selected_service_changed.connect (settings_view.show_service_settings);96 sidebar.selected_service_changed.connect (settings_view.show_service_settings);
97
98 link_button.activate_link.connect (() => {
99 var list = new List<string> ();
100 list.append ("network");
101
102 try {
103 var appinfo = AppInfo.create_from_commandline ("switchboard", null, AppInfoCreateFlags.SUPPORTS_URIS);
104 appinfo.launch_uris (list, null);
105 } catch (Error e) {
106 warning (e.message);
107 }
108
109 return true;
110 });
111 }
112
113 private void update_content_view () {
114 if (NetworkMonitor.get_default ().get_network_available () || NetworkMonitor.get_default ().get_network_metered ()) {
115 content.visible_child_name = "main-container";
116 } else {
117 content.visible_child_name = "network-alert-view";
118 }
75 }119 }
76}120}
77121

Subscribers

People subscribed via source and target branches