+ printf("Command exited with unknown result %04X\n", status);
+ }
+
+ if(!WIFEXITED(status) || WEXITSTATUS(status))
+ return -1;
+
+ if(umount)
+ {
+ free(device->mount_point);
+ device->mount_point = NULL;
+ }
+ else
+ device->mount_point = strdup(mount_point);
+
+ return 0;
+}
+
+/**
+Callback for selection in the device list changing. Updates the action button
+label according to device status.
+*/
+void selection_changed(GtkTreeSelection *selection, gpointer user_data)
+{
+ GuiContext *context = (GuiContext *)user_data;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ Device *device;
+
+ gtk_tree_selection_get_selected(selection, &model, &iter);
+ gtk_tree_model_get(model, &iter, 1, &device, -1);
+ gtk_button_set_label(GTK_BUTTON(context->button), (device->mount_point ? "Unmount" : "Mount"));
+}
+
+/**
+Callback for activating a row in the device list. Mounts or unmounts the
+device depending on operating mode.
+*/
+void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
+{
+ GuiContext *context = (GuiContext *)user_data;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ Device *device;
+ int ret;
+ char output[1024];
+ int pid;
+
+ model = gtk_tree_view_get_model(list);
+
+ if(!gtk_tree_model_get_iter(model, &iter, path))
+ return;
+
+ gtk_tree_model_get(model, &iter, 1, &device, -1);
+ ret = toggle_device(device, output, sizeof(output));
+ if(ret)
+ {
+ GtkWidget *dialog;
+
+ /* Pmount terminated with nonzero status or a signal. Display an
+ error to the user. */
+ dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", output);
+ if(context->manager)
+ g_signal_connect(dialog, "response", G_CALLBACK(>k_widget_destroy), dialog);
+ else
+ g_signal_connect(dialog, "response", G_CALLBACK(>k_main_quit), NULL);
+ gtk_widget_show_all(dialog);
+ return;
+ }
+
+ if(context->manager)
+ {
+ gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+ 2, !!device->mount_point,
+ 3, device->mount_point,
+ -1);
+
+ gtk_button_set_label(GTK_BUTTON(context->button), (device->mount_point ? "Unmount" : "Mount"));
+ }
+ else
+ gtk_main_quit();
+
+ if(context->post_mount_command && device->mount_point)
+ {
+ if(verbosity>=1)
+ printf("Running %s in %s\n", context->post_mount_command, device->mount_point);
+
+ pid = fork();
+ if(pid==0)