]> git.street.me.uk Git - andy/viking.git/blobdiff - src/download.c
Add default values for layers.
[andy/viking.git] / src / download.c
index 05a525a092338a448b7cb0ba64a6b9b7da4b0200..1da110d088ca429c2b9d4e3364361b21ac880d39 100644 (file)
@@ -109,7 +109,7 @@ VikLayerParamScale params_scales[] = {
 };
 
 static VikLayerParam prefs[] = {
-  { VIKING_PREFERENCES_NAMESPACE "download_tile_age", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Tile age (s):"), VIK_LAYER_WIDGET_SPINBUTTON, params_scales + 0, NULL },
+  { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "download_tile_age", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Tile age (s):"), VIK_LAYER_WIDGET_SPINBUTTON, &params_scales[0], NULL, NULL },
 };
 
 void a_download_init (void)
@@ -293,3 +293,37 @@ void a_download_handle_cleanup ( void *handle )
 {
   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;
+}