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