Project

General

Profile

gtkui-save-column-widths.diff

John Lindgren, January 14, 2013 02:59

View differences:

src/gtkui/columns.c
212 212
            pw_cols[pw_num_cols] = ((Column *) index_get (chosen, pw_num_cols))
213 213
             ->column;
214 214

  
215
        aud_set_string ("gtkui", "column_widths", "");
216
        aud_set_string ("gtkui", "column_expand", "");
217

  
215 218
        ui_playlist_notebook_populate ();
216 219
    }
217 220

  
src/gtkui/ui_playlist_notebook.c
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"
......
123 125
    return GTK_NOTEBOOK(notebook);
124 126
}
125 127

  
128
static void save_column_widths ()
129
{
130
    int current = gtk_notebook_get_current_page ((GtkNotebook *) notebook);
131
    GtkWidget * treeview = playlist_get_treeview (current);
132

  
133
    char * widths, * expand;
134
    ui_playlist_widget_get_column_widths (treeview, & widths, & expand);
135

  
136
    aud_set_string ("gtkui", "column_widths", widths);
137
    aud_set_string ("gtkui", "column_expand", expand);
138

  
139
    free (widths);
140
    free (expand);
141
}
142

  
143
static void apply_column_widths (GtkWidget * treeview)
144
{
145
    char * widths = aud_get_string ("gtkui", "column_widths");
146
    char * expand = aud_get_string ("gtkui", "column_expand");
147

  
148
    if (widths && widths[0] && expand && expand[0])
149
        ui_playlist_widget_set_column_widths (treeview, widths, expand);
150

  
151
    free (widths);
152
    free (expand);
153
}
154

  
126 155
static void tab_title_reset(GtkWidget *ebox)
127 156
{
128 157
    GtkWidget *label = g_object_get_data(G_OBJECT(ebox), "label");
......
169 198
static void tab_changed (GtkNotebook * notebook, GtkWidget * page, gint
170 199
 page_num, void * unused)
171 200
{
172
    GtkWidget * treeview = playlist_get_treeview (page_num);
201
    save_column_widths ();
202
    apply_column_widths (playlist_get_treeview (page_num));
173 203

  
174
    if (treeview != NULL)
175
        aud_playlist_set_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)
......
233 262
    vscroll = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrollwin));
234 263

  
235 264
    treeview = ui_playlist_widget_new(playlist);
265
    apply_column_widths (treeview);
266

  
236 267
    g_object_set_data(G_OBJECT(scrollwin), "treeview", treeview);
237 268

  
238 269
    gtk_container_add(GTK_CONTAINER(scrollwin), treeview);
......
320 351

  
321 352
static void add_remove_pages (void)
322 353
{
354
    g_signal_handlers_block_by_func (notebook, (void *) tab_changed, NULL);
355
    g_signal_handlers_block_by_func (notebook, (void *) tab_reordered, NULL);
356

  
357
    save_column_widths ();
358

  
323 359
    gint lists = aud_playlist_count ();
324 360
    gint pages = gtk_notebook_get_n_pages ((GtkNotebook *) notebook);
325 361

  
......
333 369
        /* do we have an orphaned treeview? */
334 370
        if (aud_playlist_by_unique_id (tree_id) < 0)
335 371
        {
336
            g_signal_handlers_block_by_func (notebook, (void *) tab_changed, NULL);
337 372
            gtk_notebook_remove_page ((GtkNotebook *) notebook, i);
338
            g_signal_handlers_unblock_by_func (notebook, (void *) tab_changed, NULL);
339 373
            pages --;
340 374
            continue;
341 375
        }
......
362 396
            /* found it? move it to the right place */
363 397
            if (tree_id == list_id)
364 398
            {
365
                g_signal_handlers_block_by_func (notebook, (void *) tab_reordered, NULL);
366 399
                gtk_notebook_reorder_child ((GtkNotebook *) notebook, page, i);
367
                g_signal_handlers_unblock_by_func (notebook, (void *) tab_reordered, NULL);
368 400
                found = TRUE;
369 401
                break;
370 402
            }
......
385 417
        ui_playlist_notebook_create_tab (pages);
386 418
        pages ++;
387 419
    }
420

  
421
    int active = aud_playlist_get_active ();
422
    apply_column_widths (playlist_get_treeview (active));
423
    gtk_notebook_set_current_page ((GtkNotebook *) notebook, active);
424

  
425
    g_signal_handlers_unblock_by_func (notebook, (void *) tab_changed, NULL);
426
    g_signal_handlers_unblock_by_func (notebook, (void *) tab_reordered, NULL);
388 427
}
389 428

  
390 429
void ui_playlist_notebook_update (void * data, void * user)
......
461 500

  
462 501
static void destroy_cb (void)
463 502
{
503
    hook_dissociate ("config save", (HookFunction) save_column_widths);
504

  
464 505
    notebook = NULL;
465 506
    switch_handler = 0;
466 507
    reorder_handler = 0;
......
472 513
    gtk_notebook_set_scrollable ((GtkNotebook *) notebook, TRUE);
473 514
    make_add_button (notebook);
474 515

  
516
    hook_associate ("config save", (HookFunction) save_column_widths, NULL);
517

  
475 518
    g_signal_connect (notebook, "destroy", (GCallback) destroy_cb, NULL);
476 519
    return notebook;
477 520
}
src/gtkui/ui_playlist_widget.c
25 25
#include <audacious/i18n.h>
26 26
#include <audacious/misc.h>
27 27
#include <audacious/playlist.h>
28
#include <libaudcore/audstrings.h>
28 29
#include <libaudgui/libaudgui.h>
29 30
#include <libaudgui/libaudgui-gtk.h>
30 31
#include <libaudgui/list.h>
......
477 478
    else
478 479
        popup_hide (data);
479 480
}
481

  
482
void ui_playlist_widget_get_column_widths (GtkWidget * widget, char * * widths,
483
 char * * expand)
484
{
485
    int w[pw_num_cols], ex[pw_num_cols];
486

  
487
    for (int i = 0; i < pw_num_cols; i ++)
488
    {
489
        GtkTreeViewColumn * col = gtk_tree_view_get_column ((GtkTreeView *) widget, i);
490
        w[i] = gtk_tree_view_column_get_fixed_width (col);
491
        ex[i] = gtk_tree_view_column_get_expand (col);
492
    }
493

  
494
    * widths = int_array_to_string (w, pw_num_cols);
495
    * expand = int_array_to_string (ex, pw_num_cols);
496
}
497

  
498
void ui_playlist_widget_set_column_widths (GtkWidget * widget,
499
 const char * widths, const char * expand)
500
{
501
    int w[pw_num_cols], ex[pw_num_cols];
502

  
503
    if (! string_to_int_array (widths, w, pw_num_cols) ||
504
     ! string_to_int_array (expand, ex, pw_num_cols))
505
        return;
506

  
507
    for (int i = 0; i < pw_num_cols; i ++)
508
    {
509
        GtkTreeViewColumn * col = gtk_tree_view_get_column ((GtkTreeView *) widget, i);
510
        gtk_tree_view_column_set_fixed_width (col, w[i]);
511
        gtk_tree_view_column_set_expand (col, ex[i]);
512
     }
513
}
src/gtkui/ui_playlist_widget.h
29 29
 gint count);
30 30
void ui_playlist_widget_scroll (GtkWidget * widget);
31 31

  
32
void ui_playlist_widget_get_column_widths (GtkWidget * widget, char * * widths,
33
 char * * expand);
34
void ui_playlist_widget_set_column_widths (GtkWidget * widget,
35
 const char * widths, const char * expand);
36

  
32 37
enum {PW_COL_NUMBER, PW_COL_TITLE, PW_COL_ARTIST, PW_COL_YEAR, PW_COL_ALBUM,
33 38
 PW_COL_TRACK, PW_COL_GENRE, PW_COL_QUEUED, PW_COL_LENGTH, PW_COL_PATH,
34 39
 PW_COL_FILENAME, PW_COL_CUSTOM, PW_COL_BITRATE, PW_COLS};