Get GUI mostly working again
[projects/chimara/chimara.git] / player / player.c
index 2b29bea514b359f57af41eee6789f178b2f51fc5..0d8d629d016dfe407cf458c20f4ddec889a27e74 100644 (file)
@@ -1,8 +1,10 @@
 #include <glib-object.h>
+#include <glib/gi18n.h>
 #include <libchimara/chimara-glk.h>
 #include <libchimara/chimara-if.h>
 #include "player.h"
 #include "error.h"
+#include "app.h"
 
 typedef struct _ChimaraPlayerPrivate {
        int dummy;
@@ -91,11 +93,19 @@ static void
 chimara_player_init(ChimaraPlayer *self)
 {      
        GError *error = NULL;
-       
+
+       /* Set parent properties */
+       g_object_set(self,
+               "title", _("Chimara"),
+               "default-width", 600,
+               "default-height", 800,
+               NULL);
+
+       /* Construct user interface */
        GtkBuilder *builder = gtk_builder_new();
        char *object_ids[] = {
                "actiongroup",
-               "vbox",
+               "player-vbox",
                NULL
        };
        
@@ -158,11 +168,14 @@ chimara_player_init(ChimaraPlayer *self)
         chimara_glk_set_css_from_string(CHIMARA_GLK(glk),
         "buffer.normal { font-family: 'Comic Sans MS'; }");*/
        
-       GtkBox *vbox = GTK_BOX(load_object(builder, "vbox"));                   
-       
+       GtkBox *vbox = GTK_BOX(load_object(builder, "player-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 +209,104 @@ chimara_player_new(void)
     return GTK_WIDGET(g_object_new(CHIMARA_TYPE_PLAYER,
                "type", GTK_WINDOW_TOPLEVEL,
                NULL));
-}
\ No newline at end of file
+}
+
+/* GLADE CALLBACKS */
+
+#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
+game if the user wishes to continue. */
+static gboolean
+confirm_open_new_game(ChimaraGlk *glk)
+{
+       g_return_val_if_fail(glk && CHIMARA_IS_GLK(glk), FALSE);
+       
+       GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
+       
+       if(chimara_glk_get_running(glk)) {
+               GtkWidget *dialog = gtk_message_dialog_new(window,
+                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                   GTK_MESSAGE_WARNING,
+                   GTK_BUTTONS_CANCEL,
+                   _("Are you sure you want to open a new game?"));
+               gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
+                   _("If you open a new game, you will quit the one you are currently playing."));
+               gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OPEN, GTK_RESPONSE_OK);
+               gint response = gtk_dialog_run(GTK_DIALOG(dialog));
+               gtk_widget_destroy(dialog);
+               
+               if(response != GTK_RESPONSE_OK)
+                       return FALSE;
+
+               chimara_glk_stop(glk);
+               chimara_glk_wait(glk);
+       }
+       return TRUE;
+}
+#endif
+
+void
+on_stop_activate(GtkAction *action, ChimaraPlayer *player)
+{
+       chimara_glk_stop(CHIMARA_GLK(player->glk));
+}
+
+void
+on_copy_activate(GtkAction *action, ChimaraPlayer *player)
+{
+       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, ChimaraPlayer *player)
+{
+       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_toolbar_toggled(GtkToggleAction *action, ChimaraPlayer *player)
+{
+       if(gtk_toggle_action_get_active(action))
+               gtk_widget_show(player->toolbar);
+       else
+               gtk_widget_hide(player->toolbar);
+}
+
+void
+on_undo_activate(GtkAction *action, ChimaraPlayer *player)
+{
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "undo");
+}
+
+void 
+on_save_activate(GtkAction *action, ChimaraPlayer *player)
+{
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "save");
+}
+
+void 
+on_restore_activate(GtkAction *action, ChimaraPlayer *player)
+{
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "restore");
+}
+
+void 
+on_restart_activate(GtkAction *action, ChimaraPlayer *player)
+{
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "restart");
+}
+
+void 
+on_quit_activate(GtkAction *action, ChimaraPlayer *player)
+{
+       chimara_glk_feed_line_input(CHIMARA_GLK(player->glk), "quit");
+}
+