Merge lp:~voldyman/switchboard-plug-about/reset-settings into lp:~elementary-apps/switchboard-plug-about/trunk

Proposed by Akshay Shekher
Status: Merged
Approved by: Danielle Foré
Approved revision: 301
Merged at revision: 296
Proposed branch: lp:~voldyman/switchboard-plug-about/reset-settings
Merge into: lp:~elementary-apps/switchboard-plug-about/trunk
Diff against target: 242 lines (+133/-17)
1 file modified
src/Plug.vala (+133/-17)
To merge this branch: bzr merge lp:~voldyman/switchboard-plug-about/reset-settings
Reviewer Review Type Date Requested Status
Cody Garver (community) Needs Fixing
Danielle Foré Needs Fixing
Cameron Norman (community) Needs Fixing
Review via email: mp+256993@code.launchpad.net

Commit message

Adds the ability to reset dconf keys org.gnome.desktop and org.pantheon.desktop

Description of the change

Adds the ability to reset dconf keys org.gnome.desktop and org.pantheon.desktop

To post a comment you must log in.
Revision history for this message
Cameron Norman (cameronnemo) wrote :

Some of the style fixes, specifically the closure bits, seem a bit off. Also see inline comments about the wording of the warning message.

review: Needs Fixing
298. By Akshay Shekher

Fixed indentations and comments

299. By Akshay Shekher

Improved the warning dialog

Revision history for this message
Danielle Foré (danrabbit) wrote :

* "Restore to default settings" -> "Restore Default Settings" and remove destructive action class

To fix dialog margins and padding:

    layout.set_column_spacing (12);
    layout.set_margin_right (6);
    layout.set_margin_bottom (18);
    layout.set_margin_left (6);

    dialog.border_width = 6;

review: Needs Fixing
300. By Akshay Shekher

Updated dialog box appearance

Revision history for this message
Cody Garver (codygarver) wrote :

Restore Default Dettings

review: Needs Fixing
301. By Akshay Shekher

Fixed typo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Plug.vala'
2--- src/Plug.vala 2015-02-27 00:39:09 +0000
3+++ src/Plug.vala 2015-04-22 19:57:06 +0000
4@@ -1,5 +1,5 @@
5 //
6-// Copyright (C) 2012 Ivo Nunes
7+// Copyright (C) 2015 Ivo Nunes, Akshay Shekher
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11@@ -28,8 +28,8 @@
12 private string graphics;
13 private string hdd;
14 private Gtk.Label based_off;
15-
16-
17+
18+
19 private string is_ubuntu;
20 private string ubuntu_version;
21 private string ubuntu_codename;
22@@ -42,7 +42,7 @@
23 description: _("View System Information"),
24 icon: "help-info");
25 }
26-
27+
28 public override Gtk.Widget get_widget () {
29 if (main_grid == null) {
30 setup_info ();
31@@ -50,19 +50,19 @@
32 }
33 return main_grid;
34 }
35-
36+
37 public override void shown () {
38-
39+
40 }
41-
42+
43 public override void hidden () {
44-
45+
46 }
47-
48+
49 public override void search_callback (string location) {
50-
51+
52 }
53-
54+
55 // 'search' returns results like ("Keyboard → Behavior → Duration", "keyboard<sep>behavior")
56 public override async Gee.TreeMap<string, string> search (string search) {
57 return new Gee.TreeMap<string, string> (null, null);
58@@ -93,7 +93,7 @@
59 private void setup_info () {
60
61 // Operating System
62-
63+
64 File file = File.new_for_path("/etc/lsb-release");
65 try {
66 var dis = new DataInputStream (file.read ());
67@@ -118,7 +118,7 @@
68 version = "0.3";
69 codename = "Freya";
70 }
71-
72+
73 file = File.new_for_path("/etc/upstream-release/lsb-release");
74 try {
75 var dis = new DataInputStream (file.read ());
76@@ -150,7 +150,7 @@
77 string line;
78 // Read lines until end of file (null) is reached
79 while ((line = dis.read_line (null)) != null) {
80- if (line.has_prefix("Bugs:")) {
81+ if (line.has_prefix("Bugs:")) {
82 bugtracker_url = line.replace ("Bugs: ", "");
83 }
84 }
85@@ -232,7 +232,7 @@
86 }
87
88 // Hard Drive
89-
90+
91 var file_root = GLib.File.new_for_path ("/");
92 try {
93 var info = file_root.query_filesystem_info (GLib.FileAttribute.FILESYSTEM_SIZE, null);
94@@ -276,7 +276,7 @@
95 title.get_style_context ().add_class ("h2");
96 title.set_alignment (0, 0);
97 title.set_selectable (true);
98-
99+
100 if (is_ubuntu != null) {
101 based_off = new Gtk.Label (_("Built on %s %s").printf (is_ubuntu, ubuntu_version));
102 based_off.set_alignment (0, 0);
103@@ -398,15 +398,20 @@
104 }
105 });
106
107+ // Restore settings button
108+ var settings_restore_button = new Gtk.Button.with_label (_("Restore Default Settings"));
109+ settings_restore_button.clicked.connect (settings_restore_clicked);
110+
111 // Create a box for the buttons
112 var button_box = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
113 button_box.spacing = 6;
114 button_box.pack_start (help_button, false, false, 0);
115 button_box.set_child_non_homogeneous (help_button, true);
116+ button_box.pack_end (settings_restore_button, false, false, 0);
117 button_box.pack_end (translate_button, false, false, 0);
118 button_box.pack_end (bug_button, false, false, 0);
119 button_box.pack_end (update_button, false, false, 0);
120-
121+
122 // Fit everything in a box
123 var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 5);
124 box.pack_start (elementary_box, false, false, 24);
125@@ -445,6 +450,117 @@
126 return result;
127 }
128
129+private void reset_all_keys (GLib.Settings settings) {
130+ var keys = settings.list_keys ();
131+ foreach (var key in keys) {
132+ settings.reset (key);
133+ }
134+}
135+
136+private string[] get_pantheon_schemas () {
137+ string[] schemas = {};
138+ string[] pantheon_schemas = {};
139+ string[] prefixes = { "org.pantheon.desktop", "org.gnome.desktop" };
140+
141+ var sss = SettingsSchemaSource.get_default ();
142+
143+ sss.list_schemas (true, out schemas, null);
144+
145+ foreach (var schema in schemas) {
146+ foreach (var prefix in prefixes) {
147+ if (schema.has_prefix (prefix)) {
148+ pantheon_schemas += schema;
149+ }
150+ }
151+ }
152+ return pantheon_schemas;
153+}
154+
155+private void reset_recursively (string schema) {
156+ var settings = new GLib.Settings (schema);
157+ // change into delay mode
158+ // so changes take place when apply () is called
159+ settings.delay ();
160+
161+ reset_all_keys (settings);
162+
163+ var children = settings.list_children ();
164+ foreach (var child in children) {
165+ var child_settings = settings.get_child (child);
166+
167+ reset_all_keys (child_settings);
168+ }
169+ settings.apply ();
170+ GLib.Settings.sync ();
171+}
172+
173+/**
174+ * returns true to continue, false to cancel
175+ */
176+private bool confirm_restore_action () {
177+ var dialog = new Gtk.Dialog ();
178+
179+ Gtk.Box box = dialog.get_content_area () as Gtk.Box;
180+ var layout = new Gtk.Grid ();
181+ var text = new Gtk.Label ("");
182+
183+ text.set_markup ("<span weight='bold' size='larger'>" +
184+ _("System settings will be restored to the factory defaults") + "</span>\n\n"+
185+ _("All system settings and data will be reset to the default values.") + "\n" +
186+ _("Personal data, such as music and pictures, will be uneffected."));
187+
188+ var image = new Gtk.Image.from_icon_name ("dialog-warning",
189+ Gtk.IconSize.DIALOG);
190+ image.yalign = 0;
191+ image.show ();
192+
193+ layout.set_column_spacing (12);
194+ layout.set_margin_right (6);
195+ layout.set_margin_bottom (18);
196+ layout.set_margin_left (6);
197+
198+ layout.add (image);
199+ layout.add (text);
200+
201+ box.pack_start (layout);
202+
203+ var continue_button = new Gtk.Button.with_label (_("Restore Settings"));
204+ continue_button.get_style_context ().add_class ("destructive-action");
205+
206+ var cancel_button = new Gtk.Button.with_label (_("Cancel"));
207+ continue_button.show ();
208+ cancel_button.show ();
209+
210+ dialog.border_width = 6;
211+ dialog.deletable = false;
212+ dialog.add_action_widget (cancel_button, 0);
213+ dialog.add_action_widget (continue_button, 1);
214+
215+ dialog.show_all ();
216+ var result = dialog.run ();
217+ dialog.destroy ();
218+
219+ if (result == 1) {
220+ // continue was clicked
221+ return true;
222+ } else {
223+ // cancel was clicked
224+ return false;
225+ }
226+}
227+
228+private void settings_restore_clicked () {
229+ var should_display = confirm_restore_action ();
230+
231+ if (should_display) {
232+ var all_schemas = get_pantheon_schemas ();
233+
234+ foreach (var schema in all_schemas) {
235+ reset_recursively (schema);
236+ }
237+ }
238+}
239+
240 public Switchboard.Plug get_plug (Module module) {
241 debug ("Activating About plug");
242 var plug = new About.Plug ();

Subscribers

People subscribed via source and target branches

to all changes: