From 91e55b23fdc8c5d4d72947b2bed9899bd7f90ce2 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 16 Nov 2014 18:37:52 +0200 Subject: [PATCH] Display a mount/unmount button below the device list --- main.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index bed5e1b..25ad7ed 100644 --- a/main.c +++ b/main.c @@ -634,6 +634,23 @@ void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *colu (void)column; } +void button_clicked(GtkButton *button, gpointer user_data) +{ + GtkWidget *list = (GtkWidget *)user_data; + GtkTreeSelection *selection; + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreePath *path; + + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list)); + gtk_tree_selection_get_selected(selection, &model, &iter); + path = gtk_tree_model_get_path(model, &iter); + gtk_tree_view_row_activated(GTK_TREE_VIEW(list), path, gtk_tree_view_get_column(GTK_TREE_VIEW(list), 0)); + gtk_tree_path_free(path); + + (void)button; +} + gboolean key_press(GtkWidget *widget, GdkEvent *event, gpointer user_data) { if(event->key.keyval==GDK_KEY_Escape) @@ -651,10 +668,12 @@ gboolean key_press(GtkWidget *widget, GdkEvent *event, gpointer user_data) int main(int argc, char **argv) { GtkWidget *window; + GtkWidget *box; GtkWidget *viewport; GtkWidget *list; GtkListStore *store; GtkTreeSelection *selection; + GtkWidget *button; GtkTreeIter iter; Device *devices; int i; @@ -680,9 +699,12 @@ int main(int argc, char **argv) g_signal_connect(window, "destroy", G_CALLBACK(>k_main_quit), NULL); g_signal_connect(window, "key-press-event", G_CALLBACK(&key_press), NULL); + box = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(window), box); + viewport = gtk_viewport_new(NULL, NULL); gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_IN); - gtk_container_add(GTK_CONTAINER(window), viewport); + gtk_box_pack_start(GTK_BOX(box), viewport, TRUE, TRUE, 0); list = gtk_tree_view_new(); gtk_container_add(GTK_CONTAINER(viewport), list); @@ -695,6 +717,10 @@ int main(int argc, char **argv) selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list)); + button = gtk_button_new_with_label(umount ? "Unmount" : "Mount"); + g_signal_connect(button, "clicked", G_CALLBACK(&button_clicked), list); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, TRUE, 0); + devices = get_devices(); n_listed = 0; if(devices) -- 2.45.2