gui/view: Save and restore column widths

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-19 10:16:26 -05:00
parent 13525eda22
commit 4c784366d7
8 changed files with 168 additions and 0 deletions

View File

@ -10,6 +10,7 @@ extern "C" {
#include <gui/playlist.h>
#include <gui/settings.h>
#include <gui/sidebar.h>
#include <gui/view.h>
#include <gui/window.h>
}
#include <gui/ocarina.h>
@ -67,6 +68,7 @@ int main(int argc, char **argv)
core_init(&argc, &argv, &init_data);
gui_settings_init();
gui_view_init();
gui_window_init(gui :: share_file("ocarina.png").c_str());
gui_sidebar_init();
gui_collection_init();

51
gui/view.c Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <gui/builder.h>
#include <gui/model.h>
#include <gui/queue.h>
#include <gui/settings.h>
static const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
[Q_MODEL_TRACK_NR] = "gui.queue.track",
[Q_MODEL_TITLE] = "gui.queue.title",
[Q_MODEL_LENGTH] = "gui.queue.length",
[Q_MODEL_ARTIST] = "gui.queue.artist",
[Q_MODEL_ALBUM] = "gui.queue.album",
[Q_MODEL_YEAR] = "gui.queue.year",
[Q_MODEL_GENRE] = "gui.queue.genre",
[Q_MODEL_COUNT] = "gui.queue.count",
[Q_MODEL_LAST_PLAY] = "gui.queue.played",
[Q_MODEL_FILE_PATH] = "gui.queue.filepath",
};
static GtkTreeView *view_treeview = NULL;
void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec,
gpointer data)
{
unsigned int i;
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
if (col == gtk_tree_view_get_column(view_treeview, i)) {
gui_settings_set(QUEUE_SETTINGS[i],
gtk_tree_view_column_get_width(col));
break;
}
}
}
void gui_view_init()
{
GtkTreeViewColumn *col;
int i, pos;
view_treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
col = gtk_tree_view_get_column(view_treeview, i);
pos = gui_settings_get(QUEUE_SETTINGS[i]);
if (col && pos > 0)
gtk_tree_view_column_set_fixed_width(col, pos);
}
}

10
include/gui/view.h Normal file
View File

@ -0,0 +1,10 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#ifndef OCARINA_GUI_VIEW_H
#define OCARINA_GUI_VIEW_H
/* Called to initialize structures needed by the treeview. */
void gui_view_init();
#endif /* OCARINA_GUI_VIEW_H */

View File

@ -29,6 +29,12 @@ void __collection_toggled() {}
void __playlist_selection_changed() {}
#endif /* TEST_NEED_PLAYLIST */
#ifdef TEST_NEED_QUEUE
void __queue_disabled() {}
void __queue_random() {}
void __queue_repeat() {}
#endif /* TEST_NEED_QUEUE */
#ifdef TEST_NEED_WINDOW
void __window_configure() {}
void __window_state() {}

View File

@ -1121,6 +1121,7 @@
<property name="fixed_width">20</property>
<property name="title" translatable="yes">#</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
<attributes>
@ -1136,6 +1137,7 @@
<property name="fixed_width">300</property>
<property name="title" translatable="yes">Title</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext5"/>
<attributes>
@ -1151,6 +1153,7 @@
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Length</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext6"/>
<attributes>
@ -1166,6 +1169,7 @@
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Artist</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext7"/>
<attributes>
@ -1181,6 +1185,7 @@
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Album</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext8"/>
<attributes>
@ -1196,6 +1201,7 @@
<property name="fixed_width">45</property>
<property name="title" translatable="yes">Year</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext9"/>
<attributes>
@ -1211,6 +1217,7 @@
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Genre</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext10"/>
<attributes>
@ -1226,6 +1233,7 @@
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Count</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext11"/>
<attributes>
@ -1241,6 +1249,7 @@
<property name="fixed_width">1</property>
<property name="title" translatable="yes">Played</property>
<property name="clickable">True</property>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext12"/>
<attributes>

View File

@ -1,6 +1,7 @@
builder
settings
model
view
queue
window
sidebar

View File

@ -27,6 +27,7 @@ env.UsePackage("gmodule-export-2.0")
res += [ GuiTest("builder") ]
res += [ GuiTest("settings") ]
res += [ GuiTest("model") ]
res += [ GuiTest("view") ]
res += [ GuiTest("queue") ]
res += [ GuiTest("window") ]
res += [ GuiTest("sidebar") ]

88
tests/gui/view.c Normal file
View File

@ -0,0 +1,88 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#define TEST_NEED_AUDIO
#define TEST_NEED_COLLECTION
#define TEST_NEED_PLAYLIST
#define TEST_NEED_QUEUE
#define TEST_NEED_SIDEBAR
#define TEST_NEED_WINDOW
#include <gui/builder.h>
#include <gui/model.h>
#include <gui/settings.h>
#include <gui/view.h>
#include <tests/gui.h>
#include <tests/test.h>
const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
[Q_MODEL_TRACK_NR] = "gui.queue.track",
[Q_MODEL_TITLE] = "gui.queue.title",
[Q_MODEL_LENGTH] = "gui.queue.length",
[Q_MODEL_ARTIST] = "gui.queue.artist",
[Q_MODEL_ALBUM] = "gui.queue.album",
[Q_MODEL_YEAR] = "gui.queue.year",
[Q_MODEL_GENRE] = "gui.queue.genre",
[Q_MODEL_COUNT] = "gui.queue.count",
[Q_MODEL_LAST_PLAY] = "gui.queue.played",
[Q_MODEL_FILE_PATH] = "gui.queue.filepath",
};
GMainLoop *main_loop;
static int test_on_idle(gpointer data)
{
g_main_loop_quit(main_loop);
return G_SOURCE_CONTINUE;
}
static void test_treeview()
{
GtkTreeViewColumn *col;
GtkTreeView *treeview;
unsigned int i;
int argc = 0;
gtk_init(&argc, NULL);
gui_builder_init("share/ocarina/ocarina6.glade");
gui_settings_init();
gui_view_init();
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
main_loop = g_main_loop_new(NULL, FALSE);
g_idle_add(test_on_idle, NULL);
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
test_loop_equal(gui_settings_has(QUEUE_SETTINGS[i]),
(bool)false, i);
} test_loop_passed();
for (i = 0; i < (Q_MODEL_N_COLUMNS - 1); i++) {
col = gtk_tree_view_get_column(treeview, i);
gtk_tree_view_column_set_fixed_width(col, (i + 1) * 10);
}
g_main_loop_run(main_loop);
for (i = 0; i < (Q_MODEL_N_COLUMNS - 1); i++) {
test_loop_equal(gui_settings_has(QUEUE_SETTINGS[i]),
(bool)true, i);
/* The "Played" column gets any remaining space. */
if (i != Q_MODEL_LAST_PLAY)
test_loop_equal(gui_settings_get(QUEUE_SETTINGS[i]),
(i + 1) * 10, i);
} test_loop_passed();
test_equal(gui_settings_has("gui.queue.filepath"), (bool)false);
test_equal(gui_settings_get("gui.queue.filepath"), 0);
for (i = 0; i < Q_MODEL_LAST_PLAY; i++)
gui_settings_set(QUEUE_SETTINGS[i], 42);
gui_view_init();
for (i = 0; i < Q_MODEL_LAST_PLAY; i++) {
col = gtk_tree_view_get_column(treeview, i);
test_loop_equal(gtk_tree_view_column_get_fixed_width(col), 42, i);
} test_loop_passed();
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Treeview", test_treeview),
);