/*
* Viking - GPS data editor
* Copyright (C) 2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ * Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
* Based on:
* Copyright (C) 2003-2007, Leandro A. F. Pereira <leandro@linuxmag.com.br>
*
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+ /*
+ * Ideally dependencies should just be on Glib, Gtk,
+ * see vikutils for things that further depend on other Viking types
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <glib/gprintf.h>
#include "util.h"
#include "dialog.h"
-/*
#ifdef WINDOWS
#include <windows.h>
#endif
+/*
#ifndef WINDOWS
static gboolean spawn_command_line_async(const gchar * cmd,
const gchar * arg)
#endif
*/
+// Annoyingly gtk_show_uri() doesn't work so resort to ShellExecute method
+// (non working at least in our Windows build with GTK+2.24.10 on Windows 7)
+
void open_url(GtkWindow *parent, const gchar * url)
{
+#ifdef WINDOWS
+ ShellExecute(NULL, NULL, (char *) url, NULL, ".\\", 0);
+#else
GError *error = NULL;
gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), url, GDK_CURRENT_TIME, &error );
if ( error ) {
a_dialog_error_msg_extra ( parent, _("Could not launch web browser. %s"), error->message );
g_error_free ( error );
}
+#endif
}
void new_email(GtkWindow *parent, const gchar * address)
return TRUE;
}
-/* 1 << (x) is like a 2**(x) */
-#define GZ(x) (1<<(x))
-
-static const gdouble scale_mpps[] = { 0.125, 0.25, 0.5, GZ(0), GZ(1), GZ(2), GZ(3), GZ(4), GZ(5), GZ(6), GZ(7), GZ(8), GZ(9),
- GZ(10), GZ(11), GZ(12), GZ(13), GZ(14), GZ(15), GZ(16), GZ(17) };
+static GSList* deletion_list = NULL;
-static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0]));
+/**
+ * util_add_to_deletion_list:
+ *
+ * Add a name of a file into the list that is to be deleted on program exit
+ * Normally this is for files that get used asynchronously,
+ * so we don't know when it's time to delete them - other than at this program's end
+ */
+void util_add_to_deletion_list ( const gchar* filename )
+{
+ deletion_list = g_slist_append ( deletion_list, g_strdup (filename) );
+}
-#define ERROR_MARGIN 0.01
/**
- * mpp_to_zoom:
+ * util_remove_all_in_deletion_list:
*
- * Returns: a zoom level. see : http://wiki.openstreetmap.org/wiki/Zoom_levels
+ * Delete all the files in the deletion list
+ * This should only be called on program exit
*/
-guint8 mpp_to_zoom ( gdouble mpp )
+void util_remove_all_in_deletion_list ( void )
{
- gint i;
- for ( i = 0; i < num_scales; i++ ) {
- if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) {
- g_debug ( "mpp_to_zoom: %f -> %d", mpp, i );
- return 20-i;
- }
- }
- return 17; // a safe zoomed in default
+ while ( deletion_list )
+ {
+ g_remove ( deletion_list->data );
+ g_free ( deletion_list->data );
+ deletion_list = g_slist_delete_link ( deletion_list, deletion_list );
+ }
}