Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make the 'Add Dive' dialog at least slightly less butt-ugly

I still suspect that using spinbuttons for the time handling is the
wrong way, and I'm a bit surprised the Calendar widget doesn't have a
mode where you can see/set the time too.

But this makes things at least minimally prettier, and initializes the
time entries to the current time (which is obviously not what anybody
really wants, but looks a lot better than defaulting to "midnight" or
some other random time that *also* won't be what anybody actually
wants).

I think this might be something we can live with, although I hope
somebody with good taste comes along and say "don't use spinbuttons, do
this: xyzzy" and makes things look better yet.

Also, I have this suspicion that I should put the time/depth/duration
stuff to the right of the calendar.  Most displays are wider than they
are tall, so tall and skinny dialogs are bad especially if you have
limited vertical pixels.  I still have flashbacks to my netbook-using
days, hating applictions that did that.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information...
commit 03174992a8617c9fa3428583713c2e3e12d293a7 1 parent 162b36f
@torvalds authored
Showing with 43 additions and 23 deletions.
  1. +43 −23 info.c
View
66 info.c
@@ -12,6 +12,7 @@
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
+#include <sys/time.h>
#include "dive.h"
#include "display.h"
@@ -420,16 +421,35 @@ int edit_dive_info(struct dive *dive)
return success;
}
+static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)
+{
+ va_list ap;
+ char buffer[64];
+ GtkWidget *frame, *hbox;
+
+ va_start(ap, fmt);
+ vsnprintf(buffer, sizeof(buffer), fmt, ap);
+ va_end(ap);
+
+ frame = gtk_frame_new(buffer);
+ gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, TRUE, 0);
+ hbox = gtk_hbox_new(0, 3);
+ gtk_container_add(GTK_CONTAINER(frame), hbox);
+ return hbox;
+}
+
/* Fixme - should do at least depths too - a dive without a depth is kind of pointless */
static time_t dive_time_widget(struct dive *dive)
{
GtkWidget *dialog;
- GtkWidget *cal, *hbox, *vbox;
+ GtkWidget *cal, *hbox, *vbox, *box;
GtkWidget *h, *m;
GtkWidget *duration, *depth;
GtkWidget *label;
guint yval, mval, dval;
- struct tm tm;
+ struct tm tm, *tmp;
+ struct timeval tv;
+ time_t time;
int success;
double depthinterval, val;
@@ -443,47 +463,47 @@ static time_t dive_time_widget(struct dive *dive)
vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
/* Calendar hbox */
- hbox = gtk_hbox_new(0, 3);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
-
+ hbox = frame_box(vbox, "Date:");
cal = gtk_calendar_new();
gtk_box_pack_start(GTK_BOX(hbox), cal, FALSE, TRUE, 0);
- /* Time/duration hbox */
- hbox = gtk_hbox_new(0, 3);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
+ /* Time hbox */
+ hbox = frame_box(vbox, "Time");
h = gtk_spin_button_new_with_range (0.0, 23.0, 1.0);
m = gtk_spin_button_new_with_range (0.0, 59.0, 1.0);
+ gettimeofday(&tv, NULL);
+ time = tv.tv_sec;
+ tmp = localtime(&time);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(h), tmp->tm_hour);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(m), (tmp->tm_min / 5)*5);
+
gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(h), TRUE);
gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(m), TRUE);
- duration = gtk_spin_button_new_with_range (0.0, 1000.0, 1.0);
-
- gtk_box_pack_start(GTK_BOX(hbox), h, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox), m, FALSE, FALSE, 0);
label = gtk_label_new(":");
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), m, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox), h, FALSE, FALSE, 0);
- label = gtk_label_new(" Duration:");
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), duration, FALSE, FALSE, 0);
+ hbox = gtk_hbox_new(TRUE, 3);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
- /* Depth box */
- hbox = gtk_hbox_new(0, 3);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
+ /* Duration hbox */
+ box = frame_box(hbox, "Duration (min)");
+ duration = gtk_spin_button_new_with_range (0.0, 1000.0, 1.0);
+ gtk_box_pack_end(GTK_BOX(box), duration, FALSE, FALSE, 0);
+ /* Depth box */
+ box = frame_box(hbox, "Depth (%s):", output_units.length == FEET ? "ft" : "m");
if (output_units.length == FEET) {
depthinterval = 1.0;
} else {
depthinterval = 0.1;
}
depth = gtk_spin_button_new_with_range (0.0, 1000.0, depthinterval);
-
- label = gtk_label_new("Depth: ");
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), depth, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(box), depth, FALSE, FALSE, 0);
/* All done, show it and wait for editing */
gtk_widget_show_all(dialog);
Please sign in to comment.
Something went wrong with that request. Please try again.