17 |
17 |
* the use of this software.
|
18 |
18 |
*/
|
19 |
19 |
|
20 |
|
#include "config.h"
|
|
20 |
#include <stdlib.h>
|
21 |
21 |
|
22 |
22 |
#include <gdk/gdkkeysyms.h>
|
23 |
23 |
#include <gtk/gtk.h>
|
... | ... | |
27 |
27 |
#include <audacious/misc.h>
|
28 |
28 |
#include <audacious/playlist.h>
|
29 |
29 |
#include <audacious/plugin.h>
|
|
30 |
#include <libaudcore/hook.h>
|
30 |
31 |
#include <libaudgui/list.h>
|
31 |
32 |
#include <libaudgui/libaudgui.h>
|
32 |
33 |
|
|
34 |
#include "config.h"
|
33 |
35 |
#include "gtkui.h"
|
34 |
36 |
#include "ui_playlist_notebook.h"
|
35 |
37 |
#include "ui_playlist_widget.h"
|
... | ... | |
37 |
39 |
|
38 |
40 |
static GtkWidget * notebook = NULL;
|
39 |
41 |
static gint highlighted = -1;
|
|
42 |
static gint last_active = -1;
|
40 |
43 |
|
41 |
44 |
static gint switch_handler = 0;
|
42 |
45 |
static gint reorder_handler = 0;
|
... | ... | |
123 |
126 |
return GTK_NOTEBOOK(notebook);
|
124 |
127 |
}
|
125 |
128 |
|
|
129 |
static void save_column_widths (void)
|
|
130 |
{
|
|
131 |
GtkWidget * treeview = playlist_get_treeview (last_active);
|
|
132 |
char * widths = ui_playlist_widget_get_column_widths (treeview);
|
|
133 |
|
|
134 |
printf ("save: %s\n", widths);
|
|
135 |
aud_set_string ("gtkui", "column_widths", widths);
|
|
136 |
|
|
137 |
free (widths);
|
|
138 |
}
|
|
139 |
|
|
140 |
static void apply_column_widths (GtkWidget * treeview)
|
|
141 |
{
|
|
142 |
char * widths = aud_get_string ("gtkui", "column_widths");
|
|
143 |
|
|
144 |
if (widths && widths[0])
|
|
145 |
{
|
|
146 |
printf ("apply: %s\n", widths);
|
|
147 |
ui_playlist_widget_set_column_widths (treeview, widths);
|
|
148 |
}
|
|
149 |
|
|
150 |
free (widths);
|
|
151 |
}
|
|
152 |
|
126 |
153 |
static void tab_title_reset(GtkWidget *ebox)
|
127 |
154 |
{
|
128 |
155 |
GtkWidget *label = g_object_get_data(G_OBJECT(ebox), "label");
|
... | ... | |
166 |
193 |
return FALSE;
|
167 |
194 |
}
|
168 |
195 |
|
169 |
|
static void tab_changed (GtkNotebook * notebook, GtkWidget * page, gint
|
170 |
|
page_num, void * unused)
|
|
196 |
static void tab_changed (GtkNotebook * notebook, GtkWidget * page, int page_num)
|
171 |
197 |
{
|
172 |
|
GtkWidget * treeview = playlist_get_treeview (page_num);
|
|
198 |
printf ("tab changed, last active = %d\n", last_active);
|
173 |
199 |
|
174 |
|
if (treeview != NULL)
|
175 |
|
aud_playlist_set_active (page_num);
|
|
200 |
save_column_widths ();
|
|
201 |
apply_column_widths (playlist_get_treeview (page_num));
|
|
202 |
|
|
203 |
last_active = page_num;
|
|
204 |
aud_playlist_set_active (page_num);
|
176 |
205 |
}
|
177 |
206 |
|
178 |
207 |
static void tab_reordered(GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer user_data)
|
... | ... | |
222 |
251 |
gtk_widget_show(entry);
|
223 |
252 |
}
|
224 |
253 |
|
225 |
|
void ui_playlist_notebook_create_tab(gint playlist)
|
|
254 |
static void ui_playlist_notebook_create_tab (int playlist)
|
226 |
255 |
{
|
227 |
256 |
GtkWidget *scrollwin, *treeview;
|
228 |
257 |
GtkWidget *label, *entry, *ebox, *hbox;
|
... | ... | |
233 |
262 |
vscroll = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrollwin));
|
234 |
263 |
|
235 |
264 |
treeview = ui_playlist_widget_new(playlist);
|
236 |
|
g_object_set_data(G_OBJECT(scrollwin), "treeview", treeview);
|
|
265 |
apply_column_widths (treeview);
|
237 |
266 |
|
|
267 |
g_object_set_data(G_OBJECT(scrollwin), "treeview", treeview);
|
238 |
268 |
gtk_container_add(GTK_CONTAINER(scrollwin), treeview);
|
239 |
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
269 |
gtk_scrolled_window_set_policy ((GtkScrolledWindow *) scrollwin,
|
|
270 |
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
240 |
271 |
gtk_widget_show_all(scrollwin);
|
241 |
272 |
|
242 |
273 |
ebox = gtk_event_box_new();
|
... | ... | |
283 |
314 |
G_CALLBACK(ui_playlist_widget_scroll), treeview);
|
284 |
315 |
}
|
285 |
316 |
|
286 |
|
void ui_playlist_notebook_populate(void)
|
|
317 |
void ui_playlist_notebook_populate (void)
|
287 |
318 |
{
|
288 |
|
gint playlists = aud_playlist_count();
|
289 |
|
gint count;
|
|
319 |
last_active = aud_playlist_get_active ();
|
|
320 |
highlighted = aud_playlist_get_unique_id (aud_playlist_get_playing ());
|
290 |
321 |
|
291 |
|
for (count = 0; count < playlists; count++)
|
292 |
|
ui_playlist_notebook_create_tab(count);
|
|
322 |
int n_lists = aud_playlist_count ();
|
|
323 |
for (int i = 0; i < n_lists; i ++)
|
|
324 |
ui_playlist_notebook_create_tab (i);
|
293 |
325 |
|
294 |
|
gtk_notebook_set_current_page (UI_PLAYLIST_NOTEBOOK, aud_playlist_get_active ());
|
295 |
|
highlighted = aud_playlist_get_unique_id (aud_playlist_get_playing ());
|
|
326 |
gtk_notebook_set_current_page ((GtkNotebook *) notebook, last_active);
|
|
327 |
gtk_widget_grab_focus (playlist_get_treeview (last_active));
|
296 |
328 |
|
297 |
329 |
if (! switch_handler)
|
298 |
330 |
switch_handler = g_signal_connect (notebook, "switch-page", (GCallback)
|
... | ... | |
300 |
332 |
if (! reorder_handler)
|
301 |
333 |
reorder_handler = g_signal_connect (notebook, "page-reordered",
|
302 |
334 |
(GCallback) tab_reordered, NULL);
|
303 |
|
|
304 |
|
gtk_widget_grab_focus (playlist_get_treeview (aud_playlist_get_active ()));
|
305 |
335 |
}
|
306 |
336 |
|
307 |
337 |
void ui_playlist_notebook_empty (void)
|
308 |
338 |
{
|
|
339 |
last_active = -1;
|
|
340 |
highlighted = -1;
|
|
341 |
|
309 |
342 |
if (switch_handler)
|
310 |
343 |
g_signal_handler_disconnect (notebook, switch_handler);
|
311 |
344 |
switch_handler = 0;
|
... | ... | |
323 |
356 |
gint lists = aud_playlist_count ();
|
324 |
357 |
gint pages = gtk_notebook_get_n_pages ((GtkNotebook *) notebook);
|
325 |
358 |
|
|
359 |
printf ("add-remove, last active = %d\n", last_active);
|
|
360 |
save_column_widths ();
|
|
361 |
|
326 |
362 |
/* scan through existing treeviews */
|
327 |
363 |
for (gint i = 0; i < pages; )
|
328 |
364 |
{
|
... | ... | |
385 |
421 |
ui_playlist_notebook_create_tab (pages);
|
386 |
422 |
pages ++;
|
387 |
423 |
}
|
|
424 |
|
|
425 |
last_active = aud_playlist_get_active ();
|
|
426 |
gtk_notebook_set_current_page ((GtkNotebook *) notebook, last_active);
|
|
427 |
apply_column_widths ();
|
388 |
428 |
}
|
389 |
429 |
|
390 |
430 |
void ui_playlist_notebook_update (void * data, void * user)
|
... | ... | |
433 |
473 |
|
434 |
474 |
void ui_playlist_notebook_activate (void * data, void * user)
|
435 |
475 |
{
|
436 |
|
if (! aud_playlist_update_pending ())
|
437 |
|
gtk_notebook_set_current_page ((GtkNotebook *) notebook, aud_playlist_get_active ());
|
|
476 |
if (aud_playlist_update_pending ())
|
|
477 |
return;
|
|
478 |
|
|
479 |
int active = aud_playlist_get_active ();
|
|
480 |
if (active != last_active)
|
|
481 |
gtk_notebook_set_current_page ((GtkNotebook *) notebook, active);
|
438 |
482 |
}
|
439 |
483 |
|
440 |
484 |
void ui_playlist_notebook_set_playing (void * data, void * user)
|
... | ... | |
461 |
505 |
|
462 |
506 |
static void destroy_cb (void)
|
463 |
507 |
{
|
|
508 |
hook_dissociate ("config save", (HookFunction) save_column_widths);
|
|
509 |
|
464 |
510 |
notebook = NULL;
|
|
511 |
highlighted = -1;
|
|
512 |
last_active = -1;
|
465 |
513 |
switch_handler = 0;
|
466 |
514 |
reorder_handler = 0;
|
467 |
515 |
}
|
... | ... | |
472 |
520 |
gtk_notebook_set_scrollable ((GtkNotebook *) notebook, TRUE);
|
473 |
521 |
make_add_button (notebook);
|
474 |
522 |
|
|
523 |
hook_associate ("config save", (HookFunction) save_column_widths, NULL);
|
|
524 |
|
475 |
525 |
g_signal_connect (notebook, "destroy", (GCallback) destroy_cb, NULL);
|
476 |
526 |
return notebook;
|
477 |
527 |
}
|