b026d95ba11f98e53f025db9501b4084c6c58289
[drnoksnes] / gui / save.c
1 /*
2 * This file is part of DrNokSnes
3 *
4 * Copyright (C) 2005 INdT - Instituto Nokia de Tecnologia
5 * http://www.indt.org/maemo
6 * Copyright (C) 2009 Javier S. Pedro <maemo@javispedro.com>
7 *
8 * This software is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This software is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this software; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25 #include <string.h>
26 #include <glib.h>
27 #include <hildon/hildon-file-chooser-dialog.h>
28
29 #include "plugin.h"
30
31 static gchar * cur_save_filename = NULL;
32
33 void save_clear()
34 {
35         if (cur_save_filename) {
36                 g_free(cur_save_filename);
37                 cur_save_filename = NULL;
38         }
39 }
40
41 static gchar * show_dialog(GtkWindow* parent, GtkFileChooserAction action)
42 {
43         GtkWidget * dialog;
44         GtkFileFilter * filter;
45         gchar * filename = NULL;
46
47         filter = gtk_file_filter_new();
48         gtk_file_filter_add_pattern(filter, "*.snsg");
49
50         dialog = hildon_file_chooser_dialog_new_with_properties(GTK_WINDOW(parent), 
51                 "action", action, "filter", filter, NULL);
52
53         // TODO Default path
54
55         gtk_widget_show_all(GTK_WIDGET(dialog));
56         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
57                 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
58         }
59
60         gtk_widget_destroy(dialog);
61
62         return filename;
63 }
64
65 void save_load(GtkWindow* parent)
66 {
67         gchar * filename = show_dialog(parent, GTK_FILE_CHOOSER_ACTION_OPEN);
68         
69         // TODO: Something
70 }
71
72 void save_save(GtkWindow* parent)
73 {
74         if (!cur_save_filename) {
75                 save_save_as(parent);
76         }
77         
78         // TODO: Something again
79 }
80
81 void save_save_as(GtkWindow* parent)
82 {
83         gchar * filename = show_dialog(parent, GTK_FILE_CHOOSER_ACTION_SAVE);
84         
85         // TODO: Something again
86 }
87