summaryrefslogtreecommitdiff
path: root/src/actions
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/actions
Imported Upstream version 0.2+gitdfdad95upstream/0.2+gitdfdad95
Diffstat (limited to 'src/actions')
-rw-r--r--src/actions/action.vala77
-rw-r--r--src/actions/actionRegistry.vala200
-rw-r--r--src/actions/appAction.vala72
-rw-r--r--src/actions/keyAction.vala77
-rw-r--r--src/actions/pieAction.vala95
-rw-r--r--src/actions/sigAction.vala63
-rw-r--r--src/actions/uriAction.vala71
7 files changed, 655 insertions, 0 deletions
diff --git a/src/actions/action.vala b/src/actions/action.vala
new file mode 100644
index 0000000..ceed357
--- /dev/null
+++ b/src/actions/action.vala
@@ -0,0 +1,77 @@
+/*
+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 for actions, which are executed when the user
+/// activates a pie's slice.
+/////////////////////////////////////////////////////////////////////////
+
+public abstract class Action : GLib.Object {
+
+ /////////////////////////////////////////////////////////////////////
+ /// The command which gets executed when user activates the Slice.
+ /// It may be anything but has to be representable with a string.
+ /////////////////////////////////////////////////////////////////////
+
+ public abstract string real_command { get; construct set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The command displayed to the user. It should be a bit more
+ /// beautiful than the real_command.
+ /////////////////////////////////////////////////////////////////////
+
+ public abstract string display_command { get; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The name of the Action.
+ /////////////////////////////////////////////////////////////////////
+
+ public virtual string name { get; protected set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The name of the icon of this Action. It should be in the users
+ /// current icon theme.
+ /////////////////////////////////////////////////////////////////////
+
+ public virtual string icon { get; protected set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// True, if this Action is the quickAction of the associated Pie.
+ /// The quickAction of a Pie gets executed when the users clicks on
+ /// the center of a Pie.
+ /////////////////////////////////////////////////////////////////////
+
+ public virtual bool is_quick_action { get; protected set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public Action(string name, string icon, bool is_quick_action) {
+ GLib.Object(name : name, icon : icon, is_quick_action : is_quick_action);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// This one is called, when the user activates the Slice.
+ /////////////////////////////////////////////////////////////////////
+
+ public abstract void activate();
+}
+
+}
diff --git a/src/actions/actionRegistry.vala b/src/actions/actionRegistry.vala
new file mode 100644
index 0000000..091865f
--- /dev/null
+++ b/src/actions/actionRegistry.vala
@@ -0,0 +1,200 @@
+/*
+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 types.
+/////////////////////////////////////////////////////////////////////////
+
+public class ActionRegistry : GLib.Object {
+
+ /////////////////////////////////////////////////////////////////////
+ /// A list containing all available Action types.
+ /////////////////////////////////////////////////////////////////////
+
+ public static Gee.ArrayList<Type> types { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Three maps associating a displayable name for each Action,
+ /// whether it has a custom icon 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, bool> icon_name_editables { get; private set; }
+ public static Gee.HashMap<Type, string> settings_names { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Registers all Action types.
+ /////////////////////////////////////////////////////////////////////
+
+ public static void init() {
+ types = new Gee.ArrayList<Type>();
+
+ names = new Gee.HashMap<Type, string>();
+ icon_name_editables = new Gee.HashMap<Type, bool>();
+ settings_names = new Gee.HashMap<Type, string>();
+
+ string name = "";
+ bool icon_name_editable = true;
+ string settings_name = "";
+
+ AppAction.register(out name, out icon_name_editable, out settings_name);
+ types.add(typeof(AppAction));
+ names.set(typeof(AppAction), name);
+ icon_name_editables.set(typeof(AppAction), icon_name_editable);
+ settings_names.set(typeof(AppAction), settings_name);
+
+ KeyAction.register(out name, out icon_name_editable, out settings_name);
+ types.add(typeof(KeyAction));
+ names.set(typeof(KeyAction), name);
+ icon_name_editables.set(typeof(KeyAction), icon_name_editable);
+ settings_names.set(typeof(KeyAction), settings_name);
+
+ PieAction.register(out name, out icon_name_editable, out settings_name);
+ types.add(typeof(PieAction));
+ names.set(typeof(PieAction), name);
+ icon_name_editables.set(typeof(PieAction), icon_name_editable);
+ settings_names.set(typeof(PieAction), settings_name);
+
+ UriAction.register(out name, out icon_name_editable, out settings_name);
+ types.add(typeof(UriAction));
+ names.set(typeof(UriAction), name);
+ icon_name_editables.set(typeof(UriAction), icon_name_editable);
+ settings_names.set(typeof(UriAction), settings_name);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// A helper method which creates an Action, appropriate for the
+ /// given URI. This can result in an UriAction or in an AppAction,
+ /// depending on the Type of the URI.
+ /////////////////////////////////////////////////////////////////////
+
+ public static Action? new_for_uri(string uri, string? name = null) {
+ var file = GLib.File.new_for_uri(uri);
+ var scheme = file.get_uri_scheme();
+
+ string final_icon = "";
+ string final_name = file.get_basename();
+
+ switch (scheme) {
+ case "application":
+ var file_name = uri.split("//")[1];
+
+ var desktop_file = GLib.File.new_for_path("/usr/share/applications/" + file_name);
+ if (desktop_file.query_exists())
+ return new_for_desktop_file(desktop_file.get_path());
+
+ break;
+
+ case "trash":
+ final_icon = "user-trash";
+ final_name = _("Trash");
+ break;
+
+ case "http": case "https":
+ final_icon = "www";
+ break;
+
+ case "ftp": case "sftp":
+ final_icon = "folder-remote";
+ break;
+
+ default:
+ try {
+ var info = file.query_info("*", GLib.FileQueryInfoFlags.NONE);
+
+ if (info.get_content_type() == "application/x-desktop")
+ return new_for_desktop_file(file.get_parse_name());
+
+ // search for an appropriate icon
+ var gicon = info.get_icon();
+ string[] icons = gicon.to_string().split(" ");
+
+ foreach (var icon in icons) {
+ if (Gtk.IconTheme.get_default().has_icon(icon)) {
+ final_icon = icon;
+ break;
+ }
+ }
+
+ } catch (GLib.Error e) {
+ warning(e.message);
+ }
+
+ break;
+ }
+
+ if (!Gtk.IconTheme.get_default().has_icon(final_icon))
+ final_icon = "application-default-icon";
+
+ if (name != null)
+ final_name = name;
+
+ return new UriAction(final_name, final_icon, uri);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// A helper method which creates an AppAction for given AppInfo.
+ /////////////////////////////////////////////////////////////////////
+
+ public static Action? new_for_app_info(GLib.AppInfo info) {
+ string[] icons = info.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;
+ }
+ }
+
+ return new AppAction(info.get_display_name() , final_icon, info.get_commandline());
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// A helper method which creates an AppAction for given *.desktop
+ /// file.
+ /////////////////////////////////////////////////////////////////////
+
+ public static Action? new_for_desktop_file(string file_name) {
+ var info = new DesktopAppInfo.from_filename(file_name);
+ return new_for_app_info(info);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// A helper method which creates an AppAction for given mime type.
+ /////////////////////////////////////////////////////////////////////
+
+ public static Action? default_for_mime_type(string type) {
+ var info = AppInfo.get_default_for_type(type, false);
+ return new_for_app_info(info);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// A helper method which creates an AppAction for given uri scheme.
+ /////////////////////////////////////////////////////////////////////
+
+ public static Action? default_for_uri(string uri) {
+ var info = AppInfo. get_default_for_uri_scheme(uri);
+ return new_for_app_info(info);
+ }
+}
+
+}
diff --git a/src/actions/appAction.vala b/src/actions/appAction.vala
new file mode 100644
index 0000000..d8363e4
--- /dev/null
+++ b/src/actions/appAction.vala
@@ -0,0 +1,72 @@
+/*
+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 type of Action launches an application or a custom command.
+/////////////////////////////////////////////////////////////////////////
+
+public class AppAction : Action {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of Action. It sets the display name
+ /// for this Action, whether it has a custom Icon/Name and the string
+ /// used in the pies.conf file for this kind of Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ public static void register(out string name, out bool icon_name_editable, out string settings_name) {
+ name = _("Launch application");
+ icon_name_editable = true;
+ settings_name = "app";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Stores the command line.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string real_command { get; construct set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Simply returns the real_command. No beautification.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string display_command { get {return real_command;} }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public AppAction(string name, string icon, string command, bool is_quick_action = false) {
+ GLib.Object(name : name, icon : icon, real_command : command, is_quick_action : is_quick_action);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Launches the desired command.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void activate() {
+ try{
+ var item = GLib.AppInfo.create_from_commandline(this.real_command, null, GLib.AppInfoCreateFlags.NONE);
+ item.launch(null, null);
+ } catch (Error e) {
+ warning(e.message);
+ }
+ }
+}
+
+}
diff --git a/src/actions/keyAction.vala b/src/actions/keyAction.vala
new file mode 100644
index 0000000..0f6d094
--- /dev/null
+++ b/src/actions/keyAction.vala
@@ -0,0 +1,77 @@
+/*
+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 type of Action "presses" a key stroke.
+/////////////////////////////////////////////////////////////////////////
+
+public class KeyAction : Action {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of Action. It sets the display name
+ /// for this Action, whether it has a custom Icon/Name and the string
+ /// used in the pies.conf file for this kind of Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ public static void register(out string name, out bool icon_name_editable, out string settings_name) {
+ name = _("Press key stroke");
+ icon_name_editable = true;
+ settings_name = "key";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Stores the accelerator of this action.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string real_command { get; construct set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns a human readable form of the accelerator.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string display_command { get {return key.label;} }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The simulated key which gets 'pressed' on execution.
+ /////////////////////////////////////////////////////////////////////
+
+ public Key key { get; set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public KeyAction(string name, string icon, string command, bool is_quick_action = false) {
+ GLib.Object(name : name, icon : icon, real_command : command, is_quick_action : is_quick_action);
+ }
+
+ construct {
+ this.key = new Key(real_command);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Presses the desired key.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void activate() {
+ key.press();
+ }
+}
+
+}
diff --git a/src/actions/pieAction.vala b/src/actions/pieAction.vala
new file mode 100644
index 0000000..53ea919
--- /dev/null
+++ b/src/actions/pieAction.vala
@@ -0,0 +1,95 @@
+/*
+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 Action opens another pie.
+/////////////////////////////////////////////////////////////////////////
+
+public class PieAction : Action {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of Action. It sets the display name
+ /// for this Action, whether it has a custom Icon/Name and the string
+ /// used in the pies.conf file for this kind of Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ public static void register(out string name, out bool icon_name_editable, out string settings_name) {
+ name = _("Open Pie");
+ icon_name_editable = false;
+ settings_name = "pie";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Stores the ID of the referenced Pie.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string real_command { get; construct set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns the name of the referenced Pie.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string display_command { get {return name;} }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns the name of the referenced Pie.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string name {
+ get {
+ var referee = PieManager.all_pies[real_command];
+ if (referee != null)
+ return referee.name;
+ return "";
+ }
+ protected set {}
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns the icon of the referenced Pie.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string icon {
+ get {
+ var referee = PieManager.all_pies[real_command];
+ if (referee != null)
+ return referee.icon;
+ return "";
+ }
+ protected set {}
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public PieAction(string id, bool is_quick_action = false) {
+ GLib.Object(name : "", icon : "", real_command : id, is_quick_action : is_quick_action);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Opens the desired Pie.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void activate() {
+ PieManager.open_pie(real_command);
+ }
+}
+
+}
diff --git a/src/actions/sigAction.vala b/src/actions/sigAction.vala
new file mode 100644
index 0000000..cec9836
--- /dev/null
+++ b/src/actions/sigAction.vala
@@ -0,0 +1,63 @@
+/*
+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 type of Action can't be selected by the user, therefore there is
+/// no register() method for this class. But it may be useful for
+/// ActionGroups: It emits a signal on activation.
+/////////////////////////////////////////////////////////////////////////
+
+public class SigAction : Action {
+
+ /////////////////////////////////////////////////////////////////////
+ /// This signal is emitted on activation.
+ /////////////////////////////////////////////////////////////////////
+
+ public signal void activated();
+
+ /////////////////////////////////////////////////////////////////////
+ /// This may store something useful.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string real_command { get; construct set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Only for inheritance... Greetings to Liskov.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string display_command { get {return real_command;} }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public SigAction(string name, string icon, string command, bool is_quick_action = false) {
+ GLib.Object(name : name, icon : icon, real_command : command, is_quick_action : is_quick_action);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Emits the signal on activation.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void activate() {
+ this.activated();
+ }
+}
+
+}
diff --git a/src/actions/uriAction.vala b/src/actions/uriAction.vala
new file mode 100644
index 0000000..25d5c75
--- /dev/null
+++ b/src/actions/uriAction.vala
@@ -0,0 +1,71 @@
+/*
+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 type of Action opens the default application for an URI.
+/////////////////////////////////////////////////////////////////////////
+
+public class UriAction : Action {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Used to register this type of Action. It sets the display name
+ /// for this Action, whether it has a custom Icon/Name and the string
+ /// used in the pies.conf file for this kind of Actions.
+ /////////////////////////////////////////////////////////////////////
+
+ public static void register(out string name, out bool icon_name_editable, out string settings_name) {
+ name = _("Open URI");
+ icon_name_editable = true;
+ settings_name = "uri";
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The URI of this Action.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string real_command { get; construct set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns only the real URI. An URI can't be beautified.
+ /////////////////////////////////////////////////////////////////////
+
+ public override string display_command { get {return real_command;} }
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
+ public UriAction(string name, string icon, string command, bool is_quick_action = false) {
+ GLib.Object(name : name, icon : icon, real_command : command, is_quick_action : is_quick_action);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Opens the default application for the URI.
+ /////////////////////////////////////////////////////////////////////
+
+ public override void activate() {
+ try{
+ GLib.AppInfo.launch_default_for_uri(real_command, null);
+ } catch (Error e) {
+ warning(e.message);
+ }
+ }
+}
+
+}