Merge lp:~elementary-apps/switchboard/cleanup into lp:~elementary-pantheon/switchboard/switchboard
- cleanup
- Merge into switchboard
Status: | Rejected |
---|---|
Rejected by: | Julián Unrrein |
Proposed branch: | lp:~elementary-apps/switchboard/cleanup |
Merge into: | lp:~elementary-pantheon/switchboard/switchboard |
Diff against target: |
577 lines (+148/-120) 3 files modified
src/CategoryView.vala (+1/-1) src/EmbeddedAlert.vala (+1/-1) src/Switchboard.vala (+146/-118) |
To merge this branch: | bzr merge lp:~elementary-apps/switchboard/cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Julián Unrrein (community) | Disapprove | ||
David Gomes (community) | Needs Fixing | ||
Review via email: mp+188034@code.launchpad.net |
Commit message
Description of the change
Fixing codestyle.
Julián Unrrein (junrrein) wrote : | # |
Julián Unrrein (junrrein) wrote : | # |
I would offer to submit the changes myself (since I'm in ~elementary-apps too) but I am not able to compile this on Luna (GTK >= 3.6 required).
- 406. By David Gomes
-
More fixes.
David Gomes (davidgomes) wrote : | # |
Junrrein, I fixed the stuff. Care to re-review?
Julián Unrrein (junrrein) wrote : | # |
Re-indent diff lines 150, 153, 163-164, 391, they are part of foreach blocks.
You can close lines 163-164 in curly braces for clarity.
Diff line 225: Move the warning to its own line.
Diff line 373: Space after get_file_type.
Diff line 475: Space after search_
I see you also fixed stuff I didn't catch, nice!
- 407. By David Gomes
-
Fixed yet more code style.
Julián Unrrein (junrrein) wrote : | # |
It's ready to go.
Good work Raphael and Munchor!
Julián Unrrein (junrrein) wrote : | # |
Rejecting this branch because there are major changes coming to Switchboard (see https:/
We should review that branch for code style later instead.
Unmerged revisions
- 407. By David Gomes
-
Fixed yet more code style.
- 406. By David Gomes
-
More fixes.
- 405. By Raphael Isemann
-
cleaning CategoryView.vala
- 404. By Raphael Isemann
-
cleaning EmbeddedAlert.vala
- 403. By Raphael Isemann
-
cleaning Switchboard.vala
Preview Diff
1 | === modified file 'src/CategoryView.vala' | |||
2 | --- src/CategoryView.vala 2013-09-29 19:41:03 +0000 | |||
3 | +++ src/CategoryView.vala 2013-12-03 21:13:09 +0000 | |||
4 | @@ -53,7 +53,7 @@ | |||
5 | 53 | category_label.margin_left = 12; | 53 | category_label.margin_left = 12; |
6 | 54 | category_label.margin_right = 8; | 54 | category_label.margin_right = 8; |
7 | 55 | var filtered = new Gtk.TreeModelFilter (store, null); | 55 | var filtered = new Gtk.TreeModelFilter (store, null); |
9 | 56 | filtered.set_visible_column(3); | 56 | filtered.set_visible_column (3); |
10 | 57 | filtered.refilter (); | 57 | filtered.refilter (); |
11 | 58 | 58 | ||
12 | 59 | var category_plugs = new Gtk.IconView.with_model (filtered); | 59 | var category_plugs = new Gtk.IconView.with_model (filtered); |
13 | 60 | 60 | ||
14 | === modified file 'src/EmbeddedAlert.vala' | |||
15 | --- src/EmbeddedAlert.vala 2013-01-08 15:21:51 +0000 | |||
16 | +++ src/EmbeddedAlert.vala 2013-12-03 21:13:09 +0000 | |||
17 | @@ -113,7 +113,7 @@ | |||
18 | 113 | primary_text_label.halign = secondary_text_label.halign = Gtk.Align.START; | 113 | primary_text_label.halign = secondary_text_label.halign = Gtk.Align.START; |
19 | 114 | primary_text_label.justify = Gtk.Justification.LEFT; | 114 | primary_text_label.justify = Gtk.Justification.LEFT; |
20 | 115 | secondary_text_label.justify = Gtk.Justification.FILL; | 115 | secondary_text_label.justify = Gtk.Justification.FILL; |
22 | 116 | image.set_pixel_size(64); | 116 | image.set_pixel_size (64); |
23 | 117 | 117 | ||
24 | 118 | // TODO: More intelligent icon support, I guess. Or support all the | 118 | // TODO: More intelligent icon support, I guess. Or support all the |
25 | 119 | // MessageType flags. | 119 | // MessageType flags. |
26 | 120 | 120 | ||
27 | === modified file 'src/Switchboard.vala' | |||
28 | --- src/Switchboard.vala 2013-09-26 08:05:15 +0000 | |||
29 | +++ src/Switchboard.vala 2013-12-03 21:13:09 +0000 | |||
30 | @@ -1,18 +1,18 @@ | |||
31 | 1 | /*** | 1 | /*** |
46 | 2 | BEGIN LICENSE | 2 | BEGIN LICENSE |
47 | 3 | Copyright (C) 2011-2012 Avi Romanoff <aviromanoff@gmail.com> | 3 | Copyright (C) 2011-2012 Avi Romanoff <aviromanoff@gmail.com> |
48 | 4 | This program is free software: you can redistribute it and/or modify it | 4 | This program is free software: you can redistribute it and/or modify it |
49 | 5 | under the terms of the GNU Lesser General Public License version 3, as published | 5 | under the terms of the GNU Lesser General Public License version 3, as published |
50 | 6 | by the Free Software Foundation. | 6 | by the Free Software Foundation. |
51 | 7 | 7 | ||
52 | 8 | This program is distributed in the hope that it will be useful, but | 8 | This program is distributed in the hope that it will be useful, but |
53 | 9 | WITHOUT ANY WARRANTY; without even the implied warranties of | 9 | WITHOUT ANY WARRANTY; without even the implied warranties of |
54 | 10 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | 10 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
55 | 11 | PURPOSE. See the GNU General Public License for more details. | 11 | PURPOSE. See the GNU General Public License for more details. |
56 | 12 | 12 | ||
57 | 13 | You should have received a copy of the GNU General Public License along | 13 | You should have received a copy of the GNU General Public License along |
58 | 14 | with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | with this program. If not, see <http://www.gnu.org/licenses/>. |
59 | 15 | END LICENSE | 15 | END LICENSE |
60 | 16 | ***/ | 16 | ***/ |
61 | 17 | 17 | ||
62 | 18 | namespace Switchboard { | 18 | namespace Switchboard { |
63 | @@ -21,13 +21,13 @@ | |||
64 | 21 | 21 | ||
65 | 22 | [DBus (name = "org.elementary.switchboard")] | 22 | [DBus (name = "org.elementary.switchboard")] |
66 | 23 | public class SwitchboardApp : Granite.Application { | 23 | public class SwitchboardApp : Granite.Application { |
68 | 24 | 24 | ||
69 | 25 | construct { | 25 | construct { |
70 | 26 | application_id = "org.elementary.Switchboard"; | 26 | application_id = "org.elementary.Switchboard"; |
71 | 27 | program_name = "Switchboard"; | 27 | program_name = "Switchboard"; |
72 | 28 | app_years = "2011-2012"; | 28 | app_years = "2011-2012"; |
73 | 29 | exec_name = "switchboard"; | 29 | exec_name = "switchboard"; |
75 | 30 | app_launcher = exec_name+".desktop"; | 30 | app_launcher = exec_name + ".desktop"; |
76 | 31 | 31 | ||
77 | 32 | build_version = VERSION; | 32 | build_version = VERSION; |
78 | 33 | app_icon = APP_ICON; | 33 | app_icon = APP_ICON; |
79 | @@ -51,9 +51,9 @@ | |||
80 | 51 | // These two wrap the progress bar | 51 | // These two wrap the progress bar |
81 | 52 | Gtk.ToolItem lspace = new Gtk.ToolItem (); | 52 | Gtk.ToolItem lspace = new Gtk.ToolItem (); |
82 | 53 | Gtk.ToolItem rspace = new Gtk.ToolItem (); | 53 | Gtk.ToolItem rspace = new Gtk.ToolItem (); |
84 | 54 | 54 | ||
85 | 55 | Gtk.Spinner loading; | 55 | Gtk.Spinner loading; |
87 | 56 | 56 | ||
88 | 57 | Gtk.Window main_window; | 57 | Gtk.Window main_window; |
89 | 58 | 58 | ||
90 | 59 | // Content area widgets | 59 | // Content area widgets |
91 | @@ -65,12 +65,12 @@ | |||
92 | 65 | 65 | ||
93 | 66 | // Plug data | 66 | // Plug data |
94 | 67 | bool socket_shown; | 67 | bool socket_shown; |
96 | 68 | Gee.HashMap<string, string> current_plug = new Gee.HashMap<string, string>(); | 68 | Gee.HashMap<string, string> current_plug = new Gee.HashMap<string, string> (); |
97 | 69 | Gee.HashMap<string, string>[] plugs; | 69 | Gee.HashMap<string, string>[] plugs; |
98 | 70 | 70 | ||
99 | 71 | string[] plug_places = {"/usr/share/plugs/", | 71 | string[] plug_places = {"/usr/share/plugs/", |
100 | 72 | "/usr/lib/plugs/", | 72 | "/usr/lib/plugs/", |
102 | 73 | "/usr/local/share/plugs/", | 73 | "/usr/local/share/plugs/", |
103 | 74 | "/usr/local/lib/plugs/"}; | 74 | "/usr/local/lib/plugs/"}; |
104 | 75 | string search_box_buffer = ""; | 75 | string search_box_buffer = ""; |
105 | 76 | 76 | ||
106 | @@ -78,9 +78,9 @@ | |||
107 | 78 | 78 | ||
108 | 79 | public SwitchboardApp () { | 79 | public SwitchboardApp () { |
109 | 80 | } | 80 | } |
111 | 81 | 81 | ||
112 | 82 | void build () { | 82 | void build () { |
114 | 83 | main_window = new Gtk.Window(); | 83 | main_window = new Gtk.Window (); |
115 | 84 | 84 | ||
116 | 85 | // Set up defaults | 85 | // Set up defaults |
117 | 86 | main_window.title = APP_TITLE; | 86 | main_window.title = APP_TITLE; |
118 | @@ -95,8 +95,8 @@ | |||
119 | 95 | 95 | ||
120 | 96 | // Set up socket | 96 | // Set up socket |
121 | 97 | socket = new Gtk.Socket (); | 97 | socket = new Gtk.Socket (); |
124 | 98 | socket.set_hexpand(true); | 98 | socket.set_hexpand (true); |
125 | 99 | socket.set_vexpand(true); | 99 | socket.set_vexpand (true); |
126 | 100 | 100 | ||
127 | 101 | socket.plug_removed.connect (() => { | 101 | socket.plug_removed.connect (() => { |
128 | 102 | plug_closed (); | 102 | plug_closed (); |
129 | @@ -108,11 +108,12 @@ | |||
130 | 108 | uint accel_key; | 108 | uint accel_key; |
131 | 109 | Gdk.ModifierType accel_mod; | 109 | Gdk.ModifierType accel_mod; |
132 | 110 | var accel_flags = Gtk.AccelFlags.LOCKED; | 110 | var accel_flags = Gtk.AccelFlags.LOCKED; |
136 | 111 | Gtk.accelerator_parse("<Control>q", out accel_key, out accel_mod); | 111 | Gtk.accelerator_parse ("<Control>q", out accel_key, out accel_mod); |
137 | 112 | accel_group.connect(accel_key, accel_mod, accel_flags, () => { | 112 | accel_group.connect (accel_key, accel_mod, accel_flags, () => { |
138 | 113 | main_window.destroy(); | 113 | main_window.destroy (); |
139 | 114 | return true; | 114 | return true; |
140 | 115 | }); | 115 | }); |
141 | 116 | |||
142 | 116 | main_window.add_accel_group (accel_group); | 117 | main_window.add_accel_group (accel_group); |
143 | 117 | 118 | ||
144 | 118 | // ??? Why? | 119 | // ??? Why? |
145 | @@ -151,6 +152,7 @@ | |||
146 | 151 | 152 | ||
147 | 152 | foreach (var label in category_view.category_labels.values) | 153 | foreach (var label in category_view.category_labels.values) |
148 | 153 | label.hide (); | 154 | label.hide (); |
149 | 155 | |||
150 | 154 | foreach (var view in category_view.category_views.values) | 156 | foreach (var view in category_view.category_views.values) |
151 | 155 | view.hide (); | 157 | view.hide (); |
152 | 156 | 158 | ||
153 | @@ -178,17 +180,19 @@ | |||
154 | 178 | } | 180 | } |
155 | 179 | }); | 181 | }); |
156 | 180 | 182 | ||
159 | 181 | foreach (string place in plug_places) | 183 | foreach (string place in plug_places) { |
160 | 182 | if (enumerate_plugs (place)) | 184 | if (enumerate_plugs (place)) { |
161 | 183 | any_plugs = true; | 185 | any_plugs = true; |
162 | 186 | } | ||
163 | 187 | } | ||
164 | 184 | 188 | ||
165 | 185 | if (!any_plugs) { | 189 | if (!any_plugs) { |
167 | 186 | show_alert(_("No settings found"), _("Install some and re-launch Switchboard"), Gtk.MessageType.WARNING); | 190 | show_alert (_("No settings found"), _("Install some and re-launch Switchboard"), Gtk.MessageType.WARNING); |
168 | 187 | search_box.sensitive = false; | 191 | search_box.sensitive = false; |
169 | 188 | } else { | 192 | } else { |
170 | 189 | update_libunity_quicklist (); | 193 | update_libunity_quicklist (); |
171 | 190 | } | 194 | } |
173 | 191 | 195 | ||
174 | 192 | bool found = false; | 196 | bool found = false; |
175 | 193 | if (plug_to_open != null) { | 197 | if (plug_to_open != null) { |
176 | 194 | foreach (var plug in plugs) { | 198 | foreach (var plug in plugs) { |
177 | @@ -201,17 +205,17 @@ | |||
178 | 201 | critical ("Couldn't find %s among the loaded settings.", plug_to_open); | 205 | critical ("Couldn't find %s among the loaded settings.", plug_to_open); |
179 | 202 | } | 206 | } |
180 | 203 | } | 207 | } |
182 | 204 | 208 | ||
183 | 205 | foreach (var store in category_view.category_store.values) { | 209 | foreach (var store in category_view.category_store.values) { |
184 | 206 | store.foreach ((model, path, iter) => { | 210 | store.foreach ((model, path, iter) => { |
185 | 207 | store.set_value (iter, 3, true); | 211 | store.set_value (iter, 3, true); |
186 | 208 | return false; | 212 | return false; |
187 | 209 | }); | 213 | }); |
188 | 210 | } | 214 | } |
190 | 211 | 215 | ||
191 | 212 | progress_toolitem.hide (); | 216 | progress_toolitem.hide (); |
192 | 213 | } | 217 | } |
194 | 214 | 218 | ||
195 | 215 | void shut_down () { | 219 | void shut_down () { |
196 | 216 | plug_closed (); | 220 | plug_closed (); |
197 | 217 | } | 221 | } |
198 | @@ -234,28 +238,30 @@ | |||
199 | 234 | if (current_plug["title"] != title || !socket.visible) { | 238 | if (current_plug["title"] != title || !socket.visible) { |
200 | 235 | try { | 239 | try { |
201 | 236 | // The plug is already selected | 240 | // The plug is already selected |
203 | 237 | debug(_("Closing plug \"%s\" in Switchboard controller..."), current_plug["title"]); | 241 | debug (_("Closing plug \"%s\" in Switchboard controller..."), current_plug["title"]); |
204 | 238 | plug_closed (); | 242 | plug_closed (); |
206 | 239 | 243 | ||
207 | 240 | string[] cmd_exploded = (executable!=null)?executable.split (" "):null; | 244 | string[] cmd_exploded = (executable!=null)?executable.split (" "):null; |
208 | 241 | GLib.Process.spawn_async (File.new_for_path (cmd_exploded[0]).get_parent (). | 245 | GLib.Process.spawn_async (File.new_for_path (cmd_exploded[0]).get_parent (). |
211 | 242 | get_path (), cmd_exploded, null, SpawnFlags.SEARCH_PATH, null, null); | 246 | get_path (), cmd_exploded, null, SpawnFlags.SEARCH_PATH, null, null); |
212 | 243 | 247 | ||
213 | 244 | // ensure the button is sensitive; it might be the first plug loaded | 248 | // ensure the button is sensitive; it might be the first plug loaded |
214 | 245 | if (!@extern) { | 249 | if (!@extern) { |
216 | 246 | navigation_button.set_sensitive(true); | 250 | navigation_button.set_sensitive (true); |
217 | 247 | navigation_button.set_icon_name ("go-home"); | 251 | navigation_button.set_icon_name ("go-home"); |
218 | 248 | current_plug["title"] = title; | 252 | current_plug["title"] = title; |
219 | 249 | current_plug["executable"] = executable; | 253 | current_plug["executable"] = executable; |
220 | 250 | switch_to_socket (); | 254 | switch_to_socket (); |
221 | 251 | main_window.title = @"$APP_TITLE - $title"; | 255 | main_window.title = @"$APP_TITLE - $title"; |
222 | 252 | } | 256 | } |
224 | 253 | } catch { warning(_("Failed to launch plug: title %s | executable %s"), title, executable); } | 257 | } catch { |
225 | 258 | warning (_("Failed to launch plug: title %s | executable %s"), title, executable); | ||
226 | 259 | } | ||
227 | 254 | } else { | 260 | } else { |
229 | 255 | navigation_button.set_sensitive(true); | 261 | navigation_button.set_sensitive (true); |
230 | 256 | navigation_button.set_icon_name ("go-home"); | 262 | navigation_button.set_icon_name ("go-home"); |
231 | 257 | } | 263 | } |
233 | 258 | 264 | ||
234 | 259 | if (@extern) { | 265 | if (@extern) { |
235 | 260 | switch_to_icons (); | 266 | switch_to_icons (); |
236 | 261 | } | 267 | } |
237 | @@ -270,7 +276,7 @@ | |||
238 | 270 | void handle_navigation_button_clicked () { | 276 | void handle_navigation_button_clicked () { |
239 | 271 | string icon_name = navigation_button.get_icon_name (); | 277 | string icon_name = navigation_button.get_icon_name (); |
240 | 272 | if (icon_name == "go-home") { | 278 | if (icon_name == "go-home") { |
242 | 273 | switch_to_icons(); | 279 | switch_to_icons (); |
243 | 274 | navigation_button.set_icon_name ("go-previous"); | 280 | navigation_button.set_icon_name ("go-previous"); |
244 | 275 | } | 281 | } |
245 | 276 | else { | 282 | else { |
246 | @@ -289,25 +295,25 @@ | |||
247 | 289 | socket.hide (); | 295 | socket.hide (); |
248 | 290 | loading.show_all (); | 296 | loading.show_all (); |
249 | 291 | } | 297 | } |
251 | 292 | 298 | ||
252 | 293 | // Switches back to the icons | 299 | // Switches back to the icons |
253 | 294 | bool switch_to_icons () { | 300 | bool switch_to_icons () { |
254 | 295 | socket.hide (); | 301 | socket.hide (); |
255 | 296 | loading.hide (); | 302 | loading.hide (); |
256 | 297 | category_view.show (); | 303 | category_view.show (); |
258 | 298 | 304 | ||
259 | 299 | socket_shown = false; | 305 | socket_shown = false; |
260 | 300 | 306 | ||
261 | 301 | // Reset state | 307 | // Reset state |
262 | 302 | reset_title (); | 308 | reset_title (); |
266 | 303 | search_box.set_text(""); | 309 | search_box.set_text (""); |
267 | 304 | search_box.sensitive = count_plugs() > 0; | 310 | search_box.sensitive = count_plugs () > 0; |
268 | 305 | progress_label.set_text(""); | 311 | progress_label.set_text (""); |
269 | 306 | progress_bar.fraction = 0.0; | 312 | progress_bar.fraction = 0.0; |
270 | 307 | progress_toolitem.visible = false; | 313 | progress_toolitem.visible = false; |
272 | 308 | 314 | ||
273 | 309 | plug_closed (); | 315 | plug_closed (); |
275 | 310 | 316 | ||
276 | 311 | return true; | 317 | return true; |
277 | 312 | } | 318 | } |
278 | 313 | 319 | ||
279 | @@ -318,19 +324,24 @@ | |||
280 | 318 | 324 | ||
281 | 319 | // <keyfile's absolute path, keyfile's directory> | 325 | // <keyfile's absolute path, keyfile's directory> |
282 | 320 | List<string> keyfiles = find_plugs (plug_root_dir); | 326 | List<string> keyfiles = find_plugs (plug_root_dir); |
284 | 321 | if (keyfiles.length() == 0) { | 327 | if (keyfiles.length () == 0) { |
285 | 322 | return false; | 328 | return false; |
286 | 323 | } else { | 329 | } else { |
287 | 324 | foreach (string keyfile in keyfiles) { | 330 | foreach (string keyfile in keyfiles) { |
289 | 325 | KeyFile kf = new KeyFile(); | 331 | KeyFile kf = new KeyFile (); |
290 | 326 | 332 | ||
293 | 327 | string head = File.new_for_path(keyfile).get_basename(); | 333 | string head = File.new_for_path (keyfile).get_basename (); |
294 | 328 | string parent = File.new_for_path(keyfile).get_parent().get_path(); | 334 | string parent = File.new_for_path (keyfile).get_parent ().get_path (); |
295 | 329 | 335 | ||
296 | 330 | Gee.HashMap<string, string> plug = new Gee.HashMap<string, string> (); | 336 | Gee.HashMap<string, string> plug = new Gee.HashMap<string, string> (); |
300 | 331 | try { kf.load_from_file(keyfile, KeyFileFlags.NONE); | 337 | try { |
301 | 332 | } catch (Error e) { warning("Couldn't load this keyfile, %s (path: %s)", e.message, keyfile); } | 338 | kf.load_from_file (keyfile, KeyFileFlags.NONE); |
302 | 333 | plug["id"] = kf.get_start_group(); | 339 | } catch (Error e) { |
303 | 340 | warning ("Couldn't load this keyfile, %s (path: %s)", e.message, keyfile); | ||
304 | 341 | } | ||
305 | 342 | |||
306 | 343 | plug["id"] = kf.get_start_group (); | ||
307 | 344 | |||
308 | 334 | try { | 345 | try { |
309 | 335 | var exec = kf.get_string (head, "exec"); | 346 | var exec = kf.get_string (head, "exec"); |
310 | 336 | //if a path starts with a double slash, we take it as an absolute path | 347 | //if a path starts with a double slash, we take it as an absolute path |
311 | @@ -338,14 +349,21 @@ | |||
312 | 338 | exec = exec.substring (1); | 349 | exec = exec.substring (1); |
313 | 339 | plug["extern"] = "1"; | 350 | plug["extern"] = "1"; |
314 | 340 | } else { | 351 | } else { |
316 | 341 | exec = Path.build_filename(parent, exec); | 352 | exec = Path.build_filename (parent, exec); |
317 | 342 | plug["extern"] = "0"; | 353 | plug["extern"] = "0"; |
318 | 343 | } | 354 | } |
320 | 344 | 355 | ||
321 | 345 | plug["exec"] = exec; | 356 | plug["exec"] = exec; |
325 | 346 | } catch (Error e) { warning("Couldn't read exec field in file %s, %s", keyfile, e.message); } | 357 | } catch (Error e) { |
326 | 347 | try { plug["icon"] = kf.get_string (head, "icon"); | 358 | warning ("Couldn't read exec field in file %s, %s", keyfile, e.message); |
327 | 348 | } catch (Error e) { warning("Couldn't read icon field in file %s, %s", keyfile, e.message); } | 359 | } |
328 | 360 | |||
329 | 361 | try { | ||
330 | 362 | plug["icon"] = kf.get_string (head, "icon"); | ||
331 | 363 | } catch (Error e) { | ||
332 | 364 | warning ("Couldn't read icon field in file %s, %s", keyfile, e.message); | ||
333 | 365 | } | ||
334 | 366 | |||
335 | 349 | try { | 367 | try { |
336 | 350 | plug["title"] = kf.get_locale_string (head, "title"); | 368 | plug["title"] = kf.get_locale_string (head, "title"); |
337 | 351 | string? textdomain = null; | 369 | string? textdomain = null; |
338 | @@ -371,7 +389,7 @@ | |||
339 | 371 | 389 | ||
340 | 372 | // Checks if the file is a .plug file | 390 | // Checks if the file is a .plug file |
341 | 373 | bool is_plug_file (string filename) { | 391 | bool is_plug_file (string filename) { |
343 | 374 | return (filename.down().has_suffix(".plug")); | 392 | return (filename.down ().has_suffix (".plug")); |
344 | 375 | } | 393 | } |
345 | 376 | 394 | ||
346 | 377 | // Find all .plug files | 395 | // Find all .plug files |
347 | @@ -382,10 +400,10 @@ | |||
348 | 382 | } else { | 400 | } else { |
349 | 383 | keyfiles = new List<string> (); | 401 | keyfiles = new List<string> (); |
350 | 384 | foreach(var keyfile in keyfiles_list) { | 402 | foreach(var keyfile in keyfiles_list) { |
352 | 385 | keyfiles.append(keyfile); | 403 | keyfiles.append (keyfile); |
353 | 386 | } | 404 | } |
354 | 387 | } | 405 | } |
356 | 388 | 406 | ||
357 | 389 | var directory = File.new_for_path (path); | 407 | var directory = File.new_for_path (path); |
358 | 390 | if (!directory.query_exists ()) { | 408 | if (!directory.query_exists ()) { |
359 | 391 | return null; | 409 | return null; |
360 | @@ -395,30 +413,33 @@ | |||
361 | 395 | FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE, 0); | 413 | FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE, 0); |
362 | 396 | FileInfo file_info; | 414 | FileInfo file_info; |
363 | 397 | while ((file_info = enumerator.next_file ()) != null) { | 415 | while ((file_info = enumerator.next_file ()) != null) { |
370 | 398 | string file_path = Path.build_filename(path, file_info.get_name()); | 416 | string file_path = Path.build_filename (path, file_info.get_name ()); |
371 | 399 | if (file_info.get_file_type() == GLib.FileType.REGULAR && | 417 | if (file_info.get_file_type () == GLib.FileType.REGULAR && |
372 | 400 | is_plug_file(file_info.get_name())) { | 418 | is_plug_file (file_info.get_name ())) { |
373 | 401 | keyfiles.append(file_path); | 419 | keyfiles.append (file_path); |
374 | 402 | } else if(file_info.get_file_type() == GLib.FileType.DIRECTORY) { | 420 | } else if (file_info.get_file_type () == GLib.FileType.DIRECTORY) { |
375 | 403 | keyfiles = find_plugs(file_path, keyfiles); | 421 | keyfiles = find_plugs (file_path, keyfiles); |
376 | 404 | } | 422 | } |
377 | 405 | } | 423 | } |
380 | 406 | } catch { warning(_(@"Unable to iterate over enumerated plug directory \"$path\"'s contents")); } | 424 | } catch { |
381 | 407 | 425 | warning (_(@"Unable to iterate over enumerated plug directory \"$path\"'s contents")); | |
382 | 426 | } | ||
383 | 427 | |||
384 | 408 | return keyfiles; | 428 | return keyfiles; |
385 | 409 | } | 429 | } |
386 | 410 | 430 | ||
387 | 411 | // Counts how many plugs exist at the moment | 431 | // Counts how many plugs exist at the moment |
388 | 412 | int count_plugs () { | 432 | int count_plugs () { |
389 | 413 | |||
390 | 414 | uint count = 0; | 433 | uint count = 0; |
391 | 434 | |||
392 | 415 | foreach (string place in plug_places) | 435 | foreach (string place in plug_places) |
393 | 416 | count += find_plugs (place).length (); | 436 | count += find_plugs (place).length (); |
394 | 437 | |||
395 | 417 | return (int) count; | 438 | return (int) count; |
396 | 418 | } | 439 | } |
397 | 419 | 440 | ||
398 | 420 | /* | 441 | /* |
400 | 421 | D-Bus ONLY methods | 442 | D-Bus ONLY methods |
401 | 422 | */ | 443 | */ |
402 | 423 | 444 | ||
403 | 424 | public int get_socket_wid () { | 445 | public int get_socket_wid () { |
404 | @@ -430,12 +451,12 @@ | |||
405 | 430 | 451 | ||
406 | 431 | public void progress_bar_set_visible (bool visibility) { | 452 | public void progress_bar_set_visible (bool visibility) { |
407 | 432 | 453 | ||
409 | 433 | progress_toolitem.set_visible(visibility); | 454 | progress_toolitem.set_visible (visibility); |
410 | 434 | } | 455 | } |
411 | 435 | 456 | ||
412 | 436 | public void progress_bar_set_text (string text) { | 457 | public void progress_bar_set_text (string text) { |
413 | 437 | 458 | ||
415 | 438 | progress_label.set_text(text); | 459 | progress_label.set_text (text); |
416 | 439 | } | 460 | } |
417 | 440 | 461 | ||
418 | 441 | public void progress_bar_set_fraction (double fraction) { | 462 | public void progress_bar_set_fraction (double fraction) { |
419 | @@ -445,7 +466,7 @@ | |||
420 | 445 | 466 | ||
421 | 446 | public void progress_bar_pulse () { | 467 | public void progress_bar_pulse () { |
422 | 447 | 468 | ||
424 | 448 | progress_bar.pulse(); | 469 | progress_bar.pulse (); |
425 | 449 | } | 470 | } |
426 | 450 | 471 | ||
427 | 451 | public signal void search_box_activated (); | 472 | public signal void search_box_activated (); |
428 | @@ -458,7 +479,7 @@ | |||
429 | 458 | 479 | ||
430 | 459 | public void search_box_set_text (string text) { | 480 | public void search_box_set_text (string text) { |
431 | 460 | 481 | ||
433 | 461 | plug_closed(); | 482 | plug_closed (); |
434 | 462 | search_box.set_text (text); | 483 | search_box.set_text (text); |
435 | 463 | } | 484 | } |
436 | 464 | 485 | ||
437 | @@ -468,7 +489,7 @@ | |||
438 | 468 | } | 489 | } |
439 | 469 | 490 | ||
440 | 470 | /* | 491 | /* |
442 | 471 | End D-Bus ONLY methods | 492 | End D-Bus ONLY methods |
443 | 472 | */ | 493 | */ |
444 | 473 | 494 | ||
445 | 474 | // Sets up the toolbar for the Switchboard app | 495 | // Sets up the toolbar for the Switchboard app |
446 | @@ -479,28 +500,30 @@ | |||
447 | 479 | toolbar.get_style_context ().add_class ("primary-toolbar"); | 500 | toolbar.get_style_context ().add_class ("primary-toolbar"); |
448 | 480 | 501 | ||
449 | 481 | // Spacing | 502 | // Spacing |
452 | 482 | lspace.set_expand(true); | 503 | lspace.set_expand (true); |
453 | 483 | rspace.set_expand(true); | 504 | rspace.set_expand (true); |
454 | 484 | 505 | ||
455 | 485 | // Progressbar | 506 | // Progressbar |
456 | 486 | var progress_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); | 507 | var progress_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); |
457 | 487 | progress_label = new Gtk.Label (""); | 508 | progress_label = new Gtk.Label (""); |
459 | 488 | progress_label.set_use_markup(true); | 509 | progress_label.set_use_markup (true); |
460 | 489 | progress_bar = new Gtk.ProgressBar (); | 510 | progress_bar = new Gtk.ProgressBar (); |
461 | 490 | progress_toolitem = new Gtk.ToolItem (); | 511 | progress_toolitem = new Gtk.ToolItem (); |
466 | 491 | progress_vbox.pack_start(progress_label, true, false, 0); | 512 | progress_vbox.pack_start (progress_label, true, false, 0); |
467 | 492 | progress_vbox.pack_end(progress_bar, false, false, 0); | 513 | progress_vbox.pack_end (progress_bar, false, false, 0); |
468 | 493 | progress_toolitem.add(progress_vbox); | 514 | progress_toolitem.add (progress_vbox); |
469 | 494 | progress_toolitem.set_expand(true); | 515 | progress_toolitem.set_expand (true); |
470 | 495 | 516 | ||
471 | 496 | // Searchbar | 517 | // Searchbar |
472 | 497 | search_box = new Gtk.SearchEntry (); | 518 | search_box = new Gtk.SearchEntry (); |
473 | 498 | search_box.set_placeholder_text (_("Search Settings")); | 519 | search_box.set_placeholder_text (_("Search Settings")); |
478 | 499 | search_box.activate.connect(() => search_box_activated()); | 520 | search_box.activate.connect (() => search_box_activated ()); |
479 | 500 | search_box.changed.connect(() => { | 521 | |
480 | 501 | category_view.filter_plugs(search_box.get_text (), this); | 522 | search_box.changed.connect (() => { |
481 | 502 | search_box_text_changed(); | 523 | category_view.filter_plugs (search_box.get_text (), this); |
482 | 524 | search_box_text_changed (); | ||
483 | 503 | }); | 525 | }); |
484 | 526 | |||
485 | 504 | search_box.sensitive = (count_plugs () > 0); | 527 | search_box.sensitive = (count_plugs () > 0); |
486 | 505 | var find_toolitem = new Gtk.ToolItem (); | 528 | var find_toolitem = new Gtk.ToolItem (); |
487 | 506 | find_toolitem.add(search_box); | 529 | find_toolitem.add(search_box); |
488 | @@ -519,7 +542,7 @@ | |||
489 | 519 | navigation_button = new Gtk.ToolButton (null, null); | 542 | navigation_button = new Gtk.ToolButton (null, null); |
490 | 520 | navigation_button.set_icon_name ("go-previous"); | 543 | navigation_button.set_icon_name ("go-previous"); |
491 | 521 | navigation_button.clicked.connect (handle_navigation_button_clicked); | 544 | navigation_button.clicked.connect (handle_navigation_button_clicked); |
493 | 522 | navigation_button.set_sensitive(false); | 545 | navigation_button.set_sensitive (false); |
494 | 523 | 546 | ||
495 | 524 | // Add everything to the toolbar | 547 | // Add everything to the toolbar |
496 | 525 | toolbar.insert (navigation_button, -1); | 548 | toolbar.insert (navigation_button, -1); |
497 | @@ -528,7 +551,7 @@ | |||
498 | 528 | toolbar.insert (rspace, -1); | 551 | toolbar.insert (rspace, -1); |
499 | 529 | toolbar.insert (find_toolitem, -1); | 552 | toolbar.insert (find_toolitem, -1); |
500 | 530 | } | 553 | } |
502 | 531 | 554 | ||
503 | 532 | public override void activate () { | 555 | public override void activate () { |
504 | 533 | // If app is already running, present the current window. | 556 | // If app is already running, present the current window. |
505 | 534 | if (get_windows () != null) { | 557 | if (get_windows () != null) { |
506 | @@ -582,41 +605,46 @@ | |||
507 | 582 | } | 605 | } |
508 | 583 | 606 | ||
509 | 584 | static const OptionEntry[] entries = { | 607 | static const OptionEntry[] entries = { |
512 | 585 | { "open-plug", 'o', 0, OptionArg.STRING, ref plug_to_open, N_("Open a plug"), "PLUG_NAME" }, | 608 | { "open-plug", 'o', 0, OptionArg.STRING, ref plug_to_open, N_("Open a plug"), "PLUG_NAME" }, |
513 | 586 | { null } | 609 | { null } |
514 | 587 | }; | 610 | }; |
515 | 588 | 611 | ||
516 | 589 | public static int main (string[] args) { | 612 | public static int main (string[] args) { |
517 | 590 | |||
518 | 591 | var logger = new Granite.Services.Logger (); | 613 | var logger = new Granite.Services.Logger (); |
520 | 592 | logger.initialize(APP_TITLE); | 614 | logger.initialize (APP_TITLE); |
521 | 593 | logger.DisplayLevel = Granite.Services.LogLevel.INFO; | 615 | logger.DisplayLevel = Granite.Services.LogLevel.INFO; |
526 | 594 | message(_(@"Welcome to $APP_TITLE")); | 616 | message (_(@"Welcome to $APP_TITLE")); |
527 | 595 | message(_(@"Version: $VERSION")); | 617 | message (_(@"Version: $VERSION")); |
528 | 596 | message(_("Report any issues/bugs you mind find to lp:switchboard")); | 618 | message (_("Report any issues/bugs you mind find to lp:switchboard")); |
529 | 597 | 619 | ||
530 | 598 | Gtk.init (ref args); | 620 | Gtk.init (ref args); |
535 | 599 | 621 | ||
536 | 600 | var context = new OptionContext(""); | 622 | var context = new OptionContext (""); |
537 | 601 | context.add_main_entries(entries, "switchboard "); | 623 | context.add_main_entries (entries, "switchboard "); |
538 | 602 | context.add_group(Gtk.get_option_group(true)); | 624 | context.add_group (Gtk.get_option_group (true)); |
539 | 625 | |||
540 | 603 | try { | 626 | try { |
544 | 604 | context.parse(ref args); | 627 | context.parse (ref args); |
545 | 605 | } catch(Error e) { warning (e.message); } | 628 | } catch(Error e) { |
546 | 606 | 629 | warning (e.message); | |
547 | 630 | } | ||
548 | 631 | |||
549 | 607 | // In the future, the plug_root_dir should be overridable by CLI flags. | 632 | // In the future, the plug_root_dir should be overridable by CLI flags. |
550 | 608 | var switchboard_app = new SwitchboardApp (); | 633 | var switchboard_app = new SwitchboardApp (); |
552 | 609 | 634 | ||
553 | 610 | GLib.Bus.own_name (BusType.SESSION, "org.elementary.switchboard", | 635 | GLib.Bus.own_name (BusType.SESSION, "org.elementary.switchboard", |
563 | 611 | BusNameOwnerFlags.NONE, | 636 | BusNameOwnerFlags.NONE, |
564 | 612 | (conn) => { | 637 | (conn) => { |
565 | 613 | try { | 638 | try { |
566 | 614 | conn.register_object("/org/elementary/switchboard", switchboard_app); | 639 | conn.register_object ("/org/elementary/switchboard", switchboard_app); |
567 | 615 | } catch (IOError e) { warning (e.message); } | 640 | } catch (IOError e) { |
568 | 616 | }, | 641 | warning (e.message); |
569 | 617 | () => {}, | 642 | } |
570 | 618 | () => {logger.notification(_("Switchboard already running. Exiting..")); Process.exit(1);}); | 643 | }, |
571 | 619 | 644 | ||
572 | 645 | () => {}, | ||
573 | 646 | () => { logger.notification (_("Switchboard already running. Exiting..")); Process.exit (1); }); | ||
574 | 647 | |||
575 | 620 | return switchboard_app.run (args); | 648 | return switchboard_app.run (args); |
576 | 621 | } | 649 | } |
577 | 622 | } | 650 | } |
Code style
Diff lines 244-245, 262, 265, 310, 445: Put the blocks of code in separate lines from the "try" and "catch" statements:
try {
//...
} catch (Error e) {
//...
}
Diff line 303: A space after "else if" and before the parenthesis.
Diff line 320: A space on the other side of the parenthesis :)
Diff line 380: A space before the opening parenthesis.
Diff line 450: A space after the opening curly brace.