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