Merge lp:~elementary-pantheon/switchboard-plug-security-privacy/clear-usage-popover into lp:~elementary-apps/switchboard-plug-security-privacy/trunk
- clear-usage-popover
- Merge into trunk
Proposed by
Danielle Foré
Status: | Merged |
---|---|
Approved by: | Danielle Foré |
Approved revision: | 294 |
Merged at revision: | 294 |
Proposed branch: | lp:~elementary-pantheon/switchboard-plug-security-privacy/clear-usage-popover |
Merge into: | lp:~elementary-apps/switchboard-plug-security-privacy/trunk |
Diff against target: |
426 lines (+195/-165) 3 files modified
src/CMakeLists.txt (+1/-0) src/Views/TrackPanel.vala (+2/-165) src/Widgets/ClearUsagePopover.vala (+192/-0) |
To merge this branch: | bzr merge lp:~elementary-pantheon/switchboard-plug-security-privacy/clear-usage-popover |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Hewitt | code, function | Approve | |
Review via email: mp+318318@code.launchpad.net |
Commit message
Move the ClearUsagePopover to its own class
Description of the change
To post a comment you must log in.
Revision history for this message
David Hewitt (davidmhewitt) wrote : | # |
review:
Approve
(code, function)
Revision history for this message
RabbitBot (rabbitbot-a) wrote : | # |
Attempt to merge into lp:switchboard-plug-security-privacy failed due to conflicts:
text conflict in src/CMakeLists.txt
- 294. By Danielle Foré
-
resolve merge conflicts
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/CMakeLists.txt' |
2 | --- src/CMakeLists.txt 2017-02-22 17:18:21 +0000 |
3 | +++ src/CMakeLists.txt 2017-02-26 17:34:41 +0000 |
4 | @@ -24,6 +24,7 @@ |
5 | |
6 | Widgets/AppChooser.vala |
7 | Widgets/AppRow.vala |
8 | + Widgets/ClearUsagePopover.vala |
9 | |
10 | ${CMAKE_CURRENT_BINARY_DIR}/config.vala |
11 | PACKAGES |
12 | |
13 | === modified file 'src/Views/TrackPanel.vala' |
14 | --- src/Views/TrackPanel.vala 2017-02-19 21:27:25 +0000 |
15 | +++ src/Views/TrackPanel.vala 2017-02-26 17:34:41 +0000 |
16 | @@ -21,11 +21,7 @@ |
17 | */ |
18 | |
19 | public class SecurityPrivacy.TrackPanel : Gtk.Grid { |
20 | - |
21 | - private Gtk.RecentManager recent; |
22 | - private List<Gtk.RecentInfo> items; |
23 | - |
24 | - private Gtk.Popover remove_popover; |
25 | + private Widgets.ClearUsagePopover remove_popover; |
26 | private Dialogs.AppChooser app_chooser; |
27 | private ApplicationBlacklist app_blacklist; |
28 | private PathBlacklist path_blacklist; |
29 | @@ -34,13 +30,6 @@ |
30 | private Gtk.Container description_frame; |
31 | private Gtk.Grid exclude_grid; |
32 | |
33 | - private Granite.Widgets.DatePicker to_datepicker; |
34 | - private Granite.Widgets.DatePicker from_datepicker; |
35 | - private Gtk.RadioButton all_time_radio; |
36 | - private Gtk.RadioButton from_radio; |
37 | - private Gtk.RadioButton past_hour_radio; |
38 | - private Gtk.RadioButton past_day_radio; |
39 | - private Gtk.RadioButton past_week_radio; |
40 | private Gtk.Switch record_switch; |
41 | |
42 | private enum Columns { |
43 | @@ -63,7 +52,6 @@ |
44 | app_blacklist = new ApplicationBlacklist (blacklist); |
45 | path_blacklist = new PathBlacklist (blacklist); |
46 | filetype_blacklist = new FileTypeBlacklist (blacklist); |
47 | - recent = new Gtk.RecentManager (); |
48 | |
49 | var privacy_settings = new GLib.Settings ("org.gnome.desktop.privacy"); |
50 | |
51 | @@ -96,8 +84,6 @@ |
52 | record_grid.add (record_switch); |
53 | record_grid.add (info_button); |
54 | |
55 | - /* Remove Popover */ |
56 | - |
57 | var clear_data = new Gtk.ToggleButton.with_label (_("Clear Usage Data…")); |
58 | clear_data.halign = Gtk.Align.END; |
59 | clear_data.notify["active"].connect (() => { |
60 | @@ -108,44 +94,7 @@ |
61 | } |
62 | }); |
63 | |
64 | - var clear_label = new Gtk.Label (_("Remove system-collected file and application usage data from:")); |
65 | - clear_label.halign = Gtk.Align.START; |
66 | - |
67 | - past_hour_radio = new Gtk.RadioButton.with_label (null, _("The past hour")); |
68 | - past_day_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("The past day")); |
69 | - past_week_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("The past week")); |
70 | - from_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("From:")); |
71 | - all_time_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("All time")); |
72 | - |
73 | - from_datepicker = new Granite.Widgets.DatePicker (); |
74 | - var to_label = new Gtk.Label (_("To:")); |
75 | - to_datepicker = new Granite.Widgets.DatePicker (); |
76 | - |
77 | - var clear_button = new Gtk.Button.with_label (_("Clear Data")); |
78 | - clear_button.halign = Gtk.Align.END; |
79 | - clear_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION); |
80 | - clear_button.clicked.connect (() => { |
81 | - on_clear_data (); |
82 | - }); |
83 | - |
84 | - var remove_popover_grid = new Gtk.Grid (); |
85 | - remove_popover_grid.margin = 12; |
86 | - remove_popover_grid.column_spacing = 12; |
87 | - remove_popover_grid.row_spacing = 6; |
88 | - |
89 | - remove_popover_grid.attach (clear_label, 0, 0, 4, 1); |
90 | - remove_popover_grid.attach (past_hour_radio, 0, 1, 4, 1); |
91 | - remove_popover_grid.attach (past_day_radio, 0, 2, 4, 1); |
92 | - remove_popover_grid.attach (past_week_radio, 0, 3, 4, 1); |
93 | - remove_popover_grid.attach (from_radio, 0, 4, 1, 1); |
94 | - remove_popover_grid.attach (from_datepicker, 1, 4, 1, 1); |
95 | - remove_popover_grid.attach (to_label, 2, 4, 1, 1); |
96 | - remove_popover_grid.attach (to_datepicker, 3, 4, 1, 1); |
97 | - remove_popover_grid.attach (all_time_radio, 0, 5, 4, 1); |
98 | - remove_popover_grid.attach (clear_button, 0, 6, 4, 1); |
99 | - |
100 | - remove_popover = new Gtk.Popover (clear_data); |
101 | - remove_popover.add (remove_popover_grid); |
102 | + remove_popover = new Widgets.ClearUsagePopover (clear_data); |
103 | remove_popover.closed.connect (() => { |
104 | clear_data.active = false; |
105 | }); |
106 | @@ -167,20 +116,6 @@ |
107 | record_switch.grab_focus (); |
108 | } |
109 | |
110 | - private async void delete_history (Zeitgeist.TimeRange tr) { |
111 | - var events = new GenericArray<Zeitgeist.Event> (); |
112 | - events.add (new Zeitgeist.Event ()); |
113 | - var zg_log = new Zeitgeist.Log (); |
114 | - try { |
115 | - uint32[] ids = yield zg_log.find_event_ids (tr, events, Zeitgeist.StorageState.ANY, 0, 0, null); |
116 | - Array<uint32> del_ids = new Array<uint32> (); |
117 | - del_ids.append_vals (ids, ids.length); |
118 | - yield zg_log.delete_events (del_ids, null); |
119 | - } catch (Error e) { |
120 | - critical (e.message); |
121 | - } |
122 | - } |
123 | - |
124 | private string get_operating_system_name () { |
125 | string system = _("Your system"); |
126 | try { |
127 | @@ -426,102 +361,4 @@ |
128 | NotColumns.IS_APP, false); |
129 | }); |
130 | } |
131 | - |
132 | - private void on_clear_data () { |
133 | - Zeitgeist.TimeRange tr; |
134 | - |
135 | - if (past_hour_radio.active == true) { |
136 | - int range = 360000;//60*60*1000; |
137 | - int64 end = Zeitgeist.Timestamp.from_now (); |
138 | - int64 start = end - range; |
139 | - tr = new Zeitgeist.TimeRange (start, end); |
140 | - delete_history.begin (tr); |
141 | - |
142 | - // Deletes files added in the last hour |
143 | - if (recent.size > 0) { |
144 | - items = recent.get_items (); |
145 | - |
146 | - try { |
147 | - foreach (var item in items) { |
148 | - if (item.get_added () >= start/1000) |
149 | - recent.remove_item (item.get_uri ()); |
150 | - } |
151 | - } catch (Error err) { |
152 | - critical (err.message); |
153 | - } |
154 | - } |
155 | - } else if (past_day_radio.active == true) { |
156 | - int range = 8640000;//24*60*60*1000; |
157 | - int64 end = Zeitgeist.Timestamp.from_now (); |
158 | - int64 start = end - range; |
159 | - tr = new Zeitgeist.TimeRange (start, end); |
160 | - delete_history.begin (tr); |
161 | - |
162 | - // Deletes files added in the last day |
163 | - if (recent.size > 0) { |
164 | - items = recent.get_items (); |
165 | - |
166 | - try { |
167 | - foreach (var item in items) { |
168 | - if (item.get_age () <= 1) |
169 | - recent.remove_item (item.get_uri ()); |
170 | - } |
171 | - } catch (Error err) { |
172 | - critical (err.message); |
173 | - } |
174 | - } |
175 | - } else if (past_week_radio.active == true) { |
176 | - int range = 60480000;//7*24*60*60*1000; |
177 | - int64 end = Zeitgeist.Timestamp.from_now (); |
178 | - int64 start = end - range; |
179 | - tr = new Zeitgeist.TimeRange (start, end); |
180 | - delete_history.begin (tr); |
181 | - |
182 | - // Deletes files added in the last week |
183 | - if (recent.size > 0) { |
184 | - items = recent.get_items (); |
185 | - |
186 | - try { |
187 | - foreach (var item in items) { |
188 | - if (item.get_age () <= 7) |
189 | - recent.remove_item (item.get_uri ()); |
190 | - } |
191 | - } catch (Error err) { |
192 | - critical (err.message); |
193 | - } |
194 | - } |
195 | - } else if (from_radio.active == true) { |
196 | - int64 start = from_datepicker.date.to_unix ()*1000; |
197 | - int64 end = to_datepicker.date.to_unix ()*1000; |
198 | - tr = new Zeitgeist.TimeRange (start, end); |
199 | - delete_history.begin (tr); |
200 | - |
201 | - // Deletes files added during the given period |
202 | - if (recent.size > 0) { |
203 | - items = recent.get_items (); |
204 | - |
205 | - try { |
206 | - foreach (var item in items) { |
207 | - if (item.get_added () >= start/1000 && item.get_added () <= end/1000) |
208 | - recent.remove_item (item.get_uri ()); |
209 | - } |
210 | - } catch (Error err) { |
211 | - critical (err.message); |
212 | - } |
213 | - } |
214 | - } else if (all_time_radio.active == true) { |
215 | - tr = new Zeitgeist.TimeRange.anytime (); |
216 | - delete_history.begin (tr); |
217 | - |
218 | - // Deletes all recent files |
219 | - if (recent.size > 0) { |
220 | - try { |
221 | - recent.purge_items (); |
222 | - } catch (Error err) { |
223 | - critical (err.message); |
224 | - } |
225 | - } |
226 | - } |
227 | - remove_popover.hide (); |
228 | - } |
229 | } |
230 | |
231 | === added file 'src/Widgets/ClearUsagePopover.vala' |
232 | --- src/Widgets/ClearUsagePopover.vala 1970-01-01 00:00:00 +0000 |
233 | +++ src/Widgets/ClearUsagePopover.vala 2017-02-26 17:34:41 +0000 |
234 | @@ -0,0 +1,192 @@ |
235 | +/*- |
236 | + * Copyright (c) 2014-2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy) |
237 | + * |
238 | + * This library is free software; you can redistribute it and/or |
239 | + * modify it under the terms of the GNU Library General Public |
240 | + * License as published by the Free Software Foundation; either |
241 | + * version 3 of the License, or (at your option) any later version. |
242 | + * |
243 | + * This library is distributed in the hope that it will be useful, |
244 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
245 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
246 | + * Library General Public License for more details. |
247 | + * |
248 | + * You should have received a copy of the GNU Library General Public |
249 | + * License along with this library; if not, write to the |
250 | + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
251 | + * Boston, MA 02111-1307, USA. |
252 | + * |
253 | + * Authored by: Corentin Noël <corentin@elementaryos.org> |
254 | + */ |
255 | + |
256 | +public class SecurityPrivacy.Widgets.ClearUsagePopover : Gtk.Popover { |
257 | + private Granite.Widgets.DatePicker to_datepicker; |
258 | + private Granite.Widgets.DatePicker from_datepicker; |
259 | + private Gtk.RadioButton all_time_radio; |
260 | + private Gtk.RadioButton from_radio; |
261 | + private Gtk.RadioButton past_hour_radio; |
262 | + private Gtk.RadioButton past_day_radio; |
263 | + private Gtk.RadioButton past_week_radio; |
264 | + private Gtk.RecentManager recent; |
265 | + |
266 | + private List<Gtk.RecentInfo> items; |
267 | + |
268 | + public ClearUsagePopover (Gtk.Widget? relative_to) { |
269 | + Object (relative_to: relative_to); |
270 | + } |
271 | + |
272 | + construct { |
273 | + recent = new Gtk.RecentManager (); |
274 | + |
275 | + var clear_label = new Gtk.Label (_("Remove system-collected file and application usage data from:")); |
276 | + clear_label.halign = Gtk.Align.START; |
277 | + |
278 | + past_hour_radio = new Gtk.RadioButton.with_label (null, _("The past hour")); |
279 | + past_day_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("The past day")); |
280 | + past_week_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("The past week")); |
281 | + from_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("From:")); |
282 | + all_time_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("All time")); |
283 | + |
284 | + from_datepicker = new Granite.Widgets.DatePicker (); |
285 | + var to_label = new Gtk.Label (_("To:")); |
286 | + to_datepicker = new Granite.Widgets.DatePicker (); |
287 | + |
288 | + var clear_button = new Gtk.Button.with_label (_("Clear Data")); |
289 | + clear_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION); |
290 | + clear_button.halign = Gtk.Align.END; |
291 | + |
292 | + var grid = new Gtk.Grid (); |
293 | + grid.margin = 12; |
294 | + grid.column_spacing = 12; |
295 | + grid.row_spacing = 6; |
296 | + grid.attach (clear_label, 0, 0, 4, 1); |
297 | + grid.attach (past_hour_radio, 0, 1, 4, 1); |
298 | + grid.attach (past_day_radio, 0, 2, 4, 1); |
299 | + grid.attach (past_week_radio, 0, 3, 4, 1); |
300 | + grid.attach (from_radio, 0, 4, 1, 1); |
301 | + grid.attach (from_datepicker, 1, 4, 1, 1); |
302 | + grid.attach (to_label, 2, 4, 1, 1); |
303 | + grid.attach (to_datepicker, 3, 4, 1, 1); |
304 | + grid.attach (all_time_radio, 0, 5, 4, 1); |
305 | + grid.attach (clear_button, 0, 6, 4, 1); |
306 | + |
307 | + add (grid); |
308 | + |
309 | + clear_button.clicked.connect (() => { |
310 | + on_clear_data (); |
311 | + }); |
312 | + } |
313 | + |
314 | + private async void delete_history (Zeitgeist.TimeRange tr) { |
315 | + var events = new GenericArray<Zeitgeist.Event> (); |
316 | + events.add (new Zeitgeist.Event ()); |
317 | + var zg_log = new Zeitgeist.Log (); |
318 | + try { |
319 | + uint32[] ids = yield zg_log.find_event_ids (tr, events, Zeitgeist.StorageState.ANY, 0, 0, null); |
320 | + Array<uint32> del_ids = new Array<uint32> (); |
321 | + del_ids.append_vals (ids, ids.length); |
322 | + yield zg_log.delete_events (del_ids, null); |
323 | + } catch (Error e) { |
324 | + critical (e.message); |
325 | + } |
326 | + } |
327 | + |
328 | + private void on_clear_data () { |
329 | + Zeitgeist.TimeRange tr; |
330 | + |
331 | + if (past_hour_radio.active == true) { |
332 | + int range = 360000;//60*60*1000; |
333 | + int64 end = Zeitgeist.Timestamp.from_now (); |
334 | + int64 start = end - range; |
335 | + tr = new Zeitgeist.TimeRange (start, end); |
336 | + delete_history.begin (tr); |
337 | + |
338 | + // Deletes files added in the last hour |
339 | + if (recent.size > 0) { |
340 | + items = recent.get_items (); |
341 | + |
342 | + try { |
343 | + foreach (var item in items) { |
344 | + if (item.get_added () >= start/1000) |
345 | + recent.remove_item (item.get_uri ()); |
346 | + } |
347 | + } catch (Error err) { |
348 | + critical (err.message); |
349 | + } |
350 | + } |
351 | + } else if (past_day_radio.active == true) { |
352 | + int range = 8640000;//24*60*60*1000; |
353 | + int64 end = Zeitgeist.Timestamp.from_now (); |
354 | + int64 start = end - range; |
355 | + tr = new Zeitgeist.TimeRange (start, end); |
356 | + delete_history.begin (tr); |
357 | + |
358 | + // Deletes files added in the last day |
359 | + if (recent.size > 0) { |
360 | + items = recent.get_items (); |
361 | + |
362 | + try { |
363 | + foreach (var item in items) { |
364 | + if (item.get_age () <= 1) |
365 | + recent.remove_item (item.get_uri ()); |
366 | + } |
367 | + } catch (Error err) { |
368 | + critical (err.message); |
369 | + } |
370 | + } |
371 | + } else if (past_week_radio.active == true) { |
372 | + int range = 60480000;//7*24*60*60*1000; |
373 | + int64 end = Zeitgeist.Timestamp.from_now (); |
374 | + int64 start = end - range; |
375 | + tr = new Zeitgeist.TimeRange (start, end); |
376 | + delete_history.begin (tr); |
377 | + |
378 | + // Deletes files added in the last week |
379 | + if (recent.size > 0) { |
380 | + items = recent.get_items (); |
381 | + |
382 | + try { |
383 | + foreach (var item in items) { |
384 | + if (item.get_age () <= 7) |
385 | + recent.remove_item (item.get_uri ()); |
386 | + } |
387 | + } catch (Error err) { |
388 | + critical (err.message); |
389 | + } |
390 | + } |
391 | + } else if (from_radio.active == true) { |
392 | + int64 start = from_datepicker.date.to_unix ()*1000; |
393 | + int64 end = to_datepicker.date.to_unix ()*1000; |
394 | + tr = new Zeitgeist.TimeRange (start, end); |
395 | + delete_history.begin (tr); |
396 | + |
397 | + // Deletes files added during the given period |
398 | + if (recent.size > 0) { |
399 | + items = recent.get_items (); |
400 | + |
401 | + try { |
402 | + foreach (var item in items) { |
403 | + if (item.get_added () >= start/1000 && item.get_added () <= end/1000) |
404 | + recent.remove_item (item.get_uri ()); |
405 | + } |
406 | + } catch (Error err) { |
407 | + critical (err.message); |
408 | + } |
409 | + } |
410 | + } else if (all_time_radio.active == true) { |
411 | + tr = new Zeitgeist.TimeRange.anytime (); |
412 | + delete_history.begin (tr); |
413 | + |
414 | + // Deletes all recent files |
415 | + if (recent.size > 0) { |
416 | + try { |
417 | + recent.purge_items (); |
418 | + } catch (Error err) { |
419 | + critical (err.message); |
420 | + } |
421 | + } |
422 | + } |
423 | + |
424 | + hide (); |
425 | + } |
426 | +} |
Cleans up TrackPanel.vala nicely and still works as intended.