summaryrefslogtreecommitdiff
path: root/src/actionGroups
diff options
context:
space:
mode:
Diffstat (limited to 'src/actionGroups')
-rw-r--r--src/actionGroups/actionGroup.vala113
-rw-r--r--src/actionGroups/bookmarkGroup.vala151
-rw-r--r--src/actionGroups/clipboardGroup.vala194
-rw-r--r--src/actionGroups/devicesGroup.vala124
-rw-r--r--src/actionGroups/groupRegistry.vala110
-rw-r--r--src/actionGroups/menuGroup.vala250
-rw-r--r--src/actionGroups/sessionGroup.vala76
-rw-r--r--src/actionGroups/windowListGroup.vala193
8 files changed, 1211 insertions, 0 deletions
diff --git a/src/actionGroups/actionGroup.vala b/src/actionGroups/actionGroup.vala
new file mode 100644
index 0000000..85488ad
--- /dev/null
+++ b/src/actionGroups/actionGroup.vala
@@ -0,0 +1,113 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////////
+// A base class storing a set of Actions. Derived classes may define
+// how these Actions are created. This base class serves for custom
+// actions, defined by the user.
+/////////////////////////////////////////////////////////////////////////
+
+public class ActionGroup : GLib.Object {
+
+ /////////////////////////////////////////////////////////////////////
+ /// A list of all stored actions.
+ /////////////////////////////////////////////////////////////////////
+
+ public Gee.ArrayList<Action?> actions { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The ID of the pie to which this group is attached.
+ /////////////////////////////////////////////////////////////////////
+
+ public string parent_id { get; construct set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public ActionGroup(string parent_id) {
+ GLib.Object(parent_id : parent_id);
+ }
+
+ construct {
+ this.actions = new Gee.ArrayList<Action?>();
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// This one is called, when the ActionGroup is deleted.
+ /////////////////////////////////////////////////////////////////////
+
+ public virtual void on_remove() {}
+
+ /////////////////////////////////////////////////////////////////////
+ /// This one is called, when the ActionGroup is saved.
+ /////////////////////////////////////////////////////////////////////
+
+ public virtual void on_save(Xml.TextWriter writer) {
+ writer.write_attribute("type", GroupRegistry.descriptions[this.get_type().name()].id);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// This one is called, when the ActionGroup is loaded.
+ /////////////////////////////////////////////////////////////////////
+
+ public virtual void on_load(Xml.Node* data) {}
+
+ /////////////////////////////////////////////////////////////////////
+ /// Adds a new Action to the group.
+ /////////////////////////////////////////////////////////////////////
+
+ public void add_action(Action new_action) {
+ this.actions.add(new_action);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Removes all Actions from the group.
+ /////////////////////////////////////////////////////////////////////
+
+ public void delete_all() {
+ actions.clear();
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Makes all contained Slices no Quick Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ public void disable_quickactions() {
+ foreach (var action in actions) {
+ action.is_quickaction = false;
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns true, if one o the contained Slices is a Quick Action
+ /////////////////////////////////////////////////////////////////////
+
+ public bool has_quickaction() {
+ foreach (var action in actions) {
+ if (action.is_quickaction) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
+
+}
diff --git a/src/actionGroups/bookmarkGroup.vala b/src/actionGroups/bookmarkGroup.vala
new file mode 100644
index 0000000..791d609
--- /dev/null
+++ b/src/actionGroups/bookmarkGroup.vala
@@ -0,0 +1,151 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////////
+/// A group of Actions, which represent the users gtk-bookmarks, his home
+/// directory, desktop and trash. It stay up-to-date, even if the
+/// bookmarks change.
+/////////////////////////////////////////////////////////////////////////
+
+public class BookmarkGroup : ActionGroup {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of ActionGroup. It sets the display
+ /// name for this ActionGroup, it's icon name and the string used in
+ /// the pies.conf file for this kind of ActionGroups.
+ /////////////////////////////////////////////////////////////////////
+
+ public static GroupRegistry.TypeDescription register() {
+ var description = new GroupRegistry.TypeDescription();
+ description.name = _("Group: Bookmarks");
+ description.icon = "user-bookmarks";
+ description.description = _("Shows a Slice for each of your directory Bookmarks.");
+ description.id = "bookmarks";
+ return description;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Two members needed to avoid useless, frequent changes of the
+ /// stored Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ private bool changing = false;
+ private bool changed_again = false;
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public BookmarkGroup(string parent_id) {
+ GLib.Object(parent_id : parent_id);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Construct block loads the bookmarks of the user and adds a file
+ /// monitor in order to update the BookmarkGroup when the bookmarks
+ /// of the user change.
+ /////////////////////////////////////////////////////////////////////
+
+ construct {
+ this.load();
+
+ // add monitor
+ var bookmark_file = GLib.File.new_for_path(
+ GLib.Environment.get_home_dir()).get_child(".gtk-bookmarks");
+
+ if (bookmark_file.query_exists()) {
+ try {
+ var monitor = bookmark_file.monitor(GLib.FileMonitorFlags.NONE);
+ monitor.changed.connect(this.reload);
+ } catch (GLib.Error e) {
+ warning(e.message);
+ }
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Adds Actions for each gtk-bookmark of the user and for his home
+ /// folder, desktop and trash.
+ /////////////////////////////////////////////////////////////////////
+
+ private void load() {
+ // add home folder
+ this.add_action(ActionRegistry.new_for_uri("file://" + GLib.Environment.get_home_dir()));
+
+ // add .gtk-bookmarks
+ var bookmark_file = GLib.File.new_for_path(
+ GLib.Environment.get_home_dir()).get_child(".gtk-bookmarks");
+
+ if (!bookmark_file.query_exists()) {
+ warning("Failed to find file \".gtk-bookmarks\"!");
+ return;
+ }
+
+ try {
+ var dis = new DataInputStream(bookmark_file.read());
+ string line;
+ while ((line = dis.read_line(null)) != null) {
+ var parts = line.split(" ");
+
+ string uri = parts[0];
+ string name = parts[1];
+
+ this.add_action(ActionRegistry.new_for_uri(uri, name));
+ }
+ } catch (Error e) {
+ error ("%s", e.message);
+ }
+
+ // add trash
+ this.add_action(ActionRegistry.new_for_uri("trash://"));
+
+ // add desktop
+ this.add_action(ActionRegistry.new_for_uri("file://" + GLib.Environment.get_user_special_dir(GLib.UserDirectory.DESKTOP)));
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Reloads all Bookmarks. Is called when the user's gtk-bookmarks
+ /// file changes.
+ /////////////////////////////////////////////////////////////////////
+
+ private void reload() {
+ // avoid too frequent changes...
+ if (!this.changing) {
+ this.changing = true;
+ Timeout.add(200, () => {
+ if (this.changed_again) {
+ this.changed_again = false;
+ return true;
+ }
+
+ // reload
+ message("Bookmarks changed...");
+ this.delete_all();
+ this.load();
+
+ this.changing = false;
+ return false;
+ });
+ } else {
+ this.changed_again = true;
+ }
+ }
+}
+
+}
diff --git a/src/actionGroups/clipboardGroup.vala b/src/actionGroups/clipboardGroup.vala
new file mode 100644
index 0000000..58409de
--- /dev/null
+++ b/src/actionGroups/clipboardGroup.vala
@@ -0,0 +1,194 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////////
+/// This Group keeps a history of the last used Clipboard entries.
+/// Experimental. Not enabled.
+/////////////////////////////////////////////////////////////////////////
+
+public class ClipboardGroup : ActionGroup {
+
+ /////////////////////////////////////////////////////////////////////
+
+ private class ClipboardItem : GLib.Object {
+
+ public string name { get; protected set; }
+ public string icon { get; protected set; }
+
+ protected Gtk.Clipboard clipboard { get; set; }
+ protected static Key paste_key = new Key.from_string("<Control>v");
+
+ public virtual void paste() {}
+ }
+
+ /////////////////////////////////////////////////////////////////////
+
+ private class TextClipboardItem : ClipboardItem {
+
+ public TextClipboardItem(Gtk.Clipboard clipboard) {
+ GLib.Object(clipboard : clipboard,
+ name : clipboard.wait_for_text(),
+ icon : "edit-paste");
+
+ // check whether a file has been copied and search for a cool icon
+ var first_line = this.name.substring(0, this.name.index_of("\n"));
+ var file = GLib.File.new_for_path(first_line);
+
+ if (file.query_exists()) {
+ try {
+ var info = file.query_info("standard::icon", 0);
+ this.icon = Icon.get_icon_name(info.get_icon());
+ } catch (Error e) {
+ warning("Failed to generate icon for ClipboardGroupItem.");
+ }
+ }
+ }
+
+ public override void paste() {
+ clipboard.set_text(name, name.length);
+ paste_key.press();
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+
+ private class ImageClipboardItem : ClipboardItem {
+
+ private Gdk.Pixbuf image { get; set; }
+
+ public ImageClipboardItem(Gtk.Clipboard clipboard) {
+ GLib.Object(clipboard : clipboard,
+ name : _("Image data"),
+ icon : "image-viewer");
+ this.image = clipboard.wait_for_image();
+ }
+
+ public override void paste() {
+ clipboard.set_image(image);
+ paste_key.press();
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The maximum remembered items of the clipboard.
+ /////////////////////////////////////////////////////////////////////
+
+ public int max_items {get; set; default=8; }
+
+ /////////////////////////////////////////////////////////////////////
+
+ public ClipboardGroup(string parent_id) {
+ GLib.Object(parent_id : parent_id);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of ActionGroup. It sets the display
+ /// name for this ActionGroup, it's icon name and the string used in
+ /// the pies.conf file for this kind of ActionGroups.
+ /////////////////////////////////////////////////////////////////////
+
+ public static GroupRegistry.TypeDescription register() {
+ var description = new GroupRegistry.TypeDescription();
+ description.name = _("Group: Clipboard");
+ description.icon = "edit-paste";
+ description.description = _("Manages your Clipboard.");
+ description.id = "clipboard";
+ return description;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The clipboard to be monitored.
+ /////////////////////////////////////////////////////////////////////
+
+ private Gtk.Clipboard clipboard;
+
+ private bool ignore_next_change = false;
+
+ private Gee.ArrayList<ClipboardItem?> items;
+
+ construct {
+ this.items = new Gee.ArrayList<ClipboardItem?>();
+ this.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD);
+ this.clipboard.owner_change.connect(this.on_change);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// This one is called, when the ActionGroup is saved.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void on_save(Xml.TextWriter writer) {
+ base.on_save(writer);
+ writer.write_attribute("max_items", this.max_items.to_string());
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// This one is called, when the ActionGroup is loaded.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void on_load(Xml.Node* data) {
+ for (Xml.Attr* attribute = data->properties; attribute != null; attribute = attribute->next) {
+ string attr_name = attribute->name.down();
+ string attr_content = attribute->children->content;
+
+ if (attr_name == "max_items") {
+ this.max_items = int.parse(attr_content);
+ }
+ }
+ }
+
+ private void on_change() {
+ if (ignore_next_change) {
+ ignore_next_change = false;
+ return;
+ }
+
+ if (this.clipboard.wait_is_text_available()) {
+ if (clipboard.wait_for_text() != null) {
+ add_item(new TextClipboardItem(this.clipboard));
+ }
+ } else if (this.clipboard.wait_is_image_available()) {
+ add_item(new ImageClipboardItem(this.clipboard));
+ }
+ }
+
+ private void add_item(ClipboardItem item) {
+
+ // remove one item if there are too many
+ if (this.items.size == this.max_items) {
+ this.items.remove_at(0);
+ }
+
+ this.items.add(item);
+
+ // update slices
+ this.delete_all();
+
+ for (int i=this.items.size-1; i>=0; --i) {
+ var action = new SigAction(items[i].name, items[i].icon, i.to_string());
+ action.activated.connect(() => {
+ ignore_next_change = true;
+ this.items[int.parse(action.real_command)].paste();
+ });
+ this.add_action(action);
+ }
+
+ }
+}
+
+}
diff --git a/src/actionGroups/devicesGroup.vala b/src/actionGroups/devicesGroup.vala
new file mode 100644
index 0000000..e18f4c0
--- /dev/null
+++ b/src/actionGroups/devicesGroup.vala
@@ -0,0 +1,124 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////
+/// An ActionGroup which contains all currently plugged-in devices,
+/// such as CD-ROM's or USB-sticks.
+/////////////////////////////////////////////////////////////////////
+
+public class DevicesGroup : ActionGroup {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of ActionGroup. It sets the display
+ /// name for this ActionGroup, it's icon name and the string used in
+ /// the pies.conf file for this kind of ActionGroups.
+ /////////////////////////////////////////////////////////////////////
+
+ public static GroupRegistry.TypeDescription register() {
+ var description = new GroupRegistry.TypeDescription();
+ description.name = _("Group: Devices");
+ description.icon = "drive-harddisk";
+ description.description = _("Shows a Slice for each plugged in devices, like USB-Sticks.");
+ description.id = "devices";
+ return description;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Two members needed to avoid useless, frequent changes of the
+ /// stored Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ private bool changing = false;
+ private bool changed_again = false;
+
+ /////////////////////////////////////////////////////////////////////
+ /// The VolumeMonitor used to check for added or removed devices.
+ /////////////////////////////////////////////////////////////////////
+
+ private GLib.VolumeMonitor monitor;
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public DevicesGroup(string parent_id) {
+ GLib.Object(parent_id : parent_id);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Construct block loads all currently plugged-in devices and
+ /// connects signal handlers to the VolumeMonitor.
+ /////////////////////////////////////////////////////////////////////
+
+ construct {
+ this.monitor = GLib.VolumeMonitor.get();
+
+ this.load();
+
+ // add monitor
+ this.monitor.mount_added.connect(this.reload);
+ this.monitor.mount_removed.connect(this.reload);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Loads all currently plugged-in devices.
+ /////////////////////////////////////////////////////////////////////
+
+ private void load() {
+ // add root device
+ this.add_action(new UriAction(_("Root"), "drive-harddisk", "file:///"));
+
+ // add all other devices
+ foreach(var mount in this.monitor.get_mounts()) {
+ // get icon
+ var icon = mount.get_icon();
+
+ this.add_action(new UriAction(mount.get_name(), Icon.get_icon_name(icon), mount.get_root().get_uri()));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Reloads all devices. Is called when the VolumeMonitor changes.
+ /////////////////////////////////////////////////////////////////////
+
+ private void reload() {
+ // avoid too frequent changes...
+ if (!this.changing) {
+ this.changing = true;
+ Timeout.add(200, () => {
+ if (this.changed_again) {
+ this.changed_again = false;
+ return true;
+ }
+
+ // reload
+ message("Devices changed...");
+ this.delete_all();
+ this.load();
+
+ this.changing = false;
+ return false;
+ });
+ } else {
+ this.changed_again = true;
+ }
+ }
+}
+
+}
diff --git a/src/actionGroups/groupRegistry.vala b/src/actionGroups/groupRegistry.vala
new file mode 100644
index 0000000..c97cf95
--- /dev/null
+++ b/src/actionGroups/groupRegistry.vala
@@ -0,0 +1,110 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////////
+/// A which has knowledge on all possible acion group types.
+/////////////////////////////////////////////////////////////////////////
+
+public class GroupRegistry : GLib.Object {
+
+ /////////////////////////////////////////////////////////////////////
+ /// A list containing all available ActionGroup types.
+ /////////////////////////////////////////////////////////////////////
+
+ public static Gee.ArrayList<string> types { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// A map associating a displayable name for each ActionGroup,
+ /// an icon name and a name for the pies.conf file with it's type.
+ /////////////////////////////////////////////////////////////////////
+
+ public static Gee.HashMap<string, TypeDescription?> descriptions { get; private set; }
+
+ public class TypeDescription {
+ public string name { get; set; default=""; }
+ public string icon { get; set; default=""; }
+ public string description { get; set; default=""; }
+ public string id { get; set; default=""; }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Registers all ActionGroup types.
+ /////////////////////////////////////////////////////////////////////
+
+ public static void init() {
+ types = new Gee.ArrayList<string>();
+ descriptions = new Gee.HashMap<string, TypeDescription?>();
+
+ TypeDescription type_description;
+
+ type_description = BookmarkGroup.register();
+ types.add(typeof(BookmarkGroup).name());
+ descriptions.set(typeof(BookmarkGroup).name(), type_description);
+
+ type_description = ClipboardGroup.register();
+ types.add(typeof(ClipboardGroup).name());
+ descriptions.set(typeof(ClipboardGroup).name(), type_description);
+
+ type_description = DevicesGroup.register();
+ types.add(typeof(DevicesGroup).name());
+ descriptions.set(typeof(DevicesGroup).name(), type_description);
+
+ type_description = MenuGroup.register();
+ types.add(typeof(MenuGroup).name());
+ descriptions.set(typeof(MenuGroup).name(), type_description);
+
+ type_description = SessionGroup.register();
+ types.add(typeof(SessionGroup).name());
+ descriptions.set(typeof(SessionGroup).name(), type_description);
+
+ type_description = WindowListGroup.register();
+ types.add(typeof(WindowListGroup).name());
+ descriptions.set(typeof(WindowListGroup).name(), type_description);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Creates a Group for a given type name.
+ /////////////////////////////////////////////////////////////////////
+
+ public static ActionGroup? create_group(string type_id, string parent_id) {
+ switch (type_id) {
+ case "bookmarks":
+ return new BookmarkGroup(parent_id);
+ case "clipboard":
+ return new ClipboardGroup(parent_id);
+ case "devices":
+ return new DevicesGroup(parent_id);
+ case "menu":
+ return new MenuGroup(parent_id);
+ case "session":
+ return new SessionGroup(parent_id);
+ case "window_list":
+ return new WindowListGroup(parent_id);
+ // deprecated
+ case "workspace_window_list":
+ var group = new WindowListGroup(parent_id);
+ group.current_workspace_only = true;
+ return group;
+ }
+
+ return null;
+ }
+}
+
+}
diff --git a/src/actionGroups/menuGroup.vala b/src/actionGroups/menuGroup.vala
new file mode 100644
index 0000000..ccb5407
--- /dev/null
+++ b/src/actionGroups/menuGroup.vala
@@ -0,0 +1,250 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////////
+/// An ActionGroup which displays the user's main menu. It's a bit ugly,
+/// but it supports both, an older version and libgnome-menus-3 at the
+/// same time.
+/////////////////////////////////////////////////////////////////////////
+
+public class MenuGroup : ActionGroup {
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of ActionGroup. It sets the display
+ /// name for this ActionGroup, it's icon name and the string used in
+ /// the pies.conf file for this kind of ActionGroups.
+ /////////////////////////////////////////////////////////////////////
+
+ public static GroupRegistry.TypeDescription register() {
+ var description = new GroupRegistry.TypeDescription();
+ description.name = _("Group: Main menu");
+ description.icon = "start-here";
+ description.description = _("Displays your main menu structure.");
+ description.id = "menu";
+ return description;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// True, if this MenuGroup is the top most menu.
+ /////////////////////////////////////////////////////////////////////
+
+ public bool is_toplevel {get; construct set; default = true;}
+
+ /////////////////////////////////////////////////////////////////////
+ /// The menu tree displayed by the MenuGroup. Only set for the
+ /// toplevel MenuGroup.
+ /////////////////////////////////////////////////////////////////////
+
+ private GMenu.Tree menu = null;
+
+ /////////////////////////////////////////////////////////////////////
+ /// A list of all sub menus of this MenuGroup.
+ /////////////////////////////////////////////////////////////////////
+
+ private Gee.ArrayList<MenuGroup?> childs;
+
+ /////////////////////////////////////////////////////////////////////
+ /// Two members needed to avoid useless, frequent changes of the
+ /// stored Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ private bool changing = false;
+ private bool changed_again = false;
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members. Used for the toplevel menu.
+ /////////////////////////////////////////////////////////////////////
+
+ public MenuGroup(string parent_id) {
+ GLib.Object(parent_id : parent_id, is_toplevel : true);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members. Used for sub menus.
+ /////////////////////////////////////////////////////////////////////
+
+ public MenuGroup.sub_menu(string parent_id) {
+ GLib.Object(parent_id : parent_id, is_toplevel : false);
+ }
+
+ construct {
+ this.childs = new Gee.ArrayList<MenuGroup?>();
+
+ if (this.is_toplevel) {
+ #if HAVE_GMENU_3
+ this.menu = new GMenu.Tree("applications.menu", GMenu.TreeFlags.INCLUDE_EXCLUDED);
+ this.menu.changed.connect(this.reload);
+ #endif
+
+ this.load_toplevel();
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Starts to load the menu.
+ /////////////////////////////////////////////////////////////////////
+
+ private void load_toplevel() {
+ #if HAVE_GMENU_3
+ try {
+ if (this.menu.load_sync()) {
+ this.load_contents(this.menu.get_root_directory(), this.parent_id);
+ }
+ } catch (GLib.Error e) {
+ warning(e.message);
+ }
+ #else
+ this.menu = GMenu.Tree.lookup ("applications.menu", GMenu.TreeFlags.INCLUDE_EXCLUDED);
+ this.menu.add_monitor(this.reload);
+ var dir = this.menu.get_root_directory();
+ this.load_contents(dir, this.parent_id);
+ #endif
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Parses the main menu recursively.
+ /////////////////////////////////////////////////////////////////////
+
+ private void load_contents(GMenu.TreeDirectory dir, string parent_id) {
+ #if HAVE_GMENU_3
+ var item = dir.iter();
+
+ while (true) {
+ var type = item.next();
+ if (type == GMenu.TreeItemType.INVALID)
+ break;
+
+ if (type == GMenu.TreeItemType.DIRECTORY && !item.get_directory().get_is_nodisplay()) {
+ // create a MenuGroup for sub menus
+
+ // get icon
+ var icon = item.get_directory().get_icon();
+
+ var sub_menu = PieManager.create_dynamic_pie(item.get_directory().get_name(), Icon.get_icon_name(icon));
+ var group = new MenuGroup.sub_menu(sub_menu.id);
+ group.add_action(new PieAction(parent_id, true));
+ group.load_contents(item.get_directory(), sub_menu.id);
+ childs.add(group);
+
+ sub_menu.add_group(group);
+
+ this.add_action(new PieAction(sub_menu.id));
+
+ } else if (type == GMenu.TreeItemType.ENTRY ) {
+ // create an AppAction for entries
+ if (!item.get_entry().get_is_excluded()) {
+ this.add_action(ActionRegistry.new_for_app_info(item.get_entry().get_app_info()));
+ }
+ }
+ }
+ #else
+ foreach (var item in dir.get_contents()) {
+ switch(item.get_type()) {
+ case GMenu.TreeItemType.DIRECTORY:
+ // create a MenuGroup for sub menus
+ if (!((GMenu.TreeDirectory)item).get_is_nodisplay()) {
+ var sub_menu = PieManager.create_dynamic_pie(
+ ((GMenu.TreeDirectory)item).get_name(),
+ ((GMenu.TreeDirectory)item).get_icon());
+ var group = new MenuGroup.sub_menu(sub_menu.id);
+ group.add_action(new PieAction(parent_id, true));
+ group.load_contents((GMenu.TreeDirectory)item, sub_menu.id);
+ childs.add(group);
+
+ sub_menu.add_group(group);
+
+ this.add_action(new PieAction(sub_menu.id));
+ }
+ break;
+
+ case GMenu.TreeItemType.ENTRY:
+ // create an AppAction for entries
+ if (!((GMenu.TreeEntry)item).get_is_nodisplay() && !((GMenu.TreeEntry)item).get_is_excluded()) {
+ this.add_action(new AppAction(((GMenu.TreeEntry)item).get_name(),
+ ((GMenu.TreeEntry)item).get_icon(),
+ ((GMenu.TreeEntry)item).get_exec()));
+ }
+ break;
+ }
+ }
+ #endif
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Reloads the menu.
+ /////////////////////////////////////////////////////////////////////
+
+ private void reload() {
+ // avoid too frequent changes...
+ if (!this.changing) {
+ this.changing = true;
+ Timeout.add(500, () => {
+ if (this.changed_again) {
+ this.changed_again = false;
+ return true;
+ }
+
+ // reload
+ message("Main menu changed...");
+ #if !HAVE_GMENU_3
+ this.menu.remove_monitor(this.reload);
+ #endif
+
+ this.clear();
+ this.load_toplevel();
+
+ this.changing = false;
+ return false;
+ });
+ } else {
+ this.changed_again = true;
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Deletes all generated Pies, when the toplevel menu is deleted.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void on_remove() {
+ if (this.is_toplevel)
+ this.clear();
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Clears this ActionGroup recursively.
+ /////////////////////////////////////////////////////////////////////
+
+ private void clear() {
+ foreach (var child in childs)
+ child.clear();
+
+ if (!this.is_toplevel)
+ PieManager.remove_pie(this.parent_id);
+
+ this.delete_all();
+
+ this.childs.clear();
+
+ #if !HAVE_GMENU_3
+ this.menu = null;
+ #endif
+
+ }
+}
+
+}
diff --git a/src/actionGroups/sessionGroup.vala b/src/actionGroups/sessionGroup.vala
new file mode 100644
index 0000000..42afafc
--- /dev/null
+++ b/src/actionGroups/sessionGroup.vala
@@ -0,0 +1,76 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////
+/// An ActionGroup which has three Actions: Logout, Shutdown and
+/// Reboot.
+/////////////////////////////////////////////////////////////////////
+
+public class SessionGroup : ActionGroup {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of ActionGroup. It sets the display
+ /// name for this ActionGroup, it's icon name and the string used in
+ /// the pies.conf file for this kind of ActionGroups.
+ /////////////////////////////////////////////////////////////////////
+
+ public static GroupRegistry.TypeDescription register() {
+ var description = new GroupRegistry.TypeDescription();
+ description.name = _("Group: Session Control");
+ description.icon = "system-log-out";
+ description.description = _("Shows a Slice for Shutdown, Reboot, and Hibernate.");
+ description.id = "session";
+ return description;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public SessionGroup(string parent_id) {
+ GLib.Object(parent_id : parent_id);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Construct block adds the three Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ construct {
+// string iface = GLib.Bus.get_proxy_sync(GLib.BusType.SESSION, "org.gnome.SessionManager", "/org/gnome/SessionManager");
+// iface = GLib.Bus.get_proxy_sync(GLib.BusType.SESSION, "org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer");
+// iface = GLib.Bus.get_proxy_sync(GLib.BusType.SESSION, "org.kde.ksmserver", "/KSMServer");
+// iface = GLib.Bus.get_proxy_sync(GLib.BusType.SESSION, "org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager");
+
+ this.add_action(new AppAction(_("Shutdown"), "system-shutdown",
+ "dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Shutdown"));
+
+ this.add_action(new AppAction(_("Logout"), "system-log-out",
+ "dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1"));
+
+ this.add_action(new AppAction(_("Reboot"), "view-refresh",
+ "dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Reboot"));
+ }
+
+ // TODO: check for available interfaces --- these may work too:
+ // dbus-send --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
+ // dbus-send --print-reply --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout 0 2 2
+ // dbus-send --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
+}
+
+}
diff --git a/src/actionGroups/windowListGroup.vala b/src/actionGroups/windowListGroup.vala
new file mode 100644
index 0000000..69029a7
--- /dev/null
+++ b/src/actionGroups/windowListGroup.vala
@@ -0,0 +1,193 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////
+/// This group displays a list of all running application windows.
+/////////////////////////////////////////////////////////////////////
+
+public class WindowListGroup : ActionGroup {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of ActionGroup. It sets the display
+ /// name for this ActionGroup, it's icon name and the string used in
+ /// the pies.conf file for this kind of ActionGroups.
+ /////////////////////////////////////////////////////////////////////
+
+ public static GroupRegistry.TypeDescription register() {
+ var description = new GroupRegistry.TypeDescription();
+ description.name = _("Group: Window List");
+ description.icon = "preferences-system-windows";
+ description.description = _("Shows a Slice for each of your opened Windows. Almost like Alt-Tab.");
+ description.id = "window_list";
+ return description;
+ }
+
+ public bool current_workspace_only { get; set; default=false; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Two members needed to avoid useless, frequent changes of the
+ /// stored Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ private bool changing = false;
+ private bool changed_again = false;
+
+ private Wnck.Screen screen;
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public WindowListGroup(string parent_id) {
+ GLib.Object(parent_id : parent_id);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Loads all windows.
+ /////////////////////////////////////////////////////////////////////
+
+ construct {
+ this.screen = Wnck.Screen.get_default();
+
+ this.screen.window_opened.connect(reload);
+ this.screen.window_closed.connect(reload);
+ this.screen.active_workspace_changed.connect(reload);
+
+ this.update();
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// This one is called, when the ActionGroup is saved.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void on_save(Xml.TextWriter writer) {
+ base.on_save(writer);
+ writer.write_attribute("current_workspace_only", this.current_workspace_only.to_string());
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// This one is called, when the ActionGroup is loaded.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void on_load(Xml.Node* data) {
+ for (Xml.Attr* attribute = data->properties; attribute != null; attribute = attribute->next) {
+ string attr_name = attribute->name.down();
+ string attr_content = attribute->children->content;
+
+ if (attr_name == "current_workspace_only") {
+ this.current_workspace_only = bool.parse(attr_content);
+ }
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Loads all currently opened windows and creates actions for them.
+ /////////////////////////////////////////////////////////////////////
+
+ private void update() {
+ unowned GLib.List<Wnck.Window?> windows = this.screen.get_windows();
+
+ var matcher = Bamf.Matcher.get_default();
+
+ foreach (var window in windows) {
+ if (window.get_window_type() == Wnck.WindowType.NORMAL
+ && !window.is_skip_pager() && !window.is_skip_tasklist()
+ && (!current_workspace_only || (window.get_workspace() != null
+ && window.get_workspace() == this.screen.get_active_workspace()))) {
+
+ var application = window.get_application();
+ var bamf_app = matcher.get_application_for_xid((uint32)window.get_xid());
+
+ string name = window.get_name();
+
+ if (name.length > 30)
+ name = name.substring(0, 30) + "...";
+
+ var action = new SigAction(
+ name,
+ (bamf_app == null) ? application.get_icon_name().down() : bamf_app.get_icon(),
+ "%lu".printf(window.get_xid())
+ );
+ action.activated.connect((time_stamp) => {
+ Wnck.Screen.get_default().force_update();
+
+ var xid = (X.Window)uint64.parse(action.real_command);
+ var win = Wnck.Window.get(xid);
+
+ if (win.get_workspace() != null) {
+ //select the workspace
+ if (win.get_workspace() != win.get_screen().get_active_workspace()) {
+ win.get_workspace().activate(time_stamp);
+ }
+
+ //select the viewport inside the workspace
+ if (!win.is_in_viewport(win.get_workspace()) ) {
+ int xp, yp, widthp, heightp, scx, scy, nx, ny, wx, wy;
+ win.get_geometry (out xp, out yp, out widthp, out heightp);
+ scx = win.get_screen().get_width();
+ scy = win.get_screen().get_height();
+ wx = win.get_workspace().get_viewport_x();
+ wy = win.get_workspace().get_viewport_y();
+ if (scx > 0 && scy > 0) {
+ nx= ((wx+xp) / scx) * scx;
+ ny= ((wy+yp) / scy) * scy;
+ win.get_screen().move_viewport(nx, ny);
+ }
+ }
+ }
+
+ if (win.is_minimized()) {
+ win.unminimize(time_stamp);
+ }
+
+ win.activate_transient(time_stamp);
+ });
+ this.add_action(action);
+ }
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Reloads all running applications.
+ /////////////////////////////////////////////////////////////////////
+
+ private void reload() {
+ // avoid too frequent changes...
+ if (!this.changing) {
+ this.changing = true;
+ Timeout.add(500, () => {
+ if (this.changed_again) {
+ this.changed_again = false;
+ return true;
+ }
+
+ // reload
+ this.delete_all();
+ this.update();
+
+ this.changing = false;
+ return false;
+ });
+ } else {
+ this.changed_again = true;
+ }
+ }
+}
+
+}