Merge lp:~voldyman/switchboard/handle-cmd-line into lp:~elementary-pantheon/switchboard/switchboard

Proposed by Akshay Shekher
Status: Merged
Approved by: Corentin Noël
Approved revision: 450
Merged at revision: 447
Proposed branch: lp:~voldyman/switchboard/handle-cmd-line
Merge into: lp:~elementary-pantheon/switchboard/switchboard
Diff against target: 165 lines (+53/-34)
2 files modified
src/CategoryView.vala (+5/-1)
src/Switchboard.vala (+48/-33)
To merge this branch: bzr merge lp:~voldyman/switchboard/handle-cmd-line
Reviewer Review Type Date Requested Status
Corentin Noël Approve
Review via email: mp+220920@code.launchpad.net

Commit message

SwitchboardApp now handle command line even if launched

Description of the change

Fix bug 1172682.

Bug fixed by making Switchboad Application handle command line flags.

to test:

./switchboard -o system-pantheon-power
switchboard will open with Power plug

in a new tab in terminal
./switchboard -o personal-pantheon-default

the window that is already open will show the Defaults Plug.

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

All is nice, you actually fixed an other bug (#1321064)
Only one thing, diff line 145 you did remove Gtk.main (); please revert this and your branch is ready to be merged.

Revision history for this message
Corentin Noël (tintou) :
review: Needs Fixing
Revision history for this message
Akshay Shekher (voldyman) wrote :

AFAIK Gtk.main (); doesn't need to be manually called when using an Application class with Windows.

is it necessary?

Revision history for this message
Corentin Noël (tintou) wrote :

The program will indeed run without it but I haven't seen anywhere that it
wasn't needed.
In all cases, the GLib.main_quit (); complains about GLib.Main () not being
called.
Le 27 mai 2014 05:17, "Akshay Shekher" <email address hidden> a écrit :

> AFAIK Gtk.main (); doesn't need to be manually called when using an
> Application class with Windows.
>
> is it necessary?
> --
>
> https://code.launchpad.net/~voldyman/switchboard/handle-cmd-line/+merge/220920
> You are reviewing the proposed merge of
> lp:~voldyman/switchboard/handle-cmd-line into lp:switchboard.
>

448. By Akshay Shekher

removed main_quit

Revision history for this message
Akshay Shekher (voldyman) wrote :

Removed the main_quit

Revision history for this message
Corentin Noël (tintou) wrote :

Please not. Do add the main.
Le 27 mai 2014 07:29, "Akshay Shekher" <email address hidden> a écrit :

> Removed the main_quit
> --
>
> https://code.launchpad.net/~voldyman/switchboard/handle-cmd-line/+merge/220920
> You are reviewing the proposed merge of
> lp:~voldyman/switchboard/handle-cmd-line into lp:switchboard.
>

Revision history for this message
Akshay Shekher (voldyman) wrote :

The branch doesn't work with Gtk.main ();

Revision history for this message
Corentin Noël (tintou) wrote :

Why wouldn't it, I've tested it westerday and could open different plugs
without any problem.
Le 27 mai 2014 07:42, "Akshay Shekher" <email address hidden> a écrit :

> The branch doesn't work with Gtk.main ();
>
> --
>
> https://code.launchpad.net/~voldyman/switchboard/handle-cmd-line/+merge/220920
> You are reviewing the proposed merge of
> lp:~voldyman/switchboard/handle-cmd-line into lp:switchboard.
>

449. By Akshay Shekher

added Gtk.main

Revision history for this message
Akshay Shekher (voldyman) wrote :

sorry, my bad. tested the wrong branch.

450. By Akshay Shekher

fixed tab

Revision history for this message
Corentin Noël (tintou) wrote :

Okay let's merge it, nice work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/CategoryView.vala'
--- src/CategoryView.vala 2014-04-18 18:08:44 +0000
+++ src/CategoryView.vala 2014-05-27 05:49:00 +0000
@@ -43,7 +43,11 @@
43 public Gtk.IconView network_iconview;43 public Gtk.IconView network_iconview;
44 public Gtk.IconView system_iconview;44 public Gtk.IconView system_iconview;
4545
46 public CategoryView () {46 private string? plug_to_open = null;
47
48 public CategoryView (string? plug_to_open = null) {
49 this.plug_to_open = plug_to_open;
50
47 setup_category (Switchboard.Plug.Category.PERSONAL, 0);51 setup_category (Switchboard.Plug.Category.PERSONAL, 0);
48 setup_category (Switchboard.Plug.Category.HARDWARE, 1);52 setup_category (Switchboard.Plug.Category.HARDWARE, 1);
49 setup_category (Switchboard.Plug.Category.NETWORK, 2);53 setup_category (Switchboard.Plug.Category.NETWORK, 2);
5054
=== modified file 'src/Switchboard.vala'
--- src/Switchboard.vala 2014-04-18 18:08:44 +0000
+++ src/Switchboard.vala 2014-05-27 05:49:00 +0000
@@ -17,31 +17,15 @@
1717
18namespace Switchboard {18namespace Switchboard {
1919
20 static const OptionEntry[] entries = {
21 { "open-plug", 'o', 0, OptionArg.STRING, ref plug_to_open, N_("Open a plug"), "PLUG_NAME" },
22 { null }
23 };
2420
25 public enum WindowState {21 public enum WindowState {
26 NORMAL = 0,22 NORMAL = 0,
27 MAXIMIZED = 123 MAXIMIZED = 1
28 }24 }
2925
30 private static string? plug_to_open = null;
31 private static bool should_animate_next_transition = true;
32
33 public static int main (string[] args) {26 public static int main (string[] args) {
34 Gtk.init (ref args);27 Gtk.init (ref args);
3528
36 var context = new OptionContext ("");
37 context.add_main_entries (entries, "switchboard ");
38 context.add_group (Gtk.get_option_group (true));
39 try {
40 context.parse (ref args);
41 } catch (Error e) {
42 warning (e.message);
43 }
44
45 var app = new SwitchboardApp ();29 var app = new SwitchboardApp ();
46 return app.run (args);30 return app.run (args);
47 }31 }
@@ -66,12 +50,21 @@
66 private int default_width = 0;50 private int default_width = 0;
67 private int default_height = 0;51 private int default_height = 0;
6852
53 private static string? plug_to_open = null;
54 private static bool should_animate_next_transition = true;
55
56 static const OptionEntry[] entries = {
57 { "open-plug", 'o', 0, OptionArg.STRING, ref plug_to_open, N_("Open a plug"), "PLUG_NAME" },
58 { null }
59 };
60
69 construct {61 construct {
70 application_id = "org.elementary.switchboard";62 application_id = "org.elementary.switchboard";
71 program_name = _("System Settings");63 program_name = _("System Settings");
72 app_years = "2011-2014";64 app_years = "2011-2014";
73 exec_name = "switchboard";65 exec_name = "switchboard";
74 app_launcher = exec_name+".desktop";66 app_launcher = exec_name+".desktop";
67 flags |= ApplicationFlags.HANDLES_COMMAND_LINE;
7568
76 build_version = "2.0";69 build_version = "2.0";
77 app_icon = "preferences-desktop";70 app_icon = "preferences-desktop";
@@ -84,21 +77,26 @@
84 about_license_type = Gtk.License.GPL_3_0;77 about_license_type = Gtk.License.GPL_3_0;
85 }78 }
8679
87 public override void activate () {80 public override int command_line (ApplicationCommandLine command_line) {
88 // If app is already running, present the current window.81 hold ();
89 if (get_windows () != null) {82 int res = _command_line (command_line);
90 get_windows ().data.present ();83 release ();
91 if (plug_to_open != null) {84 return res;
92 var plugsmanager = Switchboard.PlugsManager.get_default ();85 }
93 foreach (var plug in plugsmanager.get_plugs ()) {86
94 if (plug_to_open.has_suffix (plug.code_name)) {87 private int _command_line (ApplicationCommandLine command_line) {
95 load_plug (plug);88 var context = new OptionContext ("");
96 plug_to_open = null;89 context.add_main_entries (entries, "switchboard ");
97 break;90 context.add_group (Gtk.get_option_group (true));
98 }91
99 }92 string[] args = command_line.get_arguments ();
100 }93
101 return;94 try {
95 unowned string[] tmp = args;
96 context.parse (ref tmp);
97 } catch (Error e) {
98 warning (e.message);
99 return 0;
102 }100 }
103101
104 if (DEBUG)102 if (DEBUG)
@@ -106,8 +104,22 @@
106 else104 else
107 Granite.Services.Logger.DisplayLevel = Granite.Services.LogLevel.INFO;105 Granite.Services.Logger.DisplayLevel = Granite.Services.LogLevel.INFO;
108106
109 // If plug_to_open was set from the command line
110 if (plug_to_open != null) {107 if (plug_to_open != null) {
108 var plugsmanager = Switchboard.PlugsManager.get_default ();
109 foreach (var plug in plugsmanager.get_plugs ()) {
110 if (plug_to_open.has_suffix (plug.code_name)) {
111 load_plug (plug);
112 plug_to_open = null;
113 break;
114 }
115 }
116 // If app is already running, present the current window.
117 if (get_windows () != null) {
118 get_windows ().data.present ();
119 return 1;
120 }
121
122 // If plug_to_open was set from the command line
111 should_animate_next_transition = false;123 should_animate_next_transition = false;
112 }124 }
113125
@@ -117,6 +129,8 @@
117 build ();129 build ();
118 category_view.load_default_plugs.begin ();130 category_view.load_default_plugs.begin ();
119 Gtk.main ();131 Gtk.main ();
132
133 return 0;
120 }134 }
121135
122 public void hide_alert () {136 public void hide_alert () {
@@ -180,6 +194,7 @@
180194
181 private void build () {195 private void build () {
182 main_window = new Gtk.Window();196 main_window = new Gtk.Window();
197 add_window (main_window);
183198
184 // Set up defaults199 // Set up defaults
185 main_window.title = program_name;200 main_window.title = program_name;
@@ -216,7 +231,7 @@
216 return true;231 return true;
217 });232 });
218233
219 category_view = new Switchboard.CategoryView ();234 category_view = new Switchboard.CategoryView (plug_to_open);
220 category_view.plug_selected.connect ((plug) => load_plug (plug));235 category_view.plug_selected.connect ((plug) => load_plug (plug));
221 category_view.margin_top = 12;236 category_view.margin_top = 12;
222237

Subscribers

People subscribed via source and target branches

to all changes: