Display a mount/unmount button below the device list
authorMikko Rasa <tdb@tdb.fi>
Sun, 16 Nov 2014 16:37:52 +0000 (18:37 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 16 Nov 2014 16:37:52 +0000 (18:37 +0200)
main.c

diff --git a/main.c b/main.c
index bed5e1bf0dd0964c69e6fa161816e6d05a9ec075..25ad7edd401bd7ad7f6aa49128c52effa5058262 100644 (file)
--- 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(&gtk_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)