+ (void)user_data;
+}
+
+/**
+Callback for the mount/unmount button. Causes the selected row in the device
+list to be activated.
+*/
+void button_clicked(GtkButton *button, gpointer user_data)
+{
+ GuiContext *context = (GuiContext *)user_data;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeViewColumn *column;
+
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(context->list));
+ gtk_tree_selection_get_selected(selection, &model, &iter);
+ path = gtk_tree_model_get_path(model, &iter);
+ column = gtk_tree_view_get_column(GTK_TREE_VIEW(context->list), 0);
+ gtk_tree_view_row_activated(GTK_TREE_VIEW(context->list), path, column);
+ gtk_tree_path_free(path);
+
+ (void)button;
+}
+
+/**
+Global key press callback for the window.
+*/
+gboolean key_press(GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+ if(event->key.keyval==GDK_KEY_Escape)
+ {
+ gtk_main_quit();
+ return TRUE;
+ }
+
+ (void)widget;
+ (void)user_data;
+
+ return FALSE;
+}
+
+/**
+Callback for inotify events.
+*/
+gboolean inotify_event_available(GIOChannel *source, GIOCondition condition, gpointer user_data)
+{
+ GuiContext *context = (GuiContext *)user_data;
+ int fd;
+ char eventbuf[sizeof(struct inotify_event)+NAME_MAX+1];
+ int len;
+
+ fd = g_io_channel_unix_get_fd(source);
+ len = read(fd, eventbuf, sizeof(eventbuf));
+ if(len>=(int)sizeof(struct inotify_event))
+ {
+ if(!context->refresh_pending)
+ {
+ g_timeout_add(500, &refresh_devices_idle, context);
+ context->refresh_pending = 1;
+ }
+ }
+
+ (void)condition;
+
+ return TRUE;
+}
+
+void show_help(void)
+{
+ printf("pmount-gui\n"
+ "Copyright (c) 2011-2015 Mikko Rasa, Mikkosoft Productions\n\n"
+ "Usage: pmount-gui [-v] [-u] [-r <command>] [-h]\n\n"
+ "Options:\n"
+ " -v Increase verbosity\n"
+ " -u Unmount a device (default is mount)\n"
+ " -r Run a command after mounting\n"
+ " -m Start a persistent mount manager\n"
+ " -M Like -m, but hide the window if there are no devices\n"
+ " -h Display this help\n");