More generic use of event.
[familia.git] / src / main.c
1 /****************************************************************************
2  *  Familia Lignum - Genealogical program                                   *
3  *  Copyright (C) 2011-2012 Rafał Długołęcki <rafal@dlugolecki.net.pl>      *
4  *                                                                          *
5  *  This program is free software; you can redistribute it and/or modify    *
6  *  it under the terms of the GNU General Public License as published by    *
7  *  the Free Software Foundation; version 2 of the License.                 *
8  *                                                                          *
9  *  This program is distributed in the hope that it will be useful,         *
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
12  *  GNU General Public License for more details.                            *
13  *                                                                          *
14  *  You should have received a copy of the GNU General Public License along *
15  *  with this program; if not, write to the Free Software Foundation, Inc., *
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             *
17  *                                                                          *
18  ****************************************************************************/
19
20 #include <gtk/gtk.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <locale.h>
24
25 #include <gtk/gtkgl.h>
26 #include <GL/gl.h>
27 #include <gedcom.h>
28
29 #include "../config.h"
30 #include "i18n.h"
31 #include "debug.h"
32 #include "commandline.h"
33 #include "familia.h"
34 #include "storage/storage.h"
35 #include "gedcom/familia_gedcom.h"
36
37 extern GtkDrawingArea * drawing_area;
38
39 const char * get_guidatafile()
40 {
41         if (g_file_test (DATADIR "/gui.glade", G_FILE_TEST_EXISTS)) {
42                 return DATADIR "/gui.glade";
43         }
44         return "data/gui.glade";
45 }
46
47 int main(int argc, char** argv) {
48         GtkBuilder *builder = NULL;
49         GtkWidget *window = NULL;
50         GdkGLConfig *glconfig = NULL;
51         FamiliaData * app = NULL;
52         struct familia_storage * storage = NULL;
53
54         storage = familia_storage_new();
55         familia_storage_set_current(storage);
56
57         gedcom_init();
58         familia_gedcom_init();
59
60         gtk_init(&argc, &argv);
61
62         if(!commandline_parse(&argc, &argv)) {
63                 exit(1);
64         }
65
66         /* Initialize OpenGL */
67         gtk_gl_init(&argc, &argv);
68
69         setlocale(LC_ALL, "");
70         bindtextdomain(PACKAGE_TARNAME, LOCALEDIR);
71         textdomain(PACKAGE_TARNAME);
72
73         g_set_prgname(PACKAGE_NAME);
74
75         GdkGLConfigMode gl_mode = GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH |
76                                                         GDK_GL_MODE_DOUBLE;
77
78         /* Try double-buffered visual */
79         glconfig = gdk_gl_config_new_by_mode (gl_mode);
80         if (glconfig == NULL) {
81                 debug("OpenGL mode is not supported. Exiting...");
82                 exit(1);
83         }
84
85         builder = gtk_builder_new();
86
87         gtk_builder_add_from_file(builder, get_guidatafile(), NULL);
88
89         app = g_new(FamiliaData, 1);
90         app->hadjustment = gtk_builder_get_object(builder, "horizontal-adjustment");
91         app->vadjustment = gtk_builder_get_object(builder, "vertical-adjustment");
92
93         gtk_builder_connect_signals(builder, app);
94
95         window = GTK_WIDGET(gtk_builder_get_object(builder, "main-window"));
96         drawing_area = GTK_WIDGET(gtk_builder_get_object(builder, "drawing-area"));
97
98         gtk_window_set_title(GTK_WINDOW(window), g_get_application_name());
99
100         /* Set OpenGL-capability to the widget. */
101         gtk_widget_set_gl_capability (drawing_area, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
102
103         gtk_widget_show(window);
104
105         gtk_main();
106
107         if (familia_storage_get_current()) {
108                 storage = familia_storage_get_current();
109                 familia_storage_free(storage);
110                 storage = NULL;
111         }
112
113         g_free(app);
114
115         return 0;
116 }