]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Merge branch 'misc-fixes' of git://github.com/DataBeaver/subsurface
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Aug 2012 17:57:24 +0000 (10:57 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Aug 2012 17:57:24 +0000 (10:57 -0700)
Pull miscellaneous fixes, mostly UI stuff from Mikko Rasa.

Both this and the pull from Pierre-Yves Chibon created a "Save As" menu
entry and logic.  As a result, there were a fair number of conflicts,
but I tried to make the end result somewhat reasonable.  I might have
missed some semantic conflict, though.

Series-acked-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
* 'misc-fixes' of git://github.com/DataBeaver/subsurface:
  Add a separate "Save as" entry to the menu
  Changes to menu icons
  Improved depth info for dives without samples
  Divide the panes evenly in view_three

dive.c
divelist.c
gtk-gui.c
info.c
profile.c

diff --git a/dive.c b/dive.c
index f5d0828015e2b64990a390d877839e43335ffd48..f4bf497a7da0edeafb91b5a26b1de067f87d64b7 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -473,7 +473,12 @@ struct dive *fixup_dive(struct dive *dive)
                }
        }
        if (end < 0)
+       {
+               /* Assume an ascent/descent rate of 9 m/min */
+               int asc_desc_time = dive->maxdepth.mm*60/9000;
+               dive->meandepth.mm = dive->maxdepth.mm*(dive->duration.seconds-asc_desc_time)/dive->duration.seconds;
                return dive;
+       }
 
        update_duration(&dive->duration, end - start);
        if (start != end)
index 0e1b40dd6f71abb64f9acd32082b6df06585875f..5d6915256c5f08a2dea140fdd3ed884d4ed416ac 100644 (file)
@@ -1047,11 +1047,13 @@ void edit_dive_cb(GtkWidget *menuitem, gpointer data)
 
 static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int button)
 {
-       GtkWidget *menu, *menuitem;
+       GtkWidget *menu, *menuitem, *image;
        char editlabel[] = "Edit dives";
 
        menu = gtk_menu_new();
-       menuitem = gtk_menu_item_new_with_label("Add dive");
+       menuitem = gtk_image_menu_item_new_with_label("Add dive");
+       image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
+       gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
        g_signal_connect(menuitem, "activate", G_CALLBACK(add_dive_cb), NULL);
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
        if (amount_selected) {
index 02463d91e24c475c3a60f2a377db71577a3e3b68..5bc46d2190248be4c7a7c68b121c2766258b9f0b 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -170,43 +170,16 @@ static void file_open(GtkWidget *w, gpointer data)
        gtk_widget_destroy(dialog);
 }
 
-static void file_save(GtkWidget *w, gpointer data)
+static void file_save_as(GtkWidget *w, gpointer data)
 {
        GtkWidget *dialog;
        char *filename;
-       if (!existing_filename) {
-               dialog = gtk_file_chooser_dialog_new("Save File",
+       dialog = gtk_file_chooser_dialog_new("Save File As",
                GTK_WINDOW(main_window),
                GTK_FILE_CHOOSER_ACTION_SAVE,
                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                NULL);
-               gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
-
-               gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document");
-               if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
-                       filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
-               }
-               gtk_widget_destroy(dialog);
-       } else {
-               filename = existing_filename;
-       }
-       if (filename){
-               save_dives(filename);
-               mark_divelist_changed(FALSE);
-       }
-}
-
-static void file_save_as(GtkWidget *w, gpointer data)
-{
-       GtkWidget *dialog;
-       char *filename;
-       dialog = gtk_file_chooser_dialog_new("Save File As",
-       GTK_WINDOW(main_window),
-       GTK_FILE_CHOOSER_ACTION_SAVE,
-       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-       GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
-       NULL);
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
 
        gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), existing_filename);
@@ -217,10 +190,21 @@ static void file_save_as(GtkWidget *w, gpointer data)
 
        if (filename){
                save_dives(filename);
+               set_filename(filename);
+               g_free(filename);
                mark_divelist_changed(FALSE);
        }
 }
 
+static void file_save(GtkWidget *w, gpointer data)
+{
+       if (!existing_filename)
+               return file_save_as(w, data);
+
+       save_dives(existing_filename);
+       mark_divelist_changed(FALSE);
+}
+
 static gboolean ask_save_changes()
 {
        GtkWidget *dialog, *label, *content;
@@ -247,7 +231,7 @@ static gboolean ask_save_changes()
        gtk_container_add (GTK_CONTAINER (content), label);
        gtk_widget_show_all (dialog);
        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
-       gint *outcode = gtk_dialog_run(GTK_DIALOG(dialog));
+       gint outcode = gtk_dialog_run(GTK_DIALOG(dialog));
        if (outcode == GTK_RESPONSE_ACCEPT) {
                file_save(NULL,NULL);
        } else if (outcode == GTK_RESPONSE_CANCEL) {
@@ -675,26 +659,28 @@ static void view_info(GtkWidget *w, gpointer data)
        gtk_paned_set_position(GTK_PANED(hpane), 65535);
 }
 
-/* Ooh. I don't know how to get the half-way size. So I'm just using random numbers */
 static void view_three(GtkWidget *w, gpointer data)
 {
-       gtk_paned_set_position(GTK_PANED(hpane), 400);
-       gtk_paned_set_position(GTK_PANED(vpane), 200);
+       GtkAllocation alloc;
+       gtk_widget_get_allocation(hpane, &alloc);
+       gtk_paned_set_position(GTK_PANED(hpane), alloc.width/2);
+       gtk_widget_get_allocation(vpane, &alloc);
+       gtk_paned_set_position(GTK_PANED(vpane), alloc.height/2);
 }
 
 static GtkActionEntry menu_items[] = {
-       { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
-       { "LogMenuAction",  GTK_STOCK_FILE, "Log", NULL, NULL, NULL},
-       { "ViewMenuAction",  GTK_STOCK_FILE, "View", NULL, NULL, NULL},
-       { "FilterMenuAction",  GTK_STOCK_FILE, "Filter", NULL, NULL, NULL},
-       { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
+       { "FileMenuAction", NULL, "File", NULL, NULL, NULL},
+       { "LogMenuAction",  NULL, "Log", NULL, NULL, NULL},
+       { "ViewMenuAction",  NULL, "View", NULL, NULL, NULL},
+       { "FilterMenuAction",  NULL, "Filter", NULL, NULL, NULL},
+       { "HelpMenuAction", NULL, "Help", NULL, NULL, NULL},
        { "OpenFile",       GTK_STOCK_OPEN, NULL,   CTRLCHAR "O", NULL, G_CALLBACK(file_open) },
        { "SaveFile",       GTK_STOCK_SAVE, NULL,   CTRLCHAR "S", NULL, G_CALLBACK(file_save) },
        { "SaveAsFile",     GTK_STOCK_SAVE_AS, NULL,   SHIFTCHAR CTRLCHAR "S", NULL, G_CALLBACK(file_save_as) },
        { "Print",          GTK_STOCK_PRINT, NULL,  CTRLCHAR "P", NULL, G_CALLBACK(do_print) },
        { "Import",         NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) },
-       { "AddDive",        NULL, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) },
-       { "Preferences",    NULL, "Preferences", PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) },
+       { "AddDive",        GTK_STOCK_ADD, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) },
+       { "Preferences",    GTK_STOCK_PREFERENCES, "Preferences", PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) },
        { "Renumber",       NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) },
        { "SelectEvents",   NULL, "SelectEvents", NULL, NULL, G_CALLBACK(selectevents_dialog) },
        { "Quit",           GTK_STOCK_QUIT, NULL,   CTRLCHAR "Q", NULL, G_CALLBACK(quit) },
@@ -1255,7 +1241,9 @@ void update_progressbar_text(progressbar_t *progress, const char *text)
 
 void set_filename(const char *filename)
 {
-       if (!existing_filename && filename)
+       if (existing_filename)
+               free(existing_filename);
+       existing_filename = NULL;
+       if (filename)
                existing_filename = strdup(filename);
-       return;
 }
diff --git a/info.c b/info.c
index 0ee401488062aa3105850863bf15c1c8feaca8b0..38776487bae8b69b0fb24efe97e4641b7a628fe1 100644 (file)
--- a/info.c
+++ b/info.c
@@ -175,9 +175,17 @@ static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data)
        delete_dive_info(current_dive);
 }
 
-static void add_menu_item(GtkMenu *menu, const char *label, void (*cb)(GtkMenuItem *, gpointer))
+static void add_menu_item(GtkMenu *menu, const char *label, const char *icon, void (*cb)(GtkMenuItem *, gpointer))
 {
-       GtkWidget *item = gtk_menu_item_new_with_label(label);
+       GtkWidget *item;
+       if (icon) {
+               GtkWidget *image;
+               item = gtk_image_menu_item_new_with_label(label);
+               image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU);
+               gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
+       } else {
+               item = gtk_menu_item_new_with_label(label);
+       }
        g_signal_connect(item, "activate", G_CALLBACK(cb), NULL);
        gtk_widget_show(item); /* Yes, really */
        gtk_menu_prepend(menu, item);
@@ -185,8 +193,8 @@ static void add_menu_item(GtkMenu *menu, const char *label, void (*cb)(GtkMenuIt
 
 static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
 {
-       add_menu_item(menu, "Delete", info_menu_delete_cb);
-       add_menu_item(menu, "Edit", info_menu_edit_cb);
+       add_menu_item(menu, "Delete", GTK_STOCK_DELETE, info_menu_delete_cb);
+       add_menu_item(menu, "Edit", GTK_STOCK_EDIT, info_menu_edit_cb);
 }
 
 static GtkEntry *text_value(GtkWidget *box, const char *label)
index 7a0eac4975ac9b6e4755e23236407c142f211b24..90ed0b6098c1a7d3d651c8cf8b7e9bf0b2b8fcb7 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -1355,12 +1355,15 @@ void plot(struct graphics_context *gc, cairo_rectangle_int_t *drawing_area, stru
        int nr = dive->samples;
 
        if (!nr) {
+               /* The dive has no samples, so create a few fake ones.  This assumes an
+               ascent/descent rate of 9 m/min, which is just below the limit for FAST. */
                int duration = dive->duration.seconds;
                int maxdepth = dive->maxdepth.mm;
+               int asc_desc_time = dive->maxdepth.mm*60/9000;
                sample = fake;
-               fake[1].time.seconds = duration * 0.05;
+               fake[1].time.seconds = asc_desc_time;
                fake[1].depth.mm = maxdepth;
-               fake[2].time.seconds = duration * 0.95;
+               fake[2].time.seconds = duration - asc_desc_time;
                fake[2].depth.mm = maxdepth;
                fake[3].time.seconds = duration * 1.00;
                nr = 4;