annotate src/audacious/ui_playlist_widget.c @ 4793:7f318fa97ea3

Only gtk.h should be included, as per -DGTK_DISABLE_SINGLE_INCLUDES (GTK+ 3 compatibility project).
author Tony Vroon <chainsaw@gentoo.org>
date Sat, 04 Oct 2008 23:41:34 +0100
parents 4d15507f568c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4728
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1 /* Audacious - Cross-platform multimedia player
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
2 * Copyright (C) 2008 Tomasz Moń <desowin@gmail.com>
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
3 *
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; under version 3 of the License.
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
7 *
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
12 *
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
14 * along with this program. If not, see <http://www.gnu.org/licenses>.
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
15 *
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
16 * The Audacious team does not consider modular code linking to
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
17 * Audacious or using our public API to be a derived work.
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
18 */
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
19
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
20 #include <gtk/gtk.h>
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
21 #include <gdk/gdkkeysyms.h>
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
22 #include "playlist.h"
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
23 #include "playback.h"
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
24 #include "strings.h"
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
25
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
26 enum {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
27 COLUMN_NUM = 0,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
28 COLUMN_TEXT,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
29 COLUMN_TIME,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
30 COLUMN_WEIGHT,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
31 N_COLUMNS
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
32 };
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
33
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
34 static void
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
35 ui_playlist_widget_change_song(guint pos)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
36 {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
37 playlist_set_position(playlist_get_active(), pos);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
38
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
39 if (!playback_get_playing())
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
40 playback_initiate();
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
41 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
42
4736
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
43 static void
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
44 ui_playlist_widget_set_title_active(GtkTreeModel *model, gint pos,
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
45 gboolean active)
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
46 {
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
47 GtkTreeIter iter;
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
48 GtkTreePath *path;
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
49 gchar *path_str;
4739
4d15507f568c remove reduntant call
Tomasz Mon <desowin@gmail.com>
parents: 4736
diff changeset
50
4736
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
51 path_str = g_strdup_printf("%d", pos);
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
52 path = gtk_tree_path_new_from_string(path_str);
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
53 gtk_tree_model_get_iter(model, &iter, path);
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
54
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
55 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
56 3, active ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL, -1);
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
57
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
58 g_free(path_str);
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
59 gtk_tree_path_free(path);
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
60 }
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
61
4728
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
62 void
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
63 ui_playlist_widget_set_current(GtkWidget *treeview, gint pos)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
64 {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
65 GtkTreeModel *model;
4736
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
66 gint old_pos;
4739
4d15507f568c remove reduntant call
Tomasz Mon <desowin@gmail.com>
parents: 4736
diff changeset
67
4728
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
68 model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
4736
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
69 old_pos = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(treeview), "current"));
4728
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
70
4736
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
71 if (old_pos != -1)
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
72 ui_playlist_widget_set_title_active(model, old_pos, FALSE);
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
73 if (pos != -1)
e14398ef0868 remove some code duplication
mf0102 <0102@gmx.at>
parents: 4735
diff changeset
74 ui_playlist_widget_set_title_active(model, pos, TRUE);
4728
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
75
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
76 g_object_set_data(G_OBJECT(treeview), "current", GINT_TO_POINTER(pos));
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
77 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
78
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
79 static void
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
80 ui_playlist_widget_jump(GtkTreeView * treeview, gpointer data)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
81 {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
82 GtkTreeModel *model;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
83 GtkTreeSelection *selection;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
84 GtkTreeIter iter;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
85 guint pos;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
86
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
87 model = gtk_tree_view_get_model(treeview);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
88 selection = gtk_tree_view_get_selection(treeview);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
89
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
90 if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
91 return;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
92
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
93 gtk_tree_model_get(model, &iter, 0, &pos, -1);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
94
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
95 ui_playlist_widget_change_song(pos - 1);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
96 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
97
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
98 static gboolean
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
99 ui_playlist_widget_keypress_cb(GtkWidget * widget,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
100 GdkEventKey * event,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
101 gpointer data)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
102 {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
103 switch (event->keyval) {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
104 case GDK_KP_Enter:
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
105 ui_playlist_widget_jump(GTK_TREE_VIEW(widget), NULL);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
106 return TRUE;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
107 default:
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
108 return FALSE;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
109 };
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
110 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
111
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
112 void
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
113 ui_playlist_widget_update(GtkWidget *widget)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
114 {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
115 guint row;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
116 gboolean valid;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
117
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
118 GList *playlist_glist;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
119 gchar *desc_buf = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
120 gchar *length = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
121 GtkTreeIter iter;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
122 Playlist *playlist;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
123 GtkTreeModel *store;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
124 GtkTreeView *tree = GTK_TREE_VIEW(widget);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
125
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
126 store = gtk_tree_view_get_model(tree);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
127 valid = gtk_tree_model_get_iter_first(store, &iter);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
128
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
129 row = 1;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
130 playlist = playlist_get_active();
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
131
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
132 for (playlist_glist = playlist->entries; playlist_glist;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
133 playlist_glist = g_list_next(playlist_glist)) {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
134 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist_glist->data);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
135
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
136 if (entry->title)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
137 desc_buf = g_strdup(entry->title);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
138 else {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
139 gchar *realfn = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
140 realfn = g_filename_from_uri(entry->filename, NULL, NULL);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
141 if (strchr(realfn ? realfn : entry->filename, '/'))
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
142 desc_buf = str_assert_utf8(strrchr(realfn ? realfn : entry->filename, '/') + 1);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
143 else
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
144 desc_buf = str_assert_utf8(realfn ? realfn : entry->filename);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
145 g_free(realfn); realfn = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
146 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
147
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
148 if (entry->length != -1) {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
149 length = g_strdup_printf("%d:%-2.2d", entry->length / 60000, (entry->length / 1000) % 60);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
150 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
151
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
152 if (!valid)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
153 gtk_list_store_append(GTK_LIST_STORE(store), &iter);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
154 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
155 COLUMN_NUM, row, COLUMN_TEXT, desc_buf,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
156 COLUMN_TIME, length,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
157 COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, -1);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
158 row++;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
159
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
160 g_free(desc_buf);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
161 desc_buf = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
162
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
163 if (length) g_free(length);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
164 length = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
165
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
166 valid = gtk_tree_model_iter_next(store, &iter);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
167 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
168
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
169 /* remove additional rows */
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
170 while (valid) {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
171 valid = gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
172 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
173
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
174 ui_playlist_widget_set_current(widget, playlist_get_position(playlist));
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
175 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
176
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
177 static gboolean
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
178 ui_playlist_widget_fill(gpointer treeview)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
179 {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
180 GList *playlist_glist;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
181 Playlist *playlist;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
182 gchar *desc_buf = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
183 gchar *length = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
184 guint row;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
185 GtkTreeIter iter;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
186 GtkListStore *store = (GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(treeview) );
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
187
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
188 /* detach model from treeview before fill */
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
189 g_object_ref(store);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
190 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL );
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
191
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
192 gtk_list_store_clear(store);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
193
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
194 row = 1;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
195 playlist = playlist_get_active();
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
196
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
197 PLAYLIST_LOCK(playlist);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
198 for (playlist_glist = playlist->entries; playlist_glist;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
199 playlist_glist = g_list_next(playlist_glist)) {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
200
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
201 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist_glist->data);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
202
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
203 if (entry->title)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
204 desc_buf = g_strdup(entry->title);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
205 else {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
206 gchar *realfn = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
207 realfn = g_filename_from_uri(entry->filename, NULL, NULL);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
208 if (strchr(realfn ? realfn : entry->filename, '/'))
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
209 desc_buf = str_assert_utf8(strrchr(realfn ? realfn : entry->filename, '/') + 1);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
210 else
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
211 desc_buf = str_assert_utf8(realfn ? realfn : entry->filename);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
212 g_free(realfn); realfn = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
213 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
214
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
215 if (entry->length != -1) {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
216 length = g_strdup_printf("%d:%-2.2d", entry->length / 60000, (entry->length / 1000) % 60);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
217 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
218
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
219 gtk_list_store_append(GTK_LIST_STORE(store), &iter);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
220 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
221 COLUMN_NUM, row, COLUMN_TEXT, desc_buf,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
222 COLUMN_TIME, length,
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
223 COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, -1);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
224 row++;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
225
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
226 g_free(desc_buf);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
227 desc_buf = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
228
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
229 if (length) g_free(length);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
230 length = NULL;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
231 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
232 PLAYLIST_UNLOCK(playlist);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
233
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
234 /* attach liststore to treeview */
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
235 gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
236 g_object_unref(store);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
237
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
238 return FALSE;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
239 }
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
240
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
241 GtkWidget *
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
242 ui_playlist_widget_new(void)
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
243 {
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
244 GtkWidget *treeview;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
245 GtkListStore *store;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
246 GtkCellRenderer *renderer;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
247 GtkTreeViewColumn *column;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
248
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
249 store = gtk_list_store_new(N_COLUMNS, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, PANGO_TYPE_WEIGHT);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
250 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
251 g_object_unref(store);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
252
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
253 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
254
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
255 column = gtk_tree_view_column_new();
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
256 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
257 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
258 gtk_tree_view_column_set_spacing(column, 4);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
259
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
260 renderer = gtk_cell_renderer_text_new();
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
261 gtk_tree_view_column_pack_start(column, renderer, FALSE);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
262 gtk_tree_view_column_set_attributes(column, renderer, "text", COLUMN_NUM, NULL);
4729
5e70c200eb8d Use GtkCellRenderer::ypad to provide a more compact playlist, similar to the list widgets in Conspire.
William Pitcock <nenolod@atheme.org>
parents: 4728
diff changeset
263 g_object_set(G_OBJECT(renderer), "ypad", 0, NULL);
4728
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
264
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
265 renderer = gtk_cell_renderer_text_new();
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
266 gtk_tree_view_column_pack_start(column, renderer, TRUE);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
267 gtk_tree_view_column_set_attributes(column, renderer, "text", COLUMN_TEXT, "weight", COLUMN_WEIGHT, NULL);
4735
cc107c7ec07f set ellipsize to PANGO_ELLIPSIZE_END in title column
Tomasz Mon <desowin@gmail.com>
parents: 4729
diff changeset
268 g_object_set(G_OBJECT(renderer), "ypad", 0, "ellipsize-set", TRUE,
cc107c7ec07f set ellipsize to PANGO_ELLIPSIZE_END in title column
Tomasz Mon <desowin@gmail.com>
parents: 4729
diff changeset
269 "ellipsize", PANGO_ELLIPSIZE_END, NULL);
4728
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
270
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
271 renderer = gtk_cell_renderer_text_new();
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
272 gtk_tree_view_column_pack_start(column, renderer, FALSE);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
273 gtk_tree_view_column_set_attributes(column, renderer, "text", COLUMN_TIME, NULL);
4729
5e70c200eb8d Use GtkCellRenderer::ypad to provide a more compact playlist, similar to the list widgets in Conspire.
William Pitcock <nenolod@atheme.org>
parents: 4728
diff changeset
274 g_object_set(G_OBJECT(renderer), "ypad", 0, NULL);
4728
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
275
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
276 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
277
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
278 g_signal_connect(treeview, "row-activated",
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
279 G_CALLBACK(ui_playlist_widget_jump), NULL);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
280
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
281 g_signal_connect(treeview, "key-press-event",
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
282 G_CALLBACK(ui_playlist_widget_keypress_cb), NULL);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
283
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
284 ui_playlist_widget_fill(treeview);
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
285
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
286 g_object_set_data(G_OBJECT(treeview), "current", GINT_TO_POINTER(-1));
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
287
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
288 return treeview;
ab79ddbdcf42 introduce new playlist widget
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
289 }