From b84a19cd77ac6bb9a4f826ebe58d178bd1822863 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Thu, 20 Oct 2011 20:19:51 -0400 Subject: [PATCH] ocarina: Created a "remove path" button Clicking this button removes a path from the library --- ocarina/settings/library.cpp | 56 ++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/ocarina/settings/library.cpp b/ocarina/settings/library.cpp index 5e67a125..a76e6c5a 100644 --- a/ocarina/settings/library.cpp +++ b/ocarina/settings/library.cpp @@ -11,10 +11,17 @@ using namespace std; #include #include +struct PathInfo +{ + GtkWidget *widget; + GtkWidget *remove; + string path; +}; + /* This is a gtk vbox */ static GtkWidget *library_settings = NULL; static GtkWidget *path_panels = NULL; -static list path_widgets; +static list path_widgets; static void on_click_add(GtkWidget *b, GdkEvent *e, gpointer d) { @@ -30,6 +37,17 @@ static void on_click_update(GtkWidget *b, GdkEvent *e, gpointer d) libsaria::library::update(); } +static void on_click_remove(GtkWidget *b, GdkEvent *e, gpointer d) +{ + list::iterator it; + for (it = path_widgets.begin(); it != path_widgets.end(); it++) { + if ((*it).remove == b) { + libsaria::library::remove_path((*it).path); + break; + } + } +} + static GtkWidget *make_add_button() { return make_text_button(GTK_STOCK_ADD, @@ -46,6 +64,14 @@ static GtkWidget *make_update_button() true); } +static GtkWidget *make_remove_button() +{ + return make_text_button(GTK_STOCK_REMOVE, + "Remove Path", + on_click_remove, + true); +} + static GtkWidget *markup_label(string markup) { GtkWidget *label = gtk_label_new(""); @@ -71,7 +97,18 @@ static GtkWidget *make_path_info(string path, unsigned int size) return box; } -static void add_library_panel(GtkWidget *content) +static GtkWidget *add_buttons(GtkWidget *info_box, struct PathInfo &path) +{ + GtkWidget *button_box = gtk_hbox_new(FALSE, 0); + GtkWidget *remove_btn = make_remove_button(); + + path.remove = remove_btn; + box_pack_start(button_box, info_box, TRUE, TRUE, 0); + box_pack_start(button_box, remove_btn, FALSE, FALSE, 0); + return button_box; +} + +static void add_library_panel(GtkWidget *content, struct PathInfo &path) { GtkWidget *panel_box = gtk_vbox_new(FALSE, 0); GtkWidget *sep = gtk_hseparator_new(); @@ -79,21 +116,28 @@ static void add_library_panel(GtkWidget *content) box_pack_start(panel_box, content, TRUE, TRUE, 0); box_pack_start(panel_box, sep, TRUE, TRUE, 0); box_pack_start(path_panels, panel_box, FALSE, FALSE, 0); - path_widgets.push_back(panel_box); + + path.widget = panel_box; + path_widgets.push_back(path); } static void add_library_path(struct libsaria::library::PathInfo &info) { + struct PathInfo path; GtkWidget *main_box = gtk_hbox_new(FALSE, 0); GtkWidget *info_box = make_path_info(info.path, info.size); - box_pack_start(main_box, info_box, TRUE, TRUE, 0); - add_library_panel(main_box); + GtkWidget *buttons = add_buttons(info_box, path); + + path.path = info.path; + + box_pack_start(main_box, buttons, TRUE, TRUE, 0); + add_library_panel(main_box, path); } void library_settings_refresh() { while (path_widgets.size() != 0) { - gtk_widget_destroy(path_widgets.front()); + gtk_widget_destroy(path_widgets.front().widget); path_widgets.pop_front(); }