summaryrefslogtreecommitdiff
path: root/src/gui/preferencesWindow.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/preferencesWindow.vala')
-rw-r--r--src/gui/preferencesWindow.vala325
1 files changed, 211 insertions, 114 deletions
diff --git a/src/gui/preferencesWindow.vala b/src/gui/preferencesWindow.vala
index 29b5250..a1dacac 100644
--- a/src/gui/preferencesWindow.vala
+++ b/src/gui/preferencesWindow.vala
@@ -33,19 +33,21 @@ public class PreferencesWindow : GLib.Object {
/// Some Gtk widgets used by this window.
/////////////////////////////////////////////////////////////////////
+ private Gtk.Stack? stack = null;
+ private Gtk.Notebook? notebook = null;
+
private Gtk.Window? window = null;
- private Gtk.Label? id_label = null;
- private Gtk.Label? name_label = null;
- private Gtk.Label? hotkey_label = null;
private Gtk.Label? no_pie_label = null;
private Gtk.Label? no_slice_label = null;
private Gtk.Box? preview_box = null;
- private Gtk.Image? icon = null;
private Gtk.EventBox? preview_background = null;
- private Gtk.Button? icon_button = null;
- private Gtk.Button? name_button = null;
- private Gtk.Button? hotkey_button = null;
- private Gtk.ToolButton? remove_pie_button = null;
+ private Gtk.Button? remove_pie_button = null;
+ private Gtk.Button? edit_pie_button = null;
+
+ private ThemeList? theme_list = null;
+ private Gtk.ToggleButton? indicator = null;
+ private Gtk.ToggleButton? autostart = null;
+ private Gtk.ToggleButton? captions = null;
/////////////////////////////////////////////////////////////////////
/// Some custom widgets and dialogs used by this window.
@@ -53,10 +55,7 @@ public class PreferencesWindow : GLib.Object {
private PiePreview? preview = null;
private PieList? pie_list = null;
- private SettingsWindow? settings_window = null;
- private TriggerSelectWindow? trigger_window = null;
- private IconSelectWindow? icon_window = null;
- private RenameWindow? rename_window = null;
+ private PieOptionsWindow? pie_options_window = null;
/////////////////////////////////////////////////////////////////////
/// C'tor, creates the window.
@@ -71,14 +70,49 @@ public class PreferencesWindow : GLib.Object {
Gdk.EventMask.KEY_PRESS_MASK |
Gdk.EventMask.POINTER_MOTION_MASK);
- var toolbar = builder.get_object ("toolbar") as Gtk.Widget;
- toolbar.get_style_context().add_class("primary-toolbar");
+ if (Deamon.header_bar) {
+ var headerbar = new Gtk.HeaderBar();
+ headerbar.show_close_button = true;
+ headerbar.title = _("Gnome-Pie Settings");
+ headerbar.subtitle = _("bake your pies!");
+ window.set_titlebar(headerbar);
+ }
+
+ this.notebook = builder.get_object("notebook") as Gtk.Notebook;
+
+ if (Deamon.stack_switcher) {
+ var main_box = builder.get_object("main-box") as Gtk.Box;
+ var pie_settings = builder.get_object("pie-settings") as Gtk.Box;
+ var general_settings = builder.get_object("general-settings") as Gtk.Box;
- var inline_toolbar = builder.get_object ("pies-toolbar") as Gtk.Widget;
- inline_toolbar.get_style_context().add_class("inline-toolbar");
+ pie_settings.parent.remove(pie_settings);
+ general_settings.parent.remove(general_settings);
+
+ main_box.remove(this.notebook);
+
+ Gtk.StackSwitcher switcher = new Gtk.StackSwitcher();
+ switcher.margin_top = 10;
+ switcher.set_halign(Gtk.Align.CENTER);
+ main_box.pack_start(switcher, false, true, 0);
+
+ this.stack = new Gtk.Stack();
+ this.stack.transition_duration = 500;
+ this.stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
+ this.stack.homogeneous = true;
+ this.stack.halign = Gtk.Align.FILL;
+ this.stack.expand = true;
+ main_box.add(stack);
+ switcher.set_stack(stack);
+
+ this.stack.add_with_properties(general_settings, "name", "1", "title", _("General Settings"), null);
+ this.stack.add_with_properties(pie_settings, "name", "2", "title", _("Pie Settings"), null);
+ }
this.pie_list = new PieList();
this.pie_list.on_select.connect(this.on_pie_select);
+ this.pie_list.on_activate.connect(() => {
+ this.on_edit_pie_button_clicked();
+ });
var scroll_area = builder.get_object("pies-scrolledwindow") as Gtk.ScrolledWindow;
scroll_area.add(this.pie_list);
@@ -94,29 +128,82 @@ public class PreferencesWindow : GLib.Object {
preview_box = builder.get_object("preview-box") as Gtk.Box;
this.preview_box.pack_start(preview, true, true);
- this.id_label = builder.get_object("id-label") as Gtk.Label;
- this.name_label = builder.get_object("pie-name-label") as Gtk.Label;
- this.hotkey_label = builder.get_object("hotkey-label") as Gtk.Label;
this.no_pie_label = builder.get_object("no-pie-label") as Gtk.Label;
this.no_slice_label = builder.get_object("no-slice-label") as Gtk.Label;
- this.icon = builder.get_object("icon") as Gtk.Image;
this.preview_background = builder.get_object("preview-background") as Gtk.EventBox;
- (builder.get_object("settings-button") as Gtk.ToolButton).clicked.connect(on_settings_button_clicked);
+ this.remove_pie_button = builder.get_object("remove-pie-button") as Gtk.Button;
+ this.remove_pie_button.clicked.connect(on_remove_pie_button_clicked);
- this.hotkey_button = builder.get_object("key-button") as Gtk.Button;
- this.hotkey_button.clicked.connect(on_key_button_clicked);
+ this.edit_pie_button = builder.get_object("edit-pie-button") as Gtk.Button;
+ this.edit_pie_button.clicked.connect(on_edit_pie_button_clicked);
- this.icon_button = builder.get_object("icon-button") as Gtk.Button;
- this.icon_button.clicked.connect(on_icon_button_clicked);
+ (builder.get_object("add-pie-button") as Gtk.Button).clicked.connect(on_add_pie_button_clicked);
- this.name_button = builder.get_object("rename-button") as Gtk.Button;
- this.name_button.clicked.connect(on_rename_button_clicked);
+ this.theme_list = new ThemeList();
+ this.theme_list.on_select_new.connect(() => {
+ this.captions.active = Config.global.show_captions;
+ if (Config.global.theme.has_slice_captions) {
+ this.captions.sensitive = true;
+ } else {
+ this.captions.sensitive = false;
+ }
+ });
- this.remove_pie_button = builder.get_object("remove-pie-button") as Gtk.ToolButton;
- this.remove_pie_button.clicked.connect(on_remove_pie_button_clicked);
+ scroll_area = builder.get_object("theme-scrolledwindow") as Gtk.ScrolledWindow;
+ scroll_area.add(this.theme_list);
+
+ this.autostart = (builder.get_object("autostart-checkbox") as Gtk.ToggleButton);
+ this.autostart.toggled.connect(on_autostart_toggled);
+
+ this.indicator = (builder.get_object("indicator-checkbox") as Gtk.ToggleButton);
+ this.indicator.toggled.connect(on_indicator_toggled);
+
+ this.captions = (builder.get_object("captions-checkbox") as Gtk.ToggleButton);
+ this.captions.toggled.connect(on_captions_toggled);
+
+ var scale_slider = (builder.get_object("scale-hscale") as Gtk.Scale);
+ scale_slider.set_range(0.5, 2.0);
+ scale_slider.set_increments(0.05, 0.25);
+ scale_slider.set_value(Config.global.global_scale);
+
+ bool changing = false;
+ bool changed_again = false;
+
+ scale_slider.value_changed.connect(() => {
+ if (!changing) {
+ changing = true;
+ Timeout.add(300, () => {
+ if (changed_again) {
+ changed_again = false;
+ return true;
+ }
+
+ Config.global.global_scale = scale_slider.get_value();
+ Config.global.load_themes(Config.global.theme.name);
+ changing = false;
+ return false;
+ });
+ } else {
+ changed_again = true;
+ }
+ });
- (builder.get_object("add-pie-button") as Gtk.ToolButton).clicked.connect(on_add_pie_button_clicked);
+ var range_slider = (builder.get_object("range-hscale") as Gtk.Scale);
+ range_slider.set_range(0, 2000);
+ range_slider.set_increments(10, 100);
+ range_slider.set_value(Config.global.activation_range);
+ range_slider.value_changed.connect(() => {
+ Config.global.activation_range = (int)range_slider.get_value();
+ });
+
+ var range_slices = (builder.get_object("range-slices") as Gtk.Scale);
+ range_slices.set_range(12, 96);
+ range_slices.set_increments(4, 12);
+ range_slices.set_value(Config.global.max_visible_slices);
+ range_slices.value_changed.connect(() => {
+ Config.global.max_visible_slices = (int)range_slices.get_value();
+ });
this.window.hide.connect(() => {
// save settings on close
@@ -143,6 +230,85 @@ public class PreferencesWindow : GLib.Object {
var style = this.preview_background.get_style_context();
this.preview_background.override_background_color(Gtk.StateFlags.NORMAL, style.get_background_color(Gtk.StateFlags.NORMAL));
+
+ this.indicator.active = Config.global.show_indicator;
+ this.autostart.active = Config.global.auto_start;
+ this.captions.active = Config.global.show_captions;
+
+ if (Config.global.theme.has_slice_captions) {
+ this.captions.sensitive = true;
+ } else {
+ this.captions.sensitive = false;
+ }
+
+ if (Deamon.stack_switcher) {
+ this.stack.set_visible_child_full("2", Gtk.StackTransitionType.NONE);
+ } else {
+ this.notebook.set_current_page(1);
+ }
+ this.pie_list.has_focus = true;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Creates or deletes the autostart file. This code is inspired
+ /// by project synapse as well.
+ /////////////////////////////////////////////////////////////////////
+
+ private void on_autostart_toggled(Gtk.ToggleButton check_box) {
+
+ bool active = check_box.active;
+ if (!active && FileUtils.test(Paths.autostart, FileTest.EXISTS)) {
+ Config.global.auto_start = false;
+ // delete the autostart file
+ FileUtils.remove (Paths.autostart);
+ }
+ else if (active && !FileUtils.test(Paths.autostart, FileTest.EXISTS)) {
+ Config.global.auto_start = true;
+
+ string autostart_entry =
+ "#!/usr/bin/env xdg-open\n" +
+ "[Desktop Entry]\n" +
+ "Name=Gnome-Pie\n" +
+ "Exec=" + Paths.executable + "\n" +
+ "Encoding=UTF-8\n" +
+ "Type=Application\n" +
+ "X-GNOME-Autostart-enabled=true\n" +
+ "Icon=gnome-pie\n";
+
+ // create the autostart file
+ string autostart_dir = GLib.Path.get_dirname(Paths.autostart);
+ if (!FileUtils.test(autostart_dir, FileTest.EXISTS | FileTest.IS_DIR)) {
+ DirUtils.create_with_parents(autostart_dir, 0755);
+ }
+
+ try {
+ FileUtils.set_contents(Paths.autostart, autostart_entry);
+ FileUtils.chmod(Paths.autostart, 0755);
+ } catch (Error e) {
+ var d = new Gtk.MessageDialog (this.window, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE,
+ "%s", e.message);
+ d.run ();
+ d.destroy ();
+ }
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Shows or hides the indicator.
+ /////////////////////////////////////////////////////////////////////
+
+ private void on_indicator_toggled(Gtk.ToggleButton check_box) {
+ var check = check_box as Gtk.CheckButton;
+ Config.global.show_indicator = check.active;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Shows or hides the captions of Slices.
+ /////////////////////////////////////////////////////////////////////
+
+ private void on_captions_toggled(Gtk.ToggleButton check_box) {
+ var check = check_box as Gtk.CheckButton;
+ Config.global.show_captions = check.active;
}
/////////////////////////////////////////////////////////////////////
@@ -156,33 +322,13 @@ public class PreferencesWindow : GLib.Object {
this.no_pie_label.hide();
this.preview_box.hide();
- this.name_button.sensitive = false;
- this.hotkey_button.sensitive = false;
- this.icon_button.sensitive = false;
this.remove_pie_button.sensitive = false;
+ this.edit_pie_button.sensitive = false;
if (id == "") {
- this.id_label.label = "";
- this.name_label.label = _("No Pie selected.");
- this.hotkey_label.set_markup("");
- this.icon.icon_name = "stock_unknown";
-
this.no_pie_label.show();
} else {
var pie = PieManager.all_pies[selected_id];
- this.id_label.label = ("ID: %s").printf(pie.id);
- this.name_label.label = PieManager.get_name_of(pie.id);
- this.hotkey_label.set_markup(PieManager.get_accelerator_label_of(pie.id));
-
- if (pie.icon.contains("/"))
- try {
- this.icon.pixbuf = new Gdk.Pixbuf.from_file_at_scale(pie.icon,
- this.icon.get_pixel_size(), this.icon.get_pixel_size(), true);
- } catch (GLib.Error error) {
- warning(error.message);
- }
- else
- this.icon.icon_name = pie.icon;
this.preview.set_pie(id);
this.preview_box.show();
@@ -191,10 +337,8 @@ public class PreferencesWindow : GLib.Object {
this.no_slice_label.show();
}
- this.name_button.sensitive = true;
- this.hotkey_button.sensitive = true;
- this.icon_button.sensitive = true;
this.remove_pie_button.sensitive = true;
+ this.edit_pie_button.sensitive = true;
}
}
@@ -202,17 +346,19 @@ public class PreferencesWindow : GLib.Object {
/// Called when the add Pie button is clicked.
/////////////////////////////////////////////////////////////////////
- private void on_add_pie_button_clicked(Gtk.ToolButton button) {
+ private void on_add_pie_button_clicked(Gtk.Button button) {
var new_pie = PieManager.create_persistent_pie(_("New Pie"), "stock_unknown", null);
this.pie_list.reload_all();
this.pie_list.select(new_pie.id);
+
+ this.on_edit_pie_button_clicked();
}
/////////////////////////////////////////////////////////////////////
/// Called when the remove Pie button is clicked.
/////////////////////////////////////////////////////////////////////
- private void on_remove_pie_button_clicked(Gtk.ToolButton button) {
+ private void on_remove_pie_button_clicked(Gtk.Button button) {
if (this.selected_id != "") {
var dialog = new Gtk.MessageDialog((Gtk.Window)this.window.get_toplevel(), Gtk.DialogFlags.MODAL,
Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO,
@@ -232,74 +378,25 @@ public class PreferencesWindow : GLib.Object {
}
/////////////////////////////////////////////////////////////////////
- /// Called when rename Pie button is clicked.
+ /// Called when the edit pie button is clicked.
/////////////////////////////////////////////////////////////////////
- private void on_rename_button_clicked(Gtk.Button button) {
- if (this.rename_window == null) {
- this.rename_window = new RenameWindow();
- this.rename_window.set_parent(window);
- this.rename_window.on_ok.connect((name) => {
+ private void on_edit_pie_button_clicked(Gtk.Button? button = null) {
+ if (this.pie_options_window == null) {
+ this.pie_options_window = new PieOptionsWindow();
+ this.pie_options_window.set_parent(window);
+ this.pie_options_window.on_ok.connect((trigger, name, icon) => {
var pie = PieManager.all_pies[selected_id];
pie.name = name;
- PieManager.create_launcher(pie.id);
- this.name_label.label = name;
- this.pie_list.reload_all();
- });
- }
-
- this.rename_window.set_pie(selected_id);
- this.rename_window.show();
- }
-
- /////////////////////////////////////////////////////////////////////
- /// Called when the hotkey button is clicked.
- /////////////////////////////////////////////////////////////////////
-
- private void on_key_button_clicked(Gtk.Button button) {
- if (this.trigger_window == null) {
- this.trigger_window = new TriggerSelectWindow();
- this.trigger_window.set_parent(window);
- this.trigger_window.on_ok.connect((trigger) => {
- PieManager.bind_trigger(trigger, selected_id);
- this.hotkey_label.set_markup(trigger.label_with_specials);
- });
- }
-
- this.trigger_window.set_pie(selected_id);
- this.trigger_window.show();
- }
-
- /////////////////////////////////////////////////////////////////////
- /// Called when the general settings button is clicked.
- /////////////////////////////////////////////////////////////////////
-
- private void on_settings_button_clicked(Gtk.ToolButton button) {
- if (this.settings_window == null) {
- this.settings_window = new SettingsWindow();
- this.settings_window.set_parent(this.window.get_toplevel() as Gtk.Window);
- }
-
- this.settings_window.show();
- }
-
- /////////////////////////////////////////////////////////////////////
- /// Called when the icon button is clicked.
- /////////////////////////////////////////////////////////////////////
-
- private void on_icon_button_clicked(Gtk.Button button) {
- if (this.icon_window == null) {
- this.icon_window = new IconSelectWindow(this.window);
- this.icon_window.on_ok.connect((icon) => {
- var pie = PieManager.all_pies[selected_id];
pie.icon = icon;
+ PieManager.bind_trigger(trigger, selected_id);
PieManager.create_launcher(pie.id);
this.pie_list.reload_all();
});
}
- this.icon_window.show();
- this.icon_window.set_icon(PieManager.all_pies[selected_id].icon);
+ this.pie_options_window.set_pie(selected_id);
+ this.pie_options_window.show();
}
}