diff options
Diffstat (limited to 'src/actions')
-rw-r--r-- | src/actions/action.vala | 10 | ||||
-rw-r--r-- | src/actions/actionRegistry.vala | 102 | ||||
-rw-r--r-- | src/actions/appAction.vala | 16 | ||||
-rw-r--r-- | src/actions/keyAction.vala | 18 | ||||
-rw-r--r-- | src/actions/pieAction.vala | 16 | ||||
-rw-r--r-- | src/actions/sigAction.vala | 4 | ||||
-rw-r--r-- | src/actions/uriAction.vala | 18 |
7 files changed, 118 insertions, 66 deletions
diff --git a/src/actions/action.vala b/src/actions/action.vala index ceed357..ff0e9cd 100644 --- a/src/actions/action.vala +++ b/src/actions/action.vala @@ -42,14 +42,14 @@ public abstract class Action : GLib.Object { /// The name of the Action. ///////////////////////////////////////////////////////////////////// - public virtual string name { get; protected set; } + public virtual string name { get; 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; } + public virtual string icon { get; set; } ///////////////////////////////////////////////////////////////////// /// True, if this Action is the quickAction of the associated Pie. @@ -57,14 +57,14 @@ public abstract class Action : GLib.Object { /// the center of a Pie. ///////////////////////////////////////////////////////////////////// - public virtual bool is_quick_action { get; protected set; } + public virtual bool is_quickaction { get; 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); + public Action(string name, string icon, bool is_quickaction) { + GLib.Object(name : name, icon : icon, is_quickaction : is_quickaction); } ///////////////////////////////////////////////////////////////////// diff --git a/src/actions/actionRegistry.vala b/src/actions/actionRegistry.vala index 091865f..135e90c 100644 --- a/src/actions/actionRegistry.vala +++ b/src/actions/actionRegistry.vala @@ -27,56 +27,68 @@ public class ActionRegistry : GLib.Object { /// A list containing all available Action types. ///////////////////////////////////////////////////////////////////// - public static Gee.ArrayList<Type> types { get; private set; } + public static Gee.ArrayList<string> types { get; private set; } ///////////////////////////////////////////////////////////////////// - /// Three maps associating a displayable name for each Action, + /// A map 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; } + public static Gee.HashMap<string, TypeDescription?> descriptions { get; private set; } + + ///////////////////////////////////////////////////////////////////// + /// A helper class storing information on a Action type. + ///////////////////////////////////////////////////////////////////// + + 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=""; } + public bool icon_name_editable { get; set; default=false; } + } ///////////////////////////////////////////////////////////////////// /// 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>(); + types = new Gee.ArrayList<string>(); + descriptions = new Gee.HashMap<string, TypeDescription?>(); - string name = ""; - bool icon_name_editable = true; - string settings_name = ""; + TypeDescription type_description; - 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); + types.add(typeof(AppAction).name()); + type_description = AppAction.register(); + descriptions.set(typeof(AppAction).name(), type_description); - 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); + types.add(typeof(KeyAction).name()); + type_description = KeyAction.register(); + descriptions.set(typeof(KeyAction).name(), type_description); - 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); + types.add(typeof(PieAction).name()); + type_description = PieAction.register(); + descriptions.set(typeof(PieAction).name(), type_description); + + types.add(typeof(UriAction).name()); + type_description = UriAction.register(); + descriptions.set(typeof(UriAction).name(), type_description); + } + + ///////////////////////////////////////////////////////////////////// + /// Creates a new Action from the given type name. + ///////////////////////////////////////////////////////////////////// + + public static Action? create_action(string type_id, string name, string icon, string command, bool quickaction) { + switch (type_id) { + case "app": return new AppAction(name, icon, command, quickaction); + case "key": return new KeyAction(name, icon, command, quickaction); + case "uri": return new UriAction(name, icon, command, quickaction); + case "pie": return new PieAction(command, quickaction); + } - 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); + return null; } ///////////////////////////////////////////////////////////////////// @@ -109,10 +121,12 @@ public class ActionRegistry : GLib.Object { case "http": case "https": final_icon = "www"; + final_name = get_domain_name(uri); break; case "ftp": case "sftp": final_icon = "folder-remote"; + final_name = get_domain_name(uri); break; default: @@ -174,6 +188,12 @@ public class ActionRegistry : GLib.Object { ///////////////////////////////////////////////////////////////////// public static Action? new_for_desktop_file(string file_name) { + // check whether its a desktop file to open one of Gnome-Pie's pies + if (file_name.has_prefix(Paths.launchers)) { + string id = file_name.substring((long)file_name.length - 11, 3); + return new PieAction(id); + } + var info = new DesktopAppInfo.from_filename(file_name); return new_for_app_info(info); } @@ -192,9 +212,23 @@ public class ActionRegistry : GLib.Object { ///////////////////////////////////////////////////////////////////// public static Action? default_for_uri(string uri) { - var info = AppInfo. get_default_for_uri_scheme(uri); + var info = AppInfo.get_default_for_uri_scheme(uri); return new_for_app_info(info); } + + ///////////////////////////////////////////////////////////////////// + /// Returns for example www.google.com when http://www.google.de/?q=h + /// is given. + ///////////////////////////////////////////////////////////////////// + + private static string get_domain_name(string url) { + int domain_end = url.index_of_char('/', 7); + int domain_begin = url.index_of_char('/', 0) + 2; + + if (domain_begin < domain_end) return url.substring(domain_begin, domain_end-domain_begin); + + return url; + } } } diff --git a/src/actions/appAction.vala b/src/actions/appAction.vala index d8363e4..2371f7c 100644 --- a/src/actions/appAction.vala +++ b/src/actions/appAction.vala @@ -29,10 +29,14 @@ public class AppAction : Action { /// 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"; + public static ActionRegistry.TypeDescription register() { + var description = new ActionRegistry.TypeDescription(); + description.name = _("Launch application"); + description.icon = "application-x-executable"; + description.description = _("Executes the given command."); + description.icon_name_editable = true; + description.id = "app"; + return description; } ///////////////////////////////////////////////////////////////////// @@ -51,8 +55,8 @@ public class AppAction : Action { /// 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); + public AppAction(string name, string icon, string command, bool is_quickaction = false) { + GLib.Object(name : name, icon : icon, real_command : command, is_quickaction : is_quickaction); } ///////////////////////////////////////////////////////////////////// diff --git a/src/actions/keyAction.vala b/src/actions/keyAction.vala index ddeebb5..3816686 100644 --- a/src/actions/keyAction.vala +++ b/src/actions/keyAction.vala @@ -29,10 +29,14 @@ public class KeyAction : Action { /// 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 hotkey"); - icon_name_editable = true; - settings_name = "key"; + public static ActionRegistry.TypeDescription register() { + var description = new ActionRegistry.TypeDescription(); + description.name = _("Press hotkey"); + description.icon = "preferences-desktop-keyboard-shortcuts"; + description.description = _("Simulates the activation of a hotkey."); + description.icon_name_editable = true; + description.id = "key"; + return description; } ///////////////////////////////////////////////////////////////////// @@ -57,12 +61,12 @@ public class KeyAction : Action { /// 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); + public KeyAction(string name, string icon, string command, bool is_quickaction = false) { + GLib.Object(name : name, icon : icon, real_command : command, is_quickaction : is_quickaction); } construct { - this.key = new Key(real_command); + this.key = new Key.from_string(real_command); } ///////////////////////////////////////////////////////////////////// diff --git a/src/actions/pieAction.vala b/src/actions/pieAction.vala index 53ea919..5b2c81d 100644 --- a/src/actions/pieAction.vala +++ b/src/actions/pieAction.vala @@ -29,10 +29,14 @@ public class PieAction : Action { /// 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"; + public static ActionRegistry.TypeDescription register() { + var description = new ActionRegistry.TypeDescription(); + description.name = _("Open Pie"); + description.icon = "gnome-pie"; + description.description = _("Opens another Pie of Gnome-Pie. You may create sub menus this way."); + description.icon_name_editable = false; + description.id = "pie"; + return description; } ///////////////////////////////////////////////////////////////////// @@ -79,8 +83,8 @@ public class PieAction : Action { /// 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); + public PieAction(string id, bool is_quickaction = false) { + GLib.Object(name : "", icon : "", real_command : id, is_quickaction : is_quickaction); } ///////////////////////////////////////////////////////////////////// diff --git a/src/actions/sigAction.vala b/src/actions/sigAction.vala index cec9836..1edbc08 100644 --- a/src/actions/sigAction.vala +++ b/src/actions/sigAction.vala @@ -47,8 +47,8 @@ public class SigAction : Action { /// 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); + public SigAction(string name, string icon, string command, bool is_quickaction = false) { + GLib.Object(name : name, icon : icon, real_command : command, is_quickaction : is_quickaction); } ///////////////////////////////////////////////////////////////////// diff --git a/src/actions/uriAction.vala b/src/actions/uriAction.vala index 25d5c75..f407f6c 100644 --- a/src/actions/uriAction.vala +++ b/src/actions/uriAction.vala @@ -29,10 +29,14 @@ public class UriAction : Action { /// 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"; + public static ActionRegistry.TypeDescription register() { + var description = new ActionRegistry.TypeDescription(); + description.name = _("Open URI"); + description.icon = "web-browser"; + description.description = _("Opens a given location. You may use URL's or files paths."); + description.icon_name_editable = true; + description.id = "uri"; + return description; } ///////////////////////////////////////////////////////////////////// @@ -51,8 +55,10 @@ public class UriAction : Action { /// 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); + public UriAction(string name, string icon, string command, bool is_quickaction = false) { + GLib.Object(name : name, icon : icon, + real_command : command.has_prefix("www") ? "http://" + command : command, + is_quickaction : is_quickaction); } ///////////////////////////////////////////////////////////////////// |