gui/collection: Change tab page when "Add new Path" is selected
I also add in code that reuses the current file chooser for picking paths. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
eb81fa2e20
commit
f34e2cb57b
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/collection.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/tempq.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/collection.h>
|
||||
|
||||
|
@ -15,6 +18,61 @@ enum collection_sidebar_columns {
|
|||
|
||||
static GtkTreeModel *c_model;
|
||||
|
||||
static void __collection_set_header(GtkTreeIter *iter, const gchar *image,
|
||||
GtkIconSize size, const gchar *text)
|
||||
{
|
||||
gtk_tree_store_set(GTK_TREE_STORE(c_model), iter, C_SB_IMAGE, image,
|
||||
C_SB_IMAGE_SZ, size, C_SB_PATH, text, -1);
|
||||
}
|
||||
|
||||
static void __collection_set_library(GtkTreeIter *iter, struct library *library)
|
||||
{
|
||||
gtk_tree_store_set(GTK_TREE_STORE(c_model), iter,
|
||||
C_SB_ENABLED, library->li_enabled,
|
||||
C_SB_SHOW_ENABLED, true,
|
||||
C_SB_PATH, library->li_path,
|
||||
C_SB_LIBRARY, library, -1);
|
||||
}
|
||||
|
||||
static struct library *__collection_get_library(GtkTreeIter *iter)
|
||||
{
|
||||
struct library *library;
|
||||
|
||||
gtk_tree_model_get(c_model, iter, C_SB_LIBRARY, &library, -1);
|
||||
return library;
|
||||
}
|
||||
|
||||
void __collection_add(GtkButton *button, GtkFileChooser *chooser)
|
||||
{
|
||||
gchar *filename = gtk_file_chooser_get_filename(chooser);
|
||||
GtkTreeIter iter, last;
|
||||
|
||||
gtk_tree_model_get_iter_first(c_model, &iter);
|
||||
gtk_tree_model_iter_nth_child(c_model, &last, &iter, 0);
|
||||
while (__collection_get_library(&last) != NULL)
|
||||
gtk_tree_model_iter_next(c_model, &last);
|
||||
|
||||
gtk_tree_store_insert_before(GTK_TREE_STORE(c_model), &iter, NULL, &last);
|
||||
__collection_set_library(&iter, collection_add(filename));
|
||||
|
||||
gui_collection_idle_enable();
|
||||
g_free(filename);
|
||||
}
|
||||
|
||||
void __collection_selection_changed(GtkTreeSelection *selection,
|
||||
gpointer data)
|
||||
{
|
||||
GtkNotebook *notebook = GTK_NOTEBOOK(gui_builder_widget("o_notebook"));
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (gtk_tree_selection_get_selected(selection, &c_model, &iter)) {
|
||||
if (!__collection_get_library(&iter)) {
|
||||
gtk_notebook_set_current_page(notebook,
|
||||
tempq_count() + 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean __collection_select(GtkTreeSelection *selection,
|
||||
GtkTreeModel *model, GtkTreePath *path,
|
||||
gboolean selected, gpointer data)
|
||||
|
@ -22,23 +80,48 @@ static gboolean __collection_select(GtkTreeSelection *selection,
|
|||
return gtk_tree_path_get_depth(path) != 1;
|
||||
}
|
||||
|
||||
static gboolean __collection_on_idle(gpointer data)
|
||||
{
|
||||
GtkProgressBar *progress = GTK_PROGRESS_BAR(data);
|
||||
|
||||
if (idle_run_task()) {
|
||||
gtk_progress_bar_set_fraction(progress, idle_progress());
|
||||
return G_SOURCE_CONTINUE;
|
||||
} else {
|
||||
gtk_widget_hide(GTK_WIDGET(progress));
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
}
|
||||
|
||||
void gui_collection_init()
|
||||
{
|
||||
GtkTreeIter parent, iter;
|
||||
GtkTreeView *treeview;
|
||||
GtkTreeIter parent;
|
||||
|
||||
c_model = GTK_TREE_MODEL(gui_builder_object("o_collection_store"));
|
||||
|
||||
/* Add "Collection" header. */
|
||||
gtk_tree_store_insert(GTK_TREE_STORE(c_model), &parent, NULL, -1);
|
||||
gtk_tree_store_set(GTK_TREE_STORE(c_model), &parent,
|
||||
C_SB_IMAGE, "system-file-manager",
|
||||
C_SB_IMAGE_SZ, GTK_ICON_SIZE_LARGE_TOOLBAR,
|
||||
C_SB_PATH, "<span size='large'>Collection</span>",
|
||||
-1);
|
||||
__collection_set_header(&parent, "system-file-manager",
|
||||
GTK_ICON_SIZE_LARGE_TOOLBAR,
|
||||
"<span size='large'>Collection</span>");
|
||||
|
||||
/* Add "Add new Library" entry. */
|
||||
gtk_tree_store_insert(GTK_TREE_STORE(c_model), &iter, &parent, -1);
|
||||
__collection_set_header(&iter, "folder-new", GTK_ICON_SIZE_MENU,
|
||||
"<span style='italic'><Add new path></span>");
|
||||
|
||||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view"));
|
||||
gtk_tree_view_expand_all(treeview);
|
||||
gtk_tree_selection_set_select_function(
|
||||
gtk_tree_view_get_selection(treeview),
|
||||
__collection_select, NULL, NULL);
|
||||
}
|
||||
|
||||
void gui_collection_idle_enable()
|
||||
{
|
||||
GtkWidget *progress = gui_builder_widget("o_idle_progress");
|
||||
|
||||
gtk_widget_show(progress);
|
||||
g_idle_add(__collection_on_idle, progress);
|
||||
}
|
||||
|
|
|
@ -7,4 +7,7 @@
|
|||
/* Called to initialize the GUI collection code. */
|
||||
void gui_collection_init();
|
||||
|
||||
/* Called to enable processing idle queue tasks. */
|
||||
void gui_collection_idle_enable();
|
||||
|
||||
#endif /* OCARINA_GUI_COLLECTION_H */
|
||||
|
|
|
@ -15,4 +15,9 @@ void __audio_seek() {}
|
|||
void __sidebar_resize() {}
|
||||
#endif /* TEST_NEED_SIDEBAR */
|
||||
|
||||
#ifdef TEST_NEED_COLLECTION
|
||||
void __collection_add() {}
|
||||
void __collection_selection_changed() {}
|
||||
#endif /* TEST_NEED_COLLECTION */
|
||||
|
||||
#endif /* TESTS_GUI_H */
|
||||
|
|
|
@ -24,6 +24,14 @@
|
|||
<mime-type>inode/directory</mime-type>
|
||||
</mime-types>
|
||||
</object>
|
||||
<object class="GtkImage" id="image11">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xpad">5</property>
|
||||
<property name="ypad">5</property>
|
||||
<property name="icon_name">dialog-ok</property>
|
||||
<property name="icon_size">3</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="image12">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -621,7 +629,9 @@
|
|||
<property name="level_indentation">10</property>
|
||||
<property name="enable_tree_lines">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="treeview-selection2"/>
|
||||
<object class="GtkTreeSelection" id="treeview-selection2">
|
||||
<signal name="changed" handler="__collection_selection_changed" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
|
||||
|
@ -698,7 +708,6 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="action">select-folder</property>
|
||||
<property name="create_folders">False</property>
|
||||
<property name="filter">filefilter1</property>
|
||||
|
@ -886,11 +895,45 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButtonBox" id="buttonbox3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="opacity">0.96999999999999997</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="layout_style">start</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="button1">
|
||||
<property name="label" translatable="yes">Add Selected Path</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="image">image11</property>
|
||||
<signal name="clicked" handler="__collection_add" object="colmgr_chooser" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="tab_fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkBox" id="box4">
|
||||
|
@ -1072,7 +1115,6 @@ Manager</property>
|
|||
<object class="GtkBox" id="box12">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkProgressBar" id="o_idle_progress">
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -1125,7 +1167,7 @@ Manager</property>
|
|||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="padding">1</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
|
|
|
@ -10,16 +10,18 @@
|
|||
static void test_collection_sidebar()
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeIter iter, child;
|
||||
GtkNotebook *notebook;
|
||||
GtkTreeView *treeview;
|
||||
GtkTreeModel *model;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
int argc = 0;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||
gui_collection_init();
|
||||
|
||||
notebook = GTK_NOTEBOOK(gui_builder_widget("o_notebook"));
|
||||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view"));
|
||||
selection = gtk_tree_view_get_selection(treeview);
|
||||
model = GTK_TREE_MODEL(gui_builder_object("o_collection_store"));
|
||||
|
@ -28,9 +30,16 @@ static void test_collection_sidebar()
|
|||
path = gtk_tree_model_get_path(model, &iter);
|
||||
gtk_tree_view_set_cursor(treeview, path, NULL, false);
|
||||
gtk_tree_path_free(path);
|
||||
|
||||
test_equal(gtk_tree_selection_count_selected_rows(selection), 0);
|
||||
|
||||
gtk_tree_model_iter_nth_child(model, &child, &iter, 0);
|
||||
path = gtk_tree_model_get_path(model, &child);
|
||||
gtk_tree_view_set_cursor(treeview, path, NULL, false);
|
||||
gtk_tree_path_free(path);
|
||||
test_equal(gtk_tree_selection_count_selected_rows(selection), 1);
|
||||
test_equal(gtk_notebook_get_current_page(notebook),
|
||||
gtk_notebook_get_n_pages(notebook) - 1);
|
||||
|
||||
gui_builder_deinit();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#define TEST_NEED_AUDIO
|
||||
#define TEST_NEED_COLLECTION
|
||||
#include <gui/builder.h>
|
||||
#include <gui/settings.h>
|
||||
#include <gui/sidebar.h>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
#define TEST_NEED_AUDIO
|
||||
#define TEST_NEED_SIDEBAR
|
||||
#define TEST_NEED_COLLECTION
|
||||
#include <gui/builder.h>
|
||||
#include <gui/settings.h>
|
||||
#include <gui/window.h>
|
||||
|
|
Loading…
Reference in New Issue