]> git.tdb.fi Git - ext/subsurface.git/blob - main.c
Use a 'notebook' for Info vs Profile
[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 static GtkWidget *dive_profile;
51
52 void repaint_dive(void)
53 {
54         update_dive_info(current_dive);
55         gtk_widget_queue_draw(dive_profile);
56 }
57
58 int main(int argc, char **argv)
59 {
60         int i;
61         GtkWidget *win;
62         GtkWidget *divelist;
63         GtkWidget *table;
64         GtkWidget *notebook;
65         GtkWidget *frame;
66
67         parse_xml_init();
68
69         gtk_init(&argc, &argv);
70
71         for (i = 1; i < argc; i++) {
72                 const char *a = argv[i];
73
74                 if (a[0] == '-') {
75                         parse_argument(a);
76                         continue;
77                 }
78                 parse_xml_file(a);
79         }
80
81         report_dives();
82
83         win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
84         g_signal_connect(G_OBJECT(win), "destroy",      G_CALLBACK(on_destroy), NULL);
85
86         /* Table for the list of dives, cairo window, and dive info */
87         table = gtk_table_new(2, 2, FALSE);
88         gtk_container_set_border_width(GTK_CONTAINER(table), 5);
89         gtk_container_add(GTK_CONTAINER(win), table);
90         gtk_widget_show(table);
91
92         /* Create the atual divelist */
93         divelist = create_dive_list();
94         gtk_table_attach_defaults(GTK_TABLE(table), divelist, 0, 1, 0, 2);
95
96         /* Notebook for dive info vs profile vs .. */
97         notebook = gtk_notebook_new();
98         gtk_table_attach_defaults(GTK_TABLE(table), notebook, 1, 2, 1, 2);
99
100         /* Frame for dive info */
101         frame = dive_info_frame();
102         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, gtk_label_new("Dive Info"));
103
104         /* Frame for dive profile */
105         frame = dive_profile_frame();
106         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, gtk_label_new("Dive Profile"));
107         dive_profile = frame;
108
109         gtk_widget_set_app_paintable(win, TRUE);
110         gtk_widget_show_all(win);
111
112         gtk_main();
113         return 0;
114 }