8 static int sortfn(const void *_a, const void *_b)
10 const struct dive *a = *(void **)_a;
11 const struct dive *b = *(void **)_b;
13 if (a->when < b->when)
15 if (a->when > b->when)
21 * This doesn't really report anything at all. We just sort the
22 * dives, the GUI does the reporting
24 static void report_dives(void)
26 qsort(dive_table.dives, dive_table.nr, sizeof(struct dive *), sortfn);
29 static void parse_argument(const char *arg)
31 const char *p = arg+1;
39 fprintf(stderr, "Bad argument '%s'\n", arg);
45 static void on_destroy(GtkWidget* w, gpointer data)
50 static GtkWidget *dive_profile;
52 void repaint_dive(void)
54 update_dive_info(current_dive);
55 gtk_widget_queue_draw(dive_profile);
58 static void file_open(GtkWidget *w, gpointer data)
62 static void file_save(GtkWidget *w, gpointer data)
66 static GtkItemFactoryEntry menu_items[] = {
67 { "/_File", NULL, NULL, 0, "<Branch>" },
68 { "/File/_Open", "<control>O", file_open, 0, "<StockItem>", GTK_STOCK_OPEN },
69 { "/File/_Save", "<control>S", file_save, 0, "<StockItem>", GTK_STOCK_SAVE },
71 static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
73 /* This is just directly from the gtk menubar tutorial. */
74 static GtkWidget *get_menubar_menu(GtkWidget *window)
76 GtkItemFactory *item_factory;
77 GtkAccelGroup *accel_group;
79 accel_group = gtk_accel_group_new();
80 item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);
82 gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL);
83 gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
84 return gtk_item_factory_get_widget(item_factory, "<main>");
87 int main(int argc, char **argv)
100 gtk_init(&argc, &argv);
102 for (i = 1; i < argc; i++) {
103 const char *a = argv[i];
114 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
115 g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
117 vbox = gtk_vbox_new(FALSE, 1);
118 gtk_container_add(GTK_CONTAINER(win), vbox);
120 menubar = get_menubar_menu(win);
121 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
123 /* Table for the list of dives, cairo window, and dive info */
124 table = gtk_table_new(2, 2, FALSE);
125 gtk_container_set_border_width(GTK_CONTAINER(table), 5);
126 gtk_box_pack_end(GTK_BOX(vbox), table, FALSE, TRUE, 0);
127 gtk_widget_show(table);
129 /* Create the atual divelist */
130 divelist = create_dive_list();
131 gtk_table_attach_defaults(GTK_TABLE(table), divelist, 0, 1, 0, 2);
133 /* Notebook for dive info vs profile vs .. */
134 notebook = gtk_notebook_new();
135 gtk_table_attach_defaults(GTK_TABLE(table), notebook, 1, 2, 1, 2);
137 /* Frame for dive info */
138 frame = dive_info_frame();
139 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, gtk_label_new("Dive Info"));
141 /* Frame for dive profile */
142 frame = dive_profile_frame();
143 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, gtk_label_new("Dive Profile"));
144 dive_profile = frame;
146 gtk_widget_set_app_paintable(win, TRUE);
147 gtk_widget_show_all(win);