Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- ../udisks-automounter-0.0.2/Makefile 2010-10-05 19:02:14.000000000 +0200
- +++ Makefile 2010-10-10 11:32:55.000000000 +0200
- @@ -6,10 +6,10 @@ CFLAGS?= -O2
- PREFIX?=/usr/local
- udisks-automounter.c udisks-dbus-interfaces.c : udisks-automounter.vala udisks-dbus-interfaces.vala
- - valac --pkg dbus-glib-1 --pkg gio-2.0 -C $^
- + valac --pkg gee-1.0 --pkg dbus-glib-1 --pkg gio-2.0 -C $^
- udisks-automounter: udisks-automounter.c udisks-dbus-interfaces.c
- - gcc $(CFLAGS) $(LDFLAGS) -o udisks-automounter `pkg-config --cflags --libs glib-2.0 gio-2.0 dbus-glib-1` $^
- + gcc $(CFLAGS) $(LDFLAGS) -o udisks-automounter `pkg-config --cflags --libs gee-1.0 glib-2.0 gio-2.0 dbus-glib-1` $^
- dist: udisks-automounter.c udisks-dbus-interfaces.c
- mkdir udisks-automounter-$(VERSION)
- --- ../udisks-automounter-0.0.2/udisks-automounter.vala 2010-10-04 10:45:45.000000000 +0200
- +++ udisks-automounter.vala 2010-10-10 11:32:55.000000000 +0200
- @@ -19,11 +19,15 @@
- using UDisks;
- using DBus;
- +using Gee;
- const string[] gui_clients = { "Thunar", "nautilus", "pcmanfm", "emelfm2" };
- DBus.Connection dbus;
- bool coldplug = true;
- +HashMap<string, string> device_map;
- +string env_client ;
- +bool close_client;
- async void
- on_device_added_async(ObjectPath device)
- @@ -42,24 +46,74 @@ on_device_added_async(ObjectPath device)
- {
- stdout.printf(" appropriate for auto-mounting\n");
- string path = yield dev.filesystem_mount("", {"auth_no_user_interaction"});
- + device_map[device] = path;
- stdout.printf(" mounted to: %s\n", path);
- /* now launch a GUI window on the mount path */
- if (open_client) {
- int pid;
- - foreach (string client in gui_clients) {
- - stdout.printf(" trying to launch %s\n", client);
- - try {
- - if (Process.spawn_async(null, {client, path}, null,
- - SpawnFlags.SEARCH_PATH, null, out pid))
- - stdout.printf(" success!\n");
- - break;
- - } catch { /* ignore, try next one */ }
- + Environment.set_variable ("ACTION", "MOUNT", true);
- + if (env_client == null)
- + {
- + foreach (string client in gui_clients) {
- + stdout.printf(" trying to launch %s\n", client);
- + try {
- + if (Process.spawn_async(null, {client, path}, null,
- + SpawnFlags.SEARCH_PATH, null, out pid))
- + stdout.printf(" success!\n");
- + break;
- + } catch { /* ignore, try next one */ }
- + }
- + }
- + else
- + {
- + if (Process.spawn_async(null, {env_client, path}, null,
- + SpawnFlags.SEARCH_PATH, null, out pid))
- + stdout.printf(" success!\n");
- + }
- + }
- + }
- +}
- +
- +async void
- +on_device_removed_async(ObjectPath device)
- +{
- + stdout.printf("Device removed: %s \n", device);
- + if ( device_map.has_key(device) )
- + {
- + string path = device_map[device];
- + if (device_map.unset(device))
- + {
- + stdout.printf("Device removed from List: %s \n", device);
- + }
- +
- + /* now launch a GUI window on the mount path */
- + if (close_client) {
- + int pid;
- + Environment.set_variable ("ACTION", "UNMOUNT", true);
- + if (env_client == null)
- + {
- + foreach (string client in gui_clients) {
- + stdout.printf(" trying to launch %s\n", client);
- + try {
- + if (Process.spawn_async(null, {client, path}, null,
- + SpawnFlags.SEARCH_PATH, null, out pid))
- + stdout.printf(" success!\n");
- + break;
- + } catch { /* ignore, try next one */ }
- + }
- + }
- + else
- + {
- + if (Process.spawn_async(null, {env_client, path}, null,
- + SpawnFlags.SEARCH_PATH, null, out pid))
- + stdout.printf(" success!\n");
- }
- }
- }
- }
- +
- void
- on_device_added(ObjectPath device)
- {
- @@ -69,7 +123,7 @@ on_device_added(ObjectPath device)
- void
- on_device_removed(ObjectPath device)
- {
- - stdout.printf("Device removed: %s\n", device);
- + on_device_removed_async.begin(device);
- }
- int
- @@ -89,6 +143,27 @@ main(string[] args)
- stdout.printf("Connected to UDisks %s\n", udisks.daemon_version);
- + /* initialize handled devices map */
- + device_map = new HashMap<string, string> ();
- +
- + /* try to read client and if action to be send from ENV */
- + if (Environment.get_variable("UDISK_AUTOMOUNTER_CLIENT") != null)
- + {
- + env_client = Environment.get_variable("UDISK_AUTOMOUNTER_CLIENT");
- + }
- +
- + if (Environment.get_variable("UDISK_AUTOMOUNTER_ON_CLOSE") != null)
- + {
- + if (Environment.get_variable("UDISK_AUTOMOUNTER_ON_CLOSE") == "yes")
- + {
- + close_client = true ;
- + }
- + else
- + {
- + close_client = false;
- + }
- + }
- +
- /* Coldplug */
- foreach (ObjectPath o in udisks.enumerate_devices())
- on_device_added_async (o);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement