summaryrefslogtreecommitdiff
path: root/src/actionGroups
diff options
context:
space:
mode:
authorAlessandro Ghedini <al3xbio@gmail.com>2011-10-19 10:56:04 +0200
committerAlessandro Ghedini <al3xbio@gmail.com>2011-10-19 10:56:04 +0200
commit6451a495637c6e3047a5a56573cffc6e3de9a515 (patch)
tree7c3eb29532e7c4b36a9da13c5890664fb816959b /src/actionGroups
Imported Upstream version 0.2+gitdfdad95upstream/0.2+gitdfdad95
Diffstat (limited to 'src/actionGroups')
-rw-r--r--src/actionGroups/actionGroup.vala75
-rw-r--r--src/actionGroups/bookmarkGroup.vala148
-rw-r--r--src/actionGroups/clipboardGroup.vala116
-rw-r--r--src/actionGroups/devicesGroup.vala129
-rw-r--r--src/actionGroups/groupRegistry.vala89
-rw-r--r--src/actionGroups/menuGroup.vala254
-rw-r--r--src/actionGroups/sessionGroup.vala68
7 files changed, 879 insertions, 0 deletions
diff --git a/src/actionGroups/actionGroup.vala b/src/actionGroups/actionGroup.vala
new file mode 100644
index 0000000..a6b52ff
--- /dev/null
+++ b/src/actionGroups/actionGroup.vala
@@ -0,0 +1,75 @@
+/*
+Copyright (c) 2011 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() {}
+
+ /////////////////////////////////////////////////////////////////////
+ /// 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();
+ }
+}
+
+}
diff --git a/src/actionGroups/bookmarkGroup.vala b/src/actionGroups/bookmarkGroup.vala
new file mode 100644
index 0000000..f4ba66e
--- /dev/null
+++ b/src/actionGroups/bookmarkGroup.vala
@@ -0,0 +1,148 @@
+/*
+Copyright (c) 2011 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 void register(out string name, out string icon, out string settings_name) {
+ name = _("Bookmarks");
+ icon = "user-bookmarks";
+ settings_name = "bookmarks";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// 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..0e95b65
--- /dev/null
+++ b/src/actionGroups/clipboardGroup.vala
@@ -0,0 +1,116 @@
+/*
+Copyright (c) 2011 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.
+/////////////////////////////////////////////////////////////////////////
+
+public class ClipboardGroup : ActionGroup {
+
+ /////////////////////////////////////////////////////////////////////
+ ///
+ /////////////////////////////////////////////////////////////////////
+
+ private class ClipboardItem : GLib.Object {
+
+ public string name { get; private set; }
+ public string icon { get; private set; }
+
+ private Gtk.SelectionData contents;
+
+ public ClipboardItem(Gtk.SelectionData contents) {
+ this.contents = contents.copy();
+ this.name = this.contents.get_text() ?? "";
+ this.icon = "edit-paste";
+ }
+
+ public void paste() {
+ debug(name);
+ }
+ }
+
+ 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 void register(out string name, out string icon, out string settings_name) {
+ name = _("Clipboard");
+ icon = "edit-paste";
+ settings_name = "clipboard";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The clipboard to be monitored.
+ /////////////////////////////////////////////////////////////////////
+
+ private Gtk.Clipboard clipboard;
+
+
+ /////////////////////////////////////////////////////////////////////
+ /// The maximum remembered items of the clipboard.
+ /////////////////////////////////////////////////////////////////////
+
+ private const int max_items = 6;
+
+ 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);
+ }
+
+ private void on_change() {
+ if (this.clipboard.wait_is_text_available()) {
+ this.clipboard.request_contents(Gdk.Atom.intern("text/plain", false), this.add_item);
+ }
+ }
+
+ private void add_item(Gtk.Clipboard c, Gtk.SelectionData contents) {
+ var new_item = new ClipboardItem(contents);
+
+ if (this.items.size == this.max_items)
+ this.items.remove_at(0);
+
+ this.items.add(new_item);
+
+ // update slices
+ this.delete_all();
+
+ for (int i=0; i<this.items.size; ++i) {
+ var action = new SigAction(items[i].name, items[i].icon, i.to_string());
+ action.activated.connect(() => {
+ 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..3d2ced0
--- /dev/null
+++ b/src/actionGroups/devicesGroup.vala
@@ -0,0 +1,129 @@
+/*
+Copyright (c) 2011 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 void register(out string name, out string icon, out string settings_name) {
+ name = _("Devices");
+ icon = "harddrive";
+ settings_name = "devices";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// 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"), "harddrive", "file:///"));
+
+ // add all other devices
+ foreach(var mount in this.monitor.get_mounts()) {
+ // get icon
+ var icon_names = mount.get_icon().to_string().split(" ");
+
+ string icon = "";
+ foreach (var icon_name in icon_names) {
+ if (Gtk.IconTheme.get_default().has_icon(icon_name)) {
+ icon = icon_name;
+ break;
+ }
+ }
+
+ this.add_action(new UriAction(mount.get_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..94169d5
--- /dev/null
+++ b/src/actionGroups/groupRegistry.vala
@@ -0,0 +1,89 @@
+/*
+Copyright (c) 2011 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<Type> types { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Three maps 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<Type, string> names { get; private set; }
+ public static Gee.HashMap<Type, string> icons { get; private set; }
+ public static Gee.HashMap<Type, string> settings_names { get; private set; }
+
+
+ /////////////////////////////////////////////////////////////////////
+ /// Registers all ActionGroup types.
+ /////////////////////////////////////////////////////////////////////
+
+ public static void init() {
+ types = new Gee.ArrayList<Type>();
+
+ names = new Gee.HashMap<Type, string>();
+ icons = new Gee.HashMap<Type, string>();
+ settings_names = new Gee.HashMap<Type, string>();
+
+ string name = "";
+ string icon = "";
+ string settings_name = "";
+
+ BookmarkGroup.register(out name, out icon, out settings_name);
+ types.add(typeof(BookmarkGroup));
+ names.set(typeof(BookmarkGroup), name);
+ icons.set(typeof(BookmarkGroup), icon);
+ settings_names.set(typeof(BookmarkGroup), settings_name);
+
+ DevicesGroup.register(out name, out icon, out settings_name);
+ types.add(typeof(DevicesGroup));
+ names.set(typeof(DevicesGroup), name);
+ icons.set(typeof(DevicesGroup), icon);
+ settings_names.set(typeof(DevicesGroup), settings_name);
+
+ MenuGroup.register(out name, out icon, out settings_name);
+ types.add(typeof(MenuGroup));
+ names.set(typeof(MenuGroup), name);
+ icons.set(typeof(MenuGroup), icon);
+ settings_names.set(typeof(MenuGroup), settings_name);
+
+ SessionGroup.register(out name, out icon, out settings_name);
+ types.add(typeof(SessionGroup));
+ names.set(typeof(SessionGroup), name);
+ icons.set(typeof(SessionGroup), icon);
+ settings_names.set(typeof(SessionGroup), settings_name);
+
+// ClipboardGroup.register(out name, out icon, out settings_name);
+// types.add(typeof(ClipboardGroup));
+// names.set(typeof(ClipboardGroup), name);
+// icons.set(typeof(ClipboardGroup), icon);
+// settings_names.set(typeof(ClipboardGroup), settings_name);
+ }
+}
+
+}
diff --git a/src/actionGroups/menuGroup.vala b/src/actionGroups/menuGroup.vala
new file mode 100644
index 0000000..07a4bd1
--- /dev/null
+++ b/src/actionGroups/menuGroup.vala
@@ -0,0 +1,254 @@
+/*
+Copyright (c) 2011 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 void register(out string name, out string icon, out string settings_name) {
+ name = _("Main menu");
+ icon = "gnome-main-menu";
+ settings_name = "menu";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// 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
+ string[] icons = item.get_directory().get_icon().to_string().split(" ");
+ string final_icon = "application-default-icon";
+
+ // search for available icons
+ foreach (var icon in icons) {
+ if (Gtk.IconTheme.get_default().has_icon(icon)) {
+ final_icon = icon;
+ break;
+ }
+ }
+
+ var sub_menu = PieManager.create_dynamic_pie(item.get_directory().get_name(), final_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..9fcab1d
--- /dev/null
+++ b/src/actionGroups/sessionGroup.vala
@@ -0,0 +1,68 @@
+/*
+Copyright (c) 2011 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 void register(out string name, out string icon, out string settings_name) {
+ name = _("Session Control");
+ icon = "gnome-logout";
+ settings_name = "session";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public SessionGroup(string parent_id) {
+ GLib.Object(parent_id : parent_id);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Construct block adds the three Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ construct {
+ this.add_action(new AppAction(_("Shutdown"), "gnome-shutdown",
+ "dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.RequestShutdown"));
+
+ this.add_action(new AppAction(_("Logout"), "gnome-session-logout",
+ "dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1"));
+
+ this.add_action(new AppAction(_("Reboot"), "gnome-session-reboot",
+ "dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.RequestReboot"));
+ }
+
+ // TODO: check for available interfaces --- these may work too:
+ // dbus-send --print-reply --system --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 --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
+}
+
+}