/
gui_gtkplus2.c
911 lines (746 loc) · 30 KB
1
2
3
4
5
6
7
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
8
9
// Not only does GTK+ 2.x _look_ better than 1.x, it offers a lot of basic
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// functionality, like message boxes, that you'd expect to exist in a GUI
// toolkit. In GTK+v1, you'd have to roll all that on your own!
//
// It's easier to implement in that regard, and produces a smaller DLL, but
// it has a million dependencies, so you might need to use a GTK+v1 plugin,
// too, in case they break backwards compatibility.
#if !SUPPORT_GUI_GTKPLUS2
#error Something is wrong in the build system.
#endif
#define BUILDING_EXTERNAL_PLUGIN 1
#include "gui.h"
MOJOGUI_PLUGIN(gtkplus2)
#if !GUI_STATIC_LINK_GTKPLUS2
CREATE_MOJOGUI_ENTRY_POINT(gtkplus2)
#endif
30
#undef format
31
#include <gtk/gtk.h>
32
#define format entry->format
33
34
35
typedef enum
{
36
PAGE_INTRO,
37
38
PAGE_README,
PAGE_OPTIONS,
39
PAGE_DEST,
40
PAGE_PRODUCTKEY,
41
PAGE_PROGRESS,
42
PAGE_FINAL
43
44
} WizardPages;
45
46
static WizardPages currentpage = PAGE_INTRO;
static gboolean canfwd = TRUE;
47
48
49
50
51
52
53
static GtkWidget *gtkwindow = NULL;
static GtkWidget *pagetitle = NULL;
static GtkWidget *notebook = NULL;
static GtkWidget *readme = NULL;
static GtkWidget *cancel = NULL;
static GtkWidget *back = NULL;
static GtkWidget *next = NULL;
54
static GtkWidget *finish = NULL;
55
static GtkWidget *msgbox = NULL;
56
static GtkWidget *destination = NULL;
57
static GtkWidget *productkey = NULL;
58
59
static GtkWidget *progressbar = NULL;
static GtkWidget *progresslabel = NULL;
60
static GtkWidget *finallabel = NULL;
61
static GtkWidget *browse = NULL;
62
static GtkWidget *splash = NULL;
63
64
65
66
67
68
69
70
71
72
static volatile enum
{
CLICK_BACK=-1,
CLICK_CANCEL,
CLICK_NEXT,
CLICK_NONE
} click_value = CLICK_NONE;
73
static void prepare_wizard(const char *name, WizardPages page,
74
boolean can_back, boolean can_fwd,
75
boolean can_cancel, boolean fwd_at_start)
76
{
77
78
79
80
char *markup = g_markup_printf_escaped(
"<span size='large' weight='bold'>%s</span>",
name);
81
82
83
currentpage = page;
canfwd = can_fwd;
84
gtk_label_set_markup(GTK_LABEL(pagetitle), markup);
85
g_free(markup);
86
87
gtk_widget_set_sensitive(back, can_back);
88
gtk_widget_set_sensitive(next, fwd_at_start);
89
gtk_widget_set_sensitive(cancel, can_cancel);
90
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), (gint) page);
91
92
93
94
assert(click_value == CLICK_NONE);
assert(gtkwindow != NULL);
assert(msgbox == NULL);
95
} // prepare_wizard
96
97
98
static int wait_event(void)
99
100
101
{
int retval = 0;
102
103
104
// signals fired under gtk_main_iteration can change click_value.
gtk_main_iteration();
if (click_value == CLICK_CANCEL)
105
{
106
if (!MojoGui_gtkplus2_promptyn(_("Cancel installation"), _("Are you sure you want to cancel installation?"), false))
107
108
click_value = CLICK_NONE;
} // if
109
110
assert(click_value <= CLICK_NONE);
111
112
113
retval = (int) click_value;
click_value = CLICK_NONE;
return retval;
114
115
116
117
118
119
120
121
122
} // wait_event
static int pump_events(void)
{
int retval = (int) CLICK_NONE;
while ( (retval == ((int) CLICK_NONE)) && (gtk_events_pending()) )
retval = wait_event();
return retval;
123
124
125
} // pump_events
126
static int run_wizard(const char *name, WizardPages page,
127
128
boolean can_back, boolean can_fwd, boolean can_cancel,
boolean fwd_at_start)
129
130
{
int retval = CLICK_NONE;
131
prepare_wizard(name, page, can_back, can_fwd, can_cancel, fwd_at_start);
132
while (retval == ((int) CLICK_NONE))
133
retval = wait_event();
134
135
136
assert(retval < ((int) CLICK_NONE));
return retval;
137
138
139
140
141
} // run_wizard
static gboolean signal_delete(GtkWidget *w, GdkEvent *evt, gpointer data)
{
142
143
144
145
if (gtk_widget_get_visible(finish))
click_value = CLICK_NEXT;
else
click_value = CLICK_CANCEL;
146
147
148
149
150
151
152
153
154
155
156
return TRUE; /* eat event: default handler destroys window! */
} // signal_delete
static void signal_clicked(GtkButton *_button, gpointer data)
{
GtkWidget *button = GTK_WIDGET(_button);
if (button == back)
click_value = CLICK_BACK;
else if (button == cancel)
click_value = CLICK_CANCEL;
157
else if ((button == next) || (button == finish))
158
159
160
161
162
163
164
click_value = CLICK_NEXT;
else
{
assert(0 && "Unknown click event.");
} // else
} // signal_clicked
165
166
167
static void signal_browse_clicked(GtkButton *_button, gpointer data)
{
168
GtkWidget *dialog = gtk_file_chooser_dialog_new (
169
_("Destination"),
170
171
172
173
174
175
NULL,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
176
177
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
gtk_combo_box_get_active_text(GTK_COMBO_BOX(destination)));
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
gchar *filename;
gchar *utfname;
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
utfname = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
gtk_combo_box_prepend_text(GTK_COMBO_BOX(destination), utfname);
gtk_combo_box_set_active(GTK_COMBO_BOX(destination), 0);
g_free(utfname);
g_free(filename);
}
// !!! FIXME: should append the package name to the directory they chose?
// !!! FIXME: This is annoying, they might have created the folder
// !!! FIXME: themselves in the dialog.
// !!! FIXME: Could warn when the target directory already contains files?
gtk_widget_destroy(dialog);
199
200
201
202
203
204
} // signal_browse_clicked
static void signal_dest_changed(GtkComboBox *combo, gpointer user_data)
{
// Disable the forward button when the destination entry is blank.
205
if ((currentpage == PAGE_DEST) && (canfwd))
206
207
208
209
210
211
212
{
gchar *str = gtk_combo_box_get_active_text(combo);
const gboolean filled_in = ((str != NULL) && (*str != '\0'));
g_free(str);
gtk_widget_set_sensitive(next, filled_in);
} // if
} // signal_dest_changed
213
214
215
216
217
218
219
220
221
static void signal_productkey_changed(GtkEditable *edit, gpointer user_data)
{
// Disable the forward button when the entry is blank.
if ((currentpage == PAGE_PRODUCTKEY) && (canfwd))
{
const char *fmt = (const char *) user_data;
char *key = (char *) gtk_editable_get_chars(edit, 0, -1);
222
const gboolean okay = isValidProductKey(fmt, key);
223
224
225
226
227
228
g_free(key);
gtk_widget_set_sensitive(next, okay);
} // if
} // signal_productkey_changed
229
static uint8 MojoGui_gtkplus2_priority(boolean istty)
230
{
231
// gnome-session exports this environment variable since 2002.
232
233
234
235
236
237
238
239
240
241
242
243
if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL)
return MOJOGUI_PRIORITY_TRY_FIRST;
return MOJOGUI_PRIORITY_TRY_NORMAL;
} // MojoGui_gtkplus2_priority
static boolean MojoGui_gtkplus2_init(void)
{
int tmpargc = 0;
char *args[] = { NULL, NULL };
char **tmpargv = args;
244
245
if (!gtk_init_check(&tmpargc, &tmpargv))
{
246
logInfo("gtkplus2: gtk_init_check() failed, use another UI.");
247
248
249
return false;
} // if
return true;
250
251
252
253
254
255
256
257
258
} // MojoGui_gtkplus2_init
static void MojoGui_gtkplus2_deinit(void)
{
// !!! FIXME: GTK+ doesn't have a deinit function...it installs a crappy
// !!! FIXME: atexit() function!
} // MojoGui_gtkplus2_deinit
259
260
261
262
263
/**
*
* @param defbutton The response ID to use when enter is pressed, or 0
* to leave it up to GTK+.
*/
264
static gint do_msgbox(const char *title, const char *text,
265
GtkMessageType mtype, GtkButtonsType btype,
266
GtkResponseType defbutton,
267
void (*addButtonCallback)(GtkWidget *_msgbox))
268
269
{
gint retval = 0;
270
271
272
273
// Modal dialog, this will never be called recursively.
assert(msgbox == NULL);
274
275
276
277
msgbox = gtk_message_dialog_new(GTK_WINDOW(gtkwindow), GTK_DIALOG_MODAL,
mtype, btype, "%s", title);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msgbox),
"%s", text);
278
279
280
281
if (defbutton)
gtk_dialog_set_default_response(GTK_DIALOG(msgbox), defbutton);
282
283
284
if (addButtonCallback != NULL)
addButtonCallback(msgbox);
285
286
287
retval = gtk_dialog_run(GTK_DIALOG(msgbox));
gtk_widget_destroy(msgbox);
msgbox = NULL;
288
289
290
291
292
293
294
return retval;
} // do_msgbox
static void MojoGui_gtkplus2_msgbox(const char *title, const char *text)
{
295
do_msgbox(title, text, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, 0, NULL);
296
297
298
} // MojoGui_gtkplus2_msgbox
299
300
static boolean MojoGui_gtkplus2_promptyn(const char *title, const char *text,
boolean defval)
301
{
302
gint rc = do_msgbox(title, text, GTK_MESSAGE_QUESTION,
303
304
305
306
GTK_BUTTONS_YES_NO,
defval ? GTK_RESPONSE_YES : GTK_RESPONSE_NO,
NULL);
307
308
309
310
return (rc == GTK_RESPONSE_YES);
} // MojoGui_gtkplus2_promptyn
311
312
313
314
315
static void promptynanButtonCallback(GtkWidget *_msgbox)
{
gtk_dialog_add_buttons(GTK_DIALOG(_msgbox),
GTK_STOCK_YES, GTK_RESPONSE_YES,
GTK_STOCK_NO, GTK_RESPONSE_NO,
316
317
_("_Always"), 1,
_("N_ever"), 0,
318
NULL);
319
320
321
322
} // promptynanButtonCallback
static MojoGuiYNAN MojoGui_gtkplus2_promptynan(const char *title,
323
324
const char *text,
boolean defval)
325
326
{
const gint rc = do_msgbox(title, text, GTK_MESSAGE_QUESTION,
327
328
329
GTK_BUTTONS_NONE,
defval ? GTK_RESPONSE_YES : GTK_RESPONSE_NO,
promptynanButtonCallback);
330
331
332
333
switch (rc)
{
case GTK_RESPONSE_YES: return MOJOGUI_YES;
case GTK_RESPONSE_NO: return MOJOGUI_NO;
334
335
case 1: return MOJOGUI_ALWAYS;
case 0: return MOJOGUI_NEVER;
336
337
} // switch
338
assert(false && "BUG: unhandled case in switch statement");
339
340
341
342
return MOJOGUI_NO; // just in case.
} // MojoGui_gtkplus2_promptynan
343
static GtkWidget *create_button(GtkWidget *box, const char *iconname,
344
345
346
const char *text,
void (*signal_callback)
(GtkButton *button, gpointer data))
347
{
348
GtkWidget *button = gtk_button_new_with_mnemonic(text);
349
GtkWidget *image = gtk_image_new_from_stock(iconname, GTK_ICON_SIZE_BUTTON);
350
gtk_button_set_image (GTK_BUTTON(button), image);
351
gtk_widget_show(button);
352
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
353
gtk_signal_connect(GTK_OBJECT(button), "clicked",
354
GTK_SIGNAL_FUNC(signal_callback), NULL);
355
356
357
358
return button;
} // create_button
359
static void free_splash(guchar *pixels, gpointer data)
360
{
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
free(pixels);
} // free_splash
static GtkWidget *build_splash(const MojoGuiSplash *splash)
{
GtkWidget *retval = NULL;
GdkPixbuf *pixbuf = NULL;
guchar *rgba = NULL;
const uint32 splashlen = splash->w * splash->h * 4;
if (splash->position == MOJOGUI_SPLASH_NONE)
return NULL;
if ((splash->rgba == NULL) || (splashlen == 0))
return NULL;
378
rgba = (guchar *) xmalloc(splashlen);
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
memcpy(rgba, splash->rgba, splashlen);
pixbuf = gdk_pixbuf_new_from_data(rgba, GDK_COLORSPACE_RGB, TRUE, 8,
splash->w, splash->h, splash->w * 4,
free_splash, NULL);
if (pixbuf == NULL)
free(rgba);
else
{
retval = gtk_image_new_from_pixbuf(pixbuf);
g_object_unref(pixbuf); // retval adds a ref to pixbuf, so lose our's.
if (retval != NULL)
gtk_widget_show(retval);
} // else
return retval;
} // build_splash
static GtkWidget *create_gtkwindow(const char *title,
const MojoGuiSplash *_splash)
{
GtkWidget *splashbox = NULL;
401
402
403
GtkWidget *window;
GtkWidget *widget;
GtkWidget *box;
404
GtkWidget *alignment;
405
GtkWidget *hbox;
406
407
408
409
currentpage = PAGE_INTRO;
canfwd = TRUE;
410
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
411
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
412
gtk_window_set_title(GTK_WINDOW(window), title);
413
gtk_window_set_default_size(GTK_WINDOW(window), 700, 550);
414
gtk_container_set_border_width(GTK_CONTAINER(window), 8);
415
416
417
418
419
420
421
GdkPixbuf *icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
"system-software-installer",
48, 0, NULL);
if (icon)
gtk_window_set_icon(GTK_WINDOW(window), icon);
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
assert(splash == NULL);
splash = build_splash(_splash);
if (splash != NULL)
{
// !!! FIXME: MOJOGUI_SPLASH_BACKGROUND?
const MojoGuiSplashPos pos = _splash->position;
if ((pos == MOJOGUI_SPLASH_LEFT) || (pos == MOJOGUI_SPLASH_RIGHT))
{
splashbox = gtk_hbox_new(FALSE, 6);
gtk_widget_show(splashbox);
gtk_container_add(GTK_CONTAINER(window), splashbox);
if (pos == MOJOGUI_SPLASH_LEFT)
gtk_box_pack_start(GTK_BOX(splashbox), splash, FALSE, FALSE, 6);
else
gtk_box_pack_end(GTK_BOX(splashbox), splash, FALSE, FALSE, 6);
} // if
else if ((pos == MOJOGUI_SPLASH_TOP) || (pos == MOJOGUI_SPLASH_BOTTOM))
{
splashbox = gtk_vbox_new(FALSE, 6);
gtk_widget_show(splashbox);
gtk_container_add(GTK_CONTAINER(window), splashbox);
if (pos == MOJOGUI_SPLASH_TOP)
gtk_box_pack_start(GTK_BOX(splashbox), splash, FALSE, FALSE, 6);
else
gtk_box_pack_end(GTK_BOX(splashbox), splash, FALSE, FALSE, 6);
} // else if
} // if
if (splashbox == NULL) // no splash, use the window for the top container.
splashbox = window;
454
box = gtk_vbox_new(FALSE, 6);
455
gtk_widget_show(box);
456
gtk_container_add(GTK_CONTAINER(splashbox), box);
457
458
459
pagetitle = gtk_label_new("");
gtk_widget_show(pagetitle);
460
gtk_box_pack_start(GTK_BOX(box), pagetitle, FALSE, TRUE, 16);
461
462
463
notebook = gtk_notebook_new();
gtk_widget_show(notebook);
464
gtk_container_set_border_width(GTK_CONTAINER(notebook), 0);
465
gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0);
466
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
467
468
gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
469
widget = gtk_hbutton_box_new();
470
471
gtk_widget_show(widget);
gtk_box_pack_start(GTK_BOX(box), widget, FALSE, FALSE, 0);
472
473
474
gtk_button_box_set_layout(GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_END);
gtk_button_box_set_child_ipadding(GTK_BUTTON_BOX (widget), 6, 0);
gtk_button_box_set_spacing(GTK_BUTTON_BOX (widget), 6);
475
476
box = widget;
477
478
479
480
cancel = create_button(box, "gtk-cancel", _("Cancel"), signal_clicked);
back = create_button(box, "gtk-go-back", _("Back"), signal_clicked);
next = create_button(box, "gtk-go-forward", _("Next"), signal_clicked);
finish = create_button(box, "gtk-goto-last", _("Finish"), signal_clicked);
481
gtk_widget_hide(finish);
482
483
484
485
486
487
488
// !!! FIXME: intro page.
widget = gtk_vbox_new(FALSE, 0);
gtk_widget_show(widget);
gtk_container_add(GTK_CONTAINER(notebook), widget);
// README/EULA page.
489
widget = gtk_scrolled_window_new(NULL, NULL);
490
491
492
493
494
495
gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(widget),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_scrolled_window_set_shadow_type(
GTK_SCROLLED_WINDOW(widget),
GTK_SHADOW_IN);
496
497
498
499
500
501
502
gtk_widget_show(widget);
gtk_container_add(GTK_CONTAINER(notebook), widget);
readme = gtk_text_view_new();
gtk_widget_show(readme);
gtk_container_add(GTK_CONTAINER(widget), readme);
gtk_text_view_set_editable(GTK_TEXT_VIEW(readme), FALSE);
503
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(readme), GTK_WRAP_NONE);
504
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(readme), FALSE);
505
506
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(readme), 4);
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(readme), 4);
507
508
// !!! FIXME: options page.
509
510
511
box = gtk_vbox_new(FALSE, 0);
gtk_widget_show(box);
gtk_container_add(GTK_CONTAINER(notebook), box);
512
513
// Destination page
514
515
box = gtk_vbox_new(FALSE, 0);
gtk_widget_show(box);
516
517
hbox = gtk_hbox_new (FALSE, 6);
518
widget = gtk_label_new(_("Folder:"));
519
gtk_widget_show(widget);
520
gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
521
522
523
524
gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_CENTER);
gtk_label_set_line_wrap(GTK_LABEL(widget), FALSE);
alignment = gtk_alignment_new(0.5, 0.5, 1, 0);
destination = gtk_combo_box_entry_new_text();
525
526
gtk_signal_connect(GTK_OBJECT(destination), "changed",
GTK_SIGNAL_FUNC(signal_dest_changed), NULL);
527
gtk_container_add(GTK_CONTAINER(alignment), destination);
528
529
gtk_box_pack_start(GTK_BOX(hbox), alignment, TRUE, TRUE, 0);
browse = create_button(hbox, "gtk-open",
530
_("B_rowse..."), signal_browse_clicked);
531
532
533
534
gtk_widget_show_all (hbox);
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(notebook), box);
535
536
537
538
539
540
541
542
543
544
// Product key page
box = gtk_vbox_new(FALSE, 0);
gtk_widget_show(box);
widget = gtk_label_new(_("Please enter your product key"));
gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_CENTER);
gtk_label_set_line_wrap(GTK_LABEL(widget), TRUE);
gtk_widget_show(widget);
gtk_box_pack_start(GTK_BOX(box), widget, FALSE, TRUE, 0);
545
546
hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(hbox);
547
548
549
550
productkey = gtk_entry_new();
gtk_entry_set_editable(GTK_ENTRY(productkey), TRUE);
gtk_entry_set_visibility(GTK_ENTRY(productkey), TRUE);
gtk_widget_show(productkey);
551
552
gtk_box_pack_start(GTK_BOX(hbox), productkey, TRUE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
553
554
555
gtk_container_add(GTK_CONTAINER(notebook), box);
556
557
// Progress page
box = gtk_vbox_new(FALSE, 6);
558
559
560
561
562
563
564
565
566
567
568
569
570
571
gtk_widget_show(box);
alignment = gtk_alignment_new(0.5, 0.5, 1, 0);
gtk_widget_show(alignment);
progressbar = gtk_progress_bar_new();
gtk_widget_show(progressbar);
gtk_container_add(GTK_CONTAINER(alignment), progressbar);
gtk_box_pack_start(GTK_BOX(box), alignment, FALSE, TRUE, 0);
progresslabel = gtk_label_new("");
gtk_widget_show(progresslabel);
gtk_box_pack_start(GTK_BOX(box), progresslabel, FALSE, TRUE, 0);
gtk_label_set_justify(GTK_LABEL(progresslabel), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap(GTK_LABEL(progresslabel), FALSE);
gtk_container_add(GTK_CONTAINER(notebook), box);
572
// !!! FIXME: final page.
573
574
575
widget = gtk_vbox_new(FALSE, 0);
gtk_widget_show(widget);
gtk_container_add(GTK_CONTAINER(notebook), widget);
576
577
578
579
finallabel = gtk_label_new("");
gtk_widget_show(finallabel);
gtk_box_pack_start(GTK_BOX(widget), finallabel, FALSE, TRUE, 0);
gtk_label_set_justify(GTK_LABEL(finallabel), GTK_JUSTIFY_LEFT);
580
gtk_label_set_line_wrap(GTK_LABEL(finallabel), TRUE);
581
582
583
584
gtk_signal_connect(GTK_OBJECT(window), "delete-event",
GTK_SIGNAL_FUNC(signal_delete), NULL);
585
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
586
gtk_widget_show(window);
587
588
589
gtk_widget_grab_focus(next);
590
591
592
593
return window;
} // create_gtkwindow
594
595
static boolean MojoGui_gtkplus2_start(const char *title,
const MojoGuiSplash *splash)
596
{
597
gtkwindow = create_gtkwindow(title, splash);
598
599
600
601
602
603
604
605
606
607
608
609
return (gtkwindow != NULL);
} // MojoGui_gtkplus2_start
static void MojoGui_gtkplus2_stop(void)
{
assert(msgbox == NULL);
if (gtkwindow != NULL)
gtk_widget_destroy(gtkwindow);
gtkwindow = NULL;
pagetitle = NULL;
610
finallabel = NULL;
611
612
613
progresslabel = NULL;
progressbar = NULL;
destination = NULL;
614
productkey = NULL;
615
616
617
618
619
notebook = NULL;
readme = NULL;
cancel = NULL;
back = NULL;
next = NULL;
620
finish = NULL;
621
splash = NULL;
622
623
624
625
} // MojoGui_gtkplus2_stop
static int MojoGui_gtkplus2_readme(const char *name, const uint8 *data,
626
627
size_t datalen, boolean can_back,
boolean can_fwd)
628
629
630
{
GtkTextBuffer *textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(readme));
gtk_text_buffer_set_text(textbuf, (const gchar *) data, datalen);
631
return run_wizard(name, PAGE_README, can_back, can_fwd, true, can_fwd);
632
633
634
} // MojoGui_gtkplus2_readme
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
static void set_option_tree_sensitivity(MojoGuiSetupOptions *opts, boolean val)
{
if (opts != NULL)
{
gtk_widget_set_sensitive((GtkWidget *) opts->guiopaque, val);
set_option_tree_sensitivity(opts->next_sibling, val);
set_option_tree_sensitivity(opts->child, val && opts->value);
} // if
} // set_option_tree_sensitivity
static void signal_option_toggled(GtkToggleButton *toggle, gpointer data)
{
MojoGuiSetupOptions *opts = (MojoGuiSetupOptions *) data;
const boolean enabled = gtk_toggle_button_get_active(toggle);
opts->value = enabled;
set_option_tree_sensitivity(opts->child, enabled);
} // signal_option_toggled
static GtkWidget *new_option_level(GtkWidget *box)
{
GtkWidget *alignment = gtk_alignment_new(0.0, 0.5, 0, 0);
GtkWidget *retval = gtk_vbox_new(FALSE, 0);
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 15, 0);
gtk_widget_show(alignment);
gtk_widget_show(retval);
gtk_container_add(GTK_CONTAINER(alignment), retval);
gtk_box_pack_start(GTK_BOX(box), alignment, TRUE, TRUE, 0);
return retval;
} // new_option_level
668
669
670
671
672
673
674
675
676
677
678
679
680
681
// use this to generate a tooltip only as needed.
static GtkTooltips *get_tip(GtkTooltips **_tip)
{
if (*_tip == NULL)
{
GtkTooltips *tip = gtk_tooltips_new();
gtk_tooltips_enable(tip);
*_tip = tip;
} // if
return *_tip;
} // get_tip
682
683
684
685
686
static void build_options(MojoGuiSetupOptions *opts, GtkWidget *box,
gboolean sensitive)
{
if (opts != NULL)
{
687
688
GtkTooltips *tip = NULL;
GtkWidget *widget = NULL;
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
if (opts->is_group_parent)
{
MojoGuiSetupOptions *kids = opts->child;
GtkWidget *childbox = NULL;
GtkWidget *alignment = gtk_alignment_new(0.0, 0.5, 0, 0);
gtk_widget_show(alignment);
widget = gtk_label_new(opts->description);
opts->guiopaque = widget;
gtk_widget_set_sensitive(widget, sensitive);
gtk_widget_show(widget);
gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap(GTK_LABEL(widget), FALSE);
gtk_container_add(GTK_CONTAINER(alignment), widget);
gtk_box_pack_start(GTK_BOX(box), alignment, FALSE, TRUE, 0);
705
706
707
if (opts->tooltip != NULL)
gtk_tooltips_set_tip(get_tip(&tip), widget, opts->tooltip, 0);
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
widget = NULL;
childbox = new_option_level(box);
while (kids)
{
widget = gtk_radio_button_new_with_label_from_widget(
GTK_RADIO_BUTTON(widget),
kids->description);
kids->guiopaque = widget;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
kids->value);
gtk_widget_set_sensitive(widget, sensitive);
gtk_widget_show(widget);
gtk_box_pack_start(GTK_BOX(childbox), widget, FALSE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT(widget), "toggled",
GTK_SIGNAL_FUNC(signal_option_toggled), kids);
723
724
725
726
if (kids->tooltip != NULL)
gtk_tooltips_set_tip(get_tip(&tip),widget,kids->tooltip,0);
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
if (kids->child != NULL)
{
build_options(kids->child, new_option_level(childbox),
sensitive);
} // if
kids = kids->next_sibling;
} // while
} // if
else
{
widget = gtk_check_button_new_with_label(opts->description);
opts->guiopaque = widget;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
opts->value);
gtk_widget_set_sensitive(widget, sensitive);
gtk_widget_show(widget);
gtk_box_pack_start(GTK_BOX(box), widget, FALSE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT(widget), "toggled",
GTK_SIGNAL_FUNC(signal_option_toggled), opts);
747
748
if (opts->tooltip != NULL)
749
gtk_tooltips_set_tip(get_tip(&tip), widget, opts->tooltip, 0);
750
751
752
753
754
755
756
757
758
759
760
761
762
if (opts->child != NULL)
{
build_options(opts->child, new_option_level(box),
((sensitive) && (opts->value)) );
} // if
} // else
build_options(opts->next_sibling, box, sensitive);
} // if
} // build_options
763
static int MojoGui_gtkplus2_options(MojoGuiSetupOptions *opts,
764
boolean can_back, boolean can_fwd)
765
{
766
767
768
769
770
771
772
773
774
775
int retval;
GtkWidget *box;
GtkWidget *page; // this is a vbox.
page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), PAGE_OPTIONS);
box = gtk_vbox_new(FALSE, 0);
gtk_widget_show(box);
gtk_box_pack_start(GTK_BOX(page), box, FALSE, FALSE, 0);
build_options(opts, box, TRUE);
776
777
retval = run_wizard(_("Options"), PAGE_OPTIONS,
can_back, can_fwd, true, can_fwd);
778
779
gtk_widget_destroy(box);
return retval;
780
781
782
} // MojoGui_gtkplus2_options
783
784
785
static char *MojoGui_gtkplus2_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
786
{
787
GtkComboBox *combo = GTK_COMBO_BOX(destination);
788
const boolean fwd_at_start = ( (recnum > 0) && (*(recommends[0])) );
789
790
791
792
793
gchar *str = NULL;
char *retval = NULL;
int i;
for (i = 0; i < recnum; i++)
794
gtk_combo_box_append_text(combo, recommends[i]);
795
gtk_combo_box_set_active (combo, 0);
796
797
798
*command = run_wizard(_("Destination"), PAGE_DEST,
can_back, can_fwd, true, fwd_at_start);
799
800
str = gtk_combo_box_get_active_text(combo);
801
802
803
804
// shouldn't ever be empty ("next" should be disabled in that case).
assert( (*command <= 0) || ((str != NULL) && (*str != '\0')) );
805
retval = xstrdup(str);
806
g_free(str);
807
808
809
810
811
for (i = recnum-1; i >= 0; i--)
gtk_combo_box_remove_text(combo, i);
return retval;
812
813
814
} // MojoGui_gtkplus2_destination
815
816
817
static int MojoGui_gtkplus2_productkey(const char *desc, const char *fmt,
char *buf, const int buflen,
boolean can_back, boolean can_fwd)
818
819
820
{
gchar *str = NULL;
int retval = 0;
821
const boolean fwd_at_start = isValidProductKey(fmt, buf);
822
823
824
825
826
827
828
gtk_entry_set_max_length(GTK_ENTRY(productkey), buflen - 1);
gtk_entry_set_width_chars(GTK_ENTRY(productkey), buflen - 1);
gtk_entry_set_text(GTK_ENTRY(productkey), (gchar *) buf);
const guint connid = gtk_signal_connect(GTK_OBJECT(productkey), "changed",
GTK_SIGNAL_FUNC(signal_productkey_changed),
829
(void *) fmt);
830
831
retval = run_wizard(desc, PAGE_PRODUCTKEY,
can_back, can_fwd, true, fwd_at_start);
832
833
834
835
gtk_signal_disconnect(GTK_OBJECT(productkey), connid);
str = gtk_editable_get_chars(GTK_EDITABLE(productkey), 0, -1);
// should never be invalid ("next" should be disabled in that case).
836
assert( (retval <= 0) || ((str) && (isValidProductKey(fmt, str))) );
837
838
839
840
841
842
assert(strlen(str) < buflen);
strcpy(buf, (char *) str);
g_free(str);
gtk_entry_set_text(GTK_ENTRY(productkey), "");
return retval;
843
} // MojoGui_gtkplus2_productkey
844
845
846
847
static boolean MojoGui_gtkplus2_insertmedia(const char *medianame)
{
848
gint rc = 0;
849
// !!! FIXME: Use stock GTK icon for "media"?
850
851
852
// !!! FIXME: improve the title and text wording?
const char *text = format(_("Please insert '%0'"), medianame);
rc = do_msgbox(_("Media change"), text, GTK_MESSAGE_WARNING,
853
GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, NULL);
854
free((void *) text);
855
856
857
858
return (rc == GTK_RESPONSE_OK);
} // MojoGui_gtkplus2_insertmedia
859
860
861
862
863
864
static void MojoGui_gtkplus2_progressitem(void)
{
// no-op in this UI target.
} // MojoGui_gtkplus2_progressitem
865
static boolean MojoGui_gtkplus2_progress(const char *type, const char *component,
866
867
int percent, const char *item,
boolean can_cancel)
868
{
869
static uint32 lastTicks = 0;
870
const uint32 ticks = ticks();
871
872
int rc;
873
874
875
876
GtkProgressBar *progress = GTK_PROGRESS_BAR(progressbar);
const char *ptext = gtk_progress_bar_get_text(progress);
// only update once in a while or if the component changed...
if ((ticks - lastTicks) > 200 || ptext == NULL || strcmp(ptext, component) != 0)
877
878
879
880
881
882
{
if (percent < 0)
gtk_progress_bar_pulse(progress);
else
gtk_progress_bar_set_fraction(progress, ((gdouble) percent) / 100.0);
883
gtk_progress_bar_set_text(progress, component);
884
885
886
887
gtk_label_set_text(GTK_LABEL(progresslabel), item);
lastTicks = ticks;
} // if
888
prepare_wizard(type, PAGE_PROGRESS, false, false, can_cancel, false);
889
890
891
rc = pump_events();
assert( (rc == ((int) CLICK_CANCEL)) || (rc == ((int) CLICK_NONE)) );
return (rc != CLICK_CANCEL);
892
893
} // MojoGui_gtkplus2_progress
894
895
896
897
898
899
900
901
static void MojoGui_gtkplus2_pump(void)
{
while (gtk_events_pending())
gtk_main_iteration();
} // MojoGui_gtkplus2_pump
902
903
904
905
906
static void MojoGui_gtkplus2_final(const char *msg)
{
gtk_widget_hide(next);
gtk_widget_show(finish);
gtk_label_set_text(GTK_LABEL(finallabel), msg);
907
run_wizard(_("Finish"), PAGE_FINAL, false, true, false, true);
908
909
} // MojoGui_gtkplus2_final
910
// end of gui_gtkplus2.c ...