summaryrefslogtreecommitdiffstats
path: root/gtk-gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'gtk-gui.c')
-rw-r--r--gtk-gui.c155
1 files changed, 122 insertions, 33 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index 3994387ac..0c235b492 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -17,7 +17,7 @@
#include "libdivecomputer.h"
-GtkWidget *main_window;
+GtkWidget *main_window, *divelist_window;
GtkWidget *main_vbox;
GtkWidget *error_info_bar;
GtkWidget *error_label;
@@ -36,7 +36,8 @@ static GtkWidget *dive_profile;
void repaint_dive(void)
{
update_dive(current_dive);
- gtk_widget_queue_draw(dive_profile);
+ if (dive_profile)
+ gtk_widget_queue_draw(dive_profile);
}
static char *existing_filename;
@@ -87,6 +88,8 @@ void report_error(GError* error)
static void file_open(GtkWidget *w, gpointer data)
{
GtkWidget *dialog;
+ GtkFileFilter *filter;
+
dialog = gtk_file_chooser_dialog_new("Open File",
GTK_WINDOW(main_window),
GTK_FILE_CHOOSER_ACTION_OPEN,
@@ -95,6 +98,13 @@ static void file_open(GtkWidget *w, gpointer data)
NULL);
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
+ filter = gtk_file_filter_new();
+ gtk_file_filter_add_pattern(filter, "*.xml");
+ gtk_file_filter_add_pattern(filter, "*.XML");
+ gtk_file_filter_add_mime_type(filter, "text/xml");
+ gtk_file_filter_set_name(filter, "XML file");
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
GSList *filenames;
char *filename;
@@ -246,7 +256,7 @@ UNITCALLBACK(set_fahrenheit, temperature, FAHRENHEIT)
static void preferences_dialog(GtkWidget *w, gpointer data)
{
int result;
- GtkWidget *dialog, *font, *frame, *box;
+ GtkWidget *dialog, *font, *frame, *box, *vbox;
menu_units = output_units;
@@ -258,7 +268,8 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
NULL);
frame = gtk_frame_new("Units");
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
box = gtk_vbox_new(FALSE, 6);
gtk_container_add(GTK_CONTAINER(frame), box);
@@ -284,7 +295,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
NULL);
font = gtk_font_button_new_with_font(divelist_font);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), font, FALSE, FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(vbox), font, FALSE, FALSE, 5);
gtk_widget_show_all(dialog);
result = gtk_dialog_run(GTK_DIALOG(dialog));
@@ -310,7 +321,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
static void renumber_dialog(GtkWidget *w, gpointer data)
{
int result;
- GtkWidget *dialog, *frame, *button;
+ GtkWidget *dialog, *frame, *button, *vbox;
dialog = gtk_dialog_new_with_buttons("Renumber",
GTK_WINDOW(main_window),
@@ -319,8 +330,10 @@ static void renumber_dialog(GtkWidget *w, gpointer data)
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
frame = gtk_frame_new("New starting number");
- gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), frame);
+ gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
button = gtk_spin_button_new_with_range(1, 50000, 1);
gtk_container_add(GTK_CONTAINER(frame), button);
@@ -335,9 +348,32 @@ static void renumber_dialog(GtkWidget *w, gpointer data)
gtk_widget_destroy(dialog);
}
+static void about_dialog(GtkWidget *w, gpointer data)
+{
+ const char *logo_property = NULL;
+ GdkPixbuf *logo = NULL;
+ GtkWidget *image = gtk_image_new_from_file("icon.svg");
+
+ if (image) {
+ logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
+ logo_property = "logo";
+ }
+
+ gtk_show_about_dialog(NULL,
+ "program-name", "SubSurface",
+ "comments", "Half-arsed divelog software in C",
+ "license", "GPLv2",
+ "version", VERSION_STRING,
+ "copyright", "Linus Torvalds 2011",
+ /* Must be last: */
+ logo_property, logo,
+ NULL);
+}
+
static GtkActionEntry menu_items[] = {
{ "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
{ "LogMenuAction", GTK_STOCK_FILE, "Log", NULL, NULL, NULL},
+ { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
{ "OpenFile", GTK_STOCK_OPEN, NULL, "<control>O", NULL, G_CALLBACK(file_open) },
{ "SaveFile", GTK_STOCK_SAVE, NULL, "<control>S", NULL, G_CALLBACK(file_save) },
{ "Print", GTK_STOCK_PRINT, NULL, "<control>P", NULL, G_CALLBACK(do_print) },
@@ -345,6 +381,7 @@ static GtkActionEntry menu_items[] = {
{ "Preferences", NULL, "Preferences", NULL, NULL, G_CALLBACK(preferences_dialog) },
{ "Renumber", NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) },
{ "Quit", GTK_STOCK_QUIT, NULL, "<control>Q", NULL, G_CALLBACK(quit) },
+ { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) },
};
static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
@@ -365,6 +402,9 @@ static const gchar* ui_string = " \
<menu name=\"LogMenu\" action=\"LogMenuAction\"> \
<menuitem name=\"Renumber\" action=\"Renumber\" /> \
</menu> \
+ <menu name=\"Help\" action=\"HelpMenuAction\"> \
+ <menuitem name=\"About\" action=\"About\" /> \
+ </menu> \
</menubar> \
</ui> \
";
@@ -390,11 +430,41 @@ static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data)
repaint_dive();
}
+static GtkNotebook *create_new_notebook_window(GtkNotebook *source,
+ GtkWidget *page,
+ gint x, gint y, gpointer data)
+{
+ GtkWidget *win, *notebook, *vbox;
+
+ /* We don't detatch twice */
+ if (divelist_window)
+ return NULL;
+
+ divelist_window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(win), "Dive List");
+ gtk_window_set_transient_for(GTK_WINDOW(win), GTK_WINDOW(main_window));
+ gtk_window_set_destroy_with_parent(GTK_WINDOW(win), 1);
+ gtk_window_move(GTK_WINDOW(win), x, y);
+
+ /* Destroying the dive list will kill the application */
+ g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
+ g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
+
+ vbox = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(win), vbox);
+
+ notebook = gtk_notebook_new();
+ gtk_notebook_set_group_id(GTK_NOTEBOOK(notebook), gtk_notebook_get_group_id(source));
+ gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 6);
+ gtk_widget_set_size_request(notebook, 350, 250);
+
+ gtk_widget_show_all(win);
+ return GTK_NOTEBOOK(notebook);
+}
+
void init_ui(int argc, char **argv)
{
GtkWidget *win;
- GtkWidget *paned;
- GtkWidget *info_box;
GtkWidget *notebook;
GtkWidget *dive_info;
GtkWidget *dive_list;
@@ -423,7 +493,7 @@ void init_ui(int argc, char **argv)
error_info_bar = NULL;
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_icon_from_file(GTK_WINDOW(win), "icon.svg", NULL);
- g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK (on_delete), NULL);
+ g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
main_window = win;
@@ -434,22 +504,16 @@ void init_ui(int argc, char **argv)
menubar = get_menubar_menu(win);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
- /* HPane for left the dive list, and right the dive info */
- paned = gtk_vpaned_new();
- gtk_box_pack_end(GTK_BOX(vbox), paned, TRUE, TRUE, 0);
-
- /* Create the actual divelist */
- dive_list = dive_list_create();
- gtk_paned_add2(GTK_PANED(paned), dive_list);
-
- /* VBox for dive info, and tabs */
- info_box = gtk_vbox_new(FALSE, 6);
- gtk_paned_add1(GTK_PANED(paned), info_box);
-
/* Notebook for dive info vs profile vs .. */
notebook = gtk_notebook_new();
+ gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 6);
+ gtk_notebook_set_window_creation_hook(create_new_notebook_window, NULL, NULL);
g_signal_connect(notebook, "switch-page", G_CALLBACK(switch_page), NULL);
- gtk_box_pack_start(GTK_BOX(info_box), notebook, TRUE, TRUE, 6);
+
+ /* Create the actual divelist */
+ dive_list = dive_list_create();
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_list, gtk_label_new("Dive List"));
+ gtk_notebook_set_tab_detachable(GTK_NOTEBOOK(notebook), dive_list, 1);
/* Frame for dive profile */
dive_profile = dive_profile_widget();
@@ -574,20 +638,23 @@ static void fill_computer_list(GtkListStore *store)
}
}
-static GtkComboBox *dive_computer_selector(GtkWidget *dialog)
+static GtkComboBox *dive_computer_selector(GtkWidget *vbox)
{
- GtkWidget *hbox, *combo_box;
+ GtkWidget *hbox, *combo_box, *frame;
GtkListStore *model;
GtkCellRenderer *renderer;
hbox = gtk_hbox_new(FALSE, 6);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 3);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
fill_computer_list(model);
+ frame = gtk_frame_new("Dive computer");
+ gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
+
combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
- gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, TRUE, 3);
+ gtk_container_add(GTK_CONTAINER(frame), combo_box);
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
@@ -596,13 +663,31 @@ static GtkComboBox *dive_computer_selector(GtkWidget *dialog)
return GTK_COMBO_BOX(combo_box);
}
+static GtkEntry *dive_computer_device(GtkWidget *vbox)
+{
+ GtkWidget *hbox, *entry, *frame;
+
+ hbox = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
+
+ frame = gtk_frame_new("Device name");
+ gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
+
+ entry = gtk_entry_new();
+ gtk_container_add(GTK_CONTAINER(frame), entry);
+ gtk_entry_set_text(GTK_ENTRY(entry), "/dev/ttyUSB0");
+
+ return GTK_ENTRY(entry);
+}
+
void import_dialog(GtkWidget *w, gpointer data)
{
int result;
- GtkWidget *dialog, *hbox;
+ GtkWidget *dialog, *hbox, *vbox;
GtkComboBox *computer;
+ GtkEntry *device;
device_data_t devicedata = {
- .devname = "/dev/ttyUSB0",
+ .devname = NULL,
};
dialog = gtk_dialog_new_with_buttons("Import from dive computer",
@@ -612,12 +697,15 @@ void import_dialog(GtkWidget *w, gpointer data)
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
- computer = dive_computer_selector(dialog);
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
+ computer = dive_computer_selector(vbox);
+ device = dive_computer_device(vbox);
hbox = gtk_hbox_new(FALSE, 6);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, TRUE, 3);
- devicedata.progress->bar = gtk_progress_bar_new();
- gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress->bar);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 3);
+ devicedata.progress.bar = gtk_progress_bar_new();
+ gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress.bar);
gtk_widget_show_all(dialog);
result = gtk_dialog_run(GTK_DIALOG(dialog));
@@ -636,6 +724,7 @@ void import_dialog(GtkWidget *w, gpointer data)
-1);
devicedata.type = type;
devicedata.name = comp;
+ devicedata.devname = gtk_entry_get_text(device);
do_import(&devicedata);
break;
default: