]> git.tdb.fi Git - ext/subsurface.git/blob - gtk-gui.c
Tracking changes to tanks is trivial
[ext/subsurface.git] / gtk-gui.c
1 /* gtk-gui.c */
2 /* gtk UI implementation */
3 /* creates the window and overall layout
4  * divelist, dive info, equipment and printing are handled in their own source files
5  */
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <time.h>
10
11 #include <gconf/gconf-client.h>
12
13 #include "dive.h"
14 #include "divelist.h"
15 #include "display.h"
16 #include "display-gtk.h"
17
18 #include "libdivecomputer.h"
19
20 GtkWidget *main_window;
21 GtkWidget *main_vbox;
22 GtkWidget *error_info_bar;
23 GtkWidget *error_label;
24 int        error_count;
25
26 #define DIVELIST_DEFAULT_FONT "Sans 8"
27 const char *divelist_font;
28
29 GConfClient *gconf;
30 struct units output_units;
31
32 #define GCONF_NAME(x) "/apps/subsurface/" #x
33
34 static GtkWidget *dive_profile;
35
36 void repaint_dive(void)
37 {
38         update_dive(current_dive);
39         gtk_widget_queue_draw(dive_profile);
40 }
41
42 static char *existing_filename;
43
44 static void on_info_bar_response(GtkWidget *widget, gint response,
45                                  gpointer data)
46 {
47         if (response == GTK_RESPONSE_OK)
48         {
49                 gtk_widget_destroy(widget);
50                 error_info_bar = NULL;
51         }
52 }
53
54 void report_error(GError* error)
55 {
56         if (error == NULL)
57         {
58                 return;
59         }
60         
61         if (error_info_bar == NULL)
62         {
63                 error_count = 1;
64                 error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
65                                                                GTK_RESPONSE_OK,
66                                                                NULL);
67                 g_signal_connect(error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL);
68                 gtk_info_bar_set_message_type(GTK_INFO_BAR(error_info_bar),
69                                               GTK_MESSAGE_ERROR);
70                 
71                 error_label = gtk_label_new(error->message);
72                 GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(error_info_bar));
73                 gtk_container_add(GTK_CONTAINER(container), error_label);
74                 
75                 gtk_box_pack_start(GTK_BOX(main_vbox), error_info_bar, FALSE, FALSE, 0);
76                 gtk_widget_show_all(main_vbox);
77         }
78         else
79         {
80                 error_count++;
81                 char buffer[256];
82                 snprintf(buffer, sizeof(buffer), "Failed to open %i files.", error_count);
83                 gtk_label_set(GTK_LABEL(error_label), buffer);
84         }
85 }
86
87 static void file_open(GtkWidget *w, gpointer data)
88 {
89         GtkWidget *dialog;
90         dialog = gtk_file_chooser_dialog_new("Open File",
91                 GTK_WINDOW(main_window),
92                 GTK_FILE_CHOOSER_ACTION_OPEN,
93                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
94                 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
95                 NULL);
96         gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
97
98         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
99                 GSList *filenames;
100                 char *filename;
101                 filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
102                 
103                 GError *error = NULL;
104                 while(filenames != NULL) {
105                         filename = (char *)filenames->data;
106                         parse_xml_file(filename, &error);
107                         if (error != NULL)
108                         {
109                                 report_error(error);
110                                 g_error_free(error);
111                                 error = NULL;
112                         }
113                         
114                         g_free(filename);
115                         filenames = g_slist_next(filenames);
116                 }
117                 g_slist_free(filenames);
118                 report_dives();
119                 dive_list_update_dives();
120         }
121         gtk_widget_destroy(dialog);
122 }
123
124 static void file_save(GtkWidget *w, gpointer data)
125 {
126         GtkWidget *dialog;
127         dialog = gtk_file_chooser_dialog_new("Save File",
128                 GTK_WINDOW(main_window),
129                 GTK_FILE_CHOOSER_ACTION_SAVE,
130                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
131                 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
132                 NULL);
133         gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
134         if (!existing_filename) {
135                 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document");
136         } else
137                 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), existing_filename);
138
139         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
140                 char *filename;
141                 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
142                 save_dives(filename);
143                 g_free(filename);
144                 mark_divelist_changed(TRUE);
145         }
146         gtk_widget_destroy(dialog);
147 }
148
149 static void ask_save_changes()
150 {
151         GtkWidget *dialog;
152         dialog = gtk_dialog_new_with_buttons("Save Changes?",
153                 GTK_WINDOW(main_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
154                 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
155                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
156                 NULL);
157
158         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
159                 file_save(NULL,NULL);
160         }
161         gtk_widget_destroy(dialog);
162 }
163
164 void on_destroy(GtkWidget* w, gpointer data)
165 {
166         if (unsaved_changes())
167                 ask_save_changes();
168         gtk_main_quit();
169 }
170
171 static void quit(GtkWidget *w, gpointer data)
172 {
173         gtk_main_quit();
174 }
175
176 static void create_radio(GtkWidget *vbox, const char *name, ...)
177 {
178         va_list args;
179         GtkRadioButton *group = NULL;
180         GtkWidget *box, *label;
181
182         box = gtk_hbox_new(TRUE, 10);
183         gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 0);
184
185         label = gtk_label_new(name);
186         gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
187
188         va_start(args, name);
189         for (;;) {
190                 int enabled;
191                 const char *name;
192                 GtkWidget *button;
193                 void *callback_fn;
194
195                 name = va_arg(args, char *);
196                 if (!name)
197                         break;
198                 callback_fn = va_arg(args, void *);
199                 enabled = va_arg(args, int);
200
201                 button = gtk_radio_button_new_with_label_from_widget(group, name);
202                 group = GTK_RADIO_BUTTON(button);
203                 gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
204                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), enabled);
205                 g_signal_connect(button, "toggled", G_CALLBACK(callback_fn), NULL);
206         }
207         va_end(args);
208 }
209
210 #define UNITCALLBACK(name, type, value)                         \
211 static void name(GtkWidget *w, gpointer data)                   \
212 {                                                               \
213         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) \
214                 menu_units.type = value;                        \
215 }
216
217 static struct units menu_units;
218
219 UNITCALLBACK(set_meter, length, METERS)
220 UNITCALLBACK(set_feet, length, FEET)
221 UNITCALLBACK(set_bar, pressure, BAR)
222 UNITCALLBACK(set_psi, pressure, PSI)
223 UNITCALLBACK(set_liter, volume, LITER)
224 UNITCALLBACK(set_cuft, volume, CUFT)
225 UNITCALLBACK(set_celsius, temperature, CELSIUS)
226 UNITCALLBACK(set_fahrenheit, temperature, FAHRENHEIT)
227
228 static void preferences_dialog(GtkWidget *w, gpointer data)
229 {
230         int result;
231         GtkWidget *dialog, *font, *frame, *box;
232
233         menu_units = output_units;
234
235         dialog = gtk_dialog_new_with_buttons("Preferences",
236                 GTK_WINDOW(main_window),
237                 GTK_DIALOG_DESTROY_WITH_PARENT,
238                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
239                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
240                 NULL);
241
242         frame = gtk_frame_new("Units");
243         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
244
245         box = gtk_vbox_new(FALSE, 6);
246         gtk_container_add(GTK_CONTAINER(frame), box);
247
248         create_radio(box, "Depth:",
249                 "Meter", set_meter, (output_units.length == METERS),
250                 "Feet",  set_feet, (output_units.length == FEET),
251                 NULL);
252
253         create_radio(box, "Pressure:",
254                 "Bar", set_bar, (output_units.pressure == BAR),
255                 "PSI",  set_psi, (output_units.pressure == PSI),
256                 NULL);
257
258         create_radio(box, "Volume:",
259                 "Liter",  set_liter, (output_units.volume == LITER),
260                 "CuFt", set_cuft, (output_units.volume == CUFT),
261                 NULL);
262
263         create_radio(box, "Temperature:",
264                 "Celsius", set_celsius, (output_units.temperature == CELSIUS),
265                 "Fahrenheit",  set_fahrenheit, (output_units.temperature == FAHRENHEIT),
266                 NULL);
267
268         font = gtk_font_button_new_with_font(divelist_font);
269         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), font, FALSE, FALSE, 5);
270
271         gtk_widget_show_all(dialog);
272         result = gtk_dialog_run(GTK_DIALOG(dialog));
273         if (result == GTK_RESPONSE_ACCEPT) {
274                 /* Make sure to flush any modified old dive data with old units */
275                 update_dive(NULL);
276
277                 divelist_font = strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON(font)));
278                 set_divelist_font(divelist_font);
279
280                 output_units = menu_units;
281                 update_dive_list_units();
282                 repaint_dive();
283                 gconf_client_set_bool(gconf, GCONF_NAME(feet), output_units.length == FEET, NULL);
284                 gconf_client_set_bool(gconf, GCONF_NAME(psi), output_units.pressure == PSI, NULL);
285                 gconf_client_set_bool(gconf, GCONF_NAME(cuft), output_units.volume == CUFT, NULL);
286                 gconf_client_set_bool(gconf, GCONF_NAME(fahrenheit), output_units.temperature == FAHRENHEIT, NULL);
287                 gconf_client_set_string(gconf, GCONF_NAME(divelist_font), divelist_font, NULL);
288         }
289         gtk_widget_destroy(dialog);
290 }
291
292 static void renumber_dialog(GtkWidget *w, gpointer data)
293 {
294         int result;
295         GtkWidget *dialog, *frame, *button;
296
297         dialog = gtk_dialog_new_with_buttons("Renumber",
298                 GTK_WINDOW(main_window),
299                 GTK_DIALOG_DESTROY_WITH_PARENT,
300                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
301                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
302                 NULL);
303
304         frame = gtk_frame_new("New starting number");
305         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), frame);
306
307         button = gtk_spin_button_new_with_range(1, 50000, 1);
308         gtk_container_add(GTK_CONTAINER(frame), button);
309
310         gtk_widget_show_all(dialog);
311         result = gtk_dialog_run(GTK_DIALOG(dialog));
312         if (result == GTK_RESPONSE_ACCEPT) {
313                 int nr = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button));
314                 renumber_dives(nr);
315                 repaint_dive();
316         }
317         gtk_widget_destroy(dialog);
318 }
319
320 static GtkActionEntry menu_items[] = {
321         { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
322         { "LogMenuAction",  GTK_STOCK_FILE, "Log", NULL, NULL, NULL},
323         { "OpenFile",       GTK_STOCK_OPEN, NULL,   "<control>O", NULL, G_CALLBACK(file_open) },
324         { "SaveFile",       GTK_STOCK_SAVE, NULL,   "<control>S", NULL, G_CALLBACK(file_save) },
325         { "Print",          GTK_STOCK_PRINT, NULL,  "<control>P", NULL, G_CALLBACK(do_print) },
326         { "Import",         NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) },
327         { "Preferences",    NULL, "Preferences", NULL, NULL, G_CALLBACK(preferences_dialog) },
328         { "Renumber",       NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) },
329         { "Quit",           GTK_STOCK_QUIT, NULL,   "<control>Q", NULL, G_CALLBACK(quit) },
330 };
331 static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
332
333 static const gchar* ui_string = " \
334         <ui> \
335                 <menubar name=\"MainMenu\"> \
336                         <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
337                                 <menuitem name=\"Open\" action=\"OpenFile\" /> \
338                                 <menuitem name=\"Save\" action=\"SaveFile\" /> \
339                                 <menuitem name=\"Print\" action=\"Print\" /> \
340                                 <separator name=\"Separator1\"/> \
341                                 <menuitem name=\"Import\" action=\"Import\" /> \
342                                 <separator name=\"Separator2\"/> \
343                                 <menuitem name=\"Preferences\" action=\"Preferences\" /> \
344                                 <separator name=\"Separator3\"/> \
345                                 <menuitem name=\"Quit\" action=\"Quit\" /> \
346                         </menu> \
347                         <menu name=\"LogMenu\" action=\"LogMenuAction\"> \
348                                 <menuitem name=\"Renumber\" action=\"Renumber\" /> \
349                         </menu> \
350                 </menubar> \
351         </ui> \
352 ";
353
354 static GtkWidget *get_menubar_menu(GtkWidget *window)
355 {
356         GtkActionGroup *action_group = gtk_action_group_new("Menu");
357         gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
358
359         GtkUIManager *ui_manager = gtk_ui_manager_new();
360         gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
361         GError* error = 0;
362         gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
363
364         gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
365         GtkWidget* menu = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
366
367         return menu;
368 }
369
370 static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data)
371 {
372         repaint_dive();
373 }
374
375 void init_ui(int argc, char **argv)
376 {
377         GtkWidget *win;
378         GtkWidget *paned;
379         GtkWidget *info_box;
380         GtkWidget *notebook;
381         GtkWidget *dive_info;
382         GtkWidget *dive_list;
383         GtkWidget *equipment;
384         GtkWidget *menubar;
385         GtkWidget *vbox;
386
387         gtk_init(&argc, &argv);
388
389         g_type_init();
390         gconf = gconf_client_get_default();
391
392         if (gconf_client_get_bool(gconf, GCONF_NAME(feet), NULL))
393                 output_units.length = FEET;
394         if (gconf_client_get_bool(gconf, GCONF_NAME(psi), NULL))
395                 output_units.pressure = PSI;
396         if (gconf_client_get_bool(gconf, GCONF_NAME(cuft), NULL))
397                 output_units.volume = CUFT;
398         if (gconf_client_get_bool(gconf, GCONF_NAME(fahrenheit), NULL))
399                 output_units.temperature = FAHRENHEIT;
400
401         divelist_font = gconf_client_get_string(gconf, GCONF_NAME(divelist_font), NULL);
402         if (!divelist_font)
403                 divelist_font = DIVELIST_DEFAULT_FONT;
404
405         error_info_bar = NULL;
406         win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
407         gtk_window_set_icon_from_file(GTK_WINDOW(win), "icon.svg", NULL);
408         g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
409         main_window = win;
410
411         vbox = gtk_vbox_new(FALSE, 0);
412         gtk_container_add(GTK_CONTAINER(win), vbox);
413         main_vbox = vbox;
414
415         menubar = get_menubar_menu(win);
416         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
417
418         /* HPane for left the dive list, and right the dive info */
419         paned = gtk_vpaned_new();
420         gtk_box_pack_end(GTK_BOX(vbox), paned, TRUE, TRUE, 0);
421
422         /* Create the actual divelist */
423         dive_list = dive_list_create();
424         gtk_paned_add2(GTK_PANED(paned), dive_list);
425
426         /* VBox for dive info, and tabs */
427         info_box = gtk_vbox_new(FALSE, 6);
428         gtk_paned_add1(GTK_PANED(paned), info_box);
429
430         /* Notebook for dive info vs profile vs .. */
431         notebook = gtk_notebook_new();
432         g_signal_connect(notebook, "switch-page", G_CALLBACK(switch_page), NULL);
433         gtk_box_pack_start(GTK_BOX(info_box), notebook, TRUE, TRUE, 6);
434
435         /* Frame for dive profile */
436         dive_profile = dive_profile_widget();
437         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_profile, gtk_label_new("Dive Profile"));
438
439         /* Frame for extended dive info */
440         dive_info = extended_dive_info_widget();
441         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_info, gtk_label_new("Dive Notes"));
442
443         /* Frame for dive equipment */
444         equipment = equipment_widget();
445         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), equipment, gtk_label_new("Equipment"));
446
447         gtk_widget_set_app_paintable(win, TRUE);
448         gtk_widget_show_all(win);
449
450         return;
451 }
452
453 void run_ui(void)
454 {
455         gtk_main();
456 }
457
458 /* get the filenames the user selects and call the parsing function
459  * on them
460  * return 0 if the user cancelled the dialog
461  */
462 int open_import_file_dialog(char *filterpattern, char *filtertext, 
463                         void(* parse_function)(char *))
464 {
465         int ret=0;
466
467         GtkWidget *dialog;
468         GtkFileFilter *filter = gtk_file_filter_new ();
469         gtk_file_filter_add_pattern (filter, filterpattern);
470         gtk_file_filter_set_name(filter, filtertext);
471         dialog = gtk_file_chooser_dialog_new("Open File",
472                                         GTK_WINDOW(main_window),
473                                         GTK_FILE_CHOOSER_ACTION_OPEN,
474                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
475                                         GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
476                                         NULL);
477         gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
478         gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter);
479
480         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
481                 GSList *filenames;
482                 char *filename;
483                 filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
484                 while(filenames != NULL) {
485                         filename = (char *)filenames->data;
486                         parse_function(filename);
487                         g_free(filename);
488                         filenames = g_slist_next(filenames);
489                 }
490                 g_slist_free(filenames);
491                 ret = 1;
492         }
493         gtk_widget_destroy(dialog);
494
495         return ret;
496 }
497
498 static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
499 {
500         struct dive *dive = current_dive;
501         struct graphics_context gc = { .printer = 0 };
502         int w,h;
503
504         w = widget->allocation.width;
505         h = widget->allocation.height;
506
507         gc.cr = gdk_cairo_create(widget->window);
508         set_source_rgb(&gc, 0, 0, 0);
509         cairo_paint(gc.cr);
510
511         if (dive)
512                 plot(&gc, w, h, dive);
513
514         cairo_destroy(gc.cr);
515
516         return FALSE;
517 }
518
519 GtkWidget *dive_profile_widget(void)
520 {
521         GtkWidget *da;
522
523         da = gtk_drawing_area_new();
524         gtk_widget_set_size_request(da, 350, 250);
525         g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
526
527         return da;
528 }
529
530 int process_ui_events(void)
531 {
532         int ret=0;
533
534         while (gtk_events_pending()) {
535                 if (gtk_main_iteration_do(0)) {
536                         ret = 1;
537                         break;
538                 }
539         }
540         return(ret);
541 }
542
543
544 static void fill_computer_list(GtkListStore *store)
545 {
546         GtkTreeIter iter;
547         struct device_list *list = device_list;
548
549         for (list = device_list ; list->name ; list++) {
550                 gtk_list_store_append(store, &iter);
551                 gtk_list_store_set(store, &iter,
552                         0, list->name,
553                         1, list->type,
554                         -1);
555         }
556 }
557
558 static GtkComboBox *dive_computer_selector(GtkWidget *dialog)
559 {
560         GtkWidget *hbox, *combo_box;
561         GtkListStore *model;
562         GtkCellRenderer *renderer;
563
564         hbox = gtk_hbox_new(FALSE, 6);
565         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 3);
566
567         model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
568         fill_computer_list(model);
569
570         combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
571         gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, TRUE, 3);
572
573         renderer = gtk_cell_renderer_text_new();
574         gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
575         gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer, "text", 0, NULL);
576
577         return GTK_COMBO_BOX(combo_box);
578 }
579
580 void import_dialog(GtkWidget *w, gpointer data)
581 {
582         int result;
583         GtkWidget *dialog, *hbox;
584         GtkComboBox *computer;
585         device_data_t devicedata = {
586                 .devname = "/dev/ttyUSB0",
587         };
588
589         dialog = gtk_dialog_new_with_buttons("Import from dive computer",
590                 GTK_WINDOW(main_window),
591                 GTK_DIALOG_DESTROY_WITH_PARENT,
592                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
593                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
594                 NULL);
595
596         computer = dive_computer_selector(dialog);
597
598         hbox = gtk_hbox_new(FALSE, 6);
599         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, TRUE, 3);
600         devicedata.progress->bar = gtk_progress_bar_new();
601         gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress->bar);
602
603         gtk_widget_show_all(dialog);
604         result = gtk_dialog_run(GTK_DIALOG(dialog));
605         switch (result) {
606                 int type;
607                 GtkTreeIter iter;
608                 GtkTreeModel *model;
609                 const char *comp;
610         case GTK_RESPONSE_ACCEPT:
611                 if (!gtk_combo_box_get_active_iter(computer, &iter))
612                         break;
613                 model = gtk_combo_box_get_model(computer);
614                 gtk_tree_model_get(model, &iter,
615                         0, &comp,
616                         1, &type,
617                         -1);
618                 devicedata.type = type;
619                 devicedata.name = comp;
620                 do_import(&devicedata);
621                 break;
622         default:
623                 break;
624         }
625         gtk_widget_destroy(dialog);
626
627         report_dives();
628         dive_list_update_dives();
629 }
630
631 void update_progressbar(progressbar_t *progress, double value)
632 {
633         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), value);
634 }