2
* Copyright (C) 2001-2007 the xine-project
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19
* stuff to run on first startup / setup wizards
24
#include <sys/types.h>
42
#include "desktop_integration.h"
43
#include "preferences.h"
45
static GtkWidget *add_label (GtkBox *vbox, const char *label)
47
GtkWidget *l = ui_label_new_with_markup (label);
48
gtk_label_set_line_wrap (GTK_LABEL (l), TRUE);
49
gtk_misc_set_alignment (GTK_MISC (l), 0, 0.5);
50
gtk_box_pack_start (vbox, l, FALSE, FALSE, 5);
54
static GtkWidget *add_heading (GtkBox *vbox, const char *label)
56
char *markup = g_strdup_printf ("<big><b>%s</b></big>", label);
57
GtkWidget *l = add_label (vbox, markup);
62
static gboolean do_welcome (GtkDialog *dlg, GtkBox *vbox)
64
add_heading (vbox, _("Welcome to gxine!\n\n"));
65
add_label (vbox, _("Would you like to run some setup wizards now "
66
"that will check your installation and maybe "
67
"do some adjustments for you if necessary?\n\n"
68
"If you do not want to run the wizards right now, "
69
"just click on the <i>Close</i> button and you will "
70
"not be bothered again.\n\n"
71
"You can always run the wizards (again) from the "
78
char *msg, *explanation;
81
static void details_cb (GtkWidget* widget, gpointer data)
84
display_info (FROM_GXINE, _("Health Check Results"), "%s\n%s",
85
msg->msg, msg->explanation);
88
static void hc_update_pref (const char *pref, const char *value)
90
xine_cfg_entry_t entry;
91
xine_config_lookup_entry (xine, pref, &entry);
92
entry.str_value = (char *)value;
93
preferences_update_entry (&entry);
96
static gboolean do_health_check (GtkDialog *dlg, GtkBox *vbox)
98
GtkWidget *l, *table, *b;
99
xine_health_check_t hc;
100
xine_health_check_t *results;
104
table = gtk_table_new (1, 1, FALSE);
106
add_heading (vbox, _("System configuration check"));
107
add_label (vbox, _("The xine engine runs certain checks on your "
108
"system configuration. Results follow:"));
110
/* If media.vcd.device is empty, set it to the default "/dev/cdrom" */
111
hc.cdrom_dev = xine_config_register_string(xine,
114
_("device used for CD-ROM drive"),
115
NULL, 0, NULL, NULL);
117
/* Similarly for media.audio_cd.device */
118
const char *audio_cd = xine_config_register_string(xine,
119
"media.audio_cd.device",
121
_("device used for CD-ROM drive"),
122
NULL, 0, NULL, NULL);
124
if (!audio_cd || !*audio_cd)
125
audio_cd = hc.cdrom_dev;
126
if (!audio_cd || !*audio_cd)
127
audio_cd = "/dev/cdrom";
128
if (!hc.cdrom_dev || !*hc.cdrom_dev)
129
hc.cdrom_dev = audio_cd;
131
/* If media.dvd.device is empty, set it to the default "/dev/dvd" */
132
hc.dvd_dev = xine_config_register_string(xine,
135
_("device used for DVD drive"),
136
NULL, 0, NULL, NULL);
138
if (!hc.dvd_dev || !*hc.dvd_dev)
139
hc.dvd_dev = "/dev/dvd";
141
hc_update_pref ("media.audio_cd.device", audio_cd);
142
hc_update_pref ("media.vcd.device", hc.cdrom_dev);
143
hc_update_pref ("media.dvd.device", hc.dvd_dev);
146
for (check = 0; ; ++check)
148
results = xine_health_check (&hc, check);
150
if (results->status == XINE_HEALTH_CHECK_NO_SUCH_CHECK)
153
gtk_table_resize (GTK_TABLE (table), 3, check+1);
155
l = ui_label_new_with_xalign (results->title, 0);
156
gtk_table_attach (GTK_TABLE (table), l, 0, 1, check, check+1, GTK_FILL,
159
switch (results->status)
161
case XINE_HEALTH_CHECK_UNSUPPORTED:
162
case XINE_HEALTH_CHECK_OK:
163
l = gtk_image_new_from_stock (GTK_STOCK_YES, GTK_ICON_SIZE_BUTTON);
165
case XINE_HEALTH_CHECK_FAIL:
166
msg = malloc (sizeof (hc_msg_t));
168
msg->msg = results->msg;
169
msg->explanation = results->explanation;
171
b = gtk_button_new_with_label (_("Details"));
172
g_signal_connect (G_OBJECT (b), "clicked", G_CALLBACK (details_cb), msg);
173
gtk_table_attach (GTK_TABLE (table), b, 2, 3, check, check+1, GTK_FILL,
176
l = gtk_image_new_from_stock (GTK_STOCK_NO, GTK_ICON_SIZE_BUTTON);
180
gtk_table_attach (GTK_TABLE (table), l, 1, 2, check, check+1, GTK_FILL,
184
gtk_box_pack_start (GTK_BOX(vbox), table, FALSE, FALSE, 5);
188
#ifdef USE_INTEGRATION_WIZARD
190
GtkToggleButton *moz, *gnome, *kde, *mailcap;
193
static void integrate_cb (GtkButton *button, gpointer data)
195
gboolean state = !!data;
196
if (GTK_WIDGET_SENSITIVE (cb.mailcap))
197
gtk_toggle_button_set_active (cb.mailcap, state);
198
if (GTK_WIDGET_SENSITIVE (cb.moz))
199
gtk_toggle_button_set_active (cb.moz, state);
200
if (GTK_WIDGET_SENSITIVE (cb.gnome))
201
gtk_toggle_button_set_active (cb.gnome, state);
202
if (GTK_WIDGET_SENSITIVE (cb.kde))
203
gtk_toggle_button_set_active (cb.kde, state);
206
static GtkToggleButton *
207
new_toggle (GtkBox *box, const char *label, gboolean active)
209
GtkWidget *w = gtk_check_button_new_with_mnemonic (label);
210
gtk_widget_set_sensitive (w, active);
211
gtk_box_pack_start (box, w, FALSE, FALSE, 5);
212
GtkToggleButton *b = GTK_TOGGLE_BUTTON (w);
213
gtk_toggle_button_set_active (b, active);
217
static gboolean ask_integration_wizard (GtkDialog *w, GtkBox *vbox)
222
GtkBox *vb = GTK_BOX (vbox);
224
add_heading (vbox, _("Registration"));
225
add_label (vbox, _("Register gxine with the following applications "
226
"as a media handler/helper:"));
228
cb.mailcap = new_toggle (vb, "~_/.mailcap", TRUE);
230
sname = g_build_filename (plugindir, "gxineplugin.so", NULL);
231
cb.moz = new_toggle (vb, _("_Mozilla & Mozilla Firefox (plugin)"), !stat (sname, &st));
234
cb.gnome = new_toggle (vb, _("_GNOME, Nautilus"), gxine_vfs_init ());
236
cb.kde = new_toggle (vb, _("_KDE, Konqueror"), TRUE);
238
hbox = gtk_hbox_new (FALSE, 2);
239
gtk_box_pack_start (vb, hbox, FALSE, FALSE, 2);
241
b = ui_button_new_stock_mnemonic (GTK_STOCK_ADD, _("_All"));
242
gtk_box_pack_start (GTK_BOX (hbox), b, FALSE, FALSE, 2);
243
g_signal_connect (G_OBJECT (b), "clicked",
244
(GCallback) integrate_cb, integrate_cb);
246
b = ui_button_new_stock_mnemonic (GTK_STOCK_REMOVE, _("_None"));
247
gtk_box_pack_start (GTK_BOX (hbox), b, FALSE, FALSE, 2);
248
g_signal_connect (G_OBJECT (b), "clicked",
249
(GCallback) integrate_cb, NULL);
254
static void desktop_integration (void)
256
di_registration_flush ();
257
if (gtk_toggle_button_get_active (cb.mailcap))
258
di_register_mailcap();
259
if (gtk_toggle_button_get_active (cb.gnome))
261
if (gtk_toggle_button_get_active (cb.kde))
263
if (gtk_toggle_button_get_active (cb.moz))
264
di_register_mozilla();
267
static gboolean report_integration_wizard (GtkDialog *w, GtkBox *vbox)
269
const char *report = di_registration_report ();
273
add_heading (vbox, _("Registration report"));
274
add_label (vbox, _("There were some problems during registration."));
275
add_label (vbox, report);
276
di_registration_flush ();
282
#define RESPONSE_CLOSE 0
283
#define RESPONSE_NEXT 1
285
static gboolean close_cb (GtkWidget* widget, gpointer data)
294
static void response_cb (GtkDialog *dbox, int response, gpointer data)
299
case GTK_RESPONSE_ACCEPT:
308
#define WIZARDS_LEVEL 6
310
void run_wizards (gboolean requested)
312
static GtkDialog *dlg = NULL;
316
gtk_window_set_modal (GTK_WINDOW (dlg), FALSE);
317
gtk_window_present (GTK_WINDOW(dlg));
322
|| (xine_config_register_num (xine, "misc.wizards_shown", 0,
323
_("Keep track of whether user has seen wizards yet"),
324
NULL, 32767, NULL, NULL) < WIZARDS_LEVEL))
326
xine_cfg_entry_t entry;
329
static const struct {
330
GtkWidget *(*create) (GtkDialog *, GtkBox *);
331
gboolean (*action) (void); /* TRUE to skip a stage */
333
{ do_welcome, NULL },
334
{ do_health_check, NULL },
335
#ifdef USE_INTEGRATION_WIZARD
336
{ ask_integration_wizard, desktop_integration },
337
{ report_integration_wizard, NULL },
342
if (xine_config_lookup_entry (xine, "misc.wizards_shown", &entry))
344
entry.num_value = WIZARDS_LEVEL;
345
preferences_update_entry (&entry);
348
/* set up dialog which all wizards will use */
350
dlg = GTK_DIALOG (gtk_dialog_new_with_buttons (_("gxine setup wizards"), NULL, 0,
351
GTK_STOCK_GO_FORWARD, GTK_RESPONSE_ACCEPT,
352
GTK_STOCK_CLOSE, GTK_RESPONSE_DELETE_EVENT,
354
gtk_dialog_set_default_response (dlg, GTK_RESPONSE_ACCEPT);
355
gtk_window_set_default_size (GTK_WINDOW (dlg), -1, 400);
356
gtk_window_set_modal (GTK_WINDOW (dlg), !requested);
357
g_object_connect (G_OBJECT (dlg),
358
"signal::delete-event", G_CALLBACK (close_cb), &b,
359
"signal::response", G_CALLBACK (response_cb), &b,
363
* contents: headline, separator, wizard-specific part
368
GtkWidget *w, *b = gtk_hbox_new (0, 0);
369
gtk_box_pack_start (GTK_BOX (dlg->vbox), b, FALSE, FALSE, 2);
370
gtk_box_pack_start (GTK_BOX (b),
371
gtk_image_new_from_stock (GXINE_LOGO, icon_size_logo),
373
w = ui_label_new_with_markup (_("<span face='serif' size='xx-large' weight='bold'>Welcome!</span>"));
374
gtk_box_pack_start (GTK_BOX (b), w, FALSE, FALSE, 2);
377
gtk_box_pack_start (GTK_BOX (dlg->vbox),
378
gtk_hseparator_new (), FALSE, FALSE, 5);
380
window_show ((GtkWidget *)dlg, NULL);
385
GtkWidget *content = gtk_vbox_new (0, 0);
386
gtk_box_pack_start_defaults (GTK_BOX (dlg->vbox), content);
388
if (wizards[++state].create)
390
if (wizards[state].create (dlg, GTK_BOX (content)))
395
gtk_dialog_set_response_sensitive (dlg, GTK_RESPONSE_ACCEPT, FALSE);
396
add_heading (GTK_BOX (content), _("Setup completed."));
399
gtk_widget_show_all (content);
402
if (b == RESPONSE_CLOSE)
405
if (wizards[state].action)
406
wizards[state].action ();
409
gtk_container_remove (GTK_CONTAINER (dlg->vbox), content);
412
gtk_widget_destroy (GTK_WIDGET (dlg));
417
static JSBool js_run_wizards (JSContext *cx, JSObject *obj, uintN argc,
418
jsval *argv, jsval *rval)
420
/* se_t *se = (se_t *) JS_GetContextPrivate(cx); */
421
se_log_fncall_checkinit ("run_wizards");
426
void wizards_init (void)
428
se_defun (gse, NULL, "run_wizards", js_run_wizards, 0, 0,
429
SE_GROUP_HIDDEN, NULL, NULL);