Merge lp:~jeremywootten/pantheon-files/fix-1631982-run-as-admin-warning into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Work in progress
Proposed branch: lp:~jeremywootten/pantheon-files/fix-1631982-run-as-admin-warning
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 325 lines (+134/-34)
4 files modified
data/pantheon-files-pkexec.cmake (+1/-1)
src/Application.vala (+47/-12)
src/View/Widgets/TopMenu.vala (+5/-1)
src/View/Window.vala (+81/-20)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-1631982-run-as-admin-warning
Reviewer Review Type Date Requested Status
Dieter Debast (community) Needs Fixing
Danielle Foré ux Pending
Zisu Andrei Pending
Review via email: mp+313758@code.launchpad.net

This proposal supersedes a proposal from 2016-10-16.

Commit message

When running as admin, show info screen and change headerbar color

Description of the change

Show warning info bar when running as administrator.
Remove "as Administrator" from tab label.

The exact text of the warning to be decided.

To post a comment you must log in.
Revision history for this message
Zisu Andrei (matzipan) wrote : Posted in a previous version of this proposal

Linked 3 more relevant issues. Low hanging fruit, I think.

Revision history for this message
Jeremy Wootten (jeremywootten) wrote : Posted in a previous version of this proposal

Initial attempt at addressing bugs 1006000 and 1353974. Needs input from UX team

Revision history for this message
Zisu Andrei (matzipan) wrote : Posted in a previous version of this proposal

The yellow sidebar is different enough. I was thinking we could just do with a darker gray.

The infoscreen however, looks a bit out of place. Perhaps just a simple confirmation dialog with a Granite.AlertView.

I don't know what it's called, but I can describe the behavior. You know when you have a popover/dialog which opens up above your main window and it turns your main window insensitive until you interact with the dialog? Is that possible with Gtk?

review: Needs Fixing
Revision history for this message
Zisu Andrei (matzipan) wrote : Posted in a previous version of this proposal

Looking good. Just tiny comment about the "WARNING" label inline.

review: Needs Fixing
Revision history for this message
Jeremy Wootten (jeremywootten) wrote : Posted in a previous version of this proposal

Fixed tab label string.

Revision history for this message
Danielle Foré (danrabbit) wrote : Posted in a previous version of this proposal

lgtm :)

review: Approve (ux)
2363. By Jeremy Wootten

Merge trunk to r2445

2364. By Jeremy Wootten

Fix regression in sidebar sensitivity on tab change

2365. By Jeremy Wootten

Merge changes from parent

Revision history for this message
Dieter Debast (ddieter) wrote :

I left some diff comments. Please correct me if I'm wrong.

review: Needs Fixing
2366. By Jeremy Wootten

Merge trunk to r2575 and resolve conflicts

2367. By Jeremy Wootten

Use empty array rather than null for absent commandline parameters

2368. By Jeremy Wootten

Fix indentation

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

Dieter: Thanks for the review. The reason a local variable is assigned to the Files[] parameter in a couple of places is so that it can be used in the following closure. However, I have changed the code a little so that an empty array is used when there are no commandline parameters as this feels better than using a null and fixes conflicting types.

I have also fixed the indentation and updated the branch so that it does not conflict with current trunk.

There seems to be a problem using commandline parameters with pantheon-files-pkexec anyway - they are not being passed to the application or are ignored at some point. I need to fix this as it does not occur in trunk. Putting back to "In progress" for now.

Unmerged revisions

2368. By Jeremy Wootten

Fix indentation

2367. By Jeremy Wootten

Use empty array rather than null for absent commandline parameters

2366. By Jeremy Wootten

Merge trunk to r2575 and resolve conflicts

2365. By Jeremy Wootten

Merge changes from parent

2364. By Jeremy Wootten

Fix regression in sidebar sensitivity on tab change

2363. By Jeremy Wootten

Merge trunk to r2445

2362. By Jeremy Wootten

Hide sidebar and tabs when showing admin warning; do not nullify current_tab when removing admin warning; do not restore user tabs when root

2361. By Jeremy Wootten

Merge trunk to r2390

2360. By Jeremy Wootten

Remove unnecessary capitals and exclamation mark

2359. By Jeremy Wootten

Use AlertView, make sidebar insensitive, work with commandline directory parameters

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/pantheon-files-pkexec.cmake'
2--- data/pantheon-files-pkexec.cmake 2017-02-15 14:00:30 +0000
3+++ data/pantheon-files-pkexec.cmake 2017-06-09 11:40:39 +0000
4@@ -1,2 +1,2 @@
5 #!/bin/sh
6-pkexec "@CMAKE_INSTALL_PREFIX@/bin/pantheon-files"
7\ No newline at end of file
8+pkexec "@CMAKE_INSTALL_PREFIX@/bin/pantheon-files"
9
10=== modified file 'src/Application.vala'
11--- src/Application.vala 2017-06-04 11:12:44 +0000
12+++ src/Application.vala 2017-06-09 11:40:39 +0000
13@@ -196,12 +196,12 @@
14 }
15 }
16
17- File[] files = null;
18+ File[] files = {};
19
20 /* Convert remaining arguments to GFiles */
21 foreach (string filepath in remaining) {
22 string path = PF.FileUtils.sanitize_path (filepath, null);
23- GLib.File? file = null;
24+ File? file = null;
25
26 if (path.length > 0) {
27 file = File.new_for_uri (PF.FileUtils.escape_uri (path));
28@@ -281,13 +281,28 @@
29 GOF.Preferences.get_default (), "clock-format", GLib.SettingsBindFlags.GET);
30 }
31
32- private void open_windows (File[]? files) {
33- if (files == null)
34- open_tabs (null); /* open_tabs () will restore saved tabs or default tab depending on preference */
35+ private void open_windows (File[] files) {
36+ if (files.length == 0)
37+ open_tabs (files); /* open_tabs () will restore saved tabs or default tab depending on preference */
38 else {
39- /* Open windows with tab at each requested location. */
40- foreach (var file in files) {
41- create_window (file);
42+ if (Posix.getuid () == 0) {
43+ var warning_window = create_window (null);
44+ Granite.Widgets.AlertView warning = warning_window.add_admin_warning_tab ();
45+
46+ File[] locations = files; /* Needed for closure */
47+ warning.action_activated.connect (() => {
48+ /* Open windows with tab at each requested location. */
49+ foreach (var file in locations) {
50+ create_window (file);
51+ }
52+
53+ warning_window.close ();
54+ });
55+ } else {
56+ /* Open windows with tab at each requested location. */
57+ foreach (var file in files) {
58+ create_window (file);
59+ }
60 }
61 }
62 }
63@@ -347,9 +362,8 @@
64 return win;
65 }
66
67- private void open_tabs (File[]? files, Gdk.Screen screen = Gdk.Screen.get_default ()) {
68+ private void open_tabs (File[] files, Gdk.Screen screen = Gdk.Screen.get_default ()) {
69 Marlin.View.Window window = null;
70-
71 /* Get the first window, if any, else create a new window */
72 if (windows_exist ()) {
73 window = (this.get_windows ()).data as Marlin.View.Window;
74@@ -360,7 +374,27 @@
75 return;
76 }
77 }
78- if (files == null) {
79+
80+ if (Posix.getuid () == 0) {
81+ Granite.Widgets.AlertView warning = window.add_admin_warning_tab ();
82+ File[] locations = files; /* Needed for closure */
83+
84+ warning.action_activated.connect (() => {
85+ /* When as root only create tabs if location given on commandline.
86+ * Otherwise default (home) tab is shown */
87+ if (locations.length > 0) {
88+ restore_or_create_tabs (locations, window);
89+ }
90+
91+ window.remove_warning_tab (warning);
92+ });
93+ } else {
94+ restore_or_create_tabs (files, window);
95+ }
96+ }
97+
98+ private void restore_or_create_tabs (File[] files, Marlin.View.Window window) {
99+ if (files.length == 0) {
100 /* Restore session if not root and settings allow */
101 if (Posix.getuid () == 0 ||
102 !Preferences.settings.get_boolean ("restore-tabs") ||
103@@ -372,8 +406,9 @@
104 }
105 } else {
106 /* Open tabs at each requested location */
107- foreach (var file in files)
108+ foreach (var file in files) {
109 window.add_tab (file, Marlin.ViewMode.PREFERRED);
110+ }
111 }
112 }
113
114
115=== modified file 'src/View/Widgets/TopMenu.vala'
116--- src/View/Widgets/TopMenu.vala 2017-03-08 19:39:11 +0000
117+++ src/View/Widgets/TopMenu.vala 2017-06-09 11:40:39 +0000
118@@ -33,7 +33,11 @@
119
120 public bool working {
121 set {
122- location_bar.sensitive = !value;
123+ var sensitive = !value;
124+ location_bar.sensitive = sensitive;
125+ view_switcher.sensitive = sensitive;
126+ button_forward.sensitive = sensitive;
127+ button_back.sensitive = sensitive;
128 }
129 }
130
131
132=== modified file 'src/View/Window.vala'
133--- src/View/Window.vala 2017-06-04 11:12:44 +0000
134+++ src/View/Window.vala 2017-06-09 11:40:39 +0000
135@@ -56,7 +56,7 @@
136 private unowned UndoManager undo_manager;
137 public Chrome.TopMenu top_menu;
138 public Chrome.ViewSwitcher view_switcher;
139- public Gtk.InfoBar info_bar;
140+ private Gtk.InfoBar info_bar;
141 public Granite.Widgets.DynamicNotebook tabs;
142 private Gtk.Paned lside_pane;
143 public Marlin.Places.Sidebar sidebar;
144@@ -101,8 +101,6 @@
145 undo_manager = Marlin.UndoManager.instance ();
146 construct_top_menu ();
147 set_titlebar (top_menu);
148- construct_info_bar ();
149- show_infobar (!is_marlin_mydefault_fm ());
150 construct_notebook ();
151 construct_sidebar ();
152 build_window ();
153@@ -124,7 +122,15 @@
154 private void build_window () {
155 Gtk.Box window_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
156 window_box.show();
157+
158+ if (Posix.getuid () == 0) {
159+ apply_admin_theming ();
160+ }
161+
162+ construct_info_bar ();
163 window_box.pack_start(info_bar, false, false, 0);
164+ show_infobar (!is_marlin_mydefault_fm ());
165+
166 window_box.pack_start(tabs, true, true, 0);
167
168 lside_pane = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
169@@ -230,6 +236,13 @@
170 ((Gtk.Box)info_bar.get_content_area ()).add (bbox);
171 }
172
173+ private void apply_admin_theming () {
174+ var warning_bar = new Gtk.InfoBar ();
175+ warning_bar.message_type = Gtk.MessageType.WARNING;
176+ /* Set headerbar to the appropriate colour for a warning, as determined by the current theme */
177+ Granite.Widgets.Utils.set_color_primary (top_menu, warning_bar.get_style_context ().get_color (Gtk.StateFlags.NORMAL));
178+ }
179+
180 private void connect_signals () {
181 /*/
182 /* Connect and abstract signals to local ones
183@@ -303,16 +316,19 @@
184 });
185
186 tabs.close_tab_requested.connect ((tab) => {
187- var view_container = (tab.page as ViewContainer);
188- tab.restore_data = view_container.location.get_uri ();
189-
190- /* If closing tab is current, set current_tab to null to ensure
191- * closed ViewContainer is destroyed. It will be reassigned in tab_changed
192- */
193- if (view_container == current_tab)
194- current_tab = null;
195-
196- view_container.close ();
197+ if (tab.page is ViewContainer) {
198+ var view_container = (tab.page as ViewContainer);
199+ tab.restore_data = view_container.location.get_uri ();
200+
201+ /* If closing tab is current, set current_tab to null to ensure
202+ * closed ViewContainer is destroyed. It will be reassigned in tab_changed
203+ */
204+ if (view_container == current_tab) {
205+ current_tab = null;
206+ }
207+
208+ view_container.close ();
209+ }
210
211 if (tabs.n_tabs == 1)
212 add_tab ();
213@@ -343,11 +359,17 @@
214 });
215
216 sidebar.request_focus.connect (() => {
217- return !current_tab.locked_focus && !top_menu.locked_focus;
218+ if (current_tab is ViewContainer) {
219+ return !current_tab.locked_focus && !top_menu.locked_focus;
220+ } else {
221+ return !top_menu.locked_focus;
222+ }
223 });
224
225 sidebar.sync_needed.connect (() => {
226- loading_uri (current_tab.uri);
227+ if (current_tab is ViewContainer) {
228+ loading_uri (current_tab.uri);
229+ }
230 });
231 }
232
233@@ -414,10 +436,11 @@
234 }
235
236 private void show_infobar (bool val) {
237- if (val)
238+ if (val) {
239 info_bar.show_all ();
240- else
241+ } else {
242 info_bar.hide ();
243+ }
244 }
245
246 public GOF.AbstractSlot? get_active_slot() {
247@@ -437,6 +460,7 @@
248 }
249
250 ViewContainer? old_tab = current_tab;
251+
252 current_tab = (tabs.get_tab_by_index (offset)).page as ViewContainer;
253
254 if (current_tab == null || old_tab == current_tab)
255@@ -455,6 +479,39 @@
256 loading_uri (current_tab.uri);
257 current_tab.set_active_state (true, false); /* changing tab should not cause animated scrolling */
258 top_menu.working = current_tab.is_frozen;
259+ sidebar.sensitive = !current_tab.is_frozen;
260+ }
261+
262+ public Granite.Widgets.AlertView add_admin_warning_tab () {
263+ var content = new Granite.Widgets.AlertView (_("Files is Running as Administrator"),
264+ _("Altering or deleting system files could damage your system or render it unusable"),
265+ "dialog-warning");
266+
267+ content.show_action (_("Continue"));
268+
269+ var tab = new Granite.Widgets.Tab ("", null, content);
270+ tab.label = _("Warning");
271+ change_tab ((int)tabs.insert_tab (tab, -1));
272+ tabs.current = tab;
273+
274+ set_warning_visible (true);
275+
276+ return content;
277+ }
278+
279+ public void remove_warning_tab (Gtk.Widget content) {
280+ set_warning_visible (false);
281+ remove_tab (content);
282+ }
283+
284+ private void set_warning_visible (bool warning_is_visible) {
285+ /* Set widget properties according to whether admin warning view is showing */
286+ top_menu.working = warning_is_visible;
287+ sidebar.sensitive = !warning_is_visible;
288+ sidebar.visible = !warning_is_visible;
289+ sidebar.no_show_all = warning_is_visible;
290+ tabs.show_tabs = !warning_is_visible;
291+ tabs.no_show_all = warning_is_visible;
292 }
293
294 public void add_tab_by_uri (string uri, Marlin.ViewMode mode = Marlin.ViewMode.PREFERRED) {
295@@ -553,8 +610,8 @@
296 return !sidebar.has_bookmark (uri);
297 }
298
299- public void remove_tab (ViewContainer view_container) {
300- actual_remove_tab (tabs.get_tab_by_widget (view_container as Gtk.Widget));
301+ public void remove_tab (Gtk.Widget content) {
302+ actual_remove_tab (tabs.get_tab_by_widget (content));
303 }
304
305 private void actual_remove_tab (Granite.Widgets.Tab tab) {
306@@ -913,7 +970,9 @@
307
308 foreach (var tab in tabs.tabs) {
309 current_tab = null;
310- (tab.page as Marlin.View.ViewContainer).close ();
311+ if (tab.page is Marlin.View.ViewContainer) {
312+ (tab.page as Marlin.View.ViewContainer).close ();
313+ }
314 }
315
316 this.destroy ();
317@@ -1087,6 +1146,8 @@
318 top_menu.can_go_forward = (current_tab.can_show_folder && current_tab.can_go_forward);
319 top_menu.working = current_tab.is_loading;
320
321+ sidebar.sensitive = !current_tab.is_loading;
322+
323 /* Update viewmode switch, action state and settings */
324 var mode = current_tab.view_mode;
325 view_switcher.mode = mode;

Subscribers

People subscribed via source and target branches

to all changes: