1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * arch-tag: Implementation of preferences dialog object
5 * Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org>
6 * Copyright (C) 2003 Colin Walters <walters@debian.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <glib/gi18n.h>
30 #include <glade/glade.h>
31 #include <libgnome/gnome-help.h>
33 #include "rb-file-helpers.h"
34 #include "rb-shell-preferences.h"
35 #include "rb-source.h"
36 #include "rb-glade-helpers.h"
37 #include "rb-dialog.h"
39 #include "eel-gconf-extensions.h"
40 #include "rb-preferences.h"
42 static void rb_shell_preferences_class_init (RBShellPreferencesClass
*klass
);
43 static void rb_shell_preferences_init (RBShellPreferences
*shell_preferences
);
44 static void rb_shell_preferences_finalize (GObject
*object
);
45 static gboolean
rb_shell_preferences_window_delete_cb (GtkWidget
*window
,
47 RBShellPreferences
*shell_preferences
);
48 static void rb_shell_preferences_response_cb (GtkDialog
*dialog
,
50 RBShellPreferences
*shell_preferences
);
51 static void rb_shell_preferences_ui_pref_changed (GConfClient
*client
,
54 RBShellPreferences
*shell_preferences
);
55 static void rb_shell_preferences_sync (RBShellPreferences
*shell_preferences
);
57 void rb_shell_preferences_column_check_changed_cb (GtkCheckButton
*butt
,
58 RBShellPreferences
*shell_preferences
);
59 void rb_shell_preferences_browser_views_activated_cb (GtkWidget
*widget
,
60 RBShellPreferences
*shell_preferences
);
61 static void rb_shell_preferences_toolbar_style_cb (GtkComboBox
*box
,
62 RBShellPreferences
*preferences
);
69 const char *styles
[] = { "desktop_default", "both", "both_horiz", "icon", "text" };
71 struct RBShellPreferencesPrivate
75 GtkWidget
*config_widget
;
76 GtkWidget
*artist_check
;
77 GtkWidget
*album_check
;
78 GtkWidget
*genre_check
;
79 GtkWidget
*duration_check
;
80 GtkWidget
*track_check
;
81 GtkWidget
*rating_check
;
82 GtkWidget
*play_count_check
;
83 GtkWidget
*last_played_check
;
84 GtkWidget
*first_seen_check
;
85 GtkWidget
*quality_check
;
86 GtkWidget
*year_check
;
88 GSList
*browser_views_group
;
90 GtkWidget
*toolbar_style_menu
;
95 #define RB_SHELL_PREFERENCES_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_SHELL_PREFERENCES, RBShellPreferencesPrivate))
97 G_DEFINE_TYPE (RBShellPreferences
, rb_shell_preferences
, GTK_TYPE_DIALOG
)
100 rb_shell_preferences_class_init (RBShellPreferencesClass
*klass
)
102 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
104 object_class
->finalize
= rb_shell_preferences_finalize
;
106 g_type_class_add_private (klass
, sizeof (RBShellPreferencesPrivate
));
110 help_cb (GtkWidget
*widget
,
111 RBShellPreferences
*shell_preferences
)
113 GError
*error
= NULL
;
115 gnome_help_display ("rhythmbox.xml", "prefs", &error
);
118 rb_error_dialog (NULL
,
119 _("Couldn't display help"),
120 "%s", error
->message
);
122 g_error_free (error
);
127 rb_shell_preferences_init (RBShellPreferences
*shell_preferences
)
132 shell_preferences
->priv
= RB_SHELL_PREFERENCES_GET_PRIVATE (shell_preferences
);
134 g_signal_connect_object (G_OBJECT (shell_preferences
),
136 G_CALLBACK (rb_shell_preferences_window_delete_cb
),
137 shell_preferences
, 0);
138 g_signal_connect_object (G_OBJECT (shell_preferences
),
140 G_CALLBACK (rb_shell_preferences_response_cb
),
141 shell_preferences
, 0);
143 gtk_dialog_add_button (GTK_DIALOG (shell_preferences
),
146 tmp
= gtk_dialog_add_button (GTK_DIALOG (shell_preferences
),
149 g_signal_connect_object (G_OBJECT (tmp
), "clicked",
150 G_CALLBACK (help_cb
), shell_preferences
, 0);
151 gtk_dialog_set_default_response (GTK_DIALOG (shell_preferences
),
154 gtk_window_set_title (GTK_WINDOW (shell_preferences
), _("Music Player Preferences"));
155 gtk_window_set_resizable (GTK_WINDOW (shell_preferences
), FALSE
);
157 shell_preferences
->priv
->notebook
= GTK_WIDGET (gtk_notebook_new ());
158 gtk_container_set_border_width (GTK_CONTAINER (shell_preferences
->priv
->notebook
), 5);
160 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (shell_preferences
)->vbox
),
161 shell_preferences
->priv
->notebook
);
163 gtk_container_set_border_width (GTK_CONTAINER (shell_preferences
), 5);
164 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (shell_preferences
)->vbox
), 2);
165 gtk_dialog_set_has_separator (GTK_DIALOG (shell_preferences
), FALSE
);
167 xml
= rb_glade_xml_new ("general-prefs.glade",
171 rb_glade_boldify_label (xml
, "visible_columns_label");
174 shell_preferences
->priv
->artist_check
=
175 glade_xml_get_widget (xml
, "artist_check");
176 shell_preferences
->priv
->album_check
=
177 glade_xml_get_widget (xml
, "album_check");
178 shell_preferences
->priv
->genre_check
=
179 glade_xml_get_widget (xml
, "genre_check");
180 shell_preferences
->priv
->duration_check
=
181 glade_xml_get_widget (xml
, "duration_check");
182 shell_preferences
->priv
->track_check
=
183 glade_xml_get_widget (xml
, "track_check");
184 shell_preferences
->priv
->rating_check
=
185 glade_xml_get_widget (xml
, "rating_check");
186 shell_preferences
->priv
->play_count_check
=
187 glade_xml_get_widget (xml
, "play_count_check");
188 shell_preferences
->priv
->last_played_check
=
189 glade_xml_get_widget (xml
, "last_played_check");
190 shell_preferences
->priv
->quality_check
=
191 glade_xml_get_widget (xml
, "quality_check");
192 shell_preferences
->priv
->year_check
=
193 glade_xml_get_widget (xml
, "year_check");
194 shell_preferences
->priv
->first_seen_check
=
195 glade_xml_get_widget (xml
, "first_seen_check");
197 /* browser options */
198 rb_glade_boldify_label (xml
, "browser_views_label");
200 tmp
= glade_xml_get_widget (xml
, "library_browser_views_radio");
201 shell_preferences
->priv
->browser_views_group
=
202 g_slist_reverse (g_slist_copy (gtk_radio_button_get_group
203 (GTK_RADIO_BUTTON (tmp
))));
205 gtk_notebook_append_page (GTK_NOTEBOOK (shell_preferences
->priv
->notebook
),
206 glade_xml_get_widget (xml
, "general_vbox"),
207 gtk_label_new (_("General")));
209 /* toolbar button style */
210 rb_glade_boldify_label (xml
, "toolbar_style_label");
211 shell_preferences
->priv
->toolbar_style_menu
=
212 glade_xml_get_widget (xml
, "toolbar_style_menu");
213 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (shell_preferences
->priv
->toolbar_style_menu
),
214 rb_combo_box_hyphen_separator_func
,
216 g_signal_connect_object (G_OBJECT (shell_preferences
->priv
->toolbar_style_menu
),
217 "changed", G_CALLBACK (rb_shell_preferences_toolbar_style_cb
),
218 shell_preferences
, 0);
220 eel_gconf_notification_add (CONF_UI_DIR
,
221 (GConfClientNotifyFunc
) rb_shell_preferences_ui_pref_changed
,
223 g_object_unref (G_OBJECT (xml
));
224 rb_shell_preferences_sync (shell_preferences
);
228 rb_shell_preferences_finalize (GObject
*object
)
230 RBShellPreferences
*shell_preferences
;
232 g_return_if_fail (object
!= NULL
);
233 g_return_if_fail (RB_IS_SHELL_PREFERENCES (object
));
235 shell_preferences
= RB_SHELL_PREFERENCES (object
);
237 g_return_if_fail (shell_preferences
->priv
!= NULL
);
239 G_OBJECT_CLASS (rb_shell_preferences_parent_class
)->finalize (object
);
243 rb_shell_preferences_append_page (RBShellPreferences
*prefs
,
249 label
= gtk_label_new (name
);
250 gtk_notebook_append_page (GTK_NOTEBOOK (prefs
->priv
->notebook
),
256 rb_shell_preferences_append_view_page (RBShellPreferences
*prefs
,
262 g_return_if_fail (RB_IS_SHELL_PREFERENCES (prefs
));
263 g_return_if_fail (RB_IS_SOURCE (source
));
265 widget
= rb_source_get_config_widget (source
, prefs
);
269 rb_shell_preferences_append_page (prefs
, name
, widget
);
272 #ifdef WITH_DAAP_SUPPORT
275 share_check_button_toggled_cb (GtkToggleButton
*button
,
280 b
= gtk_toggle_button_get_active (button
);
282 eel_gconf_set_boolean (CONF_DAAP_ENABLE_SHARING
, b
);
284 gtk_widget_set_sensitive (widget
, b
);
290 password_check_button_toggled_cb (GtkToggleButton
*button
,
295 b
= gtk_toggle_button_get_active (button
);
297 eel_gconf_set_boolean (CONF_DAAP_REQUIRE_PASSWORD
, b
);
299 gtk_widget_set_sensitive (widget
, b
);
305 share_name_entry_focus_out_event_cb (GtkEntry
*entry
,
306 GdkEventFocus
*event
,
313 name
= gtk_entry_get_text (entry
);
314 old_name
= eel_gconf_get_string (CONF_DAAP_SHARE_NAME
);
316 if (name
== NULL
&& old_name
== NULL
) {
318 } else if (name
== NULL
|| old_name
== NULL
) {
320 } else if (strcmp (name
, old_name
) != 0) {
327 eel_gconf_set_string (CONF_DAAP_SHARE_NAME
, name
);
336 share_password_entry_focus_out_event_cb (GtkEntry
*entry
,
337 GdkEventFocus
*event
,
344 pw
= gtk_entry_get_text (entry
);
345 old_pw
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
347 if (pw
== NULL
&& old_pw
== NULL
) {
349 } else if (pw
== NULL
|| old_pw
== NULL
) {
351 } else if (strcmp (pw
, old_pw
) != 0) {
358 eel_gconf_set_string (CONF_DAAP_SHARE_PASSWORD
, pw
);
367 add_daap_preferences (RBShellPreferences
*shell_preferences
)
371 GtkWidget
*name_entry
;
372 GtkWidget
*password_entry
;
373 GtkWidget
*password_check
;
375 gboolean sharing_enabled
;
376 gboolean require_password
;
381 xml
= rb_glade_xml_new ("daap-prefs.glade",
385 check
= glade_xml_get_widget (xml
, "daap_enable_check");
386 password_check
= glade_xml_get_widget (xml
, "daap_password_check");
387 name_entry
= glade_xml_get_widget (xml
, "daap_name_entry");
388 password_entry
= glade_xml_get_widget (xml
, "daap_password_entry");
389 box
= glade_xml_get_widget (xml
, "daap_box");
391 sharing_enabled
= eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING
);
392 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check
), sharing_enabled
);
393 g_signal_connect (check
, "toggled", G_CALLBACK (share_check_button_toggled_cb
), box
);
395 require_password
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
396 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_check
), require_password
);
397 g_signal_connect (password_check
, "toggled", G_CALLBACK (password_check_button_toggled_cb
), password_entry
);
399 name
= eel_gconf_get_string (CONF_DAAP_SHARE_NAME
);
401 gtk_entry_set_text (GTK_ENTRY (name_entry
), name
);
404 g_signal_connect (name_entry
, "focus-out-event",
405 G_CALLBACK (share_name_entry_focus_out_event_cb
), NULL
);
407 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
408 if (password
!= NULL
) {
409 gtk_entry_set_text (GTK_ENTRY (password_entry
), password
);
412 g_signal_connect (password_entry
, "focus-out-event",
413 G_CALLBACK (share_password_entry_focus_out_event_cb
), NULL
);
415 gtk_widget_set_sensitive (box
, sharing_enabled
);
416 gtk_widget_set_sensitive (password_entry
, require_password
);
418 gtk_notebook_append_page (GTK_NOTEBOOK (shell_preferences
->priv
->notebook
),
419 glade_xml_get_widget (xml
, "daap_vbox"),
420 gtk_label_new (_("Sharing")));
422 #endif /* WITH_DAAP_SUPPORT */
425 rb_shell_preferences_new (GList
*views
)
427 RBShellPreferences
*shell_preferences
;
429 shell_preferences
= g_object_new (RB_TYPE_SHELL_PREFERENCES
,
432 g_return_val_if_fail (shell_preferences
->priv
!= NULL
, NULL
);
434 for (; views
; views
= views
->next
)
437 g_object_get (views
->data
, "name", &name
, NULL
);
438 g_assert (name
!= NULL
);
439 rb_shell_preferences_append_view_page (shell_preferences
,
441 RB_SOURCE (views
->data
));
445 #ifdef WITH_DAAP_SUPPORT
446 add_daap_preferences (shell_preferences
);
447 #endif /* WITH_DAAP_SUPPORT */
449 return GTK_WIDGET (shell_preferences
);
453 rb_shell_preferences_window_delete_cb (GtkWidget
*window
,
455 RBShellPreferences
*shell_preferences
)
457 gtk_widget_hide (GTK_WIDGET (shell_preferences
));
463 rb_shell_preferences_response_cb (GtkDialog
*dialog
,
465 RBShellPreferences
*shell_preferences
)
467 if (response_id
== GTK_RESPONSE_CLOSE
)
468 gtk_widget_hide (GTK_WIDGET (shell_preferences
));
472 rb_shell_preferences_ui_pref_changed (GConfClient
*client
,
475 RBShellPreferences
*shell_preferences
)
477 if (shell_preferences
->priv
->loading
== TRUE
)
480 rb_shell_preferences_sync (shell_preferences
);
484 rb_shell_preferences_column_check_changed_cb (GtkCheckButton
*butt
,
485 RBShellPreferences
*shell_preferences
)
487 GString
*newcolumns
= g_string_new ("");
488 char *currentcols
= eel_gconf_get_string (CONF_UI_COLUMNS_SETUP
);
489 char **colnames
= currentcols
? g_strsplit (currentcols
, ",", 0) : NULL
;
490 char *colname
= NULL
;
493 if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->artist_check
))
494 colname
= "RHYTHMDB_PROP_ARTIST";
495 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->album_check
))
496 colname
= "RHYTHMDB_PROP_ALBUM";
497 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->genre_check
))
498 colname
= "RHYTHMDB_PROP_GENRE";
499 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->duration_check
))
500 colname
= "RHYTHMDB_PROP_DURATION";
501 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->track_check
))
502 colname
= "RHYTHMDB_PROP_TRACK_NUMBER";
503 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->rating_check
))
504 colname
= "RHYTHMDB_PROP_RATING";
505 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->play_count_check
))
506 colname
= "RHYTHMDB_PROP_PLAY_COUNT";
507 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->last_played_check
))
508 colname
= "RHYTHMDB_PROP_LAST_PLAYED";
509 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->year_check
))
510 colname
= "RHYTHMDB_PROP_DATE";
511 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->quality_check
))
512 colname
= "RHYTHMDB_PROP_BITRATE";
513 else if (butt
== GTK_CHECK_BUTTON (shell_preferences
->priv
->first_seen_check
))
514 colname
= "RHYTHMDB_PROP_FIRST_SEEN";
516 g_assert_not_reached ();
518 rb_debug ("\"%s\" changed, current cols are \"%s\"", colname
, currentcols
);
520 /* Append this if we want it */
521 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (butt
))) {
522 g_string_append (newcolumns
, colname
);
523 g_string_append (newcolumns
, ",");
526 /* Append everything else */
527 for (i
= 0; colnames
!= NULL
&& colnames
[i
] != NULL
; i
++) {
528 if (strcmp (colnames
[i
], colname
)) {
529 g_string_append (newcolumns
, colnames
[i
]);
530 if (colnames
[i
+1] != NULL
)
531 g_string_append (newcolumns
, ",");
535 eel_gconf_set_string (CONF_UI_COLUMNS_SETUP
, newcolumns
->str
);
536 g_string_free (newcolumns
, TRUE
);
540 rb_shell_preferences_sync_column_button (RBShellPreferences
*preferences
,
545 g_signal_handlers_block_by_func (G_OBJECT (button
),
546 rb_shell_preferences_column_check_changed_cb
,
549 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
),
550 strstr (columns
, propid
) != NULL
);
552 g_signal_handlers_unblock_by_func (G_OBJECT (button
),
553 rb_shell_preferences_column_check_changed_cb
,
558 rb_shell_preferences_sync (RBShellPreferences
*shell_preferences
)
564 shell_preferences
->priv
->loading
= TRUE
;
566 rb_debug ("syncing prefs");
568 columns
= eel_gconf_get_string (CONF_UI_COLUMNS_SETUP
);
571 rb_shell_preferences_sync_column_button (shell_preferences
,
572 shell_preferences
->priv
->artist_check
,
573 columns
, "RHYTHMDB_PROP_ARTIST");
574 rb_shell_preferences_sync_column_button (shell_preferences
,
575 shell_preferences
->priv
->album_check
,
576 columns
, "RHYTHMDB_PROP_ALBUM");
577 rb_shell_preferences_sync_column_button (shell_preferences
,
578 shell_preferences
->priv
->genre_check
,
579 columns
, "RHYTHMDB_PROP_GENRE");
580 rb_shell_preferences_sync_column_button (shell_preferences
,
581 shell_preferences
->priv
->duration_check
,
582 columns
, "RHYTHMDB_PROP_DURATION");
583 rb_shell_preferences_sync_column_button (shell_preferences
,
584 shell_preferences
->priv
->track_check
,
585 columns
, "RHYTHMDB_PROP_TRACK_NUMBER");
586 rb_shell_preferences_sync_column_button (shell_preferences
,
587 shell_preferences
->priv
->rating_check
,
588 columns
, "RHYTHMDB_PROP_RATING");
589 rb_shell_preferences_sync_column_button (shell_preferences
,
590 shell_preferences
->priv
->play_count_check
,
591 columns
, "RHYTHMDB_PROP_PLAY_COUNT");
592 rb_shell_preferences_sync_column_button (shell_preferences
,
593 shell_preferences
->priv
->last_played_check
,
594 columns
, "RHYTHMDB_PROP_LAST_PLAYED");
595 rb_shell_preferences_sync_column_button (shell_preferences
,
596 shell_preferences
->priv
->year_check
,
597 columns
, "RHYTHMDB_PROP_DATE");
598 rb_shell_preferences_sync_column_button (shell_preferences
,
599 shell_preferences
->priv
->first_seen_check
,
600 columns
, "RHYTHMDB_PROP_FIRST_SEEN");
601 rb_shell_preferences_sync_column_button (shell_preferences
,
602 shell_preferences
->priv
->quality_check
,
603 columns
, "RHYTHMDB_PROP_BITRATE");
608 view
= eel_gconf_get_integer (CONF_UI_BROWSER_VIEWS
);
609 for (l
= shell_preferences
->priv
->browser_views_group
, i
= 0; l
!= NULL
; l
= g_slist_next (l
), i
++)
610 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l
->data
), (i
== view
));
613 g_signal_handlers_block_by_func (G_OBJECT (shell_preferences
->priv
->toolbar_style_menu
),
614 G_CALLBACK (rb_shell_preferences_toolbar_style_cb
),
617 view
= eel_gconf_get_integer (CONF_UI_TOOLBAR_STYLE
);
618 /* skip the separator row */
621 gtk_combo_box_set_active (GTK_COMBO_BOX (shell_preferences
->priv
->toolbar_style_menu
), view
);
623 g_signal_handlers_unblock_by_func (G_OBJECT (shell_preferences
->priv
->toolbar_style_menu
),
624 G_CALLBACK (rb_shell_preferences_toolbar_style_cb
),
627 shell_preferences
->priv
->loading
= FALSE
;
631 rb_shell_preferences_toolbar_style_cb (GtkComboBox
*box
, RBShellPreferences
*preferences
)
635 selection
= gtk_combo_box_get_active (box
);
637 /* skip the separator row */
641 eel_gconf_set_integer (CONF_UI_TOOLBAR_STYLE
, selection
);
645 rb_shell_preferences_browser_views_activated_cb (GtkWidget
*widget
,
646 RBShellPreferences
*shell_preferences
)
650 if (shell_preferences
->priv
->loading
)
653 index
= g_slist_index (shell_preferences
->priv
->browser_views_group
, widget
);
655 eel_gconf_set_integer (CONF_UI_BROWSER_VIEWS
, index
);