From 25a7dce7786ce3c8514bd67313048e4f6d19816a Mon Sep 17 00:00:00 2001 From: "P. F. Chimento" Date: Sun, 19 Jun 2011 03:33:38 +0200 Subject: [PATCH] Made ChimaraApp class To do: ChimaraPreferences, ChimaraBrowser --- player/Makefile.am | 3 +- player/app.c | 157 ++++++++++++++++++++++++++++++++++++++++ player/app.h | 38 ++++++++++ player/callbacks.c | 99 +++++++++++++++---------- player/chimara.menus.in | 16 +++- player/chimara.ui | 100 ++++++++++++------------- player/main.c | 95 ++---------------------- player/player.c | 12 ++- player/preferences.c | 130 +++++++++++++++++---------------- player/preferences.h | 4 +- 10 files changed, 405 insertions(+), 249 deletions(-) create mode 100644 player/app.c create mode 100644 player/app.h diff --git a/player/Makefile.am b/player/Makefile.am index 1b5f561..12724da 100644 --- a/player/Makefile.am +++ b/player/Makefile.am @@ -20,7 +20,8 @@ chimara_SOURCES = main.c \ callbacks.c \ preferences.c preferences.h \ error.c error.h \ - player.c player.h + player.c player.h \ + app.c app.h chimara_CPPFLAGS = $(AM_CPPFLAGS) \ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \ diff --git a/player/app.c b/player/app.c new file mode 100644 index 0000000..2efe755 --- /dev/null +++ b/player/app.c @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include + +/* Use a custom GSettings backend for our preferences file */ +#define G_SETTINGS_ENABLE_BACKEND +#include + +#include "app.h" +#include "error.h" +#include "preferences.h" + +typedef struct _ChimaraAppPrivate { + GtkActionGroup *action_group; +} ChimaraAppPrivate; + +#define CHIMARA_APP_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), CHIMARA_TYPE_APP, ChimaraAppPrivate)) +#define CHIMARA_APP_USE_PRIVATE ChimaraAppPrivate *priv = CHIMARA_APP_PRIVATE(self) + +G_DEFINE_TYPE(ChimaraApp, chimara_app, G_TYPE_OBJECT); + +static void +chimara_app_finalize(GObject *self) +{ + CHIMARA_APP_USE_PRIVATE; + g_object_unref(priv->action_group); + + /* Chain up */ + G_OBJECT_CLASS(chimara_app_parent_class)->finalize(self); +} + +static void +chimara_app_class_init(ChimaraAppClass *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->finalize = chimara_app_finalize; + + /* Signals */ + + /* Properties */ + + /* Private data */ + g_type_class_add_private(klass, sizeof(ChimaraAppPrivate)); +} + +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 +chimara_app_init(ChimaraApp *self) +{ + CHIMARA_APP_USE_PRIVATE; + GError *error = NULL; + + /* Create configuration dir ~/.chimara */ + gchar *configdir = g_build_filename(g_get_home_dir(), ".chimara", NULL); + if(!g_file_test(configdir, G_FILE_TEST_IS_DIR) + && g_mkdir(configdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) + g_error(_("Cannot create configuration directory ~/.chimara")); + g_free(configdir); + + /* Initialize settings file; it can be overridden by a "chimara-config" file + in the current directory */ + gchar *keyfile; + if(g_file_test("chimara-config", G_FILE_TEST_IS_REGULAR)) + keyfile = g_strdup("chimara-config"); + else + keyfile = g_build_filename(g_get_home_dir(), ".chimara", "config", NULL); + GSettingsBackend *backend = g_keyfile_settings_backend_new(keyfile, "/org/chimara-if/player/", NULL); + self->prefs_settings = g_settings_new_with_backend("org.chimara-if.player.preferences", backend); + self->state_settings = g_settings_new_with_backend("org.chimara-if.player.state", backend); + g_free(keyfile); + + /* Build user interface */ + GtkBuilder *builder = gtk_builder_new(); + char *object_ids[] = { + "app_group", + "aboutwindow", + "prefswindow", + "available_interpreters", + "interpreters", + "style-list", + 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 */ + } + + self->aboutwindow = GTK_WIDGET(load_object(builder, "aboutwindow")); + self->prefswindow = GTK_WIDGET(load_object(builder, "prefswindow")); + priv->action_group = GTK_ACTION_GROUP(load_object(builder, "app_group")); + g_object_ref(priv->action_group); + + const gchar **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(builder, "recent")); + gtk_recent_chooser_add_filter(recent, filter); + + /* Create preferences window */ + preferences_create(self, builder); + + gtk_builder_connect_signals(builder, self); + + g_object_unref(builder); +} + +/* PUBLIC FUNCTIONS */ + +ChimaraApp * +chimara_app_get(void) +{ + static ChimaraApp *theapp = NULL; + + if(G_UNLIKELY(theapp == NULL)) + theapp = CHIMARA_APP(g_object_new(CHIMARA_TYPE_APP, NULL)); + + return theapp; +} + +GtkActionGroup * +chimara_app_get_action_group(ChimaraApp *self) +{ + CHIMARA_APP_USE_PRIVATE; + return priv->action_group; +} + diff --git a/player/app.h b/player/app.h new file mode 100644 index 0000000..d15f2a9 --- /dev/null +++ b/player/app.h @@ -0,0 +1,38 @@ +#ifndef __APP_H__ +#define __APP_H__ + +#include +#include + +G_BEGIN_DECLS + +#define CHIMARA_TYPE_APP (chimara_app_get_type()) +#define CHIMARA_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CHIMARA_TYPE_APP, ChimaraApp)) +#define CHIMARA_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CHIMARA_TYPE_APP, ChimaraAppClass)) +#define CHIMARA_IS_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CHIMARA_TYPE_APP)) +#define CHIMARA_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CHIMARA_TYPE_APP)) +#define CHIMARA_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CHIMARA_TYPE_APP, ChimaraAppClass)) + +typedef struct _ChimaraApp { + GObject parent_instance; + + /* Public pointers */ + // library browser window? + GtkWidget *aboutwindow; + GtkWidget *prefswindow; + /* Public settings */ + GSettings *prefs_settings; + GSettings *state_settings; +} ChimaraApp; + +typedef struct _ChimaraAppClass { + GObjectClass parent_class; +} ChimaraAppClass; + +GType chimara_app_get_type(void) G_GNUC_CONST; +ChimaraApp *chimara_app_get(void); +GtkActionGroup *chimara_app_get_action_group(ChimaraApp *self); + +G_END_DECLS + +#endif /* __APP_H__ */ diff --git a/player/callbacks.c b/player/callbacks.c index d995537..baa8ca5 100644 --- a/player/callbacks.c +++ b/player/callbacks.c @@ -38,7 +38,9 @@ #include #include "error.h" #include "player.h" +#include "app.h" +#if 0 /* 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. Returns FALSE if the user cancelled. Returns TRUE and shuts down the running @@ -70,13 +72,14 @@ confirm_open_new_game(ChimaraGlk *glk) } return TRUE; } +#endif -/* Internal function: See if there is a corresponding graphics file */ -static void -search_for_graphics_file(const char *filename, ChimaraIF *glk) +/* Internal function: See if there is a corresponding graphics file. If so, +return its path. If not, return NULL. */ +static char * +search_for_graphics_file(const char *filename) { - - extern GSettings *prefs_settings; + ChimaraApp *theapp = chimara_app_get(); /* First get the name of the story file */ char *scratch = g_path_get_basename(filename); @@ -84,49 +87,58 @@ search_for_graphics_file(const char *filename, ChimaraIF *glk) /* Check in the stored resource path, if set */ char *resource_path; - g_settings_get(prefs_settings, "resource-path", "ms", &resource_path); + g_settings_get(theapp->prefs_settings, "resource-path", "ms", &resource_path); /* Otherwise check in the current directory */ if(!resource_path) resource_path = g_path_get_dirname(filename); char *blorbfile = g_strconcat(resource_path, "/", scratch, ".blb", NULL); + g_free(scratch); + g_free(resource_path); + if(g_file_test(blorbfile, G_FILE_TEST_EXISTS)) - g_object_set(glk, "graphics-file", blorbfile, NULL); + return blorbfile; g_free(blorbfile); - g_free(scratch); - g_free(resource_path); + return NULL; } void -on_open_activate(GtkAction *action, ChimaraPlayer *player) +on_open_activate(GtkAction *action, ChimaraApp *theapp) { - if(!confirm_open_new_game(CHIMARA_GLK(player->glk))) - return; + //if(!confirm_open_new_game(CHIMARA_GLK(player->glk))) + // return; GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Open Game"), - GTK_WINDOW(player), + NULL, // FIXME 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); - //} + gchar *path; + g_settings_get(theapp->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)); - search_for_graphics_file(filename, CHIMARA_IF(player->glk)); + /* Open a new player window */ + ChimaraPlayer *player = CHIMARA_PLAYER(chimara_player_new()); + gtk_widget_show_all(GTK_WIDGET(player)); + gtk_window_present(GTK_WINDOW(player)); + + gchar *blorbfile = search_for_graphics_file(filename); + if(blorbfile) { + g_object_set(player->glk, "graphics-file", blorbfile, NULL); + g_free(blorbfile); + } 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); @@ -134,11 +146,11 @@ on_open_activate(GtkAction *action, ChimaraPlayer *player) 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(theapp->state_settings, "last-open-path", "ms", path); + g_free(path); + } /* Add file to recent files list */ GtkRecentManager *manager = gtk_recent_manager_get_default(); @@ -157,20 +169,29 @@ on_open_activate(GtkAction *action, ChimaraPlayer *player) } void -on_recent_item_activated(GtkRecentChooser *chooser, ChimaraPlayer *player) +on_recent_item_activated(GtkRecentChooser *chooser, ChimaraApp *theapp) { GError *error = NULL; gchar *uri = gtk_recent_chooser_get_current_uri(chooser); gchar *filename; if(!(filename = g_filename_from_uri(uri, NULL, &error))) { - error_dialog(GTK_WINDOW(player), error, _("Could not open game file '%s': "), uri); + error_dialog(NULL /* FIXME */, error, _("Could not open game file '%s': "), uri); goto finally; } - if(!confirm_open_new_game(CHIMARA_GLK(player->glk))) - goto finally2; + //if(!confirm_open_new_game(CHIMARA_GLK(player->glk))) + // goto finally2; + + /* Open a new player window */ + ChimaraPlayer *player = CHIMARA_PLAYER(chimara_player_new()); + gtk_widget_show_all(GTK_WIDGET(player)); + gtk_window_present(GTK_WINDOW(player)); - search_for_graphics_file(filename, CHIMARA_IF(player->glk)); + char *blorbfile = search_for_graphics_file(filename); + if(blorbfile) { + g_object_set(player->glk, "graphics-file", blorbfile, NULL); + g_free(blorbfile); + } 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; @@ -194,7 +215,7 @@ on_stop_activate(GtkAction *action, ChimaraPlayer *player) } void -on_quit_chimara_activate(GtkAction *action, ChimaraPlayer *player) +on_quit_chimara_activate(GtkAction *action, ChimaraApp *theapp) { gtk_main_quit(); } @@ -218,10 +239,9 @@ on_paste_activate(GtkAction *action, ChimaraPlayer *player) } void -on_preferences_activate(GtkAction *action, ChimaraPlayer *player) +on_preferences_activate(GtkAction *action, ChimaraApp *theapp) { - //extern GtkWidget *prefswindow; - //gtk_window_present(GTK_WINDOW(prefswindow)); + gtk_window_present(GTK_WINDOW(theapp->prefswindow)); } void @@ -264,11 +284,10 @@ on_quit_activate(GtkAction *action, ChimaraPlayer *player) } void -on_about_activate(GtkAction *action, ChimaraPlayer *player) +on_about_activate(GtkAction *action, ChimaraApp *theapp) { - extern GtkWidget *aboutwindow; - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutwindow), PACKAGE_VERSION); - gtk_window_present(GTK_WINDOW(aboutwindow)); + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(theapp->aboutwindow), PACKAGE_VERSION); + gtk_window_present(GTK_WINDOW(theapp->aboutwindow)); } gboolean diff --git a/player/chimara.menus.in b/player/chimara.menus.in index cb383f7..a140a2e 100644 --- a/player/chimara.menus.in +++ b/player/chimara.menus.in @@ -1,13 +1,23 @@ - + @OPEN_RECENT_MENU_ITEM@ - + + + + + + + + + + + @@ -28,7 +38,7 @@ - + diff --git a/player/chimara.ui b/player/chimara.ui index 0a80104..84e6d95 100644 --- a/player/chimara.ui +++ b/player/chimara.ui @@ -2,7 +2,7 @@ - + _Game @@ -19,6 +19,56 @@ + + + _Quit Chimara + _Quit Chimara + Leave the program + gtk-quit + + + + + + _Edit + _Edit + + + + + Open _Recent + Open _Recent + 10 + mru + + + + + + P_references + P_references + Configure the application + gtk-preferences + + + + + + _Help + _Help + + + + + _About... + _About + About this application + gtk-about + + + + + _Restore... @@ -38,27 +88,12 @@ - - - _Quit Chimara - _Quit Chimara - Leave the program - gtk-quit - - - _Command _Command - - - _Edit - _Edit - - _Stop Game @@ -68,15 +103,6 @@ - - - Open _Recent - Open _Recent - 10 - mru - - - _Undo @@ -123,30 +149,6 @@ - - - P_references - P_references - Configure the application - gtk-preferences - - - - - - _Help - _Help - - - - - _About... - _About - About this application - gtk-about - - - _View diff --git a/player/main.c b/player/main.c index efecdab..85ed57c 100644 --- a/player/main.c +++ b/player/main.c @@ -30,93 +30,25 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include + #include #include #include #include -#include -#include #include -/* Use a custom GSettings backend for our preferences file */ -#define G_SETTINGS_ENABLE_BACKEND -#include - #include "error.h" #include #include #include "preferences.h" #include "player.h" - - - -/* Global global pointers */ -GtkBuilder *builder = NULL; -GtkWidget *aboutwindow = NULL; -GtkWidget *prefswindow = NULL; - -GSettings *prefs_settings = NULL; -GSettings *state_settings = NULL; - -static 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 -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 */ - } - - aboutwindow = GTK_WIDGET(load_object("aboutwindow")); - prefswindow = GTK_WIDGET(load_object("prefswindow")); - - const gchar **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); - - /* Create preferences window */ - preferences_create(); -} +#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"); @@ -128,26 +60,7 @@ main(int argc, char *argv[]) gdk_threads_init(); gtk_init(&argc, &argv); - /* Create configuration dir ~/.chimara */ - gchar *configdir = g_build_filename(g_get_home_dir(), ".chimara", NULL); - if(!g_file_test(configdir, G_FILE_TEST_IS_DIR) - && g_mkdir(configdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) - g_error(_("Cannot create configuration directory ~/.chimara")); - g_free(configdir); - - /* Initialize settings file; it can be overridden by a "chimara-config" file - in the current directory */ - gchar *keyfile; - if(g_file_test("chimara-config", G_FILE_TEST_IS_REGULAR)) - keyfile = g_strdup("chimara-config"); - else - keyfile = g_build_filename(g_get_home_dir(), ".chimara", "config", NULL); - GSettingsBackend *backend = g_keyfile_settings_backend_new(keyfile, "/org/chimara-if/player/", NULL); - prefs_settings = g_settings_new_with_backend("org.chimara-if.player.preferences", backend); - state_settings = g_settings_new_with_backend("org.chimara-if.player.state", backend); - g_free(keyfile); - - create_window(); + ChimaraApp *theapp = chimara_app_get(); GtkWidget *window = chimara_player_new(); gtk_widget_show_all(window); @@ -166,5 +79,7 @@ main(int argc, char *argv[]) gtk_main(); gdk_threads_leave(); + g_object_unref(theapp); + return 0; } diff --git a/player/player.c b/player/player.c index 2b29bea..a35423b 100644 --- a/player/player.c +++ b/player/player.c @@ -3,6 +3,7 @@ #include #include "player.h" #include "error.h" +#include "app.h" typedef struct _ChimaraPlayerPrivate { int dummy; @@ -159,10 +160,13 @@ chimara_player_init(ChimaraPlayer *self) "buffer.normal { font-family: 'Comic Sans MS'; }");*/ GtkBox *vbox = GTK_BOX(load_object(builder, "vbox")); - + + ChimaraApp *theapp = chimara_app_get(); + 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_ui_manager_insert_action_group(uimanager, chimara_app_get_action_group(theapp), 1); + GtkWidget *menubar = gtk_ui_manager_get_widget(uimanager, "/player_menu"); + self->toolbar = gtk_ui_manager_get_widget(uimanager, "/player_toolbar"); gtk_widget_set_no_show_all(self->toolbar, TRUE); if(gtk_toggle_action_get_active(toolbar_action)) gtk_widget_show(self->toolbar); @@ -196,4 +200,4 @@ 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/preferences.c b/player/preferences.c index b6205b6..8c13f9c 100644 --- a/player/preferences.c +++ b/player/preferences.c @@ -38,13 +38,24 @@ #include #include #include "error.h" +#include "app.h" -GObject *load_object(const gchar *name); static GtkTextTag *current_tag; static GtkListStore *preferred_list; static void style_tree_select_callback(GtkTreeSelection *selection); +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; +} + /* Internal functions to convert from human-readable names in the config file to enums and back. Later: replace with plugin functions. */ static ChimaraIFFormat @@ -136,11 +147,10 @@ interpreter_to_display_string(ChimaraIFInterpreter interp) /* Create the preferences dialog. */ void -preferences_create(void) +preferences_create(ChimaraApp *theapp, GtkBuilder *builder) { -#if 0 /* Initialize the tree of style names */ - GtkTreeStore *style_list = GTK_TREE_STORE( load_object("style-list") ); + GtkTreeStore *style_list = GTK_TREE_STORE( load_object(builder, "style-list") ); GtkTreeIter buffer, grid, buffer_child, grid_child; gtk_tree_store_append(style_list, &buffer, NULL); @@ -148,48 +158,47 @@ preferences_create(void) gtk_tree_store_set(style_list, &buffer, 0, "Text buffer", -1); gtk_tree_store_set(style_list, &grid, 0, "Text grid", -1); - int i; - unsigned int num_tags; - const gchar **tag_names = chimara_glk_get_tag_names(glk, &num_tags); - for(i=0; iprefs_settings, "flep", flep, "active", G_SETTINGS_BIND_DEFAULT); + GtkFileChooser *blorb_chooser = GTK_FILE_CHOOSER( load_object(builder, "blorb_file_chooser") ); + GtkFileChooser *css_chooser = GTK_FILE_CHOOSER( load_object(builder, "css-filechooser") ); char *filename; - g_settings_get(prefs_settings, "resource-path", "ms", &filename); + g_settings_get(theapp->prefs_settings, "resource-path", "ms", &filename); if(filename) { gtk_file_chooser_set_filename(blorb_chooser, filename); g_free(filename); } - g_settings_get(prefs_settings, "css-file", "ms", &filename); - if(filename) { - if(!chimara_glk_set_css_from_file(glk, filename, NULL)) { - /* If the setting didn't point to a CSS file, fail silently and - null the setting */ - g_settings_set(prefs_settings, "css-file", "ms", NULL); - } else { - gtk_file_chooser_set_filename(css_chooser, filename); - } - g_free(filename); - } + g_settings_get(theapp->prefs_settings, "css-file", "ms", &filename); + //if(filename) { + // if(!chimara_glk_set_css_from_file(glk, filename, NULL)) { + // /* If the setting didn't point to a CSS file, fail silently and + // null the setting */ + // g_settings_set(theapp->prefs_settings, "css-file", "ms", NULL); + // } else { + // gtk_file_chooser_set_filename(css_chooser, filename); + // } + // g_free(filename); + //} /* Populate the list of available interpreters */ - GtkListStore *interp_list = GTK_LIST_STORE( load_object("available_interpreters") ); + GtkListStore *interp_list = GTK_LIST_STORE( load_object(builder, "available_interpreters") ); unsigned int count; GtkTreeIter tree_iter; for(count = 0; count < CHIMARA_IF_NUM_INTERPRETERS; count++) { @@ -200,30 +209,29 @@ preferences_create(void) } /* Get the list of preferred interpreters from the preferences */ - GVariantIter *iter; - char *format, *plugin; - g_settings_get(prefs_settings, "preferred-interpreters", "a{ss}", &iter); - while(g_variant_iter_loop(iter, "{ss}", &format, &plugin)) { - ChimaraIFFormat format_num = parse_format(format); - if(format_num == CHIMARA_IF_FORMAT_NONE) - continue; - ChimaraIFInterpreter interp_num = parse_interpreter(plugin); - if(interp_num == CHIMARA_IF_INTERPRETER_NONE) - continue; - chimara_if_set_preferred_interpreter(CHIMARA_IF(glk), format_num, interp_num); - } - g_variant_iter_free(iter); + //GVariantIter *iter; + //char *format, *plugin; + //g_settings_get(prefs_settings, "preferred-interpreters", "a{ss}", &iter); + //while(g_variant_iter_loop(iter, "{ss}", &format, &plugin)) { + // ChimaraIFFormat format_num = parse_format(format); + // if(format_num == CHIMARA_IF_FORMAT_NONE) + // continue; + // ChimaraIFInterpreter interp_num = parse_interpreter(plugin); + // if(interp_num == CHIMARA_IF_INTERPRETER_NONE) + // continue; + // chimara_if_set_preferred_interpreter(CHIMARA_IF(glk), format_num, interp_num); + //} + //g_variant_iter_free(iter); /* Display it all in the list */ - preferred_list = GTK_LIST_STORE( load_object("interpreters") ); - for(count = 0; count < CHIMARA_IF_NUM_FORMATS; count++) { - gtk_list_store_append(preferred_list, &tree_iter); - gtk_list_store_set(preferred_list, &tree_iter, - 0, format_to_display_string(count), - 1, interpreter_to_display_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count)), - -1); - } -#endif + //preferred_list = GTK_LIST_STORE( load_object(builder, "interpreters") ); + //for(count = 0; count < CHIMARA_IF_NUM_FORMATS; count++) { + // gtk_list_store_append(preferred_list, &tree_iter); + // gtk_list_store_set(preferred_list, &tree_iter, + // 0, format_to_display_string(count), + // 1, interpreter_to_display_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count)), + // -1); + //} } static void @@ -342,13 +350,13 @@ void on_css_filechooser_file_set(GtkFileChooserButton *button, ChimaraGlk *glk) { GError *error = NULL; - extern GSettings *prefs_settings; + ChimaraApp *theapp = chimara_app_get(); char *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(button) ); if(!chimara_glk_set_css_from_file(glk, filename, &error)) { error_dialog(NULL, error, "There was a problem reading the CSS file: "); - g_settings_set(prefs_settings, "css-file", "ms", NULL); + g_settings_set(theapp->prefs_settings, "css-file", "ms", NULL); } else { - g_settings_set(prefs_settings, "css-file", "ms", filename); + g_settings_set(theapp->prefs_settings, "css-file", "ms", filename); } g_free(filename); } @@ -356,9 +364,9 @@ on_css_filechooser_file_set(GtkFileChooserButton *button, ChimaraGlk *glk) void on_resource_file_set(GtkFileChooserButton *button, ChimaraGlk *glk) { - extern GSettings *prefs_settings; + ChimaraApp *theapp = chimara_app_get(); char *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(button) ); - g_settings_set(prefs_settings, "resource-path", "ms", filename); + g_settings_set(theapp->prefs_settings, "resource-path", "ms", filename); g_free(filename); } @@ -385,7 +393,7 @@ on_interpreter_cell_changed(GtkCellRendererCombo *combo, char *path_string, GtkT -1); /* Save the new settings in the preferences file */ - extern GSettings *prefs_settings; + ChimaraApp *theapp = chimara_app_get(); GVariantBuilder *builder = g_variant_builder_new( G_VARIANT_TYPE("a{ss}") ); unsigned int count; for(count = 0; count < CHIMARA_IF_NUM_FORMATS; count++) { @@ -393,6 +401,6 @@ on_interpreter_cell_changed(GtkCellRendererCombo *combo, char *path_string, GtkT format_to_string(count), interpreter_to_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count))); } - g_settings_set(prefs_settings, "preferred-interpreters", "a{ss}", builder); + g_settings_set(theapp->prefs_settings, "preferred-interpreters", "a{ss}", builder); g_variant_builder_unref(builder); } diff --git a/player/preferences.h b/player/preferences.h index 9fdabf7..63584a2 100644 --- a/player/preferences.h +++ b/player/preferences.h @@ -2,7 +2,9 @@ #define PREFERENCES_H #include +#include +#include "app.h" -G_GNUC_INTERNAL void preferences_create(void); +G_GNUC_INTERNAL void preferences_create(ChimaraApp *theapp, GtkBuilder *builder); #endif -- 2.30.2