#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.
return TRUE;
}
-void
-on_open_activate(GtkAction *action, ChimaraGlk *glk)
+/* Internal function: See if there is a corresponding graphics file */
+static void
+search_for_graphics_file(const char *filename, ChimaraIF *glk)
{
- GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
-
- if(!confirm_open_new_game(glk))
+
+ extern GSettings *prefs_settings;
+
+ /* First get the name of the story file */
+ char *scratch = g_path_get_basename(filename);
+ *(strrchr(scratch, '.')) = '\0';
+
+ /* Check in the stored resource path, if set */
+ char *resource_path;
+ g_settings_get(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);
+ if(g_file_test(blorbfile, G_FILE_TEST_EXISTS))
+ g_object_set(glk, "graphics-file", blorbfile, NULL);
+
+ g_free(blorbfile);
+ g_free(scratch);
+ g_free(resource_path);
+}
+
+void
+on_open_activate(GtkAction *action, ChimaraPlayer *player)
+{
+ if(!confirm_open_new_game(CHIMARA_GLK(player->glk)))
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 */
- 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;
- gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
-
- /* See if there is a corresponding graphics file */
- /* FIXME: hardcoded path */
- gchar *path = g_path_get_dirname(filename);
- gchar *scratch = g_path_get_basename(filename);
- *(strrchr(scratch, '.')) = '\0';
- gchar *blorbfile = g_strconcat(path, "/../Resources/", scratch, ".blb", NULL);
- if(g_file_test(blorbfile, G_FILE_TEST_EXISTS)) {
- g_object_set(glk, "graphics-file", blorbfile, NULL);
- g_printerr("Setting graphics file to %s\n", blorbfile);
- }
- g_free(blorbfile);
- g_free(path);
- g_free(scratch);
+ extern GSettings *prefs_settings;
+ char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
- 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);
- }
- 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;
}
+ //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();
gchar *uri;
}
void
-on_recent_item_activated(GtkRecentChooser *chooser, ChimaraGlk *glk)
+on_recent_item_activated(GtkRecentChooser *chooser, ChimaraPlayer *player)
{
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))) {
- error_dialog(window, error, _("Could not open game file '%s': "), uri);
- g_free(uri);
- return;
+ error_dialog(GTK_WINDOW(player), error, _("Could not open game file '%s': "), uri);
+ goto finally;
}
- if(!confirm_open_new_game(glk)) {
- g_free(filename);
- g_free(uri);
- return;
- }
+ if(!confirm_open_new_game(CHIMARA_GLK(player->glk)))
+ goto finally2;
- if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error)) {
- error_dialog(window, error, _("Could not open game file '%s': "), filename);
- g_free(filename);
- g_free(uri);
- return;
+ 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;
}
- g_free(filename);
/* Add file to recent files list again, this updates it to most recently used */
GtkRecentManager *manager = gtk_recent_manager_get_default();
if(!gtk_recent_manager_add_item(manager, uri))
g_warning(_("Could not add URI '%s' to recent files list."), uri);
-
+
+finally2:
+ g_free(filename);
+finally:
g_free(uri);
}
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
-on_quit_chimara_activate(GtkAction *action, ChimaraGlk *glk)
+on_quit_chimara_activate(GtkAction *action, ChimaraPlayer *player)
{
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
-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
-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
-on_toolbar_toggled(GtkToggleAction *action, ChimaraGlk *glk)
+on_toolbar_toggled(GtkToggleAction *action, ChimaraPlayer *player)
{
- extern GtkWidget *toolbar;
-
if(gtk_toggle_action_get_active(action))
- gtk_widget_show(toolbar);
+ gtk_widget_show(player->toolbar);
else
- gtk_widget_hide(toolbar);
+ gtk_widget_hide(player->toolbar);
}
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
-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
-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
-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
-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
-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);
}
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;