ocarina: Implement the "Add Library" button
To add new paths to the library. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
97a7edce41
commit
5d2631d19a
|
@ -15,6 +15,7 @@ string lib_file(const string &);
|
|||
GObject *get_object(const string &);
|
||||
GtkWidget *get_widget(const string &);
|
||||
void connect_signal(const string &, const string &, GCallback, void *);
|
||||
string run_chooser(const string &);
|
||||
|
||||
/* window.cpp */
|
||||
void init_window();
|
||||
|
|
|
@ -120,7 +120,7 @@ namespace libsaria
|
|||
path.path = dir;
|
||||
|
||||
path_ptr = push_path(path);
|
||||
do_update_path(path_ptr);
|
||||
update_path(path_ptr);
|
||||
}
|
||||
|
||||
void library::delete_path(Path *path)
|
||||
|
|
|
@ -72,12 +72,17 @@ void LibraryDriver::path_removed(libsaria::library::Path *path)
|
|||
gtk_list_store_remove(get_list(), &iter);
|
||||
}
|
||||
|
||||
static void update_libraries(GtkWidget *b, gpointer d)
|
||||
static void add_library(GtkWidget *b, gpointer d)
|
||||
{
|
||||
libsaria::library::update_all();
|
||||
string dir = run_chooser("LibraryPathChooser");
|
||||
if (dir != "") {
|
||||
println("Scanning dir: " + dir);
|
||||
libsaria::library::add_path(dir);
|
||||
}
|
||||
}
|
||||
|
||||
void init_library()
|
||||
{
|
||||
connect_signal("UpdateLibraries", "clicked", G_CALLBACK(update_libraries), NULL);
|
||||
connect_signal("AddLibrary", "clicked", G_CALLBACK(add_library), NULL);
|
||||
connect_signal("UpdateLibraries", "clicked", G_CALLBACK(libsaria::library::update_all), NULL);
|
||||
}
|
||||
|
|
|
@ -92,6 +92,21 @@ void connect_signal(const string &name, const string &signal, GCallback func, vo
|
|||
g_signal_connect(widget, signal.c_str(), func, data);
|
||||
}
|
||||
|
||||
string run_chooser(const string &name)
|
||||
{
|
||||
char *file;
|
||||
string filename = "";
|
||||
GtkWidget *chooser = get_widget(name);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_OK) {
|
||||
file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser));
|
||||
filename = file;
|
||||
g_free(file);
|
||||
}
|
||||
gtk_widget_hide(chooser);
|
||||
return filename;
|
||||
}
|
||||
|
||||
static void init(int argc, char **argv)
|
||||
{
|
||||
gtk_init(&argc, &argv);
|
||||
|
|
|
@ -19,6 +19,73 @@
|
|||
<property name="step_increment">1</property>
|
||||
<property name="page_increment">10</property>
|
||||
</object>
|
||||
<object class="GtkAction" id="action1"/>
|
||||
<object class="GtkFileChooserDialog" id="LibraryPathChooser">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">5</property>
|
||||
<property name="title" translatable="yes">Choose a directory</property>
|
||||
<property name="role">GtkFileChooserDialog</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="action">select-folder</property>
|
||||
<property name="preview_widget_active">False</property>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkVBox" id="dialog-vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkHButtonBox" id="dialog-action_area1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="button1">
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button2">
|
||||
<property name="label">gtk-open</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="-6">button1</action-widget>
|
||||
<action-widget response="-5">button2</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
<object class="GtkWindow" id="MainWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -393,6 +460,8 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">LibraryList</property>
|
||||
<property name="headers_visible">False</property>
|
||||
<property name="headers_clickable">False</property>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
|
||||
<property name="title" translatable="yes">On</property>
|
||||
|
|
Loading…
Reference in New Issue