2 * This file is part of DrNokSnes
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>
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.
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.
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
27 #include <libgnomevfs/gnome-vfs-uri.h>
28 #include <libgnomevfs/gnome-vfs-utils.h>
29 #include <libgnomevfs/gnome-vfs-ops.h>
30 #include <libgnomevfs/gnome-vfs-xfer.h>
31 #include <hildon/hildon-file-chooser-dialog.h>
32 #include <hildon/hildon-banner.h>
36 static gchar * cur_save_uri = NULL;
38 // Pulling nearly all of gnomevfs just to copy a file. *sigh*.
39 static GnomeVFSResult copy_file(const char * source_uri, const char * dest_uri)
41 GnomeVFSURI* src = gnome_vfs_uri_new(source_uri);
42 GnomeVFSURI* dst = gnome_vfs_uri_new(dest_uri);
45 res = gnome_vfs_xfer_uri(src, dst,
46 GNOME_VFS_XFER_TARGET_DEFAULT_PERMS,
47 GNOME_VFS_XFER_ERROR_MODE_ABORT,
48 GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
51 gnome_vfs_uri_unref(src);
52 gnome_vfs_uri_unref(dst);
57 static gboolean show_result(GnomeVFSResult res, GtkWindow* parent, const char* msg)
59 if (res == GNOME_VFS_OK) {
60 hildon_banner_show_information(GTK_WIDGET(parent), NULL, msg);
63 hildon_banner_show_information(GTK_WIDGET(parent), NULL, "Failed");
76 static gchar * show_dialog(GtkWindow* parent, GtkFileChooserAction action)
79 GtkFileFilter * filter;
82 filter = gtk_file_filter_new();
83 gtk_file_filter_add_pattern(filter, "*.snsg");
85 dialog = hildon_file_chooser_dialog_new_with_properties(GTK_WINDOW(parent),
86 "action", action, "local-only", FALSE, "filter", filter, NULL);
88 hildon_file_chooser_dialog_set_extension(HILDON_FILE_CHOOSER_DIALOG(dialog),
92 gchar * games_dir = g_strdup_printf("%s/.games", g_getenv("MYDOCSDIR"));
93 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), games_dir);
98 gtk_widget_show_all(GTK_WIDGET(dialog));
99 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
100 uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
103 gtk_widget_destroy(dialog);
108 void save_load(GtkWindow* parent)
110 gchar * uri = show_dialog(parent, GTK_FILE_CHOOSER_ACTION_OPEN);
113 const gchar * frz_file = game_state_get_frz_file();
114 gchar * frz_uri = gnome_vfs_get_uri_from_local_path(frz_file);
115 show_result(copy_file(uri, frz_uri), parent, "Game loaded");
120 g_free(cur_save_uri);
125 void save_save(GtkWindow* parent)
128 const gchar * frz_file = game_state_get_frz_file();
129 gchar * frz_uri = gnome_vfs_get_uri_from_local_path(frz_file);
130 show_result(copy_file(frz_uri, cur_save_uri), parent, "Game saved");
133 save_save_as(parent);
137 void save_save_as(GtkWindow* parent)
139 gchar * uri = show_dialog(parent, GTK_FILE_CHOOSER_ACTION_SAVE);
142 const gchar * frz_file = game_state_get_frz_file();
143 gchar * frz_uri = gnome_vfs_get_uri_from_local_path(frz_file);
144 gboolean res = show_result(copy_file(frz_uri, uri), parent, "Game saved");
150 g_free(cur_save_uri);