Made ChimaraPlayer class
authorP. F. Chimento <philip.chimento@gmail.com>
Sun, 19 Jun 2011 00:10:26 +0000 (02:10 +0200)
committerP. F. Chimento <philip.chimento@gmail.com>
Sun, 19 Jun 2011 00:10:26 +0000 (02:10 +0200)
player/Makefile.am
player/callbacks.c
player/main.c
player/player.c [new file with mode: 0644]
player/player.h [new file with mode: 0644]
player/preferences.c
player/preferences.h

index 2482798027e91e91212bf89dfa0df9fec4b0c3a2..1b5f56104b94c54c9cc660a5cb1ca0fe70c7da23 100644 (file)
@@ -16,7 +16,11 @@ else
 dist_pkgdata_DATA = chimara.ui chimara.menus style.css
 bin_PROGRAMS = chimara
 
 dist_pkgdata_DATA = chimara.ui chimara.menus style.css
 bin_PROGRAMS = chimara
 
-chimara_SOURCES = main.c callbacks.c preferences.c preferences.h error.c error.h
+chimara_SOURCES = main.c \
+       callbacks.c \
+       preferences.c preferences.h \
+       error.c error.h \
+       player.c player.h
 chimara_CPPFLAGS = $(AM_CPPFLAGS) \
        -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
        -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
 chimara_CPPFLAGS = $(AM_CPPFLAGS) \
        -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
        -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
index a4cc173593c8a1185ecf272519fad2d4e71c390f..d99553737fd58f0a359b3a9312e6551508cab462 100644 (file)
@@ -37,6 +37,7 @@
 #include <libchimara/chimara-if.h>
 #include <config.h>
 #include "error.h"
 #include <libchimara/chimara-if.h>
 #include <config.h>
 #include "error.h"
+#include "player.h"
 
 /* If a game is running in @glk, warn the user that they will quit the currently
 running game if they open a new one. Returns TRUE if no game was running.
 
 /* If a game is running in @glk, warn the user that they will quit the currently
 running game if they open a new one. Returns TRUE if no game was running.
@@ -99,47 +100,45 @@ search_for_graphics_file(const char *filename, ChimaraIF *glk)
 }
 
 void
 }
 
 void
-on_open_activate(GtkAction *action, ChimaraGlk *glk) 
+on_open_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
-       
-       if(!confirm_open_new_game(glk))
+       if(!confirm_open_new_game(CHIMARA_GLK(player->glk)))
                return;
 
        GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Open Game"),
                return;
 
        GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Open Game"),
-           window,
+           GTK_WINDOW(player),
            GTK_FILE_CHOOSER_ACTION_OPEN,
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
            NULL);
 
        /* Get last opened path */
            GTK_FILE_CHOOSER_ACTION_OPEN,
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
            NULL);
 
        /* Get last opened path */
-       extern GSettings *state_settings;
-       gchar *path;
-       g_settings_get(state_settings, "last-open-path", "ms", &path);
-       if(path) {
-               gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
-               g_free(path);
-       }
+       //extern GSettings *state_settings;
+       //gchar *path;
+       //g_settings_get(state_settings, "last-open-path", "ms", &path);
+       //if(path) {
+       //      gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
+       //      g_free(path);
+       //}
 
        if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
                GError *error = NULL;
                extern GSettings *prefs_settings;
                char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
 
 
        if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
                GError *error = NULL;
                extern GSettings *prefs_settings;
                char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
 
-               search_for_graphics_file(filename, CHIMARA_IF(glk));
-               if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error)) {
-                       error_dialog(window, error, _("Could not open game file '%s': "), filename);
+               search_for_graphics_file(filename, CHIMARA_IF(player->glk));
+               if(!chimara_if_run_game(CHIMARA_IF(player->glk), filename, &error)) {
+                       error_dialog(GTK_WINDOW(player), error, _("Could not open game file '%s': "), filename);
                        g_free(filename);
                        gtk_widget_destroy(dialog);
                        return;
                }
                
                        g_free(filename);
                        gtk_widget_destroy(dialog);
                        return;
                }
                
-               path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog));
-               if(path) {
-                       g_settings_set(state_settings, "last-open-path", "ms", path);
-                       g_free(path);
-               }
+               //path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog));
+               //if(path) {
+               //      g_settings_set(state_settings, "last-open-path", "ms", path);
+               //      g_free(path);
+               //}
 
                /* Add file to recent files list */
                GtkRecentManager *manager = gtk_recent_manager_get_default();
 
                /* Add file to recent files list */
                GtkRecentManager *manager = gtk_recent_manager_get_default();
@@ -158,23 +157,22 @@ on_open_activate(GtkAction *action, ChimaraGlk *glk)
 }
 
 void
 }
 
 void
-on_recent_item_activated(GtkRecentChooser *chooser, ChimaraGlk *glk)
+on_recent_item_activated(GtkRecentChooser *chooser, ChimaraPlayer *player)
 {
        GError *error = NULL;
 {
        GError *error = NULL;
-       GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
        gchar *uri = gtk_recent_chooser_get_current_uri(chooser);
        gchar *filename;
        if(!(filename = g_filename_from_uri(uri, NULL, &error))) {
        gchar *uri = gtk_recent_chooser_get_current_uri(chooser);
        gchar *filename;
        if(!(filename = g_filename_from_uri(uri, NULL, &error))) {
-               error_dialog(window, error, _("Could not open game file '%s': "), uri);
+               error_dialog(GTK_WINDOW(player), error, _("Could not open game file '%s': "), uri);
                goto finally;
        }
        
                goto finally;
        }
        
-       if(!confirm_open_new_game(glk))
+       if(!confirm_open_new_game(CHIMARA_GLK(player->glk)))
                goto finally2;
        
                goto finally2;
        
-       search_for_graphics_file(filename, CHIMARA_IF(glk));
-       if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error)) {
-               error_dialog(window, error, _("Could not open game file '%s': "), filename);
+       search_for_graphics_file(filename, CHIMARA_IF(player->glk));
+       if(!chimara_if_run_game(CHIMARA_IF(player->glk), filename, &error)) {
+               error_dialog(GTK_WINDOW(player), error, _("Could not open game file '%s': "), filename);
                goto finally2;
        }
        
                goto finally2;
        }
        
@@ -190,87 +188,83 @@ finally:
 }
 
 void
 }
 
 void
-on_stop_activate(GtkAction *action, ChimaraGlk *glk)
+on_stop_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       chimara_glk_stop(glk);
+       chimara_glk_stop(CHIMARA_GLK(player->glk));
 }
 
 void 
 }
 
 void 
-on_quit_chimara_activate(GtkAction *action, ChimaraGlk *glk) 
+on_quit_chimara_activate(GtkAction *action, ChimaraPlayer *player)
 {
        gtk_main_quit();
 }
 
 void
 {
        gtk_main_quit();
 }
 
 void
-on_copy_activate(GtkAction *action, ChimaraGlk *glk)
+on_copy_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       GtkWindow *toplevel = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
-       GtkWidget *focus = gtk_window_get_focus(toplevel);
+       GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(player));
        /* Call "copy clipboard" on any widget that defines it */
        if(GTK_IS_LABEL(focus) || GTK_IS_ENTRY(focus) || GTK_IS_TEXT_VIEW(focus))
                g_signal_emit_by_name(focus, "copy-clipboard");
 }
 
 void
        /* Call "copy clipboard" on any widget that defines it */
        if(GTK_IS_LABEL(focus) || GTK_IS_ENTRY(focus) || GTK_IS_TEXT_VIEW(focus))
                g_signal_emit_by_name(focus, "copy-clipboard");
 }
 
 void
-on_paste_activate(GtkAction *action, ChimaraGlk *glk)
+on_paste_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       GtkWindow *toplevel = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
-       GtkWidget *focus = gtk_window_get_focus(toplevel);
+       GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(player));
        /* Call "paste clipboard" on any widget that defines it */
        if(GTK_IS_ENTRY(focus) || GTK_IS_TEXT_VIEW(focus))
                g_signal_emit_by_name(focus, "paste-clipboard");
 }
 
 void
        /* Call "paste clipboard" on any widget that defines it */
        if(GTK_IS_ENTRY(focus) || GTK_IS_TEXT_VIEW(focus))
                g_signal_emit_by_name(focus, "paste-clipboard");
 }
 
 void
-on_preferences_activate(GtkAction *action, ChimaraGlk *glk)
+on_preferences_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       extern GtkWidget *prefswindow;
-       gtk_window_present(GTK_WINDOW(prefswindow));
+       //extern GtkWidget *prefswindow;
+       //gtk_window_present(GTK_WINDOW(prefswindow));
 }
 
 void
 }
 
 void
-on_toolbar_toggled(GtkToggleAction *action, ChimaraGlk *glk)
+on_toolbar_toggled(GtkToggleAction *action, ChimaraPlayer *player)
 {
 {
-       extern GtkWidget *toolbar;
-       
        if(gtk_toggle_action_get_active(action))
        if(gtk_toggle_action_get_active(action))
-               gtk_widget_show(toolbar);
+               gtk_widget_show(player->toolbar);
        else
        else
-               gtk_widget_hide(toolbar);
+               gtk_widget_hide(player->toolbar);
 }
 
 void
 }
 
 void
-on_undo_activate(GtkAction *action, ChimaraGlk *glk)
+on_undo_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       chimara_glk_feed_line_input(glk, "undo");
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "undo");
 }
 
 void 
 }
 
 void 
-on_save_activate(GtkAction *action, ChimaraGlk *glk) 
+on_save_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       chimara_glk_feed_line_input(glk, "save");
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "save");
 }
 
 void 
 }
 
 void 
-on_restore_activate(GtkAction *action, ChimaraGlk *glk) 
+on_restore_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       chimara_glk_feed_line_input(glk, "restore");
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "restore");
 }
 
 void 
 }
 
 void 
-on_restart_activate(GtkAction *action, ChimaraGlk *glk) 
+on_restart_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       chimara_glk_feed_line_input(glk, "restart");
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "restart");
 }
 
 void 
 }
 
 void 
-on_quit_activate(GtkAction *action, ChimaraGlk *glk) 
+on_quit_activate(GtkAction *action, ChimaraPlayer *player)
 {
 {
-       chimara_glk_feed_line_input(glk, "quit");
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "quit");
 }
 
 void
 }
 
 void
-on_about_activate(GtkAction *action, ChimaraGlk *glk)
+on_about_activate(GtkAction *action, ChimaraPlayer *player)
 {
        extern GtkWidget *aboutwindow;
        gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutwindow), PACKAGE_VERSION);
 {
        extern GtkWidget *aboutwindow;
        gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutwindow), PACKAGE_VERSION);
@@ -278,7 +272,7 @@ on_about_activate(GtkAction *action, ChimaraGlk *glk)
 }
 
 gboolean 
 }
 
 gboolean 
-on_window_delete_event(GtkWidget *widget, GdkEvent *event, ChimaraGlk *glk
+on_window_delete_event(GtkWidget *widget, GdkEvent *event, ChimaraPlayer *player
 {
        gtk_main_quit();
        return TRUE;
 {
        gtk_main_quit();
        return TRUE;
index bd007b4ee128b0a7966822a37c547ca98c7b7c85..efecdab3134e0305a7e05f87951866568841d4cb 100644 (file)
 #include <libchimara/chimara-if.h>
 
 #include "preferences.h"
 #include <libchimara/chimara-if.h>
 
 #include "preferences.h"
+#include "player.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;
 
 /* Global global pointers */
 GtkBuilder *builder = NULL;
 GtkWidget *aboutwindow = NULL;
 GtkWidget *prefswindow = NULL;
-GtkWidget *toolbar = NULL;
+
 GSettings *prefs_settings = NULL;
 GSettings *state_settings = NULL;
 
 GSettings *prefs_settings = NULL;
 GSettings *state_settings = NULL;
 
-GObject *
+static GObject *
 load_object(const gchar *name)
 {
        GObject *retval;
 load_object(const gchar *name)
 {
        GObject *retval;
@@ -75,32 +73,12 @@ load_object(const gchar *name)
        return retval;
 }
 
        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;
 
 static void
 create_window(void)
 {
        GError *error = NULL;
 
-       builder = gtk_builder_new();
+       builder = gtk_builder_new();
        if( !gtk_builder_add_from_file(builder, PACKAGE_DATA_DIR "/chimara.ui", &error) ) {
 #ifdef DEBUG
                g_error_free(error);
        if( !gtk_builder_add_from_file(builder, PACKAGE_DATA_DIR "/chimara.ui", &error) ) {
 #ifdef DEBUG
                g_error_free(error);
@@ -114,17 +92,8 @@ create_window(void)
 #endif /* DEBUG */
        }
 
 #endif /* DEBUG */
        }
 
-       window = GTK_WIDGET(load_object("chimara"));
        aboutwindow = GTK_WIDGET(load_object("aboutwindow"));
        prefswindow = GTK_WIDGET(load_object("prefswindow"));
        aboutwindow = GTK_WIDGET(load_object("aboutwindow"));
        prefswindow = GTK_WIDGET(load_object("prefswindow"));
-       GtkActionGroup *actiongroup = GTK_ACTION_GROUP(load_object("actiongroup"));
-
-       /* Set the default value of the "View/Toolbar" menu item upon creation of a
-        new window to the "show-toolbar-default" setting, but bind the setting
-        one-way only - we don't want toolbars to disappear suddenly */
-       GtkToggleAction *toolbar_action = GTK_TOGGLE_ACTION(load_object("toolbar"));
-       gtk_toggle_action_set_active(toolbar_action, g_settings_get_boolean(state_settings, "show-toolbar-default"));
-       g_settings_bind(state_settings, "show-toolbar-default", toolbar_action, "active", G_SETTINGS_BIND_SET);
 
        const gchar **ptr;
        GtkRecentFilter *filter = gtk_recent_filter_new();
 
        const gchar **ptr;
        GtkRecentFilter *filter = gtk_recent_filter_new();
@@ -139,73 +108,8 @@ create_window(void)
        GtkRecentChooser *recent = GTK_RECENT_CHOOSER(load_object("recent"));
        gtk_recent_chooser_add_filter(recent, filter);
 
        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,
-           /*"interpreter-number", CHIMARA_IF_ZMACHINE_TANDY_COLOR,*/
-           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");
-       toolbar = gtk_ui_manager_get_widget(uimanager, "/toolbar");
-       gtk_widget_set_no_show_all(toolbar, TRUE);
-       if(gtk_toggle_action_get_active(toolbar_action))
-               gtk_widget_show(toolbar);
-       else
-               gtk_widget_hide(toolbar);
-
-       /* Connect the accelerators */
-       GtkAccelGroup *accels = gtk_ui_manager_get_accel_group(uimanager);
-       gtk_window_add_accel_group(GTK_WINDOW(window), accels);
-
-       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 */
        /* Create preferences window */
-       preferences_create(CHIMARA_GLK(glk));
+       preferences_create();
 }
 
 int
 }
 
 int
@@ -244,28 +148,23 @@ main(int argc, char *argv[])
        g_free(keyfile);
 
        create_window();
        g_free(keyfile);
 
        create_window();
-       gtk_widget_show_all(window);
 
 
-       g_object_unref( G_OBJECT(uimanager) );
+       GtkWidget *window = chimara_player_new();
+       gtk_widget_show_all(window);
 
 
-       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 == 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;
+       //      }
+       //}
 
     gdk_threads_enter();
        gtk_main();
        gdk_threads_leave();
 
 
     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) );
-
        return 0;
 }
        return 0;
 }
diff --git a/player/player.c b/player/player.c
new file mode 100644 (file)
index 0000000..2b29bea
--- /dev/null
@@ -0,0 +1,199 @@
+#include <glib-object.h>
+#include <libchimara/chimara-glk.h>
+#include <libchimara/chimara-if.h>
+#include "player.h"
+#include "error.h"
+
+typedef struct _ChimaraPlayerPrivate {
+       int dummy;
+} ChimaraPlayerPrivate;
+
+#define CHIMARA_PLAYER_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), CHIMARA_TYPE_PLAYER, ChimaraPlayerPrivate))
+#define CHIMARA_PLAYER_USE_PRIVATE ChimaraPlayerPrivate *priv = CHIMARA_PLAYER_PRIVATE(self)
+
+G_DEFINE_TYPE(ChimaraPlayer, chimara_player, GTK_TYPE_WINDOW);
+
+static GObject *
+load_object(GtkBuilder *builder, 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
+chimara_player_dispose(GObject *object)
+{
+       ChimaraPlayer *self = CHIMARA_PLAYER(object);
+       if(chimara_glk_get_running(CHIMARA_GLK(self->glk))) {
+               chimara_glk_stop(CHIMARA_GLK(self->glk));
+               g_printerr("Stopping...\n");
+               chimara_glk_wait(CHIMARA_GLK(self->glk));
+               g_printerr("Done Waiting\n");
+       }
+       
+       /* Chain up */
+       G_OBJECT_CLASS(chimara_player_parent_class)->dispose(object);
+}
+
+static void
+chimara_player_finalize(GObject *object)
+{
+       g_printerr("Unreffing\n");
+       g_object_unref(CHIMARA_PLAYER(object)->glk);
+       
+       /* Chain up */
+       G_OBJECT_CLASS(chimara_player_parent_class)->finalize(object);
+}
+
+static void
+chimara_player_class_init(ChimaraPlayerClass *klass)
+{
+       /* Override methods of parent classes */
+       GObjectClass *object_class = G_OBJECT_CLASS(klass);
+       //object_class->set_property = chimara_if_set_property;
+       //object_class->get_property = chimara_if_get_property;
+       object_class->dispose = chimara_player_dispose;
+       object_class->finalize = chimara_player_finalize;
+       
+       /* Signals */
+
+       /* Properties */
+
+       /* Private data */
+       g_type_class_add_private(klass, sizeof(ChimaraPlayerPrivate));
+}
+
+static void
+chimara_player_init(ChimaraPlayer *self)
+{      
+       GError *error = NULL;
+       
+       GtkBuilder *builder = gtk_builder_new();
+       char *object_ids[] = {
+               "actiongroup",
+               "vbox",
+               NULL
+       };
+       
+       if( !gtk_builder_add_objects_from_file(builder, PACKAGE_DATA_DIR "/chimara.ui", object_ids, &error) ) {
+#ifdef DEBUG
+               g_error_free(error);
+               error = NULL;
+               if( !gtk_builder_add_objects_from_file(builder, PACKAGE_SRC_DIR "/chimara.ui", object_ids, &error) ) {
+#endif /* DEBUG */
+                       error_dialog(NULL, error, "Error while building interface: ");  
+                       return;
+#ifdef DEBUG
+               }
+#endif /* DEBUG */
+       }
+       
+       GtkActionGroup *actiongroup = GTK_ACTION_GROUP(load_object(builder, "actiongroup"));
+       
+       /* Set the default value of the "View/Toolbar" menu item upon creation of a
+        new window to the "show-toolbar-default" setting, but bind the setting
+        one-way only - we don't want toolbars to disappear suddenly */
+       GtkToggleAction *toolbar_action = GTK_TOGGLE_ACTION(load_object(builder, "toolbar"));
+       //gtk_toggle_action_set_active(toolbar_action, g_settings_get_boolean(state_settings, "show-toolbar-default"));
+       //g_settings_bind(state_settings, "show-toolbar-default", toolbar_action, "active", G_SETTINGS_BIND_SET);
+               
+       GtkUIManager *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 */
+       }
+       
+       self->glk = chimara_if_new();
+       g_object_set(self->glk,
+                                "ignore-errors", TRUE,
+                                /*"interpreter-number", CHIMARA_IF_ZMACHINE_TANDY_COLOR,*/
+                                NULL);
+       if( !chimara_glk_set_css_from_file(CHIMARA_GLK(self->glk), PACKAGE_DATA_DIR "/style.css", &error) ) {
+#ifdef DEBUG
+               g_error_free(error);
+               error = NULL;
+               if( !chimara_glk_set_css_from_file(CHIMARA_GLK(self->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(load_object(builder, "vbox"));                   
+       
+       gtk_ui_manager_insert_action_group(uimanager, actiongroup, 0);
+       GtkWidget *menubar = gtk_ui_manager_get_widget(uimanager, "/menubar");
+       self->toolbar = gtk_ui_manager_get_widget(uimanager, "/toolbar");
+       gtk_widget_set_no_show_all(self->toolbar, TRUE);
+       if(gtk_toggle_action_get_active(toolbar_action))
+               gtk_widget_show(self->toolbar);
+       else
+               gtk_widget_hide(self->toolbar);
+       
+       /* Connect the accelerators */
+       GtkAccelGroup *accels = gtk_ui_manager_get_accel_group(uimanager);
+       gtk_window_add_accel_group(GTK_WINDOW(self), accels);
+       
+       gtk_box_pack_end(vbox, self->glk, TRUE, TRUE, 0);
+       g_object_ref(self->glk); /* add an extra reference to keep it alive while
+                                                         the Glk program shuts down */
+       gtk_box_pack_start(vbox, menubar, FALSE, FALSE, 0);
+       gtk_box_pack_start(vbox, self->toolbar, FALSE, FALSE, 0);
+       gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(vbox));
+       
+       gtk_builder_connect_signals(builder, self);
+       g_signal_connect(self->glk, "notify::program-name", G_CALLBACK(change_window_title), self);
+       g_signal_connect(self->glk, "notify::story-name", G_CALLBACK(change_window_title), self);
+
+       g_object_unref( G_OBJECT(builder) );
+       g_object_unref( G_OBJECT(uimanager) );
+}
+
+/* PUBLIC FUNCTIONS */
+
+GtkWidget *
+chimara_player_new(void)
+{
+    return GTK_WIDGET(g_object_new(CHIMARA_TYPE_PLAYER,
+               "type", GTK_WINDOW_TOPLEVEL,
+               NULL));
+}
\ No newline at end of file
diff --git a/player/player.h b/player/player.h
new file mode 100644 (file)
index 0000000..55e58bf
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef __PLAYER_H__
+#define __PLAYER_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define CHIMARA_TYPE_PLAYER            (chimara_player_get_type())
+#define CHIMARA_PLAYER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), CHIMARA_TYPE_PLAYER, ChimaraPlayer))
+#define CHIMARA_PLAYER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), CHIMARA_TYPE_PLAYER, ChimaraPlayerClass))
+#define CHIMARA_IS_PLAYER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), CHIMARA_TYPE_PLAYER))
+#define CHIMARA_IS_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CHIMARA_TYPE_PLAYER))
+#define CHIMARA_PLAYER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), CHIMARA_TYPE_PLAYER, ChimaraPlayerClass))
+
+typedef struct _ChimaraPlayer {
+       GtkWindow parent_instance;
+       
+       /* Public pointers to widgets */
+       GtkWidget *glk, *toolbar;
+} ChimaraPlayer;
+
+typedef struct _ChimaraPlayerClass {
+       GtkWindowClass parent_class;
+} ChimaraPlayerClass;
+
+GType chimara_player_get_type(void) G_GNUC_CONST;
+GtkWidget *chimara_player_new(void);
+
+G_END_DECLS
+
+#endif /* __PLAYER_H__ */
\ No newline at end of file
index 9154f4e290a4299e221fe4211688e2d76cdba244..b6205b66885159a38e271f78d060bce48c25c953 100644 (file)
@@ -43,7 +43,7 @@ GObject *load_object(const gchar *name);
 static GtkTextTag *current_tag;
 static GtkListStore *preferred_list;
 
 static GtkTextTag *current_tag;
 static GtkListStore *preferred_list;
 
-static void style_tree_select_callback(GtkTreeSelection *selection, ChimaraGlk *glk);
+static void style_tree_select_callback(GtkTreeSelection *selection);
 
 /* Internal functions to convert from human-readable names in the config file
 to enums and back. Later: replace with plugin functions. */
 
 /* Internal functions to convert from human-readable names in the config file
 to enums and back. Later: replace with plugin functions. */
@@ -136,8 +136,9 @@ interpreter_to_display_string(ChimaraIFInterpreter interp)
 
 /* Create the preferences dialog. */
 void
 
 /* Create the preferences dialog. */
 void
-preferences_create(ChimaraGlk *glk)
+preferences_create(void)
 {
 {
+#if 0
        /* Initialize the tree of style names */
        GtkTreeStore *style_list = GTK_TREE_STORE( load_object("style-list") );
        GtkTreeIter buffer, grid, buffer_child, grid_child;
        /* Initialize the tree of style names */
        GtkTreeStore *style_list = GTK_TREE_STORE( load_object("style-list") );
        GtkTreeIter buffer, grid, buffer_child, grid_child;
@@ -161,7 +162,7 @@ preferences_create(ChimaraGlk *glk)
        GtkTreeView *view = GTK_TREE_VIEW( load_object("style-treeview") );
        GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
        gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
        GtkTreeView *view = GTK_TREE_VIEW( load_object("style-treeview") );
        GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
        gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
-       g_signal_connect(selection, "changed", G_CALLBACK(style_tree_select_callback), glk);
+       g_signal_connect(selection, "changed", G_CALLBACK(style_tree_select_callback), NULL);
 
        /* Bind the preferences to the entries in the preferences file */
        extern GSettings *prefs_settings;
 
        /* Bind the preferences to the entries in the preferences file */
        extern GSettings *prefs_settings;
@@ -222,10 +223,11 @@ preferences_create(ChimaraGlk *glk)
                        1, interpreter_to_display_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count)),
                        -1);
        }
                        1, interpreter_to_display_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count)),
                        -1);
        }
+#endif
 }
 
 static void
 }
 
 static void
-style_tree_select_callback(GtkTreeSelection *selection, ChimaraGlk *glk)
+style_tree_select_callback(GtkTreeSelection *selection)
 {
        GtkTreeIter child, parent;
        gchar *child_name, *parent_name;
 {
        GtkTreeIter child, parent;
        gchar *child_name, *parent_name;
@@ -240,10 +242,10 @@ style_tree_select_callback(GtkTreeSelection *selection, ChimaraGlk *glk)
                return;
 
        gtk_tree_model_get(model, &parent, 0, &parent_name, -1);
                return;
 
        gtk_tree_model_get(model, &parent, 0, &parent_name, -1);
-       if( !strcmp(parent_name, "Text buffer") ) 
-               current_tag = chimara_glk_get_tag(glk, CHIMARA_GLK_TEXT_BUFFER, child_name);
-       else
-               current_tag = chimara_glk_get_tag(glk, CHIMARA_GLK_TEXT_GRID, child_name);
+       //if( !strcmp(parent_name, "Text buffer") )
+       //      current_tag = chimara_glk_get_tag(glk, CHIMARA_GLK_TEXT_BUFFER, child_name);
+       //else
+       //      current_tag = chimara_glk_get_tag(glk, CHIMARA_GLK_TEXT_GRID, child_name);
 }
 
 void
 }
 
 void
index 9a1fad0c59842b2f2935f5e38900c51d05299517..9fdabf7963a0f1d7b7ad5ef91f0a6cd45be670d0 100644 (file)
@@ -1,9 +1,8 @@
 #ifndef PREFERENCES_H
 #define PREFERENCES_H
 
 #ifndef PREFERENCES_H
 #define PREFERENCES_H
 
-#include <gtk/gtk.h>
-#include <libchimara/chimara-glk.h>
+#include <glib.h>
 
 
-G_GNUC_INTERNAL void preferences_create(ChimaraGlk *glk);
+G_GNUC_INTERNAL void preferences_create(void);
 
 #endif
 
 #endif