~ubuntu-branches/ubuntu/precise/gnome-games/precise-proposed

« back to all changes in this revision

Viewing changes to glchess/src/glchess.c

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya
  • Date: 2011-05-30 13:32:04 UTC
  • mfrom: (1.3.4)
  • mto: (163.1.3 precise)
  • mto: This revision was merged to the branch mainline in revision 143.
  • Revision ID: package-import@ubuntu.com-20110530133204-celaq1v1dsxc48q1
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* glchess.c generated by valac 0.12.0, the Vala compiler
 
2
 * generated from glchess.vala, do not modify */
 
3
 
 
4
/* Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=647122 */
 
5
 
 
6
#include <glib.h>
 
7
#include <glib-object.h>
 
8
#include <gtk/gtk.h>
 
9
#include <stdlib.h>
 
10
#include <string.h>
 
11
#include <gio/gio.h>
 
12
#include <config.h>
 
13
#include <glib/gi18n-lib.h>
 
14
#include <gdk/gdk.h>
 
15
#include <cairo.h>
 
16
#include <float.h>
 
17
#include <math.h>
 
18
#include <locale.h>
 
19
#include <stdio.h>
 
20
#include <gobject/gvaluecollector.h>
 
21
 
 
22
 
 
23
#define TYPE_APPLICATION (application_get_type ())
 
24
#define APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_APPLICATION, Application))
 
25
#define APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APPLICATION, ApplicationClass))
 
26
#define IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_APPLICATION))
 
27
#define IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APPLICATION))
 
28
#define APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APPLICATION, ApplicationClass))
 
29
 
 
30
typedef struct _Application Application;
 
31
typedef struct _ApplicationClass ApplicationClass;
 
32
typedef struct _ApplicationPrivate ApplicationPrivate;
 
33
 
 
34
#define TYPE_HISTORY (history_get_type ())
 
35
#define HISTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_HISTORY, History))
 
36
#define HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_HISTORY, HistoryClass))
 
37
#define IS_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_HISTORY))
 
38
#define IS_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_HISTORY))
 
39
#define HISTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_HISTORY, HistoryClass))
 
40
 
 
41
typedef struct _History History;
 
42
typedef struct _HistoryClass HistoryClass;
 
43
 
 
44
#define TYPE_CHESS_SCENE (chess_scene_get_type ())
 
45
#define CHESS_SCENE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_SCENE, ChessScene))
 
46
#define CHESS_SCENE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_SCENE, ChessSceneClass))
 
47
#define IS_CHESS_SCENE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_SCENE))
 
48
#define IS_CHESS_SCENE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_SCENE))
 
49
#define CHESS_SCENE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_SCENE, ChessSceneClass))
 
50
 
 
51
typedef struct _ChessScene ChessScene;
 
52
typedef struct _ChessSceneClass ChessSceneClass;
 
53
 
 
54
#define TYPE_CHESS_VIEW (chess_view_get_type ())
 
55
#define CHESS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_VIEW, ChessView))
 
56
#define CHESS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_VIEW, ChessViewClass))
 
57
#define IS_CHESS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_VIEW))
 
58
#define IS_CHESS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_VIEW))
 
59
#define CHESS_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_VIEW, ChessViewClass))
 
60
 
 
61
typedef struct _ChessView ChessView;
 
62
typedef struct _ChessViewClass ChessViewClass;
 
63
 
 
64
#define TYPE_PGN_GAME (pgn_game_get_type ())
 
65
#define PGN_GAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PGN_GAME, PGNGame))
 
66
#define PGN_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PGN_GAME, PGNGameClass))
 
67
#define IS_PGN_GAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PGN_GAME))
 
68
#define IS_PGN_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PGN_GAME))
 
69
#define PGN_GAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PGN_GAME, PGNGameClass))
 
70
 
 
71
typedef struct _PGNGame PGNGame;
 
72
typedef struct _PGNGameClass PGNGameClass;
 
73
 
 
74
#define TYPE_CHESS_GAME (chess_game_get_type ())
 
75
#define CHESS_GAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_GAME, ChessGame))
 
76
#define CHESS_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_GAME, ChessGameClass))
 
77
#define IS_CHESS_GAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_GAME))
 
78
#define IS_CHESS_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_GAME))
 
79
#define CHESS_GAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_GAME, ChessGameClass))
 
80
 
 
81
typedef struct _ChessGame ChessGame;
 
82
typedef struct _ChessGameClass ChessGameClass;
 
83
 
 
84
#define TYPE_AI_PROFILE (ai_profile_get_type ())
 
85
#define AI_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_AI_PROFILE, AIProfile))
 
86
#define AI_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_AI_PROFILE, AIProfileClass))
 
87
#define IS_AI_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_AI_PROFILE))
 
88
#define IS_AI_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_AI_PROFILE))
 
89
#define AI_PROFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_AI_PROFILE, AIProfileClass))
 
90
 
 
91
typedef struct _AIProfile AIProfile;
 
92
typedef struct _AIProfileClass AIProfileClass;
 
93
 
 
94
#define TYPE_CHESS_PLAYER (chess_player_get_type ())
 
95
#define CHESS_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_PLAYER, ChessPlayer))
 
96
#define CHESS_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_PLAYER, ChessPlayerClass))
 
97
#define IS_CHESS_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_PLAYER))
 
98
#define IS_CHESS_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_PLAYER))
 
99
#define CHESS_PLAYER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_PLAYER, ChessPlayerClass))
 
100
 
 
101
typedef struct _ChessPlayer ChessPlayer;
 
102
typedef struct _ChessPlayerClass ChessPlayerClass;
 
103
 
 
104
#define TYPE_CHESS_ENGINE (chess_engine_get_type ())
 
105
#define CHESS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_ENGINE, ChessEngine))
 
106
#define CHESS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_ENGINE, ChessEngineClass))
 
107
#define IS_CHESS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_ENGINE))
 
108
#define IS_CHESS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_ENGINE))
 
109
#define CHESS_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_ENGINE, ChessEngineClass))
 
110
 
 
111
typedef struct _ChessEngine ChessEngine;
 
112
typedef struct _ChessEngineClass ChessEngineClass;
 
113
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
 
114
#define _history_unref0(var) ((var == NULL) ? NULL : (var = (history_unref (var), NULL)))
 
115
#define _pgn_game_unref0(var) ((var == NULL) ? NULL : (var = (pgn_game_unref (var), NULL)))
 
116
#define _chess_game_unref0(var) ((var == NULL) ? NULL : (var = (chess_game_unref (var), NULL)))
 
117
#define __g_list_free__ai_profile_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__ai_profile_unref0_ (var), NULL)))
 
118
#define _g_free0(var) (var = (g_free (var), NULL))
 
119
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 
120
 
 
121
#define TYPE_CHESS_VIEW3_D (chess_view3_d_get_type ())
 
122
#define CHESS_VIEW3_D(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_VIEW3_D, ChessView3D))
 
123
#define CHESS_VIEW3_D_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_VIEW3_D, ChessView3DClass))
 
124
#define IS_CHESS_VIEW3_D(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_VIEW3_D))
 
125
#define IS_CHESS_VIEW3_D_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_VIEW3_D))
 
126
#define CHESS_VIEW3_D_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_VIEW3_D, ChessView3DClass))
 
127
 
 
128
typedef struct _ChessView3D ChessView3D;
 
129
typedef struct _ChessView3DClass ChessView3DClass;
 
130
 
 
131
#define TYPE_CHESS_VIEW2_D (chess_view2_d_get_type ())
 
132
#define CHESS_VIEW2_D(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_VIEW2_D, ChessView2D))
 
133
#define CHESS_VIEW2_D_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_VIEW2_D, ChessView2DClass))
 
134
#define IS_CHESS_VIEW2_D(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_VIEW2_D))
 
135
#define IS_CHESS_VIEW2_D_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_VIEW2_D))
 
136
#define CHESS_VIEW2_D_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_VIEW2_D, ChessView2DClass))
 
137
 
 
138
typedef struct _ChessView2D ChessView2D;
 
139
typedef struct _ChessView2DClass ChessView2DClass;
 
140
typedef struct _ChessGamePrivate ChessGamePrivate;
 
141
 
 
142
#define TYPE_CHESS_RESULT (chess_result_get_type ())
 
143
 
 
144
#define TYPE_CHESS_RULE (chess_rule_get_type ())
 
145
 
 
146
#define TYPE_CHESS_STATE (chess_state_get_type ())
 
147
#define CHESS_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_STATE, ChessState))
 
148
#define CHESS_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_STATE, ChessStateClass))
 
149
#define IS_CHESS_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_STATE))
 
150
#define IS_CHESS_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_STATE))
 
151
#define CHESS_STATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_STATE, ChessStateClass))
 
152
 
 
153
typedef struct _ChessState ChessState;
 
154
typedef struct _ChessStateClass ChessStateClass;
 
155
typedef struct _ChessStatePrivate ChessStatePrivate;
 
156
 
 
157
#define TYPE_CHECK_STATE (check_state_get_type ())
 
158
 
 
159
#define TYPE_CHESS_PIECE (chess_piece_get_type ())
 
160
#define CHESS_PIECE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_PIECE, ChessPiece))
 
161
#define CHESS_PIECE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_PIECE, ChessPieceClass))
 
162
#define IS_CHESS_PIECE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_PIECE))
 
163
#define IS_CHESS_PIECE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_PIECE))
 
164
#define CHESS_PIECE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_PIECE, ChessPieceClass))
 
165
 
 
166
typedef struct _ChessPiece ChessPiece;
 
167
typedef struct _ChessPieceClass ChessPieceClass;
 
168
 
 
169
#define TYPE_CHESS_MOVE (chess_move_get_type ())
 
170
#define CHESS_MOVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_MOVE, ChessMove))
 
171
#define CHESS_MOVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_MOVE, ChessMoveClass))
 
172
#define IS_CHESS_MOVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_MOVE))
 
173
#define IS_CHESS_MOVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_MOVE))
 
174
#define CHESS_MOVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_MOVE, ChessMoveClass))
 
175
 
 
176
typedef struct _ChessMove ChessMove;
 
177
typedef struct _ChessMoveClass ChessMoveClass;
 
178
#define _chess_state_unref0(var) ((var == NULL) ? NULL : (var = (chess_state_unref (var), NULL)))
 
179
typedef struct _PGNGamePrivate PGNGamePrivate;
 
180
 
 
181
#define TYPE_CHESS_CLOCK (chess_clock_get_type ())
 
182
#define CHESS_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_CLOCK, ChessClock))
 
183
#define CHESS_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_CLOCK, ChessClockClass))
 
184
#define IS_CHESS_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_CLOCK))
 
185
#define IS_CHESS_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_CLOCK))
 
186
#define CHESS_CLOCK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_CLOCK, ChessClockClass))
 
187
 
 
188
typedef struct _ChessClock ChessClock;
 
189
typedef struct _ChessClockClass ChessClockClass;
 
190
#define _ai_profile_unref0(var) ((var == NULL) ? NULL : (var = (ai_profile_unref (var), NULL)))
 
191
typedef struct _AIProfilePrivate AIProfilePrivate;
 
192
 
 
193
#define TYPE_CHESS_ENGINE_CECP (chess_engine_cecp_get_type ())
 
194
#define CHESS_ENGINE_CECP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_ENGINE_CECP, ChessEngineCECP))
 
195
#define CHESS_ENGINE_CECP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_ENGINE_CECP, ChessEngineCECPClass))
 
196
#define IS_CHESS_ENGINE_CECP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_ENGINE_CECP))
 
197
#define IS_CHESS_ENGINE_CECP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_ENGINE_CECP))
 
198
#define CHESS_ENGINE_CECP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_ENGINE_CECP, ChessEngineCECPClass))
 
199
 
 
200
typedef struct _ChessEngineCECP ChessEngineCECP;
 
201
typedef struct _ChessEngineCECPClass ChessEngineCECPClass;
 
202
 
 
203
#define TYPE_CHESS_ENGINE_UCI (chess_engine_uci_get_type ())
 
204
#define CHESS_ENGINE_UCI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_ENGINE_UCI, ChessEngineUCI))
 
205
#define CHESS_ENGINE_UCI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_ENGINE_UCI, ChessEngineUCIClass))
 
206
#define IS_CHESS_ENGINE_UCI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_ENGINE_UCI))
 
207
#define IS_CHESS_ENGINE_UCI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_ENGINE_UCI))
 
208
#define CHESS_ENGINE_UCI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_ENGINE_UCI, ChessEngineUCIClass))
 
209
 
 
210
typedef struct _ChessEngineUCI ChessEngineUCI;
 
211
typedef struct _ChessEngineUCIClass ChessEngineUCIClass;
 
212
typedef struct _ChessEnginePrivate ChessEnginePrivate;
 
213
#define __g_list_free__g_object_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_object_unref0_ (var), NULL)))
 
214
typedef struct _ChessMovePrivate ChessMovePrivate;
 
215
typedef struct _ChessPiecePrivate ChessPiecePrivate;
 
216
 
 
217
#define TYPE_PIECE_TYPE (piece_type_get_type ())
 
218
typedef struct _ChessPlayerPrivate ChessPlayerPrivate;
 
219
 
 
220
#define TYPE_COLOR (color_get_type ())
 
221
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
 
222
 
 
223
#define TYPE_PGN (pgn_get_type ())
 
224
#define PGN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PGN, PGN))
 
225
#define PGN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PGN, PGNClass))
 
226
#define IS_PGN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PGN))
 
227
#define IS_PGN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PGN))
 
228
#define PGN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PGN, PGNClass))
 
229
 
 
230
typedef struct _PGN PGN;
 
231
typedef struct _PGNClass PGNClass;
 
232
typedef struct _PGNPrivate PGNPrivate;
 
233
#define _pgn_unref0(var) ((var == NULL) ? NULL : (var = (pgn_unref (var), NULL)))
 
234
typedef struct _ParamSpecApplication ParamSpecApplication;
 
235
 
 
236
#define TYPE_GL_CHESS (gl_chess_get_type ())
 
237
#define GL_CHESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_CHESS, GlChess))
 
238
#define GL_CHESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_CHESS, GlChessClass))
 
239
#define IS_GL_CHESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_CHESS))
 
240
#define IS_GL_CHESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_CHESS))
 
241
#define GL_CHESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GL_CHESS, GlChessClass))
 
242
 
 
243
typedef struct _GlChess GlChess;
 
244
typedef struct _GlChessClass GlChessClass;
 
245
typedef struct _GlChessPrivate GlChessPrivate;
 
246
#define _application_unref0(var) ((var == NULL) ? NULL : (var = (application_unref (var), NULL)))
 
247
typedef struct _ParamSpecGlChess ParamSpecGlChess;
 
248
 
 
249
struct _Application {
 
250
        GTypeInstance parent_instance;
 
251
        volatile int ref_count;
 
252
        ApplicationPrivate * priv;
 
253
};
 
254
 
 
255
struct _ApplicationClass {
 
256
        GTypeClass parent_class;
 
257
        void (*finalize) (Application *self);
 
258
};
 
259
 
 
260
struct _ApplicationPrivate {
 
261
        GSettings* settings;
 
262
        History* history;
 
263
        GtkBuilder* builder;
 
264
        GtkBuilder* preferences_builder;
 
265
        GtkWindow* window;
 
266
        GtkWidget* save_menu;
 
267
        GtkWidget* save_as_menu;
 
268
        GtkMenuItem* fullscreen_menu;
 
269
        GtkInfoBar* info_bar;
 
270
        GtkLabel* info_title_label;
 
271
        GtkLabel* info_label;
 
272
        GtkContainer* view_container;
 
273
        ChessScene* scene;
 
274
        ChessView* view;
 
275
        GtkWidget* undo_menu;
 
276
        GtkWidget* undo_button;
 
277
        GtkWidget* resign_menu;
 
278
        GtkWidget* resign_button;
 
279
        GtkWidget* first_move_button;
 
280
        GtkWidget* prev_move_button;
 
281
        GtkWidget* next_move_button;
 
282
        GtkWidget* last_move_button;
 
283
        GtkComboBox* history_combo;
 
284
        GtkWidget* white_time_label;
 
285
        GtkWidget* black_time_label;
 
286
        GtkDialog* preferences_dialog;
 
287
        GtkComboBox* duration_combo;
 
288
        GtkAdjustment* duration_adjustment;
 
289
        GtkContainer* custom_duration_box;
 
290
        GtkComboBox* custom_duration_units_combo;
 
291
        guint save_duration_timeout;
 
292
        GtkFileChooserDialog* open_dialog;
 
293
        GtkInfoBar* open_dialog_info_bar;
 
294
        GtkLabel* open_dialog_error_label;
 
295
        GtkFileChooserDialog* save_dialog;
 
296
        GtkInfoBar* save_dialog_info_bar;
 
297
        GtkLabel* save_dialog_error_label;
 
298
        GtkAboutDialog* about_dialog;
 
299
        PGNGame* pgn_game;
 
300
        ChessGame* game;
 
301
        gboolean in_history;
 
302
        GFile* game_file;
 
303
        gboolean game_needs_saving;
 
304
        GList* ai_profiles;
 
305
        ChessPlayer* opponent;
 
306
        ChessPlayer* human_player;
 
307
        ChessEngine* opponent_engine;
 
308
};
 
309
 
 
310
typedef enum  {
 
311
        CHESS_RESULT_IN_PROGRESS,
 
312
        CHESS_RESULT_WHITE_WON,
 
313
        CHESS_RESULT_BLACK_WON,
 
314
        CHESS_RESULT_DRAW
 
315
} ChessResult;
 
316
 
 
317
typedef enum  {
 
318
        CHESS_RULE_CHECKMATE,
 
319
        CHESS_RULE_STALEMATE,
 
320
        CHESS_RULE_FIFTY_MOVES,
 
321
        CHESS_RULE_TIMEOUT,
 
322
        CHESS_RULE_THREE_FOLD_REPETITION,
 
323
        CHESS_RULE_INSUFFICIENT_MATERIAL,
 
324
        CHESS_RULE_RESIGN,
 
325
        CHESS_RULE_ABANDONMENT,
 
326
        CHESS_RULE_DEATH
 
327
} ChessRule;
 
328
 
 
329
struct _ChessGame {
 
330
        GTypeInstance parent_instance;
 
331
        volatile int ref_count;
 
332
        ChessGamePrivate * priv;
 
333
        gboolean is_started;
 
334
        ChessResult result;
 
335
        ChessRule rule;
 
336
        GList* move_stack;
 
337
};
 
338
 
 
339
struct _ChessGameClass {
 
340
        GTypeClass parent_class;
 
341
        void (*finalize) (ChessGame *self);
 
342
};
 
343
 
 
344
typedef enum  {
 
345
        CHECK_STATE_NONE,
 
346
        CHECK_STATE_CHECK,
 
347
        CHECK_STATE_CHECKMATE
 
348
} CheckState;
 
349
 
 
350
struct _ChessState {
 
351
        GTypeInstance parent_instance;
 
352
        volatile int ref_count;
 
353
        ChessStatePrivate * priv;
 
354
        gint number;
 
355
        ChessPlayer* players[2];
 
356
        ChessPlayer* current_player;
 
357
        gboolean can_castle_kingside[2];
 
358
        gboolean can_castle_queenside[2];
 
359
        gint en_passant_index;
 
360
        CheckState check_state;
 
361
        gint halfmove_clock;
 
362
        ChessPiece* board[64];
 
363
        ChessMove* last_move;
 
364
};
 
365
 
 
366
struct _ChessStateClass {
 
367
        GTypeClass parent_class;
 
368
        void (*finalize) (ChessState *self);
 
369
};
 
370
 
 
371
struct _PGNGame {
 
372
        GTypeInstance parent_instance;
 
373
        volatile int ref_count;
 
374
        PGNGamePrivate * priv;
 
375
        GHashTable* tags;
 
376
        GList* moves;
 
377
};
 
378
 
 
379
struct _PGNGameClass {
 
380
        GTypeClass parent_class;
 
381
        void (*finalize) (PGNGame *self);
 
382
};
 
383
 
 
384
struct _AIProfile {
 
385
        GTypeInstance parent_instance;
 
386
        volatile int ref_count;
 
387
        AIProfilePrivate * priv;
 
388
        gchar* name;
 
389
        gchar* protocol;
 
390
        gchar* binary;
 
391
        gchar* path;
 
392
        gchar* args;
 
393
        gchar** easy_options;
 
394
        gint easy_options_length1;
 
395
        gchar** normal_options;
 
396
        gint normal_options_length1;
 
397
        gchar** hard_options;
 
398
        gint hard_options_length1;
 
399
};
 
400
 
 
401
struct _AIProfileClass {
 
402
        GTypeClass parent_class;
 
403
        void (*finalize) (AIProfile *self);
 
404
};
 
405
 
 
406
struct _ChessEngine {
 
407
        GObject parent_instance;
 
408
        ChessEnginePrivate * priv;
 
409
        gchar* binary;
 
410
};
 
411
 
 
412
struct _ChessEngineClass {
 
413
        GObjectClass parent_class;
 
414
        void (*process_input) (ChessEngine* self, gchar* data, int data_length1);
 
415
        void (*start_game) (ChessEngine* self);
 
416
        void (*request_move) (ChessEngine* self);
 
417
        void (*report_move) (ChessEngine* self, ChessMove* move);
 
418
        void (*undo) (ChessEngine* self);
 
419
};
 
420
 
 
421
struct _ChessMove {
 
422
        GTypeInstance parent_instance;
 
423
        volatile int ref_count;
 
424
        ChessMovePrivate * priv;
 
425
        gint number;
 
426
        ChessPiece* piece;
 
427
        ChessPiece* promotion_piece;
 
428
        ChessPiece* moved_rook;
 
429
        ChessPiece* victim;
 
430
        gint r0;
 
431
        gint f0;
 
432
        gint r1;
 
433
        gint f1;
 
434
        gboolean ambiguous_rank;
 
435
        gboolean ambiguous_file;
 
436
        CheckState check_state;
 
437
};
 
438
 
 
439
struct _ChessMoveClass {
 
440
        GTypeClass parent_class;
 
441
        void (*finalize) (ChessMove *self);
 
442
};
 
443
 
 
444
typedef enum  {
 
445
        PIECE_TYPE_PAWN,
 
446
        PIECE_TYPE_ROOK,
 
447
        PIECE_TYPE_KNIGHT,
 
448
        PIECE_TYPE_BISHOP,
 
449
        PIECE_TYPE_QUEEN,
 
450
        PIECE_TYPE_KING
 
451
} PieceType;
 
452
 
 
453
struct _ChessPiece {
 
454
        GTypeInstance parent_instance;
 
455
        volatile int ref_count;
 
456
        ChessPiecePrivate * priv;
 
457
        ChessPlayer* player;
 
458
        PieceType type;
 
459
};
 
460
 
 
461
struct _ChessPieceClass {
 
462
        GTypeClass parent_class;
 
463
        void (*finalize) (ChessPiece *self);
 
464
};
 
465
 
 
466
typedef enum  {
 
467
        COLOR_WHITE,
 
468
        COLOR_BLACK
 
469
} Color;
 
470
 
 
471
struct _ChessPlayer {
 
472
        GObject parent_instance;
 
473
        ChessPlayerPrivate * priv;
 
474
        Color color;
 
475
};
 
476
 
 
477
struct _ChessPlayerClass {
 
478
        GObjectClass parent_class;
 
479
};
 
480
 
 
481
struct _PGN {
 
482
        GTypeInstance parent_instance;
 
483
        volatile int ref_count;
 
484
        PGNPrivate * priv;
 
485
        GList* games;
 
486
};
 
487
 
 
488
struct _PGNClass {
 
489
        GTypeClass parent_class;
 
490
        void (*finalize) (PGN *self);
 
491
};
 
492
 
 
493
struct _ParamSpecApplication {
 
494
        GParamSpec parent_instance;
 
495
};
 
496
 
 
497
struct _GlChess {
 
498
        GTypeInstance parent_instance;
 
499
        volatile int ref_count;
 
500
        GlChessPrivate * priv;
 
501
};
 
502
 
 
503
struct _GlChessClass {
 
504
        GTypeClass parent_class;
 
505
        void (*finalize) (GlChess *self);
 
506
};
 
507
 
 
508
struct _ParamSpecGlChess {
 
509
        GParamSpec parent_instance;
 
510
};
 
511
 
 
512
 
 
513
static gpointer application_parent_class = NULL;
 
514
extern gchar* pgn_game_RESULT_WHITE;
 
515
extern gchar* pgn_game_RESULT_BLACK;
 
516
extern gchar* pgn_game_RESULT_DRAW;
 
517
extern gchar* pgn_game_TERMINATE_ABANDONED;
 
518
extern gchar* pgn_game_TERMINATE_DEATH;
 
519
static gpointer gl_chess_parent_class = NULL;
 
520
 
 
521
void gtk_file_filter_set_name (GtkFileFilter* filter, const gchar* name);
 
522
gpointer application_ref (gpointer instance);
 
523
void application_unref (gpointer instance);
 
524
GParamSpec* param_spec_application (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
525
void value_set_application (GValue* value, gpointer v_object);
 
526
void value_take_application (GValue* value, gpointer v_object);
 
527
gpointer value_get_application (const GValue* value);
 
528
GType application_get_type (void) G_GNUC_CONST;
 
529
gpointer history_ref (gpointer instance);
 
530
void history_unref (gpointer instance);
 
531
GParamSpec* param_spec_history (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
532
void value_set_history (GValue* value, gpointer v_object);
 
533
void value_take_history (GValue* value, gpointer v_object);
 
534
gpointer value_get_history (const GValue* value);
 
535
GType history_get_type (void) G_GNUC_CONST;
 
536
GType chess_scene_get_type (void) G_GNUC_CONST;
 
537
GType chess_view_get_type (void) G_GNUC_CONST;
 
538
gpointer pgn_game_ref (gpointer instance);
 
539
void pgn_game_unref (gpointer instance);
 
540
GParamSpec* param_spec_pgn_game (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
541
void value_set_pgn_game (GValue* value, gpointer v_object);
 
542
void value_take_pgn_game (GValue* value, gpointer v_object);
 
543
gpointer value_get_pgn_game (const GValue* value);
 
544
GType pgn_game_get_type (void) G_GNUC_CONST;
 
545
gpointer chess_game_ref (gpointer instance);
 
546
void chess_game_unref (gpointer instance);
 
547
GParamSpec* param_spec_chess_game (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
548
void value_set_chess_game (GValue* value, gpointer v_object);
 
549
void value_take_chess_game (GValue* value, gpointer v_object);
 
550
gpointer value_get_chess_game (const GValue* value);
 
551
GType chess_game_get_type (void) G_GNUC_CONST;
 
552
gpointer ai_profile_ref (gpointer instance);
 
553
void ai_profile_unref (gpointer instance);
 
554
GParamSpec* param_spec_ai_profile (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
555
void value_set_ai_profile (GValue* value, gpointer v_object);
 
556
void value_take_ai_profile (GValue* value, gpointer v_object);
 
557
gpointer value_get_ai_profile (const GValue* value);
 
558
GType ai_profile_get_type (void) G_GNUC_CONST;
 
559
GType chess_player_get_type (void) G_GNUC_CONST;
 
560
GType chess_engine_get_type (void) G_GNUC_CONST;
 
561
#define APPLICATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_APPLICATION, ApplicationPrivate))
 
562
enum  {
 
563
        APPLICATION_DUMMY_PROPERTY
 
564
};
 
565
static void _ai_profile_unref0_ (gpointer var);
 
566
static void _g_list_free__ai_profile_unref0_ (GList* self);
 
567
Application* application_new (void);
 
568
Application* application_construct (GType object_type);
 
569
History* history_new (GFile* data_dir);
 
570
History* history_construct (GType object_type, GFile* data_dir);
 
571
ChessScene* chess_scene_new (void);
 
572
ChessScene* chess_scene_construct (GType object_type);
 
573
static void application_scene_changed_cb (Application* self, ChessScene* scene);
 
574
static void _application_scene_changed_cb_chess_scene_changed (ChessScene* _sender, gpointer self);
 
575
static void application_settings_changed_cb (Application* self, GSettings* settings, const gchar* key);
 
576
static void _application_settings_changed_cb_g_settings_changed (GSettings* _sender, const gchar* key, gpointer self);
 
577
void application_quit (Application* self);
 
578
static gboolean application_save_duration_cb (Application* self);
 
579
static void application_autosave (Application* self);
 
580
void history_remove (History* self, GFile* file);
 
581
void history_update (History* self, GFile* file, const gchar* fen, const gchar* _result_);
 
582
const gchar* pgn_game_get_result (PGNGame* self);
 
583
GFile* history_add (History* self, const gchar* date, const gchar* _result_, GError** error);
 
584
const gchar* pgn_game_get_date (PGNGame* self);
 
585
void pgn_game_write (PGNGame* self, GFile* file, GError** error);
 
586
ChessView3D* chess_view3_d_new (void);
 
587
ChessView3D* chess_view3_d_construct (GType object_type);
 
588
GType chess_view3_d_get_type (void) G_GNUC_CONST;
 
589
ChessView2D* chess_view2_d_new (void);
 
590
ChessView2D* chess_view2_d_construct (GType object_type);
 
591
GType chess_view2_d_get_type (void) G_GNUC_CONST;
 
592
void chess_view_set_scene (ChessView* self, ChessScene* value);
 
593
static void application_update_history_panel (Application* self);
 
594
gint chess_scene_get_move_number (ChessScene* self);
 
595
guint chess_game_get_n_moves (ChessGame* self);
 
596
GType chess_result_get_type (void) G_GNUC_CONST;
 
597
GType chess_rule_get_type (void) G_GNUC_CONST;
 
598
gpointer chess_state_ref (gpointer instance);
 
599
void chess_state_unref (gpointer instance);
 
600
GParamSpec* param_spec_chess_state (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
601
void value_set_chess_state (GValue* value, gpointer v_object);
 
602
void value_take_chess_state (GValue* value, gpointer v_object);
 
603
gpointer value_get_chess_state (const GValue* value);
 
604
GType chess_state_get_type (void) G_GNUC_CONST;
 
605
GType check_state_get_type (void) G_GNUC_CONST;
 
606
gpointer chess_piece_ref (gpointer instance);
 
607
void chess_piece_unref (gpointer instance);
 
608
GParamSpec* param_spec_chess_piece (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
609
void value_set_chess_piece (GValue* value, gpointer v_object);
 
610
void value_take_chess_piece (GValue* value, gpointer v_object);
 
611
gpointer value_get_chess_piece (const GValue* value);
 
612
GType chess_piece_get_type (void) G_GNUC_CONST;
 
613
gpointer chess_move_ref (gpointer instance);
 
614
void chess_move_unref (gpointer instance);
 
615
GParamSpec* param_spec_chess_move (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
616
void value_set_chess_move (GValue* value, gpointer v_object);
 
617
void value_take_chess_move (GValue* value, gpointer v_object);
 
618
gpointer value_get_chess_move (const GValue* value);
 
619
GType chess_move_get_type (void) G_GNUC_CONST;
 
620
static void application_set_move_text (Application* self, GtkTreeIter* iter, ChessMove* move);
 
621
static void application_start_game (Application* self);
 
622
#define CHESS_GAME_STANDARD_SETUP "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
 
623
gboolean pgn_game_get_set_up (PGNGame* self);
 
624
const gchar* pgn_game_get_fen (PGNGame* self);
 
625
ChessGame* chess_game_new (const gchar* fen, gchar** moves, int moves_length1);
 
626
ChessGame* chess_game_construct (GType object_type, const gchar* fen, gchar** moves, int moves_length1);
 
627
const gchar* pgn_game_get_time_control (PGNGame* self);
 
628
ChessClock* chess_clock_new (guint white_duration, guint black_duration, guint white_used, guint black_used);
 
629
ChessClock* chess_clock_construct (GType object_type, guint white_duration, guint black_duration, guint white_used, guint black_used);
 
630
GType chess_clock_get_type (void) G_GNUC_CONST;
 
631
void chess_game_set_clock (ChessGame* self, ChessClock* value);
 
632
static void application_game_start_cb (Application* self, ChessGame* game);
 
633
static void _application_game_start_cb_chess_game_started (ChessGame* _sender, gpointer self);
 
634
static void application_game_turn_cb (Application* self, ChessGame* game, ChessPlayer* player);
 
635
static void _application_game_turn_cb_chess_game_turn_started (ChessGame* _sender, ChessPlayer* player, gpointer self);
 
636
static void application_game_move_cb (Application* self, ChessGame* game, ChessMove* move);
 
637
static void _application_game_move_cb_chess_game_moved (ChessGame* _sender, ChessMove* move, gpointer self);
 
638
static void application_game_undo_cb (Application* self, ChessGame* game);
 
639
static void _application_game_undo_cb_chess_game_undo (ChessGame* _sender, gpointer self);
 
640
static void application_game_end_cb (Application* self, ChessGame* game);
 
641
static void _application_game_end_cb_chess_game_ended (ChessGame* _sender, gpointer self);
 
642
ChessClock* chess_game_get_clock (ChessGame* self);
 
643
static void application_game_clock_tick_cb (Application* self, ChessClock* clock);
 
644
static void _application_game_clock_tick_cb_chess_clock_tick (ChessClock* _sender, gpointer self);
 
645
void chess_scene_set_game (ChessScene* self, ChessGame* value);
 
646
static void application_update_control_buttons (Application* self);
 
647
ChessPlayer* chess_game_get_white (ChessGame* self);
 
648
ChessPlayer* chess_game_get_black (ChessGame* self);
 
649
static ChessEngine* application_get_engine (Application* self, const gchar* name, const gchar* difficulty);
 
650
static void application_engine_ready_cb (Application* self, ChessEngine* engine);
 
651
static void _application_engine_ready_cb_chess_engine_ready_changed (ChessEngine* _sender, gpointer self);
 
652
static void application_engine_move_cb (Application* self, ChessEngine* engine, const gchar* move);
 
653
static void _application_engine_move_cb_chess_engine_moved (ChessEngine* _sender, const gchar* move, gpointer self);
 
654
gboolean chess_engine_start (ChessEngine* self);
 
655
void chess_game_start (ChessGame* self);
 
656
static gchar** _vala_array_dup2 (gchar** self, int length);
 
657
static gchar** _vala_array_dup3 (gchar** self, int length);
 
658
static gchar** _vala_array_dup4 (gchar** self, int length);
 
659
ChessEngineCECP* chess_engine_cecp_new (gchar** options, int options_length1);
 
660
ChessEngineCECP* chess_engine_cecp_construct (GType object_type, gchar** options, int options_length1);
 
661
GType chess_engine_cecp_get_type (void) G_GNUC_CONST;
 
662
ChessEngineUCI* chess_engine_uci_new (gchar** options, int options_length1);
 
663
ChessEngineUCI* chess_engine_uci_construct (GType object_type, gchar** options, int options_length1);
 
664
GType chess_engine_uci_get_type (void) G_GNUC_CONST;
 
665
void application_start (Application* self, GFile* game, GError** error);
 
666
GList* load_ai_profiles (const gchar* filename);
 
667
GList* history_get_unfinished (History* self);
 
668
static void application_load_game (Application* self, GFile* file, gboolean from_history, GError** error);
 
669
static void _g_object_unref0_ (gpointer var);
 
670
static void _g_list_free__g_object_unref0_ (GList* self);
 
671
static void application_start_new_game (Application* self);
 
672
void application_show (Application* self);
 
673
gboolean chess_engine_get_ready (ChessEngine* self);
 
674
gboolean chess_player_move (ChessPlayer* self, const gchar* move, gboolean apply);
 
675
void chess_engine_start_game (ChessEngine* self);
 
676
void chess_engine_request_move (ChessEngine* self);
 
677
const gchar* chess_scene_get_move_format (ChessScene* self);
 
678
GType piece_type_get_type (void) G_GNUC_CONST;
 
679
GType color_get_type (void) G_GNUC_CONST;
 
680
gchar* chess_move_get_san (ChessMove* self);
 
681
gchar* chess_move_get_fan (ChessMove* self);
 
682
gchar* chess_move_get_lan (ChessMove* self);
 
683
void chess_engine_report_move (ChessEngine* self, ChessMove* move);
 
684
void chess_engine_undo (ChessEngine* self);
 
685
void pgn_game_set_result (PGNGame* self, const gchar* value);
 
686
void pgn_game_set_termination (PGNGame* self, const gchar* value);
 
687
gboolean G_MODULE_EXPORT glchess_app_delete_event_cb (GtkWidget* widget, GdkEvent* event, Application* self);
 
688
gboolean G_MODULE_EXPORT glchess_app_configure_event_cb (GtkWidget* widget, GdkEventConfigure* event, Application* self);
 
689
gboolean G_MODULE_EXPORT glchess_app_window_state_event_cb (GtkWidget* widget, GdkEventWindowState* event, Application* self);
 
690
void G_MODULE_EXPORT new_game_cb (GtkWidget* widget, Application* self);
 
691
void G_MODULE_EXPORT resign_cb (GtkWidget* widget, Application* self);
 
692
ChessPlayer* chess_game_get_current_player (ChessGame* self);
 
693
gboolean chess_player_resign (ChessPlayer* self);
 
694
void G_MODULE_EXPORT claim_draw_cb (GtkWidget* widget, Application* self);
 
695
gboolean chess_player_claim_draw (ChessPlayer* self);
 
696
void G_MODULE_EXPORT undo_move_cb (GtkWidget* widget, Application* self);
 
697
void chess_player_undo (ChessPlayer* self);
 
698
ChessPlayer* chess_game_get_opponent (ChessGame* self);
 
699
void G_MODULE_EXPORT quit_cb (GtkWidget* widget, Application* self);
 
700
gboolean G_MODULE_EXPORT white_time_draw_cb (GtkWidget* widget, cairo_t* c, Application* self);
 
701
static void application_draw_time (Application* self, GtkWidget* widget, cairo_t* c, const gchar* text, gdouble* fg, int fg_length1, gdouble* bg, int bg_length1);
 
702
static gchar* application_make_clock_text (Application* self, ChessClock* clock, Color color);
 
703
gboolean G_MODULE_EXPORT black_time_draw_cb (GtkWidget* widget, cairo_t* c, Application* self);
 
704
guint chess_clock_get_white_duration (ChessClock* self);
 
705
guint chess_clock_get_white_used_in_seconds (ChessClock* self);
 
706
guint chess_clock_get_black_duration (ChessClock* self);
 
707
guint chess_clock_get_black_used_in_seconds (ChessClock* self);
 
708
void G_MODULE_EXPORT history_combo_changed_cb (GtkComboBox* combo, Application* self);
 
709
void chess_scene_set_move_number (ChessScene* self, gint value);
 
710
void G_MODULE_EXPORT history_latest_clicked_cb (GtkWidget* widget, Application* self);
 
711
void G_MODULE_EXPORT history_next_clicked_cb (GtkWidget* widget, Application* self);
 
712
void G_MODULE_EXPORT history_previous_clicked_cb (GtkWidget* widget, Application* self);
 
713
void G_MODULE_EXPORT history_start_clicked_cb (GtkWidget* widget, Application* self);
 
714
void G_MODULE_EXPORT toggle_fullscreen_cb (GtkWidget* widget, Application* self);
 
715
void G_MODULE_EXPORT preferences_cb (GtkWidget* widget, Application* self);
 
716
static void application_set_combo (Application* self, GtkComboBox* combo, gint value_index, const gchar* value);
 
717
static void application_set_duration (Application* self, gint duration, gboolean simplify);
 
718
static gchar* application_get_combo (Application* self, GtkComboBox* combo, gint value_index);
 
719
void G_MODULE_EXPORT side_combo_changed_cb (GtkComboBox* combo, Application* self);
 
720
void G_MODULE_EXPORT opponent_combo_changed_cb (GtkComboBox* combo, Application* self);
 
721
void G_MODULE_EXPORT difficulty_combo_changed_cb (GtkComboBox* combo, Application* self);
 
722
static gint application_get_duration (Application* self);
 
723
void G_MODULE_EXPORT duration_changed_cb (GtkAdjustment* adjustment, Application* self);
 
724
static void application_save_duration (Application* self);
 
725
void G_MODULE_EXPORT duration_units_changed_cb (GtkWidget* widget, Application* self);
 
726
static gboolean _application_save_duration_cb_gsource_func (gpointer self);
 
727
void G_MODULE_EXPORT duration_combo_changed_cb (GtkComboBox* combo, Application* self);
 
728
void G_MODULE_EXPORT preferences_response_cb (GtkWidget* widget, gint response_id, Application* self);
 
729
gboolean G_MODULE_EXPORT preferences_delete_event_cb (GtkWidget* widget, GdkEvent* event, Application* self);
 
730
void G_MODULE_EXPORT piece_style_combo_changed_cb (GtkComboBox* combo, Application* self);
 
731
void G_MODULE_EXPORT show_3d_toggle_cb (GtkToggleButton* widget, Application* self);
 
732
void G_MODULE_EXPORT promotion_type_combo_changed_cb (GtkComboBox* combo, Application* self);
 
733
void G_MODULE_EXPORT move_format_combo_changed_cb (GtkComboBox* combo, Application* self);
 
734
void G_MODULE_EXPORT orientation_combo_changed_cb (GtkComboBox* combo, Application* self);
 
735
void G_MODULE_EXPORT help_cb (GtkWidget* widget, Application* self);
 
736
void G_MODULE_EXPORT about_cb (GtkWidget* widget, Application* self);
 
737
static void application_about_response_cb (Application* self, gint response_id);
 
738
static void _application_about_response_cb_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self);
 
739
void G_MODULE_EXPORT save_game_as_cb (GtkWidget* widget, Application* self);
 
740
static void application_save_game (Application* self);
 
741
void G_MODULE_EXPORT save_game_cb (GtkWidget* widget, Application* self);
 
742
static void application_add_info_bar_to_dialog (Application* self, GtkDialog* dialog, GtkInfoBar** info_bar, GtkLabel** label);
 
743
static void application_save_file_cb (Application* self);
 
744
static void _application_save_file_cb_gtk_file_chooser_file_activated (GtkFileChooser* _sender, gpointer self);
 
745
static void application_save_cb (Application* self, gint response_id);
 
746
static void _application_save_cb_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self);
 
747
void G_MODULE_EXPORT open_game_cb (GtkWidget* widget, Application* self);
 
748
static void application_open_file_cb (Application* self);
 
749
static void _application_open_file_cb_gtk_file_chooser_file_activated (GtkFileChooser* _sender, gpointer self);
 
750
static void application_open_cb (Application* self, gint response_id);
 
751
static void _application_open_cb_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self);
 
752
PGNGame* pgn_game_new (void);
 
753
PGNGame* pgn_game_construct (GType object_type);
 
754
void pgn_game_set_date (PGNGame* self, const gchar* value);
 
755
void pgn_game_set_time (PGNGame* self, const gchar* value);
 
756
void pgn_game_set_time_control (PGNGame* self, const gchar* value);
 
757
PGN* pgn_new_from_file (GFile* file, GError** error);
 
758
PGN* pgn_construct_from_file (GType object_type, GFile* file, GError** error);
 
759
gpointer pgn_ref (gpointer instance);
 
760
void pgn_unref (gpointer instance);
 
761
GParamSpec* param_spec_pgn (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
762
void value_set_pgn (GValue* value, gpointer v_object);
 
763
void value_take_pgn (GValue* value, gpointer v_object);
 
764
gpointer value_get_pgn (const GValue* value);
 
765
GType pgn_get_type (void) G_GNUC_CONST;
 
766
static void application_finalize (Application* obj);
 
767
gpointer gl_chess_ref (gpointer instance);
 
768
void gl_chess_unref (gpointer instance);
 
769
GParamSpec* param_spec_gl_chess (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
770
void value_set_gl_chess (GValue* value, gpointer v_object);
 
771
void value_take_gl_chess (GValue* value, gpointer v_object);
 
772
gpointer value_get_gl_chess (const GValue* value);
 
773
GType gl_chess_get_type (void) G_GNUC_CONST;
 
774
enum  {
 
775
        GL_CHESS_DUMMY_PROPERTY
 
776
};
 
777
gint gl_chess_main (gchar** args, int args_length1);
 
778
void gl_chess_usage (const gchar* appname, gboolean show_gtk, gboolean show_application);
 
779
GlChess* gl_chess_new (void);
 
780
GlChess* gl_chess_construct (GType object_type);
 
781
static void gl_chess_finalize (GlChess* obj);
 
782
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
 
783
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
 
784
static gint _vala_array_length (gpointer array);
 
785
 
 
786
static const gchar* APPLICATION_authors[1] = {"Robert Ancell <robert.ancell@gmail.com>"};
 
787
static const gchar* APPLICATION_artists[3] = {"John-Paul Gignac (3D Models)", "Max Froumentin (2D Models)", "Hylke Bons <h.bons@student.rug.nl> (icon)"};
 
788
 
 
789
static void _ai_profile_unref0_ (gpointer var) {
 
790
        (var == NULL) ? NULL : (var = (ai_profile_unref (var), NULL));
 
791
}
 
792
 
 
793
 
 
794
static void _g_list_free__ai_profile_unref0_ (GList* self) {
 
795
        g_list_foreach (self, (GFunc) _ai_profile_unref0_, NULL);
 
796
        g_list_free (self);
 
797
}
 
798
 
 
799
 
 
800
static gpointer _g_object_ref0 (gpointer self) {
 
801
        return self ? g_object_ref (self) : NULL;
 
802
}
 
803
 
 
804
 
 
805
static void _application_scene_changed_cb_chess_scene_changed (ChessScene* _sender, gpointer self) {
 
806
        application_scene_changed_cb (self, _sender);
 
807
}
 
808
 
 
809
 
 
810
static void _application_settings_changed_cb_g_settings_changed (GSettings* _sender, const gchar* key, gpointer self) {
 
811
        application_settings_changed_cb (self, _sender, key);
 
812
}
 
813
 
 
814
 
 
815
Application* application_construct (GType object_type) {
 
816
        Application* self = NULL;
 
817
        GSettings* _tmp0_ = NULL;
 
818
        const gchar* _tmp1_ = NULL;
 
819
        gchar* _tmp2_ = NULL;
 
820
        gchar* _tmp3_;
 
821
        GFile* _tmp4_ = NULL;
 
822
        GFile* _tmp5_;
 
823
        GFile* data_dir;
 
824
        gchar* _tmp6_ = NULL;
 
825
        gchar* _tmp7_;
 
826
        History* _tmp8_ = NULL;
 
827
        GtkBuilder* _tmp9_ = NULL;
 
828
        gchar* _tmp10_ = NULL;
 
829
        gchar* _tmp11_;
 
830
        GObject* _tmp12_ = NULL;
 
831
        GtkWindow* _tmp13_;
 
832
        GObject* _tmp14_ = NULL;
 
833
        GtkWidget* _tmp15_;
 
834
        GObject* _tmp16_ = NULL;
 
835
        GtkWidget* _tmp17_;
 
836
        GObject* _tmp18_ = NULL;
 
837
        GtkMenuItem* _tmp19_;
 
838
        GObject* _tmp20_ = NULL;
 
839
        GtkWidget* _tmp21_;
 
840
        GObject* _tmp22_ = NULL;
 
841
        GtkWidget* _tmp23_;
 
842
        GObject* _tmp24_ = NULL;
 
843
        GtkWidget* _tmp25_;
 
844
        GObject* _tmp26_ = NULL;
 
845
        GtkWidget* _tmp27_;
 
846
        GObject* _tmp28_ = NULL;
 
847
        GtkWidget* _tmp29_;
 
848
        GObject* _tmp30_ = NULL;
 
849
        GtkWidget* _tmp31_;
 
850
        GObject* _tmp32_ = NULL;
 
851
        GtkWidget* _tmp33_;
 
852
        GObject* _tmp34_ = NULL;
 
853
        GtkWidget* _tmp35_;
 
854
        GObject* _tmp36_ = NULL;
 
855
        GtkComboBox* _tmp37_;
 
856
        GObject* _tmp38_ = NULL;
 
857
        GtkWidget* _tmp39_;
 
858
        GObject* _tmp40_ = NULL;
 
859
        GtkWidget* _tmp41_;
 
860
        GObject* _tmp42_ = NULL;
 
861
        GObject* _tmp43_ = NULL;
 
862
        GObject* _tmp44_ = NULL;
 
863
        GtkVBox* _tmp45_;
 
864
        GtkVBox* view_box;
 
865
        GObject* _tmp46_ = NULL;
 
866
        GtkContainer* _tmp47_;
 
867
        GtkInfoBar* _tmp48_ = NULL;
 
868
        GtkWidget* _tmp49_ = NULL;
 
869
        GtkContainer* _tmp50_;
 
870
        GtkContainer* content_area;
 
871
        GtkVBox* _tmp51_ = NULL;
 
872
        GtkVBox* vbox;
 
873
        GtkLabel* _tmp52_ = NULL;
 
874
        GtkLabel* _tmp53_ = NULL;
 
875
        ChessScene* _tmp54_ = NULL;
 
876
        GError * _inner_error_ = NULL;
 
877
        self = (Application*) g_type_create_instance (object_type);
 
878
        _tmp0_ = g_settings_new ("org.gnome.glchess.Settings");
 
879
        _g_object_unref0 (self->priv->settings);
 
880
        self->priv->settings = _tmp0_;
 
881
        _tmp1_ = g_get_user_data_dir ();
 
882
        _tmp2_ = g_build_filename (_tmp1_, "glchess", NULL, NULL);
 
883
        _tmp3_ = _tmp2_;
 
884
        _tmp4_ = g_file_new_for_path (_tmp3_);
 
885
        _tmp5_ = _tmp4_;
 
886
        _g_free0 (_tmp3_);
 
887
        data_dir = _tmp5_;
 
888
        _tmp6_ = g_file_get_path (data_dir);
 
889
        _tmp7_ = _tmp6_;
 
890
        g_mkdir_with_parents (_tmp7_, 0755);
 
891
        _g_free0 (_tmp7_);
 
892
        _tmp8_ = history_new (data_dir);
 
893
        _history_unref0 (self->priv->history);
 
894
        self->priv->history = _tmp8_;
 
895
        _tmp9_ = gtk_builder_new ();
 
896
        _g_object_unref0 (self->priv->builder);
 
897
        self->priv->builder = _tmp9_;
 
898
        _tmp10_ = g_build_filename (PKGDATADIR, "glchess.ui", NULL, NULL);
 
899
        _tmp11_ = _tmp10_;
 
900
        gtk_builder_add_from_file (self->priv->builder, _tmp11_, &_inner_error_);
 
901
        _g_free0 (_tmp11_);
 
902
        if (_inner_error_ != NULL) {
 
903
                goto __catch0_g_error;
 
904
        }
 
905
        goto __finally0;
 
906
        __catch0_g_error:
 
907
        {
 
908
                GError * e;
 
909
                e = _inner_error_;
 
910
                _inner_error_ = NULL;
 
911
                g_warning ("glchess.vala:72: Could not load UI: %s", e->message);
 
912
                _g_error_free0 (e);
 
913
        }
 
914
        __finally0:
 
915
        if (_inner_error_ != NULL) {
 
916
                _g_object_unref0 (data_dir);
 
917
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
918
                g_clear_error (&_inner_error_);
 
919
                return NULL;
 
920
        }
 
921
        _tmp12_ = gtk_builder_get_object (self->priv->builder, "glchess_app");
 
922
        _tmp13_ = _g_object_ref0 (GTK_WINDOW (_tmp12_));
 
923
        _g_object_unref0 (self->priv->window);
 
924
        self->priv->window = _tmp13_;
 
925
        _tmp14_ = gtk_builder_get_object (self->priv->builder, "menu_save_item");
 
926
        _tmp15_ = _g_object_ref0 (GTK_WIDGET (_tmp14_));
 
927
        _g_object_unref0 (self->priv->save_menu);
 
928
        self->priv->save_menu = _tmp15_;
 
929
        _tmp16_ = gtk_builder_get_object (self->priv->builder, "menu_save_as_item");
 
930
        _tmp17_ = _g_object_ref0 (GTK_WIDGET (_tmp16_));
 
931
        _g_object_unref0 (self->priv->save_as_menu);
 
932
        self->priv->save_as_menu = _tmp17_;
 
933
        _tmp18_ = gtk_builder_get_object (self->priv->builder, "fullscreen_item");
 
934
        _tmp19_ = _g_object_ref0 (GTK_MENU_ITEM (_tmp18_));
 
935
        _g_object_unref0 (self->priv->fullscreen_menu);
 
936
        self->priv->fullscreen_menu = _tmp19_;
 
937
        _tmp20_ = gtk_builder_get_object (self->priv->builder, "undo_move_item");
 
938
        _tmp21_ = _g_object_ref0 (GTK_WIDGET (_tmp20_));
 
939
        _g_object_unref0 (self->priv->undo_menu);
 
940
        self->priv->undo_menu = _tmp21_;
 
941
        _tmp22_ = gtk_builder_get_object (self->priv->builder, "undo_move_button");
 
942
        _tmp23_ = _g_object_ref0 (GTK_WIDGET (_tmp22_));
 
943
        _g_object_unref0 (self->priv->undo_button);
 
944
        self->priv->undo_button = _tmp23_;
 
945
        _tmp24_ = gtk_builder_get_object (self->priv->builder, "resign_item");
 
946
        _tmp25_ = _g_object_ref0 (GTK_WIDGET (_tmp24_));
 
947
        _g_object_unref0 (self->priv->resign_menu);
 
948
        self->priv->resign_menu = _tmp25_;
 
949
        _tmp26_ = gtk_builder_get_object (self->priv->builder, "resign_button");
 
950
        _tmp27_ = _g_object_ref0 (GTK_WIDGET (_tmp26_));
 
951
        _g_object_unref0 (self->priv->resign_button);
 
952
        self->priv->resign_button = _tmp27_;
 
953
        _tmp28_ = gtk_builder_get_object (self->priv->builder, "first_move_button");
 
954
        _tmp29_ = _g_object_ref0 (GTK_WIDGET (_tmp28_));
 
955
        _g_object_unref0 (self->priv->first_move_button);
 
956
        self->priv->first_move_button = _tmp29_;
 
957
        _tmp30_ = gtk_builder_get_object (self->priv->builder, "prev_move_button");
 
958
        _tmp31_ = _g_object_ref0 (GTK_WIDGET (_tmp30_));
 
959
        _g_object_unref0 (self->priv->prev_move_button);
 
960
        self->priv->prev_move_button = _tmp31_;
 
961
        _tmp32_ = gtk_builder_get_object (self->priv->builder, "next_move_button");
 
962
        _tmp33_ = _g_object_ref0 (GTK_WIDGET (_tmp32_));
 
963
        _g_object_unref0 (self->priv->next_move_button);
 
964
        self->priv->next_move_button = _tmp33_;
 
965
        _tmp34_ = gtk_builder_get_object (self->priv->builder, "last_move_button");
 
966
        _tmp35_ = _g_object_ref0 (GTK_WIDGET (_tmp34_));
 
967
        _g_object_unref0 (self->priv->last_move_button);
 
968
        self->priv->last_move_button = _tmp35_;
 
969
        _tmp36_ = gtk_builder_get_object (self->priv->builder, "history_combo");
 
970
        _tmp37_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp36_));
 
971
        _g_object_unref0 (self->priv->history_combo);
 
972
        self->priv->history_combo = _tmp37_;
 
973
        _tmp38_ = gtk_builder_get_object (self->priv->builder, "white_time_label");
 
974
        _tmp39_ = _g_object_ref0 (GTK_WIDGET (_tmp38_));
 
975
        _g_object_unref0 (self->priv->white_time_label);
 
976
        self->priv->white_time_label = _tmp39_;
 
977
        _tmp40_ = gtk_builder_get_object (self->priv->builder, "black_time_label");
 
978
        _tmp41_ = _g_object_ref0 (GTK_WIDGET (_tmp40_));
 
979
        _g_object_unref0 (self->priv->black_time_label);
 
980
        self->priv->black_time_label = _tmp41_;
 
981
        _tmp42_ = gtk_builder_get_object (self->priv->builder, "toolbar");
 
982
        g_settings_bind (self->priv->settings, "show-toolbar", _tmp42_, "visible", G_SETTINGS_BIND_DEFAULT);
 
983
        _tmp43_ = gtk_builder_get_object (self->priv->builder, "navigation_box");
 
984
        g_settings_bind (self->priv->settings, "show-history", _tmp43_, "visible", G_SETTINGS_BIND_DEFAULT);
 
985
        _tmp44_ = gtk_builder_get_object (self->priv->builder, "view_box");
 
986
        _tmp45_ = _g_object_ref0 (GTK_VBOX (_tmp44_));
 
987
        view_box = _tmp45_;
 
988
        _tmp46_ = gtk_builder_get_object (self->priv->builder, "view_container");
 
989
        _tmp47_ = _g_object_ref0 (GTK_CONTAINER (_tmp46_));
 
990
        _g_object_unref0 (self->priv->view_container);
 
991
        self->priv->view_container = _tmp47_;
 
992
        gtk_builder_connect_signals (self->priv->builder, self);
 
993
        _tmp48_ = (GtkInfoBar*) gtk_info_bar_new ();
 
994
        _g_object_unref0 (self->priv->info_bar);
 
995
        self->priv->info_bar = g_object_ref_sink (_tmp48_);
 
996
        _tmp49_ = gtk_info_bar_get_content_area (self->priv->info_bar);
 
997
        _tmp50_ = _g_object_ref0 (GTK_CONTAINER (_tmp49_));
 
998
        content_area = _tmp50_;
 
999
        gtk_box_pack_start ((GtkBox*) view_box, (GtkWidget*) self->priv->info_bar, FALSE, TRUE, (guint) 0);
 
1000
        _tmp51_ = (GtkVBox*) gtk_vbox_new (FALSE, 6);
 
1001
        vbox = g_object_ref_sink (_tmp51_);
 
1002
        gtk_widget_show ((GtkWidget*) vbox);
 
1003
        gtk_container_add (content_area, (GtkWidget*) vbox);
 
1004
        _tmp52_ = (GtkLabel*) gtk_label_new ("");
 
1005
        _g_object_unref0 (self->priv->info_title_label);
 
1006
        self->priv->info_title_label = g_object_ref_sink (_tmp52_);
 
1007
        gtk_widget_show ((GtkWidget*) self->priv->info_title_label);
 
1008
        gtk_box_pack_start ((GtkBox*) vbox, (GtkWidget*) self->priv->info_title_label, FALSE, TRUE, (guint) 0);
 
1009
        _tmp53_ = (GtkLabel*) gtk_label_new ("");
 
1010
        _g_object_unref0 (self->priv->info_label);
 
1011
        self->priv->info_label = g_object_ref_sink (_tmp53_);
 
1012
        gtk_widget_show ((GtkWidget*) self->priv->info_label);
 
1013
        gtk_box_pack_start ((GtkBox*) vbox, (GtkWidget*) self->priv->info_label, TRUE, TRUE, (guint) 0);
 
1014
        _tmp54_ = chess_scene_new ();
 
1015
        _g_object_unref0 (self->priv->scene);
 
1016
        self->priv->scene = _tmp54_;
 
1017
        g_signal_connect (self->priv->scene, "changed", (GCallback) _application_scene_changed_cb_chess_scene_changed, self);
 
1018
        g_settings_bind (self->priv->settings, "show-move-hints", self->priv->scene, "show-move-hints", G_SETTINGS_BIND_GET);
 
1019
        g_settings_bind (self->priv->settings, "show-numbering", self->priv->scene, "show-numbering", G_SETTINGS_BIND_GET);
 
1020
        g_settings_bind (self->priv->settings, "piece-theme", self->priv->scene, "theme-name", G_SETTINGS_BIND_GET);
 
1021
        g_settings_bind (self->priv->settings, "show-3d-smooth", self->priv->scene, "show-3d-smooth", G_SETTINGS_BIND_GET);
 
1022
        g_settings_bind (self->priv->settings, "move-format", self->priv->scene, "move-format", G_SETTINGS_BIND_GET);
 
1023
        g_settings_bind (self->priv->settings, "board-side", self->priv->scene, "board-side", G_SETTINGS_BIND_GET);
 
1024
        g_signal_connect (self->priv->settings, "changed", (GCallback) _application_settings_changed_cb_g_settings_changed, self);
 
1025
        application_settings_changed_cb (self, self->priv->settings, "show-3d");
 
1026
        _g_object_unref0 (vbox);
 
1027
        _g_object_unref0 (content_area);
 
1028
        _g_object_unref0 (view_box);
 
1029
        _g_object_unref0 (data_dir);
 
1030
        return self;
 
1031
}
 
1032
 
 
1033
 
 
1034
Application* application_new (void) {
 
1035
        return application_construct (TYPE_APPLICATION);
 
1036
}
 
1037
 
 
1038
 
 
1039
void application_quit (Application* self) {
 
1040
        g_return_if_fail (self != NULL);
 
1041
        if (self->priv->save_duration_timeout != 0) {
 
1042
                application_save_duration_cb (self);
 
1043
        }
 
1044
        application_autosave (self);
 
1045
        g_settings_sync ();
 
1046
        gtk_main_quit ();
 
1047
}
 
1048
 
 
1049
 
 
1050
static void application_autosave (Application* self) {
 
1051
        gchar* _tmp5_ = NULL;
 
1052
        gchar* _tmp6_;
 
1053
        GError * _inner_error_ = NULL;
 
1054
        g_return_if_fail (self != NULL);
 
1055
        if (!self->priv->in_history) {
 
1056
                return;
 
1057
        }
 
1058
        if (!self->priv->game_needs_saving) {
 
1059
                if (self->priv->game_file != NULL) {
 
1060
                        history_remove (self->priv->history, self->priv->game_file);
 
1061
                }
 
1062
                return;
 
1063
        }
 
1064
        if (self->priv->game_file != NULL) {
 
1065
                const gchar* _tmp0_ = NULL;
 
1066
                _tmp0_ = pgn_game_get_result (self->priv->pgn_game);
 
1067
                history_update (self->priv->history, self->priv->game_file, "", _tmp0_);
 
1068
        } else {
 
1069
                const gchar* _tmp1_ = NULL;
 
1070
                const gchar* _tmp2_ = NULL;
 
1071
                GFile* _tmp3_ = NULL;
 
1072
                GFile* _tmp4_;
 
1073
                _tmp1_ = pgn_game_get_date (self->priv->pgn_game);
 
1074
                _tmp2_ = pgn_game_get_result (self->priv->pgn_game);
 
1075
                _tmp3_ = history_add (self->priv->history, _tmp1_, _tmp2_, &_inner_error_);
 
1076
                _tmp4_ = _tmp3_;
 
1077
                if (_inner_error_ != NULL) {
 
1078
                        goto __catch1_g_error;
 
1079
                }
 
1080
                _g_object_unref0 (self->priv->game_file);
 
1081
                self->priv->game_file = _tmp4_;
 
1082
        }
 
1083
        _tmp5_ = g_file_get_path (self->priv->game_file);
 
1084
        _tmp6_ = _tmp5_;
 
1085
        g_debug ("glchess.vala:151: Writing current game to %s", _tmp6_);
 
1086
        _g_free0 (_tmp6_);
 
1087
        pgn_game_write (self->priv->pgn_game, self->priv->game_file, &_inner_error_);
 
1088
        if (_inner_error_ != NULL) {
 
1089
                goto __catch1_g_error;
 
1090
        }
 
1091
        goto __finally1;
 
1092
        __catch1_g_error:
 
1093
        {
 
1094
                GError * e;
 
1095
                e = _inner_error_;
 
1096
                _inner_error_ = NULL;
 
1097
                g_warning ("glchess.vala:156: Failed to autosave: %s", e->message);
 
1098
                _g_error_free0 (e);
 
1099
        }
 
1100
        __finally1:
 
1101
        if (_inner_error_ != NULL) {
 
1102
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
1103
                g_clear_error (&_inner_error_);
 
1104
                return;
 
1105
        }
 
1106
}
 
1107
 
 
1108
 
 
1109
static void application_settings_changed_cb (Application* self, GSettings* settings, const gchar* key) {
 
1110
        g_return_if_fail (self != NULL);
 
1111
        g_return_if_fail (settings != NULL);
 
1112
        g_return_if_fail (key != NULL);
 
1113
        if (g_strcmp0 (key, "show-3d") == 0) {
 
1114
                gboolean _tmp0_;
 
1115
                if (self->priv->view != NULL) {
 
1116
                        gtk_container_remove (self->priv->view_container, (GtkWidget*) self->priv->view);
 
1117
                        gtk_widget_destroy ((GtkWidget*) self->priv->view);
 
1118
                }
 
1119
                _tmp0_ = g_settings_get_boolean (settings, "show-3d");
 
1120
                if (_tmp0_) {
 
1121
                        ChessView3D* _tmp1_ = NULL;
 
1122
                        _tmp1_ = chess_view3_d_new ();
 
1123
                        _g_object_unref0 (self->priv->view);
 
1124
                        self->priv->view = (ChessView*) g_object_ref_sink (_tmp1_);
 
1125
                } else {
 
1126
                        ChessView2D* _tmp2_ = NULL;
 
1127
                        _tmp2_ = chess_view2_d_new ();
 
1128
                        _g_object_unref0 (self->priv->view);
 
1129
                        self->priv->view = (ChessView*) g_object_ref_sink (_tmp2_);
 
1130
                }
 
1131
                gtk_widget_set_size_request ((GtkWidget*) self->priv->view, 300, 300);
 
1132
                chess_view_set_scene (self->priv->view, self->priv->scene);
 
1133
                gtk_container_add (self->priv->view_container, (GtkWidget*) self->priv->view);
 
1134
                gtk_widget_show ((GtkWidget*) self->priv->view);
 
1135
        }
 
1136
}
 
1137
 
 
1138
 
 
1139
static gpointer _chess_state_ref0 (gpointer self) {
 
1140
        return self ? chess_state_ref (self) : NULL;
 
1141
}
 
1142
 
 
1143
 
 
1144
static void application_update_history_panel (Application* self) {
 
1145
        gint _tmp0_;
 
1146
        gint move_number;
 
1147
        guint _tmp1_;
 
1148
        gint n_moves;
 
1149
        gboolean _tmp2_ = FALSE;
 
1150
        gboolean _tmp3_ = FALSE;
 
1151
        gint i;
 
1152
        g_return_if_fail (self != NULL);
 
1153
        if (self->priv->game == NULL) {
 
1154
                return;
 
1155
        }
 
1156
        _tmp0_ = chess_scene_get_move_number (self->priv->scene);
 
1157
        move_number = _tmp0_;
 
1158
        _tmp1_ = chess_game_get_n_moves (self->priv->game);
 
1159
        n_moves = (gint) _tmp1_;
 
1160
        if (move_number < 0) {
 
1161
                move_number = move_number + (1 + n_moves);
 
1162
        }
 
1163
        if (n_moves > 0) {
 
1164
                _tmp2_ = move_number != 0;
 
1165
        } else {
 
1166
                _tmp2_ = FALSE;
 
1167
        }
 
1168
        gtk_widget_set_sensitive (self->priv->first_move_button, _tmp2_);
 
1169
        gtk_widget_set_sensitive (self->priv->prev_move_button, move_number > 0);
 
1170
        gtk_widget_set_sensitive (self->priv->next_move_button, move_number < n_moves);
 
1171
        if (n_moves > 0) {
 
1172
                _tmp3_ = move_number != n_moves;
 
1173
        } else {
 
1174
                _tmp3_ = FALSE;
 
1175
        }
 
1176
        gtk_widget_set_sensitive (self->priv->last_move_button, _tmp3_);
 
1177
        i = n_moves;
 
1178
        {
 
1179
                GList* state_collection;
 
1180
                GList* state_it;
 
1181
                state_collection = self->priv->game->move_stack;
 
1182
                for (state_it = state_collection; state_it != NULL; state_it = state_it->next) {
 
1183
                        ChessState* _tmp4_;
 
1184
                        ChessState* state;
 
1185
                        _tmp4_ = _chess_state_ref0 ((ChessState*) state_it->data);
 
1186
                        state = _tmp4_;
 
1187
                        {
 
1188
                                if (state->last_move != NULL) {
 
1189
                                        GtkTreeIter iter = {0};
 
1190
                                        GtkTreeModel* _tmp5_ = NULL;
 
1191
                                        GtkTreeIter _tmp6_ = {0};
 
1192
                                        gboolean _tmp7_;
 
1193
                                        _tmp5_ = gtk_combo_box_get_model (self->priv->history_combo);
 
1194
                                        _tmp7_ = gtk_tree_model_iter_nth_child (_tmp5_, &_tmp6_, NULL, i);
 
1195
                                        iter = _tmp6_;
 
1196
                                        if (_tmp7_) {
 
1197
                                                application_set_move_text (self, &iter, state->last_move);
 
1198
                                        }
 
1199
                                }
 
1200
                                i--;
 
1201
                                _chess_state_unref0 (state);
 
1202
                        }
 
1203
                }
 
1204
        }
 
1205
        gtk_combo_box_set_active (self->priv->history_combo, move_number);
 
1206
}
 
1207
 
 
1208
 
 
1209
static void application_scene_changed_cb (Application* self, ChessScene* scene) {
 
1210
        g_return_if_fail (self != NULL);
 
1211
        g_return_if_fail (scene != NULL);
 
1212
        application_update_history_panel (self);
 
1213
}
 
1214
 
 
1215
 
 
1216
static void _application_game_start_cb_chess_game_started (ChessGame* _sender, gpointer self) {
 
1217
        application_game_start_cb (self, _sender);
 
1218
}
 
1219
 
 
1220
 
 
1221
static void _application_game_turn_cb_chess_game_turn_started (ChessGame* _sender, ChessPlayer* player, gpointer self) {
 
1222
        application_game_turn_cb (self, _sender, player);
 
1223
}
 
1224
 
 
1225
 
 
1226
static void _application_game_move_cb_chess_game_moved (ChessGame* _sender, ChessMove* move, gpointer self) {
 
1227
        application_game_move_cb (self, _sender, move);
 
1228
}
 
1229
 
 
1230
 
 
1231
static void _application_game_undo_cb_chess_game_undo (ChessGame* _sender, gpointer self) {
 
1232
        application_game_undo_cb (self, _sender);
 
1233
}
 
1234
 
 
1235
 
 
1236
static void _application_game_end_cb_chess_game_ended (ChessGame* _sender, gpointer self) {
 
1237
        application_game_end_cb (self, _sender);
 
1238
}
 
1239
 
 
1240
 
 
1241
static void _application_game_clock_tick_cb_chess_clock_tick (ChessClock* _sender, gpointer self) {
 
1242
        application_game_clock_tick_cb (self, _sender);
 
1243
}
 
1244
 
 
1245
 
 
1246
static void _application_engine_ready_cb_chess_engine_ready_changed (ChessEngine* _sender, gpointer self) {
 
1247
        application_engine_ready_cb (self, _sender);
 
1248
}
 
1249
 
 
1250
 
 
1251
static void _application_engine_move_cb_chess_engine_moved (ChessEngine* _sender, const gchar* move, gpointer self) {
 
1252
        application_engine_move_cb (self, _sender, move);
 
1253
}
 
1254
 
 
1255
 
 
1256
static void application_start_game (Application* self) {
 
1257
        GtkTreeModel* _tmp9_ = NULL;
 
1258
        GtkListStore* _tmp10_;
 
1259
        GtkListStore* model;
 
1260
        GtkTreeIter iter = {0};
 
1261
        GtkTreeIter _tmp11_ = {0};
 
1262
        const gchar* _tmp12_ = NULL;
 
1263
        gchar* _tmp13_;
 
1264
        gchar* fen;
 
1265
        guint _tmp14_;
 
1266
        gchar** _tmp15_ = NULL;
 
1267
        gchar** moves;
 
1268
        gint moves_length1;
 
1269
        gint _moves_size_;
 
1270
        gint i;
 
1271
        gboolean _tmp20_;
 
1272
        ChessGame* _tmp24_ = NULL;
 
1273
        const gchar* _tmp25_ = NULL;
 
1274
        ChessClock* _tmp33_ = NULL;
 
1275
        gconstpointer _tmp35_ = NULL;
 
1276
        gchar* _tmp36_;
 
1277
        gchar* white_engine;
 
1278
        gconstpointer _tmp37_ = NULL;
 
1279
        gchar* _tmp38_;
 
1280
        gchar* white_level;
 
1281
        gconstpointer _tmp40_ = NULL;
 
1282
        gchar* _tmp41_;
 
1283
        gchar* black_engine;
 
1284
        gconstpointer _tmp42_ = NULL;
 
1285
        gchar* _tmp43_;
 
1286
        gchar* black_level;
 
1287
        g_return_if_fail (self != NULL);
 
1288
        if (self->priv->in_history) {
 
1289
                const gchar* _tmp0_ = NULL;
 
1290
                _tmp0_ = _ ("Chess");
 
1291
                gtk_window_set_title (self->priv->window, _tmp0_);
 
1292
        } else {
 
1293
                gchar* _tmp1_ = NULL;
 
1294
                gchar* path;
 
1295
                const gchar* _tmp2_ = NULL;
 
1296
                gchar* _tmp3_ = NULL;
 
1297
                gchar* _tmp4_;
 
1298
                gchar* _tmp5_ = NULL;
 
1299
                gchar* _tmp6_;
 
1300
                gchar* _tmp7_ = NULL;
 
1301
                gchar* _tmp8_;
 
1302
                _tmp1_ = g_file_get_path (self->priv->game_file);
 
1303
                path = _tmp1_;
 
1304
                _tmp2_ = _ ("%1$s (%2$s) - Chess");
 
1305
                _tmp3_ = g_path_get_basename (path);
 
1306
                _tmp4_ = _tmp3_;
 
1307
                _tmp5_ = g_path_get_dirname (path);
 
1308
                _tmp6_ = _tmp5_;
 
1309
                _tmp7_ = g_strdup_printf (_tmp2_, _tmp4_, _tmp6_);
 
1310
                _tmp8_ = _tmp7_;
 
1311
                gtk_window_set_title (self->priv->window, _tmp8_);
 
1312
                _g_free0 (_tmp8_);
 
1313
                _g_free0 (_tmp6_);
 
1314
                _g_free0 (_tmp4_);
 
1315
                _g_free0 (path);
 
1316
        }
 
1317
        _tmp9_ = gtk_combo_box_get_model (self->priv->history_combo);
 
1318
        _tmp10_ = _g_object_ref0 (GTK_LIST_STORE (_tmp9_));
 
1319
        model = _tmp10_;
 
1320
        gtk_list_store_clear (model);
 
1321
        gtk_list_store_append (model, &_tmp11_);
 
1322
        iter = _tmp11_;
 
1323
        _tmp12_ = _ ("Game Start");
 
1324
        gtk_list_store_set (model, &iter, 0, _tmp12_, 1, 0, -1, -1);
 
1325
        gtk_combo_box_set_active_iter (self->priv->history_combo, &iter);
 
1326
        _tmp13_ = g_strdup (CHESS_GAME_STANDARD_SETUP);
 
1327
        fen = _tmp13_;
 
1328
        _tmp14_ = g_list_length (self->priv->pgn_game->moves);
 
1329
        _tmp15_ = g_new0 (gchar*, _tmp14_ + 1);
 
1330
        moves = _tmp15_;
 
1331
        moves_length1 = _tmp14_;
 
1332
        _moves_size_ = _tmp14_;
 
1333
        i = 0;
 
1334
        {
 
1335
                GList* move_collection;
 
1336
                GList* move_it;
 
1337
                move_collection = self->priv->pgn_game->moves;
 
1338
                for (move_it = move_collection; move_it != NULL; move_it = move_it->next) {
 
1339
                        gchar* _tmp16_;
 
1340
                        gchar* move;
 
1341
                        _tmp16_ = g_strdup ((const gchar*) move_it->data);
 
1342
                        move = _tmp16_;
 
1343
                        {
 
1344
                                gint _tmp17_;
 
1345
                                gchar* _tmp18_;
 
1346
                                gchar* _tmp19_;
 
1347
                                _tmp17_ = i;
 
1348
                                i = _tmp17_ + 1;
 
1349
                                _tmp18_ = g_strdup (move);
 
1350
                                _tmp19_ = _tmp18_;
 
1351
                                _g_free0 (moves[_tmp17_]);
 
1352
                                moves[_tmp17_] = _tmp19_;
 
1353
                                _g_free0 (move);
 
1354
                        }
 
1355
                }
 
1356
        }
 
1357
        _tmp20_ = pgn_game_get_set_up (self->priv->pgn_game);
 
1358
        if (_tmp20_) {
 
1359
                const gchar* _tmp21_ = NULL;
 
1360
                _tmp21_ = pgn_game_get_fen (self->priv->pgn_game);
 
1361
                if (_tmp21_ != NULL) {
 
1362
                        const gchar* _tmp22_ = NULL;
 
1363
                        gchar* _tmp23_;
 
1364
                        _tmp22_ = pgn_game_get_fen (self->priv->pgn_game);
 
1365
                        _tmp23_ = g_strdup (_tmp22_);
 
1366
                        _g_free0 (fen);
 
1367
                        fen = _tmp23_;
 
1368
                } else {
 
1369
                        g_warning ("glchess.vala:252: Chess game has SetUp tag but no FEN tag");
 
1370
                }
 
1371
        }
 
1372
        _tmp24_ = chess_game_new (fen, moves, moves_length1);
 
1373
        _chess_game_unref0 (self->priv->game);
 
1374
        self->priv->game = _tmp24_;
 
1375
        _tmp25_ = pgn_game_get_time_control (self->priv->pgn_game);
 
1376
        if (_tmp25_ != NULL) {
 
1377
                const gchar* _tmp26_ = NULL;
 
1378
                gchar** _tmp27_;
 
1379
                gchar** _tmp28_ = NULL;
 
1380
                gchar** controls;
 
1381
                gint controls_length1;
 
1382
                gint _controls_size_;
 
1383
                _tmp26_ = pgn_game_get_time_control (self->priv->pgn_game);
 
1384
                _tmp28_ = _tmp27_ = g_strsplit (_tmp26_, ":", 0);
 
1385
                controls = _tmp28_;
 
1386
                controls_length1 = _vala_array_length (_tmp27_);
 
1387
                _controls_size_ = _vala_array_length (_tmp27_);
 
1388
                {
 
1389
                        gchar** control_collection;
 
1390
                        int control_collection_length1;
 
1391
                        int control_it;
 
1392
                        control_collection = controls;
 
1393
                        control_collection_length1 = controls_length1;
 
1394
                        for (control_it = 0; control_it < controls_length1; control_it = control_it + 1) {
 
1395
                                gchar* _tmp29_;
 
1396
                                gchar* control;
 
1397
                                _tmp29_ = g_strdup (control_collection[control_it]);
 
1398
                                control = _tmp29_;
 
1399
                                {
 
1400
                                        gint _tmp30_;
 
1401
                                        gint duration;
 
1402
                                        _tmp30_ = atoi (control);
 
1403
                                        duration = _tmp30_;
 
1404
                                        if (duration > 0) {
 
1405
                                                ChessClock* _tmp31_ = NULL;
 
1406
                                                ChessClock* _tmp32_;
 
1407
                                                _tmp31_ = chess_clock_new ((guint) duration, (guint) duration, (guint) 0, (guint) 0);
 
1408
                                                _tmp32_ = _tmp31_;
 
1409
                                                chess_game_set_clock (self->priv->game, _tmp32_);
 
1410
                                                _g_object_unref0 (_tmp32_);
 
1411
                                        }
 
1412
                                        _g_free0 (control);
 
1413
                                }
 
1414
                        }
 
1415
                }
 
1416
                controls = (_vala_array_free (controls, controls_length1, (GDestroyNotify) g_free), NULL);
 
1417
        }
 
1418
        g_signal_connect (self->priv->game, "started", (GCallback) _application_game_start_cb_chess_game_started, self);
 
1419
        g_signal_connect (self->priv->game, "turn-started", (GCallback) _application_game_turn_cb_chess_game_turn_started, self);
 
1420
        g_signal_connect (self->priv->game, "moved", (GCallback) _application_game_move_cb_chess_game_moved, self);
 
1421
        g_signal_connect (self->priv->game, "undo", (GCallback) _application_game_undo_cb_chess_game_undo, self);
 
1422
        g_signal_connect (self->priv->game, "ended", (GCallback) _application_game_end_cb_chess_game_ended, self);
 
1423
        _tmp33_ = chess_game_get_clock (self->priv->game);
 
1424
        if (_tmp33_ != NULL) {
 
1425
                ChessClock* _tmp34_ = NULL;
 
1426
                _tmp34_ = chess_game_get_clock (self->priv->game);
 
1427
                g_signal_connect (_tmp34_, "tick", (GCallback) _application_game_clock_tick_cb_chess_clock_tick, self);
 
1428
        }
 
1429
        chess_scene_set_game (self->priv->scene, self->priv->game);
 
1430
        gtk_widget_hide ((GtkWidget*) self->priv->info_bar);
 
1431
        gtk_widget_set_sensitive (self->priv->save_menu, FALSE);
 
1432
        gtk_widget_set_sensitive (self->priv->save_as_menu, FALSE);
 
1433
        application_update_history_panel (self);
 
1434
        application_update_control_buttons (self);
 
1435
        _tmp35_ = g_hash_table_lookup (self->priv->pgn_game->tags, "WhiteAI");
 
1436
        _tmp36_ = g_strdup ((const gchar*) _tmp35_);
 
1437
        white_engine = _tmp36_;
 
1438
        _tmp37_ = g_hash_table_lookup (self->priv->pgn_game->tags, "WhiteLevel");
 
1439
        _tmp38_ = g_strdup ((const gchar*) _tmp37_);
 
1440
        white_level = _tmp38_;
 
1441
        if (white_level == NULL) {
 
1442
                gchar* _tmp39_;
 
1443
                _tmp39_ = g_strdup ("normal");
 
1444
                _g_free0 (white_level);
 
1445
                white_level = _tmp39_;
 
1446
        }
 
1447
        _tmp40_ = g_hash_table_lookup (self->priv->pgn_game->tags, "BlackAI");
 
1448
        _tmp41_ = g_strdup ((const gchar*) _tmp40_);
 
1449
        black_engine = _tmp41_;
 
1450
        _tmp42_ = g_hash_table_lookup (self->priv->pgn_game->tags, "BlackLevel");
 
1451
        _tmp43_ = g_strdup ((const gchar*) _tmp42_);
 
1452
        black_level = _tmp43_;
 
1453
        if (black_level == NULL) {
 
1454
                gchar* _tmp44_;
 
1455
                _tmp44_ = g_strdup ("normal");
 
1456
                _g_free0 (black_level);
 
1457
                black_level = _tmp44_;
 
1458
        }
 
1459
        _g_object_unref0 (self->priv->opponent);
 
1460
        self->priv->opponent = NULL;
 
1461
        _g_object_unref0 (self->priv->opponent_engine);
 
1462
        self->priv->opponent_engine = NULL;
 
1463
        if (white_engine != NULL) {
 
1464
                ChessPlayer* _tmp45_ = NULL;
 
1465
                ChessPlayer* _tmp46_;
 
1466
                ChessPlayer* _tmp47_ = NULL;
 
1467
                ChessPlayer* _tmp48_;
 
1468
                ChessEngine* _tmp49_ = NULL;
 
1469
                _tmp45_ = chess_game_get_white (self->priv->game);
 
1470
                _tmp46_ = _g_object_ref0 (_tmp45_);
 
1471
                _g_object_unref0 (self->priv->opponent);
 
1472
                self->priv->opponent = _tmp46_;
 
1473
                _tmp47_ = chess_game_get_black (self->priv->game);
 
1474
                _tmp48_ = _g_object_ref0 (_tmp47_);
 
1475
                _g_object_unref0 (self->priv->human_player);
 
1476
                self->priv->human_player = _tmp48_;
 
1477
                _tmp49_ = application_get_engine (self, white_engine, white_level);
 
1478
                _g_object_unref0 (self->priv->opponent_engine);
 
1479
                self->priv->opponent_engine = _tmp49_;
 
1480
        } else {
 
1481
                if (black_engine != NULL) {
 
1482
                        ChessPlayer* _tmp50_ = NULL;
 
1483
                        ChessPlayer* _tmp51_;
 
1484
                        ChessPlayer* _tmp52_ = NULL;
 
1485
                        ChessPlayer* _tmp53_;
 
1486
                        ChessEngine* _tmp54_ = NULL;
 
1487
                        _tmp50_ = chess_game_get_black (self->priv->game);
 
1488
                        _tmp51_ = _g_object_ref0 (_tmp50_);
 
1489
                        _g_object_unref0 (self->priv->opponent);
 
1490
                        self->priv->opponent = _tmp51_;
 
1491
                        _tmp52_ = chess_game_get_white (self->priv->game);
 
1492
                        _tmp53_ = _g_object_ref0 (_tmp52_);
 
1493
                        _g_object_unref0 (self->priv->human_player);
 
1494
                        self->priv->human_player = _tmp53_;
 
1495
                        _tmp54_ = application_get_engine (self, black_engine, black_level);
 
1496
                        _g_object_unref0 (self->priv->opponent_engine);
 
1497
                        self->priv->opponent_engine = _tmp54_;
 
1498
                }
 
1499
        }
 
1500
        if (self->priv->opponent_engine != NULL) {
 
1501
                g_signal_connect (self->priv->opponent_engine, "ready-changed", (GCallback) _application_engine_ready_cb_chess_engine_ready_changed, self);
 
1502
                g_signal_connect (self->priv->opponent_engine, "moved", (GCallback) _application_engine_move_cb_chess_engine_moved, self);
 
1503
                chess_engine_start (self->priv->opponent_engine);
 
1504
        }
 
1505
        {
 
1506
                guint _tmp55_;
 
1507
                gint j;
 
1508
                _tmp55_ = g_list_length (self->priv->game->move_stack);
 
1509
                j = ((gint) _tmp55_) - 2;
 
1510
                {
 
1511
                        gboolean _tmp56_;
 
1512
                        _tmp56_ = TRUE;
 
1513
                        while (TRUE) {
 
1514
                                gconstpointer _tmp57_ = NULL;
 
1515
                                ChessState* _tmp58_;
 
1516
                                ChessState* state;
 
1517
                                if (!_tmp56_) {
 
1518
                                        j--;
 
1519
                                }
 
1520
                                _tmp56_ = FALSE;
 
1521
                                if (!(j >= 0)) {
 
1522
                                        break;
 
1523
                                }
 
1524
                                _tmp57_ = g_list_nth_data (self->priv->game->move_stack, (guint) j);
 
1525
                                _tmp58_ = _chess_state_ref0 ((ChessState*) _tmp57_);
 
1526
                                state = _tmp58_;
 
1527
                                application_game_move_cb (self, self->priv->game, state->last_move);
 
1528
                                _chess_state_unref0 (state);
 
1529
                        }
 
1530
                }
 
1531
        }
 
1532
        self->priv->game_needs_saving = FALSE;
 
1533
        chess_game_start (self->priv->game);
 
1534
        if (self->priv->game->result != CHESS_RESULT_IN_PROGRESS) {
 
1535
                application_game_end_cb (self, self->priv->game);
 
1536
        }
 
1537
        gtk_widget_queue_draw (self->priv->white_time_label);
 
1538
        gtk_widget_queue_draw (self->priv->black_time_label);
 
1539
        _g_free0 (black_level);
 
1540
        _g_free0 (black_engine);
 
1541
        _g_free0 (white_level);
 
1542
        _g_free0 (white_engine);
 
1543
        moves = (_vala_array_free (moves, moves_length1, (GDestroyNotify) g_free), NULL);
 
1544
        _g_free0 (fen);
 
1545
        _g_object_unref0 (model);
 
1546
}
 
1547
 
 
1548
 
 
1549
static gpointer _ai_profile_ref0 (gpointer self) {
 
1550
        return self ? ai_profile_ref (self) : NULL;
 
1551
}
 
1552
 
 
1553
 
 
1554
static gchar** _vala_array_dup2 (gchar** self, int length) {
 
1555
        gchar** result;
 
1556
        int i;
 
1557
        result = g_new0 (gchar*, length + 1);
 
1558
        for (i = 0; i < length; i++) {
 
1559
                result[i] = g_strdup (self[i]);
 
1560
        }
 
1561
        return result;
 
1562
}
 
1563
 
 
1564
 
 
1565
static gchar** _vala_array_dup3 (gchar** self, int length) {
 
1566
        gchar** result;
 
1567
        int i;
 
1568
        result = g_new0 (gchar*, length + 1);
 
1569
        for (i = 0; i < length; i++) {
 
1570
                result[i] = g_strdup (self[i]);
 
1571
        }
 
1572
        return result;
 
1573
}
 
1574
 
 
1575
 
 
1576
static gchar** _vala_array_dup4 (gchar** self, int length) {
 
1577
        gchar** result;
 
1578
        int i;
 
1579
        result = g_new0 (gchar*, length + 1);
 
1580
        for (i = 0; i < length; i++) {
 
1581
                result[i] = g_strdup (self[i]);
 
1582
        }
 
1583
        return result;
 
1584
}
 
1585
 
 
1586
 
 
1587
static ChessEngine* application_get_engine (Application* self, const gchar* name, const gchar* difficulty) {
 
1588
        ChessEngine* result = NULL;
 
1589
        ChessEngine* engine = NULL;
 
1590
        AIProfile* profile;
 
1591
        gchar** options = NULL;
 
1592
        gint options_length1 = 0;
 
1593
        gint _options_size_ = 0;
 
1594
        const gchar* _tmp4_;
 
1595
        GQuark _tmp5_;
 
1596
        static GQuark _tmp5__label0 = 0;
 
1597
        static GQuark _tmp5__label1 = 0;
 
1598
        gchar* _tmp14_;
 
1599
        g_return_val_if_fail (self != NULL, NULL);
 
1600
        g_return_val_if_fail (name != NULL, NULL);
 
1601
        g_return_val_if_fail (difficulty != NULL, NULL);
 
1602
        profile = NULL;
 
1603
        if (g_strcmp0 (name, "human") == 0) {
 
1604
                result = NULL;
 
1605
                _ai_profile_unref0 (profile);
 
1606
                _g_object_unref0 (engine);
 
1607
                return result;
 
1608
        }
 
1609
        {
 
1610
                GList* p_collection;
 
1611
                GList* p_it;
 
1612
                p_collection = self->priv->ai_profiles;
 
1613
                for (p_it = p_collection; p_it != NULL; p_it = p_it->next) {
 
1614
                        AIProfile* _tmp0_;
 
1615
                        AIProfile* p;
 
1616
                        _tmp0_ = _ai_profile_ref0 ((AIProfile*) p_it->data);
 
1617
                        p = _tmp0_;
 
1618
                        {
 
1619
                                gboolean _tmp1_ = FALSE;
 
1620
                                if (g_strcmp0 (name, "") == 0) {
 
1621
                                        _tmp1_ = TRUE;
 
1622
                                } else {
 
1623
                                        _tmp1_ = g_strcmp0 (p->name, name) == 0;
 
1624
                                }
 
1625
                                if (_tmp1_) {
 
1626
                                        AIProfile* _tmp2_;
 
1627
                                        _tmp2_ = _ai_profile_ref0 (p);
 
1628
                                        _ai_profile_unref0 (profile);
 
1629
                                        profile = _tmp2_;
 
1630
                                        _ai_profile_unref0 (p);
 
1631
                                        break;
 
1632
                                }
 
1633
                                _ai_profile_unref0 (p);
 
1634
                        }
 
1635
                }
 
1636
        }
 
1637
        if (profile == NULL) {
 
1638
                AIProfile* _tmp3_;
 
1639
                g_warning ("glchess.vala:351: Unknown AI profile %s", name);
 
1640
                if (self->priv->ai_profiles == NULL) {
 
1641
                        result = NULL;
 
1642
                        _ai_profile_unref0 (profile);
 
1643
                        _g_object_unref0 (engine);
 
1644
                        return result;
 
1645
                }
 
1646
                _tmp3_ = _ai_profile_ref0 ((AIProfile*) self->priv->ai_profiles->data);
 
1647
                _ai_profile_unref0 (profile);
 
1648
                profile = _tmp3_;
 
1649
        }
 
1650
        _tmp4_ = difficulty;
 
1651
        _tmp5_ = (NULL == _tmp4_) ? 0 : g_quark_from_string (_tmp4_);
 
1652
        if (_tmp5_ == ((0 != _tmp5__label0) ? _tmp5__label0 : (_tmp5__label0 = g_quark_from_static_string ("easy")))) {
 
1653
                switch (0) {
 
1654
                        default:
 
1655
                        {
 
1656
                                gchar** _tmp6_;
 
1657
                                gchar** _tmp7_;
 
1658
                                _tmp6_ = (_tmp7_ = profile->easy_options, (_tmp7_ == NULL) ? ((gpointer) _tmp7_) : _vala_array_dup2 (_tmp7_, profile->easy_options_length1));
 
1659
                                options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
 
1660
                                options = _tmp6_;
 
1661
                                options_length1 = profile->easy_options_length1;
 
1662
                                _options_size_ = profile->easy_options_length1;
 
1663
                                break;
 
1664
                        }
 
1665
                }
 
1666
        } else if (_tmp5_ == ((0 != _tmp5__label1) ? _tmp5__label1 : (_tmp5__label1 = g_quark_from_static_string ("hard")))) {
 
1667
                switch (0) {
 
1668
                        default:
 
1669
                        {
 
1670
                                gchar** _tmp8_;
 
1671
                                gchar** _tmp9_;
 
1672
                                _tmp8_ = (_tmp9_ = profile->hard_options, (_tmp9_ == NULL) ? ((gpointer) _tmp9_) : _vala_array_dup3 (_tmp9_, profile->hard_options_length1));
 
1673
                                options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
 
1674
                                options = _tmp8_;
 
1675
                                options_length1 = profile->hard_options_length1;
 
1676
                                _options_size_ = profile->hard_options_length1;
 
1677
                                break;
 
1678
                        }
 
1679
                }
 
1680
        } else {
 
1681
                switch (0) {
 
1682
                        default:
 
1683
                        {
 
1684
                                gchar** _tmp10_;
 
1685
                                gchar** _tmp11_;
 
1686
                                _tmp10_ = (_tmp11_ = profile->normal_options, (_tmp11_ == NULL) ? ((gpointer) _tmp11_) : _vala_array_dup4 (_tmp11_, profile->normal_options_length1));
 
1687
                                options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
 
1688
                                options = _tmp10_;
 
1689
                                options_length1 = profile->normal_options_length1;
 
1690
                                _options_size_ = profile->normal_options_length1;
 
1691
                                break;
 
1692
                        }
 
1693
                }
 
1694
        }
 
1695
        if (g_strcmp0 (profile->protocol, "cecp") == 0) {
 
1696
                ChessEngineCECP* _tmp12_ = NULL;
 
1697
                _tmp12_ = chess_engine_cecp_new (options, options_length1);
 
1698
                _g_object_unref0 (engine);
 
1699
                engine = (ChessEngine*) _tmp12_;
 
1700
        } else {
 
1701
                if (g_strcmp0 (profile->protocol, "uci") == 0) {
 
1702
                        ChessEngineUCI* _tmp13_ = NULL;
 
1703
                        _tmp13_ = chess_engine_uci_new (options, options_length1);
 
1704
                        _g_object_unref0 (engine);
 
1705
                        engine = (ChessEngine*) _tmp13_;
 
1706
                } else {
 
1707
                        g_warning ("glchess.vala:378: Unknown AI protocol %s", profile->protocol);
 
1708
                        result = NULL;
 
1709
                        options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
 
1710
                        _ai_profile_unref0 (profile);
 
1711
                        _g_object_unref0 (engine);
 
1712
                        return result;
 
1713
                }
 
1714
        }
 
1715
        _tmp14_ = g_strdup (profile->binary);
 
1716
        _g_free0 (engine->binary);
 
1717
        engine->binary = _tmp14_;
 
1718
        result = engine;
 
1719
        options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
 
1720
        _ai_profile_unref0 (profile);
 
1721
        return result;
 
1722
}
 
1723
 
 
1724
 
 
1725
static void _g_object_unref0_ (gpointer var) {
 
1726
        (var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
 
1727
}
 
1728
 
 
1729
 
 
1730
static void _g_list_free__g_object_unref0_ (GList* self) {
 
1731
        g_list_foreach (self, (GFunc) _g_object_unref0_, NULL);
 
1732
        g_list_free (self);
 
1733
}
 
1734
 
 
1735
 
 
1736
void application_start (Application* self, GFile* game, GError** error) {
 
1737
        gchar* _tmp0_ = NULL;
 
1738
        gchar* _tmp1_;
 
1739
        GList* _tmp2_ = NULL;
 
1740
        gint _tmp6_;
 
1741
        gint _tmp7_;
 
1742
        gboolean _tmp8_;
 
1743
        GError * _inner_error_ = NULL;
 
1744
        g_return_if_fail (self != NULL);
 
1745
        _tmp0_ = g_build_filename (PKGDATADIR, "engines.conf", NULL, NULL);
 
1746
        _tmp1_ = _tmp0_;
 
1747
        _tmp2_ = load_ai_profiles (_tmp1_);
 
1748
        __g_list_free__ai_profile_unref0_0 (self->priv->ai_profiles);
 
1749
        self->priv->ai_profiles = _tmp2_;
 
1750
        _g_free0 (_tmp1_);
 
1751
        {
 
1752
                GList* profile_collection;
 
1753
                GList* profile_it;
 
1754
                profile_collection = self->priv->ai_profiles;
 
1755
                for (profile_it = profile_collection; profile_it != NULL; profile_it = profile_it->next) {
 
1756
                        AIProfile* _tmp3_;
 
1757
                        AIProfile* profile;
 
1758
                        _tmp3_ = _ai_profile_ref0 ((AIProfile*) profile_it->data);
 
1759
                        profile = _tmp3_;
 
1760
                        {
 
1761
                                g_message ("glchess.vala:390: Detected AI profile %s in %s", profile->name, profile->path);
 
1762
                                _ai_profile_unref0 (profile);
 
1763
                        }
 
1764
                }
 
1765
        }
 
1766
        if (game == NULL) {
 
1767
                GList* _tmp4_ = NULL;
 
1768
                GList* unfinished;
 
1769
                _tmp4_ = history_get_unfinished (self->priv->history);
 
1770
                unfinished = _tmp4_;
 
1771
                if (unfinished != NULL) {
 
1772
                        GFile* _tmp5_;
 
1773
                        GFile* file;
 
1774
                        _tmp5_ = _g_object_ref0 ((GFile*) unfinished->data);
 
1775
                        file = _tmp5_;
 
1776
                        application_load_game (self, file, TRUE, &_inner_error_);
 
1777
                        if (_inner_error_ != NULL) {
 
1778
                                g_propagate_error (error, _inner_error_);
 
1779
                                _g_object_unref0 (file);
 
1780
                                __g_list_free__g_object_unref0_0 (unfinished);
 
1781
                                return;
 
1782
                        }
 
1783
                        _g_object_unref0 (file);
 
1784
                } else {
 
1785
                        application_start_new_game (self);
 
1786
                }
 
1787
                __g_list_free__g_object_unref0_0 (unfinished);
 
1788
        } else {
 
1789
                application_load_game (self, game, FALSE, &_inner_error_);
 
1790
                if (_inner_error_ != NULL) {
 
1791
                        g_propagate_error (error, _inner_error_);
 
1792
                        return;
 
1793
                }
 
1794
        }
 
1795
        _tmp6_ = g_settings_get_int (self->priv->settings, "width");
 
1796
        _tmp7_ = g_settings_get_int (self->priv->settings, "height");
 
1797
        gtk_window_set_default_size (self->priv->window, _tmp6_, _tmp7_);
 
1798
        _tmp8_ = g_settings_get_boolean (self->priv->settings, "fullscreen");
 
1799
        if (_tmp8_) {
 
1800
                gtk_window_fullscreen (self->priv->window);
 
1801
        } else {
 
1802
                gboolean _tmp9_;
 
1803
                _tmp9_ = g_settings_get_boolean (self->priv->settings, "maximized");
 
1804
                if (_tmp9_) {
 
1805
                        gtk_window_maximize (self->priv->window);
 
1806
                }
 
1807
        }
 
1808
        application_show (self);
 
1809
}
 
1810
 
 
1811
 
 
1812
static void application_engine_ready_cb (Application* self, ChessEngine* engine) {
 
1813
        gboolean _tmp0_;
 
1814
        g_return_if_fail (self != NULL);
 
1815
        g_return_if_fail (engine != NULL);
 
1816
        _tmp0_ = chess_engine_get_ready (self->priv->opponent_engine);
 
1817
        if (_tmp0_) {
 
1818
                chess_game_start (self->priv->game);
 
1819
                gtk_widget_queue_draw ((GtkWidget*) self->priv->view);
 
1820
        }
 
1821
}
 
1822
 
 
1823
 
 
1824
static void application_engine_move_cb (Application* self, ChessEngine* engine, const gchar* move) {
 
1825
        g_return_if_fail (self != NULL);
 
1826
        g_return_if_fail (engine != NULL);
 
1827
        g_return_if_fail (move != NULL);
 
1828
        chess_player_move (self->priv->opponent, move, TRUE);
 
1829
}
 
1830
 
 
1831
 
 
1832
static void application_game_start_cb (Application* self, ChessGame* game) {
 
1833
        g_return_if_fail (self != NULL);
 
1834
        g_return_if_fail (game != NULL);
 
1835
        if (self->priv->opponent_engine != NULL) {
 
1836
                chess_engine_start_game (self->priv->opponent_engine);
 
1837
        }
 
1838
}
 
1839
 
 
1840
 
 
1841
static void application_game_clock_tick_cb (Application* self, ChessClock* clock) {
 
1842
        g_return_if_fail (self != NULL);
 
1843
        g_return_if_fail (clock != NULL);
 
1844
        gtk_widget_queue_draw (self->priv->white_time_label);
 
1845
        gtk_widget_queue_draw (self->priv->black_time_label);
 
1846
}
 
1847
 
 
1848
 
 
1849
static void application_game_turn_cb (Application* self, ChessGame* game, ChessPlayer* player) {
 
1850
        gboolean _tmp0_ = FALSE;
 
1851
        g_return_if_fail (self != NULL);
 
1852
        g_return_if_fail (game != NULL);
 
1853
        g_return_if_fail (player != NULL);
 
1854
        if (self->priv->opponent_engine != NULL) {
 
1855
                _tmp0_ = player == self->priv->opponent;
 
1856
        } else {
 
1857
                _tmp0_ = FALSE;
 
1858
        }
 
1859
        if (_tmp0_) {
 
1860
                chess_engine_request_move (self->priv->opponent_engine);
 
1861
        }
 
1862
}
 
1863
 
 
1864
 
 
1865
static void application_set_move_text (Application* self, GtkTreeIter* iter, ChessMove* move) {
 
1866
        static const gchar* human_descriptions[] = {"White pawn moves from %1$s to %2$s", "White pawn at %1$s takes the black pawn at %2$s", "White pawn at %1$s takes the black rook at %2$s", "White pawn at %1$s takes the black knight at %2$s", "White pawn at %1$s takes the black bishop at %2$s", "White pawn at %1$s takes the black queen at %2$s", "White rook moves from %1$s to %2$s", "White rook at %1$s takes the black pawn at %2$s", "White rook at %1$s takes the black rook at %2$s", "White rook at %1$s takes the black knight at %2$s", "White rook at %1$s takes the black bishop at %2$s", "White rook at %1$s takes the black queen at %2$s", "White knight moves from %1$s to %2$s", "White knight at %1$s takes the black pawn at %2$s", "White knight at %1$s takes the black rook at %2$s", "White knight at %1$s takes the black knight at %2$s", "White knight at %1$s takes the black bishop at %2$s", "White knight at %1$s takes the black queen at %2$s", "White bishop moves from %1$s to %2$s", "White bishop at %1$s takes the black pawn at %2$s", "White bishop at %1$s takes the black rook at %2$s", "White bishop at %1$s takes the black knight at %2$s", "White bishop at %1$s takes the black bishop at %2$s", "White bishop at %1$s takes the black queen at %2$s", "White queen moves from %1$s to %2$s", "White queen at %1$s takes the black pawn at %2$s", "White queen at %1$s takes the black rook at %2$s", "White queen at %1$s takes the black knight at %2$s", "White queen at %1$s takes the black bishop at %2$s", "White queen at %1$s takes the black queen at %2$s", "White king moves from %1$s to %2$s", "White king at %1$s takes the black pawn at %2$s", "White king at %1$s takes the black rook at %2$s", "White king at %1$s takes the black knight at %2$s", "White king at %1$s takes the black bishop at %2$s", "White king at %1$s takes the black queen at %2$s", "Black pawn moves from %1$s to %2$s", "Black pawn at %1$s takes the white pawn at %2$s", "Black pawn at %1$s takes the white rook at %2$s", "Black pawn at %1$s takes the white knight at %2$s", "Black pawn at %1$s takes the white bishop at %2$s", "Black pawn at %1$s takes the white queen at %2$s", "Black rook moves from %1$s to %2$s", "Black rook at %1$s takes the white pawn at %2$s", "Black rook at %1$s takes the white rook at %2$s", "Black rook at %1$s takes the white knight at %2$s", "Black rook at %1$s takes the white bishop at %2$s", "Black rook at %1$s takes the white queen at %2$s", "Black knight moves from %1$s to %2$s", "Black knight at %1$s takes the white pawn at %2$s", "Black knight at %1$s takes the white rook at %2$s", "Black knight at %1$s takes the white knight at %2$s", "Black knight at %1$s takes the white bishop at %2$s", "Black knight at %1$s takes the white queen at %2$s", "Black bishop moves from %1$s to %2$s", "Black bishop at %1$s takes the white pawn at %2$s", "Black bishop at %1$s takes the white rook at %2$s", "Black bishop at %1$s takes the white knight at %2$s", "Black bishop at %1$s takes the white bishop at %2$s", "Black bishop at %1$s takes the white queen at %2$s", "Black queen moves from %1$s to %2$s", "Black queen at %1$s takes the white pawn at %2$s", "Black queen at %1$s takes the white rook at %2$s", "Black queen at %1$s takes the white knight at %2$s", "Black queen at %1$s takes the white bishop at %2$s", "Black queen at %1$s takes the white queen at %2$s", "Black king moves from %1$s to %2$s", "Black king at %1$s takes the white pawn at %2$s", "Black king at %1$s takes the white rook at %2$s", "Black king at %1$s takes the white knight at %2$s", "Black king at %1$s takes the white bishop at %2$s", "Black king at %1$s takes the white queen at %2$s"};
 
1867
        gchar* _tmp0_;
 
1868
        gchar* move_text;
 
1869
        const gchar* _tmp1_ = NULL;
 
1870
        const gchar* _tmp2_;
 
1871
        GQuark _tmp3_;
 
1872
        static GQuark _tmp3__label0 = 0;
 
1873
        static GQuark _tmp3__label1 = 0;
 
1874
        static GQuark _tmp3__label2 = 0;
 
1875
        GtkTreeModel* _tmp11_ = NULL;
 
1876
        GtkListStore* _tmp12_;
 
1877
        GtkListStore* model;
 
1878
        gchar _tmp13_ = '\0';
 
1879
        gchar* _tmp14_ = NULL;
 
1880
        gchar* label;
 
1881
        g_return_if_fail (self != NULL);
 
1882
        g_return_if_fail (move != NULL);
 
1883
        _tmp0_ = g_strdup ("");
 
1884
        move_text = _tmp0_;
 
1885
        _tmp1_ = chess_scene_get_move_format (self->priv->scene);
 
1886
        _tmp2_ = _tmp1_;
 
1887
        _tmp3_ = (NULL == _tmp2_) ? 0 : g_quark_from_string (_tmp2_);
 
1888
        if (_tmp3_ == ((0 != _tmp3__label0) ? _tmp3__label0 : (_tmp3__label0 = g_quark_from_static_string ("human")))) {
 
1889
                switch (0) {
 
1890
                        default:
 
1891
                        {
 
1892
                                gint index = 0;
 
1893
                                gchar* _tmp4_ = NULL;
 
1894
                                gchar* start;
 
1895
                                gchar* _tmp5_ = NULL;
 
1896
                                gchar* end;
 
1897
                                const gchar* _tmp6_ = NULL;
 
1898
                                gchar* _tmp7_ = NULL;
 
1899
                                if (move->victim == NULL) {
 
1900
                                        index = 0;
 
1901
                                } else {
 
1902
                                        index = (gint) (move->victim->type + 1);
 
1903
                                }
 
1904
                                index = index + ((gint) (move->piece->type * 6));
 
1905
                                if (move->piece->player->color == COLOR_BLACK) {
 
1906
                                        index = index + 36;
 
1907
                                }
 
1908
                                _tmp4_ = g_strdup_printf ("%c%d", 'a' + move->f0, move->r0 + 1);
 
1909
                                start = _tmp4_;
 
1910
                                _tmp5_ = g_strdup_printf ("%c%d", 'a' + move->f1, move->r1 + 1);
 
1911
                                end = _tmp5_;
 
1912
                                _tmp6_ = _ (human_descriptions[index]);
 
1913
                                _tmp7_ = g_strdup_printf (_tmp6_, start, end);
 
1914
                                _g_free0 (move_text);
 
1915
                                move_text = _tmp7_;
 
1916
                                _g_free0 (end);
 
1917
                                _g_free0 (start);
 
1918
                                break;
 
1919
                        }
 
1920
                }
 
1921
        } else if (_tmp3_ == ((0 != _tmp3__label1) ? _tmp3__label1 : (_tmp3__label1 = g_quark_from_static_string ("san")))) {
 
1922
                switch (0) {
 
1923
                        default:
 
1924
                        {
 
1925
                                gchar* _tmp8_ = NULL;
 
1926
                                _tmp8_ = chess_move_get_san (move);
 
1927
                                _g_free0 (move_text);
 
1928
                                move_text = _tmp8_;
 
1929
                                break;
 
1930
                        }
 
1931
                }
 
1932
        } else if (_tmp3_ == ((0 != _tmp3__label2) ? _tmp3__label2 : (_tmp3__label2 = g_quark_from_static_string ("fan")))) {
 
1933
                switch (0) {
 
1934
                        default:
 
1935
                        {
 
1936
                                gchar* _tmp9_ = NULL;
 
1937
                                _tmp9_ = chess_move_get_fan (move);
 
1938
                                _g_free0 (move_text);
 
1939
                                move_text = _tmp9_;
 
1940
                                break;
 
1941
                        }
 
1942
                }
 
1943
        } else {
 
1944
                switch (0) {
 
1945
                        default:
 
1946
                        {
 
1947
                                gchar* _tmp10_ = NULL;
 
1948
                                _tmp10_ = chess_move_get_lan (move);
 
1949
                                _g_free0 (move_text);
 
1950
                                move_text = _tmp10_;
 
1951
                                break;
 
1952
                        }
 
1953
                }
 
1954
        }
 
1955
        _tmp11_ = gtk_combo_box_get_model (self->priv->history_combo);
 
1956
        _tmp12_ = _g_object_ref0 (GTK_LIST_STORE (_tmp11_));
 
1957
        model = _tmp12_;
 
1958
        if ((move->number % 2) == 0) {
 
1959
                _tmp13_ = 'b';
 
1960
        } else {
 
1961
                _tmp13_ = 'a';
 
1962
        }
 
1963
        _tmp14_ = g_strdup_printf ("%u%c. %s", (guint) ((move->number + 1) / 2), (gint) _tmp13_, move_text);
 
1964
        label = _tmp14_;
 
1965
        gtk_list_store_set (model, iter, 0, label, -1, -1);
 
1966
        _g_free0 (label);
 
1967
        _g_object_unref0 (model);
 
1968
        _g_free0 (move_text);
 
1969
}
 
1970
 
 
1971
 
 
1972
static void application_game_move_cb (Application* self, ChessGame* game, ChessMove* move) {
 
1973
        gboolean _tmp0_ = FALSE;
 
1974
        gboolean _tmp1_ = FALSE;
 
1975
        guint _tmp2_;
 
1976
        GtkTreeModel* _tmp4_ = NULL;
 
1977
        GtkListStore* _tmp5_;
 
1978
        GtkListStore* model;
 
1979
        GtkTreeIter iter = {0};
 
1980
        GtkTreeIter _tmp6_ = {0};
 
1981
        gboolean _tmp7_ = FALSE;
 
1982
        guint _tmp8_;
 
1983
        g_return_if_fail (self != NULL);
 
1984
        g_return_if_fail (game != NULL);
 
1985
        g_return_if_fail (move != NULL);
 
1986
        self->priv->game_needs_saving = TRUE;
 
1987
        if (move->number == 1) {
 
1988
                _tmp1_ = self->priv->opponent != NULL;
 
1989
        } else {
 
1990
                _tmp1_ = FALSE;
 
1991
        }
 
1992
        if (_tmp1_) {
 
1993
                _tmp0_ = self->priv->opponent->color == COLOR_WHITE;
 
1994
        } else {
 
1995
                _tmp0_ = FALSE;
 
1996
        }
 
1997
        if (_tmp0_) {
 
1998
                self->priv->game_needs_saving = FALSE;
 
1999
        }
 
2000
        _tmp2_ = g_list_length (self->priv->pgn_game->moves);
 
2001
        if (move->number > _tmp2_) {
 
2002
                gchar* _tmp3_ = NULL;
 
2003
                _tmp3_ = chess_move_get_san (move);
 
2004
                self->priv->pgn_game->moves = g_list_append (self->priv->pgn_game->moves, _tmp3_);
 
2005
        }
 
2006
        _tmp4_ = gtk_combo_box_get_model (self->priv->history_combo);
 
2007
        _tmp5_ = _g_object_ref0 (GTK_LIST_STORE (_tmp4_));
 
2008
        model = _tmp5_;
 
2009
        gtk_list_store_append (model, &_tmp6_);
 
2010
        iter = _tmp6_;
 
2011
        gtk_list_store_set (model, &iter, 1, move->number, -1, -1);
 
2012
        application_set_move_text (self, &iter, move);
 
2013
        _tmp8_ = chess_game_get_n_moves (game);
 
2014
        if (move->number == _tmp8_) {
 
2015
                gint _tmp9_;
 
2016
                _tmp9_ = chess_scene_get_move_number (self->priv->scene);
 
2017
                _tmp7_ = _tmp9_ == (-1);
 
2018
        } else {
 
2019
                _tmp7_ = FALSE;
 
2020
        }
 
2021
        if (_tmp7_) {
 
2022
                gtk_combo_box_set_active_iter (self->priv->history_combo, &iter);
 
2023
        }
 
2024
        gtk_widget_set_sensitive (self->priv->save_menu, TRUE);
 
2025
        gtk_widget_set_sensitive (self->priv->save_as_menu, TRUE);
 
2026
        application_update_history_panel (self);
 
2027
        application_update_control_buttons (self);
 
2028
        if (self->priv->opponent_engine != NULL) {
 
2029
                chess_engine_report_move (self->priv->opponent_engine, move);
 
2030
        }
 
2031
        gtk_widget_queue_draw ((GtkWidget*) self->priv->view);
 
2032
        _g_object_unref0 (model);
 
2033
}
 
2034
 
 
2035
 
 
2036
static void application_game_undo_cb (Application* self, ChessGame* game) {
 
2037
        GList* _tmp0_ = NULL;
 
2038
        GtkTreeModel* _tmp1_ = NULL;
 
2039
        GtkListStore* _tmp2_;
 
2040
        GtkListStore* model;
 
2041
        GtkTreeIter iter = {0};
 
2042
        gint _tmp3_;
 
2043
        GtkTreeIter _tmp4_ = {0};
 
2044
        gboolean _tmp5_ = FALSE;
 
2045
        gint _tmp6_;
 
2046
        guint _tmp7_;
 
2047
        g_return_if_fail (self != NULL);
 
2048
        g_return_if_fail (game != NULL);
 
2049
        if (self->priv->opponent_engine != NULL) {
 
2050
                chess_engine_undo (self->priv->opponent_engine);
 
2051
        }
 
2052
        _tmp0_ = g_list_last (self->priv->pgn_game->moves);
 
2053
        self->priv->pgn_game->moves = g_list_remove_link (self->priv->pgn_game->moves, _tmp0_);
 
2054
        _tmp1_ = gtk_combo_box_get_model (self->priv->history_combo);
 
2055
        _tmp2_ = _g_object_ref0 (GTK_LIST_STORE (_tmp1_));
 
2056
        model = _tmp2_;
 
2057
        _tmp3_ = gtk_tree_model_iter_n_children ((GtkTreeModel*) model, NULL);
 
2058
        gtk_tree_model_iter_nth_child ((GtkTreeModel*) model, &_tmp4_, NULL, _tmp3_ - 1);
 
2059
        iter = _tmp4_;
 
2060
        gtk_list_store_remove (model, &iter);
 
2061
        _tmp6_ = chess_scene_get_move_number (self->priv->scene);
 
2062
        _tmp7_ = chess_game_get_n_moves (game);
 
2063
        if (_tmp6_ > _tmp7_) {
 
2064
                _tmp5_ = TRUE;
 
2065
        } else {
 
2066
                gint _tmp8_;
 
2067
                _tmp8_ = chess_scene_get_move_number (self->priv->scene);
 
2068
                _tmp5_ = _tmp8_ == (-1);
 
2069
        }
 
2070
        if (_tmp5_) {
 
2071
                gint _tmp9_;
 
2072
                GtkTreeIter _tmp10_ = {0};
 
2073
                _tmp9_ = gtk_tree_model_iter_n_children ((GtkTreeModel*) model, NULL);
 
2074
                gtk_tree_model_iter_nth_child ((GtkTreeModel*) model, &_tmp10_, NULL, _tmp9_ - 1);
 
2075
                iter = _tmp10_;
 
2076
                gtk_combo_box_set_active_iter (self->priv->history_combo, &iter);
 
2077
                gtk_widget_queue_draw ((GtkWidget*) self->priv->view);
 
2078
        }
 
2079
        application_update_history_panel (self);
 
2080
        application_update_control_buttons (self);
 
2081
        _g_object_unref0 (model);
 
2082
}
 
2083
 
 
2084
 
 
2085
static void application_update_control_buttons (Application* self) {
 
2086
        guint _tmp0_;
 
2087
        gboolean can_resign;
 
2088
        gboolean _tmp1_;
 
2089
        guint _tmp2_;
 
2090
        gboolean can_undo;
 
2091
        gboolean _tmp3_ = FALSE;
 
2092
        gboolean _tmp5_;
 
2093
        g_return_if_fail (self != NULL);
 
2094
        _tmp0_ = chess_game_get_n_moves (self->priv->game);
 
2095
        can_resign = _tmp0_ > 0;
 
2096
        _tmp1_ = can_resign;
 
2097
        gtk_widget_set_sensitive (self->priv->resign_button, _tmp1_);
 
2098
        gtk_widget_set_sensitive (self->priv->resign_menu, _tmp1_);
 
2099
        _tmp2_ = chess_game_get_n_moves (self->priv->game);
 
2100
        can_undo = _tmp2_ > 0;
 
2101
        if (self->priv->opponent != NULL) {
 
2102
                _tmp3_ = self->priv->opponent->color == COLOR_WHITE;
 
2103
        } else {
 
2104
                _tmp3_ = FALSE;
 
2105
        }
 
2106
        if (_tmp3_) {
 
2107
                guint _tmp4_;
 
2108
                _tmp4_ = chess_game_get_n_moves (self->priv->game);
 
2109
                can_undo = _tmp4_ > 1;
 
2110
        }
 
2111
        _tmp5_ = can_undo;
 
2112
        gtk_widget_set_sensitive (self->priv->undo_button, _tmp5_);
 
2113
        gtk_widget_set_sensitive (self->priv->undo_menu, _tmp5_);
 
2114
}
 
2115
 
 
2116
 
 
2117
static void application_game_end_cb (Application* self, ChessGame* game) {
 
2118
        gchar* _tmp0_;
 
2119
        gchar* title;
 
2120
        gchar* _tmp7_;
 
2121
        gchar* reason;
 
2122
        gchar* _tmp28_ = NULL;
 
2123
        gchar* _tmp29_;
 
2124
        g_return_if_fail (self != NULL);
 
2125
        g_return_if_fail (game != NULL);
 
2126
        _tmp0_ = g_strdup ("");
 
2127
        title = _tmp0_;
 
2128
        switch (game->result) {
 
2129
                case CHESS_RESULT_WHITE_WON:
 
2130
                {
 
2131
                        const gchar* _tmp1_ = NULL;
 
2132
                        gchar* _tmp2_;
 
2133
                        _tmp1_ = _ ("White wins");
 
2134
                        _tmp2_ = g_strdup (_tmp1_);
 
2135
                        _g_free0 (title);
 
2136
                        title = _tmp2_;
 
2137
                        pgn_game_set_result (self->priv->pgn_game, pgn_game_RESULT_WHITE);
 
2138
                        break;
 
2139
                }
 
2140
                case CHESS_RESULT_BLACK_WON:
 
2141
                {
 
2142
                        const gchar* _tmp3_ = NULL;
 
2143
                        gchar* _tmp4_;
 
2144
                        _tmp3_ = _ ("Black wins");
 
2145
                        _tmp4_ = g_strdup (_tmp3_);
 
2146
                        _g_free0 (title);
 
2147
                        title = _tmp4_;
 
2148
                        pgn_game_set_result (self->priv->pgn_game, pgn_game_RESULT_BLACK);
 
2149
                        break;
 
2150
                }
 
2151
                case CHESS_RESULT_DRAW:
 
2152
                {
 
2153
                        const gchar* _tmp5_ = NULL;
 
2154
                        gchar* _tmp6_;
 
2155
                        _tmp5_ = _ ("Game is drawn");
 
2156
                        _tmp6_ = g_strdup (_tmp5_);
 
2157
                        _g_free0 (title);
 
2158
                        title = _tmp6_;
 
2159
                        pgn_game_set_result (self->priv->pgn_game, pgn_game_RESULT_DRAW);
 
2160
                        break;
 
2161
                }
 
2162
                default:
 
2163
                {
 
2164
                        break;
 
2165
                }
 
2166
        }
 
2167
        _tmp7_ = g_strdup ("");
 
2168
        reason = _tmp7_;
 
2169
        switch (game->rule) {
 
2170
                case CHESS_RULE_CHECKMATE:
 
2171
                {
 
2172
                        const gchar* _tmp8_ = NULL;
 
2173
                        gchar* _tmp9_;
 
2174
                        _tmp8_ = _ ("Opponent is in check and cannot move (checkmate)");
 
2175
                        _tmp9_ = g_strdup (_tmp8_);
 
2176
                        _g_free0 (reason);
 
2177
                        reason = _tmp9_;
 
2178
                        break;
 
2179
                }
 
2180
                case CHESS_RULE_STALEMATE:
 
2181
                {
 
2182
                        const gchar* _tmp10_ = NULL;
 
2183
                        gchar* _tmp11_;
 
2184
                        _tmp10_ = _ ("Opponent cannot move (stalemate)");
 
2185
                        _tmp11_ = g_strdup (_tmp10_);
 
2186
                        _g_free0 (reason);
 
2187
                        reason = _tmp11_;
 
2188
                        break;
 
2189
                }
 
2190
                case CHESS_RULE_FIFTY_MOVES:
 
2191
                {
 
2192
                        const gchar* _tmp12_ = NULL;
 
2193
                        gchar* _tmp13_;
 
2194
                        _tmp12_ = _ ("No piece has been taken or pawn moved in the last fifty moves");
 
2195
                        _tmp13_ = g_strdup (_tmp12_);
 
2196
                        _g_free0 (reason);
 
2197
                        reason = _tmp13_;
 
2198
                        break;
 
2199
                }
 
2200
                case CHESS_RULE_TIMEOUT:
 
2201
                {
 
2202
                        const gchar* _tmp14_ = NULL;
 
2203
                        gchar* _tmp15_;
 
2204
                        _tmp14_ = _ ("Opponent has run out of time");
 
2205
                        _tmp15_ = g_strdup (_tmp14_);
 
2206
                        _g_free0 (reason);
 
2207
                        reason = _tmp15_;
 
2208
                        break;
 
2209
                }
 
2210
                case CHESS_RULE_THREE_FOLD_REPETITION:
 
2211
                {
 
2212
                        const gchar* _tmp16_ = NULL;
 
2213
                        gchar* _tmp17_;
 
2214
                        _tmp16_ = _ ("The same board state has occurred three times (three fold repetition)");
 
2215
                        _tmp17_ = g_strdup (_tmp16_);
 
2216
                        _g_free0 (reason);
 
2217
                        reason = _tmp17_;
 
2218
                        break;
 
2219
                }
 
2220
                case CHESS_RULE_INSUFFICIENT_MATERIAL:
 
2221
                {
 
2222
                        const gchar* _tmp18_ = NULL;
 
2223
                        gchar* _tmp19_;
 
2224
                        _tmp18_ = _ ("Neither player can cause checkmate (insufficient material)");
 
2225
                        _tmp19_ = g_strdup (_tmp18_);
 
2226
                        _g_free0 (reason);
 
2227
                        reason = _tmp19_;
 
2228
                        break;
 
2229
                }
 
2230
                case CHESS_RULE_RESIGN:
 
2231
                {
 
2232
                        if (game->result == CHESS_RESULT_WHITE_WON) {
 
2233
                                const gchar* _tmp20_ = NULL;
 
2234
                                gchar* _tmp21_;
 
2235
                                _tmp20_ = _ ("The black player has resigned");
 
2236
                                _tmp21_ = g_strdup (_tmp20_);
 
2237
                                _g_free0 (reason);
 
2238
                                reason = _tmp21_;
 
2239
                        } else {
 
2240
                                const gchar* _tmp22_ = NULL;
 
2241
                                gchar* _tmp23_;
 
2242
                                _tmp22_ = _ ("The white player has resigned");
 
2243
                                _tmp23_ = g_strdup (_tmp22_);
 
2244
                                _g_free0 (reason);
 
2245
                                reason = _tmp23_;
 
2246
                        }
 
2247
                        break;
 
2248
                }
 
2249
                case CHESS_RULE_ABANDONMENT:
 
2250
                {
 
2251
                        const gchar* _tmp24_ = NULL;
 
2252
                        gchar* _tmp25_;
 
2253
                        _tmp24_ = _ ("The game has been abandoned");
 
2254
                        _tmp25_ = g_strdup (_tmp24_);
 
2255
                        _g_free0 (reason);
 
2256
                        reason = _tmp25_;
 
2257
                        pgn_game_set_termination (self->priv->pgn_game, pgn_game_TERMINATE_ABANDONED);
 
2258
                        break;
 
2259
                }
 
2260
                case CHESS_RULE_DEATH:
 
2261
                {
 
2262
                        const gchar* _tmp26_ = NULL;
 
2263
                        gchar* _tmp27_;
 
2264
                        _tmp26_ = _ ("One of the players has died");
 
2265
                        _tmp27_ = g_strdup (_tmp26_);
 
2266
                        _g_free0 (reason);
 
2267
                        reason = _tmp27_;
 
2268
                        pgn_game_set_termination (self->priv->pgn_game, pgn_game_TERMINATE_DEATH);
 
2269
                        break;
 
2270
                }
 
2271
                default:
 
2272
                break;
 
2273
        }
 
2274
        _tmp28_ = g_strdup_printf ("<big><b>%s</b></big>", title);
 
2275
        _tmp29_ = _tmp28_;
 
2276
        gtk_label_set_markup (self->priv->info_title_label, _tmp29_);
 
2277
        _g_free0 (_tmp29_);
 
2278
        gtk_label_set_text (self->priv->info_label, reason);
 
2279
        gtk_widget_show ((GtkWidget*) self->priv->info_bar);
 
2280
        gtk_widget_queue_draw (self->priv->white_time_label);
 
2281
        gtk_widget_queue_draw (self->priv->black_time_label);
 
2282
        _g_free0 (reason);
 
2283
        _g_free0 (title);
 
2284
}
 
2285
 
 
2286
 
 
2287
void application_show (Application* self) {
 
2288
        g_return_if_fail (self != NULL);
 
2289
        gtk_widget_show ((GtkWidget*) self->priv->window);
 
2290
}
 
2291
 
 
2292
 
 
2293
gboolean G_MODULE_EXPORT glchess_app_delete_event_cb (GtkWidget* widget, GdkEvent* event, Application* self) {
 
2294
        gboolean result = FALSE;
 
2295
        g_return_val_if_fail (self != NULL, FALSE);
 
2296
        g_return_val_if_fail (widget != NULL, FALSE);
 
2297
        g_return_val_if_fail (event != NULL, FALSE);
 
2298
        application_quit (self);
 
2299
        result = FALSE;
 
2300
        return result;
 
2301
}
 
2302
 
 
2303
 
 
2304
gboolean G_MODULE_EXPORT glchess_app_configure_event_cb (GtkWidget* widget, GdkEventConfigure* event, Application* self) {
 
2305
        gboolean result = FALSE;
 
2306
        gboolean _tmp0_ = FALSE;
 
2307
        gboolean _tmp1_;
 
2308
        g_return_val_if_fail (self != NULL, FALSE);
 
2309
        g_return_val_if_fail (widget != NULL, FALSE);
 
2310
        _tmp1_ = g_settings_get_boolean (self->priv->settings, "maximized");
 
2311
        if (!_tmp1_) {
 
2312
                gboolean _tmp2_;
 
2313
                _tmp2_ = g_settings_get_boolean (self->priv->settings, "fullscreen");
 
2314
                _tmp0_ = !_tmp2_;
 
2315
        } else {
 
2316
                _tmp0_ = FALSE;
 
2317
        }
 
2318
        if (_tmp0_) {
 
2319
                g_settings_set_int (self->priv->settings, "width", (*event).width);
 
2320
                g_settings_set_int (self->priv->settings, "height", (*event).height);
 
2321
        }
 
2322
        result = FALSE;
 
2323
        return result;
 
2324
}
 
2325
 
 
2326
 
 
2327
gboolean G_MODULE_EXPORT glchess_app_window_state_event_cb (GtkWidget* widget, GdkEventWindowState* event, Application* self) {
 
2328
        gboolean result = FALSE;
 
2329
        g_return_val_if_fail (self != NULL, FALSE);
 
2330
        g_return_val_if_fail (widget != NULL, FALSE);
 
2331
        if (((*event).changed_mask & GDK_WINDOW_STATE_MAXIMIZED) != 0) {
 
2332
                gboolean is_maximized;
 
2333
                is_maximized = ((*event).new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
 
2334
                g_settings_set_boolean (self->priv->settings, "maximized", is_maximized);
 
2335
        }
 
2336
        if (((*event).changed_mask & GDK_WINDOW_STATE_FULLSCREEN) != 0) {
 
2337
                gboolean is_fullscreen;
 
2338
                const gchar* _tmp0_ = NULL;
 
2339
                is_fullscreen = ((*event).new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
 
2340
                g_settings_set_boolean (self->priv->settings, "fullscreen", is_fullscreen);
 
2341
                if (is_fullscreen) {
 
2342
                        _tmp0_ = GTK_STOCK_LEAVE_FULLSCREEN;
 
2343
                } else {
 
2344
                        _tmp0_ = GTK_STOCK_FULLSCREEN;
 
2345
                }
 
2346
                gtk_menu_item_set_label (self->priv->fullscreen_menu, _tmp0_);
 
2347
        }
 
2348
        result = FALSE;
 
2349
        return result;
 
2350
}
 
2351
 
 
2352
 
 
2353
void G_MODULE_EXPORT new_game_cb (GtkWidget* widget, Application* self) {
 
2354
        gboolean _tmp0_ = FALSE;
 
2355
        g_return_if_fail (self != NULL);
 
2356
        g_return_if_fail (widget != NULL);
 
2357
        if (self->priv->game_needs_saving) {
 
2358
                _tmp0_ = TRUE;
 
2359
        } else {
 
2360
                gboolean _tmp1_ = FALSE;
 
2361
                if (self->priv->in_history) {
 
2362
                        _tmp1_ = self->priv->game_file != NULL;
 
2363
                } else {
 
2364
                        _tmp1_ = FALSE;
 
2365
                }
 
2366
                _tmp0_ = _tmp1_;
 
2367
        }
 
2368
        if (_tmp0_) {
 
2369
                const gchar* _tmp2_ = NULL;
 
2370
                GtkMessageDialog* _tmp3_ = NULL;
 
2371
                GtkMessageDialog* dialog;
 
2372
                const gchar* _tmp4_ = NULL;
 
2373
                const gchar* _tmp5_ = NULL;
 
2374
                gint _tmp6_;
 
2375
                gint _result_;
 
2376
                _tmp2_ = _ ("Save this game before starting a new one?");
 
2377
                _tmp3_ = (GtkMessageDialog*) gtk_message_dialog_new_with_markup (self->priv->window, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "<span weight=\"bold\" size=\"larger\">%s</span>", _tmp2_, NULL);
 
2378
                dialog = g_object_ref_sink (_tmp3_);
 
2379
                gtk_dialog_add_button ((GtkDialog*) dialog, GTK_STOCK_CANCEL, (gint) GTK_RESPONSE_CANCEL);
 
2380
                _tmp4_ = _ ("_Abandon game");
 
2381
                gtk_dialog_add_button ((GtkDialog*) dialog, _tmp4_, (gint) GTK_RESPONSE_NO);
 
2382
                _tmp5_ = _ ("_Save game for later");
 
2383
                gtk_dialog_add_button ((GtkDialog*) dialog, _tmp5_, (gint) GTK_RESPONSE_YES);
 
2384
                _tmp6_ = gtk_dialog_run ((GtkDialog*) dialog);
 
2385
                _result_ = _tmp6_;
 
2386
                gtk_widget_destroy ((GtkWidget*) dialog);
 
2387
                if (_result_ == GTK_RESPONSE_CANCEL) {
 
2388
                        _g_object_unref0 (dialog);
 
2389
                        return;
 
2390
                }
 
2391
                if (_result_ == GTK_RESPONSE_NO) {
 
2392
                        self->priv->in_history = FALSE;
 
2393
                        self->priv->game_needs_saving = FALSE;
 
2394
                }
 
2395
                _g_object_unref0 (dialog);
 
2396
        }
 
2397
        application_autosave (self);
 
2398
        application_start_new_game (self);
 
2399
}
 
2400
 
 
2401
 
 
2402
void G_MODULE_EXPORT resign_cb (GtkWidget* widget, Application* self) {
 
2403
        ChessPlayer* _tmp0_ = NULL;
 
2404
        g_return_if_fail (self != NULL);
 
2405
        g_return_if_fail (widget != NULL);
 
2406
        _tmp0_ = chess_game_get_current_player (self->priv->game);
 
2407
        chess_player_resign (_tmp0_);
 
2408
}
 
2409
 
 
2410
 
 
2411
void G_MODULE_EXPORT claim_draw_cb (GtkWidget* widget, Application* self) {
 
2412
        ChessPlayer* _tmp0_ = NULL;
 
2413
        g_return_if_fail (self != NULL);
 
2414
        g_return_if_fail (widget != NULL);
 
2415
        _tmp0_ = chess_game_get_current_player (self->priv->game);
 
2416
        chess_player_claim_draw (_tmp0_);
 
2417
}
 
2418
 
 
2419
 
 
2420
void G_MODULE_EXPORT undo_move_cb (GtkWidget* widget, Application* self) {
 
2421
        g_return_if_fail (self != NULL);
 
2422
        g_return_if_fail (widget != NULL);
 
2423
        if (self->priv->opponent != NULL) {
 
2424
                chess_player_undo (self->priv->human_player);
 
2425
        } else {
 
2426
                ChessPlayer* _tmp0_ = NULL;
 
2427
                _tmp0_ = chess_game_get_opponent (self->priv->game);
 
2428
                chess_player_undo (_tmp0_);
 
2429
        }
 
2430
}
 
2431
 
 
2432
 
 
2433
void G_MODULE_EXPORT quit_cb (GtkWidget* widget, Application* self) {
 
2434
        g_return_if_fail (self != NULL);
 
2435
        g_return_if_fail (widget != NULL);
 
2436
        application_quit (self);
 
2437
}
 
2438
 
 
2439
 
 
2440
gboolean G_MODULE_EXPORT white_time_draw_cb (GtkWidget* widget, cairo_t* c, Application* self) {
 
2441
        gboolean result = FALSE;
 
2442
        static const gdouble fg[] = {0.0, 0.0, 0.0};
 
2443
        static const gdouble bg[] = {1.0, 1.0, 1.0};
 
2444
        ChessClock* _tmp0_ = NULL;
 
2445
        gchar* _tmp1_ = NULL;
 
2446
        gchar* _tmp2_;
 
2447
        g_return_val_if_fail (self != NULL, FALSE);
 
2448
        g_return_val_if_fail (widget != NULL, FALSE);
 
2449
        g_return_val_if_fail (c != NULL, FALSE);
 
2450
        _tmp0_ = chess_game_get_clock (self->priv->game);
 
2451
        _tmp1_ = application_make_clock_text (self, _tmp0_, COLOR_WHITE);
 
2452
        _tmp2_ = _tmp1_;
 
2453
        application_draw_time (self, widget, c, _tmp2_, fg, 3, bg, 3);
 
2454
        _g_free0 (_tmp2_);
 
2455
        result = FALSE;
 
2456
        return result;
 
2457
}
 
2458
 
 
2459
 
 
2460
gboolean G_MODULE_EXPORT black_time_draw_cb (GtkWidget* widget, cairo_t* c, Application* self) {
 
2461
        gboolean result = FALSE;
 
2462
        static const gdouble fg[] = {1.0, 1.0, 1.0};
 
2463
        static const gdouble bg[] = {0.0, 0.0, 0.0};
 
2464
        ChessClock* _tmp0_ = NULL;
 
2465
        gchar* _tmp1_ = NULL;
 
2466
        gchar* _tmp2_;
 
2467
        g_return_val_if_fail (self != NULL, FALSE);
 
2468
        g_return_val_if_fail (widget != NULL, FALSE);
 
2469
        g_return_val_if_fail (c != NULL, FALSE);
 
2470
        _tmp0_ = chess_game_get_clock (self->priv->game);
 
2471
        _tmp1_ = application_make_clock_text (self, _tmp0_, COLOR_BLACK);
 
2472
        _tmp2_ = _tmp1_;
 
2473
        application_draw_time (self, widget, c, _tmp2_, fg, 3, bg, 3);
 
2474
        _g_free0 (_tmp2_);
 
2475
        result = FALSE;
 
2476
        return result;
 
2477
}
 
2478
 
 
2479
 
 
2480
static gchar* application_make_clock_text (Application* self, ChessClock* clock, Color color) {
 
2481
        gchar* result = NULL;
 
2482
        gint used = 0;
 
2483
        g_return_val_if_fail (self != NULL, NULL);
 
2484
        if (clock == NULL) {
 
2485
                gchar* _tmp0_;
 
2486
                _tmp0_ = g_strdup ("āˆž");
 
2487
                result = _tmp0_;
 
2488
                return result;
 
2489
        }
 
2490
        if (color == COLOR_WHITE) {
 
2491
                ChessClock* _tmp1_ = NULL;
 
2492
                guint _tmp2_;
 
2493
                ChessClock* _tmp3_ = NULL;
 
2494
                guint _tmp4_;
 
2495
                _tmp1_ = chess_game_get_clock (self->priv->game);
 
2496
                _tmp2_ = chess_clock_get_white_duration (_tmp1_);
 
2497
                _tmp3_ = chess_game_get_clock (self->priv->game);
 
2498
                _tmp4_ = chess_clock_get_white_used_in_seconds (_tmp3_);
 
2499
                used = (gint) ((_tmp2_ / 1000) - _tmp4_);
 
2500
        } else {
 
2501
                ChessClock* _tmp5_ = NULL;
 
2502
                guint _tmp6_;
 
2503
                ChessClock* _tmp7_ = NULL;
 
2504
                guint _tmp8_;
 
2505
                _tmp5_ = chess_game_get_clock (self->priv->game);
 
2506
                _tmp6_ = chess_clock_get_black_duration (_tmp5_);
 
2507
                _tmp7_ = chess_game_get_clock (self->priv->game);
 
2508
                _tmp8_ = chess_clock_get_black_used_in_seconds (_tmp7_);
 
2509
                used = (gint) ((_tmp6_ / 1000) - _tmp8_);
 
2510
        }
 
2511
        if (used >= 60) {
 
2512
                gchar* _tmp9_ = NULL;
 
2513
                _tmp9_ = g_strdup_printf ("%d:%02d", used / 60, used % 60);
 
2514
                result = _tmp9_;
 
2515
                return result;
 
2516
        } else {
 
2517
                gchar* _tmp10_ = NULL;
 
2518
                _tmp10_ = g_strdup_printf (":%02d", used);
 
2519
                result = _tmp10_;
 
2520
                return result;
 
2521
        }
 
2522
}
 
2523
 
 
2524
 
 
2525
static void application_draw_time (Application* self, GtkWidget* widget, cairo_t* c, const gchar* text, gdouble* fg, int fg_length1, gdouble* bg, int bg_length1) {
 
2526
        gdouble alpha;
 
2527
        GtkStateType _tmp0_;
 
2528
        gint _tmp1_;
 
2529
        cairo_text_extents_t extents = {0};
 
2530
        cairo_text_extents_t _tmp2_ = {0};
 
2531
        gint _tmp3_;
 
2532
        gint _tmp4_;
 
2533
        g_return_if_fail (self != NULL);
 
2534
        g_return_if_fail (widget != NULL);
 
2535
        g_return_if_fail (c != NULL);
 
2536
        g_return_if_fail (text != NULL);
 
2537
        alpha = 1.0;
 
2538
        _tmp0_ = gtk_widget_get_state (widget);
 
2539
        if (_tmp0_ == GTK_STATE_INSENSITIVE) {
 
2540
                alpha = 0.5;
 
2541
        }
 
2542
        cairo_set_source_rgba (c, bg[0], bg[1], bg[2], alpha);
 
2543
        cairo_paint (c);
 
2544
        cairo_set_source_rgba (c, fg[0], fg[1], fg[2], alpha);
 
2545
        cairo_select_font_face (c, "fixed", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
 
2546
        _tmp1_ = gtk_widget_get_allocated_height (widget);
 
2547
        cairo_set_font_size (c, 0.6 * _tmp1_);
 
2548
        cairo_text_extents (c, text, &_tmp2_);
 
2549
        extents = _tmp2_;
 
2550
        _tmp3_ = gtk_widget_get_allocated_width (widget);
 
2551
        _tmp4_ = gtk_widget_get_allocated_height (widget);
 
2552
        cairo_move_to (c, ((_tmp3_ - extents.width) / 2) - extents.x_bearing, ((_tmp4_ - extents.height) / 2) - extents.y_bearing);
 
2553
        cairo_show_text (c, text);
 
2554
        gtk_widget_set_size_request (widget, ((gint) extents.width) + 6, -1);
 
2555
}
 
2556
 
 
2557
 
 
2558
void G_MODULE_EXPORT history_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
2559
        GtkTreeIter iter = {0};
 
2560
        GtkTreeIter _tmp0_ = {0};
 
2561
        gboolean _tmp1_;
 
2562
        gint move_number = 0;
 
2563
        GtkTreeModel* _tmp2_ = NULL;
 
2564
        gboolean _tmp3_ = FALSE;
 
2565
        g_return_if_fail (self != NULL);
 
2566
        g_return_if_fail (combo != NULL);
 
2567
        _tmp1_ = gtk_combo_box_get_active_iter (combo, &_tmp0_);
 
2568
        iter = _tmp0_;
 
2569
        if (!_tmp1_) {
 
2570
                return;
 
2571
        }
 
2572
        _tmp2_ = gtk_combo_box_get_model (combo);
 
2573
        gtk_tree_model_get (_tmp2_, &iter, 1, &move_number, -1, -1);
 
2574
        if (self->priv->game == NULL) {
 
2575
                _tmp3_ = TRUE;
 
2576
        } else {
 
2577
                guint _tmp4_;
 
2578
                _tmp4_ = chess_game_get_n_moves (self->priv->game);
 
2579
                _tmp3_ = move_number == _tmp4_;
 
2580
        }
 
2581
        if (_tmp3_) {
 
2582
                move_number = -1;
 
2583
        }
 
2584
        chess_scene_set_move_number (self->priv->scene, move_number);
 
2585
}
 
2586
 
 
2587
 
 
2588
void G_MODULE_EXPORT history_latest_clicked_cb (GtkWidget* widget, Application* self) {
 
2589
        g_return_if_fail (self != NULL);
 
2590
        g_return_if_fail (widget != NULL);
 
2591
        chess_scene_set_move_number (self->priv->scene, -1);
 
2592
}
 
2593
 
 
2594
 
 
2595
void G_MODULE_EXPORT history_next_clicked_cb (GtkWidget* widget, Application* self) {
 
2596
        gint _tmp0_;
 
2597
        gint _tmp1_;
 
2598
        gint move_number;
 
2599
        guint _tmp2_;
 
2600
        g_return_if_fail (self != NULL);
 
2601
        g_return_if_fail (widget != NULL);
 
2602
        _tmp0_ = chess_scene_get_move_number (self->priv->scene);
 
2603
        if (_tmp0_ == (-1)) {
 
2604
                return;
 
2605
        }
 
2606
        _tmp1_ = chess_scene_get_move_number (self->priv->scene);
 
2607
        move_number = _tmp1_ + 1;
 
2608
        _tmp2_ = chess_game_get_n_moves (self->priv->game);
 
2609
        if (move_number >= _tmp2_) {
 
2610
                chess_scene_set_move_number (self->priv->scene, -1);
 
2611
        } else {
 
2612
                chess_scene_set_move_number (self->priv->scene, move_number);
 
2613
        }
 
2614
}
 
2615
 
 
2616
 
 
2617
void G_MODULE_EXPORT history_previous_clicked_cb (GtkWidget* widget, Application* self) {
 
2618
        gint _tmp0_;
 
2619
        gint _tmp1_;
 
2620
        g_return_if_fail (self != NULL);
 
2621
        g_return_if_fail (widget != NULL);
 
2622
        _tmp0_ = chess_scene_get_move_number (self->priv->scene);
 
2623
        if (_tmp0_ == 0) {
 
2624
                return;
 
2625
        }
 
2626
        _tmp1_ = chess_scene_get_move_number (self->priv->scene);
 
2627
        if (_tmp1_ == (-1)) {
 
2628
                guint _tmp2_;
 
2629
                _tmp2_ = chess_game_get_n_moves (self->priv->game);
 
2630
                chess_scene_set_move_number (self->priv->scene, ((gint) _tmp2_) - 1);
 
2631
        } else {
 
2632
                gint _tmp3_;
 
2633
                _tmp3_ = chess_scene_get_move_number (self->priv->scene);
 
2634
                chess_scene_set_move_number (self->priv->scene, _tmp3_ - 1);
 
2635
        }
 
2636
}
 
2637
 
 
2638
 
 
2639
void G_MODULE_EXPORT history_start_clicked_cb (GtkWidget* widget, Application* self) {
 
2640
        g_return_if_fail (self != NULL);
 
2641
        g_return_if_fail (widget != NULL);
 
2642
        chess_scene_set_move_number (self->priv->scene, 0);
 
2643
}
 
2644
 
 
2645
 
 
2646
void G_MODULE_EXPORT toggle_fullscreen_cb (GtkWidget* widget, Application* self) {
 
2647
        const gchar* _tmp0_ = NULL;
 
2648
        g_return_if_fail (self != NULL);
 
2649
        g_return_if_fail (widget != NULL);
 
2650
        _tmp0_ = gtk_menu_item_get_label (self->priv->fullscreen_menu);
 
2651
        if (g_strcmp0 (_tmp0_, GTK_STOCK_FULLSCREEN) == 0) {
 
2652
                gtk_window_fullscreen (self->priv->window);
 
2653
        } else {
 
2654
                gtk_window_unfullscreen (self->priv->window);
 
2655
        }
 
2656
}
 
2657
 
 
2658
 
 
2659
void G_MODULE_EXPORT preferences_cb (GtkWidget* widget, Application* self) {
 
2660
        GtkBuilder* _tmp0_ = NULL;
 
2661
        gchar* _tmp1_ = NULL;
 
2662
        gchar* _tmp2_;
 
2663
        GObject* _tmp3_ = NULL;
 
2664
        GtkDialog* _tmp4_;
 
2665
        GObject* _tmp5_ = NULL;
 
2666
        GObject* _tmp6_ = NULL;
 
2667
        GObject* _tmp7_ = NULL;
 
2668
        GObject* _tmp8_ = NULL;
 
2669
        GObject* _tmp9_ = NULL;
 
2670
        GObject* _tmp10_ = NULL;
 
2671
        GObject* _tmp11_ = NULL;
 
2672
        GtkComboBox* _tmp12_;
 
2673
        GtkComboBox* side_combo;
 
2674
        gint _tmp13_ = 0;
 
2675
        gboolean _tmp14_;
 
2676
        GObject* _tmp15_ = NULL;
 
2677
        GtkComboBox* _tmp16_;
 
2678
        GtkComboBox* ai_combo;
 
2679
        GtkTreeModel* _tmp17_ = NULL;
 
2680
        GtkListStore* _tmp18_;
 
2681
        GtkListStore* ai_model;
 
2682
        gchar* _tmp19_ = NULL;
 
2683
        gchar* opponent_name;
 
2684
        GObject* _tmp25_ = NULL;
 
2685
        GtkComboBox* _tmp26_;
 
2686
        GtkComboBox* difficulty_combo;
 
2687
        gchar* _tmp27_ = NULL;
 
2688
        gchar* _tmp28_;
 
2689
        GObject* _tmp29_ = NULL;
 
2690
        GtkComboBox* _tmp30_;
 
2691
        GObject* _tmp31_ = NULL;
 
2692
        GtkAdjustment* _tmp32_;
 
2693
        GObject* _tmp33_ = NULL;
 
2694
        GtkContainer* _tmp34_;
 
2695
        GObject* _tmp35_ = NULL;
 
2696
        GtkComboBox* _tmp36_;
 
2697
        gint _tmp37_;
 
2698
        GObject* _tmp38_ = NULL;
 
2699
        GtkComboBox* _tmp39_;
 
2700
        GtkComboBox* orientation_combo;
 
2701
        gchar* _tmp40_ = NULL;
 
2702
        gchar* _tmp41_;
 
2703
        GObject* _tmp42_ = NULL;
 
2704
        GtkComboBox* _tmp43_;
 
2705
        GtkComboBox* move_combo;
 
2706
        gchar* _tmp44_ = NULL;
 
2707
        gchar* _tmp45_;
 
2708
        GObject* _tmp46_ = NULL;
 
2709
        GtkComboBox* _tmp47_;
 
2710
        GtkComboBox* promotion_combo;
 
2711
        gchar* _tmp48_ = NULL;
 
2712
        gchar* _tmp49_;
 
2713
        GObject* _tmp50_ = NULL;
 
2714
        GtkComboBox* _tmp51_;
 
2715
        GtkComboBox* theme_combo;
 
2716
        gchar* _tmp52_ = NULL;
 
2717
        gchar* _tmp53_;
 
2718
        GError * _inner_error_ = NULL;
 
2719
        g_return_if_fail (self != NULL);
 
2720
        g_return_if_fail (widget != NULL);
 
2721
        if (self->priv->preferences_dialog != NULL) {
 
2722
                gtk_window_present ((GtkWindow*) self->priv->preferences_dialog);
 
2723
                return;
 
2724
        }
 
2725
        _tmp0_ = gtk_builder_new ();
 
2726
        _g_object_unref0 (self->priv->preferences_builder);
 
2727
        self->priv->preferences_builder = _tmp0_;
 
2728
        _tmp1_ = g_build_filename (PKGDATADIR, "preferences.ui", NULL, NULL);
 
2729
        _tmp2_ = _tmp1_;
 
2730
        gtk_builder_add_from_file (self->priv->preferences_builder, _tmp2_, &_inner_error_);
 
2731
        _g_free0 (_tmp2_);
 
2732
        if (_inner_error_ != NULL) {
 
2733
                goto __catch2_g_error;
 
2734
        }
 
2735
        goto __finally2;
 
2736
        __catch2_g_error:
 
2737
        {
 
2738
                GError * e;
 
2739
                e = _inner_error_;
 
2740
                _inner_error_ = NULL;
 
2741
                g_warning ("glchess.vala:1021: Could not load preferences UI: %s", e->message);
 
2742
                _g_error_free0 (e);
 
2743
        }
 
2744
        __finally2:
 
2745
        if (_inner_error_ != NULL) {
 
2746
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
2747
                g_clear_error (&_inner_error_);
 
2748
                return;
 
2749
        }
 
2750
        _tmp3_ = gtk_builder_get_object (self->priv->preferences_builder, "preferences");
 
2751
        _tmp4_ = _g_object_ref0 (GTK_DIALOG (_tmp3_));
 
2752
        _g_object_unref0 (self->priv->preferences_dialog);
 
2753
        self->priv->preferences_dialog = _tmp4_;
 
2754
        _tmp5_ = gtk_builder_get_object (self->priv->preferences_builder, "show_numbering_check");
 
2755
        g_settings_bind (self->priv->settings, "show-numbering", _tmp5_, "active", G_SETTINGS_BIND_DEFAULT);
 
2756
        _tmp6_ = gtk_builder_get_object (self->priv->preferences_builder, "show_move_hints_check");
 
2757
        g_settings_bind (self->priv->settings, "show-move-hints", _tmp6_, "active", G_SETTINGS_BIND_DEFAULT);
 
2758
        _tmp7_ = gtk_builder_get_object (self->priv->preferences_builder, "show_toolbar_check");
 
2759
        g_settings_bind (self->priv->settings, "show-toolbar", _tmp7_, "active", G_SETTINGS_BIND_DEFAULT);
 
2760
        _tmp8_ = gtk_builder_get_object (self->priv->preferences_builder, "show_history_check");
 
2761
        g_settings_bind (self->priv->settings, "show-history", _tmp8_, "active", G_SETTINGS_BIND_DEFAULT);
 
2762
        _tmp9_ = gtk_builder_get_object (self->priv->preferences_builder, "show_3d_check");
 
2763
        g_settings_bind (self->priv->settings, "show-3d", _tmp9_, "active", G_SETTINGS_BIND_DEFAULT);
 
2764
        _tmp10_ = gtk_builder_get_object (self->priv->preferences_builder, "show_3d_smooth_check");
 
2765
        g_settings_bind (self->priv->settings, "show-3d-smooth", _tmp10_, "active", G_SETTINGS_BIND_DEFAULT);
 
2766
        _tmp11_ = gtk_builder_get_object (self->priv->preferences_builder, "side_combo");
 
2767
        _tmp12_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp11_));
 
2768
        side_combo = _tmp12_;
 
2769
        _tmp14_ = g_settings_get_boolean (self->priv->settings, "play-as-white");
 
2770
        if (_tmp14_) {
 
2771
                _tmp13_ = 0;
 
2772
        } else {
 
2773
                _tmp13_ = 1;
 
2774
        }
 
2775
        gtk_combo_box_set_active (side_combo, _tmp13_);
 
2776
        _tmp15_ = gtk_builder_get_object (self->priv->preferences_builder, "opponent_combo");
 
2777
        _tmp16_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp15_));
 
2778
        ai_combo = _tmp16_;
 
2779
        _tmp17_ = gtk_combo_box_get_model (ai_combo);
 
2780
        _tmp18_ = _g_object_ref0 (GTK_LIST_STORE (_tmp17_));
 
2781
        ai_model = _tmp18_;
 
2782
        _tmp19_ = g_settings_get_string (self->priv->settings, "opponent");
 
2783
        opponent_name = _tmp19_;
 
2784
        if (g_strcmp0 (opponent_name, "human") == 0) {
 
2785
                gtk_combo_box_set_active (ai_combo, 0);
 
2786
        }
 
2787
        {
 
2788
                GList* p_collection;
 
2789
                GList* p_it;
 
2790
                p_collection = self->priv->ai_profiles;
 
2791
                for (p_it = p_collection; p_it != NULL; p_it = p_it->next) {
 
2792
                        AIProfile* _tmp20_;
 
2793
                        AIProfile* p;
 
2794
                        _tmp20_ = _ai_profile_ref0 ((AIProfile*) p_it->data);
 
2795
                        p = _tmp20_;
 
2796
                        {
 
2797
                                GtkTreeIter iter = {0};
 
2798
                                GtkTreeIter _tmp21_ = {0};
 
2799
                                gboolean _tmp22_ = FALSE;
 
2800
                                gtk_list_store_append (ai_model, &_tmp21_);
 
2801
                                iter = _tmp21_;
 
2802
                                gtk_list_store_set (ai_model, &iter, 0, p->name, 1, p->name, -1, -1);
 
2803
                                if (g_strcmp0 (p->name, opponent_name) == 0) {
 
2804
                                        _tmp22_ = TRUE;
 
2805
                                } else {
 
2806
                                        gboolean _tmp23_ = FALSE;
 
2807
                                        if (g_strcmp0 (opponent_name, "") == 0) {
 
2808
                                                gint _tmp24_;
 
2809
                                                _tmp24_ = gtk_combo_box_get_active (ai_combo);
 
2810
                                                _tmp23_ = _tmp24_ == (-1);
 
2811
                                        } else {
 
2812
                                                _tmp23_ = FALSE;
 
2813
                                        }
 
2814
                                        _tmp22_ = _tmp23_;
 
2815
                                }
 
2816
                                if (_tmp22_) {
 
2817
                                        gtk_combo_box_set_active_iter (ai_combo, &iter);
 
2818
                                }
 
2819
                                _ai_profile_unref0 (p);
 
2820
                        }
 
2821
                }
 
2822
        }
 
2823
        g_settings_bind (self->priv->settings, "show-history", ai_combo, "visible", G_SETTINGS_BIND_SET);
 
2824
        _tmp25_ = gtk_builder_get_object (self->priv->preferences_builder, "difficulty_combo");
 
2825
        _tmp26_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp25_));
 
2826
        difficulty_combo = _tmp26_;
 
2827
        _tmp27_ = g_settings_get_string (self->priv->settings, "difficulty");
 
2828
        _tmp28_ = _tmp27_;
 
2829
        application_set_combo (self, difficulty_combo, 1, _tmp28_);
 
2830
        _g_free0 (_tmp28_);
 
2831
        _tmp29_ = gtk_builder_get_object (self->priv->preferences_builder, "duration_combo");
 
2832
        _tmp30_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp29_));
 
2833
        _g_object_unref0 (self->priv->duration_combo);
 
2834
        self->priv->duration_combo = _tmp30_;
 
2835
        _tmp31_ = gtk_builder_get_object (self->priv->preferences_builder, "duration_adjustment");
 
2836
        _tmp32_ = _g_object_ref0 (GTK_ADJUSTMENT (_tmp31_));
 
2837
        _g_object_unref0 (self->priv->duration_adjustment);
 
2838
        self->priv->duration_adjustment = _tmp32_;
 
2839
        _tmp33_ = gtk_builder_get_object (self->priv->preferences_builder, "custom_duration_box");
 
2840
        _tmp34_ = _g_object_ref0 (GTK_CONTAINER (_tmp33_));
 
2841
        _g_object_unref0 (self->priv->custom_duration_box);
 
2842
        self->priv->custom_duration_box = _tmp34_;
 
2843
        _tmp35_ = gtk_builder_get_object (self->priv->preferences_builder, "custom_duration_units_combo");
 
2844
        _tmp36_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp35_));
 
2845
        _g_object_unref0 (self->priv->custom_duration_units_combo);
 
2846
        self->priv->custom_duration_units_combo = _tmp36_;
 
2847
        _tmp37_ = g_settings_get_int (self->priv->settings, "duration");
 
2848
        application_set_duration (self, _tmp37_, TRUE);
 
2849
        _tmp38_ = gtk_builder_get_object (self->priv->preferences_builder, "orientation_combo");
 
2850
        _tmp39_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp38_));
 
2851
        orientation_combo = _tmp39_;
 
2852
        _tmp40_ = g_settings_get_string (self->priv->settings, "board-side");
 
2853
        _tmp41_ = _tmp40_;
 
2854
        application_set_combo (self, orientation_combo, 1, _tmp41_);
 
2855
        _g_free0 (_tmp41_);
 
2856
        _tmp42_ = gtk_builder_get_object (self->priv->preferences_builder, "move_format_combo");
 
2857
        _tmp43_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp42_));
 
2858
        move_combo = _tmp43_;
 
2859
        _tmp44_ = g_settings_get_string (self->priv->settings, "move-format");
 
2860
        _tmp45_ = _tmp44_;
 
2861
        application_set_combo (self, move_combo, 1, _tmp45_);
 
2862
        _g_free0 (_tmp45_);
 
2863
        _tmp46_ = gtk_builder_get_object (self->priv->preferences_builder, "promotion_type_combo");
 
2864
        _tmp47_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp46_));
 
2865
        promotion_combo = _tmp47_;
 
2866
        _tmp48_ = g_settings_get_string (self->priv->settings, "promotion-type");
 
2867
        _tmp49_ = _tmp48_;
 
2868
        application_set_combo (self, promotion_combo, 1, _tmp49_);
 
2869
        _g_free0 (_tmp49_);
 
2870
        _tmp50_ = gtk_builder_get_object (self->priv->preferences_builder, "piece_style_combo");
 
2871
        _tmp51_ = _g_object_ref0 (GTK_COMBO_BOX (_tmp50_));
 
2872
        theme_combo = _tmp51_;
 
2873
        _tmp52_ = g_settings_get_string (self->priv->settings, "piece-theme");
 
2874
        _tmp53_ = _tmp52_;
 
2875
        application_set_combo (self, theme_combo, 1, _tmp53_);
 
2876
        _g_free0 (_tmp53_);
 
2877
        gtk_builder_connect_signals (self->priv->preferences_builder, self);
 
2878
        gtk_window_present ((GtkWindow*) self->priv->preferences_dialog);
 
2879
        _g_object_unref0 (theme_combo);
 
2880
        _g_object_unref0 (promotion_combo);
 
2881
        _g_object_unref0 (move_combo);
 
2882
        _g_object_unref0 (orientation_combo);
 
2883
        _g_object_unref0 (difficulty_combo);
 
2884
        _g_free0 (opponent_name);
 
2885
        _g_object_unref0 (ai_model);
 
2886
        _g_object_unref0 (ai_combo);
 
2887
        _g_object_unref0 (side_combo);
 
2888
}
 
2889
 
 
2890
 
 
2891
static void application_set_combo (Application* self, GtkComboBox* combo, gint value_index, const gchar* value) {
 
2892
        GtkTreeIter iter = {0};
 
2893
        GtkTreeModel* _tmp0_ = NULL;
 
2894
        GtkTreeModel* _tmp1_;
 
2895
        GtkTreeModel* model;
 
2896
        GtkTreeIter _tmp2_ = {0};
 
2897
        gboolean _tmp3_;
 
2898
        g_return_if_fail (self != NULL);
 
2899
        g_return_if_fail (combo != NULL);
 
2900
        g_return_if_fail (value != NULL);
 
2901
        _tmp0_ = gtk_combo_box_get_model (combo);
 
2902
        _tmp1_ = _g_object_ref0 (_tmp0_);
 
2903
        model = _tmp1_;
 
2904
        _tmp3_ = gtk_tree_model_get_iter_first (model, &_tmp2_);
 
2905
        iter = _tmp2_;
 
2906
        if (!_tmp3_) {
 
2907
                _g_object_unref0 (model);
 
2908
                return;
 
2909
        }
 
2910
        {
 
2911
                gboolean _tmp4_;
 
2912
                _tmp4_ = TRUE;
 
2913
                while (TRUE) {
 
2914
                        gchar* v = NULL;
 
2915
                        if (!_tmp4_) {
 
2916
                                gboolean _tmp5_;
 
2917
                                _tmp5_ = gtk_tree_model_iter_next (model, &iter);
 
2918
                                if (!_tmp5_) {
 
2919
                                        break;
 
2920
                                }
 
2921
                        }
 
2922
                        _tmp4_ = FALSE;
 
2923
                        gtk_tree_model_get (model, &iter, value_index, &v, -1, -1);
 
2924
                        if (g_strcmp0 (v, value) == 0) {
 
2925
                                gtk_combo_box_set_active_iter (combo, &iter);
 
2926
                                _g_free0 (v);
 
2927
                                _g_object_unref0 (model);
 
2928
                                return;
 
2929
                        }
 
2930
                        _g_free0 (v);
 
2931
                }
 
2932
        }
 
2933
        _g_object_unref0 (model);
 
2934
}
 
2935
 
 
2936
 
 
2937
static gchar* application_get_combo (Application* self, GtkComboBox* combo, gint value_index) {
 
2938
        gchar* result = NULL;
 
2939
        gchar* value = NULL;
 
2940
        GtkTreeIter iter = {0};
 
2941
        GtkTreeIter _tmp0_ = {0};
 
2942
        gboolean _tmp1_;
 
2943
        GtkTreeModel* _tmp2_ = NULL;
 
2944
        g_return_val_if_fail (self != NULL, NULL);
 
2945
        g_return_val_if_fail (combo != NULL, NULL);
 
2946
        _tmp1_ = gtk_combo_box_get_active_iter (combo, &_tmp0_);
 
2947
        iter = _tmp0_;
 
2948
        if (!_tmp1_) {
 
2949
                result = NULL;
 
2950
                _g_free0 (value);
 
2951
                return result;
 
2952
        }
 
2953
        _tmp2_ = gtk_combo_box_get_model (combo);
 
2954
        gtk_tree_model_get (_tmp2_, &iter, value_index, &value, -1, -1);
 
2955
        result = value;
 
2956
        return result;
 
2957
}
 
2958
 
 
2959
 
 
2960
void G_MODULE_EXPORT side_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
2961
        GtkTreeIter iter = {0};
 
2962
        GtkTreeIter _tmp0_ = {0};
 
2963
        gboolean _tmp1_;
 
2964
        gboolean play_as_white = FALSE;
 
2965
        GtkTreeModel* _tmp2_ = NULL;
 
2966
        g_return_if_fail (self != NULL);
 
2967
        g_return_if_fail (combo != NULL);
 
2968
        _tmp1_ = gtk_combo_box_get_active_iter (combo, &_tmp0_);
 
2969
        iter = _tmp0_;
 
2970
        if (!_tmp1_) {
 
2971
                return;
 
2972
        }
 
2973
        _tmp2_ = gtk_combo_box_get_model (combo);
 
2974
        gtk_tree_model_get (_tmp2_, &iter, 1, &play_as_white, -1, -1);
 
2975
        g_settings_set_boolean (self->priv->settings, "play-as-white", play_as_white);
 
2976
}
 
2977
 
 
2978
 
 
2979
void G_MODULE_EXPORT opponent_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
2980
        GtkTreeIter iter = {0};
 
2981
        GtkTreeIter _tmp0_ = {0};
 
2982
        gboolean _tmp1_;
 
2983
        gchar* opponent = NULL;
 
2984
        GtkTreeModel* _tmp2_ = NULL;
 
2985
        g_return_if_fail (self != NULL);
 
2986
        g_return_if_fail (combo != NULL);
 
2987
        _tmp1_ = gtk_combo_box_get_active_iter (combo, &_tmp0_);
 
2988
        iter = _tmp0_;
 
2989
        if (!_tmp1_) {
 
2990
                return;
 
2991
        }
 
2992
        _tmp2_ = gtk_combo_box_get_model (combo);
 
2993
        gtk_tree_model_get (_tmp2_, &iter, 1, &opponent, -1, -1);
 
2994
        g_settings_set_string (self->priv->settings, "opponent", opponent);
 
2995
        _g_free0 (opponent);
 
2996
}
 
2997
 
 
2998
 
 
2999
void G_MODULE_EXPORT difficulty_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
3000
        GtkTreeIter iter = {0};
 
3001
        GtkTreeIter _tmp0_ = {0};
 
3002
        gboolean _tmp1_;
 
3003
        gchar* difficulty = NULL;
 
3004
        GtkTreeModel* _tmp2_ = NULL;
 
3005
        g_return_if_fail (self != NULL);
 
3006
        g_return_if_fail (combo != NULL);
 
3007
        _tmp1_ = gtk_combo_box_get_active_iter (combo, &_tmp0_);
 
3008
        iter = _tmp0_;
 
3009
        if (!_tmp1_) {
 
3010
                return;
 
3011
        }
 
3012
        _tmp2_ = gtk_combo_box_get_model (combo);
 
3013
        gtk_tree_model_get (_tmp2_, &iter, 1, &difficulty, -1, -1);
 
3014
        g_settings_set_string (self->priv->settings, "difficulty", difficulty);
 
3015
        _g_free0 (difficulty);
 
3016
}
 
3017
 
 
3018
 
 
3019
static void application_set_duration (Application* self, gint duration, gboolean simplify) {
 
3020
        GtkTreeModel* _tmp0_ = NULL;
 
3021
        GtkTreeModel* _tmp1_;
 
3022
        GtkTreeModel* model;
 
3023
        GtkTreeIter iter = {0};
 
3024
        GtkTreeIter _tmp2_ = {0};
 
3025
        GtkTreeIter max_iter;
 
3026
        gint max_multiplier;
 
3027
        GtkTreeIter _tmp3_ = {0};
 
3028
        gboolean _tmp4_;
 
3029
        gint value;
 
3030
        GtkTreeModel* _tmp8_ = NULL;
 
3031
        GtkTreeModel* _tmp9_;
 
3032
        GtkTreeIter _tmp10_ = {0};
 
3033
        gboolean _tmp11_;
 
3034
        g_return_if_fail (self != NULL);
 
3035
        _tmp0_ = gtk_combo_box_get_model (self->priv->custom_duration_units_combo);
 
3036
        _tmp1_ = _g_object_ref0 (_tmp0_);
 
3037
        model = _tmp1_;
 
3038
        max_iter = _tmp2_;
 
3039
        max_multiplier = 0;
 
3040
        _tmp4_ = gtk_tree_model_get_iter_first (model, &_tmp3_);
 
3041
        iter = _tmp3_;
 
3042
        if (_tmp4_) {
 
3043
                {
 
3044
                        gboolean _tmp5_;
 
3045
                        _tmp5_ = TRUE;
 
3046
                        while (TRUE) {
 
3047
                                gint multiplier = 0;
 
3048
                                gboolean _tmp7_ = FALSE;
 
3049
                                if (!_tmp5_) {
 
3050
                                        gboolean _tmp6_;
 
3051
                                        _tmp6_ = gtk_tree_model_iter_next (model, &iter);
 
3052
                                        if (!_tmp6_) {
 
3053
                                                break;
 
3054
                                        }
 
3055
                                }
 
3056
                                _tmp5_ = FALSE;
 
3057
                                gtk_tree_model_get (model, &iter, 1, &multiplier, -1, -1);
 
3058
                                if (multiplier > max_multiplier) {
 
3059
                                        _tmp7_ = (duration % multiplier) == 0;
 
3060
                                } else {
 
3061
                                        _tmp7_ = FALSE;
 
3062
                                }
 
3063
                                if (_tmp7_) {
 
3064
                                        max_multiplier = multiplier;
 
3065
                                        max_iter = iter;
 
3066
                                }
 
3067
                        }
 
3068
                }
 
3069
        }
 
3070
        value = 0;
 
3071
        if (max_multiplier > 0) {
 
3072
                value = duration / max_multiplier;
 
3073
                gtk_adjustment_set_value (self->priv->duration_adjustment, (gdouble) value);
 
3074
                gtk_combo_box_set_active_iter (self->priv->custom_duration_units_combo, &max_iter);
 
3075
        }
 
3076
        if (!simplify) {
 
3077
                _g_object_unref0 (model);
 
3078
                return;
 
3079
        }
 
3080
        _tmp8_ = gtk_combo_box_get_model (self->priv->duration_combo);
 
3081
        _tmp9_ = _g_object_ref0 (_tmp8_);
 
3082
        _g_object_unref0 (model);
 
3083
        model = _tmp9_;
 
3084
        _tmp11_ = gtk_tree_model_get_iter_first (model, &_tmp10_);
 
3085
        iter = _tmp10_;
 
3086
        if (!_tmp11_) {
 
3087
                _g_object_unref0 (model);
 
3088
                return;
 
3089
        }
 
3090
        {
 
3091
                gboolean _tmp12_;
 
3092
                _tmp12_ = TRUE;
 
3093
                while (TRUE) {
 
3094
                        gint v = 0;
 
3095
                        gboolean _tmp14_ = FALSE;
 
3096
                        if (!_tmp12_) {
 
3097
                                gboolean _tmp13_;
 
3098
                                _tmp13_ = gtk_tree_model_iter_next (model, &iter);
 
3099
                                if (!_tmp13_) {
 
3100
                                        break;
 
3101
                                }
 
3102
                        }
 
3103
                        _tmp12_ = FALSE;
 
3104
                        gtk_tree_model_get (model, &iter, 1, &v, -1, -1);
 
3105
                        if (v == duration) {
 
3106
                                _tmp14_ = TRUE;
 
3107
                        } else {
 
3108
                                _tmp14_ = v == (-1);
 
3109
                        }
 
3110
                        if (_tmp14_) {
 
3111
                                gtk_combo_box_set_active_iter (self->priv->duration_combo, &iter);
 
3112
                                gtk_widget_set_visible ((GtkWidget*) self->priv->custom_duration_box, v == (-1));
 
3113
                                _g_object_unref0 (model);
 
3114
                                return;
 
3115
                        }
 
3116
                }
 
3117
        }
 
3118
        _g_object_unref0 (model);
 
3119
}
 
3120
 
 
3121
 
 
3122
static gint application_get_duration (Application* self) {
 
3123
        gint result = 0;
 
3124
        GtkTreeIter iter = {0};
 
3125
        GtkTreeIter _tmp0_ = {0};
 
3126
        gboolean _tmp1_;
 
3127
        gdouble _tmp3_;
 
3128
        gint magnitude;
 
3129
        gint multiplier;
 
3130
        GtkTreeIter _tmp4_ = {0};
 
3131
        gboolean _tmp5_;
 
3132
        g_return_val_if_fail (self != NULL, 0);
 
3133
        _tmp1_ = gtk_combo_box_get_active_iter (self->priv->duration_combo, &_tmp0_);
 
3134
        iter = _tmp0_;
 
3135
        if (_tmp1_) {
 
3136
                gint duration = 0;
 
3137
                GtkTreeModel* _tmp2_ = NULL;
 
3138
                _tmp2_ = gtk_combo_box_get_model (self->priv->duration_combo);
 
3139
                gtk_tree_model_get (_tmp2_, &iter, 1, &duration, -1, -1);
 
3140
                if (duration >= 0) {
 
3141
                        result = duration;
 
3142
                        return result;
 
3143
                }
 
3144
        }
 
3145
        _tmp3_ = gtk_adjustment_get_value (self->priv->duration_adjustment);
 
3146
        magnitude = (gint) _tmp3_;
 
3147
        multiplier = 1;
 
3148
        _tmp5_ = gtk_combo_box_get_active_iter (self->priv->custom_duration_units_combo, &_tmp4_);
 
3149
        iter = _tmp4_;
 
3150
        if (_tmp5_) {
 
3151
                GtkTreeModel* _tmp6_ = NULL;
 
3152
                _tmp6_ = gtk_combo_box_get_model (self->priv->custom_duration_units_combo);
 
3153
                gtk_tree_model_get (_tmp6_, &iter, 1, &multiplier, -1, -1);
 
3154
        }
 
3155
        result = magnitude * multiplier;
 
3156
        return result;
 
3157
}
 
3158
 
 
3159
 
 
3160
static gboolean application_save_duration_cb (Application* self) {
 
3161
        gboolean result = FALSE;
 
3162
        gint _tmp0_;
 
3163
        g_return_val_if_fail (self != NULL, FALSE);
 
3164
        _tmp0_ = application_get_duration (self);
 
3165
        g_settings_set_int (self->priv->settings, "duration", _tmp0_);
 
3166
        g_source_remove (self->priv->save_duration_timeout);
 
3167
        self->priv->save_duration_timeout = (guint) 0;
 
3168
        result = FALSE;
 
3169
        return result;
 
3170
}
 
3171
 
 
3172
 
 
3173
void G_MODULE_EXPORT duration_changed_cb (GtkAdjustment* adjustment, Application* self) {
 
3174
        GtkTreeModel* _tmp0_ = NULL;
 
3175
        GtkListStore* _tmp1_;
 
3176
        GtkListStore* model;
 
3177
        GtkTreeIter iter = {0};
 
3178
        GtkTreeIter _tmp2_ = {0};
 
3179
        gboolean _tmp3_;
 
3180
        g_return_if_fail (self != NULL);
 
3181
        g_return_if_fail (adjustment != NULL);
 
3182
        _tmp0_ = gtk_combo_box_get_model (self->priv->custom_duration_units_combo);
 
3183
        _tmp1_ = _g_object_ref0 (GTK_LIST_STORE (_tmp0_));
 
3184
        model = _tmp1_;
 
3185
        _tmp3_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) model, &_tmp2_);
 
3186
        iter = _tmp2_;
 
3187
        if (_tmp3_) {
 
3188
                {
 
3189
                        gboolean _tmp4_;
 
3190
                        _tmp4_ = TRUE;
 
3191
                        while (TRUE) {
 
3192
                                gint multiplier = 0;
 
3193
                                if (!_tmp4_) {
 
3194
                                        gboolean _tmp5_;
 
3195
                                        _tmp5_ = gtk_tree_model_iter_next ((GtkTreeModel*) model, &iter);
 
3196
                                        if (!_tmp5_) {
 
3197
                                                break;
 
3198
                                        }
 
3199
                                }
 
3200
                                _tmp4_ = FALSE;
 
3201
                                gtk_tree_model_get ((GtkTreeModel*) model, &iter, 1, &multiplier, -1, -1);
 
3202
                                switch (multiplier) {
 
3203
                                        case 1:
 
3204
                                        {
 
3205
                                                gdouble _tmp6_;
 
3206
                                                const gchar* _tmp7_ = NULL;
 
3207
                                                _tmp6_ = gtk_adjustment_get_value (adjustment);
 
3208
                                                _tmp7_ = ngettext ("second", "seconds", (gulong) _tmp6_);
 
3209
                                                gtk_list_store_set (model, &iter, 0, _tmp7_, -1, -1);
 
3210
                                                break;
 
3211
                                        }
 
3212
                                        case 60:
 
3213
                                        {
 
3214
                                                gdouble _tmp8_;
 
3215
                                                const gchar* _tmp9_ = NULL;
 
3216
                                                _tmp8_ = gtk_adjustment_get_value (adjustment);
 
3217
                                                _tmp9_ = ngettext ("minute", "minutes", (gulong) _tmp8_);
 
3218
                                                gtk_list_store_set (model, &iter, 0, _tmp9_, -1, -1);
 
3219
                                                break;
 
3220
                                        }
 
3221
                                        case 3600:
 
3222
                                        {
 
3223
                                                gdouble _tmp10_;
 
3224
                                                const gchar* _tmp11_ = NULL;
 
3225
                                                _tmp10_ = gtk_adjustment_get_value (adjustment);
 
3226
                                                _tmp11_ = ngettext ("hour", "hours", (gulong) _tmp10_);
 
3227
                                                gtk_list_store_set (model, &iter, 0, _tmp11_, -1, -1);
 
3228
                                                break;
 
3229
                                        }
 
3230
                                        default:
 
3231
                                        break;
 
3232
                                }
 
3233
                        }
 
3234
                }
 
3235
        }
 
3236
        application_save_duration (self);
 
3237
        _g_object_unref0 (model);
 
3238
}
 
3239
 
 
3240
 
 
3241
void G_MODULE_EXPORT duration_units_changed_cb (GtkWidget* widget, Application* self) {
 
3242
        g_return_if_fail (self != NULL);
 
3243
        g_return_if_fail (widget != NULL);
 
3244
        application_save_duration (self);
 
3245
}
 
3246
 
 
3247
 
 
3248
static gboolean _application_save_duration_cb_gsource_func (gpointer self) {
 
3249
        gboolean result;
 
3250
        result = application_save_duration_cb (self);
 
3251
        return result;
 
3252
}
 
3253
 
 
3254
 
 
3255
static void application_save_duration (Application* self) {
 
3256
        guint _tmp0_;
 
3257
        g_return_if_fail (self != NULL);
 
3258
        if (self->priv->save_duration_timeout != 0) {
 
3259
                g_source_remove (self->priv->save_duration_timeout);
 
3260
        }
 
3261
        _tmp0_ = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 100, _application_save_duration_cb_gsource_func, application_ref (self), application_unref);
 
3262
        self->priv->save_duration_timeout = _tmp0_;
 
3263
}
 
3264
 
 
3265
 
 
3266
void G_MODULE_EXPORT duration_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
3267
        GtkTreeIter iter = {0};
 
3268
        GtkTreeIter _tmp0_ = {0};
 
3269
        gboolean _tmp1_;
 
3270
        gint duration = 0;
 
3271
        GtkTreeModel* _tmp2_ = NULL;
 
3272
        g_return_if_fail (self != NULL);
 
3273
        g_return_if_fail (combo != NULL);
 
3274
        _tmp1_ = gtk_combo_box_get_active_iter (combo, &_tmp0_);
 
3275
        iter = _tmp0_;
 
3276
        if (!_tmp1_) {
 
3277
                return;
 
3278
        }
 
3279
        _tmp2_ = gtk_combo_box_get_model (combo);
 
3280
        gtk_tree_model_get (_tmp2_, &iter, 1, &duration, -1, -1);
 
3281
        gtk_widget_set_visible ((GtkWidget*) self->priv->custom_duration_box, duration < 0);
 
3282
        if (duration >= 0) {
 
3283
                application_set_duration (self, duration, FALSE);
 
3284
        } else {
 
3285
                gint _tmp3_;
 
3286
                _tmp3_ = application_get_duration (self);
 
3287
                if (_tmp3_ <= 0) {
 
3288
                        application_set_duration (self, 5 * 60, FALSE);
 
3289
                }
 
3290
        }
 
3291
        application_save_duration (self);
 
3292
}
 
3293
 
 
3294
 
 
3295
void G_MODULE_EXPORT preferences_response_cb (GtkWidget* widget, gint response_id, Application* self) {
 
3296
        g_return_if_fail (self != NULL);
 
3297
        g_return_if_fail (widget != NULL);
 
3298
        gtk_widget_hide ((GtkWidget*) self->priv->preferences_dialog);
 
3299
}
 
3300
 
 
3301
 
 
3302
gboolean G_MODULE_EXPORT preferences_delete_event_cb (GtkWidget* widget, GdkEvent* event, Application* self) {
 
3303
        gboolean result = FALSE;
 
3304
        g_return_val_if_fail (self != NULL, FALSE);
 
3305
        g_return_val_if_fail (widget != NULL, FALSE);
 
3306
        g_return_val_if_fail (event != NULL, FALSE);
 
3307
        G_MODULE_EXPORT preferences_response_cb (widget, (gint) GTK_RESPONSE_CANCEL, self);
 
3308
        result = TRUE;
 
3309
        return result;
 
3310
}
 
3311
 
 
3312
 
 
3313
void G_MODULE_EXPORT piece_style_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
3314
        gchar* _tmp0_ = NULL;
 
3315
        gchar* _tmp1_;
 
3316
        g_return_if_fail (self != NULL);
 
3317
        g_return_if_fail (combo != NULL);
 
3318
        _tmp0_ = application_get_combo (self, combo, 1);
 
3319
        _tmp1_ = _tmp0_;
 
3320
        g_settings_set_string (self->priv->settings, "piece-theme", _tmp1_);
 
3321
        _g_free0 (_tmp1_);
 
3322
}
 
3323
 
 
3324
 
 
3325
void G_MODULE_EXPORT show_3d_toggle_cb (GtkToggleButton* widget, Application* self) {
 
3326
        GObject* _tmp0_ = NULL;
 
3327
        GtkWidget* _tmp1_;
 
3328
        GtkWidget* w;
 
3329
        gboolean _tmp2_;
 
3330
        GObject* _tmp3_ = NULL;
 
3331
        GtkWidget* _tmp4_;
 
3332
        gboolean _tmp5_;
 
3333
        g_return_if_fail (self != NULL);
 
3334
        g_return_if_fail (widget != NULL);
 
3335
        _tmp0_ = gtk_builder_get_object (self->priv->preferences_builder, "show_3d_smooth_check");
 
3336
        _tmp1_ = _g_object_ref0 (GTK_WIDGET (_tmp0_));
 
3337
        w = _tmp1_;
 
3338
        _tmp2_ = gtk_toggle_button_get_active (widget);
 
3339
        gtk_widget_set_sensitive (w, _tmp2_);
 
3340
        _tmp3_ = gtk_builder_get_object (self->priv->preferences_builder, "piece_style_combo");
 
3341
        _tmp4_ = _g_object_ref0 (GTK_WIDGET (_tmp3_));
 
3342
        _g_object_unref0 (w);
 
3343
        w = _tmp4_;
 
3344
        _tmp5_ = gtk_toggle_button_get_active (widget);
 
3345
        gtk_widget_set_sensitive (w, !_tmp5_);
 
3346
        _g_object_unref0 (w);
 
3347
}
 
3348
 
 
3349
 
 
3350
void G_MODULE_EXPORT promotion_type_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
3351
        gchar* _tmp0_ = NULL;
 
3352
        gchar* _tmp1_;
 
3353
        g_return_if_fail (self != NULL);
 
3354
        g_return_if_fail (combo != NULL);
 
3355
        _tmp0_ = application_get_combo (self, combo, 1);
 
3356
        _tmp1_ = _tmp0_;
 
3357
        g_settings_set_string (self->priv->settings, "promotion-type", _tmp1_);
 
3358
        _g_free0 (_tmp1_);
 
3359
}
 
3360
 
 
3361
 
 
3362
void G_MODULE_EXPORT move_format_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
3363
        gchar* _tmp0_ = NULL;
 
3364
        gchar* _tmp1_;
 
3365
        g_return_if_fail (self != NULL);
 
3366
        g_return_if_fail (combo != NULL);
 
3367
        _tmp0_ = application_get_combo (self, combo, 1);
 
3368
        _tmp1_ = _tmp0_;
 
3369
        g_settings_set_string (self->priv->settings, "move-format", _tmp1_);
 
3370
        _g_free0 (_tmp1_);
 
3371
}
 
3372
 
 
3373
 
 
3374
void G_MODULE_EXPORT orientation_combo_changed_cb (GtkComboBox* combo, Application* self) {
 
3375
        gchar* _tmp0_ = NULL;
 
3376
        gchar* _tmp1_;
 
3377
        g_return_if_fail (self != NULL);
 
3378
        g_return_if_fail (combo != NULL);
 
3379
        _tmp0_ = application_get_combo (self, combo, 1);
 
3380
        _tmp1_ = _tmp0_;
 
3381
        g_settings_set_string (self->priv->settings, "board-side", _tmp1_);
 
3382
        _g_free0 (_tmp1_);
 
3383
}
 
3384
 
 
3385
 
 
3386
void G_MODULE_EXPORT help_cb (GtkWidget* widget, Application* self) {
 
3387
        GdkScreen* _tmp0_ = NULL;
 
3388
        guint32 _tmp1_;
 
3389
        GError * _inner_error_ = NULL;
 
3390
        g_return_if_fail (self != NULL);
 
3391
        g_return_if_fail (widget != NULL);
 
3392
        _tmp0_ = gtk_window_get_screen (self->priv->window);
 
3393
        _tmp1_ = gtk_get_current_event_time ();
 
3394
        gtk_show_uri (_tmp0_, "ghelp:glchess", _tmp1_, &_inner_error_);
 
3395
        if (_inner_error_ != NULL) {
 
3396
                goto __catch3_g_error;
 
3397
        }
 
3398
        goto __finally3;
 
3399
        __catch3_g_error:
 
3400
        {
 
3401
                GError * e;
 
3402
                e = _inner_error_;
 
3403
                _inner_error_ = NULL;
 
3404
                g_warning ("glchess.vala:1340: Unable to open help: %s", e->message);
 
3405
                _g_error_free0 (e);
 
3406
        }
 
3407
        __finally3:
 
3408
        if (_inner_error_ != NULL) {
 
3409
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
3410
                g_clear_error (&_inner_error_);
 
3411
                return;
 
3412
        }
 
3413
}
 
3414
 
 
3415
 
 
3416
static void _application_about_response_cb_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self) {
 
3417
        application_about_response_cb (self, response_id);
 
3418
}
 
3419
 
 
3420
 
 
3421
void G_MODULE_EXPORT about_cb (GtkWidget* widget, Application* self) {
 
3422
        GtkAboutDialog* _tmp0_ = NULL;
 
3423
        const gchar* _tmp1_ = NULL;
 
3424
        const gchar* _tmp2_ = NULL;
 
3425
        g_return_if_fail (self != NULL);
 
3426
        g_return_if_fail (widget != NULL);
 
3427
        if (self->priv->about_dialog != NULL) {
 
3428
                gtk_window_present ((GtkWindow*) self->priv->about_dialog);
 
3429
                return;
 
3430
        }
 
3431
        _tmp0_ = (GtkAboutDialog*) gtk_about_dialog_new ();
 
3432
        _g_object_unref0 (self->priv->about_dialog);
 
3433
        self->priv->about_dialog = g_object_ref_sink (_tmp0_);
 
3434
        gtk_window_set_transient_for ((GtkWindow*) self->priv->about_dialog, self->priv->window);
 
3435
        gtk_widget_set_name ((GtkWidget*) self->priv->about_dialog, "glchess");
 
3436
        gtk_about_dialog_set_version (self->priv->about_dialog, VERSION);
 
3437
        gtk_about_dialog_set_copyright (self->priv->about_dialog, "Copyright 2010 Robert Ancell <robert.ancell@gmail.com>");
 
3438
        gtk_about_dialog_set_license_type (self->priv->about_dialog, GTK_LICENSE_GPL_2_0);
 
3439
        gtk_about_dialog_set_wrap_license (self->priv->about_dialog, TRUE);
 
3440
        _tmp1_ = _ ("The 2D/3D chess game for GNOME. \n" \
 
3441
"\n" \
 
3442
"glChess is a part of GNOME Games.");
 
3443
        gtk_about_dialog_set_comments (self->priv->about_dialog, _tmp1_);
 
3444
        gtk_about_dialog_set_authors (self->priv->about_dialog, APPLICATION_authors);
 
3445
        gtk_about_dialog_set_artists (self->priv->about_dialog, APPLICATION_artists);
 
3446
        gtk_about_dialog_set_translator_credits (self->priv->about_dialog, "translator-credits");
 
3447
        gtk_about_dialog_set_website (self->priv->about_dialog, "http://www.gnome.org/projects/gnome-games/");
 
3448
        _tmp2_ = _ ("GNOME Games web site");
 
3449
        gtk_about_dialog_set_website_label (self->priv->about_dialog, _tmp2_);
 
3450
        gtk_about_dialog_set_logo_icon_name (self->priv->about_dialog, "glchess");
 
3451
        g_signal_connect ((GtkDialog*) self->priv->about_dialog, "response", (GCallback) _application_about_response_cb_gtk_dialog_response, self);
 
3452
        gtk_widget_show ((GtkWidget*) self->priv->about_dialog);
 
3453
}
 
3454
 
 
3455
 
 
3456
static void application_about_response_cb (Application* self, gint response_id) {
 
3457
        g_return_if_fail (self != NULL);
 
3458
        gtk_widget_destroy ((GtkWidget*) self->priv->about_dialog);
 
3459
        _g_object_unref0 (self->priv->about_dialog);
 
3460
        self->priv->about_dialog = NULL;
 
3461
}
 
3462
 
 
3463
 
 
3464
void G_MODULE_EXPORT save_game_as_cb (GtkWidget* widget, Application* self) {
 
3465
        g_return_if_fail (self != NULL);
 
3466
        g_return_if_fail (widget != NULL);
 
3467
        application_save_game (self);
 
3468
}
 
3469
 
 
3470
 
 
3471
void G_MODULE_EXPORT save_game_cb (GtkWidget* widget, Application* self) {
 
3472
        g_return_if_fail (self != NULL);
 
3473
        g_return_if_fail (widget != NULL);
 
3474
        application_save_game (self);
 
3475
}
 
3476
 
 
3477
 
 
3478
static void application_add_info_bar_to_dialog (Application* self, GtkDialog* dialog, GtkInfoBar** info_bar, GtkLabel** label) {
 
3479
        GtkInfoBar* _info_bar = NULL;
 
3480
        GtkLabel* _label = NULL;
 
3481
        GtkVBox* _tmp0_ = NULL;
 
3482
        GtkVBox* vbox;
 
3483
        GtkInfoBar* _tmp1_ = NULL;
 
3484
        GtkWidget* _tmp2_ = NULL;
 
3485
        GtkContainer* _tmp3_;
 
3486
        GtkContainer* content_area;
 
3487
        GtkLabel* _tmp4_ = NULL;
 
3488
        GtkWidget* _tmp5_ = NULL;
 
3489
        GtkContainer* _tmp6_;
 
3490
        GtkContainer* child;
 
3491
        guint _tmp7_;
 
3492
        g_return_if_fail (self != NULL);
 
3493
        g_return_if_fail (dialog != NULL);
 
3494
        _tmp0_ = (GtkVBox*) gtk_vbox_new (FALSE, 0);
 
3495
        vbox = g_object_ref_sink (_tmp0_);
 
3496
        gtk_widget_show ((GtkWidget*) vbox);
 
3497
        _tmp1_ = (GtkInfoBar*) gtk_info_bar_new ();
 
3498
        _g_object_unref0 (_info_bar);
 
3499
        _info_bar = g_object_ref_sink (_tmp1_);
 
3500
        _tmp2_ = gtk_info_bar_get_content_area (_info_bar);
 
3501
        _tmp3_ = _g_object_ref0 (GTK_CONTAINER (_tmp2_));
 
3502
        content_area = _tmp3_;
 
3503
        gtk_box_pack_start ((GtkBox*) vbox, (GtkWidget*) _info_bar, FALSE, TRUE, (guint) 0);
 
3504
        _tmp4_ = (GtkLabel*) gtk_label_new ("");
 
3505
        _g_object_unref0 (_label);
 
3506
        _label = g_object_ref_sink (_tmp4_);
 
3507
        gtk_container_add (content_area, (GtkWidget*) _label);
 
3508
        gtk_widget_show ((GtkWidget*) _label);
 
3509
        _tmp5_ = gtk_bin_get_child ((GtkBin*) dialog);
 
3510
        _tmp6_ = _g_object_ref0 (GTK_CONTAINER (_tmp5_));
 
3511
        child = _tmp6_;
 
3512
        gtk_widget_reparent ((GtkWidget*) child, (GtkWidget*) vbox);
 
3513
        _tmp7_ = gtk_container_get_border_width ((GtkContainer*) dialog);
 
3514
        gtk_container_set_border_width (child, _tmp7_);
 
3515
        gtk_container_set_border_width ((GtkContainer*) dialog, (guint) 0);
 
3516
        gtk_container_add ((GtkContainer*) dialog, (GtkWidget*) vbox);
 
3517
        _g_object_unref0 (child);
 
3518
        _g_object_unref0 (content_area);
 
3519
        _g_object_unref0 (vbox);
 
3520
        if (info_bar) {
 
3521
                *info_bar = _info_bar;
 
3522
        } else {
 
3523
                _g_object_unref0 (_info_bar);
 
3524
        }
 
3525
        if (label) {
 
3526
                *label = _label;
 
3527
        } else {
 
3528
                _g_object_unref0 (_label);
 
3529
        }
 
3530
}
 
3531
 
 
3532
 
 
3533
static void _application_save_file_cb_gtk_file_chooser_file_activated (GtkFileChooser* _sender, gpointer self) {
 
3534
        application_save_file_cb (self);
 
3535
}
 
3536
 
 
3537
 
 
3538
static void _application_save_cb_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self) {
 
3539
        application_save_cb (self, response_id);
 
3540
}
 
3541
 
 
3542
 
 
3543
static void application_save_game (Application* self) {
 
3544
        const gchar* _tmp0_ = NULL;
 
3545
        GtkFileChooserDialog* _tmp1_ = NULL;
 
3546
        GtkInfoBar* _tmp2_ = NULL;
 
3547
        GtkLabel* _tmp3_ = NULL;
 
3548
        GtkFileFilter* _tmp4_ = NULL;
 
3549
        GtkFileFilter* pgn_filter;
 
3550
        const gchar* _tmp5_ = NULL;
 
3551
        GtkFileFilter* _tmp6_ = NULL;
 
3552
        GtkFileFilter* all_filter;
 
3553
        const gchar* _tmp7_ = NULL;
 
3554
        g_return_if_fail (self != NULL);
 
3555
        if (self->priv->save_dialog != NULL) {
 
3556
                gtk_window_present ((GtkWindow*) self->priv->save_dialog);
 
3557
                return;
 
3558
        }
 
3559
        _tmp0_ = _ ("Save Chess Game");
 
3560
        _tmp1_ = (GtkFileChooserDialog*) gtk_file_chooser_dialog_new (_tmp0_, self->priv->window, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL, NULL);
 
3561
        _g_object_unref0 (self->priv->save_dialog);
 
3562
        self->priv->save_dialog = g_object_ref_sink (_tmp1_);
 
3563
        application_add_info_bar_to_dialog (self, (GtkDialog*) self->priv->save_dialog, &_tmp2_, &_tmp3_);
 
3564
        _g_object_unref0 (self->priv->save_dialog_info_bar);
 
3565
        self->priv->save_dialog_info_bar = _tmp2_;
 
3566
        _g_object_unref0 (self->priv->save_dialog_error_label);
 
3567
        self->priv->save_dialog_error_label = _tmp3_;
 
3568
        g_signal_connect ((GtkFileChooser*) self->priv->save_dialog, "file-activated", (GCallback) _application_save_file_cb_gtk_file_chooser_file_activated, self);
 
3569
        g_signal_connect ((GtkDialog*) self->priv->save_dialog, "response", (GCallback) _application_save_cb_gtk_dialog_response, self);
 
3570
        _tmp4_ = gtk_file_filter_new ();
 
3571
        pgn_filter = g_object_ref_sink (_tmp4_);
 
3572
        _tmp5_ = _ ("PGN files");
 
3573
        gtk_file_filter_set_name (pgn_filter, _tmp5_);
 
3574
        gtk_file_filter_add_pattern (pgn_filter, "*.pgn");
 
3575
        gtk_file_chooser_add_filter ((GtkFileChooser*) self->priv->save_dialog, pgn_filter);
 
3576
        _tmp6_ = gtk_file_filter_new ();
 
3577
        all_filter = g_object_ref_sink (_tmp6_);
 
3578
        _tmp7_ = _ ("All files");
 
3579
        gtk_file_filter_set_name (all_filter, _tmp7_);
 
3580
        gtk_file_filter_add_pattern (all_filter, "*");
 
3581
        gtk_file_chooser_add_filter ((GtkFileChooser*) self->priv->save_dialog, all_filter);
 
3582
        gtk_window_present ((GtkWindow*) self->priv->save_dialog);
 
3583
        _g_object_unref0 (all_filter);
 
3584
        _g_object_unref0 (pgn_filter);
 
3585
}
 
3586
 
 
3587
 
 
3588
static void application_save_file_cb (Application* self) {
 
3589
        g_return_if_fail (self != NULL);
 
3590
        application_save_cb (self, (gint) GTK_RESPONSE_OK);
 
3591
}
 
3592
 
 
3593
 
 
3594
static void application_save_cb (Application* self, gint response_id) {
 
3595
        GError * _inner_error_ = NULL;
 
3596
        g_return_if_fail (self != NULL);
 
3597
        if (response_id == GTK_RESPONSE_OK) {
 
3598
                GFile* _tmp0_ = NULL;
 
3599
                gtk_widget_set_sensitive (self->priv->save_menu, FALSE);
 
3600
                _tmp0_ = gtk_file_chooser_get_file ((GtkFileChooser*) self->priv->save_dialog);
 
3601
                pgn_game_write (self->priv->pgn_game, _tmp0_, &_inner_error_);
 
3602
                if (_inner_error_ != NULL) {
 
3603
                        goto __catch4_g_error;
 
3604
                }
 
3605
                goto __finally4;
 
3606
                __catch4_g_error:
 
3607
                {
 
3608
                        GError * e;
 
3609
                        const gchar* _tmp1_ = NULL;
 
3610
                        gchar* _tmp2_ = NULL;
 
3611
                        gchar* _tmp3_;
 
3612
                        e = _inner_error_;
 
3613
                        _inner_error_ = NULL;
 
3614
                        _tmp1_ = _ ("Failed to save game: %s");
 
3615
                        _tmp2_ = g_strdup_printf (_tmp1_, e->message);
 
3616
                        _tmp3_ = _tmp2_;
 
3617
                        gtk_label_set_text (self->priv->save_dialog_error_label, _tmp3_);
 
3618
                        _g_free0 (_tmp3_);
 
3619
                        gtk_info_bar_set_message_type (self->priv->save_dialog_info_bar, GTK_MESSAGE_ERROR);
 
3620
                        gtk_widget_show ((GtkWidget*) self->priv->save_dialog_info_bar);
 
3621
                        _g_error_free0 (e);
 
3622
                        return;
 
3623
                }
 
3624
                __finally4:
 
3625
                if (_inner_error_ != NULL) {
 
3626
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
3627
                        g_clear_error (&_inner_error_);
 
3628
                        return;
 
3629
                }
 
3630
        }
 
3631
        gtk_widget_destroy ((GtkWidget*) self->priv->save_dialog);
 
3632
        _g_object_unref0 (self->priv->save_dialog);
 
3633
        self->priv->save_dialog = NULL;
 
3634
        _g_object_unref0 (self->priv->save_dialog_info_bar);
 
3635
        self->priv->save_dialog_info_bar = NULL;
 
3636
        _g_object_unref0 (self->priv->save_dialog_error_label);
 
3637
        self->priv->save_dialog_error_label = NULL;
 
3638
}
 
3639
 
 
3640
 
 
3641
static void _application_open_file_cb_gtk_file_chooser_file_activated (GtkFileChooser* _sender, gpointer self) {
 
3642
        application_open_file_cb (self);
 
3643
}
 
3644
 
 
3645
 
 
3646
static void _application_open_cb_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self) {
 
3647
        application_open_cb (self, response_id);
 
3648
}
 
3649
 
 
3650
 
 
3651
void G_MODULE_EXPORT open_game_cb (GtkWidget* widget, Application* self) {
 
3652
        const gchar* _tmp0_ = NULL;
 
3653
        GtkFileChooserDialog* _tmp1_ = NULL;
 
3654
        GtkInfoBar* _tmp2_ = NULL;
 
3655
        GtkLabel* _tmp3_ = NULL;
 
3656
        GtkFileFilter* _tmp4_ = NULL;
 
3657
        GtkFileFilter* pgn_filter;
 
3658
        const gchar* _tmp5_ = NULL;
 
3659
        GtkFileFilter* _tmp6_ = NULL;
 
3660
        GtkFileFilter* all_filter;
 
3661
        const gchar* _tmp7_ = NULL;
 
3662
        g_return_if_fail (self != NULL);
 
3663
        g_return_if_fail (widget != NULL);
 
3664
        if (self->priv->open_dialog != NULL) {
 
3665
                gtk_window_present ((GtkWindow*) self->priv->open_dialog);
 
3666
                return;
 
3667
        }
 
3668
        _tmp0_ = _ ("Load Chess Game");
 
3669
        _tmp1_ = (GtkFileChooserDialog*) gtk_file_chooser_dialog_new (_tmp0_, self->priv->window, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL, NULL);
 
3670
        _g_object_unref0 (self->priv->open_dialog);
 
3671
        self->priv->open_dialog = g_object_ref_sink (_tmp1_);
 
3672
        application_add_info_bar_to_dialog (self, (GtkDialog*) self->priv->open_dialog, &_tmp2_, &_tmp3_);
 
3673
        _g_object_unref0 (self->priv->open_dialog_info_bar);
 
3674
        self->priv->open_dialog_info_bar = _tmp2_;
 
3675
        _g_object_unref0 (self->priv->open_dialog_error_label);
 
3676
        self->priv->open_dialog_error_label = _tmp3_;
 
3677
        g_signal_connect ((GtkFileChooser*) self->priv->open_dialog, "file-activated", (GCallback) _application_open_file_cb_gtk_file_chooser_file_activated, self);
 
3678
        g_signal_connect ((GtkDialog*) self->priv->open_dialog, "response", (GCallback) _application_open_cb_gtk_dialog_response, self);
 
3679
        _tmp4_ = gtk_file_filter_new ();
 
3680
        pgn_filter = g_object_ref_sink (_tmp4_);
 
3681
        _tmp5_ = _ ("PGN files");
 
3682
        gtk_file_filter_set_name (pgn_filter, _tmp5_);
 
3683
        gtk_file_filter_add_pattern (pgn_filter, "*.pgn");
 
3684
        gtk_file_chooser_add_filter ((GtkFileChooser*) self->priv->open_dialog, pgn_filter);
 
3685
        _tmp6_ = gtk_file_filter_new ();
 
3686
        all_filter = g_object_ref_sink (_tmp6_);
 
3687
        _tmp7_ = _ ("All files");
 
3688
        gtk_file_filter_set_name (all_filter, _tmp7_);
 
3689
        gtk_file_filter_add_pattern (all_filter, "*");
 
3690
        gtk_file_chooser_add_filter ((GtkFileChooser*) self->priv->open_dialog, all_filter);
 
3691
        gtk_window_present ((GtkWindow*) self->priv->open_dialog);
 
3692
        _g_object_unref0 (all_filter);
 
3693
        _g_object_unref0 (pgn_filter);
 
3694
}
 
3695
 
 
3696
 
 
3697
static void application_open_file_cb (Application* self) {
 
3698
        g_return_if_fail (self != NULL);
 
3699
        application_open_cb (self, (gint) GTK_RESPONSE_OK);
 
3700
}
 
3701
 
 
3702
 
 
3703
static void application_open_cb (Application* self, gint response_id) {
 
3704
        GError * _inner_error_ = NULL;
 
3705
        g_return_if_fail (self != NULL);
 
3706
        if (response_id == GTK_RESPONSE_OK) {
 
3707
                GFile* _tmp0_ = NULL;
 
3708
                _tmp0_ = gtk_file_chooser_get_file ((GtkFileChooser*) self->priv->open_dialog);
 
3709
                application_load_game (self, _tmp0_, FALSE, &_inner_error_);
 
3710
                if (_inner_error_ != NULL) {
 
3711
                        goto __catch5_g_error;
 
3712
                }
 
3713
                goto __finally5;
 
3714
                __catch5_g_error:
 
3715
                {
 
3716
                        GError * e;
 
3717
                        const gchar* _tmp1_ = NULL;
 
3718
                        gchar* _tmp2_ = NULL;
 
3719
                        gchar* _tmp3_;
 
3720
                        e = _inner_error_;
 
3721
                        _inner_error_ = NULL;
 
3722
                        _tmp1_ = _ ("Failed to open game: %s");
 
3723
                        _tmp2_ = g_strdup_printf (_tmp1_, e->message);
 
3724
                        _tmp3_ = _tmp2_;
 
3725
                        gtk_label_set_text (self->priv->open_dialog_error_label, _tmp3_);
 
3726
                        _g_free0 (_tmp3_);
 
3727
                        gtk_info_bar_set_message_type (self->priv->open_dialog_info_bar, GTK_MESSAGE_ERROR);
 
3728
                        gtk_widget_show ((GtkWidget*) self->priv->open_dialog_info_bar);
 
3729
                        _g_error_free0 (e);
 
3730
                        return;
 
3731
                }
 
3732
                __finally5:
 
3733
                if (_inner_error_ != NULL) {
 
3734
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
3735
                        g_clear_error (&_inner_error_);
 
3736
                        return;
 
3737
                }
 
3738
        }
 
3739
        gtk_widget_destroy ((GtkWidget*) self->priv->open_dialog);
 
3740
        _g_object_unref0 (self->priv->open_dialog);
 
3741
        self->priv->open_dialog = NULL;
 
3742
        _g_object_unref0 (self->priv->open_dialog_info_bar);
 
3743
        self->priv->open_dialog_info_bar = NULL;
 
3744
        _g_object_unref0 (self->priv->open_dialog_error_label);
 
3745
        self->priv->open_dialog_error_label = NULL;
 
3746
}
 
3747
 
 
3748
 
 
3749
static void application_start_new_game (Application* self) {
 
3750
        PGNGame* _tmp0_ = NULL;
 
3751
        GDateTime* _tmp1_ = NULL;
 
3752
        GDateTime* now;
 
3753
        gchar* _tmp2_ = NULL;
 
3754
        gchar* _tmp3_;
 
3755
        gchar* _tmp4_ = NULL;
 
3756
        gchar* _tmp5_;
 
3757
        gint _tmp6_;
 
3758
        gint duration;
 
3759
        gchar* _tmp9_ = NULL;
 
3760
        gchar* engine_name;
 
3761
        gchar* _tmp10_ = NULL;
 
3762
        gchar* engine_level;
 
3763
        gboolean _tmp11_ = FALSE;
 
3764
        g_return_if_fail (self != NULL);
 
3765
        self->priv->in_history = TRUE;
 
3766
        _g_object_unref0 (self->priv->game_file);
 
3767
        self->priv->game_file = NULL;
 
3768
        _tmp0_ = pgn_game_new ();
 
3769
        _pgn_game_unref0 (self->priv->pgn_game);
 
3770
        self->priv->pgn_game = _tmp0_;
 
3771
        _tmp1_ = g_date_time_new_now_local ();
 
3772
        now = _tmp1_;
 
3773
        _tmp2_ = g_date_time_format (now, "%Y.%m.%d");
 
3774
        _tmp3_ = _tmp2_;
 
3775
        pgn_game_set_date (self->priv->pgn_game, _tmp3_);
 
3776
        _g_free0 (_tmp3_);
 
3777
        _tmp4_ = g_date_time_format (now, "%H:%M:%S");
 
3778
        _tmp5_ = _tmp4_;
 
3779
        pgn_game_set_time (self->priv->pgn_game, _tmp5_);
 
3780
        _g_free0 (_tmp5_);
 
3781
        _tmp6_ = g_settings_get_int (self->priv->settings, "duration");
 
3782
        duration = _tmp6_;
 
3783
        if (duration > 0) {
 
3784
                gchar* _tmp7_ = NULL;
 
3785
                gchar* _tmp8_;
 
3786
                _tmp7_ = g_strdup_printf ("%d", duration);
 
3787
                _tmp8_ = _tmp7_;
 
3788
                pgn_game_set_time_control (self->priv->pgn_game, _tmp8_);
 
3789
                _g_free0 (_tmp8_);
 
3790
        }
 
3791
        _tmp9_ = g_settings_get_string (self->priv->settings, "opponent");
 
3792
        engine_name = _tmp9_;
 
3793
        _tmp10_ = g_settings_get_string (self->priv->settings, "difficulty");
 
3794
        engine_level = _tmp10_;
 
3795
        if (engine_name != NULL) {
 
3796
                _tmp11_ = g_strcmp0 (engine_name, "human") != 0;
 
3797
        } else {
 
3798
                _tmp11_ = FALSE;
 
3799
        }
 
3800
        if (_tmp11_) {
 
3801
                gboolean _tmp12_;
 
3802
                _tmp12_ = g_settings_get_boolean (self->priv->settings, "play-as-white");
 
3803
                if (_tmp12_) {
 
3804
                        gchar* _tmp13_;
 
3805
                        gchar* _tmp14_;
 
3806
                        gchar* _tmp15_;
 
3807
                        gchar* _tmp16_;
 
3808
                        _tmp13_ = g_strdup ("BlackAI");
 
3809
                        _tmp14_ = g_strdup (engine_name);
 
3810
                        g_hash_table_insert (self->priv->pgn_game->tags, _tmp13_, _tmp14_);
 
3811
                        _tmp15_ = g_strdup ("BlackLevel");
 
3812
                        _tmp16_ = g_strdup (engine_level);
 
3813
                        g_hash_table_insert (self->priv->pgn_game->tags, _tmp15_, _tmp16_);
 
3814
                } else {
 
3815
                        gchar* _tmp17_;
 
3816
                        gchar* _tmp18_;
 
3817
                        gchar* _tmp19_;
 
3818
                        gchar* _tmp20_;
 
3819
                        _tmp17_ = g_strdup ("WhiteAI");
 
3820
                        _tmp18_ = g_strdup (engine_name);
 
3821
                        g_hash_table_insert (self->priv->pgn_game->tags, _tmp17_, _tmp18_);
 
3822
                        _tmp19_ = g_strdup ("WhiteLevel");
 
3823
                        _tmp20_ = g_strdup (engine_level);
 
3824
                        g_hash_table_insert (self->priv->pgn_game->tags, _tmp19_, _tmp20_);
 
3825
                }
 
3826
        }
 
3827
        application_start_game (self);
 
3828
        _g_free0 (engine_level);
 
3829
        _g_free0 (engine_name);
 
3830
        _g_date_time_unref0 (now);
 
3831
}
 
3832
 
 
3833
 
 
3834
static gpointer _pgn_game_ref0 (gpointer self) {
 
3835
        return self ? pgn_game_ref (self) : NULL;
 
3836
}
 
3837
 
 
3838
 
 
3839
static void application_load_game (Application* self, GFile* file, gboolean from_history, GError** error) {
 
3840
        PGN* _tmp0_ = NULL;
 
3841
        PGN* pgn;
 
3842
        gconstpointer _tmp1_ = NULL;
 
3843
        PGNGame* _tmp2_;
 
3844
        GFile* _tmp3_;
 
3845
        GError * _inner_error_ = NULL;
 
3846
        g_return_if_fail (self != NULL);
 
3847
        g_return_if_fail (file != NULL);
 
3848
        _tmp0_ = pgn_new_from_file (file, &_inner_error_);
 
3849
        pgn = _tmp0_;
 
3850
        if (_inner_error_ != NULL) {
 
3851
                g_propagate_error (error, _inner_error_);
 
3852
                return;
 
3853
        }
 
3854
        _tmp1_ = g_list_nth_data (pgn->games, (guint) 0);
 
3855
        _tmp2_ = _pgn_game_ref0 ((PGNGame*) _tmp1_);
 
3856
        _pgn_game_unref0 (self->priv->pgn_game);
 
3857
        self->priv->pgn_game = _tmp2_;
 
3858
        _tmp3_ = _g_object_ref0 (file);
 
3859
        _g_object_unref0 (self->priv->game_file);
 
3860
        self->priv->game_file = _tmp3_;
 
3861
        self->priv->in_history = from_history;
 
3862
        application_start_game (self);
 
3863
        _pgn_unref0 (pgn);
 
3864
}
 
3865
 
 
3866
 
 
3867
static void value_application_init (GValue* value) {
 
3868
        value->data[0].v_pointer = NULL;
 
3869
}
 
3870
 
 
3871
 
 
3872
static void value_application_free_value (GValue* value) {
 
3873
        if (value->data[0].v_pointer) {
 
3874
                application_unref (value->data[0].v_pointer);
 
3875
        }
 
3876
}
 
3877
 
 
3878
 
 
3879
static void value_application_copy_value (const GValue* src_value, GValue* dest_value) {
 
3880
        if (src_value->data[0].v_pointer) {
 
3881
                dest_value->data[0].v_pointer = application_ref (src_value->data[0].v_pointer);
 
3882
        } else {
 
3883
                dest_value->data[0].v_pointer = NULL;
 
3884
        }
 
3885
}
 
3886
 
 
3887
 
 
3888
static gpointer value_application_peek_pointer (const GValue* value) {
 
3889
        return value->data[0].v_pointer;
 
3890
}
 
3891
 
 
3892
 
 
3893
static gchar* value_application_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
 
3894
        if (collect_values[0].v_pointer) {
 
3895
                Application* object;
 
3896
                object = collect_values[0].v_pointer;
 
3897
                if (object->parent_instance.g_class == NULL) {
 
3898
                        return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
 
3899
                } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
 
3900
                        return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
 
3901
                }
 
3902
                value->data[0].v_pointer = application_ref (object);
 
3903
        } else {
 
3904
                value->data[0].v_pointer = NULL;
 
3905
        }
 
3906
        return NULL;
 
3907
}
 
3908
 
 
3909
 
 
3910
static gchar* value_application_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
 
3911
        Application** object_p;
 
3912
        object_p = collect_values[0].v_pointer;
 
3913
        if (!object_p) {
 
3914
                return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
 
3915
        }
 
3916
        if (!value->data[0].v_pointer) {
 
3917
                *object_p = NULL;
 
3918
        } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
 
3919
                *object_p = value->data[0].v_pointer;
 
3920
        } else {
 
3921
                *object_p = application_ref (value->data[0].v_pointer);
 
3922
        }
 
3923
        return NULL;
 
3924
}
 
3925
 
 
3926
 
 
3927
GParamSpec* param_spec_application (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
 
3928
        ParamSpecApplication* spec;
 
3929
        g_return_val_if_fail (g_type_is_a (object_type, TYPE_APPLICATION), NULL);
 
3930
        spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
 
3931
        G_PARAM_SPEC (spec)->value_type = object_type;
 
3932
        return G_PARAM_SPEC (spec);
 
3933
}
 
3934
 
 
3935
 
 
3936
gpointer value_get_application (const GValue* value) {
 
3937
        g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION), NULL);
 
3938
        return value->data[0].v_pointer;
 
3939
}
 
3940
 
 
3941
 
 
3942
void value_set_application (GValue* value, gpointer v_object) {
 
3943
        Application* old;
 
3944
        g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION));
 
3945
        old = value->data[0].v_pointer;
 
3946
        if (v_object) {
 
3947
                g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_APPLICATION));
 
3948
                g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
 
3949
                value->data[0].v_pointer = v_object;
 
3950
                application_ref (value->data[0].v_pointer);
 
3951
        } else {
 
3952
                value->data[0].v_pointer = NULL;
 
3953
        }
 
3954
        if (old) {
 
3955
                application_unref (old);
 
3956
        }
 
3957
}
 
3958
 
 
3959
 
 
3960
void value_take_application (GValue* value, gpointer v_object) {
 
3961
        Application* old;
 
3962
        g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION));
 
3963
        old = value->data[0].v_pointer;
 
3964
        if (v_object) {
 
3965
                g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_APPLICATION));
 
3966
                g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
 
3967
                value->data[0].v_pointer = v_object;
 
3968
        } else {
 
3969
                value->data[0].v_pointer = NULL;
 
3970
        }
 
3971
        if (old) {
 
3972
                application_unref (old);
 
3973
        }
 
3974
}
 
3975
 
 
3976
 
 
3977
static void application_class_init (ApplicationClass * klass) {
 
3978
        application_parent_class = g_type_class_peek_parent (klass);
 
3979
        APPLICATION_CLASS (klass)->finalize = application_finalize;
 
3980
        g_type_class_add_private (klass, sizeof (ApplicationPrivate));
 
3981
}
 
3982
 
 
3983
 
 
3984
static void application_instance_init (Application * self) {
 
3985
        self->priv = APPLICATION_GET_PRIVATE (self);
 
3986
        self->priv->preferences_dialog = NULL;
 
3987
        self->priv->save_duration_timeout = (guint) 0;
 
3988
        self->priv->open_dialog = NULL;
 
3989
        self->priv->open_dialog_info_bar = NULL;
 
3990
        self->priv->open_dialog_error_label = NULL;
 
3991
        self->priv->save_dialog = NULL;
 
3992
        self->priv->save_dialog_info_bar = NULL;
 
3993
        self->priv->save_dialog_error_label = NULL;
 
3994
        self->priv->about_dialog = NULL;
 
3995
        self->priv->opponent = NULL;
 
3996
        self->priv->human_player = NULL;
 
3997
        self->priv->opponent_engine = NULL;
 
3998
        self->ref_count = 1;
 
3999
}
 
4000
 
 
4001
 
 
4002
static void application_finalize (Application* obj) {
 
4003
        Application * self;
 
4004
        self = APPLICATION (obj);
 
4005
        _g_object_unref0 (self->priv->settings);
 
4006
        _history_unref0 (self->priv->history);
 
4007
        _g_object_unref0 (self->priv->builder);
 
4008
        _g_object_unref0 (self->priv->preferences_builder);
 
4009
        _g_object_unref0 (self->priv->window);
 
4010
        _g_object_unref0 (self->priv->save_menu);
 
4011
        _g_object_unref0 (self->priv->save_as_menu);
 
4012
        _g_object_unref0 (self->priv->fullscreen_menu);
 
4013
        _g_object_unref0 (self->priv->info_bar);
 
4014
        _g_object_unref0 (self->priv->info_title_label);
 
4015
        _g_object_unref0 (self->priv->info_label);
 
4016
        _g_object_unref0 (self->priv->view_container);
 
4017
        _g_object_unref0 (self->priv->scene);
 
4018
        _g_object_unref0 (self->priv->view);
 
4019
        _g_object_unref0 (self->priv->undo_menu);
 
4020
        _g_object_unref0 (self->priv->undo_button);
 
4021
        _g_object_unref0 (self->priv->resign_menu);
 
4022
        _g_object_unref0 (self->priv->resign_button);
 
4023
        _g_object_unref0 (self->priv->first_move_button);
 
4024
        _g_object_unref0 (self->priv->prev_move_button);
 
4025
        _g_object_unref0 (self->priv->next_move_button);
 
4026
        _g_object_unref0 (self->priv->last_move_button);
 
4027
        _g_object_unref0 (self->priv->history_combo);
 
4028
        _g_object_unref0 (self->priv->white_time_label);
 
4029
        _g_object_unref0 (self->priv->black_time_label);
 
4030
        _g_object_unref0 (self->priv->preferences_dialog);
 
4031
        _g_object_unref0 (self->priv->duration_combo);
 
4032
        _g_object_unref0 (self->priv->duration_adjustment);
 
4033
        _g_object_unref0 (self->priv->custom_duration_box);
 
4034
        _g_object_unref0 (self->priv->custom_duration_units_combo);
 
4035
        _g_object_unref0 (self->priv->open_dialog);
 
4036
        _g_object_unref0 (self->priv->open_dialog_info_bar);
 
4037
        _g_object_unref0 (self->priv->open_dialog_error_label);
 
4038
        _g_object_unref0 (self->priv->save_dialog);
 
4039
        _g_object_unref0 (self->priv->save_dialog_info_bar);
 
4040
        _g_object_unref0 (self->priv->save_dialog_error_label);
 
4041
        _g_object_unref0 (self->priv->about_dialog);
 
4042
        _pgn_game_unref0 (self->priv->pgn_game);
 
4043
        _chess_game_unref0 (self->priv->game);
 
4044
        _g_object_unref0 (self->priv->game_file);
 
4045
        __g_list_free__ai_profile_unref0_0 (self->priv->ai_profiles);
 
4046
        _g_object_unref0 (self->priv->opponent);
 
4047
        _g_object_unref0 (self->priv->human_player);
 
4048
        _g_object_unref0 (self->priv->opponent_engine);
 
4049
}
 
4050
 
 
4051
 
 
4052
GType application_get_type (void) {
 
4053
        static volatile gsize application_type_id__volatile = 0;
 
4054
        if (g_once_init_enter (&application_type_id__volatile)) {
 
4055
                static const GTypeValueTable g_define_type_value_table = { value_application_init, value_application_free_value, value_application_copy_value, value_application_peek_pointer, "p", value_application_collect_value, "p", value_application_lcopy_value };
 
4056
                static const GTypeInfo g_define_type_info = { sizeof (ApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Application), 0, (GInstanceInitFunc) application_instance_init, &g_define_type_value_table };
 
4057
                static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
 
4058
                GType application_type_id;
 
4059
                application_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Application", &g_define_type_info, &g_define_type_fundamental_info, 0);
 
4060
                g_once_init_leave (&application_type_id__volatile, application_type_id);
 
4061
        }
 
4062
        return application_type_id__volatile;
 
4063
}
 
4064
 
 
4065
 
 
4066
gpointer application_ref (gpointer instance) {
 
4067
        Application* self;
 
4068
        self = instance;
 
4069
        g_atomic_int_inc (&self->ref_count);
 
4070
        return instance;
 
4071
}
 
4072
 
 
4073
 
 
4074
void application_unref (gpointer instance) {
 
4075
        Application* self;
 
4076
        self = instance;
 
4077
        if (g_atomic_int_dec_and_test (&self->ref_count)) {
 
4078
                APPLICATION_GET_CLASS (self)->finalize (self);
 
4079
                g_type_free_instance ((GTypeInstance *) self);
 
4080
        }
 
4081
}
 
4082
 
 
4083
 
 
4084
gint gl_chess_main (gchar** args, int args_length1) {
 
4085
        gint result = 0;
 
4086
        GFile* game_file;
 
4087
        Application* _tmp6_ = NULL;
 
4088
        Application* app;
 
4089
        GError * _inner_error_ = NULL;
 
4090
        setlocale (LC_ALL, "");
 
4091
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
 
4092
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
4093
        textdomain (GETTEXT_PACKAGE);
 
4094
        gtk_init (&args_length1, &args);
 
4095
        game_file = NULL;
 
4096
        {
 
4097
                gint i;
 
4098
                i = 1;
 
4099
                {
 
4100
                        gboolean _tmp0_;
 
4101
                        _tmp0_ = TRUE;
 
4102
                        while (TRUE) {
 
4103
                                const gchar* _tmp1_;
 
4104
                                GQuark _tmp2_;
 
4105
                                static GQuark _tmp2__label0 = 0;
 
4106
                                static GQuark _tmp2__label1 = 0;
 
4107
                                static GQuark _tmp2__label2 = 0;
 
4108
                                static GQuark _tmp2__label3 = 0;
 
4109
                                static GQuark _tmp2__label4 = 0;
 
4110
                                static GQuark _tmp2__label5 = 0;
 
4111
                                static GQuark _tmp2__label6 = 0;
 
4112
                                if (!_tmp0_) {
 
4113
                                        i++;
 
4114
                                }
 
4115
                                _tmp0_ = FALSE;
 
4116
                                if (!(i < args_length1)) {
 
4117
                                        break;
 
4118
                                }
 
4119
                                _tmp1_ = args[i];
 
4120
                                _tmp2_ = (NULL == _tmp1_) ? 0 : g_quark_from_string (_tmp1_);
 
4121
                                if ((_tmp2_ == ((0 != _tmp2__label0) ? _tmp2__label0 : (_tmp2__label0 = g_quark_from_static_string ("-v")))) || (_tmp2_ == ((0 != _tmp2__label1) ? _tmp2__label1 : (_tmp2__label1 = g_quark_from_static_string ("--version"))))) {
 
4122
                                        switch (0) {
 
4123
                                                default:
 
4124
                                                {
 
4125
                                                        fprintf (stderr, "glchess %s\n", VERSION);
 
4126
                                                        result = EXIT_SUCCESS;
 
4127
                                                        _g_object_unref0 (game_file);
 
4128
                                                        return result;
 
4129
                                                }
 
4130
                                        }
 
4131
                                } else if (((_tmp2_ == ((0 != _tmp2__label2) ? _tmp2__label2 : (_tmp2__label2 = g_quark_from_static_string ("-h")))) || (_tmp2_ == ((0 != _tmp2__label3) ? _tmp2__label3 : (_tmp2__label3 = g_quark_from_static_string ("-?"))))) || (_tmp2_ == ((0 != _tmp2__label4) ? _tmp2__label4 : (_tmp2__label4 = g_quark_from_static_string ("--help"))))) {
 
4132
                                        switch (0) {
 
4133
                                                default:
 
4134
                                                {
 
4135
                                                        gl_chess_usage (args[0], FALSE, TRUE);
 
4136
                                                        result = EXIT_SUCCESS;
 
4137
                                                        _g_object_unref0 (game_file);
 
4138
                                                        return result;
 
4139
                                                }
 
4140
                                        }
 
4141
                                } else if (_tmp2_ == ((0 != _tmp2__label5) ? _tmp2__label5 : (_tmp2__label5 = g_quark_from_static_string ("--help-gtk")))) {
 
4142
                                        switch (0) {
 
4143
                                                default:
 
4144
                                                {
 
4145
                                                        gl_chess_usage (args[0], TRUE, FALSE);
 
4146
                                                        result = EXIT_SUCCESS;
 
4147
                                                        _g_object_unref0 (game_file);
 
4148
                                                        return result;
 
4149
                                                }
 
4150
                                        }
 
4151
                                } else if (_tmp2_ == ((0 != _tmp2__label6) ? _tmp2__label6 : (_tmp2__label6 = g_quark_from_static_string ("--help-all")))) {
 
4152
                                        switch (0) {
 
4153
                                                default:
 
4154
                                                {
 
4155
                                                        gl_chess_usage (args[0], TRUE, TRUE);
 
4156
                                                        result = EXIT_SUCCESS;
 
4157
                                                        _g_object_unref0 (game_file);
 
4158
                                                        return result;
 
4159
                                                }
 
4160
                                        }
 
4161
                                } else {
 
4162
                                        switch (0) {
 
4163
                                                default:
 
4164
                                                {
 
4165
                                                        gboolean _tmp3_ = FALSE;
 
4166
                                                        if (game_file == NULL) {
 
4167
                                                                gboolean _tmp4_;
 
4168
                                                                _tmp4_ = g_str_has_prefix (args[i], "-");
 
4169
                                                                _tmp3_ = !_tmp4_;
 
4170
                                                        } else {
 
4171
                                                                _tmp3_ = FALSE;
 
4172
                                                        }
 
4173
                                                        if (_tmp3_) {
 
4174
                                                                GFile* _tmp5_ = NULL;
 
4175
                                                                _tmp5_ = g_file_new_for_path (args[i]);
 
4176
                                                                _g_object_unref0 (game_file);
 
4177
                                                                game_file = _tmp5_;
 
4178
                                                        } else {
 
4179
                                                                fprintf (stderr, "Unknown argument '%s'\n", args[i]);
 
4180
                                                                fprintf (stderr, "Run '%s --help' to see a full list of available command line options.\n", args[0]);
 
4181
                                                                result = EXIT_FAILURE;
 
4182
                                                                _g_object_unref0 (game_file);
 
4183
                                                                return result;
 
4184
                                                        }
 
4185
                                                        break;
 
4186
                                                }
 
4187
                                        }
 
4188
                                }
 
4189
                        }
 
4190
                }
 
4191
        }
 
4192
        _tmp6_ = application_new ();
 
4193
        app = _tmp6_;
 
4194
        application_start (app, game_file, &_inner_error_);
 
4195
        if (_inner_error_ != NULL) {
 
4196
                goto __catch6_g_error;
 
4197
        }
 
4198
        goto __finally6;
 
4199
        __catch6_g_error:
 
4200
        {
 
4201
                GError * e;
 
4202
                gchar* _tmp7_ = NULL;
 
4203
                gchar* _tmp8_;
 
4204
                e = _inner_error_;
 
4205
                _inner_error_ = NULL;
 
4206
                _tmp7_ = g_file_get_path (game_file);
 
4207
                _tmp8_ = _tmp7_;
 
4208
                fprintf (stderr, "Failed to load %s: %s\n", _tmp8_, e->message);
 
4209
                _g_free0 (_tmp8_);
 
4210
                result = EXIT_FAILURE;
 
4211
                _g_error_free0 (e);
 
4212
                _application_unref0 (app);
 
4213
                _g_object_unref0 (game_file);
 
4214
                return result;
 
4215
        }
 
4216
        __finally6:
 
4217
        if (_inner_error_ != NULL) {
 
4218
                _application_unref0 (app);
 
4219
                _g_object_unref0 (game_file);
 
4220
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
4221
                g_clear_error (&_inner_error_);
 
4222
                return 0;
 
4223
        }
 
4224
        gtk_main ();
 
4225
        result = EXIT_SUCCESS;
 
4226
        _application_unref0 (app);
 
4227
        _g_object_unref0 (game_file);
 
4228
        return result;
 
4229
}
 
4230
 
 
4231
 
 
4232
int main (int argc, char ** argv) {
 
4233
        g_type_init ();
 
4234
        return gl_chess_main (argv, argc);
 
4235
}
 
4236
 
 
4237
 
 
4238
void gl_chess_usage (const gchar* appname, gboolean show_gtk, gboolean show_application) {
 
4239
        g_return_if_fail (appname != NULL);
 
4240
        fprintf (stderr, "Usage:\n" "  %s [OPTIONS...] [FILE] - Play Chess", appname);
 
4241
        fprintf (stderr, "\n\n");
 
4242
        fprintf (stderr, "%s", "Help Options:\n" "  -h, -?, --help                  Show help options\n" "  --help-all                      Show all help options\n" "  --help-gtk                      Show GTK+ options");
 
4243
        fprintf (stderr, "\n\n");
 
4244
        if (show_gtk) {
 
4245
                fprintf (stderr, "%s", "GTK+ Options:\n" "  --class=CLASS                   Program class as used by the window " \
 
4246
"manager\n" "  --name=NAME                     Program name as used by the window m" \
 
4247
"anager\n" "  --screen=SCREEN                 X screen to use\n" "  --sync                          Make X calls synchronous\n" "  --gtk-module=MODULES            Load additional GTK+ modules\n" "  --g-fatal-warnings              Make all warnings fatal");
 
4248
                fprintf (stderr, "\n\n");
 
4249
        }
 
4250
        if (show_application) {
 
4251
                fprintf (stderr, "%s", "Application Options:\n" "  -v, --version                   Show release version");
 
4252
                fprintf (stderr, "\n\n");
 
4253
        }
 
4254
}
 
4255
 
 
4256
 
 
4257
GlChess* gl_chess_construct (GType object_type) {
 
4258
        GlChess* self = NULL;
 
4259
        self = (GlChess*) g_type_create_instance (object_type);
 
4260
        return self;
 
4261
}
 
4262
 
 
4263
 
 
4264
GlChess* gl_chess_new (void) {
 
4265
        return gl_chess_construct (TYPE_GL_CHESS);
 
4266
}
 
4267
 
 
4268
 
 
4269
static void value_gl_chess_init (GValue* value) {
 
4270
        value->data[0].v_pointer = NULL;
 
4271
}
 
4272
 
 
4273
 
 
4274
static void value_gl_chess_free_value (GValue* value) {
 
4275
        if (value->data[0].v_pointer) {
 
4276
                gl_chess_unref (value->data[0].v_pointer);
 
4277
        }
 
4278
}
 
4279
 
 
4280
 
 
4281
static void value_gl_chess_copy_value (const GValue* src_value, GValue* dest_value) {
 
4282
        if (src_value->data[0].v_pointer) {
 
4283
                dest_value->data[0].v_pointer = gl_chess_ref (src_value->data[0].v_pointer);
 
4284
        } else {
 
4285
                dest_value->data[0].v_pointer = NULL;
 
4286
        }
 
4287
}
 
4288
 
 
4289
 
 
4290
static gpointer value_gl_chess_peek_pointer (const GValue* value) {
 
4291
        return value->data[0].v_pointer;
 
4292
}
 
4293
 
 
4294
 
 
4295
static gchar* value_gl_chess_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
 
4296
        if (collect_values[0].v_pointer) {
 
4297
                GlChess* object;
 
4298
                object = collect_values[0].v_pointer;
 
4299
                if (object->parent_instance.g_class == NULL) {
 
4300
                        return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
 
4301
                } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
 
4302
                        return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
 
4303
                }
 
4304
                value->data[0].v_pointer = gl_chess_ref (object);
 
4305
        } else {
 
4306
                value->data[0].v_pointer = NULL;
 
4307
        }
 
4308
        return NULL;
 
4309
}
 
4310
 
 
4311
 
 
4312
static gchar* value_gl_chess_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
 
4313
        GlChess** object_p;
 
4314
        object_p = collect_values[0].v_pointer;
 
4315
        if (!object_p) {
 
4316
                return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
 
4317
        }
 
4318
        if (!value->data[0].v_pointer) {
 
4319
                *object_p = NULL;
 
4320
        } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
 
4321
                *object_p = value->data[0].v_pointer;
 
4322
        } else {
 
4323
                *object_p = gl_chess_ref (value->data[0].v_pointer);
 
4324
        }
 
4325
        return NULL;
 
4326
}
 
4327
 
 
4328
 
 
4329
GParamSpec* param_spec_gl_chess (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
 
4330
        ParamSpecGlChess* spec;
 
4331
        g_return_val_if_fail (g_type_is_a (object_type, TYPE_GL_CHESS), NULL);
 
4332
        spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
 
4333
        G_PARAM_SPEC (spec)->value_type = object_type;
 
4334
        return G_PARAM_SPEC (spec);
 
4335
}
 
4336
 
 
4337
 
 
4338
gpointer value_get_gl_chess (const GValue* value) {
 
4339
        g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_GL_CHESS), NULL);
 
4340
        return value->data[0].v_pointer;
 
4341
}
 
4342
 
 
4343
 
 
4344
void value_set_gl_chess (GValue* value, gpointer v_object) {
 
4345
        GlChess* old;
 
4346
        g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_GL_CHESS));
 
4347
        old = value->data[0].v_pointer;
 
4348
        if (v_object) {
 
4349
                g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_GL_CHESS));
 
4350
                g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
 
4351
                value->data[0].v_pointer = v_object;
 
4352
                gl_chess_ref (value->data[0].v_pointer);
 
4353
        } else {
 
4354
                value->data[0].v_pointer = NULL;
 
4355
        }
 
4356
        if (old) {
 
4357
                gl_chess_unref (old);
 
4358
        }
 
4359
}
 
4360
 
 
4361
 
 
4362
void value_take_gl_chess (GValue* value, gpointer v_object) {
 
4363
        GlChess* old;
 
4364
        g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_GL_CHESS));
 
4365
        old = value->data[0].v_pointer;
 
4366
        if (v_object) {
 
4367
                g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_GL_CHESS));
 
4368
                g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
 
4369
                value->data[0].v_pointer = v_object;
 
4370
        } else {
 
4371
                value->data[0].v_pointer = NULL;
 
4372
        }
 
4373
        if (old) {
 
4374
                gl_chess_unref (old);
 
4375
        }
 
4376
}
 
4377
 
 
4378
 
 
4379
static void gl_chess_class_init (GlChessClass * klass) {
 
4380
        gl_chess_parent_class = g_type_class_peek_parent (klass);
 
4381
        GL_CHESS_CLASS (klass)->finalize = gl_chess_finalize;
 
4382
}
 
4383
 
 
4384
 
 
4385
static void gl_chess_instance_init (GlChess * self) {
 
4386
        self->ref_count = 1;
 
4387
}
 
4388
 
 
4389
 
 
4390
static void gl_chess_finalize (GlChess* obj) {
 
4391
        GlChess * self;
 
4392
        self = GL_CHESS (obj);
 
4393
}
 
4394
 
 
4395
 
 
4396
GType gl_chess_get_type (void) {
 
4397
        static volatile gsize gl_chess_type_id__volatile = 0;
 
4398
        if (g_once_init_enter (&gl_chess_type_id__volatile)) {
 
4399
                static const GTypeValueTable g_define_type_value_table = { value_gl_chess_init, value_gl_chess_free_value, value_gl_chess_copy_value, value_gl_chess_peek_pointer, "p", value_gl_chess_collect_value, "p", value_gl_chess_lcopy_value };
 
4400
                static const GTypeInfo g_define_type_info = { sizeof (GlChessClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gl_chess_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GlChess), 0, (GInstanceInitFunc) gl_chess_instance_init, &g_define_type_value_table };
 
4401
                static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
 
4402
                GType gl_chess_type_id;
 
4403
                gl_chess_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GlChess", &g_define_type_info, &g_define_type_fundamental_info, 0);
 
4404
                g_once_init_leave (&gl_chess_type_id__volatile, gl_chess_type_id);
 
4405
        }
 
4406
        return gl_chess_type_id__volatile;
 
4407
}
 
4408
 
 
4409
 
 
4410
gpointer gl_chess_ref (gpointer instance) {
 
4411
        GlChess* self;
 
4412
        self = instance;
 
4413
        g_atomic_int_inc (&self->ref_count);
 
4414
        return instance;
 
4415
}
 
4416
 
 
4417
 
 
4418
void gl_chess_unref (gpointer instance) {
 
4419
        GlChess* self;
 
4420
        self = instance;
 
4421
        if (g_atomic_int_dec_and_test (&self->ref_count)) {
 
4422
                GL_CHESS_GET_CLASS (self)->finalize (self);
 
4423
                g_type_free_instance ((GTypeInstance *) self);
 
4424
        }
 
4425
}
 
4426
 
 
4427
 
 
4428
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
 
4429
        if ((array != NULL) && (destroy_func != NULL)) {
 
4430
                int i;
 
4431
                for (i = 0; i < array_length; i = i + 1) {
 
4432
                        if (((gpointer*) array)[i] != NULL) {
 
4433
                                destroy_func (((gpointer*) array)[i]);
 
4434
                        }
 
4435
                }
 
4436
        }
 
4437
}
 
4438
 
 
4439
 
 
4440
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
 
4441
        _vala_array_destroy (array, array_length, destroy_func);
 
4442
        g_free (array);
 
4443
}
 
4444
 
 
4445
 
 
4446
static gint _vala_array_length (gpointer array) {
 
4447
        int length;
 
4448
        length = 0;
 
4449
        if (array) {
 
4450
                while (((gpointer*) array)[length]) {
 
4451
                        length++;
 
4452
                }
 
4453
        }
 
4454
        return length;
 
4455
}
 
4456
 
 
4457
 
 
4458