1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * arch-tag: Implementation of Rhythmbox first-time druid
5 * Copyright (C) 2003,2004 Colin Walters <walters@debian.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <glib/gi18n.h>
27 #include <libgnomeui/gnome-druid.h>
28 #include <libgnomeui/gnome-druid-page-edge.h>
29 #include <libgnomeui/gnome-druid-page-standard.h>
30 #include <libgnomevfs/gnome-vfs-utils.h>
33 #include "rb-preferences.h"
35 #include "rb-dialog.h"
36 #include "rb-glade-helpers.h"
37 #include "eel-gconf-extensions.h"
39 static void rb_druid_finalize (GObject
*object
);
40 static void rb_druid_set_property (GObject
*object
,
44 static void rb_druid_get_property (GObject
*object
,
48 static void rb_druid_browse_clicked_cb (GtkButton
*button
, RBDruid
*druid
);
49 static void rb_druid_entry_changed_cb (GtkEntry
*entry
, RBDruid
*druid
);
50 static gboolean
rb_druid_page2_prepare_cb (GnomeDruidPage
*druid_page
, GtkWidget
*druid_widget
,
52 static void rb_druid_skip_toggled_cb (GtkToggleButton
*button
, RBDruid
*druid
);
53 static void rb_druid_page3_finish_cb (GnomeDruidPage
*druid_page
, GtkWidget
*druid_widget
,
55 static void do_response (RBDruid
*druid
);
62 GtkWidget
*page2_vbox
;
63 GtkWidget
*browse_button
;
64 GtkWidget
*page2_skip_radiobutton
;
65 GtkWidget
*path_entry
;
68 G_DEFINE_TYPE (RBDruid
, rb_druid
, GTK_TYPE_DIALOG
)
69 #define RB_DRUID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_DRUID, RBDruidPrivate))
78 rb_druid_class_init (RBDruidClass
*klass
)
80 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
82 object_class
->finalize
= rb_druid_finalize
;
83 object_class
->set_property
= rb_druid_set_property
;
84 object_class
->get_property
= rb_druid_get_property
;
86 g_object_class_install_property (object_class
,
88 g_param_spec_object ("db",
94 g_type_class_add_private (klass
, sizeof (RBDruidPrivate
));
98 rb_druid_init (RBDruid
*druid
)
102 druid
->priv
= RB_DRUID_GET_PRIVATE (druid
);
104 xml
= rb_glade_xml_new ("druid.glade", "druid_toplevel", druid
);
106 druid
->priv
->page2_vbox
= glade_xml_get_widget (xml
, "page2_vbox");
107 gtk_object_ref (GTK_OBJECT (druid
->priv
->page2_vbox
));
108 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (druid
->priv
->page2_vbox
)),
109 druid
->priv
->page2_vbox
);
110 druid
->priv
->browse_button
= glade_xml_get_widget (xml
, "browse_button");
111 druid
->priv
->path_entry
= glade_xml_get_widget (xml
, "path_entry");
112 druid
->priv
->page2_skip_radiobutton
= glade_xml_get_widget (xml
, "page2_skip_radiobutton");
114 g_signal_connect_object (G_OBJECT (druid
->priv
->page2_skip_radiobutton
), "toggled",
115 G_CALLBACK (rb_druid_skip_toggled_cb
), druid
, 0);
116 g_signal_connect_object (G_OBJECT (druid
->priv
->browse_button
), "clicked",
117 G_CALLBACK (rb_druid_browse_clicked_cb
), druid
, 0);
118 g_signal_connect_object (G_OBJECT (druid
->priv
->path_entry
), "changed",
119 G_CALLBACK (rb_druid_entry_changed_cb
), druid
, 0);
121 g_object_unref (G_OBJECT (xml
));
125 rb_druid_finalize (GObject
*object
)
129 g_return_if_fail (object
!= NULL
);
130 g_return_if_fail (RB_IS_DRUID (object
));
132 druid
= RB_DRUID (object
);
134 g_return_if_fail (druid
->priv
!= NULL
);
136 G_OBJECT_CLASS (rb_druid_parent_class
)->finalize (object
);
140 rb_druid_set_property (GObject
*object
,
145 RBDruid
*druid
= RB_DRUID (object
);
150 druid
->priv
->db
= g_value_get_object (value
);
153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
159 rb_druid_get_property (GObject
*object
,
164 RBDruid
*druid
= RB_DRUID (object
);
169 g_value_set_object (value
, druid
->priv
->db
);
172 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
178 rb_druid_init_widgets (RBDruid
*druid
)
180 GnomeDruidPage
*page
;
182 g_return_if_fail (RB_IS_DRUID (druid
));
184 gtk_window_set_title (GTK_WINDOW (druid
),_("Rhythmbox"));
185 gtk_window_set_modal (GTK_WINDOW (druid
), TRUE
);
187 druid
->priv
->druid
= GNOME_DRUID (gnome_druid_new ());
188 gtk_widget_show (GTK_WIDGET (druid
->priv
->druid
));
189 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (druid
)->vbox
),
190 GTK_WIDGET (druid
->priv
->druid
));
191 gnome_druid_set_show_help (druid
->priv
->druid
, FALSE
);
193 g_signal_connect_object (druid
->priv
->druid
, "cancel",
194 G_CALLBACK (do_response
),
195 druid
, G_CONNECT_SWAPPED
);
197 g_signal_connect_object (druid
->priv
->druid
, "destroy",
198 G_CALLBACK (do_response
),
199 druid
, G_CONNECT_SWAPPED
);
202 page
= GNOME_DRUID_PAGE (gnome_druid_page_edge_new (GNOME_EDGE_START
));
203 gtk_widget_show (GTK_WIDGET (page
));
204 gnome_druid_page_edge_set_title (GNOME_DRUID_PAGE_EDGE (page
),
205 _("Welcome to Rhythmbox"));
206 gnome_druid_append_page (druid
->priv
->druid
, page
);
207 gnome_druid_set_page (druid
->priv
->druid
, page
);
208 gnome_druid_page_edge_set_text (GNOME_DRUID_PAGE_EDGE (page
),
209 _("Rhythmbox is the GNOME music player that lets you do everything: play your music files, listen to Internet Radio, import music from CDs, and much more.\n\nThis assistant will help you get started by asking you some simple questions."));
212 page
= GNOME_DRUID_PAGE (gnome_druid_page_standard_new ());
213 gtk_widget_show (GTK_WIDGET (page
));
214 gnome_druid_page_standard_set_title (GNOME_DRUID_PAGE_STANDARD (page
),
215 _("Music library setup"));
216 gtk_container_add (GTK_CONTAINER (GNOME_DRUID_PAGE_STANDARD (page
)->vbox
),
217 druid
->priv
->page2_vbox
);
218 gnome_druid_append_page (druid
->priv
->druid
, page
);
219 g_signal_connect_object (G_OBJECT (page
), "prepare", G_CALLBACK (rb_druid_page2_prepare_cb
), druid
, 0);
222 page
= GNOME_DRUID_PAGE (gnome_druid_page_edge_new (GNOME_EDGE_FINISH
));
223 gtk_widget_show (GTK_WIDGET (page
));
224 gnome_druid_page_edge_set_title (GNOME_DRUID_PAGE_EDGE (page
), _("Finish"));
225 gnome_druid_page_edge_set_text (GNOME_DRUID_PAGE_EDGE (page
),
226 _("You are now ready to start Rhythmbox.\n\nRemember that you may add music to the library using \"Music\" then \"Import Folder\", or by importing it from CDs."));
227 g_signal_connect_object (G_OBJECT (page
), "finish", G_CALLBACK (rb_druid_page3_finish_cb
), druid
, 0);
228 gnome_druid_append_page (druid
->priv
->druid
, page
);
230 /* g_signal_connect_object (page, "prepare", G_CALLBACK (gb_export_druid_page_5_prepare_cb), d, 0); */
233 gnome_druid_set_show_help (druid
->priv
->druid
, FALSE
);
234 gtk_button_set_label (GTK_BUTTON (druid
->priv
->druid
->cancel
), GTK_STOCK_CLOSE
);
238 rb_druid_new (RhythmDB
*db
)
240 RBDruid
*druid
= g_object_new (RB_TYPE_DRUID
, "db", db
, NULL
);
242 g_return_val_if_fail (druid
->priv
!= NULL
, NULL
);
244 rb_druid_init_widgets (druid
);
250 path_dialog_response_cb (GtkDialog
*dialog
,
257 rb_debug ("got response");
259 if (response_id
!= GTK_RESPONSE_ACCEPT
) {
260 gtk_widget_destroy (GTK_WIDGET (dialog
));
264 uri
= gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog
));
266 uri
= gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dialog
));
269 gtk_widget_destroy (GTK_WIDGET (dialog
));
274 path
= gnome_vfs_format_uri_for_display (uri
);
275 gtk_entry_set_text (GTK_ENTRY (druid
->priv
->path_entry
), path
);
281 rb_druid_browse_clicked_cb (GtkButton
*button
, RBDruid
*druid
)
286 dialog
= rb_file_chooser_new (_("Load folder into Library"),
288 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
,
290 gtk_window_set_modal (GTK_WINDOW (dialog
), TRUE
);
292 g_signal_connect_object (G_OBJECT (dialog
), "response",
293 G_CALLBACK (path_dialog_response_cb
), druid
, 0);
297 rb_druid_page2_sync_sensitive (RBDruid
*druid
)
299 gboolean next_enabled
;
300 gboolean skip_active
;
302 rb_debug ("syncing sensitivity");
304 text
= gtk_entry_get_text (GTK_ENTRY (druid
->priv
->path_entry
));
306 skip_active
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (druid
->priv
->page2_skip_radiobutton
));
307 next_enabled
= g_utf8_strlen (text
, -1) > 0 || skip_active
;
309 gtk_widget_set_sensitive (druid
->priv
->path_entry
, !skip_active
);
310 gtk_widget_set_sensitive (druid
->priv
->druid
->next
, next_enabled
);
314 rb_druid_skip_toggled_cb (GtkToggleButton
*button
, RBDruid
*druid
)
316 rb_debug ("skip changed");
318 rb_druid_page2_sync_sensitive (druid
);
322 rb_druid_entry_changed_cb (GtkEntry
*entry
, RBDruid
*druid
)
324 rb_debug ("entry changed");
326 rb_druid_page2_sync_sensitive (druid
);
330 idle_set_sensitive (RBDruid
*druid
)
332 g_return_val_if_fail (RB_IS_DRUID (druid
), FALSE
);
334 GDK_THREADS_ENTER ();
336 rb_druid_page2_sync_sensitive (druid
);
338 GDK_THREADS_LEAVE ();
343 rb_druid_page2_prepare_cb (GnomeDruidPage
*druid_page
, GtkWidget
*druid_widget
,
346 g_return_val_if_fail (RB_IS_DRUID (druid
), FALSE
);
348 rb_debug ("page2 prepare");
350 /* FIXME: this is a gross hack, but setting the next button
351 * to not be sensitive at this point doesn't work! */
352 g_idle_add ((GSourceFunc
) idle_set_sensitive
, druid
);
357 do_response (RBDruid
*druid
)
359 g_return_if_fail (RB_IS_DRUID (druid
));
360 gtk_dialog_response (GTK_DIALOG (druid
), GTK_RESPONSE_OK
);
364 rb_druid_page3_finish_cb (GnomeDruidPage
*druid_page
, GtkWidget
*druid_widget
,
367 rb_debug ("druid finished!");
368 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (druid
->priv
->page2_skip_radiobutton
))) {
369 const char *uri
= gtk_entry_get_text (GTK_ENTRY (druid
->priv
->path_entry
));
371 rb_debug ("page2 next; adding %s to library", uri
);
372 rhythmdb_add_uri (druid
->priv
->db
, uri
);
374 eel_gconf_set_boolean (CONF_FIRST_TIME
, TRUE
);
375 gnome_druid_set_buttons_sensitive (GNOME_DRUID (druid_widget
),
376 FALSE
, FALSE
, FALSE
, FALSE
);