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)"\" \
--- /dev/null
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+
+/* Use a custom GSettings backend for our preferences file */
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
+
+#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;
+}
+
--- /dev/null
+#ifndef __APP_H__
+#define __APP_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+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__ */
#include <config.h>
#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
}
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);
/* 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);
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();
}
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;
}
void
-on_quit_chimara_activate(GtkAction *action, ChimaraPlayer *player)
+on_quit_chimara_activate(GtkAction *action, ChimaraApp *theapp)
{
gtk_main_quit();
}
}
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
}
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
<?xml version="1.0"?>
<ui>
- <menubar>
+ <menubar name="browser_menu">
<menu action="game">
<menuitem action="open"/>
@OPEN_RECENT_MENU_ITEM@
<separator/>
- <menuitem action="stop"/>
<menuitem action="quit_chimara"/>
</menu>
+ <menu action="edit">
+ <menuitem action="preferences"/>
+ </menu>
+ <menu action="help">
+ <menuitem action="about"/>
+ </menu>
+ </menubar>
+ <menubar name="player_menu">
+ <menu action="game">
+ <menuitem action="stop"/>
+ </menu>
<menu action="edit">
<menuitem action="copy"/>
<menuitem action="paste"/>
<menuitem action="about"/>
</menu>
</menubar>
- <toolbar>
+ <toolbar name="player_toolbar">
<toolitem action="open"/>
<separator/>
<toolitem action="restore"/>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
- <object class="GtkActionGroup" id="actiongroup">
+ <object class="GtkActionGroup" id="app_group">
<child>
<object class="GtkAction" id="game">
<property name="label">_Game</property>
</object>
<accelerator key="o" modifiers="GDK_CONTROL_MASK"/>
</child>
+ <child>
+ <object class="GtkAction" id="quit_chimara">
+ <property name="label">_Quit Chimara</property>
+ <property name="short_label" translatable="yes">_Quit Chimara</property>
+ <property name="tooltip">Leave the program</property>
+ <property name="stock_id">gtk-quit</property>
+ <signal name="activate" handler="on_quit_chimara_activate" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkAction" id="edit">
+ <property name="label">_Edit</property>
+ <property name="short_label" translatable="yes">_Edit</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRecentAction" id="recent">
+ <property name="label">Open _Recent</property>
+ <property name="short_label" translatable="yes">Open _Recent</property>
+ <property name="limit">10</property>
+ <property name="sort_type">mru</property>
+ <signal name="item-activated" handler="on_recent_item_activated" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkAction" id="preferences">
+ <property name="label">P_references</property>
+ <property name="short_label" translatable="yes">P_references</property>
+ <property name="tooltip">Configure the application</property>
+ <property name="stock_id">gtk-preferences</property>
+ <signal name="activate" handler="on_preferences_activate" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkAction" id="help">
+ <property name="label">_Help</property>
+ <property name="short_label" translatable="yes">_Help</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkAction" id="about">
+ <property name="label">_About...</property>
+ <property name="short_label">_About</property>
+ <property name="tooltip">About this application</property>
+ <property name="stock_id">gtk-about</property>
+ <signal name="activate" handler="on_about_activate" swapped="no"/>
+ </object>
+ </child>
+ </object>
+ <object class="GtkActionGroup" id="actiongroup">
<child>
<object class="GtkAction" id="restore">
<property name="label">_Restore...</property>
<signal name="activate" handler="on_save_activate" swapped="no"/>
</object>
</child>
- <child>
- <object class="GtkAction" id="quit_chimara">
- <property name="label">_Quit Chimara</property>
- <property name="short_label" translatable="yes">_Quit Chimara</property>
- <property name="tooltip">Leave the program</property>
- <property name="stock_id">gtk-quit</property>
- <signal name="activate" handler="on_quit_chimara_activate" swapped="no"/>
- </object>
- </child>
<child>
<object class="GtkAction" id="command">
<property name="label">_Command</property>
<property name="short_label" translatable="yes">_Command</property>
</object>
</child>
- <child>
- <object class="GtkAction" id="edit">
- <property name="label">_Edit</property>
- <property name="short_label" translatable="yes">_Edit</property>
- </object>
- </child>
<child>
<object class="GtkAction" id="stop">
<property name="label">_Stop Game</property>
<signal name="activate" handler="on_stop_activate" swapped="no"/>
</object>
</child>
- <child>
- <object class="GtkRecentAction" id="recent">
- <property name="label">Open _Recent</property>
- <property name="short_label" translatable="yes">Open _Recent</property>
- <property name="limit">10</property>
- <property name="sort_type">mru</property>
- <signal name="item-activated" handler="on_recent_item_activated" swapped="no"/>
- </object>
- </child>
<child>
<object class="GtkAction" id="undo">
<property name="label">_Undo</property>
<signal name="activate" handler="on_paste_activate" swapped="no"/>
</object>
</child>
- <child>
- <object class="GtkAction" id="preferences">
- <property name="label">P_references</property>
- <property name="short_label" translatable="yes">P_references</property>
- <property name="tooltip">Configure the application</property>
- <property name="stock_id">gtk-preferences</property>
- <signal name="activate" handler="on_preferences_activate" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="help">
- <property name="label">_Help</property>
- <property name="short_label" translatable="yes">_Help</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="about">
- <property name="label">_About...</property>
- <property name="short_label">_About</property>
- <property name="tooltip">About this application</property>
- <property name="stock_id">gtk-about</property>
- <signal name="activate" handler="on_about_activate" swapped="no"/>
- </object>
- </child>
<child>
<object class="GtkAction" id="view">
<property name="label" translatable="yes">_View</property>
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
+
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>
-#include <glib/gi18n.h>
-#include <glib/gstdio.h>
#include <gtk/gtk.h>
-/* Use a custom GSettings backend for our preferences file */
-#define G_SETTINGS_ENABLE_BACKEND
-#include <gio/gsettingsbackend.h>
-
#include "error.h"
#include <libchimara/chimara-glk.h>
#include <libchimara/chimara-if.h>
#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");
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);
gtk_main();
gdk_threads_leave();
+ g_object_unref(theapp);
+
return 0;
}
#include <libchimara/chimara-if.h>
#include "player.h"
#include "error.h"
+#include "app.h"
typedef struct _ChimaraPlayerPrivate {
int dummy;
"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);
return GTK_WIDGET(g_object_new(CHIMARA_TYPE_PLAYER,
"type", GTK_WINDOW_TOPLEVEL,
NULL));
-}
\ No newline at end of file
+}
#include <libchimara/chimara-if.h>
#include <config.h>
#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
/* 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);
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; i<num_tags; i++) {
- gtk_tree_store_append(style_list, &buffer_child, &buffer);
- gtk_tree_store_append(style_list, &grid_child, &grid);
- gtk_tree_store_set(style_list, &buffer_child, 0, tag_names[i], -1);
- gtk_tree_store_set(style_list, &grid_child, 0, tag_names[i], -1);
- }
+ //int i;
+ //unsigned int num_tags;
+ //const gchar **tag_names = chimara_glk_get_tag_names(glk, &num_tags);
+ //for(i=0; i<num_tags; i++) {
+ // gtk_tree_store_append(style_list, &buffer_child, &buffer);
+ // gtk_tree_store_append(style_list, &grid_child, &grid);
+ // gtk_tree_store_set(style_list, &buffer_child, 0, tag_names[i], -1);
+ // gtk_tree_store_set(style_list, &grid_child, 0, tag_names[i], -1);
+ //}
/* Set selection mode to single select */
- GtkTreeView *view = GTK_TREE_VIEW( load_object("style-treeview") );
+ GtkTreeView *view = GTK_TREE_VIEW( load_object(builder, "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), NULL);
/* Bind the preferences to the entries in the preferences file */
- extern GSettings *prefs_settings;
- GObject *flep = G_OBJECT( load_object("flep") );
- g_settings_bind(prefs_settings, "flep", flep, "active", G_SETTINGS_BIND_DEFAULT);
- GtkFileChooser *blorb_chooser = GTK_FILE_CHOOSER( load_object("blorb_file_chooser") );
- GtkFileChooser *css_chooser = GTK_FILE_CHOOSER( load_object("css-filechooser") );
+ GObject *flep = G_OBJECT( load_object(builder, "flep") );
+ g_settings_bind(theapp->prefs_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++) {
}
/* 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
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);
}
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);
}
-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++) {
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);
}
#define PREFERENCES_H
#include <glib.h>
+#include <gtk/gtk.h>
+#include "app.h"
-G_GNUC_INTERNAL void preferences_create(void);
+G_GNUC_INTERNAL void preferences_create(ChimaraApp *theapp, GtkBuilder *builder);
#endif