| 1 |
/* This code was mostly imported from elementary: https://github.com/elementary/scratch/blob/master/src/Dialogs/PropertiesDialog.vala |
| 2 |
* |
| 3 |
* Copyright (c) 2011-2017 elementary LLC (https://elementary.io) |
| 4 |
* Copyright (c) 2017-2019 José Amuedo (https://github.com/spheras) |
| 5 |
* |
| 6 |
* This program is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation, either version 3 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authored by: Giulio Collura <[email protected]> |
| 20 |
* Mario Guerriero <[email protected]> |
| 21 |
* Fabio Zaramella <[email protected]> |
| 22 |
*/ |
| 23 |
|
| 24 |
namespace DesktopFolder.Dialogs { |
| 25 |
|
| 26 |
|
| 27 |
public class ShowInfo : Gtk.Window { |
| 28 |
|
| 29 |
private string filepath; |
| 30 |
private File file; |
| 31 |
FileInfo general_info; |
| 32 |
|
| 33 |
public ShowInfo (string fpath, string fname) { |
| 34 |
try { |
| 35 |
// general |
| 36 |
this.filepath = fpath; |
| 37 |
this.file = File.new_for_commandline_arg (this.filepath); |
| 38 |
general_info = this.file.query_info ("*", FileQueryInfoFlags.NONE); |
| 39 |
// essential info we need to decide on the gui elements |
| 40 |
bool is_a_link = FileUtils.test (this.filepath, FileTest.IS_SYMLINK); |
| 41 |
bool is_a_folder = FileUtils.test (this.filepath, FileTest.IS_DIR); |
| 42 |
// window props |
| 43 |
this.set_title (DesktopFolder.Lang.ITEM_PROPSWINDOW_SHOW_FILEINFO); |
| 44 |
this.set_modal (true); |
| 45 |
this.set_default_size (400, 200); |
| 46 |
// get file icon & maingrid |
| 47 |
Gtk.Image fileicon = get_fileicon (); |
| 48 |
var maingrid = new Gtk.Grid (); |
| 49 |
maingrid.attach (fileicon, 1, 1, 1, 2); |
| 50 |
maingrid.set_column_spacing (20); |
| 51 |
maingrid.set_row_spacing (10); |
| 52 |
maingrid.attach (new Gtk.Label (""), 0, 0, 1, 1); |
| 53 |
maingrid.attach (new Gtk.Label (""), 100, 100, 1, 1); |
| 54 |
// name |
| 55 |
var name_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_SHOW_FILENAME.concat (":")); |
| 56 |
var name_value = new Gtk.Label (fname); |
| 57 |
// location |
| 58 |
string location = filepath.replace ("/" + fname, ""); |
| 59 |
var location_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_SHOW_LOCATION.concat (":")); |
| 60 |
var location_value = new Gtk.Label (location); |
| 61 |
// content type |
| 62 |
var content_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_SHOW_CONTENTTYPE.concat (":")); |
| 63 |
var content_value = new Gtk.Label (""); |
| 64 |
|
| 65 |
Gtk.Label[] labels = { |
| 66 |
name_label, location_label, content_label |
| 67 |
}; |
| 68 |
|
| 69 |
Gtk.Label[] values = { |
| 70 |
name_value, location_value, content_value |
| 71 |
}; |
| 72 |
|
| 73 |
// content type & fill in gui, depending on type |
| 74 |
string content = get_filetype (); |
| 75 |
if (is_a_link) { |
| 76 |
content = "inode/symlink"; // overrule possibly different output from get_filetype() |
| 77 |
var target_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_SHOW_TARGET.concat (":")); |
| 78 |
labels += target_label; |
| 79 |
string target = general_info.get_symlink_target (); |
| 80 |
var target_value = new Gtk.Label (target); |
| 81 |
values += target_value; |
| 82 |
} else if (is_a_folder) { |
| 83 |
// get n-files |
| 84 |
int64[] folderdata = get_folderdata (); |
| 85 |
// labels / values |
| 86 |
var n_items_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_CONTENT.concat (":")); |
| 87 |
labels += n_items_label; |
| 88 |
var total_size_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_TOTALSIZE.concat (":")); |
| 89 |
labels += total_size_label; |
| 90 |
string n_items = folderdata[0].to_string ().concat (" ", DesktopFolder.Lang.ITEM_PROPSWINDOW_N_ITEMS); |
| 91 |
var n_items_value = new Gtk.Label (n_items); |
| 92 |
values += n_items_value; |
| 93 |
string totalsize = get_readablesize (folderdata[1]); |
| 94 |
var total_size_value = new Gtk.Label (totalsize); |
| 95 |
values += total_size_value; |
| 96 |
if (folderdata[0] == -1) { |
| 97 |
n_items_value.set_text ("?"); |
| 98 |
total_size_value.set_text ("?"); |
| 99 |
} |
| 100 |
} else { |
| 101 |
var filesize_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_FILESIZE.concat (":")); |
| 102 |
labels += filesize_label; |
| 103 |
string filesize = get_readablesize (general_info.get_size ()); |
| 104 |
var filesize_value = new Gtk.Label (filesize); |
| 105 |
values += filesize_value; |
| 106 |
// executable, unfortunately, we cannot add it to attach-list; its not a Label |
| 107 |
maingrid.attach (new Gtk.Label (""), 1, 10, 1, 1); |
| 108 |
var executable_label = new Gtk.Label (DesktopFolder.Lang.ITEM_MENU_EXECUTE.concat (":")); |
| 109 |
maingrid.attach (executable_label, 2, 11, 1, 1); |
| 110 |
var executable_value = new Gtk.CheckButton.with_label (DesktopFolder.Lang.ITEM_PROPSWINDOW_ALLOWEXECUTE); |
| 111 |
bool isexec = FileUtils.test (this.filepath, FileTest.IS_EXECUTABLE); |
| 112 |
executable_value.set_active (isexec); |
| 113 |
maingrid.attach (executable_value, 3, 11, 1, 1); |
| 114 |
executable_value.toggled.connect (toggle_executable); |
| 115 |
} |
| 116 |
|
| 117 |
content_value.set_text (content); |
| 118 |
// separate acces/modify time |
| 119 |
labels += new Gtk.Label (""); |
| 120 |
values += new Gtk.Label (""); |
| 121 |
string[] timedata = get_filetime (); |
| 122 |
if (!is_a_folder) { |
| 123 |
var last_accessed_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_LASTUSED.concat (":")); |
| 124 |
labels += last_accessed_label; |
| 125 |
var last_accessed_value = new Gtk.Label (timedata[0]); |
| 126 |
values += last_accessed_value; |
| 127 |
} |
| 128 |
var last_modified_label = new Gtk.Label (DesktopFolder.Lang.ITEM_PROPSWINDOW_LASTMODIFIED.concat (":")); |
| 129 |
labels += last_modified_label; |
| 130 |
var last_modified_value = new Gtk.Label (timedata[1]); |
| 131 |
values += last_modified_value; |
| 132 |
int labelpos = 1; |
| 133 |
foreach (Gtk.Label l in labels) { |
| 134 |
l.set_xalign (0); |
| 135 |
maingrid.attach (l, 2, labelpos, 1, 1); |
| 136 |
labelpos += 1; |
| 137 |
} |
| 138 |
int valuepos = 1; |
| 139 |
foreach (Gtk.Label l in values) { |
| 140 |
l.set_xalign (0); |
| 141 |
l.set_ellipsize (Pango.EllipsizeMode.END); |
| 142 |
l.set_selectable (true); |
| 143 |
maingrid.attach (l, 3, valuepos, 1, 1); |
| 144 |
valuepos += 1; |
| 145 |
} |
| 146 |
|
| 147 |
this.add (maingrid); |
| 148 |
maingrid.show_all (); |
| 149 |
} catch (Error e) { |
| 150 |
stderr.printf ("Error: %s\n", e.message); |
| 151 |
Util.show_error_dialog ("Error", e.message); |
| 152 |
} |
| 153 |
this.show_all (); |
| 154 |
} |
| 155 |
|
| 156 |
public string get_readablesize (int64 bytes) { |
| 157 |
// convert to readable size, decide on unit |
| 158 |
string unit; |
| 159 |
double size; |
| 160 |
if (bytes >= 1000000000000) { |
| 161 |
size = bytes / 1000000000000.0; |
| 162 |
unit = "TB"; |
| 163 |
} else if (bytes >= 1000000000) { |
| 164 |
size = bytes / 1000000000.0; |
| 165 |
unit = "GB"; |
| 166 |
} else if (bytes >= 1000000) { |
| 167 |
size = bytes / 1000000.0; |
| 168 |
unit = "MB"; |
| 169 |
} else if (bytes >= 1000) { |
| 170 |
size = bytes / 1000.0; |
| 171 |
unit = "kB"; |
| 172 |
} else { |
| 173 |
size = bytes; |
| 174 |
unit = "byte"; |
| 175 |
} |
| 176 |
// prevent silly .0 if first decimal is 0 |
| 177 |
return "%.1f".printf (size).replace (".0", "").replace (",0", "").concat (" ", unit); |
| 178 |
} |
| 179 |
|
| 180 |
private int64[] get_folderdata () { |
| 181 |
// folder properties: count items |
| 182 |
string cmd = "find \"" + this.filepath + "\""; |
| 183 |
string output; |
| 184 |
try { |
| 185 |
GLib.Process.spawn_command_line_sync (cmd, out output); |
| 186 |
string[] all_lines = output.split ("\n"); |
| 187 |
string[] real_files = all_lines[1 : all_lines.length - 1]; |
| 188 |
int64 totalsize = 0; |
| 189 |
foreach (string l in real_files) { |
| 190 |
File file = File.new_for_path (l); |
| 191 |
try { |
| 192 |
int64 size = file.query_info ("*", FileQueryInfoFlags.NONE).get_size (); |
| 193 |
totalsize += size; |
| 194 |
} catch (Error e) { |
| 195 |
totalsize += 0; // ? |
| 196 |
} |
| 197 |
} |
| 198 |
int lines = real_files.length; |
| 199 |
return { lines, totalsize }; |
| 200 |
} catch (SpawnError e) { |
| 201 |
return { -1, -1 }; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
private string[] get_filetime () { |
| 206 |
int64 last_edit = (int64) general_info.get_attribute_uint64 (FileAttribute.TIME_MODIFIED); |
| 207 |
int64 last_access = (int64) general_info.get_attribute_uint64 (FileAttribute.TIME_ACCESS); |
| 208 |
return { |
| 209 |
new DateTime.from_unix_local (last_access).to_string (), |
| 210 |
new DateTime.from_unix_local (last_edit).to_string () |
| 211 |
}; |
| 212 |
} |
| 213 |
|
| 214 |
private void toggle_executable (Gtk.ToggleButton button) { |
| 215 |
bool ex = button.get_active (); |
| 216 |
string cmd = "chmod +x \"" + this.filepath + "\""; |
| 217 |
if (!ex) { |
| 218 |
cmd = "chmod -x \"" + this.filepath + "\""; |
| 219 |
} |
| 220 |
try { |
| 221 |
Process.spawn_command_line_async (cmd); |
| 222 |
} catch (SpawnError e) { |
| 223 |
// nothing to be done |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
private Gtk.Image get_fileicon () { |
| 228 |
// get file icon, fallback to icon name "unknown" on error (which exists!) |
| 229 |
string icon_name = "unknown"; |
| 230 |
try { |
| 231 |
string[] icondata = general_info.get_icon ().to_string ().split (" "); |
| 232 |
int len_icons = icondata.length; |
| 233 |
icon_name = icondata[len_icons - 1]; |
| 234 |
if (len_icons >= 4) { |
| 235 |
icon_name = icondata[3]; |
| 236 |
} |
| 237 |
print ("%s\n", icon_name); |
| 238 |
} catch (Error error) { |
| 239 |
print ("Error: %s\n", error.message); |
| 240 |
} |
| 241 |
Gtk.Image fileicon = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG); |
| 242 |
return fileicon; |
| 243 |
} |
| 244 |
|
| 245 |
private string get_filetype () { |
| 246 |
string ftype = DesktopFolder.Lang.ITEM_PROPSWINDOW_UNKNOWN; |
| 247 |
try { |
| 248 |
ftype = general_info.get_content_type (); |
| 249 |
print ("%s\n", ftype); |
| 250 |
} catch (Error error) { |
| 251 |
print ("Error: %s\n", error.message); |
| 252 |
} |
| 253 |
return ftype; |
| 254 |
} |
| 255 |
|
| 256 |
} |
| 257 |
|
| 258 |
public class OpenWith : Gtk.AppChooserDialog { |
| 259 |
public OpenWith (string content_type, string path) { |
| 260 |
string cleaned_path = "'" + path.replace ("'", "'\\''") + "'"; |
| 261 |
var dialog = new Gtk.AppChooserDialog.for_content_type ( |
| 262 |
this, 0, content_type |
| 263 |
); |
| 264 |
if (dialog.run () == Gtk.ResponseType.OK) { |
| 265 |
AppInfo info = dialog.get_app_info (); |
| 266 |
if (info != null) { |
| 267 |
try { |
| 268 |
Process.spawn_command_line_async ( |
| 269 |
info.get_executable () + " " + cleaned_path); |
| 270 |
} catch (SpawnError e) { |
| 271 |
// nothing to be done |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
dialog.close (); |
| 276 |
} |
| 277 |
|
| 278 |
} |
| 279 |
|
| 280 |
public class PanelProperties : Gtk.Dialog { |
| 281 |
private enum ResolutionStrategy { |
| 282 |
NONE, |
| 283 |
SCALE, |
| 284 |
STORE |
| 285 |
} |
| 286 |
private Gtk.Stack main_stack; |
| 287 |
private FolderWindow window; |
| 288 |
private FolderManager manager; |
| 289 |
private Gtk.Widget properties_grid; |
| 290 |
|
| 291 |
public PanelProperties (FolderWindow window) { |
| 292 |
Object ( |
| 293 |
border_width: 5, |
| 294 |
deletable: false, |
| 295 |
resizable: false, |
| 296 |
modal: true, |
| 297 |
title: DesktopFolder.Lang.PANELPROPERTIES_PROPERTIES |
| 298 |
); |
| 299 |
|
| 300 |
this.window = window; |
| 301 |
this.manager = this.window.get_manager (); |
| 302 |
build (); |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* @name build |
| 307 |
* @description build the window components |
| 308 |
*/ |
| 309 |
private void build () { |
| 310 |
main_stack = new Gtk.Stack (); |
| 311 |
main_stack.margin = 12; |
| 312 |
main_stack.margin_bottom = 18; |
| 313 |
main_stack.margin_top = 24; |
| 314 |
this.properties_grid = get_properties_box (); |
| 315 |
main_stack.add_titled (properties_grid, "properties", DesktopFolder.Lang.PANELPROPERTIES_PROPERTIES); |
| 316 |
main_stack.add_titled (get_general_box (), "general", DesktopFolder.Lang.PANELPROPERTIES_GENERAL); |
| 317 |
|
| 318 |
var version_label = new Gtk.Label ("Version " + DesktopFolder.VERSION.up ()); |
| 319 |
version_label.set_size_request (250, -1); |
| 320 |
version_label.xalign = 0; |
| 321 |
|
| 322 |
var main_stackswitcher = new Gtk.StackSwitcher (); |
| 323 |
main_stackswitcher.set_stack (main_stack); |
| 324 |
main_stackswitcher.homogeneous = true; |
| 325 |
|
| 326 |
main_stackswitcher.margin_start = 12; |
| 327 |
main_stackswitcher.margin_end = 12; |
| 328 |
|
| 329 |
var main_grid = new Gtk.Grid (); |
| 330 |
main_grid.attach (main_stackswitcher, 0, 0, 1, 1); |
| 331 |
main_grid.attach (main_stack, 0, 1, 1, 1); |
| 332 |
|
| 333 |
get_content_area ().add (main_grid); |
| 334 |
|
| 335 |
var close_button = new Gtk.Button.with_label (DesktopFolder.Lang.PANELPROPERTIES_CLOSE); |
| 336 |
close_button.clicked.connect (() => { |
| 337 |
destroy (); |
| 338 |
}); |
| 339 |
|
| 340 |
add_action_widget (version_label, 1); |
| 341 |
add_action_widget (close_button, 0); |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* @name get_properties_box |
| 346 |
* @description build the properties section |
| 347 |
* @return {Gtk.Widget} the built Gtk.Grid widget |
| 348 |
*/ |
| 349 |
private Gtk.Widget get_properties_box () { |
| 350 |
var general_grid = new Gtk.Grid (); |
| 351 |
general_grid.row_spacing = 6; |
| 352 |
general_grid.column_spacing = 12; |
| 353 |
|
| 354 |
// The behavior section |
| 355 |
general_grid.attach (new SettingsHeader (DesktopFolder.Lang.PANELPROPERTIES_BEHAVIOR), 0, 0, 2, 1); |
| 356 |
|
| 357 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT), 0, 1, 1, 1); |
| 358 |
var arrangement_combo = new Gtk.ComboBoxText (); |
| 359 |
arrangement_combo.append ("FREE", DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_FREE); |
| 360 |
arrangement_combo.append ("GRID", DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_GRID); |
| 361 |
arrangement_combo.append ("MANAGED", DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_MANAGED); |
| 362 |
arrangement_combo.active = this.manager.get_settings ().arrangement_type - 1; |
| 363 |
arrangement_combo.changed.connect (() => { |
| 364 |
if (arrangement_combo.get_active_id () == "FREE") { |
| 365 |
this.manager.on_arrange_change (FolderArrangement.ARRANGEMENT_TYPE_FREE); |
| 366 |
} else if (arrangement_combo.get_active_id () == "GRID") { |
| 367 |
this.manager.on_arrange_change (FolderArrangement.ARRANGEMENT_TYPE_GRID); |
| 368 |
} else { |
| 369 |
this.manager.on_arrange_change (FolderArrangement.ARRANGEMENT_TYPE_MANAGED); |
| 370 |
} |
| 371 |
}); |
| 372 |
arrangement_combo.expand = true; |
| 373 |
general_grid.attach (arrangement_combo, 1, 1, 1, 1); |
| 374 |
|
| 375 |
/* |
| 376 |
// align to grid |
| 377 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.DESKTOPFOLDER_MENU_ALIGN_TO_GRID), 0, 1, 1, 1); |
| 378 |
SettingsSwitch settings_switch = new SettingsSwitch ("align_to_grid"); |
| 379 |
settings_switch.set_active (this.manager.get_settings ().align_to_grid); |
| 380 |
general_grid.attach (settings_switch, 1, 1, 1, 1); |
| 381 |
settings_switch.notify["active"].connect (this.window.on_toggle_align_to_grid); |
| 382 |
*/ |
| 383 |
|
| 384 |
|
| 385 |
// lock items |
| 386 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.DESKTOPFOLDER_MENU_LOCK_ITEMS), 0, 2, 1, 1); |
| 387 |
SettingsSwitch settings_switch = new SettingsSwitch ("lock_items"); |
| 388 |
general_grid.attach (settings_switch, 1, 2, 1, 1); |
| 389 |
settings_switch.set_active (this.manager.get_settings ().lockitems); |
| 390 |
settings_switch.notify["active"].connect (this.window.on_toggle_lockitems); |
| 391 |
|
| 392 |
int top_offset = -1; |
| 393 |
|
| 394 |
if (this.window.get_type () != typeof (DesktopFolder.DesktopWindow)) { |
| 395 |
top_offset = 0; |
| 396 |
// lock panel |
| 397 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.DESKTOPFOLDER_MENU_LOCK_PANEL), 0, 3, 1, 1); |
| 398 |
settings_switch = new SettingsSwitch ("lock_panel"); |
| 399 |
general_grid.attach (settings_switch, 1, 3, 1, 1); |
| 400 |
settings_switch.set_active (this.manager.get_settings ().lockpanel); |
| 401 |
settings_switch.notify["active"].connect (this.window.on_toggle_lockpanel); |
| 402 |
} |
| 403 |
|
| 404 |
// The interface section |
| 405 |
general_grid.attach (new SettingsHeader (DesktopFolder.Lang.PANELPROPERTIES_APPEARANCE), 0, 4 + top_offset, 2, 1); |
| 406 |
// Tet shadow |
| 407 |
settings_switch = new SettingsSwitch ("text_shadow"); |
| 408 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.DESKTOPFOLDER_MENU_TEXT_SHADOW), 0, 5 + top_offset, 1, 1); |
| 409 |
general_grid.attach (settings_switch, 1, 5 + top_offset, 1, 1); |
| 410 |
settings_switch.set_active (this.manager.get_settings ().textshadow); |
| 411 |
settings_switch.notify["active"].connect (this.window.on_toggle_shadow); |
| 412 |
// text bold |
| 413 |
settings_switch = new SettingsSwitch ("text_bold"); |
| 414 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.DESKTOPFOLDER_MENU_TEXT_BOLD), 0, 6 + top_offset, 1, 1); |
| 415 |
general_grid.attach (settings_switch, 1, 6 + top_offset, 1, 1); |
| 416 |
settings_switch.set_active (this.manager.get_settings ().textbold); |
| 417 |
settings_switch.notify["active"].connect (this.window.on_toggle_bold); |
| 418 |
|
| 419 |
// the items padding |
| 420 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_PADDING), 0, 7 + top_offset, 1, 1); |
| 421 |
var scale = new Gtk.SpinButton.with_range (0, 50, 1); |
| 422 |
scale.set_value (this.manager.get_settings ().arrangement_padding); |
| 423 |
scale.value_changed.connect (() => { |
| 424 |
this.manager.get_settings ().arrangement_padding = (int) scale.get_value (); |
| 425 |
if (this.manager.get_arrangement ().force_organization ()) { |
| 426 |
this.manager.organize_panel_items (); |
| 427 |
} |
| 428 |
}); |
| 429 |
general_grid.attach (scale, 1, 7 + top_offset, 1, 1); |
| 430 |
|
| 431 |
|
| 432 |
if (this.window.get_type () == typeof (DesktopFolder.DesktopWindow) && (!this.manager.get_application ().get_desktoppanel_enabled () || !this.manager.get_application ().get_desktopicons_enabled ())) { |
| 433 |
general_grid.set_sensitive (false); |
| 434 |
} |
| 435 |
|
| 436 |
return general_grid; |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* @name set_property_page_sensitivity |
| 441 |
* @description set sensitivity of properties page items |
| 442 |
*/ |
| 443 |
private void set_property_page_sensitivity (bool sensitivity) { |
| 444 |
if (this.properties_grid != null) { |
| 445 |
properties_grid.set_sensitive (sensitivity); |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
/** |
| 450 |
* @name get_general_box |
| 451 |
* @description build the general section |
| 452 |
* @return {Gtk.Widget} the built Gtk.Grid widget |
| 453 |
*/ |
| 454 |
private Gtk.Widget get_general_box () { |
| 455 |
var general_grid = new Gtk.Grid (); |
| 456 |
general_grid.row_spacing = 6; |
| 457 |
general_grid.column_spacing = 12; |
| 458 |
|
| 459 |
|
| 460 |
GLib.Settings settings = new GLib.Settings ("com.github.spheras.desktopfolder"); |
| 461 |
|
| 462 |
general_grid.attach (new SettingsHeader (DesktopFolder.Lang.PANELPROPERTIES_GENERAL), 0, 0, 2, 1); |
| 463 |
|
| 464 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.PANELPROPERTIES_DESKTOP_ICONS), 0, 1, 1, 1); |
| 465 |
|
| 466 |
SettingsSwitch settings_switch = new SettingsSwitch ("icons-on-desktop"); |
| 467 |
settings_switch.halign = Gtk.Align.START; |
| 468 |
settings_switch.margin_end = 8; |
| 469 |
general_grid.attach (settings_switch, 1, 1, 1, 1); |
| 470 |
|
| 471 |
settings_switch.set_active (settings.get_boolean ("icons-on-desktop")); |
| 472 |
settings_switch.notify["active"].connect (() => { |
| 473 |
bool desktopicons_enabled = settings.get_boolean ("icons-on-desktop"); |
| 474 |
settings.set_boolean ("icons-on-desktop", !desktopicons_enabled); |
| 475 |
if (this.window.get_type () == typeof (DesktopFolder.DesktopWindow)) { |
| 476 |
this.set_property_page_sensitivity (!desktopicons_enabled); |
| 477 |
} |
| 478 |
}); |
| 479 |
|
| 480 |
// Uncomment the following block when the option to remove DesktopWindow is wanted again |
| 481 |
/* |
| 482 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.PANELPROPERTIES_DESKTOP_PANEL), 0, 2, 1, 1); |
| 483 |
|
| 484 |
settings_switch = new SettingsSwitch ("desktop_panel"); |
| 485 |
settings_switch.halign = Gtk.Align.START; |
| 486 |
settings_switch.margin_end = 8; |
| 487 |
general_grid.attach (settings_switch, 1, 2, 1, 1); |
| 488 |
|
| 489 |
var icons_on_desktop_help = new Gtk.Image.from_icon_name ("help-info-symbolic", Gtk.IconSize.BUTTON); |
| 490 |
icons_on_desktop_help.halign = Gtk.Align.START; |
| 491 |
icons_on_desktop_help.hexpand = true; |
| 492 |
icons_on_desktop_help.tooltip_text = DesktopFolder.Lang.PANELPROPERTIES_DESKTOP_PANEL_DESCRIPTION; |
| 493 |
general_grid.attach (icons_on_desktop_help, 2, 2, 1, 1); |
| 494 |
|
| 495 |
settings_switch.set_active (settings.get_boolean ("desktop-panel")); |
| 496 |
settings_switch.notify["active"].connect (() => { |
| 497 |
bool desktop_enabled = settings.get_boolean ("desktop-panel"); |
| 498 |
settings.set_boolean ("desktop-panel", !desktop_enabled); |
| 499 |
if (this.window.get_type () == typeof (DesktopFolder.DesktopWindow)) { |
| 500 |
this.set_property_page_sensitivity (!desktop_enabled); |
| 501 |
} |
| 502 |
}); |
| 503 |
*/ |
| 504 |
|
| 505 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.PANELPROPERTIES_RESOLUTION_STRATEGY), 0, 3, 1, 1); |
| 506 |
|
| 507 |
var strategy_combo = new Gtk.ComboBoxText (); |
| 508 |
strategy_combo.append ("NONE", DesktopFolder.Lang.PANELPROPERTIES_RESOLUTION_STRATEGY_NONE); |
| 509 |
strategy_combo.append ("SCALE", DesktopFolder.Lang.PANELPROPERTIES_RESOLUTION_STRATEGY_SCALE); |
| 510 |
strategy_combo.append ("STORE", DesktopFolder.Lang.PANELPROPERTIES_RESOLUTION_STRATEGY_STORE); |
| 511 |
settings.bind ("resolution-strategy", strategy_combo, "active-id", GLib.SettingsBindFlags.DEFAULT); |
| 512 |
strategy_combo.margin_end = 8; |
| 513 |
general_grid.attach (strategy_combo, 1, 3, 1, 1); |
| 514 |
|
| 515 |
var resolution_strategy_help = new Gtk.Image.from_icon_name ("help-info-symbolic", Gtk.IconSize.BUTTON); |
| 516 |
resolution_strategy_help.halign = Gtk.Align.START; |
| 517 |
resolution_strategy_help.hexpand = true; |
| 518 |
resolution_strategy_help.tooltip_text = DesktopFolder.Lang.PANELPROPERTIES_RESOLUTION_STRATEGY_DESCRIPTION; |
| 519 |
general_grid.attach (resolution_strategy_help, 2, 3, 1, 1); |
| 520 |
|
| 521 |
general_grid.attach (new SettingsHeader (DesktopFolder.Lang.PANELPROPERTIES_ICONS), 0, 4, 2, 1); |
| 522 |
|
| 523 |
// DEFAULT Panel Arrangement |
| 524 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_DEFAULT), 0, 5, 1, 1); |
| 525 |
var arrangement_combo = new Gtk.ComboBoxText (); |
| 526 |
arrangement_combo.append ("FREE", DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_FREE); |
| 527 |
arrangement_combo.append ("GRID", DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_GRID); |
| 528 |
arrangement_combo.append ("MANAGED", DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_MANAGED); |
| 529 |
settings.bind ("default-arrangement", arrangement_combo, "active-id", GLib.SettingsBindFlags.DEFAULT); |
| 530 |
arrangement_combo.margin_end = 8; |
| 531 |
general_grid.attach (arrangement_combo, 1, 5, 1, 1); |
| 532 |
|
| 533 |
// DEFAULT Panel Arrangement |
| 534 |
general_grid.attach (new SettingsLabel (DesktopFolder.Lang.PANELPROPERTIES_ARRANGEMENT_PADDING_DEFAULT), 0, 6, 1, 1); |
| 535 |
var scale = new Gtk.SpinButton.with_range (0, 50, 1); |
| 536 |
scale.set_value (settings.get_int ("default-arrangement-padding")); |
| 537 |
scale.value_changed.connect (() => { |
| 538 |
settings.set_int ("default-arrangement-padding", (int) scale.get_value ()); |
| 539 |
}); |
| 540 |
general_grid.attach (scale, 1, 6, 1, 1); |
| 541 |
|
| 542 |
return general_grid; |
| 543 |
} |
| 544 |
|
| 545 |
private class SettingsHeader : Gtk.Label { |
| 546 |
public SettingsHeader (string text) { |
| 547 |
label = text; |
| 548 |
get_style_context ().add_class ("h4"); |
| 549 |
halign = Gtk.Align.START; |
| 550 |
} |
| 551 |
|
| 552 |
} |
| 553 |
|
| 554 |
private class SettingsLabel : Gtk.Label { |
| 555 |
public SettingsLabel (string text) { |
| 556 |
label = text; |
| 557 |
halign = Gtk.Align.END; |
| 558 |
margin_start = 12; |
| 559 |
} |
| 560 |
|
| 561 |
} |
| 562 |
|
| 563 |
private class SettingsSwitch : Gtk.Switch { |
| 564 |
public SettingsSwitch (string setting) { |
| 565 |
halign = Gtk.Align.START; |
| 566 |
// Scratch.settings.schema.bind (setting, this, "active", SettingsBindFlags.DEFAULT); |
| 567 |
} |
| 568 |
|
| 569 |
} |
| 570 |
} |
| 571 |
} |