Fix typo: Similar Artist -> Similar Artists
[gmpc.git] / src / Tools / setup-assistant.c
blob8e59a6cd11074879affd506945ee621ccbcc4ead
1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
3 * Project homepage: http://gmpclient.org/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <gtk/gtk.h>
21 #include "main.h"
22 #include "playlist3.h"
23 #include "setup-assistant.h"
25 extern gmpcPlugin connection_plug;
26 GtkWidget *con_pref = NULL, *error_label = NULL;
27 gulong connect_signal = 0;
29 gboolean sa_running = FALSE;
31 gboolean setup_assistant_is_running(void)
33 return sa_running;
36 void setup_assistant_set_error(char *error)
38 if (error_label)
40 gtk_label_set_markup(GTK_LABEL(error_label), error);
44 static void destroy_assistant(GtkAssistant * assistant)
46 /**
47 * Destroy
50 if (con_pref)
52 connection_plug.pref->destroy(con_pref);
54 gtk_widget_destroy(GTK_WIDGET(assistant));
55 if (connect_signal)
57 g_signal_handler_disconnect(G_OBJECT(gmpcconn), connect_signal);
58 connect_signal = 0;
60 error_label = NULL;
61 sa_running = FALSE;
64 static void close_assistant(GtkAssistant * assistant)
66 /* Read out the configuration */
67 destroy_assistant(assistant);
70 static void cancel_assistant(GtkAssistant * assistant)
72 destroy_assistant(assistant);
75 static void connection_changed_assistant(GmpcConnection * gc, MpdObj * mi, int connect, gpointer data)
77 GtkAssistant *assistant = GTK_ASSISTANT(data);
78 if (con_pref)
80 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), gtk_widget_get_parent(con_pref),
81 mpd_check_connected(mi));
82 if (mpd_check_connected(mi))
84 if (error_label)
86 gtk_label_set_text(GTK_LABEL(error_label), "");
92 void setup_assistant(void)
94 GtkWidget *page = NULL;
95 GdkPixbuf *header_pb;
96 GtkWidget *assistant = gtk_assistant_new();
98 gtk_window_set_default_size(GTK_WINDOW(assistant), 400, 300);
99 gtk_window_set_title(GTK_WINDOW(assistant), _("GMPC - First start assistant"));
101 sa_running = TRUE;
104 * Header image
106 header_pb = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "gmpc", 48, 0, NULL);
109 * Append an introduction page
111 page =
112 gtk_label_new(_
113 ("It is the first time you have launched gmpc.\nThis assistant will help you connect gmpc to your mpd daemon."));
114 gtk_assistant_append_page(GTK_ASSISTANT(assistant), page);
115 gtk_assistant_set_page_title(GTK_ASSISTANT(assistant), page, _("Welcome to GMPC"));
116 gtk_assistant_set_page_header_image(GTK_ASSISTANT(assistant), page, header_pb);
117 gtk_widget_show_all(page);
118 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), page, TRUE);
121 * Add a configure page
123 page = gtk_vbox_new(FALSE, 6);
124 con_pref = gtk_event_box_new();
125 error_label = gtk_label_new("");
126 gtk_container_set_border_width(GTK_CONTAINER(page), 8);
127 connection_plug.pref->construct(con_pref);
128 gtk_box_pack_start(GTK_BOX(page), con_pref, TRUE, TRUE, 0);
129 gtk_box_pack_start(GTK_BOX(page), error_label, FALSE, FALSE, 0);
130 gtk_widget_show_all(page);
131 gtk_assistant_append_page(GTK_ASSISTANT(assistant), page);
132 /* set up header */
133 gtk_assistant_set_page_header_image(GTK_ASSISTANT(assistant), page, header_pb);
134 gtk_assistant_set_page_title(GTK_ASSISTANT(assistant), page, _("Setup connection"));
135 /* setup page type */
136 gtk_assistant_set_page_type(GTK_ASSISTANT(assistant), page, GTK_ASSISTANT_PAGE_CONTENT);
137 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), page, FALSE);
140 * End
142 page = gtk_label_new(_("Gmpc is now ready for use.\nEnjoy using gmpc."));
143 gtk_assistant_append_page(GTK_ASSISTANT(assistant), page);
144 gtk_assistant_set_page_title(GTK_ASSISTANT(assistant), page, _("Finish"));
145 gtk_assistant_set_page_header_image(GTK_ASSISTANT(assistant), page, header_pb);
146 gtk_widget_show_all(page);
147 gtk_assistant_set_page_type(GTK_ASSISTANT(assistant), page, GTK_ASSISTANT_PAGE_SUMMARY);
148 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), page, TRUE);
150 /* remove refernce to pixbuf */
151 g_object_unref(header_pb);
154 * Process it
157 gtk_window_set_transient_for(GTK_WINDOW(assistant), GTK_WINDOW(playlist3_get_window()));
158 gtk_window_set_modal(GTK_WINDOW(assistant), TRUE);
159 gtk_window_set_position(GTK_WINDOW(assistant), GTK_WIN_POS_CENTER_ON_PARENT);
160 gtk_widget_show_all(GTK_WIDGET(assistant));
162 g_signal_connect(G_OBJECT(assistant), "close", G_CALLBACK(close_assistant), NULL);
163 g_signal_connect(G_OBJECT(assistant), "cancel", G_CALLBACK(cancel_assistant), NULL);
165 connect_signal =
166 g_signal_connect(G_OBJECT(gmpcconn), "connection_changed", G_CALLBACK(connection_changed_assistant), assistant);