Cosmetic: Message typo.
[captive.git] / src / install / acquire / ui-gnome.c
1 /* $Id$
2  * Drivers acquiring installation utility
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
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; exactly version 2 of June 1991 is required
8  * 
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.
13  * 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "ui-gnome.h"   /* self */
23 #include <glib/gmessages.h>
24 #include "moduriload.h"
25 #include "main.h"
26 #include <gtk/gtkmain.h>
27 #include <gtk/gtktreeviewcolumn.h>
28 #include <gtk/gtkbox.h>
29 #include <sys/time.h>
30 #include <libgnomeui/gnome-app.h>
31 #include <gtk/gtktreestore.h>
32 #include <gtk/gtkframe.h>
33 #include <gtk/gtkentry.h>
34 #include <libgnomeui/gnome-druid.h>
35 #include <libgnomeui/gnome-app-util.h>
36 #include <libgnomeui/gnome-druid-page-edge.h>
37 #include "final.h"
38 #include <libgnomevfs/gnome-vfs-utils.h>
39
40 #include <captive/macros.h>
41
42
43 /* Config: */
44 #define PROGRESS_UPDATE_USEC 100000
45
46
47 static GnomeApp *App;
48 static GtkTreeStore *DriversTreeStore;
49 static GtkFrame *DriversFrame;
50 static GtkFrame *ProgressFrame;
51 static GtkEntry *ProgressEntry;
52 static GnomeDruid *Druid;
53 static GtkButton *DruidButtonSkip;
54 static GtkButton *DruidButtonOK;
55 static GtkTreeView *DriversTreeView;
56 static GnomeDruidPage *PageStart;
57 static GnomeDruidPage *ScanDiskPage;
58 static GnomeDruidPage *ScanPathPage;
59 static GnomeDruidPage *MicrosoftComPage;
60 static GnomeDruidPage *PageFinish;
61 static GtkEntry *ScanPathLocationComboEntry;
62 static GtkButton *MicrosoftComConfirmButton;
63 static GtkProgressBar *MicrosoftComProgress;
64 enum {
65                 DRIVERS_TREE_STORE_COLUMN_TYPE,
66                 DRIVERS_TREE_STORE_COLUMN_ID,
67                 DRIVERS_TREE_STORE_COLUMN_NUM,  /* total # */
68                 };
69 #define DRIVERS_TREE_STORE_COLUMN_TYPE_LIST G_TYPE_STRING,G_TYPE_STRING
70
71
72 /* map: (gchar *)type-> (GtkTreeIter *) */
73 static GHashTable *DriversTreeStore_Iter_hash;
74
75 static void DriversTreeStore_Iter_hash_key_destroy_func(gchar *type)
76 {
77         g_return_if_fail(type!=NULL);
78
79         g_free(type);
80 }
81
82 static void DriversTreeStore_Iter_hash_init(void)
83 {
84         if (DriversTreeStore_Iter_hash)
85                 return;
86         DriversTreeStore_Iter_hash=g_hash_table_new_full(g_str_hash,g_str_equal,
87                         (GDestroyNotify)DriversTreeStore_Iter_hash_key_destroy_func,
88                         NULL);  /* value_destroy_func */
89 }
90
91 static GtkTreeIter *DriversTreeStore_Iter_hash_get_iter(const gchar *type)
92 {
93 GtkTreeIter *r;
94
95         g_return_val_if_fail(type!=NULL,NULL);
96
97         DriversTreeStore_Iter_hash_init();
98         if (!(r=g_hash_table_lookup(DriversTreeStore_Iter_hash,type))) {
99                 captive_new(r);
100                 gtk_tree_store_append(DriversTreeStore,
101                                 r,      /* iter */
102                                 NULL);  /* parent */
103                 g_hash_table_insert(DriversTreeStore_Iter_hash,g_strdup(type),r);
104                 }
105
106         return r;
107 }
108
109 static gboolean some_modules_found=FALSE;
110 static gboolean in_progress=FALSE;
111 static GnomeDruidPage *page_active;
112
113 static void state_changed(void)
114 {
115         /* Not yet initialized? */
116         if (!App)
117                 return;
118
119         gtk_widget_set_sensitive(GTK_WIDGET(DruidButtonSkip),
120                         (page_active!=PageStart && page_active!=PageFinish));
121         gtk_widget_set_sensitive(GTK_WIDGET(DruidButtonOK),some_modules_found);
122
123         if (in_progress) {
124                 gtk_widget_set_sensitive(Druid->next,FALSE);
125                 gtk_widget_set_sensitive(GTK_WIDGET(DruidButtonOK),some_modules_found);
126                 gtk_widget_set_sensitive(GTK_WIDGET(MicrosoftComConfirmButton),FALSE);
127                 }
128         else {
129                 /* It is checked by GTK+ whether the text changed: */
130                 gtk_entry_set_text(ProgressEntry,"");
131                 gtk_widget_set_sensitive(Druid->next,
132                                 (page_active!=PageFinish && page_active!=MicrosoftComPage));
133                 gtk_widget_set_sensitive(GTK_WIDGET(MicrosoftComConfirmButton),
134                                 (page_active==MicrosoftComPage));
135                 gtk_progress_bar_set_fraction(MicrosoftComProgress,(gdouble)0);
136                 gtk_progress_bar_set_text(MicrosoftComProgress,"");
137                 }
138 }
139
140 static void ui_gnome_module_best_priority_notify(const gchar *module_type)
141 {
142 GtkTreeIter *iter;
143
144         g_return_if_fail(module_type!=NULL);
145
146         iter=DriversTreeStore_Iter_hash_get_iter(module_type);
147         gtk_tree_store_set(DriversTreeStore,iter,
148                         DRIVERS_TREE_STORE_COLUMN_TYPE,module_type,
149                         DRIVERS_TREE_STORE_COLUMN_ID  ,
150                                         ((0
151                                                                         || !strcmp(module_type,"ntoskrnl.exe")
152                                                                         || !strcmp(module_type,"ntfs.sys"))
153                                                         ? _("NOT FOUND; essential module for NTFS disks access")
154                                                         : _("not found; optional module")),
155                         -1);
156 }
157
158 static void ui_gnome_module_available_notify(struct module_available *module_available)
159 {
160 GtkTreeIter *iter;
161 static gboolean some_module_ntoskrnl_exe_found=FALSE;
162 static gboolean some_module_ntfs_sys_found=FALSE;
163
164         g_return_if_fail(module_available!=NULL);
165         g_return_if_fail(module_available->module!=NULL);
166
167         iter=DriversTreeStore_Iter_hash_get_iter(module_available->module->type);
168         gtk_tree_store_set(DriversTreeStore,iter,
169                         DRIVERS_TREE_STORE_COLUMN_TYPE,module_available->module->type,
170                         DRIVERS_TREE_STORE_COLUMN_ID  ,module_available->module->id,
171                         -1);
172
173         if (!strcmp(module_available->module->type,"ntoskrnl.exe"))
174                 some_module_ntoskrnl_exe_found=TRUE;
175         if (!strcmp(module_available->module->type,"ntfs.sys"))
176                 some_module_ntfs_sys_found=TRUE;
177
178         some_modules_found=some_module_ntoskrnl_exe_found && some_module_ntfs_sys_found;
179         state_changed();
180 }
181
182 static gboolean all_modules_found=FALSE;
183
184 static void ui_gnome_all_modules_found_notify(void)
185 {
186         all_modules_found=TRUE;
187         state_changed();
188 }
189
190 static gboolean aborted=FALSE;
191 static gboolean aborted_back=FALSE;     /* 'Back' button was clicked. */
192 static struct timeval ProgressEntry_updated_timeval;
193
194 static void progress_start(void)
195 {
196         in_progress=TRUE;
197         aborted=FALSE;
198         aborted_back=FALSE;
199         CAPTIVE_MEMZERO(&ProgressEntry_updated_timeval);
200         state_changed();
201 }
202
203 static void progress_end(void)
204 {
205         in_progress=FALSE;
206         state_changed();
207 }
208
209 static gboolean ui_gnome_progress(GnomeVFSURI *uri)
210 {
211         /* 'uri' may be NULL */
212
213         if (ProgressEntry) {
214 static gchar *uri_text=NULL;
215
216                 /* Store 'uri' on each call (not just if 'diff_timeval' permits)
217                  * as we may get into long cabinet extraction phase with 'uri==NULL' calls
218                  * where we want to display the currently processed 'uri'.
219                  */
220                 if (uri) {
221                         g_free(uri_text);
222                         uri_text=gnome_vfs_uri_to_string(uri,GNOME_VFS_URI_HIDE_PASSWORD);
223                         }
224
225                 if (uri_text) {
226 struct timeval now_timeval;
227 struct timeval diff_timeval;
228
229                         gettimeofday(   /* FIXME: errors ignored */
230                                         &now_timeval,   /* tv */
231                                         NULL);  /* tz */
232                         timersub(&now_timeval,&ProgressEntry_updated_timeval,&diff_timeval);
233                         if (!ProgressEntry_updated_timeval.tv_sec || diff_timeval.tv_sec>0 || diff_timeval.tv_usec>=PROGRESS_UPDATE_USEC) {
234                                 gtk_entry_set_text(ProgressEntry,
235                                                 uri_text+(strncmp(uri_text,"file://",strlen("file://")) ? 0 : strlen("file://")));
236                                 ProgressEntry_updated_timeval=now_timeval;
237                                 }
238                         }
239                 }
240         while (gtk_events_pending())
241                 gtk_main_iteration();
242
243         if (aborted)
244                 return TRUE;
245         if (all_modules_found)
246                 return TRUE;
247
248         return FALSE;
249 }
250
251 static void ui_gnome_progress_bar(gint done,gint length)
252 {
253         g_return_if_fail(done>=0);
254         g_return_if_fail(length>=0);
255
256         if (!length) {
257                 gtk_progress_bar_pulse(MicrosoftComProgress);
258                 gtk_progress_bar_set_text(MicrosoftComProgress,"");
259                 }
260         else {
261 gchar *done_display,*length_display;
262
263                 gtk_progress_bar_set_fraction(MicrosoftComProgress,((gdouble)done)/length);
264                 done_display=gnome_vfs_format_file_size_for_display(done);
265                 length_display=gnome_vfs_format_file_size_for_display(length);
266                 gtk_progress_bar_set_text(MicrosoftComProgress,
267                                 captive_printf_alloca("%s / %s",done_display,length_display));
268                 g_free(done_display);
269                 g_free(length_display);
270                 }
271 }
272
273 /* FIXME: Change it to "prepare" signal. */
274 void on_Page_map(GtkWidget *vbox_widget,GtkWidget *page_widget)
275 {
276         g_return_if_fail(vbox_widget==NULL || GTK_IS_VBOX(vbox_widget));
277         g_return_if_fail(GNOME_IS_DRUID_PAGE(page_widget));
278
279         page_active=GNOME_DRUID_PAGE(page_widget);
280         if (page_active==PageFinish) {
281                 gnome_druid_set_show_finish(Druid,FALSE);       /* set it each time */
282                 /**/ if (!some_modules_found)
283                         gnome_druid_page_edge_set_text(GNOME_DRUID_PAGE_EDGE(PageFinish),_(
284                                         "We need at least some version of drivers essential for this project:"
285                                         " ntoskrnl.exe and ntfs.sys. Please click 'Back' button to obtain them"
286                                         " by several methods offered by this installer."));
287                 else {
288 gchar *text;
289
290                         text=final_text(all_modules_found);
291                         gnome_druid_page_edge_set_text(GNOME_DRUID_PAGE_EDGE(PageFinish),text);
292                         g_free(text);
293                         }
294                 }
295         if (page_active==ScanPathPage)
296                 gtk_widget_grab_focus(GTK_WIDGET(ScanPathLocationComboEntry));
297         state_changed();
298
299         if (!vbox_widget)
300                 return;
301
302         /* FIXME: 'freeze' apparently does not help 'repositioning' of
303          * 'DriversTreeView' during first 'map' of each 'Page'.
304          */
305         gtk_widget_freeze_child_notify(vbox_widget);
306
307         gtk_widget_reparent(GTK_WIDGET(DriversFrame),vbox_widget);
308         gtk_widget_reparent(GTK_WIDGET(ProgressFrame),vbox_widget);
309
310         gtk_box_reorder_child(GTK_BOX(vbox_widget),GTK_WIDGET(DriversFrame),
311                         0);     /* position */
312
313         gtk_box_set_child_packing(GTK_BOX(vbox_widget),GTK_WIDGET(DriversFrame),
314                         FALSE,  /* expand */
315                         TRUE,   /* fill */
316                         0,      /* padding */
317                         GTK_PACK_START);
318         gtk_box_set_child_packing(GTK_BOX(vbox_widget),GTK_WIDGET(ProgressFrame),
319                         FALSE,  /* expand */
320                         TRUE,   /* fill */
321                         0,      /* padding */
322                         GTK_PACK_START);
323
324         /* FIXME: Needed to fix (0,0)-position inside parent GdkWindow. */
325         gtk_widget_queue_resize(GTK_WIDGET(DriversTreeView));
326         gtk_widget_queue_resize(GTK_WIDGET(ProgressEntry));
327
328         gtk_widget_thaw_child_notify(vbox_widget);
329 }
330
331 gboolean on_Page_next(GnomeDruidPage *gnomedruidpage,GtkWidget *widget,gpointer user_data /* unused */)
332 {
333         g_return_val_if_fail(GNOME_IS_DRUID_PAGE(gnomedruidpage),FALSE);
334
335         if (in_progress)        /* bogus callback - we should be non-sensitive */
336                 return TRUE;    /* ignore button press */
337
338         /**/ if (page_active==PageStart) {
339                 if (all_modules_found) {
340                         gnome_druid_set_page(Druid,PageFinish);
341                         return TRUE;    /* ignore button press */
342                         }
343                 }
344         else if (page_active==ScanDiskPage) {
345                 progress_start();
346                 scan_disks_quick();
347                 scan_disks();
348                 progress_end();
349                 if (aborted_back) {
350                         gnome_druid_set_page(Druid,PageStart);
351                         return TRUE;    /* ignore button press */
352                         }
353                 if (all_modules_found) {
354                         gnome_druid_set_page(Druid,PageFinish);
355                         return TRUE;    /* ignore button press */
356                         }
357                 return FALSE;   /* proceed to next page */
358                 }
359         else if (page_active==ScanPathPage) {
360 const gchar *scan_path_uri_text=gtk_entry_get_text(ScanPathLocationComboEntry);
361
362                 if (scan_path_uri_text && *scan_path_uri_text) {
363 GnomeVFSURI *scan_path_uri;
364
365                         if ((scan_path_uri=gnome_vfs_uri_new(scan_path_uri_text))) {
366                                 progress_start();
367                                 mod_uri_load(scan_path_uri);
368                                 progress_end();
369                                 gnome_vfs_uri_unref(scan_path_uri);
370                                 if (aborted_back) {
371                                         gnome_druid_set_page(Druid,(all_modules_found ? PageStart : ScanDiskPage));
372                                         return TRUE;    /* ignore button press */
373                                         }
374                                 if (all_modules_found) {
375                                         gnome_druid_set_page(Druid,PageFinish);
376                                         return TRUE;    /* ignore button press */
377                                         }
378                                 gtk_entry_set_text(ScanPathLocationComboEntry,"");
379                                 }
380                         else
381                                 g_warning(_("Invalid URI: %s"),scan_path_uri_text);
382                         gtk_widget_grab_focus(GTK_WIDGET(ScanPathLocationComboEntry));
383                         return TRUE;    /* ignore button press; we cleared the URI entry */
384                         }
385                 return FALSE;   /* proceed to next page */
386                 }
387
388         return FALSE;   /* proceed to next page */
389 }
390
391 void on_MicrosoftComConfirmButton_clicked(GtkButton *button,gpointer user_data)
392 {
393         g_return_if_fail(GTK_IS_BUTTON(button));
394
395         if (in_progress)        /* bogus callback */
396                 return;
397         if (page_active!=MicrosoftComPage)      /* bogus callback */
398                 return;
399
400         progress_start();
401         microsoft_com();
402         progress_end();
403         if (aborted_back) {
404                 gnome_druid_set_page(Druid,(all_modules_found ? PageStart : ScanPathPage));
405                 return;
406                 }
407         if (all_modules_found) {
408                 gnome_druid_set_page(Druid,PageFinish);
409                 return;
410                 }
411
412         gnome_druid_set_page(Druid,PageFinish);
413 }
414
415 void on_DruidButtonSkip_clicked(GtkButton *button,gpointer user_data /* unused */)
416 {
417         g_return_if_fail(GTK_IS_BUTTON(button));
418
419         if (in_progress) {
420                 aborted=TRUE;
421                 state_changed();
422                 return;
423                 }
424         if (all_modules_found)
425                 gnome_druid_set_page(Druid,PageFinish);
426         else if (page_active==ScanDiskPage)
427                 gnome_druid_set_page(Druid,ScanPathPage);
428         else if (page_active==ScanPathPage)
429                 gnome_druid_set_page(Druid,MicrosoftComPage);
430         else if (page_active==MicrosoftComPage)
431                 gnome_druid_set_page(Druid,PageFinish);
432 }
433
434 gboolean on_Page_back(GnomeDruidPage *gnomedruidpage,GtkWidget *widget,gpointer user_data)
435 {
436         g_return_val_if_fail(GNOME_IS_DRUID_PAGE(gnomedruidpage),FALSE);
437
438         if (!in_progress) {
439                 if (all_modules_found) {
440                         gnome_druid_set_page(Druid,PageStart);
441                         return TRUE;    /* ignore button press */
442                         }
443                 return FALSE;   /* proceed to previous page */
444                 }
445
446         aborted=TRUE;
447         aborted_back=TRUE;
448         state_changed();
449
450         return TRUE;    /* ignore button press now; we will respect 'aborted_back' */
451 }
452
453 void on_Druid_cancel(GnomeDruid *gnomedruid,gpointer user_data /* unused */)
454 {
455         g_return_if_fail(GNOME_IS_DRUID(gnomedruid));
456
457         /* gtk_main_quit() would not abort the current operation. */
458         exit(EXIT_SUCCESS);
459 }
460
461 static void on_DruidButtonOK_clicked_dialog_callback(gint reply,gint *replyp /* data */)
462 {
463         g_return_if_fail(reply>=0);
464         g_return_if_fail(replyp!=NULL);
465
466         *replyp=reply;
467 }
468
469 void on_DruidButtonOK_clicked(GtkButton *button,gpointer user_data /* unused */)
470 {
471 GtkWidget *dialog;
472 gint reply;
473
474         g_return_if_fail(GTK_IS_BUTTON(button));
475
476         if (all_modules_found)
477                 exit(EXIT_SUCCESS);
478
479         /* TODO: Avoid dialog if already on Finish page. */
480         reply=-1;
481         dialog=gnome_app_ok_cancel_modal(App,_(
482                         "Although essential modules (\"ntoskrnl.exe\" and \"ntfs.sys\") are available "
483                         "you may still want to get their better version and/or more modules. "
484                         "Really quit?"),
485                         (GnomeReplyCallback)on_DruidButtonOK_clicked_dialog_callback,
486                         &reply);        /* data */
487         g_signal_connect((gpointer)dialog,"close",G_CALLBACK(gtk_main_quit),NULL);
488         gtk_main();
489         /* 'dialog' gets destroyed automatically */
490         if (reply==0)   /* 0 for 'OK', 1 for 'Cancel', left -1 for dialog close. */
491                 exit(EXIT_SUCCESS);
492 }
493
494 static void button_stock_set_label(GtkWidget *widget,const gchar *label_text_new /* callback_data */)
495 {
496         g_return_if_fail(GTK_IS_WIDGET(widget));
497         g_return_if_fail(label_text_new!=NULL);
498
499         /**/ if (GTK_IS_CONTAINER(widget))
500                 gtk_container_foreach(GTK_CONTAINER(widget),
501                                 (GtkCallback)button_stock_set_label,    /* callback */
502                                 (/* de-conts */ gchar *)label_text_new);        /* callback_data */
503         else if (GTK_IS_LABEL(widget))
504                 gtk_label_set_text_with_mnemonic(GTK_LABEL(widget),label_text_new);
505 }
506
507 /* of "ui-gnome-interface.h": */
508 GtkWidget *create_App(void);
509 /* of "ui-gnome-support.h": */
510 GtkWidget *lookup_widget(GtkWidget *widget,const gchar *widget_name);
511
512 static void App_init(void)
513 {
514 GtkTreeViewColumn *column;
515 GtkCellRenderer *cell;
516 GtkBox *druid_button_box;
517
518         App=GNOME_APP(create_App());
519
520         DriversTreeView=GTK_TREE_VIEW(lookup_widget(GTK_WIDGET(App),"DriversTreeView"));
521         DriversFrame=GTK_FRAME(lookup_widget(GTK_WIDGET(App),"DriversFrame"));
522         ProgressFrame=GTK_FRAME(lookup_widget(GTK_WIDGET(App),"ProgressFrame"));
523         Druid=GNOME_DRUID(lookup_widget(GTK_WIDGET(App),"Druid"));
524         PageStart=GNOME_DRUID_PAGE(lookup_widget(GTK_WIDGET(App),"PageStart"));
525         ScanDiskPage=GNOME_DRUID_PAGE(lookup_widget(GTK_WIDGET(App),"ScanDiskPage"));
526         ScanPathPage=GNOME_DRUID_PAGE(lookup_widget(GTK_WIDGET(App),"ScanPathPage"));
527         MicrosoftComPage=GNOME_DRUID_PAGE(lookup_widget(GTK_WIDGET(App),"MicrosoftComPage"));
528         PageFinish=GNOME_DRUID_PAGE(lookup_widget(GTK_WIDGET(App),"PageFinish"));
529         ScanPathLocationComboEntry=GTK_ENTRY(lookup_widget(GTK_WIDGET(App),"ScanPathLocationComboEntry"));
530         MicrosoftComConfirmButton=GTK_BUTTON(lookup_widget(GTK_WIDGET(App),"MicrosoftComConfirmButton"));
531         MicrosoftComProgress=GTK_PROGRESS_BAR(lookup_widget(GTK_WIDGET(App),"MicrosoftComProgress"));
532         ProgressEntry=GTK_ENTRY(lookup_widget(GTK_WIDGET(App),"ProgressEntry"));
533
534         druid_button_box=GTK_BOX(gtk_widget_get_parent(Druid->next));
535
536         DriversTreeStore=gtk_tree_store_new(DRIVERS_TREE_STORE_COLUMN_NUM,DRIVERS_TREE_STORE_COLUMN_TYPE_LIST);
537         gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(DriversTreeStore),
538                         DRIVERS_TREE_STORE_COLUMN_TYPE,GTK_SORT_ASCENDING);
539         gtk_tree_view_set_model(DriversTreeView,GTK_TREE_MODEL(DriversTreeStore));
540
541         column=gtk_tree_view_column_new();
542         cell=gtk_cell_renderer_text_new();
543         gtk_tree_view_column_pack_start(column,cell,
544                         TRUE);  /* expand */
545         gtk_tree_view_column_set_attributes(column,cell,
546                         "text",DRIVERS_TREE_STORE_COLUMN_TYPE,
547                         NULL);
548         gtk_tree_view_append_column(DriversTreeView,column);
549
550         column=gtk_tree_view_column_new();
551         cell=gtk_cell_renderer_text_new();
552         gtk_tree_view_column_pack_start(column,cell,
553                         TRUE);  /* expand */
554         gtk_tree_view_column_set_attributes(column,cell,
555                         "text",DRIVERS_TREE_STORE_COLUMN_ID,
556                         NULL);
557         gtk_tree_view_append_column(DriversTreeView,column);
558
559         /* gnome_druid_set_show_finish() just replaces Next<->Finish buttons displayed. */
560         gtk_widget_hide(GTK_WIDGET(Druid->finish));
561
562         DruidButtonSkip=GTK_BUTTON(gtk_button_new_from_stock(GTK_STOCK_REDO));
563         gtk_container_foreach(GTK_CONTAINER(DruidButtonSkip),
564                         (GtkCallback)button_stock_set_label,    /* callback */
565                         _("_Skip"));    /* callback_data */
566         gtk_box_pack_end(druid_button_box,GTK_WIDGET(DruidButtonSkip),FALSE,TRUE,0);
567         gtk_widget_show(GTK_WIDGET(DruidButtonSkip));
568         g_signal_connect((gpointer)DruidButtonSkip,"clicked",G_CALLBACK(on_DruidButtonSkip_clicked),NULL);
569
570         DruidButtonOK=GTK_BUTTON(gtk_button_new_from_stock(GTK_STOCK_OK));
571         gtk_box_pack_end(druid_button_box,GTK_WIDGET(DruidButtonOK),FALSE,TRUE,0);
572         gtk_widget_show(GTK_WIDGET(DruidButtonOK));
573         g_signal_connect((gpointer)DruidButtonOK,"clicked",G_CALLBACK(on_DruidButtonOK_clicked),NULL);
574
575         state_changed();
576 }
577
578 static void ui_gnome_g_log_handler(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
579 {
580 GtkWidget *dialog;
581
582         /* Ignore arrors by cabextract during its abortion. */
583         if (in_progress && aborted)
584                 return;
585
586         /**/ if (log_level & G_LOG_LEVEL_ERROR)
587                 dialog=gnome_app_error(App,message);
588         else if (log_level & (G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING))
589                 dialog=gnome_app_warning(App,message);
590         else
591                 dialog=gnome_app_message(App,message);
592
593         gtk_window_set_modal(GTK_WINDOW(dialog),TRUE);
594         g_signal_connect((gpointer)dialog,"close",G_CALLBACK(gtk_main_quit),NULL);
595         gtk_main();
596         /* 'dialog' gets destroyed automatically */
597 }
598
599 static void ui_gnome_interactive(void)
600 {
601         gtk_widget_show_all(GTK_WIDGET(App));
602         gtk_main();
603         exit(EXIT_SUCCESS);
604 }
605
606 gboolean ui_gnome_init(void)
607 {
608         acquire_module_available_notify=ui_gnome_module_available_notify;
609         acquire_module_all_modules_found_notify=ui_gnome_all_modules_found_notify;
610         ui_progress=ui_gnome_progress;
611         ui_progress_bar=ui_gnome_progress_bar;
612         ui_interactive=ui_gnome_interactive;
613         captivemodid_module_best_priority_notify=ui_gnome_module_best_priority_notify;
614
615         /* Graphic widgets will all be hidden yet. */
616         App_init();
617         /* ui_gnome_g_log_handler() needs 'App'. */
618         g_log_set_handler(
619                         G_LOG_DOMAIN,   /* log_domain; "Captive" */
620                         G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL,    /* log_levels */
621                         ui_gnome_g_log_handler, /* log_func */
622                         NULL);  /* user_data */
623
624         return TRUE;
625 }