X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=player%2Fmain.c;h=36473d1697a2d08ffc3168bff0fb1cf364b4330d;hb=6fd0347f330cb24ef6145662023053a1c0f81a64;hp=7eef7f740c8228db1fb2a050faa4c542bcc853fb;hpb=bf5bc4b0d129685482eefea499f39f874744e2fd;p=projects%2Fchimara%2Fchimara.git diff --git a/player/main.c b/player/main.c index 7eef7f7..36473d1 100644 --- a/player/main.c +++ b/player/main.c @@ -1,26 +1,26 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* - * main.c - * Copyright (C) Philip en Marijn 2008 <> - * - * main.c is free software copyrighted by Philip en Marijn. - * + * Copyright (C) 2008, 2009, 2010, 2011 Philip Chimento and Marijn van Vliet. + * All rights reserved. + * + * Chimara is free software copyrighted by Philip Chimento and Marijn van Vliet. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name ``Philip en Marijn'' nor the name of any other - * contributor may be used to endorse or promote products derived + * 3. Neither of the names Philip Chimento or Marijn van Vliet, nor the name of + * any other contributor may be used to endorse or promote products derived * from this software without specific prior written permission. - * - * main.c IS PROVIDED BY Philip en Marijn ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Philip en Marijn OR ANY OTHER CONTRIBUTORS + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR @@ -30,199 +30,13 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include -#include -#include - #include -#include #include - -#include "error.h" -#include -#include - -#include "preferences.h" - -/* Static global pointers to widgets */ -static GtkUIManager *uimanager = NULL; -static GtkWidget *window = NULL; -static GtkWidget *glk = NULL; - -/* Global global pointers */ -GtkBuilder *builder = NULL; -GtkWidget *aboutwindow = NULL; -GtkWidget *prefswindow = NULL; - -GObject * -load_object(const gchar *name) -{ - GObject *retval; - if( (retval = gtk_builder_get_object(builder, name)) == NULL) { - error_dialog(NULL, NULL, "Error while getting object '%s'", name); - g_error("Error while getting object '%s'", name); - } - return retval; -} - -static void -change_window_title(ChimaraGlk *glk, GParamSpec *pspec, GtkWindow *window) -{ - gchar *program_name, *story_name, *title; - g_object_get(glk, "program-name", &program_name, "story-name", &story_name, NULL); - if(!program_name) { - gtk_window_set_title(window, "Chimara"); - return; - } - else if(!story_name) - title = g_strdup_printf("%s - Chimara", program_name); - else - title = g_strdup_printf("%s - %s - Chimara", program_name, story_name); - - g_free(program_name); - g_free(story_name); - gtk_window_set_title(window, title); - g_free(title); -} - -static void -create_window(void) -{ - GError *error = NULL; - - builder = gtk_builder_new(); - if( !gtk_builder_add_from_file(builder, PACKAGE_DATA_DIR "/chimara.ui", &error) ) { -#ifdef DEBUG - g_error_free(error); - error = NULL; - if( !gtk_builder_add_from_file(builder, PACKAGE_SRC_DIR "/chimara.ui", &error) ) { -#endif /* DEBUG */ - error_dialog(NULL, error, "Error while building interface: "); - return; -#ifdef DEBUG - } -#endif /* DEBUG */ - } - - window = GTK_WIDGET(load_object("chimara")); - aboutwindow = GTK_WIDGET(load_object("aboutwindow")); - prefswindow = GTK_WIDGET(load_object("prefswindow")); - GtkActionGroup *actiongroup = GTK_ACTION_GROUP(load_object("actiongroup")); - GtkActionGroup *style_actiongroup = GTK_ACTION_GROUP(load_object("style-actiongroup")); - - /* Add all the actions to the action group. This for-loop is a temporary fix - and can be removed once Glade supports adding actions and accelerators to an - action group. */ - const gchar *actions[] = { - "game", "", - "open", "O", - "recent", "", - "stop", "", - "quit_chimara", NULL, /* NULL means use stock accelerator */ - "command", "", - "undo", "Z", - "save", NULL, - "restore", "R", - "restart", "", - "quit", "", - "edit", "", - "copy", NULL, - "paste", NULL, - "preferences", "", - "help", "", - "about", "", - NULL - }; - const gchar *style_actions[] = { - "align-left", - "align-justify", - "align-right", - "bold", - "italic", - "underline", - NULL - }; - const gchar **ptr; - for(ptr = actions; *ptr; ptr += 2) - gtk_action_group_add_action_with_accel(actiongroup, GTK_ACTION(load_object(ptr[0])), ptr[1]); - for(ptr = style_actions; *ptr; ptr ++) - gtk_action_group_add_action(style_actiongroup, GTK_ACTION(load_object(*ptr))); - GtkRecentFilter *filter = gtk_recent_filter_new(); - /* TODO: Use mimetypes and construct the filter dynamically depending on - what plugins are installed */ - const gchar *patterns[] = { - "*.z[1-8]", "*.[zg]lb", "*.[zg]blorb", "*.ulx", "*.blb", "*.blorb", NULL - }; - - for(ptr = patterns; *ptr; ptr++) - gtk_recent_filter_add_pattern(filter, *ptr); - GtkRecentChooser *recent = GTK_RECENT_CHOOSER(load_object("recent")); - gtk_recent_chooser_add_filter(recent, filter); - - uimanager = gtk_ui_manager_new(); - if( !gtk_ui_manager_add_ui_from_file(uimanager, PACKAGE_DATA_DIR "/chimara.menus", &error) ) { -#ifdef DEBUG - g_error_free(error); - error = NULL; - if( !gtk_ui_manager_add_ui_from_file(uimanager, PACKAGE_SRC_DIR "/chimara.menus", &error) ) { -#endif /* DEBUG */ - error_dialog(NULL, error, "Error while building interface: "); - return; -#ifdef DEBUG - } -#endif /* DEBUG */ - } - - glk = chimara_if_new(); - g_object_set(glk, "ignore-errors", TRUE, NULL); - if( !chimara_glk_set_css_from_file(CHIMARA_GLK(glk), PACKAGE_DATA_DIR "/style.css", &error) ) { -#ifdef DEBUG - g_error_free(error); - error = NULL; - if( !chimara_glk_set_css_from_file(CHIMARA_GLK(glk), PACKAGE_SRC_DIR "/style.css", &error) ) { -#endif /* DEBUG */ - error_dialog(NULL, error, "Couldn't open CSS file: "); - return; -#ifdef DEBUG - } -#endif /* DEBUG */ - } - - /* DON'T UNCOMMENT THIS your eyes will burn - but it is a good test of programmatically altering just one style - chimara_glk_set_css_from_string(CHIMARA_GLK(glk), - "buffer.normal { font-family: 'Comic Sans MS'; }");*/ - - GtkBox *vbox = GTK_BOX( gtk_builder_get_object(builder, "vbox") ); - if(vbox == NULL) - { - error_dialog(NULL, NULL, "Could not find vbox"); - return; - } - - gtk_ui_manager_insert_action_group(uimanager, actiongroup, 0); - GtkWidget *menubar = gtk_ui_manager_get_widget(uimanager, "/menubar"); - //GtkWidget *toolbar = gtk_ui_manager_get_widget(uimanager, "/toolbar"); - - gtk_box_pack_end(vbox, glk, TRUE, TRUE, 0); - gtk_box_pack_start(vbox, menubar, FALSE, FALSE, 0); - //gtk_box_pack_start(vbox, toolbar, FALSE, FALSE, 0); - - gtk_builder_connect_signals(builder, glk); - g_signal_connect(glk, "notify::program-name", G_CALLBACK(change_window_title), window); - g_signal_connect(glk, "notify::story-name", G_CALLBACK(change_window_title), window); - - /* Create preferences window */ - //preferences_create(CHIMARA_GLK(glk)); -} +#include "app.h" int main(int argc, char *argv[]) { - GError *error = NULL; - #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); @@ -234,26 +48,25 @@ main(int argc, char *argv[]) gdk_threads_init(); gtk_init(&argc, &argv); - create_window(); - gtk_widget_show_all(window); + ChimaraApp *theapp = chimara_app_get(); - g_object_unref( G_OBJECT(uimanager) ); + //if(argc == 3) { + // g_object_set(glk, "graphics-file", argv[2], NULL); + //} + //if(argc >= 2) { + // if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) { + // error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: "); + // return 1; + // } + //} - if(argc >= 2) { - if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) { - error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: "); - return 1; - } - } + gtk_widget_show_all(theapp->browser_window); gdk_threads_enter(); gtk_main(); gdk_threads_leave(); - chimara_glk_stop(CHIMARA_GLK(glk)); - chimara_glk_wait(CHIMARA_GLK(glk)); - - g_object_unref( G_OBJECT(builder) ); + g_object_unref(theapp); return 0; }