-#define _GNU_SOURCE
+/*
+ * This file is part of mapper
+ *
+ * Copyright (C) 2007 Kaj-Michael Lang
+ * Copyright (C) 2006-2007 John Costigan.
+ *
+ * POI and GPS-Info code originally written by Cezary Jackiewicz.
+ *
+ * Default map data provided by http://www.openstreetmap.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
#include <config.h>
#include <gtk/gtk.h>
#include "hildon-mapper.h"
+#include "path.h"
#include "utils.h"
#include "mapper-types.h"
#include "settings.h"
#include "ui-common.h"
#include "hildon-wrappers.h"
+#include "file.h"
/**
* Open a file for reading.
*/
gboolean
-file_open(gchar **dir, gchar **file, gchar *new_file)
+file_open(gchar **dir, gchar **new_file)
{
GtkWidget *dialog;
-gint r;
gboolean success=FALSE;
+GtkFileFilter *filter;
#ifdef WITH_HILDON
dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(_window), GTK_FILE_CHOOSER_ACTION_OPEN);
#else
dialog = gtk_file_chooser_dialog_new("Open...", GTK_WINDOW(_window), GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN,
- GTK_RESPONSE_ACCEPT, NULL);
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN,
+ GTK_RESPONSE_OK, NULL);
#endif
-if (dir && *dir)
- gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(dialog), *dir);
+/* Show .gpx files only */
+filter=gtk_file_filter_new();
+gtk_file_filter_add_pattern(filter, "*.gpx");
+gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
-if (file && *file)
- gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(dialog), *file);
+if (dir && *dir) {
+ gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(dialog), *dir);
+} else {
+ gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(dialog), g_get_home_dir());
+}
-new_file=NULL;
+*new_file=NULL;
-r=gtk_dialog_run(GTK_DIALOG(dialog));
-if (r==GTK_RESPONSE_ACCEPT || r==GTK_RESPONSE_OK) {
+if (gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_OK) {
/* Get the selected filename. */
- new_file = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
- g_printf("file: %s\n", new_file);
+ *new_file = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
+ g_printf("file: %s\n", *new_file);
success=TRUE;
}
file_save(gchar **dir, gchar **file, GnomeVFSHandle **vfs_handle)
{
GtkWidget *dialog;
-gint r;
gboolean success=FALSE;
#ifdef WITH_HILDON
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE,
- GTK_RESPONSE_ACCEPT, NULL);
+ GTK_RESPONSE_OK, NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
#endif
-if (dir && *dir)
+if (dir && *dir) {
gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(dialog), *dir);
+} else {
+ gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(dialog), g_get_home_dir());
+}
-if (file && *file)
+if (file && *file) {
gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(dialog), *file);
+ if (strlen(*file)==0)
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "track.gpx");
+} else
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "track.gpx");
-r=gtk_dialog_run(GTK_DIALOG(dialog));
-if (r==GTK_RESPONSE_ACCEPT || r==GTK_RESPONSE_OK) {
+if (gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_OK) {
gchar *file_uri_str;
GnomeVFSResult vfs_result;
}
gboolean
-file_open_get_content(gchar *file, gchar *dir, gchar **buffer, guint *bytes)
+file_open_get_contents(gchar **dir, gchar **buffer, guint *bytes)
{
gchar *file_uri_str;
GnomeVFSResult vfs_result;
-if (!file_open(&file,&dir,file_uri_str)) {
+if (!file_open(dir, &file_uri_str)) {
buffer=NULL;
- return TRUE;
-}
-vfs_result = gnome_vfs_read_entire_file(file_uri_str, bytes, buffer);
-if (vfs_result != GNOME_VFS_OK) {
return FALSE;
-} else {
- return TRUE;
-}
}
-/**
- * This is a multi-purpose function for allowing the user to select a file
- * for either reading or writing. If chooser_action is
- * GTK_FILE_CHOOSER_ACTION_OPEN, then bytes_out and size_out must be
- * non-NULL. If chooser_action is GTK_FILE_CHOOSER_ACTION_SAVE, then
- * handle_out must be non-NULL. Either dir or file (or both) can be NULL.
- * This function returns TRUE if a file was successfully opened.
- */
-gboolean
-open_file(gchar ** bytes_out, GnomeVFSHandle ** handle_out, gint * size_out,
- gchar ** dir, gchar ** file, GtkFileChooserAction chooser_action)
-{
- GtkWidget *dialog;
- gboolean success = FALSE;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(_window), chooser_action);
-
- if (dir && *dir)
- gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER
- (dialog), *dir);
-
- if (file && *file) {
- GValue val;
- gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(dialog), *file);
- if (chooser_action == GTK_FILE_CHOOSER_ACTION_SAVE) {
- /* Work around a bug in HildonFileChooserDialog. */
- memset(&val, 0, sizeof(val));
- g_value_init(&val, G_TYPE_BOOLEAN);
- g_value_set_boolean(&val, FALSE);
- g_object_set_property(G_OBJECT(dialog), "autonaming",
- &val);
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER
- (dialog), strrchr(*file, '/') + 1);
- }
- }
-
- gtk_widget_show_all(dialog);
-
- g_printf("A\n");
-
- while (!success && gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- gchar *file_uri_str;
- GnomeVFSResult vfs_result;
-
- /* Get the selected filename. */
- file_uri_str = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
-
- g_printf("file: %s\n", file_uri_str);
-
- if ((chooser_action == GTK_FILE_CHOOSER_ACTION_OPEN
- && (GNOME_VFS_OK !=
- (vfs_result = gnome_vfs_read_entire_file(file_uri_str, size_out,
- bytes_out))))
- || (chooser_action == GTK_FILE_CHOOSER_ACTION_SAVE
- && GNOME_VFS_OK != (vfs_result = gnome_vfs_create(handle_out,
- file_uri_str, GNOME_VFS_OPEN_WRITE, FALSE, 0664)))) {
- gchar buffer[BUFFER_SIZE];
- snprintf(buffer, sizeof(buffer),"%s:\n%s",
- chooser_action == GTK_FILE_CHOOSER_ACTION_OPEN ?
- _("Failed to open file for reading")
- : _("Failed to open file for writing"),
- gnome_vfs_result_to_string(vfs_result));
- popup_error(dialog, buffer);
- } else
- success = TRUE;
-
- g_free(file_uri_str);
- }
-
- g_printf("B\n");
-
- if (success) {
- /* Success!. */
- if (dir) {
- g_free(*dir);
- *dir = gtk_file_chooser_get_current_folder_uri
- (GTK_FILE_CHOOSER(dialog));
- }
-
- /* If desired, save the file for later. */
- if (file) {
- g_free(*file);
- *file = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
- }
-
- g_printf("C\n");
-
- }
-
- gtk_widget_destroy(dialog);
+vfs_result=gnome_vfs_read_entire_file(file_uri_str, bytes, buffer);
+if (vfs_result!=GNOME_VFS_OK)
+ return FALSE;
- vprintf("%s(): return %d\n", __PRETTY_FUNCTION__, success);
- return success;
+return TRUE;
}