-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gtk_ui.c
2282 lines (1966 loc) · 72.5 KB
/
gtk_ui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
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
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* GTK-based UI
$Id: gtk_ui.c,v 1.130 2007-01-30 00:06:19 megastep Exp $
*/
/* Modifications by Borland/Inprise Corp.
04/11/2000: Added check in check_install_button to see if install and
binary path are the same. If so, leave install button
disabled and give user a message.
04/17/2000: Created two new GladeXML objects, one for the readme dialog,
the other for the license dialog and modified gtkui_init,
setup_button_view_readme_slot and gtkui_license to create &
use these new objects. Created 2 new handlers for destroy
events on the readme and license dialogs. This was done to fix
problems when the user uses the 'X' button in the upper
right corner instead of the Close, Cancel or Agree buttons.
For the readme, setup would seg fault if the user tried to open
the readme dialog a second time. For the license, setup would
stop responding.
The setup.glade file was modified to include destroy
handlers for the readme_dialog and license_dialog widgets.
Added code to gtkui_complete to clean up the GladeXML objects.
04/21/2000: Cleaned up a bit too much, too soon in gtkui_complete.
Removed the gtk_object_unref for setup_glade because it's
still in use by the Play Now button if uid is root...
04/28/2000: More cleanup problems. Can't unref the gtk objects in
gtkui_complete...too much is still in use. Maybe make a cleanup
routine that gets called by the exit and play button handlers.
Added code to disable the View Readme button (all 3 of them)
when it is clicked. That way, the user can have only 1 instance
of the readme dialog. Multiple instances was causing a problem
for the destroy routine. Destroying the latest instance
worked OK. Destroying the others caused a seg fault. Readme
buttons are re-enabled when the dialog is closed.
Cleaned up close_view_readme_slot to avoid the duplication with
destroy_view_readme. close now just calls destroy.
05/12/2000: Changed the way the focus mechanism works for the install path
and binary path fields and how the Begin Install button gets
enabled/disabled. There were ways in which an invalid path
could be selected from the combo boxes and the Begin Install
button would not be disabled until the user clicked on it. Then,
the mouse focus was on an insensitive item, making it appear
that the UI locked up. Here's the changes:
Modified gtkui_init to add signal handlers for the keypress and
mouse button release events for both the install path and binary
path fields. Also added these functions to handle the signals:
path_entry_keypress_slot, path_combo_change_slot,
binary_path_entry_keypress_slot, binary_path_combo_change_slot.
The "keypress" slots evaluate the status of the Begin Install
button after every keystroke when the user is typing a pathname.
The "combo_change" slots evaluate the status of the button when-
ever the user makes a selection from the drop-down list.
Modified setup.glade to remove the signal handlers that grabbed
the focus when the mouse was passed over these fields.
Modified gtkui_prompt to add a RESPONSE_OK option and modifed
the yesno_answer structure to support this. This will display
a dialog with a message and a single OK button. This was a
result of one of the (many) failed attempts to fix the focus
issue. It turns out that I don't use this anywhere anymore, but
I figured I'd leave it for someone who wants to display a
simple message without using the gnome libs. To use it, just
pass RESPONSE_OK as the last parameter.
05/17/2000: Modified gtkui_init to disable the install path or binary path
widgets if the value was passed in as a command-line parameter
(see main.c for the new -i and -b options).
06/02/2000: Modified gtkui_update to make sure the progress bar object is
never sent an invalid value. If the <option size="xx"> value is
not set correctly, then the calculated new_update value could
sometimes be greater than 1. This generated lots of gtk error
messages on the console. Added an if/else statement to make
sure the calculated value never exceeds 1.
*/
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <ctype.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#include "install.h"
#include "install_ui.h"
#include "install_log.h"
#include "detect.h"
#include "file.h"
#include "copy.h"
#include "bools.h"
#include "loki_launchurl.h"
#if defined(ENABLE_GTK2)
#define SETUP_GLADE SETUP_BASE "setup.gtk2.glade"
#else
#define SETUP_GLADE SETUP_BASE "setup.glade"
#endif
#define LICENSE_FONT \
"-misc-fixed-medium-r-semicondensed-*-*-120-*-*-c-*-iso8859-8"
#define MAX_TEXTLEN 40 /* The maximum length of current filename */
/* Globals */
static char *default_install_paths[] = {
"/usr/local/games",
"/opt/games",
"/usr/games",
NULL
};
/* Use an arbitrary maximum; the lack of
flexibility shouldn't be an issue */
#define MAX_INSTALL_PATHS 26
static char *install_paths[MAX_INSTALL_PATHS];
/* Various warning dialogs */
static enum {
WARNING_NONE,
WARNING_ROOT
} warning_dialog;
typedef enum
{
CLASS_PAGE,
OPTION_PAGE,
COPY_PAGE,
DONE_PAGE,
ABORT_PAGE,
WARNING_PAGE,
WEBSITE_PAGE,
CDKEY_PAGE
} InstallPages;
static GladeXML *setup_glade = NULL;
static GladeXML *setup_glade_readme = NULL;
static GladeXML *setup_glade_license = NULL;
static int cur_state;
static install_info *cur_info;
static int diskspace;
static int license_okay = 0;
static gboolean in_setup = TRUE;
static GSList *radio_list = NULL; /* Group for the radio buttons */
static const char* glade_file = SETUP_GLADE;
/******** Local prototypes **********/
static const char *check_for_installation(install_info *info, char** explanation);
static void check_install_button(void);
static void update_space(void);
static void update_size(void);
void setup_destroy_view_readme_slot(GtkWidget*, gpointer);
static yesno_answer gtkui_prompt(const char*, yesno_answer);
static void gtkui_abort(install_info *info);
static int iterate_for_state(void)
{
int start = cur_state;
while(cur_state == start) {
if ( !gtk_main_iteration() )
break;
}
/* fprintf(stderr,"New state: %d\n", cur_state); */
return cur_state;
}
/*********** GTK slots *************/
/*void setup_entry_gainfocus( GtkWidget* widget, gpointer func_data )
{
gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(widget)), widget);
}
void setup_entry_givefocus( GtkWidget* widget, gpointer func_data )
{
gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(widget)), NULL);
}*/
gint path_entry_keypress_slot(GtkWidget *widget, GdkEvent *event,
gpointer data)
{
const char* string;
string = gtk_entry_get_text( GTK_ENTRY(widget) );
if ( string ) {
set_installpath(cur_info, string, 0);
if ( strcmp(string, cur_info->install_path) != 0 ) {
gtk_entry_set_text(GTK_ENTRY(widget), cur_info->install_path);
}
update_space();
}
return FALSE;
}
gint path_combo_change_slot(GtkWidget *widget, GdkEvent *event,
gpointer data)
{
const char* string;
GtkWidget *install_entry;
install_entry = glade_xml_get_widget(setup_glade, "install_entry");
string = gtk_entry_get_text( GTK_ENTRY(install_entry) );
if ( string ) {
set_installpath(cur_info, string, 1);
if ( strcmp(string, cur_info->install_path) != 0 ) {
gtk_entry_set_text(GTK_ENTRY(install_entry), cur_info->install_path);
}
update_space();
}
return(FALSE);
}
gboolean setup_entry_installpath_slot( GtkWidget* widget, GdkEventFocus *event, gpointer func_data )
{
const char* string;
string = gtk_entry_get_text( GTK_ENTRY(widget) );
if ( string ) {
set_installpath(cur_info, string, 1);
if ( strcmp(string, cur_info->install_path) != 0 ) {
gtk_entry_set_text(GTK_ENTRY(widget), cur_info->install_path);
}
update_space();
}
return FALSE;
}
gint binary_path_entry_keypress_slot(GtkWidget *widget, GdkEvent *event,
gpointer data)
{
const char* string;
string = gtk_entry_get_text( GTK_ENTRY(widget) );
if ( string ) {
set_symlinkspath(cur_info, string);
if ( strcmp(string, cur_info->symlinks_path) != 0 ) {
gtk_entry_set_text(GTK_ENTRY(widget), cur_info->symlinks_path);
}
check_install_button();
}
return FALSE;
}
gint binary_path_combo_change_slot(GtkWidget *widget, GdkEvent *event,
gpointer data)
{
const char* string;
GtkWidget *binary_entry;
binary_entry = glade_xml_get_widget(setup_glade, "binary_entry");
string = gtk_entry_get_text( GTK_ENTRY(binary_entry) );
if ( string ) {
set_symlinkspath(cur_info, string);
if ( strcmp(string, cur_info->symlinks_path) != 0 ) {
gtk_entry_set_text(GTK_ENTRY(widget), cur_info->symlinks_path);
}
check_install_button();
}
return(FALSE);
}
gboolean setup_entry_binarypath_slot( GtkWidget* widget, GdkEventFocus *event, gpointer func_data )
{
const char* string;
string = gtk_entry_get_text( GTK_ENTRY(widget) );
if ( string ) {
set_symlinkspath(cur_info, string);
if ( strcmp(string, cur_info->symlinks_path) != 0 ) {
gtk_entry_set_text(GTK_ENTRY(widget), cur_info->symlinks_path);
}
check_install_button();
}
return FALSE;
}
#if defined(ENABLE_GTK2)
/* Computes a nice size for a dialog box */
static int get_nice_width(GtkWidget *widget, int maxlen)
{
PangoContext *pc;
PangoFontDescription *fd;
PangoLanguage *pl;
PangoFontMetrics *fm;
int approx_width;
pc = gtk_widget_get_pango_context(widget);
fd = pango_context_get_font_description(pc);
pl = pango_context_get_language(pc);
fm = pango_context_get_metrics(pc, fd, pl);
approx_width = pango_font_metrics_get_approximate_char_width(fm);
if (maxlen > 100)
maxlen = 100;
return((maxlen * approx_width) / PANGO_SCALE);
}
/*
Returns 0 if fails.
*/
static gboolean load_file_gtk2( GtkTextView *widget, const char *file )
{
FILE *fp;
int pos;
GtkTextBuffer *buffer;
GtkTextIter start, end;
int nice_width = 0;
int maxlen = 0;
GtkWidget *toplevel;
buffer = gtk_text_view_get_buffer (widget);
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_get_end_iter(buffer, &end);
gtk_text_buffer_delete(buffer, &start, &end);
fp = fopen(file, "r");
if ( fp ) {
char line[BUFSIZ];
pos = 0;
while ( fgets(line, BUFSIZ-1, fp) ) {
gtk_text_buffer_insert_at_cursor (buffer, line, strlen(line));
if (strlen(line) > maxlen)
maxlen = strlen(line);
}
fclose(fp);
}
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_place_cursor(buffer, &start);
nice_width = get_nice_width(GTK_WIDGET(widget), maxlen);
if (nice_width / 5 < 75)
nice_width += 75;
else
nice_width += (nice_width / 5);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET(widget));
if (GTK_WIDGET_TOPLEVEL (toplevel))
gtk_window_set_default_size(GTK_WINDOW(toplevel), nice_width, (nice_width * 3) / 4);
return (fp != NULL);
}
#else /* ! ENABLE_GTK2 */
/*
Returns 0 if fails.
*/
static gboolean load_file_gtk1( GtkText *widget, GdkFont *font, const char *file )
{
FILE *fp;
int pos;
gtk_editable_delete_text(GTK_EDITABLE(widget), 0, -1);
fp = fopen(file, "r");
if ( fp ) {
char line[BUFSIZ];
pos = 0;
while ( fgets(line, BUFSIZ-1, fp) ) {
gtk_text_insert(widget, font, NULL, NULL, line, strlen(line));
}
fclose(fp);
}
gtk_editable_set_position(GTK_EDITABLE(widget), 0);
return (fp != NULL);
}
#endif
void on_class_continue_clicked( GtkWidget *w, gpointer data )
{
GtkWidget *widget = glade_xml_get_widget(setup_glade, "recommended_but");
if ( cur_state != SETUP_CLASS ) {
return;
}
express_setup = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
if ( express_setup ) {
const char *msg = check_for_installation(cur_info, NULL);
if ( msg ) {
char buf[BUFSIZ];
snprintf(buf, sizeof(buf),
_("Installation could not proceed due to the following error:\n%s\nTry to use 'Expert' installation."),
msg);
gtkui_prompt(buf, RESPONSE_OK);
widget = glade_xml_get_widget(setup_glade, "expert_but");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
return;
}
}
/* Install desktop menu items */
if((!GetProductHasNoBinaries(cur_info)) && (GetProductInstallMenuItems(cur_info))) {
cur_info->options.install_menuitems = 1;
}
widget = glade_xml_get_widget(setup_glade, "setup_notebook");
gtk_notebook_set_page(GTK_NOTEBOOK(widget), OPTION_PAGE);
cur_state = SETUP_OPTIONS;
}
void setup_close_view_readme_slot( GtkWidget* w, gpointer data )
{
setup_destroy_view_readme_slot(w, data);
}
void setup_destroy_view_readme_slot( GtkWidget* w, gpointer data )
{
GtkWidget *widget;
if ( setup_glade_readme ) {
widget = glade_xml_get_widget(setup_glade_readme, "readme_dialog");
if (widget)
gtk_widget_hide(widget);
GLADE_XML_UNREF(setup_glade_readme);
setup_glade_readme = NULL;
/*
* re-enable the 'view readme buttons...all 3 of them since we don't
* know where we are
*/
widget = glade_xml_get_widget(setup_glade, "button_readme");
gtk_widget_set_sensitive(widget, TRUE);
widget = glade_xml_get_widget(setup_glade, "class_readme");
gtk_widget_set_sensitive(widget, TRUE);
widget = glade_xml_get_widget(setup_glade, "view_readme_progress_button");
gtk_widget_set_sensitive(widget, TRUE);
widget = glade_xml_get_widget(setup_glade, "view_readme_end_button");
gtk_widget_set_sensitive(widget, TRUE);
}
}
void setup_button_view_readme_slot( GtkWidget* w, gpointer data )
{
GtkWidget *readme;
GtkWidget *widget;
const char *file;
setup_glade_readme = GLADE_XML_NEW(glade_file, "readme_dialog");
glade_xml_signal_autoconnect(setup_glade_readme);
readme = glade_xml_get_widget(setup_glade_readme, "readme_dialog");
widget = glade_xml_get_widget(setup_glade_readme, "readme_area");
file = GetProductREADME(cur_info, NULL);
if ( file && readme && widget ) {
gtk_widget_hide(readme);
#if defined(ENABLE_GTK2)
load_file_gtk2(GTK_TEXT_VIEW(widget), file);
#else
load_file_gtk1(GTK_TEXT(widget), NULL, file);
#endif
gtk_widget_show(readme);
/* there are 3 'view readme' buttons...disable all of them */
widget = glade_xml_get_widget(setup_glade, "button_readme");
gtk_widget_set_sensitive(widget, FALSE);
widget = glade_xml_get_widget(setup_glade, "class_readme");
gtk_widget_set_sensitive(widget, FALSE);
widget = glade_xml_get_widget(setup_glade, "view_readme_progress_button");
gtk_widget_set_sensitive(widget, FALSE);
widget = glade_xml_get_widget(setup_glade, "view_readme_end_button");
gtk_widget_set_sensitive(widget, FALSE);
}
}
void setup_button_license_agree_slot( GtkWidget* widget, gpointer func_data )
{
GtkWidget *license;
license = glade_xml_get_widget(setup_glade_license, "license_dialog");
gtk_widget_hide(license);
license_okay = 1;
check_install_button();
cur_state = SETUP_README;
}
void setup_destroy_license_slot( GtkWidget* w, gpointer data )
{
/* !!! FIXME: this gets called more than once if LANG is set...not sure
* !!! FIXME: why, but we explicitly set setup_glade_license to NULL
* !!! FIXME: here so we don't touch an unref'd var.
*/
if (setup_glade_license) {
GtkWidget *widget;
widget = glade_xml_get_widget(setup_glade_license, "license_dialog");
gtk_widget_hide(widget);
cur_state = SETUP_EXIT;
GLADE_XML_UNREF(setup_glade_license);
setup_glade_license = NULL;
}
}
void setup_button_warning_continue_slot( GtkWidget* widget, gpointer func_data )
{
switch (warning_dialog) {
case WARNING_NONE:
break;
case WARNING_ROOT:
cur_state = SETUP_PLAY;
break;
}
warning_dialog = WARNING_NONE;
}
void setup_button_warning_cancel_slot( GtkWidget* widget, gpointer func_data )
{
switch (warning_dialog) {
case WARNING_NONE:
break;
case WARNING_ROOT:
cur_state = SETUP_EXIT;
break;
}
warning_dialog = WARNING_NONE;
}
void setup_button_complete_slot( GtkWidget* _widget, gpointer func_data )
{
cur_state = SETUP_COMPLETE;
}
void setup_button_play_slot( GtkWidget* _widget, gpointer func_data )
{
/* Enable this only if the application actually does that */
#if 0
if ( getuid() == 0 ) {
GtkWidget *widget;
const char *warning_text =
_("If you run this as root, the preferences will be stored in\n"
"root's home directory instead of your user account directory.");
warning_dialog = WARNING_ROOT;
widget = glade_xml_get_widget(setup_glade, "setup_notebook");
gtk_notebook_set_page(GTK_NOTEBOOK(widget), WARNING_PAGE);
widget = glade_xml_get_widget(setup_glade, "warning_label");
gtk_label_set_text(GTK_LABEL(widget), warning_text);
} else
#endif
cur_state = SETUP_PLAY;
}
void setup_button_exit_slot( GtkWidget* widget, gpointer func_data )
{
cur_state = SETUP_EXIT;
}
void setup_button_abort_slot( GtkWidget* widget, gpointer func_data )
{
/* Make sure that the state will be different so that we can iterate */
cur_state = (cur_state == SETUP_ABORT) ? SETUP_EXIT : SETUP_ABORT;
}
void setup_button_cancel_slot( GtkWidget* widget, gpointer func_data )
{
switch(cur_state) {
case SETUP_COMPLETE:
case SETUP_OPTIONS:
case SETUP_ABORT:
case SETUP_EXIT:
cur_state = SETUP_EXIT;
break;
default:
if ( gtkui_prompt(_("Are you sure you want to abort\nthis installation?"), RESPONSE_NO) == RESPONSE_YES ) {
cur_state = SETUP_ABORT;
abort_install();
}
break;
}
}
static void message_dialog(const char *txt, const char *title);
/* hacked in cdkey support. --ryan. */
extern char gCDKeyString[128];
void setup_cdkey_entry_changed_slot(GtkEntry *entry, gpointer user_data)
{
const gchar *CDKey = gtk_entry_get_text( GTK_ENTRY(entry) );
GtkWidget *button;
button = glade_xml_get_widget(setup_glade, "setup_button_cdkey_continue");
gtk_widget_set_sensitive(button, (*CDKey) ? TRUE : FALSE);
}
void setup_button_cdkey_continue_slot( GtkWidget* widget, gpointer func_data )
{
/* HACK: Use external cd key validation program, if it exists. --ryan. */
#define CDKEYCHECK_PROGRAM "./vcdk"
char cmd[sizeof (gCDKeyString) + sizeof (CDKEYCHECK_PROGRAM) + 64];
GtkWidget *entry = glade_xml_get_widget(setup_glade, "setup_cdkey_entry");
char *CDKey = (char *) gtk_entry_get_text( GTK_ENTRY(entry) );
char *p;
snprintf(cmd, sizeof (cmd), "%s-%s", CDKEYCHECK_PROGRAM, cur_info->arch);
if (access(cmd, X_OK) != 0)
{
message_dialog(_("ERROR: vcdk is missing. Installation aborted.\n"), _("Problem"));
cur_state = SETUP_ABORT;
return;
}
else
{
snprintf(cmd, sizeof (cmd), "%s-%s %s", CDKEYCHECK_PROGRAM, cur_info->arch, CDKey);
if (system(cmd) == 0) /* binary ran and reported key invalid? */
{
message_dialog(_("CD key is invalid!\nPlease double check your key and enter it again."), _("Problem"));
return;
}
}
strncpy(gCDKeyString, CDKey, sizeof (gCDKeyString));
gCDKeyString[sizeof (gCDKeyString) - 1] = '\0';
p = gCDKeyString;
while(*p)
{
*p = toupper(*p);
p++;
}
cur_state = SETUP_INSTALL;
}
void setup_button_install_slot( GtkWidget* widget, gpointer func_data )
{
const char* message;
char* explanation = NULL;
GtkWidget *notebook;
notebook = glade_xml_get_widget(setup_glade, "setup_notebook");
message = check_for_installation(cur_info, &explanation);
if(message)
{
if(explanation)
{
char* tmp = g_strconcat(message, "\n\n", explanation, NULL);
g_free(explanation);
explanation = tmp;
}
gtkui_prompt(explanation?explanation:message, RESPONSE_OK);
g_free(explanation);
return;
}
/* If CDKEY attribute was specified, show the CDKEY screen */
if(GetProductCDKey(cur_info))
{
GtkWidget *button = glade_xml_get_widget(setup_glade, "setup_button_cdkey_continue");
GtkWidget *entry = glade_xml_get_widget(setup_glade, "setup_cdkey_entry");
gtk_notebook_set_page(GTK_NOTEBOOK(notebook), CDKEY_PAGE);
gtk_entry_set_text(GTK_ENTRY(entry), "");
gtk_widget_set_sensitive(button, FALSE);
cur_state = SETUP_CDKEY;
iterate_for_state();
if (cur_state != SETUP_INSTALL)
return;
}
gtk_notebook_set_page(GTK_NOTEBOOK(notebook), COPY_PAGE);
cur_state = SETUP_INSTALL;
}
void setup_button_browser_slot( GtkWidget* widget, gpointer func_data )
{
/* Don't let the user accidentally double-launch the browser */
gtk_widget_set_sensitive(widget, FALSE);
launch_browser(cur_info, loki_launchURL);
}
/* Returns NULL if installation can be performed */
static const char *check_for_installation(install_info *info, char** explanation)
{
if ( ! license_okay ) {
return _("Please respond to the license dialog");
}
return IsReadyToInstall_explain(info, explanation);
}
/* Checks if we can enable the "Begin install" button */
static void check_install_button(void)
{
const char *message;
GtkWidget *options_status;
GtkWidget *install_widget;
message = check_for_installation(cur_info, NULL);
/* Get the appropriate widgets and set the new state */
options_status = glade_xml_get_widget(setup_glade, "options_status");
install_widget = glade_xml_get_widget(setup_glade, "button_install");
if ( !message ) {
message = _("Ready to install!");
gtk_widget_set_sensitive(install_widget, TRUE);
}
else
gtk_widget_set_sensitive(install_widget, FALSE);
gtk_label_set_text(GTK_LABEL(options_status), message);
}
static void update_size(void)
{
GtkWidget *widget;
char text[32];
widget = glade_xml_get_widget(setup_glade, "label_install_size");
if ( widget ) {
snprintf(text, sizeof(text), _("%d MB"), (int) BYTES2MB(cur_info->install_size));
gtk_label_set_text(GTK_LABEL(widget), text);
check_install_button();
}
}
static void update_space(void)
{
GtkWidget *widget;
char text[32];
widget = glade_xml_get_widget(setup_glade, "label_free_space");
if ( widget ) {
diskspace = detect_diskspace(cur_info->install_path);
snprintf(text, sizeof(text), _("%d MB"), diskspace);
gtk_label_set_text(GTK_LABEL(widget), text);
check_install_button();
}
}
static void empty_container(GtkWidget *widget, gpointer data)
{
gtk_container_remove(GTK_CONTAINER(data), widget);
}
static void enable_tree(xmlNodePtr node, GtkWidget *window)
{
if ( strcmp((char *)node->name, "option") == 0 ) {
GtkWidget *button = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(window),
get_option_name(cur_info, node, NULL, 0));
if(button)
gtk_widget_set_sensitive(button, TRUE);
}
node = XML_CHILDREN(node);
while ( node ) {
enable_tree(node, window);
node = node->next;
}
}
gboolean on_manpage_entry_focus_out_event(GtkWidget *widget,
GdkEventFocus *event,
gpointer user_data)
{
const char* string;
string = gtk_entry_get_text( GTK_ENTRY(widget) );
if ( string ) {
set_manpath(cur_info, string);
if ( strcmp(string, cur_info->man_path) != 0 ) {
gtk_entry_set_text(GTK_ENTRY(widget), cur_info->man_path);
}
}
return FALSE;
}
/*-----------------------------------------------------------------------------
** on_use_binary_toggled
** Signal function to repsond to a toggle state in the
** 'Use symbolic link' checkbox.
**---------------------------------------------------------------------------*/
void on_use_binary_toggled ( GtkWidget* widget, gpointer func_data)
{
GtkWidget *binary_path_widget;
GtkWidget *binary_label_widget;
GtkWidget *binary_entry;
const char *string;
/*-------------------------------------------------------------------------
** Pick up widget handles
**-----------------------------------------------------------------------*/
binary_path_widget = glade_xml_get_widget(setup_glade, "binary_path");
binary_label_widget = glade_xml_get_widget(setup_glade, "binary_label");
/*-------------------------------------------------------------------------
** Mark the appropriate widgets active or inactive
**-----------------------------------------------------------------------*/
gtk_widget_set_sensitive(binary_path_widget, GTK_TOGGLE_BUTTON(widget)->active);
gtk_widget_set_sensitive(binary_label_widget, GTK_TOGGLE_BUTTON(widget)->active);
/*-------------------------------------------------------------------------
** Finally, set the symlinks_path. If we've made it active
** again, we have to go get the current binary entry box
** value and restash it into the global symlinkspath.
**-----------------------------------------------------------------------*/
if (GTK_TOGGLE_BUTTON(widget)->active) {
binary_entry = glade_xml_get_widget(setup_glade, "binary_entry");
string = gtk_entry_get_text( GTK_ENTRY(binary_entry) );
} else {
string = NULL;
}
set_symlinkspath(cur_info, string ? string : "");
check_install_button();
}
void setup_checkbox_option_slot( GtkWidget* widget, gpointer func_data)
{
GtkWidget *window;
xmlNodePtr node, data_node = (xmlNodePtr) func_data; //gtk_object_get_data(GTK_OBJECT(widget),"data");
if(!data_node)
return;
window = glade_xml_get_widget(setup_glade, "setup_window");
if ( GTK_TOGGLE_BUTTON(widget)->active ) {
const char *warn = get_option_warn(cur_info, data_node);
/* does this option require a seperate EULA? */
xmlNodePtr child;
child = XML_CHILDREN(data_node);
while(child)
{
if (!strcmp((char *)child->name, "eula"))
{
/* this option has some EULA nodes
* we need to prompt before this change can be validated / turned on
*/
const char* name = GetProductEULANode(cur_info, data_node, NULL);
if (name)
{
GtkWidget *license;
GtkWidget *license_widget;
if (!setup_glade_license)
setup_glade_license = GLADE_XML_NEW(glade_file, "license_dialog");
glade_xml_signal_autoconnect(setup_glade_license);
license = glade_xml_get_widget(setup_glade_license, "license_dialog");
license_widget = glade_xml_get_widget(setup_glade_license, "license_area");
if ( license && license_widget ) {
install_state start;
#if ! defined(ENABLE_GTK2)
GdkFont *font;
#endif
gtk_widget_hide(license);
#if defined(ENABLE_GTK2)
load_file_gtk2(GTK_TEXT_VIEW(license_widget), name);
#else
font = gdk_font_load(LICENSE_FONT);
load_file_gtk1(GTK_TEXT(license_widget), font, name);
#endif
gtk_widget_show(license);
gtk_window_set_modal(GTK_WINDOW(license), TRUE);
start = cur_state; /* happy hacking */
license_okay = 0;
iterate_for_state();
cur_state = start;
gtk_widget_hide(license);
if (!license_okay)
{
/* the user doesn't accept the option EULA, leave this option disabled */
license_okay = 1; /* put things back in order regarding the product EULA */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
return;
}
license_okay = 1;
break;
}
}
else
{
log_warning("option-specific EULA not found, can't set option on\n");
/* EULA not found or not accepted */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
return;
}
}
child = child->next;
}
if ( warn && !in_setup ) { /* Display a warning message to the user */
gtkui_prompt(warn, RESPONSE_OK);
}
/* Mark this option for installation */
mark_option(cur_info, data_node, "true", 0);
/* Recurse down any other options to re-enable grayed out options */
node = XML_CHILDREN(data_node);
while ( node ) {
enable_tree(node, window);
node = node->next;
}
} else {
/* Unmark this option for installation */
mark_option(cur_info, data_node, "false", 1);
/* Recurse down any other options */
node = XML_CHILDREN(data_node);
while ( node ) {
if ( !strcmp((char *)node->name, "option") ) {
GtkWidget *button;
button = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(window),
get_option_name(cur_info, node, NULL, 0));
if(button){ /* This recursively calls this function */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
gtk_widget_set_sensitive(button, FALSE);
}
} else if ( !strcmp((char *)node->name, "exclusive") ) {
xmlNodePtr child;
for ( child = XML_CHILDREN(node); child; child = child->next) {
GtkWidget *button;
button = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(window),
get_option_name(cur_info, child, NULL, 0));
if(button){ /* This recursively calls this function */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
gtk_widget_set_sensitive(button, FALSE);
}
}
}
node = node->next;
}
}
cur_info->install_size = size_tree(cur_info, XML_CHILDREN(XML_ROOT(cur_info->config)));
update_size();
}
void setup_checkbox_menuitems_slot( GtkWidget* widget, gpointer func_data)
{
cur_info->options.install_menuitems = (GTK_TOGGLE_BUTTON(widget)->active != 0);
}
#ifndef ENABLE_GTK2
static yesno_answer prompt_response;
static void prompt_button_slot( GtkWidget* widget, gpointer func_data)
{
prompt_response = RESPONSE_YES;
}
static void prompt_yesbutton_slot( GtkWidget* widget, gpointer func_data)
{
prompt_response = RESPONSE_YES;
}
static void prompt_nobutton_slot( GtkWidget* widget, gpointer func_data)
{
prompt_response = RESPONSE_NO;
}
static void prompt_okbutton_slot( GtkWidget* widget, gpointer func_data)
{
prompt_response = RESPONSE_OK;
}
#endif
static yesno_answer gtkui_prompt(const char *txt, yesno_answer suggest)
{
GtkWidget *dialog;
#ifdef ENABLE_GTK2
gint ret;
dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
(suggest != RESPONSE_OK) ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO,
(suggest != RESPONSE_OK) ? GTK_BUTTONS_YES_NO : GTK_BUTTONS_OK,
txt);
ret = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
if (ret==GTK_RESPONSE_YES || ret==GTK_RESPONSE_OK)
return (suggest==RESPONSE_OK) ? RESPONSE_OK : RESPONSE_YES;
return RESPONSE_NO;
#else
GtkWidget *label, *yes_button, *no_button, *ok_button;
/* Create the widgets */
dialog = gtk_dialog_new();
label = gtk_label_new (txt);
gtk_misc_set_padding(GTK_MISC(label), 8, 8);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);