]> git.tdb.fi Git - ext/subsurface.git/blobdiff - main.c
Add some more dive info - and actually update it
[ext/subsurface.git] / main.c
diff --git a/main.c b/main.c
index 6da386ccd6c8d02b12bc2d697450721b917e1c1f..6a82c6f933e4e3f6cab9ef53d777e72c4a36b6aa 100644 (file)
--- a/main.c
+++ b/main.c
@@ -3,33 +3,7 @@
 #include <time.h>
 
 #include "dive.h"
-
-static void show_dive(int nr, struct dive *dive)
-{
-       int i;
-       struct tm *tm;
-
-       tm = gmtime(&dive->when);
-
-       printf("At %02d:%02d:%02d %04d-%02d-%02d  (%d ft max, %d minutes)\n",
-               tm->tm_hour, tm->tm_min, tm->tm_sec,
-               tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
-               to_feet(dive->maxdepth), dive->duration.seconds / 60);
-
-       if (!verbose)
-               return;
-
-       for (i = 0; i < dive->samples; i++) {
-               struct sample *s = dive->sample + i;
-
-               printf("%4d:%02d: %3d ft, %2d C, %4d PSI\n",
-                       s->time.seconds / 60,
-                       s->time.seconds % 60,
-                       to_feet(s->depth),
-                       to_C(s->temperature),
-                       to_PSI(s->tankpressure));
-       }
-}
+#include "display.h"
 
 static int sortfn(const void *_a, const void *_b)
 {
@@ -43,13 +17,13 @@ static int sortfn(const void *_a, const void *_b)
        return 0;
 }
 
+/*
+ * This doesn't really report anything at all. We just sort the
+ * dives, the GUI does the reporting
+ */
 static void report_dives(void)
 {
-       int i;
-
        qsort(dive_table.dives, dive_table.nr, sizeof(struct dive *), sortfn);
-       for (i = 0; i < dive_table.nr; i++)
-               show_dive(i+1, dive_table.dives[i]);
 }
 
 static void parse_argument(const char *arg)
@@ -68,12 +42,31 @@ static void parse_argument(const char *arg)
        } while (*++p);
 }
 
+static void on_destroy(GtkWidget* w, gpointer data)
+{
+       gtk_main_quit();
+}
+
+static GtkWidget *dive_profile;
+
+void repaint_dive(void)
+{
+       update_dive_info(current_dive);
+       gtk_widget_queue_draw(dive_profile);
+}
+
 int main(int argc, char **argv)
 {
        int i;
+       GtkWidget *win;
+       GtkWidget *divelist;
+       GtkWidget *table;
+       GtkWidget *frame;
 
        parse_xml_init();
 
+       gtk_init(&argc, &argv);
+
        for (i = 1; i < argc; i++) {
                const char *a = argv[i];
 
@@ -83,7 +76,34 @@ int main(int argc, char **argv)
                }
                parse_xml_file(a);
        }
+
        report_dives();
+
+       win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       g_signal_connect(G_OBJECT(win), "destroy",      G_CALLBACK(on_destroy), NULL);
+
+       /* Table for the list of dives, cairo window, and dive info */
+       table = gtk_table_new(2, 2, FALSE);
+       gtk_container_set_border_width(GTK_CONTAINER(table), 5);
+       gtk_container_add(GTK_CONTAINER(win), table);
+       gtk_widget_show(table);
+
+       /* Create the atual divelist */
+       divelist = create_dive_list();
+       gtk_table_attach_defaults(GTK_TABLE(table), divelist, 0, 1, 0, 2);
+
+       /* Frame for dive profile */
+       frame = dive_profile_frame();
+       gtk_table_attach_defaults(GTK_TABLE(table), frame, 1, 2, 1, 2);
+       dive_profile = frame;
+
+       /* Frame for dive info */
+       frame = dive_info_frame();
+       gtk_table_attach_defaults(GTK_TABLE(table), frame, 1, 2, 0, 1);
+
+       gtk_widget_set_app_paintable(win, TRUE);
+       gtk_widget_show_all(win);
+
+       gtk_main();
        return 0;
 }
-