#include "vikgototool.h"
#include "util.h"
-#include "curl_download.h"
#include <string.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-static void goto_tool_class_init ( VikGotoToolClass *klass );
-static void goto_tool_init ( VikGotoTool *vlp );
-
static GObjectClass *parent_class;
static void goto_tool_finalize ( GObject *gob );
static gchar *goto_tool_get_label ( VikGotoTool *vw );
-static DownloadOptions *goto_tool_get_download_options ( VikGotoTool *self );
+static DownloadFileOptions *goto_tool_get_download_options ( VikGotoTool *self );
typedef struct _VikGotoToolPrivate VikGotoToolPrivate;
VIK_GOTO_TOOL_TYPE, \
VikGotoToolPrivate))
-GType vik_goto_tool_get_type()
-{
- static GType w_type = 0;
-
- if (!w_type)
- {
- static const GTypeInfo w_info =
- {
- sizeof (VikGotoToolClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) goto_tool_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (VikGotoTool),
- 0,
- (GInstanceInitFunc) goto_tool_init,
- };
- w_type = g_type_register_static ( G_TYPE_OBJECT, "VikGotoTool", &w_info, G_TYPE_FLAG_ABSTRACT );
- }
-
- return w_type;
-}
+G_DEFINE_ABSTRACT_TYPE (VikGotoTool, vik_goto_tool, G_TYPE_OBJECT)
enum
{
}
}
-static void goto_tool_class_init ( VikGotoToolClass *klass )
+static void vik_goto_tool_class_init ( VikGotoToolClass *klass )
{
GObjectClass *gobject_class;
GParamSpec *pspec;
return VIK_GOTO_TOOL ( g_object_new ( VIK_GOTO_TOOL_TYPE, NULL ) );
}
-static void goto_tool_init ( VikGotoTool *self )
+static void vik_goto_tool_init ( VikGotoTool *self )
{
VikGotoToolPrivate *priv = GOTO_TOOL_GET_PRIVATE (self);
priv->label = NULL;
return g_strdup ( priv->label );
}
-static DownloadOptions *goto_tool_get_download_options ( VikGotoTool *self )
+static DownloadFileOptions *goto_tool_get_download_options ( VikGotoTool *self )
{
// Default: return NULL
return NULL;
return VIK_GOTO_TOOL_GET_CLASS( self )->get_url_format( self );
}
-DownloadOptions *vik_goto_tool_get_download_options ( VikGotoTool *self )
+DownloadFileOptions *vik_goto_tool_get_download_options ( VikGotoTool *self )
{
return VIK_GOTO_TOOL_GET_CLASS( self )->get_download_options( self );
}
return VIK_GOTO_TOOL_GET_CLASS( self )->parse_file_for_latlon( self, filename, ll );
}
+/**
+ * vik_goto_tool_get_coord:
+ *
+ * @self: The #VikGotoTool
+ * @vvp: The #VikViewport
+ * @srch_str: The string to search with
+ * @coord: Returns the top match position for a successful search
+ *
+ * Returns: An integer value indicating:
+ * 0 = search found something
+ * -1 = search place not found by the #VikGotoTool
+ * 1 = search unavailable in the #VikGotoTool due to communication issue
+ *
+ */
int vik_goto_tool_get_coord ( VikGotoTool *self, VikWindow *vw, VikViewport *vvp, gchar *srch_str, VikCoord *coord )
{
- FILE *tmp_file;
- int tmp_fd;
gchar *tmpname;
gchar *uri;
gchar *escaped_srch_str;
g_debug("%s: escaped goto: %s", __FUNCTION__, escaped_srch_str);
- if ((tmp_fd = g_file_open_tmp ("vikgoto.XXXXXX", &tmpname, NULL)) == -1) {
- g_critical(_("couldn't open temp file"));
- return -1;
- }
-
- tmp_file = fdopen(tmp_fd, "r+");
uri = g_strdup_printf(vik_goto_tool_get_url_format(self), escaped_srch_str);
- /* TODO: curl may not be available */
- if (curl_download_uri(uri, tmp_file, vik_goto_tool_get_download_options(self), 0, NULL)) { /* error */
- fclose(tmp_file);
- tmp_file = NULL;
- ret = -1;
- goto done;
+ tmpname = a_download_uri_to_tmp_file ( uri, vik_goto_tool_get_download_options(self) );
+
+ if ( !tmpname ) {
+ // Some kind of download error, so no tmp file
+ ret = 1;
+ goto done_no_file;
}
- fclose(tmp_file);
- tmp_file = NULL;
g_debug("%s: %s", __FILE__, tmpname);
if (!vik_goto_tool_parse_file_for_latlon(self, tmpname, &ll)) {
ret = -1;
vik_coord_load_from_latlon ( coord, vik_viewport_get_coord_mode(vvp), &ll );
done:
+ (void)util_remove(tmpname);
+done_no_file:
+ g_free(tmpname);
g_free(escaped_srch_str);
g_free(uri);
- g_remove(tmpname);
- g_free(tmpname);
return ret;
}