Created open game functionality in the player. Fix #37.
[rodin/chimara.git] / player / callbacks.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * callbacks.c
4  * Copyright (C) Philip en Marijn 2008 <>
5  * 
6  * callbacks.c is free software copyrighted by Philip en Marijn.
7  * 
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name ``Philip en Marijn'' nor the name of any other
17  *    contributor may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  * 
20  * callbacks.c IS PROVIDED BY Philip en Marijn ``AS IS'' AND ANY EXPRESS
21  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL Philip en Marijn OR ANY OTHER CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <glib.h>
34 #include <glib/gi18n.h>
35 #include <gtk/gtk.h>
36 #include <libchimara/chimara-glk.h>
37 #include <libchimara/chimara-if.h>
38 #include "error.h"
39
40 void 
41 on_open_activate(GtkAction *action, ChimaraGlk *glk) 
42 {
43         GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
44         
45         if(chimara_glk_get_running(glk)) {
46                 GtkWidget *dialog = gtk_message_dialog_new(window,
47                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
48                     GTK_MESSAGE_WARNING,
49                     GTK_BUTTONS_CANCEL,
50                     _("Are you sure you want to open a new game?"));
51                 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
52                     _("If you open a new game, you will quit the one you are currently playing."));
53                 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OPEN, GTK_RESPONSE_OK);
54                 gint response = gtk_dialog_run(GTK_DIALOG(dialog));
55                 gtk_widget_destroy(dialog);
56
57                 if(response != GTK_RESPONSE_OK)
58                         return;
59
60                 chimara_glk_stop(glk);
61                 chimara_glk_wait(glk);
62         }
63
64         GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Open Game"),
65             window,
66             GTK_FILE_CHOOSER_ACTION_OPEN,
67             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
68             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
69             NULL);
70         if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
71                 GError *error = NULL;
72                 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
73                 if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error))
74                         error_dialog(window, error, _("Could not open game file."));
75                 g_free(filename);
76         }
77         gtk_widget_destroy(dialog);
78 }
79
80 void
81 on_recent_item_activated(GtkRecentChooser *chooser, ChimaraGlk *glk)
82 {
83
84 }
85
86 void
87 on_stop_activate(GtkAction *action, ChimaraGlk *glk)
88 {
89         chimara_glk_stop(glk);
90 }
91
92 void 
93 on_quit_chimara_activate(GtkAction *action, ChimaraGlk *glk) 
94 {
95         gtk_main_quit();
96 }
97
98 void
99 on_cut_activate(GtkAction *action, ChimaraGlk *glk)
100 {
101
102 }
103
104 void
105 on_copy_activate(GtkAction *action, ChimaraGlk *glk)
106 {
107
108 }
109
110 void
111 on_paste_activate(GtkAction *action, ChimaraGlk *glk)
112 {
113
114 }
115
116 void
117 on_preferences_activate(GtkAction *action, ChimaraGlk *glk)
118 {
119
120 }
121
122 void
123 on_undo_activate(GtkAction *action, ChimaraGlk *glk)
124 {
125         chimara_glk_feed_line_input(glk, "undo");
126 }
127
128 void 
129 on_save_activate(GtkAction *action, ChimaraGlk *glk) 
130 {
131         chimara_glk_feed_line_input(glk, "save");
132 }
133
134 void 
135 on_restore_activate(GtkAction *action, ChimaraGlk *glk) 
136 {
137         chimara_glk_feed_line_input(glk, "restore");
138 }
139
140 void 
141 on_restart_activate(GtkAction *action, ChimaraGlk *glk) 
142 {
143         chimara_glk_feed_line_input(glk, "restart");
144 }
145
146 void 
147 on_quit_activate(GtkAction *action, ChimaraGlk *glk) 
148 {
149         chimara_glk_feed_line_input(glk, "quit");
150 }
151
152 void
153 on_about_activate(GtkAction *action, ChimaraGlk *glk)
154 {
155
156 }
157
158 gboolean 
159 on_window_delete_event(GtkWidget *widget, GdkEvent *event, ChimaraGlk *glk) 
160 {
161         gtk_main_quit();
162         return TRUE;
163 }