ocarina: Created a "remove path" button

Clicking this button removes a path from the library
This commit is contained in:
Bryan Schumaker 2011-10-20 20:19:51 -04:00
parent 245157c6b4
commit b84a19cd77
1 changed files with 50 additions and 6 deletions

View File

@ -11,10 +11,17 @@ using namespace std;
#include <libsaria/library.h>
#include <libsaria/print.h>
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<GtkWidget *> path_widgets;
static list<PathInfo> 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<PathInfo>::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();
}