commit 14251c5870d6048053dbf44d1a433360384d762a Author: phantomjinx <p.g.richard...@phantomjinx.co.uk> Date: Sun Oct 17 17:31:37 2010 +0100
Add playlist display preferences * Foremost preference to sort the playlists alphabetically .gitignore | 1 + libgtkpod/prefs.c | 25 ++-- plugins/playlist_display/Makefile.am | 29 +++- plugins/playlist_display/display_playlists.c | 64 +++---- .../icons/hicolor/16x16/places/Makefile.am | 3 +- .../places/playlist_display-playlist-category.png | Bin 0 -> 566 bytes .../icons/hicolor/22x22/places/Makefile.am | 3 +- .../places/playlist_display-playlist-category.png | Bin 0 -> 671 bytes .../icons/hicolor/24x24/places/Makefile.am | 3 +- .../places/playlist_display-playlist-category.png | Bin 0 -> 662 bytes .../icons/hicolor/32x32/places/Makefile.am | 3 +- .../places/playlist_display-playlist-category.png | Bin 0 -> 919 bytes .../icons/hicolor/48x48/places/Makefile.am | 3 +- .../places/playlist_display-playlist-category.png | Bin 0 -> 1340 bytes plugins/playlist_display/playlist_display.glade | 210 ++++++++++++++++++++ .../playlist_display_preferences.c | 98 +++++++++ .../playlist_display_preferences.h | 34 ++++ plugins/playlist_display/plugin.c | 42 ++++- plugins/playlist_display/plugin.h | 9 + 19 files changed, 468 insertions(+), 59 deletions(-) --- diff --git a/.gitignore b/.gitignore index f41a4f4..c7550e4 100644 --- a/.gitignore +++ b/.gitignore @@ -84,6 +84,7 @@ cscope.out /data/glade/core_prefs.xml /data/glade/photo_editor.glade /data/glade/media_player.glade +/data/glade/playlist_display.glade /data/ui/details_editor.ui /data/ui/coverweb.ui diff --git a/libgtkpod/prefs.c b/libgtkpod/prefs.c index 0e10901..e757b12 100644 --- a/libgtkpod/prefs.c +++ b/libgtkpod/prefs.c @@ -1875,30 +1875,31 @@ void prefs_apply_list(gchar *key, GList *list) { GList *prefs_get_list(const gchar *key) { guint end_marker_hash; /* Hash value of the list end marker */ guint item_hash; /* Hash value of current list string */ - gchar *item_string; /* List item string */ - guint i; /* Counter */ - GList *list; /* List that contains items */ + gchar *item_string = NULL; /* List item string */ + guint i = 0; /* Counter */ + GList *list = NULL; /* List that contains items */ /* Go through each key in the table until we find the end marker */ end_marker_hash = g_str_hash(LIST_END_MARKER); - list = NULL; - for (i = 0;; i++) { + /* + * The moment that a preference index returns NULL then + * return as a NULL cannot appear mid-list. + * + * Also return if a preference value is the end marker. This + * should avoid this function getting stuck in an infinite loop. + */ + do { item_string = prefs_get_string_index(key, i); if (item_string) { item_hash = g_str_hash(item_string); - if (item_hash != end_marker_hash) { list = g_list_append(list, item_string); - continue; - } - else { - g_free(item_string); - break; } } - } + i++; + } while(item_string != NULL && item_hash != end_marker_hash); return list; } diff --git a/plugins/playlist_display/Makefile.am b/plugins/playlist_display/Makefile.am index 2195c33..569c5f4 100644 --- a/plugins/playlist_display/Makefile.am +++ b/plugins/playlist_display/Makefile.am @@ -8,7 +8,7 @@ playlist_display_ui_DATA = $(plugin_name).ui # Plugin Glade file - No glade/xml file playlist_display_gladedir = $(gtkpod_glade_dir) -playlist_display_glade_DATA = +playlist_display_glade_DATA = $(plugin_name).glade # Plugin Toolbar file playlist_display_toolbardir = $(gtkpod_glade_dir) @@ -48,7 +48,8 @@ plugin_LTLIBRARIES = libplaylist_display.la libplaylist_display_la_SOURCES = plugin.c plugin.h \ display_playlists.c display_playlists.h \ playlist_display_actions.c playlist_display_actions.h \ - playlist_display_context_menu.c playlist_display_context_menu.h + playlist_display_context_menu.c playlist_display_context_menu.h \ + playlist_display_preferences.c playlist_display_preferences.h libplaylist_display_la_LDFLAGS = $(GTKPOD_PLUGIN_LDFLAGS) @@ -65,7 +66,7 @@ EXTRA_DIST = \ $(playlist_display_toolbar_DATA) \ $(playlist_display_pixmaps_DATA) -all-local: create-plugin-links create-ui-link create-toolbar-link +all-local: create-plugin-links create-ui-link create-glade-link # Creating symbolic links in plugin root directory create-plugin-links: @@ -82,8 +83,18 @@ create-ui-link: if [ ! -e ../../data/ui/$(plugin_name).ui ]; then \ ln -s `pwd`/$(plugin_name).ui ../../data/ui/$(plugin_name).ui; \ fi; - -create-toolbar-link: + +create-glade-link: + if [ -e `pwd`/$(plugin_name).glade ]; then \ + if [ ! -e ../../data/glade/$(plugin_name).glade ]; then \ + ln -s `pwd`/$(plugin_name).glade ../../data/glade/$(plugin_name).glade; \ + fi; \ + fi; \ + if [ -e `pwd`/$(plugin_name).xml ]; then \ + if [ ! -e ../../data/glade/$(plugin_name).xml ]; then \ + ln -s `pwd`/$(plugin_name).xml ../../data/glade/$(plugin_name).xml; \ + fi; \ + fi; \ if [ -e `pwd`/$(plugin_name)_toolbar.xml ]; then \ if [ ! -e ../../data/glade/$(plugin_name)_toolbar.xml ]; then \ ln -s `pwd`/$(plugin_name)_toolbar.xml ../../data/glade/$(plugin_name)_toolbar.xml; \ @@ -102,8 +113,14 @@ clean-ui-dir: if [ -h ../../data/ui/$(plugin_name).ui ]; then \ rm -f ../../data/ui/$(plugin_name).ui; \ fi; - + clean-glade-dir: + if [ -h ../../data/glade/$(plugin_name).glade ]; then \ + rm -f ../../data/glade/$(plugin_name).glade; \ + fi; \ + if [ -h ../../data/glade/$(plugin_name).xml ]; then \ + rm -f ../../data/glade/$(plugin_name).xml; \ + fi; \ if [ -h ../../data/glade/$(plugin_name)_toolbar.xml ]; then \ rm -f ../../data/glade/$(plugin_name)_toolbar.xml; \ fi; diff --git a/plugins/playlist_display/display_playlists.c b/plugins/playlist_display/display_playlists.c index e792fdd..1adcaad 100644 --- a/plugins/playlist_display/display_playlists.c +++ b/plugins/playlist_display/display_playlists.c @@ -1380,9 +1380,6 @@ static void pm_unsort() { pm_set_selected_playlist(cur_pl); - /* add playlists back to model (without selecting) */ - pm_add_all_itdbs(); - pm_selection_blocked = FALSE; /* reset sort counter */ pm_sort_counter(-1); @@ -1484,8 +1481,6 @@ gint pm_data_compare_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, g GtkSortType order; gint corr, colid; - return 0; /* FIXME: see below -- deactivated for now */ - g_return_val_if_fail (model, 0); g_return_val_if_fail (a, 0); g_return_val_if_fail (b, 0); @@ -1493,15 +1488,12 @@ gint pm_data_compare_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, g if (gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE (model), &colid, &order) == FALSE) return 0; + if (order == SORT_NONE) + return 0; + gtk_tree_model_get(model, a, colid, &playlist1, -1); gtk_tree_model_get(model, b, colid, &playlist2, -1); - /* FIXME: this function crashes because it is provided illegal - * GtkTreeIters. */ - /* FIXME: after the introduction of a GtkTreeView rather than a - * ListView, sorting should be done by a customs sort mechanism - * anyway. */ - g_return_val_if_fail (playlist1 && playlist2, 0); /* We make sure that the master playlist always stays on top */ @@ -1509,8 +1501,13 @@ gint pm_data_compare_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, g corr = +1; else corr = -1; + + if (itdb_playlist_is_mpl(playlist1) && itdb_playlist_is_mpl(playlist2)) + return 0; // Don't resort mpl playlists - only sub playlists + if (itdb_playlist_is_mpl(playlist1)) return (-corr); + if (itdb_playlist_is_mpl(playlist2)) return (corr); @@ -1852,18 +1849,12 @@ static void pm_add_columns(void) { /* playlist column */ column = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(column, _("Playlists")); - /* FIXME: see comments at pm_data_compare_func() */ - /* - gtk_tree_view_column_set_sort_column_id (column, PM_COLUMN_PLAYLIST); - gtk_tree_view_column_set_sort_order (column, GTK_SORT_ASCENDING); - gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (model), - PM_COLUMN_PLAYLIST, - pm_data_compare_func, column, NULL); - gtk_tree_view_column_set_clickable(column, TRUE); - g_signal_connect (G_OBJECT (column), "clicked", - G_CALLBACK (pm_track_column_button_clicked), - (gpointer)PM_COLUMN_PLAYLIST); - */ + + gtk_tree_view_column_set_sort_column_id (column, PM_COLUMN_PLAYLIST); + gtk_tree_view_column_set_sort_order (column, GTK_SORT_ASCENDING); + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (model), + PM_COLUMN_PLAYLIST, + pm_data_compare_func, column, NULL); gtk_tree_view_append_column(playlist_treeview, column); @@ -1895,26 +1886,27 @@ void pm_destroy_playlist_view(void) { static void pm_create_treeview(void) { GtkTreeStore *model; GtkTreeSelection *selection; - GtkWidget *tree; /* destroy old treeview */ - if (playlist_treeview) { + if (! playlist_treeview) { + /* create new one */ + playlist_treeview = GTK_TREE_VIEW (gtk_tree_view_new()); + gtk_widget_set_events(GTK_WIDGET(playlist_treeview), GDK_KEY_RELEASE_MASK); + } else { model = GTK_TREE_STORE (gtk_tree_view_get_model(playlist_treeview)); g_return_if_fail (model); g_object_unref(model); - gtk_widget_destroy(GTK_WIDGET (playlist_treeview)); - playlist_treeview = NULL; + GList *columns = gtk_tree_view_get_columns(playlist_treeview); + while (columns != NULL) { + GtkTreeViewColumn *column = columns->data; + gtk_tree_view_remove_column(playlist_treeview, column); + columns = columns->next; + } + g_list_free(columns); } - /* create new one */ - tree = gtk_tree_view_new(); - gtk_widget_set_events(tree, GDK_KEY_RELEASE_MASK); - gtk_widget_show(tree); - playlist_treeview = GTK_TREE_VIEW (tree); - /* create model */ model = gtk_tree_store_new(PM_NUM_COLUMNS, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_POINTER, G_TYPE_POINTER); - /* set tree model */ gtk_tree_view_set_model(playlist_treeview, GTK_TREE_MODEL (model)); /* gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (playlist_treeview), TRUE); */ @@ -2004,6 +1996,8 @@ GtkWidget *pm_create_playlist_view(GtkActionGroup *action_group) { gtk_box_pack_start(vbox, GTK_WIDGET(playlist_toolbar), FALSE, TRUE, 0); pm_create_treeview(); + pm_sort(prefs_get_int("pm_sort")); + gtk_box_pack_start(vbox, GTK_WIDGET(playlist_treeview), TRUE, TRUE, 0); playlist_viewport = gtk_viewport_new (0, 0); @@ -2141,7 +2135,7 @@ void playlist_display_playlist_removed_cb(GtkPodApp *app, gpointer pl, gpointer void playlist_display_preference_changed_cb(GtkPodApp *app, gpointer pfname, gint32 value, gpointer data) { gchar *pref_name = pfname; - if (g_str_equal(pref_name, "pm_sort")) { + if (g_str_equal(pref_name, "pm_sort") || g_str_equal(pref_name, "case_sensitive")) { pm_sort(value); } } diff --git a/plugins/playlist_display/icons/hicolor/16x16/places/Makefile.am b/plugins/playlist_display/icons/hicolor/16x16/places/Makefile.am index 11da52f..9737401 100644 --- a/plugins/playlist_display/icons/hicolor/16x16/places/Makefile.am +++ b/plugins/playlist_display/icons/hicolor/16x16/places/Makefile.am @@ -5,6 +5,7 @@ places_DATA = playlist_display-add-dirs.png \ playlist_display-add-files.png \ playlist_display-sync.png \ playlist_display-add-playlists.png \ - playlist_display-photo.png + playlist_display-photo.png \ + playlist_display-playlist-category.png EXTRA_DIST = $(places_DATA) diff --git a/plugins/playlist_display/icons/hicolor/16x16/places/playlist_display-playlist-category.png b/plugins/playlist_display/icons/hicolor/16x16/places/playlist_display-playlist-category.png new file mode 100644 index 0000000..968208d Binary files /dev/null and b/plugins/playlist_display/icons/hicolor/16x16/places/playlist_display-playlist-category.png differ diff --git a/plugins/playlist_display/icons/hicolor/22x22/places/Makefile.am b/plugins/playlist_display/icons/hicolor/22x22/places/Makefile.am index 20322d1..24e8679 100644 --- a/plugins/playlist_display/icons/hicolor/22x22/places/Makefile.am +++ b/plugins/playlist_display/icons/hicolor/22x22/places/Makefile.am @@ -5,6 +5,7 @@ places_DATA = playlist_display-add-dirs.png \ playlist_display-add-files.png \ playlist_display-sync.png \ playlist_display-add-playlists.png \ - playlist_display-photo.png + playlist_display-photo.png \ + playlist_display-playlist-category.png EXTRA_DIST = $(places_DATA) diff --git a/plugins/playlist_display/icons/hicolor/22x22/places/playlist_display-playlist-category.png b/plugins/playlist_display/icons/hicolor/22x22/places/playlist_display-playlist-category.png new file mode 100644 index 0000000..df73799 Binary files /dev/null and b/plugins/playlist_display/icons/hicolor/22x22/places/playlist_display-playlist-category.png differ diff --git a/plugins/playlist_display/icons/hicolor/24x24/places/Makefile.am b/plugins/playlist_display/icons/hicolor/24x24/places/Makefile.am index 4c6c8be..e95a951 100644 --- a/plugins/playlist_display/icons/hicolor/24x24/places/Makefile.am +++ b/plugins/playlist_display/icons/hicolor/24x24/places/Makefile.am @@ -5,6 +5,7 @@ places_DATA = playlist_display-add-dirs.png \ playlist_display-add-files.png \ playlist_display-sync.png \ playlist_display-add-playlists.png \ - playlist_display-photo.png + playlist_display-photo.png \ + playlist_display-playlist-category.png EXTRA_DIST = $(places_DATA) diff --git a/plugins/playlist_display/icons/hicolor/24x24/places/playlist_display-playlist-category.png b/plugins/playlist_display/icons/hicolor/24x24/places/playlist_display-playlist-category.png new file mode 100644 index 0000000..98e81c6 Binary files /dev/null and b/plugins/playlist_display/icons/hicolor/24x24/places/playlist_display-playlist-category.png differ diff --git a/plugins/playlist_display/icons/hicolor/32x32/places/Makefile.am b/plugins/playlist_display/icons/hicolor/32x32/places/Makefile.am index 8102217..5c5e376 100644 --- a/plugins/playlist_display/icons/hicolor/32x32/places/Makefile.am +++ b/plugins/playlist_display/icons/hicolor/32x32/places/Makefile.am @@ -5,6 +5,7 @@ places_DATA = playlist_display-add-dirs.png \ playlist_display-add-files.png \ playlist_display-sync.png \ playlist_display-add-playlists.png \ - playlist_display-photo.png + playlist_display-photo.png \ + playlist_display-playlist-category.png EXTRA_DIST = $(places_DATA) diff --git a/plugins/playlist_display/icons/hicolor/32x32/places/playlist_display-playlist-category.png b/plugins/playlist_display/icons/hicolor/32x32/places/playlist_display-playlist-category.png new file mode 100644 index 0000000..0cf644b Binary files /dev/null and b/plugins/playlist_display/icons/hicolor/32x32/places/playlist_display-playlist-category.png differ diff --git a/plugins/playlist_display/icons/hicolor/48x48/places/Makefile.am b/plugins/playlist_display/icons/hicolor/48x48/places/Makefile.am index 8111230..67ad6ef 100644 --- a/plugins/playlist_display/icons/hicolor/48x48/places/Makefile.am +++ b/plugins/playlist_display/icons/hicolor/48x48/places/Makefile.am @@ -5,6 +5,7 @@ places_DATA = playlist_display-add-dirs.png \ playlist_display-add-files.png \ playlist_display-sync.png \ playlist_display-add-playlists.png \ - playlist_display-photo.png + playlist_display-photo.png \ + playlist_display-playlist-category.png EXTRA_DIST = $(places_DATA) diff --git a/plugins/playlist_display/icons/hicolor/48x48/places/playlist_display-playlist-category.png b/plugins/playlist_display/icons/hicolor/48x48/places/playlist_display-playlist-category.png new file mode 100644 index 0000000..12a5d57 Binary files /dev/null and b/plugins/playlist_display/icons/hicolor/48x48/places/playlist_display-playlist-category.png differ diff --git a/plugins/playlist_display/playlist_display.glade b/plugins/playlist_display/playlist_display.glade new file mode 100644 index 0000000..0f5a727 --- /dev/null +++ b/plugins/playlist_display/playlist_display.glade @@ -0,0 +1,210 @@ +<?xml version="1.0"?> +<glade-interface> + <!-- interface-requires gtk+ 2.16 --> + <!-- interface-naming-policy project-wide --> + <widget class="GtkWindow" id="prefs_window"> + <child> + <widget class="GtkNotebook" id="playlist_settings_notebook"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <child> + <widget class="GtkVBox" id="vbox5"> + <property name="visible">True</property> + <property name="border_width">12</property> + <property name="orientation">vertical</property> + <property name="spacing">18</property> + <child> + <widget class="GtkFrame" id="frame4"> + <property name="visible">True</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <widget class="GtkAlignment" id="alignment14"> + <property name="visible">True</property> + <property name="top_padding">6</property> + <property name="left_padding">12</property> + <child> + <widget class="GtkVBox" id="vbox1"> + <property name="visible">True</property> + <property name="orientation">vertical</property> + <property name="spacing">10</property> + <child> + <widget class="GtkHBox" id="hbox30"> + <property name="visible">True</property> + <child> + <widget class="GtkTable" id="table1"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="n_rows">2</property> + <property name="n_columns">3</property> + <child> + <widget class="GtkLabel" id="label82"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes"><b>Ascending</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label85"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes"><b>Descending</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="left_attach">2</property> + <property name="right_attach">3</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkRadioButton" id="pm_ascend"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + <property name="group">pm_none</property> + <signal name="toggled" handler="on_pm_ascend_toggled"/> + <child> + <widget class="GtkImage" id="image1928"> + <property name="visible">True</property> + <property name="stock">gtk-sort-ascending</property> + </widget> + </child> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options"></property> + </packing> + </child> + <child> + <widget class="GtkRadioButton" id="pm_descend"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="draw_indicator">True</property> + <property name="group">pm_none</property> + <signal name="toggled" handler="on_pm_descend_toggled"/> + <child> + <widget class="GtkImage" id="image1929"> + <property name="visible">True</property> + <property name="stock">gtk-sort-descending</property> + </widget> + </child> + </widget> + <packing> + <property name="left_attach">2</property> + <property name="right_attach">3</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options"></property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label86"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes"><b>None</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkRadioButton" id="pm_none"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="on_pm_none_toggled"/> + <child> + <widget class="GtkImage" id="image1930"> + <property name="visible">True</property> + <property name="stock">gtk-undo</property> + </widget> + </child> + </widget> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options"></property> + </packing> + </child> + </widget> + <packing> + <property name="position">0</property> + </packing> + </child> + </widget> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkCheckButton" id="pm_cfg_case_sensitive"> + <property name="label" translatable="yes">Case sensitive sorting</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="has_tooltip">True</property> + <property name="tooltip" translatable="yes">If checked, sorting will be case sensitive. Please note that case sensitive sorting will not work well with most charsets.</property> + <property name="use_underline">True</property> + <property name="draw_indicator">True</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkLabel" id="label7"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Playlist Sort Order</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="type">label_item</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </widget> + </child> + <child> + <widget class="GtkLabel" id="display_page_label"> + <property name="visible">True</property> + <property name="label" translatable="yes">Playlist Display</property> + </widget> + <packing> + <property name="tab_fill">False</property> + <property name="type">tab</property> + </packing> + </child> + </widget> + </child> + </widget> +</glade-interface> diff --git a/plugins/playlist_display/playlist_display_preferences.c b/plugins/playlist_display/playlist_display_preferences.c new file mode 100644 index 0000000..efe482a --- /dev/null +++ b/plugins/playlist_display/playlist_display_preferences.c @@ -0,0 +1,98 @@ +/* + | Copyright (C) 2002-2010 Jorg Schuler <jcsjcs at users sourceforge net> + | Paul Richardson <phantom_sf at users.sourceforge.net> + | Part of the gtkpod project. + | + | URL: http://www.gtkpod.org/ + | URL: http://gtkpod.sourceforge.net/ + | + | This program is free software; you can redistribute it and/or modify + | it under the terms of the GNU General Public License as published by + | the Free Software Foundation; either version 2 of the License, or + | (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, write to the Free Software + | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + | + | iTunes and iPod are trademarks of Apple + | + | This product is not supported/written/published by Apple! + | + */ + +#include <gtk/gtk.h> +#include <glade/glade.h> +#include "libgtkpod/prefs.h" +#include "libgtkpod/misc.h" +#include "libgtkpod/directories.h" +#include "libgtkpod/gp_private.h" +#include "libgtkpod/gtkpod_app_iface.h" +#include "plugin.h" + +static GtkWidget *notebook = NULL; + +static void set_pm_sort(gint val) { + prefs_set_int("pm_sort", val); + gtkpod_broadcast_preference_change("pm_sort", val); +} + +G_MODULE_EXPORT void on_pm_ascend_toggled(GtkToggleButton *togglebutton, gpointer user_data) { + if (gtk_toggle_button_get_active(togglebutton)) + set_pm_sort(SORT_ASCENDING); +} + +G_MODULE_EXPORT void on_pm_descend_toggled(GtkToggleButton *togglebutton, gpointer user_data) { + if (gtk_toggle_button_get_active(togglebutton)) + set_pm_sort(SORT_DESCENDING); +} + +G_MODULE_EXPORT void on_pm_none_toggled(GtkToggleButton *togglebutton, gpointer user_data) { + if (gtk_toggle_button_get_active(togglebutton)) + set_pm_sort(SORT_NONE); +} + +G_MODULE_EXPORT void on_sort_case_sensitive_toggled(GtkToggleButton *togglebutton, gpointer user_data) { + gboolean val = gtk_toggle_button_get_active(togglebutton); + prefs_set_int("case_sensitive", val); + gtkpod_broadcast_preference_change("case_sensitive", val); +} + +GtkWidget *init_playlist_display_preferences() { + GladeXML *pref_xml; + GtkWidget *w = NULL; + + gchar *glade_path = g_build_filename(get_glade_dir(), "playlist_display.glade", NULL); + pref_xml = gtkpod_xml_new(glade_path, "playlist_settings_notebook"); + notebook = gtkpod_xml_get_widget(pref_xml, "playlist_settings_notebook"); + g_object_ref(notebook); + g_free(glade_path); + + switch (prefs_get_int("pm_sort")) { + case SORT_ASCENDING: + w = gtkpod_xml_get_widget(pref_xml, "pm_ascend"); + break; + case SORT_DESCENDING: + w = gtkpod_xml_get_widget(pref_xml, "pm_descend"); + break; + case SORT_NONE: + w = gtkpod_xml_get_widget(pref_xml, "pm_none"); + break; + } + + if (w) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), TRUE); + + if ((w = gtkpod_xml_get_widget(pref_xml, "pm_cfg_case_sensitive"))) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), prefs_get_int("case_sensitive")); + } + + glade_xml_signal_autoconnect(pref_xml); + + return notebook; +} diff --git a/plugins/playlist_display/playlist_display_preferences.h b/plugins/playlist_display/playlist_display_preferences.h new file mode 100644 index 0000000..a90bf7f --- /dev/null +++ b/plugins/playlist_display/playlist_display_preferences.h @@ -0,0 +1,34 @@ +/* + | Copyright (C) 2002-2010 Jorg Schuler <jcsjcs at users sourceforge net> + | Paul Richardson <phantom_sf at users.sourceforge.net> + | Part of the gtkpod project. + | + | URL: http://www.gtkpod.org/ + | URL: http://gtkpod.sourceforge.net/ + | + | This program is free software; you can redistribute it and/or modify + | it under the terms of the GNU General Public License as published by + | the Free Software Foundation; either version 2 of the License, or + | (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, write to the Free Software + | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + | + | iTunes and iPod are trademarks of Apple + | + | This product is not supported/written/published by Apple! + | + */ + +#ifndef PLAYLIST_DISPLAY_PREFERENCES_H_ +#define PLAYLIST_DISPLAY_PREFERENCES_H_ + +GtkWidget *init_playlist_display_preferences(); + +#endif /* PLAYLIST_DISPLAY_PREFERENCES_H_ */ diff --git a/plugins/playlist_display/plugin.c b/plugins/playlist_display/plugin.c index b10188d..f64045d 100644 --- a/plugins/playlist_display/plugin.c +++ b/plugins/playlist_display/plugin.c @@ -31,6 +31,7 @@ #endif #include <glib.h> +#include <libanjuta/interfaces/ianjuta-preferences.h> #include "libgtkpod/stock_icons.h" #include "libgtkpod/directories.h" #include "libgtkpod/misc_playlist.h" @@ -42,6 +43,11 @@ #include "plugin.h" #include "display_playlists.h" #include "playlist_display_actions.h" +#include "playlist_display_preferences.h" + +#define PREFERENCE_ICON "playlist_display-playlist-category" +#define PREFERENCE_ICON_STOCK_ID "playlist_display-preference-icon" +#define TAB_NAME "Playlist Display" /* Parent class. Part of standard class definition */ static gpointer parent_class; @@ -294,11 +300,13 @@ static gboolean activate_plugin(AnjutaPlugin *plugin) { GtkAction *new_playlist_action; /* preferences */ - if (prefs_get_int_value("pm_sort", NULL)) + if (! prefs_get_int_value("pm_sort", NULL)) prefs_set_int("pm_sort", SORT_NONE); /* Prepare the icons for the playlist */ register_icon_path(get_plugin_dir(), "playlist_display"); + register_stock_icon(PREFERENCE_ICON, PREFERENCE_ICON_STOCK_ID); + register_stock_icon("playlist_display-photo", PLAYLIST_DISPLAY_PHOTO_ICON_STOCK_ID); register_stock_icon("playlist_display-playlist", PLAYLIST_DISPLAY_PLAYLIST_ICON_STOCK_ID); register_stock_icon("playlist_display-read", PLAYLIST_DISPLAY_READ_ICON_STOCK_ID); @@ -401,7 +409,39 @@ static void playlist_display_plugin_class_init(GObjectClass *klass) { plugin_class->deactivate = deactivate_plugin; } +static void ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e) { + GdkPixbuf *pixbuf; + GError *error = NULL; + + PlaylistDisplayPlugin* plugin = PLAYLIST_DISPLAY_PLUGIN(ipref); + plugin->prefs = init_playlist_display_preferences(); + if (plugin->prefs == NULL) + return; + + pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), PREFERENCE_ICON, 48, 0, &error); + + if (!pixbuf) { + g_warning ("Couldn't load icon: %s", error->message); + g_error_free(error); + } + + anjuta_preferences_dialog_add_page(ANJUTA_PREFERENCES_DIALOG (anjuta_preferences_get_dialog (prefs)), "gtkpod-track-display-settings", _(TAB_NAME), pixbuf, plugin->prefs); + g_object_unref(pixbuf); +} + +static void ipreferences_unmerge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e) { + anjuta_preferences_remove_page(prefs, _(TAB_NAME)); + PlaylistDisplayPlugin* plugin = PLAYLIST_DISPLAY_PLUGIN(ipref); + gtk_widget_destroy(plugin->prefs); +} + +static void ipreferences_iface_init(IAnjutaPreferencesIface* iface) { + iface->merge = ipreferences_merge; + iface->unmerge = ipreferences_unmerge; +} + ANJUTA_PLUGIN_BEGIN (PlaylistDisplayPlugin, playlist_display_plugin); +ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences, IANJUTA_TYPE_PREFERENCES); ANJUTA_PLUGIN_END; ANJUTA_SIMPLE_PLUGIN (PlaylistDisplayPlugin, playlist_display_plugin); diff --git a/plugins/playlist_display/plugin.h b/plugins/playlist_display/plugin.h index a0ae212..62ea4a1 100644 --- a/plugins/playlist_display/plugin.h +++ b/plugins/playlist_display/plugin.h @@ -53,6 +53,14 @@ #define ACTION_NEW_PLAYLIST "ActionNewPlaylist" #define ACTION_NEW_PLAYLIST_MENU "ActionNewPlaylistMenu" +extern GType playlist_display_plugin_get_type (GTypeModule *module); +#define PLAYLIST_DISPLAY_TYPE_PLUGIN (playlist_display_plugin_get_type (NULL)) +#define PLAYLIST_DISPLAY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PLAYLIST_DISPLAY_TYPE_PLUGIN, PlaylistDisplayPlugin)) +#define PLAYLIST_DISPLAY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), PLAYLIST_DISPLAY_TYPE_PLUGIN, PlaylistDisplayPluginClass)) +#define PLAYLIST_DISPLAY_IS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PLAYLIST_DISPLAY_TYPE_PLUGIN)) +#define PLAYLIST_DISPLAY_IS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PLAYLIST_DISPLAY_TYPE_PLUGIN)) +#define PLAYLIST_DISPLAY_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PLAYLIST_DISPLAY_TYPE_PLUGIN, PlaylistDisplayPluginClass)) + typedef struct _PlaylistDisplayPlugin PlaylistDisplayPlugin; typedef struct _PlaylistDisplayPluginClass PlaylistDisplayPluginClass; @@ -62,6 +70,7 @@ struct _PlaylistDisplayPlugin { GtkWidget *playlist_view; gint uiid; GtkActionGroup *action_group; + GtkWidget *prefs; }; struct _PlaylistDisplayPluginClass { ------------------------------------------------------------------------------ Download new Adobe(R) Flash(R) Builder(TM) 4 The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly Flex(R) Builder(TM)) enable the development of rich applications that run across multiple browsers and platforms. Download your free trials today! http://p.sf.net/sfu/adobe-dev2dev _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2