new developer release
[xboard.git] / interface.c
1 /*
2  * interface.c -- gtk-interface
3  *
4  * Copyright 2009, 2010 Free Software Foundation, Inc.
5  *
6  * GNU XBoard is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or (at
9  * your option) any later version.
10  *
11  * GNU XBoard is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://www.gnu.org/licenses/.  *
18  *
19  *------------------------------------------------------------------------
20  ** See the file ChangeLog for a revision history.  */
21
22 #include "config.h"
23
24 #include <stdio.h>
25 #include <ctype.h>
26 #include <signal.h>
27 #include <errno.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <pwd.h>
31
32 #include <gtk/gtk.h>
33 #include <gdk-pixbuf/gdk-pixbuf.h>
34
35 #include "common.h"
36 #include "frontend.h"
37 #include "backend.h"
38 #include "moves.h"
39 #include "xboard.h"
40 #include "childio.h"
41 #include "xgamelist.h"
42 #include "xhistory.h"
43 #include "xedittags.h"
44 #include "gettext.h"
45 #include "callback.h"
46
47 #ifdef ENABLE_NLS
48 # define  _(s) gettext (s)
49 # define N_(s) gettext_noop (s)
50 #else
51 # define  _(s) (s)
52 # define N_(s)  s
53 #endif
54
55 extern GtkWidget *GUI_Window;
56
57
58 GdkPixbuf *load_pixbuf(char *filename,int size)
59 {
60   GdkPixbuf *image;
61
62   if(size)
63     image = gdk_pixbuf_new_from_file_at_size(filename,size,size,NULL);
64   else
65     image = gdk_pixbuf_new_from_file(filename,NULL);
66   
67   if(image == NULL)
68     {
69       fprintf(stderr,_("Error: couldn't load file: %s\n"),filename);
70       exit(1);
71     }
72   return image;
73 }
74
75 void
76 FileNamePopUp(label, def, proc, openMode)
77      char *label;
78      char *def;
79      FileProc proc;
80      char *openMode;
81 {
82   /* TODO:
83    *   implement look for certain file types
84    *   use save/load button depending on what function is calling
85    */
86
87   GtkWidget *dialog;
88
89   dialog = gtk_file_chooser_dialog_new (label,
90                                         GTK_WINDOW(GUI_Window),
91                                         GTK_FILE_CHOOSER_ACTION_OPEN,
92                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
93                                         GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
94                                         NULL);
95   if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
96     {
97       char *filename;
98       FILE *f;
99
100       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
101
102       //see loadgamepopup
103       f = fopen(filename, openMode);
104       if (f == NULL) 
105         {
106           DisplayError(_("Failed to open file"), errno);
107         }
108       else 
109         {
110           /* TODO add indec */
111           (*proc)(f, 0, filename);
112         }
113       g_free (filename);
114     };
115   
116   gtk_widget_destroy (dialog);
117   ModeHighlight();
118   
119   return;
120
121 }