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
15 #include "display-gtk.h"
17 #include "libdivecomputer.h"
19 GtkWidget *main_window;
21 GtkWidget *error_info_bar;
22 GtkWidget *error_label;
23 GtkWidget *vpane, *hpane;
28 const char *divelist_font;
30 struct units output_units;
32 static GtkWidget *dive_profile;
34 visible_cols_t visible_cols = {TRUE, FALSE};
36 static const char *default_dive_computer_vendor;
37 static const char *default_dive_computer_product;
38 static const char *default_dive_computer_device;
40 static int is_default_dive_computer(const char *vendor, const char *product)
42 return default_dive_computer_vendor && !strcmp(vendor, default_dive_computer_vendor) &&
43 default_dive_computer_product && !strcmp(product, default_dive_computer_product);
46 static int is_default_dive_computer_device(const char *name)
48 return default_dive_computer_device && !strcmp(name, default_dive_computer_device);
51 static void set_default_dive_computer(const char *vendor, const char *product)
53 if (!vendor || !*vendor)
55 if (!product || !*product)
57 if (is_default_dive_computer(vendor, product))
59 default_dive_computer_vendor = vendor;
60 default_dive_computer_product = product;
61 subsurface_set_conf("dive_computer_vendor", PREF_STRING, vendor);
62 subsurface_set_conf("dive_computer_product", PREF_STRING, product);
65 static void set_default_dive_computer_device(const char *name)
69 if (is_default_dive_computer_device(name))
71 default_dive_computer_device = name;
72 subsurface_set_conf("dive_computer_device", PREF_STRING, name);
75 void repaint_dive(void)
77 update_dive(current_dive);
79 gtk_widget_queue_draw(dive_profile);
82 static char *existing_filename;
83 static gboolean need_icon = TRUE;
85 static void on_info_bar_response(GtkWidget *widget, gint response,
88 if (response == GTK_RESPONSE_OK)
90 gtk_widget_destroy(widget);
91 error_info_bar = NULL;
95 void report_error(GError* error)
102 if (error_info_bar == NULL)
105 error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
108 g_signal_connect(error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL);
109 gtk_info_bar_set_message_type(GTK_INFO_BAR(error_info_bar),
112 error_label = gtk_label_new(error->message);
113 GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(error_info_bar));
114 gtk_container_add(GTK_CONTAINER(container), error_label);
116 gtk_box_pack_start(GTK_BOX(main_vbox), error_info_bar, FALSE, FALSE, 0);
117 gtk_widget_show_all(main_vbox);
123 snprintf(buffer, sizeof(buffer), "Failed to open %i files.", error_count);
124 gtk_label_set(GTK_LABEL(error_label), buffer);
128 static void file_open(GtkWidget *w, gpointer data)
131 GtkFileFilter *filter;
133 dialog = gtk_file_chooser_dialog_new("Open File",
134 GTK_WINDOW(main_window),
135 GTK_FILE_CHOOSER_ACTION_OPEN,
136 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
137 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
139 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
141 filter = gtk_file_filter_new();
142 gtk_file_filter_add_pattern(filter, "*.xml");
143 gtk_file_filter_add_pattern(filter, "*.XML");
144 gtk_file_filter_add_pattern(filter, "*.sda");
145 gtk_file_filter_add_pattern(filter, "*.SDA");
146 gtk_file_filter_add_mime_type(filter, "text/xml");
147 gtk_file_filter_set_name(filter, "XML file");
148 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
150 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
151 GSList *filenames, *fn_glist;
153 filenames = fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
155 GError *error = NULL;
156 while(filenames != NULL) {
157 filename = filenames->data;
158 parse_file(filename, &error);
167 filenames = g_slist_next(filenames);
169 g_slist_free(fn_glist);
172 gtk_widget_destroy(dialog);
175 /* return the path and the file component contained in the full path */
176 static char *path_and_file(char *pathin, char **fileout) {
177 char *slash = pathin, *next;
182 *fileout = strdup("");
185 while ((next = strpbrk(slash + 1, "\\/")))
189 *fileout = strdup(slash);
191 /* strndup(pathin, slash - pathin) */
193 len = strlen(pathin);
197 result = (char *)malloc(len + 1);
202 return (char *)memcpy(result, pathin, len);
205 static void file_save_as(GtkWidget *w, gpointer data)
208 char *filename = NULL;
212 dialog = gtk_file_chooser_dialog_new("Save File As",
213 GTK_WINDOW(main_window),
214 GTK_FILE_CHOOSER_ACTION_SAVE,
215 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
216 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
218 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
220 current_dir = path_and_file(existing_filename, ¤t_file);
221 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), current_dir);
222 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), current_file);
227 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
228 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
230 gtk_widget_destroy(dialog);
233 save_dives(filename);
234 set_filename(filename);
236 mark_divelist_changed(FALSE);
240 static void file_save(GtkWidget *w, gpointer data)
242 if (!existing_filename)
243 return file_save_as(w, data);
245 save_dives(existing_filename);
246 mark_divelist_changed(FALSE);
249 static gboolean ask_save_changes()
251 GtkWidget *dialog, *label, *content;
252 gboolean quit = TRUE;
253 dialog = gtk_dialog_new_with_buttons("Save Changes?",
254 GTK_WINDOW(main_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
255 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
256 GTK_STOCK_NO, GTK_RESPONSE_NO,
257 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
259 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
261 if (!existing_filename){
262 label = gtk_label_new (
263 "You have unsaved changes\nWould you like to save those before exiting the program?");
265 char *label_text = (char*) malloc(sizeof(char) * (93 + strlen(existing_filename)));
267 "You have unsaved changes to file: %s \nWould you like to save those before exiting the program?",
269 label = gtk_label_new (label_text);
272 gtk_container_add (GTK_CONTAINER (content), label);
273 gtk_widget_show_all (dialog);
274 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
275 gint outcode = gtk_dialog_run(GTK_DIALOG(dialog));
276 if (outcode == GTK_RESPONSE_ACCEPT) {
277 file_save(NULL,NULL);
278 } else if (outcode == GTK_RESPONSE_CANCEL) {
281 gtk_widget_destroy(dialog);
285 static gboolean on_delete(GtkWidget* w, gpointer data)
287 /* Make sure to flush any modified dive data */
290 gboolean quit = TRUE;
291 if (unsaved_changes())
292 quit = ask_save_changes();
295 return FALSE; /* go ahead, kill the program, we're good now */
297 return TRUE; /* We are not leaving */
301 static void on_destroy(GtkWidget* w, gpointer data)
306 static void quit(GtkWidget *w, gpointer data)
308 /* Make sure to flush any modified dive data */
311 gboolean quit = TRUE;
312 if (unsaved_changes())
313 quit = ask_save_changes();
320 GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
321 data_func_t data_func, unsigned int flags)
323 GtkCellRenderer *renderer;
324 GtkTreeViewColumn *col;
325 double xalign = 0.0; /* left as default */
326 PangoAlignment align;
329 align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT :
330 (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT :
332 visible = !(flags & INVISIBLE);
334 renderer = gtk_cell_renderer_text_new();
335 col = gtk_tree_view_column_new();
337 gtk_tree_view_column_set_title(col, title);
338 if (!(flags & UNSORTABLE))
339 gtk_tree_view_column_set_sort_column_id(col, index);
340 gtk_tree_view_column_set_resizable(col, TRUE);
341 gtk_tree_view_column_pack_start(col, renderer, TRUE);
343 gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, (void *)(long)index, NULL);
345 gtk_tree_view_column_add_attribute(col, renderer, "text", index);
346 gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
348 case PANGO_ALIGN_LEFT:
351 case PANGO_ALIGN_CENTER:
354 case PANGO_ALIGN_RIGHT:
358 gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
359 gtk_tree_view_column_set_visible(col, visible);
360 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
364 static void create_radio(GtkWidget *vbox, const char *w_name, ...)
367 GtkRadioButton *group = NULL;
368 GtkWidget *box, *label;
370 box = gtk_hbox_new(TRUE, 10);
371 gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 0);
373 label = gtk_label_new(w_name);
374 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
376 va_start(args, w_name);
383 name = va_arg(args, char *);
386 callback_fn = va_arg(args, void *);
387 enabled = va_arg(args, int);
389 button = gtk_radio_button_new_with_label_from_widget(group, name);
390 group = GTK_RADIO_BUTTON(button);
391 gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
392 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), enabled);
393 g_signal_connect(button, "toggled", G_CALLBACK(callback_fn), NULL);
398 #define UNITCALLBACK(name, type, value) \
399 static void name(GtkWidget *w, gpointer data) \
401 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) \
402 menu_units.type = value; \
405 static struct units menu_units;
407 UNITCALLBACK(set_meter, length, METERS)
408 UNITCALLBACK(set_feet, length, FEET)
409 UNITCALLBACK(set_bar, pressure, BAR)
410 UNITCALLBACK(set_psi, pressure, PSI)
411 UNITCALLBACK(set_liter, volume, LITER)
412 UNITCALLBACK(set_cuft, volume, CUFT)
413 UNITCALLBACK(set_celsius, temperature, CELSIUS)
414 UNITCALLBACK(set_fahrenheit, temperature, FAHRENHEIT)
415 UNITCALLBACK(set_kg, weight, KG)
416 UNITCALLBACK(set_lbs, weight, LBS)
418 #define OPTIONCALLBACK(name, option) \
419 static void name(GtkWidget *w, gpointer data) \
421 option = GTK_TOGGLE_BUTTON(w)->active; \
424 OPTIONCALLBACK(otu_toggle, visible_cols.otu)
425 OPTIONCALLBACK(sac_toggle, visible_cols.sac)
426 OPTIONCALLBACK(nitrox_toggle, visible_cols.nitrox)
427 OPTIONCALLBACK(temperature_toggle, visible_cols.temperature)
428 OPTIONCALLBACK(totalweight_toggle, visible_cols.totalweight)
429 OPTIONCALLBACK(suit_toggle, visible_cols.suit)
430 OPTIONCALLBACK(cylinder_toggle, visible_cols.cylinder)
431 OPTIONCALLBACK(autogroup_toggle, autogroup)
433 static void event_toggle(GtkWidget *w, gpointer _data)
435 gboolean *plot_ev = _data;
437 *plot_ev = GTK_TOGGLE_BUTTON(w)->active;
440 static void preferences_dialog(GtkWidget *w, gpointer data)
443 GtkWidget *dialog, *font, *frame, *box, *vbox, *button;
445 menu_units = output_units;
447 dialog = gtk_dialog_new_with_buttons("Preferences",
448 GTK_WINDOW(main_window),
449 GTK_DIALOG_DESTROY_WITH_PARENT,
450 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
451 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
454 frame = gtk_frame_new("Units");
455 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
456 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
458 box = gtk_vbox_new(FALSE, 6);
459 gtk_container_add(GTK_CONTAINER(frame), box);
461 create_radio(box, "Depth:",
462 "Meter", set_meter, (output_units.length == METERS),
463 "Feet", set_feet, (output_units.length == FEET),
466 create_radio(box, "Pressure:",
467 "Bar", set_bar, (output_units.pressure == BAR),
468 "PSI", set_psi, (output_units.pressure == PSI),
471 create_radio(box, "Volume:",
472 "Liter", set_liter, (output_units.volume == LITER),
473 "CuFt", set_cuft, (output_units.volume == CUFT),
476 create_radio(box, "Temperature:",
477 "Celsius", set_celsius, (output_units.temperature == CELSIUS),
478 "Fahrenheit", set_fahrenheit, (output_units.temperature == FAHRENHEIT),
481 create_radio(box, "Weight:",
482 "kg", set_kg, (output_units.weight == KG),
483 "lbs", set_lbs, (output_units.weight == LBS),
486 frame = gtk_frame_new("Show Columns");
487 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
489 box = gtk_hbox_new(FALSE, 6);
490 gtk_container_add(GTK_CONTAINER(frame), box);
492 button = gtk_check_button_new_with_label("Temp");
493 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.temperature);
494 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
495 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(temperature_toggle), NULL);
497 button = gtk_check_button_new_with_label("Cyl");
498 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.cylinder);
499 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
500 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(cylinder_toggle), NULL);
502 button = gtk_check_button_new_with_label("O" UTF8_SUBSCRIPT_2 "%");
503 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.nitrox);
504 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
505 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(nitrox_toggle), NULL);
507 button = gtk_check_button_new_with_label("SAC");
508 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.sac);
509 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
510 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(sac_toggle), NULL);
512 button = gtk_check_button_new_with_label("OTU");
513 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.otu);
514 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
515 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(otu_toggle), NULL);
517 button = gtk_check_button_new_with_label("Weight");
518 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.totalweight);
519 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
520 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(totalweight_toggle), NULL);
522 button = gtk_check_button_new_with_label("Suit");
523 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.suit);
524 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
525 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(suit_toggle), NULL);
527 frame = gtk_frame_new("Divelist Font");
528 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
530 font = gtk_font_button_new_with_font(divelist_font);
531 gtk_container_add(GTK_CONTAINER(frame),font);
533 frame = gtk_frame_new("Misc. Options");
534 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
536 box = gtk_hbox_new(FALSE, 6);
537 gtk_container_add(GTK_CONTAINER(frame), box);
539 button = gtk_check_button_new_with_label("Automatically group dives in trips");
540 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), autogroup);
541 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
542 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(autogroup_toggle), NULL);
544 gtk_widget_show_all(dialog);
545 result = gtk_dialog_run(GTK_DIALOG(dialog));
546 if (result == GTK_RESPONSE_ACCEPT) {
547 /* Make sure to flush any modified old dive data with old units */
550 divelist_font = strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON(font)));
551 set_divelist_font(divelist_font);
553 output_units = menu_units;
554 update_dive_list_units();
556 update_dive_list_col_visibility();
558 subsurface_set_conf("feet", PREF_BOOL, BOOL_TO_PTR(output_units.length == FEET));
559 subsurface_set_conf("psi", PREF_BOOL, BOOL_TO_PTR(output_units.pressure == PSI));
560 subsurface_set_conf("cuft", PREF_BOOL, BOOL_TO_PTR(output_units.volume == CUFT));
561 subsurface_set_conf("fahrenheit", PREF_BOOL, BOOL_TO_PTR(output_units.temperature == FAHRENHEIT));
562 subsurface_set_conf("lbs", PREF_BOOL, BOOL_TO_PTR(output_units.weight == LBS));
563 subsurface_set_conf("TEMPERATURE", PREF_BOOL, BOOL_TO_PTR(visible_cols.temperature));
564 subsurface_set_conf("TOTALWEIGHT", PREF_BOOL, BOOL_TO_PTR(visible_cols.totalweight));
565 subsurface_set_conf("SUIT", PREF_BOOL, BOOL_TO_PTR(visible_cols.suit));
566 subsurface_set_conf("CYLINDER", PREF_BOOL, BOOL_TO_PTR(visible_cols.cylinder));
567 subsurface_set_conf("NITROX", PREF_BOOL, BOOL_TO_PTR(visible_cols.nitrox));
568 subsurface_set_conf("SAC", PREF_BOOL, BOOL_TO_PTR(visible_cols.sac));
569 subsurface_set_conf("OTU", PREF_BOOL, BOOL_TO_PTR(visible_cols.otu));
570 subsurface_set_conf("divelist_font", PREF_STRING, divelist_font);
571 subsurface_set_conf("autogroup", PREF_BOOL, BOOL_TO_PTR(autogroup));
573 /* Flush the changes out to the system */
574 subsurface_flush_conf();
576 gtk_widget_destroy(dialog);
579 static void create_toggle(const char* label, int *on, void *_data)
581 GtkWidget *button, *table = _data;
582 int rows, cols, x, y;
586 /* magic way to reset the number of toggle buttons
587 * that we have already added - call this before you
588 * create the dialog */
592 g_object_get(G_OBJECT(table), "n-columns", &cols, "n-rows", &rows, NULL);
593 if (count > rows * cols) {
594 gtk_table_resize(GTK_TABLE(table),rows+1,cols);
599 button = gtk_check_button_new_with_label(label);
600 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), *on);
601 gtk_table_attach_defaults(GTK_TABLE(table), button, x, x+1, y, y+1);
602 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(event_toggle), on);
606 static void selectevents_dialog(GtkWidget *w, gpointer data)
609 GtkWidget *dialog, *frame, *vbox, *table;
611 dialog = gtk_dialog_new_with_buttons("SelectEvents",
612 GTK_WINDOW(main_window),
613 GTK_DIALOG_DESTROY_WITH_PARENT,
614 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
615 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
617 /* initialize the function that fills the table */
618 create_toggle(NULL, NULL, NULL);
620 frame = gtk_frame_new("Enable / Disable Events");
621 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
622 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
624 table = gtk_table_new(1, 4, TRUE);
625 gtk_container_add(GTK_CONTAINER(frame), table);
627 evn_foreach(&create_toggle, table);
629 gtk_widget_show_all(dialog);
630 result = gtk_dialog_run(GTK_DIALOG(dialog));
631 if (result == GTK_RESPONSE_ACCEPT) {
634 gtk_widget_destroy(dialog);
637 static void renumber_dialog(GtkWidget *w, gpointer data)
641 GtkWidget *dialog, *frame, *button, *vbox;
643 dialog = gtk_dialog_new_with_buttons("Renumber",
644 GTK_WINDOW(main_window),
645 GTK_DIALOG_DESTROY_WITH_PARENT,
646 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
647 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
650 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
652 frame = gtk_frame_new("New starting number");
653 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
655 button = gtk_spin_button_new_with_range(1, 50000, 1);
656 gtk_container_add(GTK_CONTAINER(frame), button);
659 * Do we have a number for the first dive already? Use that
663 if (dive && dive->number)
664 gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), dive->number);
666 gtk_widget_show_all(dialog);
667 result = gtk_dialog_run(GTK_DIALOG(dialog));
668 if (result == GTK_RESPONSE_ACCEPT) {
669 int nr = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button));
673 gtk_widget_destroy(dialog);
676 static void about_dialog(GtkWidget *w, gpointer data)
678 const char *logo_property = NULL;
679 GdkPixbuf *logo = NULL;
682 GtkWidget *image = gtk_image_new_from_file(subsurface_icon_name());
685 logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
686 logo_property = "logo";
690 gtk_show_about_dialog(NULL,
691 "program-name", "SubSurface",
692 "comments", "Half-arsed divelog software in C",
694 "version", VERSION_STRING,
695 "copyright", "Linus Torvalds 2011",
696 "logo-icon-name", "subsurface",
702 static void view_list(GtkWidget *w, gpointer data)
704 gtk_paned_set_position(GTK_PANED(vpane), 0);
707 static void view_profile(GtkWidget *w, gpointer data)
709 gtk_paned_set_position(GTK_PANED(hpane), 0);
710 gtk_paned_set_position(GTK_PANED(vpane), 65535);
713 static void view_info(GtkWidget *w, gpointer data)
715 gtk_paned_set_position(GTK_PANED(vpane), 65535);
716 gtk_paned_set_position(GTK_PANED(hpane), 65535);
719 static void view_three(GtkWidget *w, gpointer data)
722 GtkRequisition requisition;
724 gtk_widget_get_allocation(hpane, &alloc);
725 gtk_paned_set_position(GTK_PANED(hpane), alloc.width/2);
726 gtk_widget_get_allocation(vpane, &alloc);
727 gtk_widget_size_request(notebook, &requisition);
728 /* pick the requested size for the notebook plus 6 pixels for frame */
729 gtk_paned_set_position(GTK_PANED(vpane), requisition.height + 6);
732 static void toggle_zoom(GtkWidget *w, gpointer data)
734 zoomed_plot = (zoomed_plot)?0 : 1;
739 static GtkActionEntry menu_items[] = {
740 { "FileMenuAction", NULL, "File", NULL, NULL, NULL},
741 { "LogMenuAction", NULL, "Log", NULL, NULL, NULL},
742 { "ViewMenuAction", NULL, "View", NULL, NULL, NULL},
743 { "FilterMenuAction", NULL, "Filter", NULL, NULL, NULL},
744 { "HelpMenuAction", NULL, "Help", NULL, NULL, NULL},
745 { "OpenFile", GTK_STOCK_OPEN, NULL, CTRLCHAR "O", NULL, G_CALLBACK(file_open) },
746 { "SaveFile", GTK_STOCK_SAVE, NULL, CTRLCHAR "S", NULL, G_CALLBACK(file_save) },
747 { "SaveAsFile", GTK_STOCK_SAVE_AS, NULL, SHIFTCHAR CTRLCHAR "S", NULL, G_CALLBACK(file_save_as) },
748 { "Print", GTK_STOCK_PRINT, NULL, CTRLCHAR "P", NULL, G_CALLBACK(do_print) },
749 { "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) },
750 { "AddDive", GTK_STOCK_ADD, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) },
751 { "Preferences", GTK_STOCK_PREFERENCES, "Preferences", PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) },
752 { "Renumber", NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) },
753 { "SelectEvents", NULL, "SelectEvents", NULL, NULL, G_CALLBACK(selectevents_dialog) },
754 { "Quit", GTK_STOCK_QUIT, NULL, CTRLCHAR "Q", NULL, G_CALLBACK(quit) },
755 { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) },
756 { "ViewList", NULL, "List", CTRLCHAR "1", NULL, G_CALLBACK(view_list) },
757 { "ViewProfile", NULL, "Profile", CTRLCHAR "2", NULL, G_CALLBACK(view_profile) },
758 { "ViewInfo", NULL, "Info", CTRLCHAR "3", NULL, G_CALLBACK(view_info) },
759 { "ViewThree", NULL, "Three", CTRLCHAR "4", NULL, G_CALLBACK(view_three) },
760 { "ToggleZoom", NULL, "Toggle Zoom", CTRLCHAR "0", NULL, G_CALLBACK(toggle_zoom) },
762 static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
764 static const gchar* ui_string = " \
766 <menubar name=\"MainMenu\"> \
767 <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
768 <menuitem name=\"Open\" action=\"OpenFile\" /> \
769 <menuitem name=\"Save\" action=\"SaveFile\" /> \
770 <menuitem name=\"Save As\" action=\"SaveAsFile\" /> \
771 <menuitem name=\"Print\" action=\"Print\" /> \
772 <separator name=\"Separator1\"/> \
773 <menuitem name=\"Preferences\" action=\"Preferences\" /> \
774 <separator name=\"Separator2\"/> \
775 <menuitem name=\"Quit\" action=\"Quit\" /> \
777 <menu name=\"LogMenu\" action=\"LogMenuAction\"> \
778 <menuitem name=\"Import\" action=\"Import\" /> \
779 <menuitem name=\"Add Dive\" action=\"AddDive\" /> \
780 <separator name=\"Separator\"/> \
781 <menuitem name=\"Renumber\" action=\"Renumber\" /> \
782 <menuitem name=\"Toggle Zoom\" action=\"ToggleZoom\" /> \
783 <menu name=\"View\" action=\"ViewMenuAction\"> \
784 <menuitem name=\"List\" action=\"ViewList\" /> \
785 <menuitem name=\"Profile\" action=\"ViewProfile\" /> \
786 <menuitem name=\"Info\" action=\"ViewInfo\" /> \
787 <menuitem name=\"Paned\" action=\"ViewThree\" /> \
790 <menu name=\"FilterMenu\" action=\"FilterMenuAction\"> \
791 <menuitem name=\"SelectEvents\" action=\"SelectEvents\" /> \
793 <menu name=\"Help\" action=\"HelpMenuAction\"> \
794 <menuitem name=\"About\" action=\"About\" /> \
800 static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
802 GtkActionGroup *action_group = gtk_action_group_new("Menu");
803 gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
805 gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
807 gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
809 gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
810 GtkWidget* menu = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
815 static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data)
820 void init_ui(int *argcp, char ***argvp)
824 GtkWidget *dive_list;
829 GtkIconTheme *icon_theme=NULL;
830 GtkSettings *settings;
831 GtkUIManager *ui_manager;
833 gtk_init(argcp, argvp);
834 settings = gtk_settings_get_default();
835 gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "subsurface setting");
839 subsurface_open_conf();
840 if (subsurface_get_conf("feet", PREF_BOOL))
841 output_units.length = FEET;
842 if (subsurface_get_conf("psi", PREF_BOOL))
843 output_units.pressure = PSI;
844 if (subsurface_get_conf("cuft", PREF_BOOL))
845 output_units.volume = CUFT;
846 if (subsurface_get_conf("fahrenheit", PREF_BOOL))
847 output_units.temperature = FAHRENHEIT;
848 if (subsurface_get_conf("lbs", PREF_BOOL))
849 output_units.weight = LBS;
850 /* an unset key is FALSE - all these are hidden by default */
851 visible_cols.cylinder = PTR_TO_BOOL(subsurface_get_conf("CYLINDER", PREF_BOOL));
852 visible_cols.temperature = PTR_TO_BOOL(subsurface_get_conf("TEMPERATURE", PREF_BOOL));
853 visible_cols.totalweight = PTR_TO_BOOL(subsurface_get_conf("TOTALWEIGHT", PREF_BOOL));
854 visible_cols.suit = PTR_TO_BOOL(subsurface_get_conf("SUIT", PREF_BOOL));
855 visible_cols.nitrox = PTR_TO_BOOL(subsurface_get_conf("NITROX", PREF_BOOL));
856 visible_cols.otu = PTR_TO_BOOL(subsurface_get_conf("OTU", PREF_BOOL));
857 visible_cols.sac = PTR_TO_BOOL(subsurface_get_conf("SAC", PREF_BOOL));
859 divelist_font = subsurface_get_conf("divelist_font", PREF_STRING);
861 autogroup = PTR_TO_BOOL(subsurface_get_conf("autogroup", PREF_BOOL));
863 default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING);
864 default_dive_computer_product = subsurface_get_conf("dive_computer_product", PREF_STRING);
865 default_dive_computer_device = subsurface_get_conf("dive_computer_device", PREF_STRING);
867 error_info_bar = NULL;
868 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
869 g_set_application_name ("subsurface");
870 /* Let's check if the subsurface icon has been installed or if
871 * we need to try to load it from the current directory */
872 screen = gdk_screen_get_default();
874 icon_theme = gtk_icon_theme_get_for_screen(screen);
876 if (gtk_icon_theme_has_icon(icon_theme, "subsurface")) {
878 gtk_window_set_default_icon_name ("subsurface");
882 const char *icon_name = subsurface_icon_name();
883 if (!access(icon_name, R_OK))
884 gtk_window_set_icon_from_file(GTK_WINDOW(win), icon_name, NULL);
886 g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
887 g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
890 vbox = gtk_vbox_new(FALSE, 0);
891 gtk_container_add(GTK_CONTAINER(win), vbox);
894 ui_manager = gtk_ui_manager_new();
895 menubar = get_menubar_menu(win, ui_manager);
897 subsurface_ui_setup(settings, menubar, vbox, ui_manager);
899 vpane = gtk_vpaned_new();
900 gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 3);
901 hpane = gtk_hpaned_new();
902 gtk_paned_add1(GTK_PANED(vpane), hpane);
903 g_signal_connect_after(G_OBJECT(vbox), "realize", G_CALLBACK(view_three), NULL);
905 /* Notebook for dive info vs profile vs .. */
906 notebook = gtk_notebook_new();
907 scrolled = gtk_scrolled_window_new(NULL, NULL);
908 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
909 gtk_paned_add1(GTK_PANED(hpane), scrolled);
910 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), notebook);
911 g_signal_connect(notebook, "switch-page", G_CALLBACK(switch_page), NULL);
913 /* Create the actual divelist */
914 dive_list = dive_list_create();
915 gtk_widget_set_name(dive_list, "Dive List");
916 gtk_paned_add2(GTK_PANED(vpane), dive_list);
918 /* Frame for dive profile */
919 dive_profile = dive_profile_widget();
920 gtk_widget_set_name(dive_profile, "Dive Profile");
921 gtk_paned_add2(GTK_PANED(hpane), dive_profile);
923 /* Frame for extended dive info */
924 nb_page = extended_dive_info_widget();
925 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Dive Notes"));
927 /* Frame for dive equipment */
928 nb_page = equipment_widget(W_IDX_PRIMARY);
929 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Equipment"));
931 /* Frame for single dive statistics */
932 nb_page = single_stats_widget();
933 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Dive Info"));
935 /* Frame for total dive statistics */
936 nb_page = total_stats_widget();
937 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Stats"));
939 gtk_widget_set_app_paintable(win, TRUE);
940 gtk_widget_show_all(win);
952 subsurface_close_conf();
956 cairo_rectangle_int_t rect;
960 static tooltip_record_t *tooltip_rects;
963 void attach_tooltip(int x, int y, int w, int h, const char *text)
965 cairo_rectangle_int_t *rect;
966 tooltip_rects = realloc(tooltip_rects, (tooltips + 1) * sizeof(tooltip_record_t));
967 rect = &tooltip_rects[tooltips].rect;
972 tooltip_rects[tooltips].text = text;
976 #define INSIDE_RECT(_r,_x,_y) ((_r.x <= _x) && (_r.x + _r.width >= _x) && \
977 (_r.y <= _y) && (_r.y + _r.height >= _y))
979 static gboolean profile_tooltip (GtkWidget *widget, gint x, gint y,
980 gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data)
983 cairo_rectangle_int_t *drawing_area = user_data;
984 gint tx = x - drawing_area->x; /* get transformed coordinates */
985 gint ty = y - drawing_area->y;
987 /* are we over an event marker ? */
988 for (i = 0; i < tooltips; i++) {
989 if (INSIDE_RECT(tooltip_rects[i].rect, tx, ty)) {
990 gtk_tooltip_set_text(tooltip,tooltip_rects[i].text);
991 return TRUE; /* show tooltip */
994 return FALSE; /* don't show tooltip */
997 static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
999 struct dive *dive = current_dive;
1000 struct graphics_context gc = { .printer = 0 };
1001 static cairo_rectangle_int_t drawing_area;
1003 /* the drawing area gives TOTAL width * height - x,y is used as the topx/topy offset
1004 * so effective drawing area is width-2x * height-2y */
1005 drawing_area.width = widget->allocation.width;
1006 drawing_area.height = widget->allocation.height;
1007 drawing_area.x = drawing_area.width / 20.0;
1008 drawing_area.y = drawing_area.height / 20.0;
1010 gc.cr = gdk_cairo_create(widget->window);
1011 g_object_set(widget, "has-tooltip", TRUE, NULL);
1012 g_signal_connect(widget, "query-tooltip", G_CALLBACK(profile_tooltip), &drawing_area);
1013 init_profile_background(&gc);
1017 if (tooltip_rects) {
1018 free(tooltip_rects);
1019 tooltip_rects = NULL;
1022 plot(&gc, &drawing_area, dive);
1024 cairo_destroy(gc.cr);
1029 GtkWidget *dive_profile_widget(void)
1033 da = gtk_drawing_area_new();
1034 gtk_widget_set_size_request(da, 350, 250);
1035 g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
1040 int process_ui_events(void)
1044 while (gtk_events_pending()) {
1045 if (gtk_main_iteration_do(0)) {
1053 static int fill_computer_list(GtkListStore *store)
1057 dc_iterator_t *iterator = NULL;
1058 dc_descriptor_t *descriptor = NULL;
1061 dc_descriptor_iterator(&iterator);
1062 while (dc_iterator_next (iterator, &descriptor) == DC_STATUS_SUCCESS) {
1063 const char *vendor = dc_descriptor_get_vendor(descriptor);
1064 const char *product = dc_descriptor_get_product(descriptor);
1066 gtk_list_store_append(store, &iter);
1067 gtk_list_store_set(store, &iter,
1070 if (is_default_dive_computer(vendor, product))
1074 dc_iterator_free(iterator);
1078 void render_dive_computer(GtkCellLayout *cell,
1079 GtkCellRenderer *renderer,
1080 GtkTreeModel *model,
1085 dc_descriptor_t *descriptor = NULL;
1086 const char *vendor, *product;
1088 gtk_tree_model_get(model, iter, 0, &descriptor, -1);
1089 vendor = dc_descriptor_get_vendor(descriptor);
1090 product = dc_descriptor_get_product(descriptor);
1091 snprintf(buffer, sizeof(buffer), "%s %s", vendor, product);
1092 g_object_set(renderer, "text", buffer, NULL);
1096 static GtkComboBox *dive_computer_selector(GtkWidget *vbox)
1098 GtkWidget *hbox, *combo_box, *frame;
1099 GtkListStore *model;
1100 GtkCellRenderer *renderer;
1103 hbox = gtk_hbox_new(FALSE, 6);
1104 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
1106 model = gtk_list_store_new(1, G_TYPE_POINTER);
1107 default_index = fill_computer_list(model);
1109 frame = gtk_frame_new("Dive computer");
1110 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
1112 combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
1113 gtk_container_add(GTK_CONTAINER(frame), combo_box);
1115 renderer = gtk_cell_renderer_text_new();
1116 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
1117 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo_box), renderer, render_dive_computer, NULL, NULL);
1119 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), default_index);
1121 return GTK_COMBO_BOX(combo_box);
1124 const char *subsurface_device_name()
1126 if (!default_dive_computer_device || !*default_dive_computer_device)
1127 return subsurface_USB_name();
1129 return default_dive_computer_device;
1132 static GtkEntry *dive_computer_device(GtkWidget *vbox)
1134 GtkWidget *hbox, *entry, *frame;
1136 hbox = gtk_hbox_new(FALSE, 6);
1137 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
1139 frame = gtk_frame_new("Device name");
1140 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
1142 entry = gtk_entry_new();
1143 gtk_container_add(GTK_CONTAINER(frame), entry);
1144 gtk_entry_set_text(GTK_ENTRY(entry), subsurface_device_name());
1146 return GTK_ENTRY(entry);
1149 /* once a file is selected in the FileChooserButton we want to exit the import dialog */
1150 static void on_file_set(GtkFileChooserButton *widget, gpointer _data)
1152 GtkDialog *main_dialog = _data;
1154 gtk_dialog_response(main_dialog, GTK_RESPONSE_ACCEPT);
1157 static GtkWidget *xml_file_selector(GtkWidget *vbox, GtkWidget *main_dialog)
1159 GtkWidget *hbox, *frame, *chooser, *dialog;
1160 GtkFileFilter *filter;
1162 hbox = gtk_hbox_new(FALSE, 6);
1163 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
1165 frame = gtk_frame_new("XML file name");
1166 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
1167 dialog = gtk_file_chooser_dialog_new("Open XML File",
1168 GTK_WINDOW(main_window),
1169 GTK_FILE_CHOOSER_ACTION_OPEN,
1170 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1171 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1173 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
1175 filter = gtk_file_filter_new();
1176 gtk_file_filter_add_pattern(filter, "*.xml");
1177 gtk_file_filter_add_pattern(filter, "*.XML");
1178 gtk_file_filter_add_pattern(filter, "*.sda");
1179 gtk_file_filter_add_pattern(filter, "*.SDA");
1180 gtk_file_filter_add_mime_type(filter, "text/xml");
1181 gtk_file_filter_set_name(filter, "XML file");
1182 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
1184 chooser = gtk_file_chooser_button_new_with_dialog(dialog);
1185 g_signal_connect(G_OBJECT(chooser), "file-set", G_CALLBACK(on_file_set), main_dialog);
1187 gtk_file_chooser_button_set_width_chars(GTK_FILE_CHOOSER_BUTTON(chooser), 30);
1188 gtk_container_add(GTK_CONTAINER(frame), chooser);
1193 static void do_import_file(gpointer data, gpointer user_data)
1195 GError *error = NULL;
1196 parse_file(data, &error);
1200 report_error(error);
1201 g_error_free(error);
1206 static GtkWidget *import_dive_computer(device_data_t *data, GtkDialog *dialog)
1209 GtkWidget *vbox, *info, *container, *label, *button;
1211 error = do_import(data);
1215 button = gtk_dialog_get_widget_for_response(dialog, GTK_RESPONSE_ACCEPT);
1216 gtk_button_set_use_stock(GTK_BUTTON(button), 0);
1217 gtk_button_set_label(GTK_BUTTON(button), "Retry");
1219 vbox = gtk_dialog_get_content_area(dialog);
1221 info = gtk_info_bar_new();
1222 container = gtk_info_bar_get_content_area(GTK_INFO_BAR(info));
1223 label = gtk_label_new(error->message);
1224 gtk_container_add(GTK_CONTAINER(container), label);
1225 gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0);
1229 void import_dialog(GtkWidget *w, gpointer data)
1232 GtkWidget *dialog, *hbox, *vbox, *label, *info = NULL;
1233 GtkComboBox *computer;
1235 GtkWidget *XMLchooser;
1236 device_data_t devicedata = {
1240 dialog = gtk_dialog_new_with_buttons("Import from dive computer",
1241 GTK_WINDOW(main_window),
1242 GTK_DIALOG_DESTROY_WITH_PARENT,
1243 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1244 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1247 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
1248 label = gtk_label_new("Import: \nLoad XML file or import directly from dive computer");
1249 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 3);
1250 XMLchooser = xml_file_selector(vbox, dialog);
1251 computer = dive_computer_selector(vbox);
1252 device = dive_computer_device(vbox);
1253 hbox = gtk_hbox_new(FALSE, 6);
1254 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 3);
1255 devicedata.progress.bar = gtk_progress_bar_new();
1256 gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress.bar);
1259 gtk_widget_show_all(dialog);
1260 result = gtk_dialog_run(GTK_DIALOG(dialog));
1262 dc_descriptor_t *descriptor;
1264 GtkTreeModel *model;
1266 case GTK_RESPONSE_ACCEPT:
1267 /* what happened - did the user pick a file? In that case
1268 * we ignore whether a dive computer model was picked */
1270 gtk_widget_destroy(info);
1271 list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(XMLchooser));
1272 if (g_slist_length(list) == 0) {
1273 const char *vendor, *product;
1275 if (!gtk_combo_box_get_active_iter(computer, &iter))
1277 model = gtk_combo_box_get_model(computer);
1278 gtk_tree_model_get(model, &iter,
1282 vendor = dc_descriptor_get_vendor(descriptor);
1283 product = dc_descriptor_get_product(descriptor);
1285 devicedata.descriptor = descriptor;
1286 devicedata.vendor = vendor;
1287 devicedata.product = product;
1288 devicedata.devname = gtk_entry_get_text(device);
1289 set_default_dive_computer(vendor, product);
1290 set_default_dive_computer_device(devicedata.devname);
1291 info = import_dive_computer(&devicedata, GTK_DIALOG(dialog));
1295 g_slist_foreach(list,do_import_file,NULL);
1302 gtk_widget_destroy(dialog);
1307 void update_progressbar(progressbar_t *progress, double value)
1309 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), value);
1312 void update_progressbar_text(progressbar_t *progress, const char *text)
1314 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), text);
1317 void set_filename(const char *filename)
1319 if (existing_filename)
1320 free(existing_filename);
1321 existing_filename = NULL;
1323 existing_filename = strdup(filename);