3
* Lucas Baudin <xapantu@gmail.com>
4
* ammonkey <am.monkeyd@gmail.com>
6
* Copyright (C) Lucas Baudin 2011 <xapantu@gmail.com>
8
* Marlin is free software: you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License as published by the
10
* Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
13
* Marlin is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
* See the GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License along
19
* with this program. If not, see <http://www.gnu.org/licenses/>.
25
[DBus (name = "org.elementary.contractor")]
26
public interface ExtendedActionsService : Object
28
//public abstract GLib.HashTable<string,string>[] GetServicesByMime (string mime) throws IOError;
29
public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime="") throws IOError;
30
public abstract GLib.HashTable<string,string>[] GetServicesByLocationsList (GLib.HashTable<string, string>[] locations) throws IOError;
33
public class Marlin.Plugins.ExtendedActions : Marlin.Plugins.Base
37
GOF.File current_directory = null;
38
unowned GLib.List<GOF.File> selection;
39
GLib.HashTable<string,string>[] services = null;
41
private ExtendedActionsService service_eactions;
43
public ExtendedActions ()
46
service_eactions = Bus.get_proxy_sync (BusType.SESSION,
47
"org.elementary.contractor",
48
"/org/elementary/contractor");
50
stderr.printf ("%s\n", e.message);
54
private string get_app_display_name (GLib.HashTable<string,string> app__)
56
return app__.lookup ("Description");
59
private GLib.HashTable<string,string> add_location_entry (GOF.File file)
61
GLib.HashTable<string,string> entry;
63
entry = new GLib.HashTable<string,string> (str_hash, str_equal);
64
entry.insert ("uri", file.uri);
65
var ftype = file.get_ftype ();
66
if (ftype == "application/octet-stream" || ftype == null)
67
entry.insert ("mimetype", "");
69
entry.insert ("mimetype", ftype);
74
private GLib.HashTable<string, string>[] build_hash_from_list_selection ()
76
GLib.HashTable<string,string>[] locations = null;
78
foreach (GOF.File file in selection) {
80
locations += add_location_entry (file);
81
//message ("file %s", file.name);
83
if (selection == null && current_directory != null) {
84
locations += add_location_entry (current_directory);
90
public void action_activated ()
92
Gtk.MenuItem menuitem;
93
GLib.HashTable<string,string> app__;
95
menuitem = (Gtk.MenuItem) menu.get_active ();
96
app__ = menuitem.get_data<GLib.HashTable<string,string>> ("app");
99
var cmd = app__.lookup ("Exec");
100
//message ("test exec %s", cmd);
102
GLib.Process.spawn_command_line_async (cmd);
103
} catch (SpawnError e) {
104
stderr.printf ("error spawn command line %s: %s", cmd, e.message);
109
public override void context_menu (Gtk.Widget? widget, GLib.List<GOF.File> files)
111
menu = widget as Gtk.Menu;
115
services = service_eactions.GetServicesByLocationsList (build_hash_from_list_selection ());
118
foreach(var app__ in services)
120
/* insert separator if we got at least 1 action */
122
var item = new Gtk.SeparatorMenuItem ();
125
plugins.menus.prepend (item);
127
var menuitem = new Gtk.MenuItem.with_label(get_app_display_name(app__));
128
menu.append (menuitem);
129
menuitem.set_data<GLib.HashTable<string,string>> ("app", app__);
131
menuitem.activate.connect (action_activated);
132
plugins.menus.prepend (menuitem);
135
} catch (IOError e) {
136
stderr.printf ("%s\n", e.message);
140
public override void ui (Gtk.UIManager? widget)
143
menu = (Gtk.Menu)ui_manager.get_widget("/selection");
146
public override void directory_loaded (void* user_data)
148
current_directory = ((Object[])user_data)[2] as GOF.File;
152
public Marlin.Plugins.Base module_init ()
154
return new Marlin.Plugins.ExtendedActions ();