#include <glib/gi18n.h>
#include <gdk-pixbuf/gdk-pixdata.h>
#include "globals.h"
-#include "curl_download.h"
#include "bingmapsource.h"
#include "bbox.h"
#include "background.h"
static int
_load_attributions ( BingMapSource *self )
{
- FILE *tmp_file;
- int tmp_fd;
- gchar *tmpname;
- gchar *uri;
int ret = 0; /* OK */
BingMapSourcePrivate *priv = BING_MAP_SOURCE_GET_PRIVATE (self);
+ gchar *uri = g_strdup_printf(URL_ATTR_FMT, priv->api_key);
- if ((tmp_fd = g_file_open_tmp ("vik-bing.XXXXXX", &tmpname, NULL)) == -1) {
- g_critical(_("couldn't open temp file"));
- return -1;
- }
-
- tmp_file = fdopen(tmp_fd, "r+");
- uri = g_strdup_printf(URL_ATTR_FMT, priv->api_key);
-
- /* TODO: curl may not be available */
- if (curl_download_uri(uri, tmp_file, vik_map_source_default_get_download_options(VIK_MAP_SOURCE_DEFAULT(self)), 0, NULL)) { /* error */
- fclose(tmp_file);
- tmp_file = NULL;
- ret = -1;
- goto done;
- }
-
- fclose(tmp_file);
- tmp_file = NULL;
+ gchar *tmpname = a_download_uri_to_tmp_file ( uri, vik_map_source_default_get_download_options(VIK_MAP_SOURCE_DEFAULT(self)) );
g_debug("%s: %s", __FUNCTION__, tmpname);
if (!_parse_file_for_attributions(self, tmpname)) {
{
curl_download_handle_cleanup ( handle );
}
+
+/**
+ * a_download_url_to_tmp_file:
+ * @uri: The URI (Uniform Resource Identifier)
+ * @options: Download options (maybe NULL)
+ *
+ * returns name of the temporary file created - NULL if unsuccessful
+ * this string needs to be freed once used
+ * the file needs to be removed once used
+ */
+gchar *a_download_uri_to_tmp_file ( const gchar *uri, DownloadMapOptions *options )
+{
+ FILE *tmp_file;
+ int tmp_fd;
+ gchar *tmpname;
+
+ if ( (tmp_fd = g_file_open_tmp ("viking-download.XXXXXX", &tmpname, NULL)) == -1 ) {
+ g_critical (_("couldn't open temp file"));
+ return NULL;
+ }
+
+ tmp_file = fdopen(tmp_fd, "r+");
+
+ if ( curl_download_uri ( uri, tmp_file, options, NULL, NULL ) ) {
+ // error
+ fclose ( tmp_file );
+ g_remove ( tmpname );
+ g_free ( tmpname );
+ return NULL;
+ }
+ fclose ( tmp_file );
+
+ return tmpname;
+}
void *a_download_handle_init ();
void a_download_handle_cleanup ( void *handle );
+gchar *a_download_uri_to_tmp_file ( const gchar *uri, DownloadMapOptions *options );
+
/* Error messages returned by download functions */
enum { DOWNLOAD_NO_ERROR = 0,
DOWNLOAD_NO_NEWER_FILE,
#include "viking.h"
#include "util.h"
-#include "curl_download.h"
#include "geonamessearch.h"
/* Compatibility */
}
-static gchar *download_url(gchar *uri)
-{
- FILE *tmp_file;
- int tmp_fd;
- gchar *tmpname;
-
- if ((tmp_fd = g_file_open_tmp ("vikgsearch.XXXXXX", &tmpname, NULL)) == -1) {
- g_critical(_("couldn't open temp file"));
- return NULL;
- }
- tmp_file = fdopen(tmp_fd, "r+");
-
- if (curl_download_uri(uri, tmp_file, NULL, 0, NULL)) {
- // error
- fclose(tmp_file);
- tmp_file = NULL;
- g_remove(tmpname);
- g_free(tmpname);
- return(NULL);
- }
- fclose(tmp_file);
- tmp_file = NULL;
- return(tmpname);
-}
-
void a_geonames_wikipedia_box ( VikWindow *vw, VikTrwLayer *vtl, struct LatLon maxmin[2] )
{
gchar *uri;
g_free(south); south = NULL;
g_free(east); east = NULL;
g_free(west); west = NULL;
- tmpname = download_url(uri);
+ tmpname = a_download_uri_to_tmp_file ( uri, NULL );
if (!tmpname) {
none_found(vw);
return;
#include "vikgototool.h"
#include "util.h"
-#include "curl_download.h"
#include <string.h>
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) );
- 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;