Make file handling more general so it can be reused.
[fw/altos] / aoview / aoview_main.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #include "aoview.h"
19
20 static const char aoview_glade[] = {
21 #include "aoview_glade.h"
22 };
23
24 static void usage(void) {
25         printf("aoview [--device|-d device_file]");
26         exit(1);
27 }
28
29 static void destroy_event(GtkWidget *widget, gpointer data)
30 {
31         gtk_main_quit();
32 }
33
34 int main(int argc, char **argv)
35 {
36         GladeXML *xml = NULL;
37         GtkWidget *mainwindow;
38         char *device = NULL;
39         GtkAboutDialog *about_dialog;
40
41         static struct option long_options[] = {
42                 { "device", 1, 0, 'd'},
43                 { 0, 0, 0, 0 }
44         };
45         for (;;) {
46                 int c, temp;
47
48                 c = getopt_long_only(argc, argv, "d:", long_options, &temp);
49                 if (c == -1)
50                         break;
51
52                 switch (c) {
53                 case 'd':
54                         device = optarg;
55                         break;
56                 default:
57                         usage();
58                 }
59         }
60
61         gtk_init(&argc, &argv);
62         glade_init();
63
64         xml = glade_xml_new_from_buffer(aoview_glade, sizeof (aoview_glade), NULL, NULL);
65
66         /* connect the signals in the interface */
67         glade_xml_signal_autoconnect(xml);
68
69         /* Hook up the close button. */
70         mainwindow = glade_xml_get_widget(xml, "aoview");
71         assert(mainwindow);
72
73         g_signal_connect (G_OBJECT(mainwindow), "destroy",
74             G_CALLBACK(destroy_event), NULL);
75
76         about_dialog = GTK_ABOUT_DIALOG(glade_xml_get_widget(xml, "about_dialog"));
77         assert(about_dialog);
78         gtk_about_dialog_set_version(about_dialog, AOVIEW_VERSION);
79
80         aoview_dev_dialog_init(xml);
81
82         aoview_state_init(xml);
83
84         aoview_file_init(xml);
85
86         aoview_log_init(xml);
87
88         aoview_table_init(xml);
89
90         gtk_main();
91
92         return 0;
93 }