Improve player
authorPhilip Chimento <philip.chimento@gmail.com>
Sat, 12 Dec 2009 19:52:38 +0000 (19:52 +0000)
committerPhilip Chimento <philip.chimento@gmail.com>
Sat, 12 Dec 2009 19:52:38 +0000 (19:52 +0000)
git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@205 ddfedd41-794f-dd11-ae45-00112f111e67

player/callbacks.c
player/chimara.menus
player/chimara.ui
player/main.c

index a4c81a164992628c146ba0725463436ec0df3ba9..38629fe875da262df3d56369001eb85b2571103b 100644 (file)
 #include <gtk/gtk.h>
 #include <libchimara/chimara-glk.h>
 #include <libchimara/chimara-if.h>
+#include <config.h>
 #include "error.h"
 
-void 
-on_open_activate(GtkAction *action, ChimaraGlk *glk) 
+/* 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)) {
@@ -53,13 +60,23 @@ on_open_activate(GtkAction *action, ChimaraGlk *glk)
                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;
+                       return FALSE;
 
                chimara_glk_stop(glk);
                chimara_glk_wait(glk);
        }
+       return TRUE;
+}
+
+void 
+on_open_activate(GtkAction *action, ChimaraGlk *glk) 
+{
+       GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
+       
+       if(!confirm_open_new_game(glk))
+               return;
 
        GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Open Game"),
            window,
@@ -70,8 +87,24 @@ on_open_activate(GtkAction *action, ChimaraGlk *glk)
        if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
                GError *error = NULL;
                gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
-               if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error))
-                       error_dialog(window, error, _("Could not open game file."));
+               if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error)) {
+                       error_dialog(window, error, _("Could not open game file '%s': "), filename);
+                       g_free(filename);
+                       gtk_widget_destroy(dialog);
+                       return;
+               }
+               
+               /* Add file to recent files list */
+               GtkRecentManager *manager = gtk_recent_manager_get_default();
+               gchar *uri;
+               
+               if(!(uri = g_filename_to_uri(filename, NULL, &error)))
+                       g_warning(_("Could not convert filename '%s' to URI: %s"), filename, error->message);
+               else {
+                       if(!gtk_recent_manager_add_item(manager, uri))
+                               g_warning(_("Could not add URI '%s' to recent files list."), uri);
+                       g_free(uri);
+               }
                g_free(filename);
        }
        gtk_widget_destroy(dialog);
@@ -80,7 +113,36 @@ on_open_activate(GtkAction *action, ChimaraGlk *glk)
 void
 on_recent_item_activated(GtkRecentChooser *chooser, ChimaraGlk *glk)
 {
-
+       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;
+       }
+       
+       if(!confirm_open_new_game(glk)) {
+               g_free(filename);
+               g_free(uri);
+               return;
+       }
+       
+       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;
+       }
+       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);
+       
+       g_free(uri);
 }
 
 void
@@ -95,28 +157,31 @@ on_quit_chimara_activate(GtkAction *action, ChimaraGlk *glk)
        gtk_main_quit();
 }
 
-void
-on_cut_activate(GtkAction *action, ChimaraGlk *glk)
-{
-
-}
-
 void
 on_copy_activate(GtkAction *action, ChimaraGlk *glk)
 {
-
+       GtkWindow *toplevel = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
+       GtkWidget *focus = gtk_window_get_focus(toplevel);
+       /* 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)
 {
-
+       GtkWindow *toplevel = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
+       GtkWidget *focus = gtk_window_get_focus(toplevel);
+       /* 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)
 {
-
+       extern GtkWidget *prefswindow;
+       gtk_window_present(GTK_WINDOW(prefswindow));
 }
 
 void
@@ -152,7 +217,9 @@ on_quit_activate(GtkAction *action, ChimaraGlk *glk)
 void
 on_about_activate(GtkAction *action, ChimaraGlk *glk)
 {
-
+       extern GtkWidget *aboutwindow;
+       gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutwindow), PACKAGE_VERSION);
+       gtk_window_present(GTK_WINDOW(aboutwindow));
 }
 
 gboolean 
index 3127088e655361d71364819f142fc8f2c99995ad..ec43fb94a85df61fbf5165a3b415d4eaf345b90f 100644 (file)
@@ -9,7 +9,6 @@
       <menuitem action="quit_chimara"/>
     </menu>
     <menu action="edit">
-      <menuitem action="cut"/>
       <menuitem action="copy"/>
       <menuitem action="paste"/>
       <separator/>
index ce4753177f4e5436cae1baa1cbdd35945ee66dee..b00887856b4999778b262a9cc1866b2319636e03 100644 (file)
     <property name="stock_id">gtk-media-stop</property>
     <signal name="activate" handler="on_quit_activate"/>
   </object>
-  <object class="GtkAction" id="cut">
-    <property name="label">Cu_t</property>
-    <property name="tooltip">Cut the selection</property>
-    <property name="stock_id">gtk-cut</property>
-    <signal name="activate" handler="on_cut_activate"/>
-  </object>
   <object class="GtkAction" id="copy">
     <property name="label">_Copy</property>
     <property name="tooltip">Copy the selection</property>
     <property name="stock_id">gtk-about</property>
     <signal name="activate" handler="on_about_activate"/>
   </object>
+  <object class="GtkAboutDialog" id="aboutwindow">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">About Chimara</property>
+    <property name="window_position">center</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">False</property>
+    <property name="program_name">Chimara</property>
+    <property name="copyright" translatable="yes">&#xA9; 2008&#x2013;2009 Marijn van Vliet and Philip Chimento</property>
+    <property name="comments" translatable="yes">Interactive Fiction Player</property>
+    <property name="license" translatable="yes">Copyright (C) 2008, Philip Chimento and Marijn van Vliet.
+All rights reserved.
+
+Chimara is free software copyrighted by Philip Chimento and Marijn van Vliet.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+   list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation 
+   and/or other materials provided with the distribution.
+3. Neither of the names Philip Chimento or Marijn van Vliet, nor the name of any 
+   other contributor may be used to endorse or promote products derived from 
+   this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+</property>
+    <property name="authors">Marijn van Vliet
+Philip Chimento</property>
+    <signal name="response" handler="gtk_widget_hide"/>
+    <signal name="delete_event" handler="gtk_widget_hide_on_delete"/>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <placeholder/>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkDialog" id="prefswindow">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Chimara Preferences</property>
+    <property name="window_position">center</property>
+    <property name="type_hint">dialog</property>
+    <signal name="response" handler="gtk_widget_hide"/>
+    <signal name="delete_event" handler="gtk_widget_hide_on_delete"/>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox2">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">9</property>
+        <child>
+          <object class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkFrame" id="frame1">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkVBox" id="vbox2">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">8</property>
+                        <child>
+                          <object class="GtkCheckButton" id="checkbutton1">
+                            <property name="label" translatable="yes">_Awesome mode</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkCheckButton" id="checkbutton2">
+                            <property name="label" translatable="yes">_Super-awesome mode</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkCheckButton" id="checkbutton3">
+                            <property name="label" translatable="yes">_Ludicrous mode</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Miscellaneous options&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkFrame" id="frame2">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkVBox" id="vbox3">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <child>
+                          <object class="GtkScrolledWindow" id="scrolledwindow1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="hscrollbar_policy">automatic</property>
+                            <property name="vscrollbar_policy">automatic</property>
+                            <child>
+                              <object class="GtkTreeView" id="treeview1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkHButtonBox" id="hbuttonbox1">
+                            <property name="visible">True</property>
+                            <property name="spacing">7</property>
+                            <property name="layout_style">end</property>
+                            <child>
+                              <object class="GtkButton" id="button2">
+                                <property name="label">gtk-add</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="use_stock">True</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="button3">
+                                <property name="label">gtk-remove</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="use_stock">True</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Styles&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area2">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+                <signal name="clicked" handler="gtk_widget_hide" object="prefswindow"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">button1</action-widget>
+    </action-widgets>
+  </object>
 </interface>
index 9827d3193e9a57f20c0c27ed33439203ec3e1c8b..c032849cb63446e3bda8bc9878acfc40d0996ea0 100644 (file)
 #include <libchimara/chimara-glk.h>
 #include <libchimara/chimara-if.h>
 
-/* Global pointers to widgets */
-GtkBuilder *builder = NULL;
-GtkUIManager *uimanager = NULL;
-GtkWidget *window = NULL;
-GtkWidget *glk = NULL;
+/* Static global pointers to widgets */
+static GtkBuilder *builder = NULL;
+static GtkUIManager *uimanager = NULL;
+static GtkWidget *window = NULL;
+static GtkWidget *glk = NULL;
+
+/* Global global pointers */
+GtkWidget *aboutwindow = NULL;
+GtkWidget *prefswindow = NULL;
 
 static GObject *
 load_object(const gchar *name)
@@ -73,6 +77,8 @@ create_window(void)
        }
 
        window = GTK_WIDGET(load_object("chimara"));
+       aboutwindow = GTK_WIDGET(load_object("aboutwindow"));
+       prefswindow = GTK_WIDGET(load_object("prefswindow"));
        GtkActionGroup *actiongroup = GTK_ACTION_GROUP(load_object("actiongroup"));
 
        /* Add all the actions to the action group. This for-loop is a temporary fix
@@ -91,7 +97,6 @@ create_window(void)
                "restart", "",
                "quit", "",
                "edit", "",
-               "cut", NULL,
                "copy", NULL,
                "paste", NULL,
                "preferences", "",
@@ -102,6 +107,16 @@ create_window(void)
        const gchar **ptr;
        for(ptr = actions; *ptr; ptr += 2)
                gtk_action_group_add_action_with_accel(actiongroup, GTK_ACTION(load_object(ptr[0])), ptr[1]);
+       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);
 
        uimanager = gtk_ui_manager_new();
        if( !gtk_ui_manager_add_ui_from_file(uimanager, PACKAGE_SRC_DIR "/chimara.menus", &error) ) {