Merge lp:~donadigo/switchboard-plug-parental-controls/update-plank-backend into lp:~elementary-pantheon/switchboard-plug-parental-controls/trunk
- update-plank-backend
- Merge into trunk
Proposed by
Adam Bieńkowski
Status: | Work in progress |
---|---|
Proposed branch: | lp:~donadigo/switchboard-plug-parental-controls/update-plank-backend |
Merge into: | lp:~elementary-pantheon/switchboard-plug-parental-controls/trunk |
Diff against target: |
407 lines (+135/-57) 6 files modified
src/Widgets/GeneralBox.vala (+17/-30) src/cli/Application.vala (+15/-18) src/daemon/CMakeLists.txt (+1/-0) src/daemon/PlankController.vala (+80/-0) src/daemon/SessionHandler.vala (+10/-3) src/shared/Vars.vala (+12/-6) |
To merge this branch: | bzr merge lp:~donadigo/switchboard-plug-parental-controls/update-plank-backend |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danielle Foré | Needs Fixing | ||
Review via email: mp+295960@code.launchpad.net |
Commit message
* Fix bug #1583221: "Update Plank settings handling".
Description of the change
Fixes bug #1583221: "Update Plank settings handling".
This is a rewrite of Plank backend which is controlling of whethever to lock the dock or not for current user.
To post a comment you must log in.
- 164. By Adam Bieńkowski
-
Remove unneded user variable
Unmerged revisions
- 164. By Adam Bieńkowski
-
Remove unneded user variable
- 163. By Adam Bieńkowski
-
Rewrite plank locking; organize constant variables
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/Widgets/GeneralBox.vala' |
2 | --- src/Widgets/GeneralBox.vala 2016-05-19 18:11:33 +0000 |
3 | +++ src/Widgets/GeneralBox.vala 2016-05-27 14:00:40 +0000 |
4 | @@ -22,7 +22,6 @@ |
5 | |
6 | namespace PC.Widgets { |
7 | public class GeneralBox : Gtk.Grid { |
8 | - private string plank_conf_file_path = ""; |
9 | private Act.User user; |
10 | private Gtk.CheckButton dock_btn; |
11 | private Gtk.CheckButton print_btn; |
12 | @@ -36,10 +35,8 @@ |
13 | |
14 | public GeneralBox (Act.User user) { |
15 | this.user = user; |
16 | - plank_conf_file_path = Path.build_filename (user.get_home_dir (), Vars.PLANK_CONF_DIR); |
17 | |
18 | dock_btn.notify["active"].connect (on_dock_btn_activate); |
19 | - |
20 | print_btn.notify["active"].connect (on_print_conf_activate); |
21 | |
22 | limit_switch.notify["active"].connect (on_limit_switch_changed); |
23 | @@ -51,7 +48,6 @@ |
24 | weekday_box.changed.connect (update_pam); |
25 | weekend_box.changed.connect (update_pam); |
26 | |
27 | - monitor_updates (); |
28 | update (); |
29 | load_restrictions (); |
30 | } |
31 | @@ -78,9 +74,9 @@ |
32 | |
33 | limit_combobox = new Gtk.ComboBoxText (); |
34 | limit_combobox.hexpand = true; |
35 | - limit_combobox.append (Vars.ALL_ID, _("On weekdays and weekends")); |
36 | - limit_combobox.append (Vars.WEEKDAYS_ID, _("Only on weekdays")); |
37 | - limit_combobox.append (Vars.WEEKENDS_ID, _("Only on weekends")); |
38 | + limit_combobox.append (Vars.PAM_ALL_ID, _("On weekdays and weekends")); |
39 | + limit_combobox.append (Vars.PAM_WEEKDAYS_ID, _("Only on weekdays")); |
40 | + limit_combobox.append (Vars.PAM_WEEKENDS_ID, _("Only on weekends")); |
41 | limit_combobox.active_id = "all"; |
42 | |
43 | frame = new Gtk.Frame (null); |
44 | @@ -130,7 +126,7 @@ |
45 | |
46 | limit_combobox.active_id = restrict.day_id; |
47 | switch (restrict.day_id) { |
48 | - case Vars.ALL_ID: |
49 | + case Vars.PAM_ALL_ID: |
50 | string from_weekday = restrict.weekday_hours.split ("-")[0]; |
51 | string to_weekday = restrict.weekday_hours.split ("-")[1]; |
52 | string from_weekend = restrict.weekend_hours.split ("-")[0]; |
53 | @@ -142,11 +138,11 @@ |
54 | weekend_box.set_from (from_weekend); |
55 | weekend_box.set_to (to_weekend); |
56 | break; |
57 | - case Vars.WEEKDAYS_ID: |
58 | + case Vars.PAM_WEEKDAYS_ID: |
59 | weekday_box.set_from (restrict.from); |
60 | weekday_box.set_to (restrict.to); |
61 | break; |
62 | - case Vars.WEEKENDS_ID: |
63 | + case Vars.PAM_WEEKENDS_ID: |
64 | weekend_box.set_from (restrict.from); |
65 | weekend_box.set_to (restrict.to); |
66 | break; |
67 | @@ -161,14 +157,14 @@ |
68 | string restrict = ""; |
69 | string id = limit_combobox.get_active_id (); |
70 | switch (id) { |
71 | - case Vars.ALL_ID: |
72 | + case Vars.PAM_ALL_ID: |
73 | restrict = generate_pam_conf_restriction (id, weekday_box.get_from (), weekday_box.get_to ()); |
74 | restrict += "|" + weekend_box.get_from () + "-" + weekend_box.get_to (); |
75 | break; |
76 | - case Vars.WEEKDAYS_ID: |
77 | + case Vars.PAM_WEEKDAYS_ID: |
78 | restrict = generate_pam_conf_restriction (id, weekday_box.get_from (), weekday_box.get_to ()); |
79 | break; |
80 | - case Vars.WEEKENDS_ID: |
81 | + case Vars.PAM_WEEKENDS_ID: |
82 | restrict = generate_pam_conf_restriction (id, weekend_box.get_from (), weekend_box.get_to ()); |
83 | break; |
84 | } |
85 | @@ -180,13 +176,13 @@ |
86 | string retval = "*;*;"; |
87 | string days = ""; |
88 | switch (id) { |
89 | - case Vars.ALL_ID: |
90 | + case Vars.PAM_ALL_ID: |
91 | days = "Al"; |
92 | break; |
93 | - case Vars.WEEKDAYS_ID: |
94 | + case Vars.PAM_WEEKDAYS_ID: |
95 | days = "Wk"; |
96 | break; |
97 | - case Vars.WEEKENDS_ID: |
98 | + case Vars.PAM_WEEKENDS_ID: |
99 | days = "Wd"; |
100 | break; |
101 | } |
102 | @@ -195,20 +191,11 @@ |
103 | return retval; |
104 | } |
105 | |
106 | - private void monitor_updates () { |
107 | - try { |
108 | - var monitor = File.new_for_path (plank_conf_file_path).monitor_file (FileMonitorFlags.NONE); |
109 | - monitor.changed.connect (update); |
110 | - } catch (IOError e) { |
111 | - warning ("%s\n", e.message); |
112 | - } |
113 | - } |
114 | - |
115 | private void update () { |
116 | var key_file = new KeyFile (); |
117 | try { |
118 | - key_file.load_from_file (plank_conf_file_path, KeyFileFlags.NONE); |
119 | - dock_btn.active = !key_file.get_boolean (Vars.PLANK_CONF_GROUP, Vars.PLANK_CONF_LOCK_ITEMS_KEY); |
120 | + key_file.load_from_file (Utils.build_daemon_conf_path (user), KeyFileFlags.NONE); |
121 | + dock_btn.active = !key_file.get_boolean (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_LOCK_PLANK_ITEMS); |
122 | } catch (FileError e) { |
123 | dock_btn.active = true; |
124 | warning ("%s\n", e.message); |
125 | @@ -272,15 +259,15 @@ |
126 | |
127 | private void on_limit_combobox_changed () { |
128 | switch (limit_combobox.get_active_id ()) { |
129 | - case Vars.ALL_ID: |
130 | + case Vars.PAM_ALL_ID: |
131 | weekday_box.sensitive = true; |
132 | weekend_box.sensitive = true; |
133 | break; |
134 | - case Vars.WEEKDAYS_ID: |
135 | + case Vars.PAM_WEEKDAYS_ID: |
136 | weekday_box.sensitive = true; |
137 | weekend_box.sensitive = false; |
138 | break; |
139 | - case Vars.WEEKENDS_ID: |
140 | + case Vars.PAM_WEEKENDS_ID: |
141 | weekday_box.sensitive = false; |
142 | weekend_box.sensitive = true; |
143 | break; |
144 | |
145 | === modified file 'src/cli/Application.vala' |
146 | --- src/cli/Application.vala 2016-05-18 15:29:00 +0000 |
147 | +++ src/cli/Application.vala 2016-05-27 14:00:40 +0000 |
148 | @@ -23,7 +23,6 @@ |
149 | namespace PC.Cli { |
150 | public class App : Application { |
151 | private const string TIME_CONF_FILE = "/etc/security/time.conf"; |
152 | - private string plank_conf_file_path = ""; |
153 | |
154 | public App () { |
155 | Object (flags: ApplicationFlags.HANDLES_COMMAND_LINE); |
156 | @@ -160,24 +159,22 @@ |
157 | } |
158 | |
159 | private void lock_dock_for_user (string user, bool lock) { |
160 | - plank_conf_file_path = Path.build_filename (Utils.get_usermanager ().get_user (user).get_home_dir (), Vars.PLANK_CONF_DIR); |
161 | - if (plank_conf_file_path != "" && File.new_for_path (plank_conf_file_path).query_exists ()) { |
162 | - var key_file = new KeyFile (); |
163 | - try { |
164 | - key_file.load_from_file (plank_conf_file_path, KeyFileFlags.KEEP_COMMENTS | KeyFileFlags.KEEP_TRANSLATIONS); |
165 | - } catch (KeyFileError e) { |
166 | - warning ("%s\n", e.message); |
167 | - } catch (FileError e) { |
168 | - warning ("%s\n", e.message); |
169 | - } |
170 | - |
171 | - key_file.set_boolean (Vars.PLANK_CONF_GROUP, Vars.PLANK_CONF_LOCK_ITEMS_KEY, lock); |
172 | + string path = Utils.build_daemon_conf_path (Utils.get_usermanager ().get_user (user)); |
173 | + var key_file = new KeyFile (); |
174 | + try { |
175 | + key_file.load_from_file (path, KeyFileFlags.KEEP_COMMENTS | KeyFileFlags.KEEP_TRANSLATIONS); |
176 | + } catch (KeyFileError e) { |
177 | + warning ("%s\n", e.message); |
178 | + } catch (FileError e) { |
179 | + warning ("%s\n", e.message); |
180 | + } |
181 | + |
182 | + key_file.set_boolean (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_LOCK_PLANK_ITEMS, lock); |
183 | |
184 | - try { |
185 | - key_file.save_to_file (plank_conf_file_path); |
186 | - } catch (FileError e) { |
187 | - warning ("%s\n", e.message); |
188 | - } |
189 | + try { |
190 | + key_file.save_to_file (path); |
191 | + } catch (FileError e) { |
192 | + warning ("%s\n", e.message); |
193 | } |
194 | } |
195 | |
196 | |
197 | === modified file 'src/daemon/CMakeLists.txt' |
198 | --- src/daemon/CMakeLists.txt 2016-03-06 11:20:50 +0000 |
199 | +++ src/daemon/CMakeLists.txt 2016-05-27 14:00:40 +0000 |
200 | @@ -14,6 +14,7 @@ |
201 | IptablesHelper.vala |
202 | SessionManager.vala |
203 | SessionHandler.vala |
204 | + PlankController.vala |
205 | Interfaces.vala |
206 | Server.vala |
207 | ${CMAKE_SOURCE_DIR}/src/shared/Vars.vala |
208 | |
209 | === added file 'src/daemon/PlankController.vala' |
210 | --- src/daemon/PlankController.vala 1970-01-01 00:00:00 +0000 |
211 | +++ src/daemon/PlankController.vala 2016-05-27 14:00:40 +0000 |
212 | @@ -0,0 +1,80 @@ |
213 | +// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
214 | +/*- |
215 | + * Copyright (c) 2016 Adam Bieńkowski (https://launchpad.net/switchboard-plug-parental-controls) |
216 | + * |
217 | + * This library is free software; you can redistribute it and/or |
218 | + * modify it under the terms of the GNU Library General Public |
219 | + * License as published by the Free Software Foundation; either |
220 | + * version 3 of the License, or (at your option) any later version. |
221 | + * |
222 | + * This library is distributed in the hope that it will be useful, |
223 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
224 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
225 | + * Library General Public License for more details. |
226 | + * |
227 | + * You should have received a copy of the GNU Library General Public |
228 | + * License along with this library; if not, write to the |
229 | + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
230 | + * Boston, MA 02111-1307, USA. |
231 | + * |
232 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
233 | + */ |
234 | + |
235 | +namespace PC.Daemon { |
236 | + public class PlankController : Object { |
237 | + private bool lock_dock; |
238 | + private HashTable<ulong, Settings> settings_table; |
239 | + |
240 | + public PlankController (bool _lock_dock) { |
241 | + lock_dock = _lock_dock; |
242 | + settings_table = new HashTable<ulong, Settings> (null, null); |
243 | + } |
244 | + |
245 | + public void start () { |
246 | + if (!lock_dock) { |
247 | + return; |
248 | + } |
249 | + |
250 | + string[]? docks = get_docks (); |
251 | + |
252 | + var schema = SettingsSchemaSource.get_default ().lookup (Vars.PLANK_SETTINGS_SCHEMA_ID, true); |
253 | + if (schema == null || docks == null) { |
254 | + return; |
255 | + } |
256 | + |
257 | + foreach (string dock in docks) { |
258 | + var dock_settings = new Settings.full (schema, null, Vars.PLANK_SETTINGS_PATH.printf (dock)); |
259 | + dock_settings.set_boolean (Vars.PLANK_SETTINGS_LOCK_ITEMS_KEY, lock_dock); |
260 | + settings_table.insert (dock_settings.changed.connect (settings_changed), dock_settings); |
261 | + } |
262 | + |
263 | + } |
264 | + |
265 | + public void stop () { |
266 | + if (!lock_dock || settings_table.length == 0) { |
267 | + return; |
268 | + } |
269 | + |
270 | + settings_table.foreach ((handler_id, settings) => { |
271 | + settings.disconnect (handler_id); |
272 | + settings.reset (Vars.PLANK_SETTINGS_LOCK_ITEMS_KEY); |
273 | + }); |
274 | + } |
275 | + |
276 | + private void settings_changed (Settings dock_settings, string key) { |
277 | + if (key == Vars.PLANK_SETTINGS_LOCK_ITEMS_KEY |
278 | + && dock_settings.get_boolean (Vars.PLANK_SETTINGS_LOCK_ITEMS_KEY) != lock_dock) { |
279 | + dock_settings.set_boolean (Vars.PLANK_SETTINGS_LOCK_ITEMS_KEY, lock_dock); |
280 | + } |
281 | + } |
282 | + |
283 | + private string[]? get_docks () { |
284 | + var plank_settings = new Settings ("net.launchpad.plank"); |
285 | + if (plank_settings != null) { |
286 | + return plank_settings.get_strv (Vars.PLANK_SETTINGS_ENABLED_DOCKS_KEY); |
287 | + } |
288 | + |
289 | + return null; |
290 | + } |
291 | + } |
292 | +} |
293 | \ No newline at end of file |
294 | |
295 | === modified file 'src/daemon/SessionHandler.vala' |
296 | --- src/daemon/SessionHandler.vala 2016-05-18 14:52:41 +0000 |
297 | +++ src/daemon/SessionHandler.vala 2016-05-27 14:00:40 +0000 |
298 | @@ -27,6 +27,7 @@ |
299 | |
300 | public Core core; |
301 | public IptablesHelper iptables_helper; |
302 | + public PlankController plank_controller; |
303 | |
304 | private ISession session; |
305 | private Server server; |
306 | @@ -49,13 +50,16 @@ |
307 | } |
308 | |
309 | string[] block_urls = {}; |
310 | + bool lock_dock = false; |
311 | try { |
312 | block_urls = core.key_file.get_string_list (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_BLOCK_URLS); |
313 | + lock_dock = core.key_file.get_boolean (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_LOCK_PLANK_ITEMS); |
314 | } catch (KeyFileError e) { |
315 | warning ("%s\n", e.message); |
316 | } |
317 | |
318 | iptables_helper = new IptablesHelper (block_urls); |
319 | + plank_controller = new PlankController (lock_dock); |
320 | } |
321 | |
322 | public void start () { |
323 | @@ -71,6 +75,8 @@ |
324 | iptables_helper.add_rules (); |
325 | } |
326 | |
327 | + plank_controller.start (); |
328 | + |
329 | var restricts = PAMControl.get_all_restrictions (); |
330 | foreach (var restrict in restricts) { |
331 | if (restrict.user == Utils.get_current_user ().get_user_name ()) { |
332 | @@ -81,7 +87,7 @@ |
333 | } |
334 | |
335 | switch (restrict.day_id) { |
336 | - case Vars.WEEKDAYS_ID: |
337 | + case Vars.PAM_WEEKDAYS_ID: |
338 | if (current_date.get_day_of_week () < 6) { |
339 | int estimated_time = int.parse (restrict.to); |
340 | var span = get_difference_span (estimated_time, current_date); |
341 | @@ -89,7 +95,7 @@ |
342 | } |
343 | |
344 | break; |
345 | - case Vars.WEEKENDS_ID: |
346 | + case Vars.PAM_WEEKENDS_ID: |
347 | if (current_date.get_day_of_week () >= 6) { |
348 | int estimated_time = int.parse (restrict.to); |
349 | var span = get_difference_span (estimated_time, current_date); |
350 | @@ -97,7 +103,7 @@ |
351 | } |
352 | |
353 | break; |
354 | - case Vars.ALL_ID: |
355 | + case Vars.PAM_ALL_ID: |
356 | int estimated_time = 2400; |
357 | if (current_date.get_day_of_week () < 6) { |
358 | estimated_time = int.parse (restrict.weekday_hours.split ("-")[1]); |
359 | @@ -124,6 +130,7 @@ |
360 | public void stop () { |
361 | core.stop (); |
362 | iptables_helper.reset (); |
363 | + plank_controller.stop (); |
364 | } |
365 | |
366 | private TimeSpan get_difference_span (int estimated_time, DateTime current_date) { |
367 | |
368 | === modified file 'src/shared/Vars.vala' |
369 | --- src/shared/Vars.vala 2016-05-20 21:19:09 +0000 |
370 | +++ src/shared/Vars.vala 2016-05-27 14:00:40 +0000 |
371 | @@ -24,12 +24,16 @@ |
372 | public const string LOGIN_IFACE = "org.freedesktop.login1"; |
373 | public const string LOGIN_OBJECT_PATH = "/org/freedesktop/login1"; |
374 | public const string DBUS_PROPERTIES_IFACE = "org.freedesktop.DBus.Properties"; |
375 | + |
376 | public const string PARENTAL_CONTROLS_IFACE = "org.pantheon.ParentalControls"; |
377 | public const string PARENTAL_CONTROLS_OBJECT_PATH = "/org/pantheon/ParentalControls"; |
378 | public const string PARENTAL_CONTROLS_ACTION_ID = "org.pantheon.switchboard.parental-controls.administration"; |
379 | - public const string PLANK_CONF_DIR = "/.config/plank/dock1/settings"; |
380 | - public const string PLANK_CONF_GROUP = "PlankDockPreferences"; |
381 | - public const string PLANK_CONF_LOCK_ITEMS_KEY = "LockItems"; |
382 | + |
383 | + public const string PLANK_SETTINGS_SCHEMA_ID = "net.launchpad.plank.dock.settings"; |
384 | + public const string PLANK_SETTINGS_PATH = "/net/launchpad/plank/docks/%s/"; |
385 | + public const string PLANK_SETTINGS_LOCK_ITEMS_KEY = "lock-items"; |
386 | + public const string PLANK_SETTINGS_ENABLED_DOCKS_KEY = "enabled-docks"; |
387 | + |
388 | public const string DAEMON_CONF_DIR = "/.config/pantheon-parental-controls-daemon.conf"; |
389 | public const string[] DAEMON_IGNORED_USERS = { "lightdm" }; |
390 | public const string DAEMON_GROUP = "PCDaemon"; |
391 | @@ -37,10 +41,12 @@ |
392 | public const string DAEMON_KEY_TARGETS = "Targets"; |
393 | public const string DAEMON_KEY_ADMIN = "Admin"; |
394 | public const string DAEMON_KEY_BLOCK_URLS = "BlockUrls"; |
395 | + public const string DAEMON_KEY_LOCK_PLANK_ITEMS = "LockPlankItems"; |
396 | + |
397 | public const string PAM_CONF_START = "## PANTHEON_PARENTAL_CONTROLS_START"; |
398 | public const string PAM_CONF_END = "## PANTHEON_PARENTAL_CONTROLS_END"; |
399 | public const string PAM_CONF_REGEX = PAM_CONF_START + "|" + PAM_CONF_END; |
400 | - public const string ALL_ID = "all"; |
401 | - public const string WEEKDAYS_ID = "weekdays"; |
402 | - public const string WEEKENDS_ID = "weekends"; |
403 | + public const string PAM_ALL_ID = "all"; |
404 | + public const string PAM_WEEKDAYS_ID = "weekdays"; |
405 | + public const string PAM_WEEKENDS_ID = "weekends"; |
406 | } |
407 | \ No newline at end of file |
I can't confirm that this locks the dock for another user. I can confirm that the daemon is running because website blocking is working