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) * (92 + 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 GtkActionEntry menu_items[] = {
733 { "FileMenuAction", NULL, "File", NULL, NULL, NULL},
734 { "LogMenuAction", NULL, "Log", NULL, NULL, NULL},
735 { "ViewMenuAction", NULL, "View", NULL, NULL, NULL},
736 { "FilterMenuAction", NULL, "Filter", NULL, NULL, NULL},
737 { "HelpMenuAction", NULL, "Help", NULL, NULL, NULL},
738 { "OpenFile", GTK_STOCK_OPEN, NULL, CTRLCHAR "O", NULL, G_CALLBACK(file_open) },
739 { "SaveFile", GTK_STOCK_SAVE, NULL, CTRLCHAR "S", NULL, G_CALLBACK(file_save) },
740 { "SaveAsFile", GTK_STOCK_SAVE_AS, NULL, SHIFTCHAR CTRLCHAR "S", NULL, G_CALLBACK(file_save_as) },
741 { "Print", GTK_STOCK_PRINT, NULL, CTRLCHAR "P", NULL, G_CALLBACK(do_print) },
742 { "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) },
743 { "AddDive", GTK_STOCK_ADD, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) },
744 { "Preferences", GTK_STOCK_PREFERENCES, "Preferences", PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) },
745 { "Renumber", NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) },
746 { "SelectEvents", NULL, "SelectEvents", NULL, NULL, G_CALLBACK(selectevents_dialog) },
747 { "Quit", GTK_STOCK_QUIT, NULL, CTRLCHAR "Q", NULL, G_CALLBACK(quit) },
748 { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) },
749 { "ViewList", NULL, "List", CTRLCHAR "1", NULL, G_CALLBACK(view_list) },
750 { "ViewProfile", NULL, "Profile", CTRLCHAR "2", NULL, G_CALLBACK(view_profile) },
751 { "ViewInfo", NULL, "Info", CTRLCHAR "3", NULL, G_CALLBACK(view_info) },
752 { "ViewThree", NULL, "Three", CTRLCHAR "4", NULL, G_CALLBACK(view_three) },
754 static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
756 static const gchar* ui_string = " \
758 <menubar name=\"MainMenu\"> \
759 <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
760 <menuitem name=\"Open\" action=\"OpenFile\" /> \
761 <menuitem name=\"Save\" action=\"SaveFile\" /> \
762 <menuitem name=\"Save As\" action=\"SaveAsFile\" /> \
763 <menuitem name=\"Print\" action=\"Print\" /> \
764 <separator name=\"Separator1\"/> \
765 <menuitem name=\"Preferences\" action=\"Preferences\" /> \
766 <separator name=\"Separator2\"/> \
767 <menuitem name=\"Quit\" action=\"Quit\" /> \
769 <menu name=\"LogMenu\" action=\"LogMenuAction\"> \
770 <menuitem name=\"Import\" action=\"Import\" /> \
771 <menuitem name=\"Add Dive\" action=\"AddDive\" /> \
772 <separator name=\"Separator\"/> \
773 <menuitem name=\"Renumber\" action=\"Renumber\" /> \
774 <menu name=\"View\" action=\"ViewMenuAction\"> \
775 <menuitem name=\"List\" action=\"ViewList\" /> \
776 <menuitem name=\"Profile\" action=\"ViewProfile\" /> \
777 <menuitem name=\"Info\" action=\"ViewInfo\" /> \
778 <menuitem name=\"Paned\" action=\"ViewThree\" /> \
781 <menu name=\"FilterMenu\" action=\"FilterMenuAction\"> \
782 <menuitem name=\"SelectEvents\" action=\"SelectEvents\" /> \
784 <menu name=\"Help\" action=\"HelpMenuAction\"> \
785 <menuitem name=\"About\" action=\"About\" /> \
791 static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
793 GtkActionGroup *action_group = gtk_action_group_new("Menu");
794 gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
796 gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
798 gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
800 gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
801 GtkWidget* menu = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
806 static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data)
811 void init_ui(int *argcp, char ***argvp)
815 GtkWidget *dive_list;
820 GtkIconTheme *icon_theme=NULL;
821 GtkSettings *settings;
822 GtkUIManager *ui_manager;
824 gtk_init(argcp, argvp);
825 settings = gtk_settings_get_default();
826 gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "subsurface setting");
830 subsurface_open_conf();
831 if (subsurface_get_conf("feet", PREF_BOOL))
832 output_units.length = FEET;
833 if (subsurface_get_conf("psi", PREF_BOOL))
834 output_units.pressure = PSI;
835 if (subsurface_get_conf("cuft", PREF_BOOL))
836 output_units.volume = CUFT;
837 if (subsurface_get_conf("fahrenheit", PREF_BOOL))
838 output_units.temperature = FAHRENHEIT;
839 if (subsurface_get_conf("lbs", PREF_BOOL))
840 output_units.weight = LBS;
841 /* an unset key is FALSE - all these are hidden by default */
842 visible_cols.cylinder = PTR_TO_BOOL(subsurface_get_conf("CYLINDER", PREF_BOOL));
843 visible_cols.temperature = PTR_TO_BOOL(subsurface_get_conf("TEMPERATURE", PREF_BOOL));
844 visible_cols.totalweight = PTR_TO_BOOL(subsurface_get_conf("TOTALWEIGHT", PREF_BOOL));
845 visible_cols.suit = PTR_TO_BOOL(subsurface_get_conf("SUIT", PREF_BOOL));
846 visible_cols.nitrox = PTR_TO_BOOL(subsurface_get_conf("NITROX", PREF_BOOL));
847 visible_cols.otu = PTR_TO_BOOL(subsurface_get_conf("OTU", PREF_BOOL));
848 visible_cols.sac = PTR_TO_BOOL(subsurface_get_conf("SAC", PREF_BOOL));
850 divelist_font = subsurface_get_conf("divelist_font", PREF_STRING);
852 autogroup = PTR_TO_BOOL(subsurface_get_conf("autogroup", PREF_BOOL));
854 default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING);
855 default_dive_computer_product = subsurface_get_conf("dive_computer_product", PREF_STRING);
856 default_dive_computer_device = subsurface_get_conf("dive_computer_device", PREF_STRING);
858 error_info_bar = NULL;
859 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
860 g_set_application_name ("subsurface");
861 /* Let's check if the subsurface icon has been installed or if
862 * we need to try to load it from the current directory */
863 screen = gdk_screen_get_default();
865 icon_theme = gtk_icon_theme_get_for_screen(screen);
867 if (gtk_icon_theme_has_icon(icon_theme, "subsurface")) {
869 gtk_window_set_default_icon_name ("subsurface");
873 const char *icon_name = subsurface_icon_name();
874 if (!access(icon_name, R_OK))
875 gtk_window_set_icon_from_file(GTK_WINDOW(win), icon_name, NULL);
877 g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
878 g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
881 vbox = gtk_vbox_new(FALSE, 0);
882 gtk_container_add(GTK_CONTAINER(win), vbox);
885 ui_manager = gtk_ui_manager_new();
886 menubar = get_menubar_menu(win, ui_manager);
888 subsurface_ui_setup(settings, menubar, vbox, ui_manager);
890 vpane = gtk_vpaned_new();
891 gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 3);
892 hpane = gtk_hpaned_new();
893 gtk_paned_add1(GTK_PANED(vpane), hpane);
894 g_signal_connect_after(G_OBJECT(vbox), "realize", G_CALLBACK(view_three), NULL);
896 /* Notebook for dive info vs profile vs .. */
897 notebook = gtk_notebook_new();
898 scrolled = gtk_scrolled_window_new(NULL, NULL);
899 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
900 gtk_paned_add1(GTK_PANED(hpane), scrolled);
901 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), notebook);
902 g_signal_connect(notebook, "switch-page", G_CALLBACK(switch_page), NULL);
904 /* Create the actual divelist */
905 dive_list = dive_list_create();
906 gtk_widget_set_name(dive_list, "Dive List");
907 gtk_paned_add2(GTK_PANED(vpane), dive_list);
909 /* Frame for dive profile */
910 dive_profile = dive_profile_widget();
911 gtk_widget_set_name(dive_profile, "Dive Profile");
912 gtk_paned_add2(GTK_PANED(hpane), dive_profile);
914 /* Frame for extended dive info */
915 nb_page = extended_dive_info_widget();
916 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Dive Notes"));
918 /* Frame for dive equipment */
919 nb_page = equipment_widget(W_IDX_PRIMARY);
920 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Equipment"));
922 /* Frame for single dive statistics */
923 nb_page = single_stats_widget();
924 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Dive Info"));
926 /* Frame for total dive statistics */
927 nb_page = total_stats_widget();
928 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Stats"));
930 gtk_widget_set_app_paintable(win, TRUE);
931 gtk_widget_show_all(win);
943 subsurface_close_conf();
947 cairo_rectangle_int_t rect;
951 static tooltip_record_t *tooltip_rects;
954 void attach_tooltip(int x, int y, int w, int h, const char *text)
956 cairo_rectangle_int_t *rect;
957 tooltip_rects = realloc(tooltip_rects, (tooltips + 1) * sizeof(tooltip_record_t));
958 rect = &tooltip_rects[tooltips].rect;
963 tooltip_rects[tooltips].text = text;
967 #define INSIDE_RECT(_r,_x,_y) ((_r.x <= _x) && (_r.x + _r.width >= _x) && \
968 (_r.y <= _y) && (_r.y + _r.height >= _y))
970 static gboolean profile_tooltip (GtkWidget *widget, gint x, gint y,
971 gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data)
974 cairo_rectangle_int_t *drawing_area = user_data;
975 gint tx = x - drawing_area->x; /* get transformed coordinates */
976 gint ty = y - drawing_area->y;
978 /* are we over an event marker ? */
979 for (i = 0; i < tooltips; i++) {
980 if (INSIDE_RECT(tooltip_rects[i].rect, tx, ty)) {
981 gtk_tooltip_set_text(tooltip,tooltip_rects[i].text);
982 return TRUE; /* show tooltip */
985 return FALSE; /* don't show tooltip */
988 static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
990 struct dive *dive = current_dive;
991 struct graphics_context gc = { .printer = 0 };
992 static cairo_rectangle_int_t drawing_area;
994 /* the drawing area gives TOTAL width * height - x,y is used as the topx/topy offset
995 * so effective drawing area is width-2x * height-2y */
996 drawing_area.width = widget->allocation.width;
997 drawing_area.height = widget->allocation.height;
998 drawing_area.x = drawing_area.width / 20.0;
999 drawing_area.y = drawing_area.height / 20.0;
1001 gc.cr = gdk_cairo_create(widget->window);
1002 g_object_set(widget, "has-tooltip", TRUE, NULL);
1003 g_signal_connect(widget, "query-tooltip", G_CALLBACK(profile_tooltip), &drawing_area);
1004 init_profile_background(&gc);
1008 if (tooltip_rects) {
1009 free(tooltip_rects);
1010 tooltip_rects = NULL;
1013 plot(&gc, &drawing_area, dive);
1015 cairo_destroy(gc.cr);
1020 GtkWidget *dive_profile_widget(void)
1024 da = gtk_drawing_area_new();
1025 gtk_widget_set_size_request(da, 350, 250);
1026 g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
1031 int process_ui_events(void)
1035 while (gtk_events_pending()) {
1036 if (gtk_main_iteration_do(0)) {
1044 static int fill_computer_list(GtkListStore *store)
1048 dc_iterator_t *iterator = NULL;
1049 dc_descriptor_t *descriptor = NULL;
1052 dc_descriptor_iterator(&iterator);
1053 while (dc_iterator_next (iterator, &descriptor) == DC_STATUS_SUCCESS) {
1054 const char *vendor = dc_descriptor_get_vendor(descriptor);
1055 const char *product = dc_descriptor_get_product(descriptor);
1057 gtk_list_store_append(store, &iter);
1058 gtk_list_store_set(store, &iter,
1061 if (is_default_dive_computer(vendor, product))
1065 dc_iterator_free(iterator);
1069 void render_dive_computer(GtkCellLayout *cell,
1070 GtkCellRenderer *renderer,
1071 GtkTreeModel *model,
1076 dc_descriptor_t *descriptor = NULL;
1077 const char *vendor, *product;
1079 gtk_tree_model_get(model, iter, 0, &descriptor, -1);
1080 vendor = dc_descriptor_get_vendor(descriptor);
1081 product = dc_descriptor_get_product(descriptor);
1082 snprintf(buffer, sizeof(buffer), "%s %s", vendor, product);
1083 g_object_set(renderer, "text", buffer, NULL);
1087 static GtkComboBox *dive_computer_selector(GtkWidget *vbox)
1089 GtkWidget *hbox, *combo_box, *frame;
1090 GtkListStore *model;
1091 GtkCellRenderer *renderer;
1094 hbox = gtk_hbox_new(FALSE, 6);
1095 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
1097 model = gtk_list_store_new(1, G_TYPE_POINTER);
1098 default_index = fill_computer_list(model);
1100 frame = gtk_frame_new("Dive computer");
1101 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
1103 combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
1104 gtk_container_add(GTK_CONTAINER(frame), combo_box);
1106 renderer = gtk_cell_renderer_text_new();
1107 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
1108 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo_box), renderer, render_dive_computer, NULL, NULL);
1110 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), default_index);
1112 return GTK_COMBO_BOX(combo_box);
1115 const char *subsurface_device_name()
1117 if (!default_dive_computer_device || !*default_dive_computer_device)
1118 return subsurface_USB_name();
1120 return default_dive_computer_device;
1123 static GtkEntry *dive_computer_device(GtkWidget *vbox)
1125 GtkWidget *hbox, *entry, *frame;
1127 hbox = gtk_hbox_new(FALSE, 6);
1128 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
1130 frame = gtk_frame_new("Device name");
1131 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
1133 entry = gtk_entry_new();
1134 gtk_container_add(GTK_CONTAINER(frame), entry);
1135 gtk_entry_set_text(GTK_ENTRY(entry), subsurface_device_name());
1137 return GTK_ENTRY(entry);
1140 /* once a file is selected in the FileChooserButton we want to exit the import dialog */
1141 static void on_file_set(GtkFileChooserButton *widget, gpointer _data)
1143 GtkDialog *main_dialog = _data;
1145 gtk_dialog_response(main_dialog, GTK_RESPONSE_ACCEPT);
1148 static GtkWidget *xml_file_selector(GtkWidget *vbox, GtkWidget *main_dialog)
1150 GtkWidget *hbox, *frame, *chooser, *dialog;
1151 GtkFileFilter *filter;
1153 hbox = gtk_hbox_new(FALSE, 6);
1154 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
1156 frame = gtk_frame_new("XML file name");
1157 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
1158 dialog = gtk_file_chooser_dialog_new("Open XML File",
1159 GTK_WINDOW(main_window),
1160 GTK_FILE_CHOOSER_ACTION_OPEN,
1161 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1162 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1164 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
1166 filter = gtk_file_filter_new();
1167 gtk_file_filter_add_pattern(filter, "*.xml");
1168 gtk_file_filter_add_pattern(filter, "*.XML");
1169 gtk_file_filter_add_pattern(filter, "*.sda");
1170 gtk_file_filter_add_pattern(filter, "*.SDA");
1171 gtk_file_filter_add_mime_type(filter, "text/xml");
1172 gtk_file_filter_set_name(filter, "XML file");
1173 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
1175 chooser = gtk_file_chooser_button_new_with_dialog(dialog);
1176 g_signal_connect(G_OBJECT(chooser), "file-set", G_CALLBACK(on_file_set), main_dialog);
1178 gtk_file_chooser_button_set_width_chars(GTK_FILE_CHOOSER_BUTTON(chooser), 30);
1179 gtk_container_add(GTK_CONTAINER(frame), chooser);
1184 static void do_import_file(gpointer data, gpointer user_data)
1186 GError *error = NULL;
1187 parse_file(data, &error);
1191 report_error(error);
1192 g_error_free(error);
1197 static GtkWidget *import_dive_computer(device_data_t *data, GtkDialog *dialog)
1200 GtkWidget *vbox, *info, *container, *label, *button;
1202 error = do_import(data);
1206 button = gtk_dialog_get_widget_for_response(dialog, GTK_RESPONSE_ACCEPT);
1207 gtk_button_set_use_stock(GTK_BUTTON(button), 0);
1208 gtk_button_set_label(GTK_BUTTON(button), "Retry");
1210 vbox = gtk_dialog_get_content_area(dialog);
1212 info = gtk_info_bar_new();
1213 container = gtk_info_bar_get_content_area(GTK_INFO_BAR(info));
1214 label = gtk_label_new(error->message);
1215 gtk_container_add(GTK_CONTAINER(container), label);
1216 gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0);
1220 void import_dialog(GtkWidget *w, gpointer data)
1223 GtkWidget *dialog, *hbox, *vbox, *label, *info = NULL;
1224 GtkComboBox *computer;
1226 GtkWidget *XMLchooser;
1227 device_data_t devicedata = {
1231 dialog = gtk_dialog_new_with_buttons("Import from dive computer",
1232 GTK_WINDOW(main_window),
1233 GTK_DIALOG_DESTROY_WITH_PARENT,
1234 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1235 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1238 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
1239 label = gtk_label_new("Import: \nLoad XML file or import directly from dive computer");
1240 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 3);
1241 XMLchooser = xml_file_selector(vbox, dialog);
1242 computer = dive_computer_selector(vbox);
1243 device = dive_computer_device(vbox);
1244 hbox = gtk_hbox_new(FALSE, 6);
1245 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 3);
1246 devicedata.progress.bar = gtk_progress_bar_new();
1247 gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress.bar);
1250 gtk_widget_show_all(dialog);
1251 result = gtk_dialog_run(GTK_DIALOG(dialog));
1253 dc_descriptor_t *descriptor;
1255 GtkTreeModel *model;
1257 case GTK_RESPONSE_ACCEPT:
1258 /* what happened - did the user pick a file? In that case
1259 * we ignore whether a dive computer model was picked */
1261 gtk_widget_destroy(info);
1262 list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(XMLchooser));
1263 if (g_slist_length(list) == 0) {
1264 const char *vendor, *product;
1266 if (!gtk_combo_box_get_active_iter(computer, &iter))
1268 model = gtk_combo_box_get_model(computer);
1269 gtk_tree_model_get(model, &iter,
1273 vendor = dc_descriptor_get_vendor(descriptor);
1274 product = dc_descriptor_get_product(descriptor);
1276 devicedata.descriptor = descriptor;
1277 devicedata.vendor = vendor;
1278 devicedata.product = product;
1279 devicedata.devname = gtk_entry_get_text(device);
1280 set_default_dive_computer(vendor, product);
1281 set_default_dive_computer_device(devicedata.devname);
1282 info = import_dive_computer(&devicedata, GTK_DIALOG(dialog));
1286 g_slist_foreach(list,do_import_file,NULL);
1293 gtk_widget_destroy(dialog);
1298 void update_progressbar(progressbar_t *progress, double value)
1300 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), value);
1303 void update_progressbar_text(progressbar_t *progress, const char *text)
1305 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), text);
1308 void set_filename(const char *filename)
1310 if (existing_filename)
1311 free(existing_filename);
1312 existing_filename = NULL;
1314 existing_filename = strdup(filename);