From d6b2677825cbb423e2099563c16321c3e23d7899 Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Sun, 20 Nov 2011 15:50:38 +0100 Subject: Imported Upstream version 0.3.1 --- src/pies/defaultConfig.vala | 12 ++++++------ src/pies/load.vala | 2 +- src/pies/pieManager.vala | 21 +++++++++++++++++++-- 3 files changed, 26 insertions(+), 9 deletions(-) (limited to 'src/pies') diff --git a/src/pies/defaultConfig.vala b/src/pies/defaultConfig.vala index bd981b5..87fd30d 100644 --- a/src/pies/defaultConfig.vala +++ b/src/pies/defaultConfig.vala @@ -26,14 +26,14 @@ namespace Pies { public void create_default_config() { // add a pie with playback controls - var multimedia = PieManager.create_persistent_pie(_("Multimedia"), "stock_media-play", "m"); + var multimedia = PieManager.create_persistent_pie(_("Multimedia"), "stock_media-play", new Trigger.from_string("m")); multimedia.add_action(new KeyAction(_("Next Track"), "stock_media-next", "XF86AudioNext", true)); multimedia.add_action(new KeyAction(_("Stop"), "stock_media-stop", "XF86AudioStop")); multimedia.add_action(new KeyAction(_("Previous Track"), "stock_media-prev", "XF86AudioPrev")); multimedia.add_action(new KeyAction(_("Play/Pause"), "stock_media-play", "XF86AudioPlay")); // add a pie with the users default applications - var apps = PieManager.create_persistent_pie(_("Applications"), "applications-accessories", "a"); + var apps = PieManager.create_persistent_pie(_("Applications"), "applications-accessories", new Trigger.from_string("a")); apps.add_action(ActionRegistry.default_for_mime_type("text/plain")); apps.add_action(ActionRegistry.default_for_mime_type("audio/ogg")); apps.add_action(ActionRegistry.default_for_mime_type("video/ogg")); @@ -42,20 +42,20 @@ namespace Pies { apps.add_action(ActionRegistry.default_for_uri("mailto")); // add a pie with the users bookmarks and devices - var bookmarks = PieManager.create_persistent_pie(_("Bookmarks"), "user-bookmarks", "b"); + var bookmarks = PieManager.create_persistent_pie(_("Bookmarks"), "user-bookmarks", new Trigger.from_string("b")); bookmarks.add_group(new BookmarkGroup(bookmarks.id)); bookmarks.add_group(new DevicesGroup(bookmarks.id)); // add a pie with session controls - var session = PieManager.create_persistent_pie(_("Session"), "gnome-session-halt", "q"); + var session = PieManager.create_persistent_pie(_("Session"), "gnome-session-halt", new Trigger.from_string("q")); session.add_group(new SessionGroup(session.id)); // add a pie with a main menu - var menu = PieManager.create_persistent_pie(_("Main Menu"), "alacarte", "space"); + var menu = PieManager.create_persistent_pie(_("Main Menu"), "alacarte", new Trigger.from_string("space")); menu.add_group(new MenuGroup(menu.id)); // add a pie with window controls - var window = PieManager.create_persistent_pie(_("Window"), "gnome-window-manager", "w"); + var window = PieManager.create_persistent_pie(_("Window"), "gnome-window-manager", new Trigger.from_string("w")); window.add_action(new KeyAction(_("Scale"), "top", "s")); window.add_action(new KeyAction(_("Minimize"), "bottom", "F9", true)); window.add_action(new KeyAction(_("Close"), "window-close", "F4")); diff --git a/src/pies/load.vala b/src/pies/load.vala index 912ddf0..98fd72f 100644 --- a/src/pies/load.vala +++ b/src/pies/load.vala @@ -115,7 +115,7 @@ namespace Pies { } // add a new Pie with the loaded properties - var pie = PieManager.create_persistent_pie(name, icon, hotkey, id); + var pie = PieManager.create_persistent_pie(name, icon, new Trigger.from_string(hotkey), id); // and parse all child elements for (Xml.Node* slice = node->children; slice != null; slice = slice->next) { diff --git a/src/pies/pieManager.vala b/src/pies/pieManager.vala index eb031d0..5f84ea0 100644 --- a/src/pies/pieManager.vala +++ b/src/pies/pieManager.vala @@ -102,6 +102,14 @@ public class PieManager : GLib.Object { return bindings.get_accelerator_label_of(id); } + ///////////////////////////////////////////////////////////////////// + /// Returns true if the pie with the given id is in turbo mode. + ///////////////////////////////////////////////////////////////////// + + public static bool get_is_turbo(string id) { + return bindings.get_is_turbo(id); + } + ///////////////////////////////////////////////////////////////////// /// Returns the name of the Pie with the given ID. ///////////////////////////////////////////////////////////////////// @@ -112,15 +120,24 @@ public class PieManager : GLib.Object { else return pie.name; } + ///////////////////////////////////////////////////////////////////// + /// Returns the name ID of the Pie bound to the given Trigger. + /// Returns "" if there is nothing bound to this trigger. + ///////////////////////////////////////////////////////////////////// + + public static string get_assigned_id(Trigger trigger) { + return bindings.get_assigned_id(trigger); + } + ///////////////////////////////////////////////////////////////////// /// Creates a new Pie which is displayed in the configuration dialog /// and gets saved. ///////////////////////////////////////////////////////////////////// - public static Pie create_persistent_pie(string name, string icon_name, string hotkey, string? desired_id = null) { + public static Pie create_persistent_pie(string name, string icon_name, Trigger? hotkey, string? desired_id = null) { Pie pie = create_pie(name, icon_name, 100, 999, desired_id); - if (hotkey != "") bindings.bind(hotkey, pie.id); + if (hotkey != null) bindings.bind(hotkey, pie.id); create_launcher(pie.id); -- cgit v1.2.3 From 60560a030fda3c539ff9dc1563b9926414a193da Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Sat, 21 Jan 2012 19:07:09 +0100 Subject: Imported Upstream version 0.4.0 --- src/pies/load.vala | 31 ++++++--------------------- src/pies/pie.vala | 38 ++++++++++++++++++++++++++++------ src/pies/pieManager.vala | 54 ++++++++++++++++++++++++++++++++++++++++++------ src/pies/save.vala | 8 +++---- 4 files changed, 90 insertions(+), 41 deletions(-) (limited to 'src/pies') diff --git a/src/pies/load.vala b/src/pies/load.vala index 98fd72f..b606cf5 100644 --- a/src/pies/load.vala +++ b/src/pies/load.vala @@ -80,7 +80,7 @@ namespace Pies { string name = ""; string icon = ""; string id = ""; - int quick_action = -1; + int quickaction = -1; // parse all attributes of this node for (Xml.Attr* attribute = node->properties; attribute != null; attribute = attribute->next) { @@ -92,7 +92,7 @@ namespace Pies { hotkey = attr_content; break; case "quickaction": - quick_action = int.parse(attr_content); + quickaction = int.parse(attr_content); break; case "name": name = attr_content; @@ -145,7 +145,7 @@ namespace Pies { string icon=""; string command=""; string type=""; - bool quick_action = false; + bool quickaction = false; // parse all attributes of this node for (Xml.Attr* attribute = slice->properties; attribute != null; attribute = attribute->next) { @@ -166,7 +166,7 @@ namespace Pies { type = attr_content; break; case "quickaction": - quick_action = bool.parse(attr_content); + quickaction = bool.parse(attr_content); break; default: warning("Invalid attribute \"" + attr_name + "\" in element in pies.conf!"); @@ -174,19 +174,8 @@ namespace Pies { } } - Action action = null; - // create a new Action according to the loaded type - foreach (var action_type in ActionRegistry.types) { - if (ActionRegistry.settings_names[action_type] == type) { - - action = GLib.Object.new(action_type, "name", name, - "icon", icon, - "real_command", command, - "is_quick_action", quick_action) as Action; - break; - } - } + Action action = ActionRegistry.create_action(type, name, icon, command, quickaction); if (action != null) pie.add_action(action); } @@ -213,15 +202,7 @@ namespace Pies { } } - ActionGroup group = null; - - // create a new ActionGroup according to the loaded type - foreach (var group_type in GroupRegistry.types) { - if (GroupRegistry.settings_names[group_type] == type) { - group = GLib.Object.new(group_type, "parent_id", pie.id) as ActionGroup; - break; - } - } + ActionGroup group = GroupRegistry.create_group(type, pie.id); if (group != null) pie.add_group(group); } diff --git a/src/pies/pie.vala b/src/pies/pie.vala index 0f87d8f..fa205c7 100644 --- a/src/pies/pie.vala +++ b/src/pies/pie.vala @@ -29,14 +29,14 @@ public class Pie : GLib.Object { /// The name of this Pie. It has not to be unique. ///////////////////////////////////////////////////////////////////// - public string name { get; construct; } + public string name { get; set; } ///////////////////////////////////////////////////////////////////// /// The name of the icon to be used for this Pie. It should exist in /// the users current icon theme, else a standard icon will be used. ///////////////////////////////////////////////////////////////////// - public string icon { get; construct; } + public string icon { get; set; } ///////////////////////////////////////////////////////////////////// /// The ID of this Pie. It has to be unique among all Pies. This ID @@ -77,18 +77,44 @@ public class Pie : GLib.Object { /// Adds an Action to this Pie. ///////////////////////////////////////////////////////////////////// - public void add_action(Action action) { + public void add_action(Action action, int at_position = -1) { var group = new ActionGroup(this.id); group.add_action(action); - this.add_group(group); + this.add_group(group, at_position); } ///////////////////////////////////////////////////////////////////// /// Adds an ActionGroup to this Pie. ///////////////////////////////////////////////////////////////////// - public void add_group(ActionGroup group) { - this.action_groups.add(group); + public void add_group(ActionGroup group, int at_position = -1) { + if (group.has_quickaction()) { + foreach (var action_group in action_groups) + action_group.disable_quickactions(); + } + + if (at_position < 0 || at_position >= this.action_groups.size) + this.action_groups.add(group); + else + this.action_groups.insert(at_position, group); + } + + public void remove_group(int index) { + if (this.action_groups.size > index) + this.action_groups.remove_at(index); + } + + public void move_group(int from, int to) { + if (this.action_groups.size > from && this.action_groups.size > to) { + var tmp = this.action_groups[from]; + this.remove_group(from); + this.add_group(tmp, to); + } + } + + public void update_group(ActionGroup group, int index) { + if (this.action_groups.size > index) + this.action_groups.set(index, group); } } diff --git a/src/pies/pieManager.vala b/src/pies/pieManager.vala index 5f84ea0..0263d23 100644 --- a/src/pies/pieManager.vala +++ b/src/pies/pieManager.vala @@ -31,6 +31,13 @@ public class PieManager : GLib.Object { public static Gee.HashMap all_pies { get; private set; } + ///////////////////////////////////////////////////////////////////// + /// Stores all PieWindows which are currently opened. Should be + /// rarely more than two... + ///////////////////////////////////////////////////////////////////// + + public static Gee.HashSet opened_windows { get; private set; } + ///////////////////////////////////////////////////////////////////// /// Stores all global hotkeys. ///////////////////////////////////////////////////////////////////// @@ -42,7 +49,7 @@ public class PieManager : GLib.Object { /// will be false already. ///////////////////////////////////////////////////////////////////// - private static bool a_pie_is_opened = false; + private static bool a_pie_is_active = false; ///////////////////////////////////////////////////////////////////// /// Initializes all Pies. They are loaded from the pies.conf file. @@ -50,6 +57,7 @@ public class PieManager : GLib.Object { public static void init() { all_pies = new Gee.HashMap(); + opened_windows = new Gee.HashSet(); bindings = new BindingManager(); // load all Pies from th pies.conf file @@ -66,19 +74,27 @@ public class PieManager : GLib.Object { ///////////////////////////////////////////////////////////////////// public static void open_pie(string id) { - if (!a_pie_is_opened) { + if (!a_pie_is_active) { Pie? pie = all_pies[id]; if (pie != null) { - a_pie_is_opened = true; + a_pie_is_active = true; var window = new PieWindow(); window.load_pie(pie); window.open(); + opened_windows.add(window); + + window.on_closed.connect(() => { + opened_windows.remove(window); + }); + window.on_closing.connect(() => { - a_pie_is_opened = false; + a_pie_is_active = false; }); + + } else { warning("Failed to open pie with ID \"" + id + "\": ID does not exist!"); } @@ -102,6 +118,15 @@ public class PieManager : GLib.Object { return bindings.get_accelerator_label_of(id); } + ///////////////////////////////////////////////////////////////////// + /// Bind the Pie with the given ID to the given trigger. + ///////////////////////////////////////////////////////////////////// + + public static void bind_trigger(Trigger trigger, string id) { + bindings.unbind(id); + bindings.bind(trigger, id); + } + ///////////////////////////////////////////////////////////////////// /// Returns true if the pie with the given id is in turbo mode. ///////////////////////////////////////////////////////////////////// @@ -110,6 +135,15 @@ public class PieManager : GLib.Object { return bindings.get_is_turbo(id); } + ///////////////////////////////////////////////////////////////////// + /// Returns true if the pie with the given id opens in the middle of + /// the screen. + ///////////////////////////////////////////////////////////////////// + + public static bool get_is_centered(string id) { + return bindings.get_is_centered(id); + } + ///////////////////////////////////////////////////////////////////// /// Returns the name of the Pie with the given ID. ///////////////////////////////////////////////////////////////////// @@ -212,7 +246,11 @@ public class PieManager : GLib.Object { } } - private static void create_launcher(string id) { + ///////////////////////////////////////////////////////////////////// + /// Creates a desktop file for which opens the Pie with given ID. + ///////////////////////////////////////////////////////////////////// + + public static void create_launcher(string id) { if (all_pies.has_key(id)) { Pie? pie = all_pies[id]; @@ -220,7 +258,7 @@ public class PieManager : GLib.Object { "#!/usr/bin/env xdg-open\n" + "[Desktop Entry]\n" + "Name=%s\n".printf(pie.name) + - "Exec=gnome-pie -o %s\n".printf(pie.id) + + "Exec=%s -o %s\n".printf(Paths.executable, pie.id) + "Encoding=UTF-8\n" + "Type=Application\n" + "Icon=%s\n".printf(pie.icon); @@ -237,6 +275,10 @@ public class PieManager : GLib.Object { } } + ///////////////////////////////////////////////////////////////////// + /// Deletes the desktop file for the Pie with the given ID. + ///////////////////////////////////////////////////////////////////// + private static void remove_launcher(string id) { string launcher = Paths.launchers + "/%s.desktop".printf(id); if (FileUtils.test(launcher, FileTest.EXISTS)) { diff --git a/src/pies/save.vala b/src/pies/save.vala index d691a95..c940e5a 100644 --- a/src/pies/save.vala +++ b/src/pies/save.vala @@ -55,18 +55,18 @@ namespace Pies { if (group.get_type().depth() == 2) { foreach (var action in group.actions) { writer.start_element("slice"); - writer.write_attribute("type", ActionRegistry.settings_names[action.get_type()]); - if (ActionRegistry.icon_name_editables[action.get_type()]) { + writer.write_attribute("type", ActionRegistry.descriptions[action.get_type().name()].id); + if (ActionRegistry.descriptions[action.get_type().name()].icon_name_editable) { writer.write_attribute("name", action.name); writer.write_attribute("icon", action.icon); } writer.write_attribute("command", action.real_command); - writer.write_attribute("quickAction", action.is_quick_action ? "true" : "false"); + writer.write_attribute("quickAction", action.is_quickaction ? "true" : "false"); writer.end_element(); } } else { writer.start_element("group"); - writer.write_attribute("type", GroupRegistry.settings_names[group.get_type()]); + writer.write_attribute("type", GroupRegistry.descriptions[group.get_type().name()].id); writer.end_element(); } } -- cgit v1.2.3