1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Philip en Marijn 2008 <>
6 * main.c is free software copyrighted by Philip en Marijn.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name ``Philip en Marijn'' nor the name of any other
17 * contributor may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * main.c IS PROVIDED BY Philip en Marijn ``AS IS'' AND ANY EXPRESS
21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Philip en Marijn OR ANY OTHER CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/types.h>
40 #include <glib/gi18n.h>
41 #include <glib/gstdio.h>
44 /* Use a custom GSettings backend for our preferences file */
45 #define G_SETTINGS_ENABLE_BACKEND
46 #include <gio/gsettingsbackend.h>
49 #include <libchimara/chimara-glk.h>
50 #include <libchimara/chimara-if.h>
52 #include "preferences.h"
57 /* Global global pointers */
58 GtkBuilder *builder = NULL;
59 GtkWidget *aboutwindow = NULL;
60 GtkWidget *prefswindow = NULL;
62 GSettings *prefs_settings = NULL;
63 GSettings *state_settings = NULL;
66 load_object(const gchar *name)
69 if( (retval = gtk_builder_get_object(builder, name)) == NULL) {
70 error_dialog(NULL, NULL, "Error while getting object '%s'", name);
71 g_error("Error while getting object '%s'", name);
81 builder = gtk_builder_new();
82 if( !gtk_builder_add_from_file(builder, PACKAGE_DATA_DIR "/chimara.ui", &error) ) {
86 if( !gtk_builder_add_from_file(builder, PACKAGE_SRC_DIR "/chimara.ui", &error) ) {
88 error_dialog(NULL, error, "Error while building interface: ");
95 aboutwindow = GTK_WIDGET(load_object("aboutwindow"));
96 prefswindow = GTK_WIDGET(load_object("prefswindow"));
99 GtkRecentFilter *filter = gtk_recent_filter_new();
100 /* TODO: Use mimetypes and construct the filter dynamically depending on
101 what plugins are installed */
102 const gchar *patterns[] = {
103 "*.z[1-8]", "*.[zg]lb", "*.[zg]blorb", "*.ulx", "*.blb", "*.blorb", NULL
106 for(ptr = patterns; *ptr; ptr++)
107 gtk_recent_filter_add_pattern(filter, *ptr);
108 GtkRecentChooser *recent = GTK_RECENT_CHOOSER(load_object("recent"));
109 gtk_recent_chooser_add_filter(recent, filter);
111 /* Create preferences window */
112 preferences_create();
116 main(int argc, char *argv[])
118 GError *error = NULL;
121 bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
122 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
123 textdomain(GETTEXT_PACKAGE);
126 if( !g_thread_supported() )
129 gtk_init(&argc, &argv);
131 /* Create configuration dir ~/.chimara */
132 gchar *configdir = g_build_filename(g_get_home_dir(), ".chimara", NULL);
133 if(!g_file_test(configdir, G_FILE_TEST_IS_DIR)
134 && g_mkdir(configdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
135 g_error(_("Cannot create configuration directory ~/.chimara"));
138 /* Initialize settings file; it can be overridden by a "chimara-config" file
139 in the current directory */
141 if(g_file_test("chimara-config", G_FILE_TEST_IS_REGULAR))
142 keyfile = g_strdup("chimara-config");
144 keyfile = g_build_filename(g_get_home_dir(), ".chimara", "config", NULL);
145 GSettingsBackend *backend = g_keyfile_settings_backend_new(keyfile, "/org/chimara-if/player/", NULL);
146 prefs_settings = g_settings_new_with_backend("org.chimara-if.player.preferences", backend);
147 state_settings = g_settings_new_with_backend("org.chimara-if.player.state", backend);
152 GtkWidget *window = chimara_player_new();
153 gtk_widget_show_all(window);
156 // g_object_set(glk, "graphics-file", argv[2], NULL);
159 // if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) {
160 // error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: ");