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
1=== modified file 'src/CategoryView.vala'
2--- src/CategoryView.vala 2014-04-18 18:08:44 +0000
3+++ src/CategoryView.vala 2014-05-27 05:49:00 +0000
4@@ -43,7 +43,11 @@
5 public Gtk.IconView network_iconview;
6 public Gtk.IconView system_iconview;
7
8- public CategoryView () {
9+ private string? plug_to_open = null;
10+
11+ public CategoryView (string? plug_to_open = null) {
12+ this.plug_to_open = plug_to_open;
13+
14 setup_category (Switchboard.Plug.Category.PERSONAL, 0);
15 setup_category (Switchboard.Plug.Category.HARDWARE, 1);
16 setup_category (Switchboard.Plug.Category.NETWORK, 2);
17
18=== modified file 'src/Switchboard.vala'
19--- src/Switchboard.vala 2014-04-18 18:08:44 +0000
20+++ src/Switchboard.vala 2014-05-27 05:49:00 +0000
21@@ -17,31 +17,15 @@
22
23 namespace Switchboard {
24
25- static const OptionEntry[] entries = {
26- { "open-plug", 'o', 0, OptionArg.STRING, ref plug_to_open, N_("Open a plug"), "PLUG_NAME" },
27- { null }
28- };
29
30 public enum WindowState {
31 NORMAL = 0,
32 MAXIMIZED = 1
33 }
34
35- private static string? plug_to_open = null;
36- private static bool should_animate_next_transition = true;
37-
38 public static int main (string[] args) {
39 Gtk.init (ref args);
40
41- var context = new OptionContext ("");
42- context.add_main_entries (entries, "switchboard ");
43- context.add_group (Gtk.get_option_group (true));
44- try {
45- context.parse (ref args);
46- } catch (Error e) {
47- warning (e.message);
48- }
49-
50 var app = new SwitchboardApp ();
51 return app.run (args);
52 }
53@@ -66,12 +50,21 @@
54 private int default_width = 0;
55 private int default_height = 0;
56
57+ private static string? plug_to_open = null;
58+ private static bool should_animate_next_transition = true;
59+
60+ static const OptionEntry[] entries = {
61+ { "open-plug", 'o', 0, OptionArg.STRING, ref plug_to_open, N_("Open a plug"), "PLUG_NAME" },
62+ { null }
63+ };
64+
65 construct {
66 application_id = "org.elementary.switchboard";
67 program_name = _("System Settings");
68 app_years = "2011-2014";
69 exec_name = "switchboard";
70 app_launcher = exec_name+".desktop";
71+ flags |= ApplicationFlags.HANDLES_COMMAND_LINE;
72
73 build_version = "2.0";
74 app_icon = "preferences-desktop";
75@@ -84,21 +77,26 @@
76 about_license_type = Gtk.License.GPL_3_0;
77 }
78
79- public override void activate () {
80- // If app is already running, present the current window.
81- if (get_windows () != null) {
82- get_windows ().data.present ();
83- if (plug_to_open != null) {
84- var plugsmanager = Switchboard.PlugsManager.get_default ();
85- foreach (var plug in plugsmanager.get_plugs ()) {
86- if (plug_to_open.has_suffix (plug.code_name)) {
87- load_plug (plug);
88- plug_to_open = null;
89- break;
90- }
91- }
92- }
93- return;
94+ public override int command_line (ApplicationCommandLine command_line) {
95+ hold ();
96+ int res = _command_line (command_line);
97+ release ();
98+ return res;
99+ }
100+
101+ private int _command_line (ApplicationCommandLine command_line) {
102+ var context = new OptionContext ("");
103+ context.add_main_entries (entries, "switchboard ");
104+ context.add_group (Gtk.get_option_group (true));
105+
106+ string[] args = command_line.get_arguments ();
107+
108+ try {
109+ unowned string[] tmp = args;
110+ context.parse (ref tmp);
111+ } catch (Error e) {
112+ warning (e.message);
113+ return 0;
114 }
115
116 if (DEBUG)
117@@ -106,8 +104,22 @@
118 else
119 Granite.Services.Logger.DisplayLevel = Granite.Services.LogLevel.INFO;
120
121- // If plug_to_open was set from the command line
122 if (plug_to_open != null) {
123+ var plugsmanager = Switchboard.PlugsManager.get_default ();
124+ foreach (var plug in plugsmanager.get_plugs ()) {
125+ if (plug_to_open.has_suffix (plug.code_name)) {
126+ load_plug (plug);
127+ plug_to_open = null;
128+ break;
129+ }
130+ }
131+ // If app is already running, present the current window.
132+ if (get_windows () != null) {
133+ get_windows ().data.present ();
134+ return 1;
135+ }
136+
137+ // If plug_to_open was set from the command line
138 should_animate_next_transition = false;
139 }
140
141@@ -117,6 +129,8 @@
142 build ();
143 category_view.load_default_plugs.begin ();
144 Gtk.main ();
145+
146+ return 0;
147 }
148
149 public void hide_alert () {
150@@ -180,6 +194,7 @@
151
152 private void build () {
153 main_window = new Gtk.Window();
154+ add_window (main_window);
155
156 // Set up defaults
157 main_window.title = program_name;
158@@ -216,7 +231,7 @@
159 return true;
160 });
161
162- category_view = new Switchboard.CategoryView ();
163+ category_view = new Switchboard.CategoryView (plug_to_open);
164 category_view.plug_selected.connect ((plug) => load_plug (plug));
165 category_view.margin_top = 12;
166

Subscribers

People subscribed via source and target branches

to all changes: