1/* 2Copyright (c) 2011 by Simon Schneegans 3 4This program is free software: you can redistribute it and/or modify it 5under the terms of the GNU General Public License as published by the Free 6Software Foundation, either version 3 of the License, or (at your option) 7any later version. 8 9This program is distributed in the hope that it will be useful, but WITHOUT 10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12more details. 13 14You should have received a copy of the GNU General Public License along with 15this program. If not, see <http://www.gnu.org/licenses/>. 16*/ 17 18namespace GnomePie { 19 20///////////////////////////////////////////////////////////////////////// 21/// This type of Action launches an application or a custom command. 22///////////////////////////////////////////////////////////////////////// 23 24public class AppAction : Action { 25 26 ///////////////////////////////////////////////////////////////////// 27 /// Used to register this type of Action. It sets the display name 28 /// for this Action, whether it has a custom Icon/Name and the string 29 /// used in the pies.conf file for this kind of Actions. 30 ///////////////////////////////////////////////////////////////////// 31 32 public static ActionRegistry.TypeDescription register() { 33 var description = new ActionRegistry.TypeDescription(); 34 description.name = _("Launch application"); 35 description.icon = "application-x-executable"; 36 description.description = _("Executes the given command."); 37 description.icon_name_editable = true; 38 description.id = "app"; 39 return description; 40 } 41 42 ///////////////////////////////////////////////////////////////////// 43 /// Stores the command line. 44 ///////////////////////////////////////////////////////////////////// 45 46 public override string real_command { get; construct set; } 47 48 ///////////////////////////////////////////////////////////////////// 49 /// Simply returns the real_command. No beautification. 50 ///////////////////////////////////////////////////////////////////// 51 52 public override string display_command { get {return real_command;} } 53 54 ///////////////////////////////////////////////////////////////////// 55 /// C'tor, initializes all members. 56 ///////////////////////////////////////////////////////////////////// 57 58 public AppAction(string name, string icon, string command, bool is_quickaction = false) { 59 GLib.Object(name : name, icon : icon, real_command : command, is_quickaction : is_quickaction); 60 } 61 62 ///////////////////////////////////////////////////////////////////// 63 /// Launches the desired command. 64 ///////////////////////////////////////////////////////////////////// 65 66 public override void activate() { 67 try{ 68 var item = GLib.AppInfo.create_from_commandline(this.real_command, null, GLib.AppInfoCreateFlags.NONE); 69 item.launch(null, null); 70 } catch (Error e) { 71 warning(e.message); 72 } 73 } 74} 75 76} 77