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