]> git.tdb.fi Git - ext/subsurface.git/blob - main.c
Split up divelist scroll window generation into its own file
[ext/subsurface.git] / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4
5 #include "dive.h"
6 #include "display.h"
7
8 static int sortfn(const void *_a, const void *_b)
9 {
10         const struct dive *a = *(void **)_a;
11         const struct dive *b = *(void **)_b;
12
13         if (a->when < b->when)
14                 return -1;
15         if (a->when > b->when)
16                 return 1;
17         return 0;
18 }
19
20 /*
21  * This doesn't really report anything at all. We just sort the
22  * dives, the GUI does the reporting
23  */
24 static void report_dives(void)
25 {
26         qsort(dive_table.dives, dive_table.nr, sizeof(struct dive *), sortfn);
27 }
28
29 static void parse_argument(const char *arg)
30 {
31         const char *p = arg+1;
32
33         do {
34                 switch (*p) {
35                 case 'v':
36                         verbose++;
37                         continue;
38                 default:
39                         fprintf(stderr, "Bad argument '%s'\n", arg);
40                         exit(1);
41                 }
42         } while (*++p);
43 }
44
45 static void on_destroy(GtkWidget* w, gpointer data)
46 {
47         gtk_main_quit();
48 }
49
50 int main(int argc, char **argv)
51 {
52         int i;
53         GtkWidget *win;
54         GtkWidget *divelist;
55         GtkWidget *vbox;
56         GtkWidget *frame;
57
58         parse_xml_init();
59
60         gtk_init(&argc, &argv);
61
62         for (i = 1; i < argc; i++) {
63                 const char *a = argv[i];
64
65                 if (a[0] == '-') {
66                         parse_argument(a);
67                         continue;
68                 }
69                 parse_xml_file(a);
70         }
71
72         report_dives();
73
74         win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
75         g_signal_connect(G_OBJECT(win), "destroy",      G_CALLBACK(on_destroy), NULL);
76
77         /* HBOX for the list of dives and cairo window */
78         vbox=gtk_hbox_new(FALSE, 5);
79         gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
80         gtk_container_add(GTK_CONTAINER(win), vbox);
81         gtk_widget_show(vbox);
82
83         /* Create the atual divelist */
84         divelist = create_dive_list();
85         gtk_container_add(GTK_CONTAINER(vbox), divelist);
86
87         /* Frame for dive profile */
88         frame = dive_profile_frame();
89         gtk_container_add(GTK_CONTAINER(vbox), frame);
90
91         gtk_widget_set_app_paintable(win, TRUE);
92         gtk_widget_show_all(win);
93
94         gtk_main();
95         return 0;
96 }