+static GList *file_list = NULL;
+static GMutex *file_list_mutex = NULL;
+
+/* spin button scales */
+VikLayerParamScale params_scales[] = {
+ {1, 86400*7, 10, 0}, /* download_tile_age */
+};
+
+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 },
+};
+
+void a_download_init (void)
+{
+ VikLayerParamData tmp;
+ tmp.u = VIK_CONFIG_DEFAULT_TILE_AGE;
+ a_preferences_register(prefs, tmp, VIKING_PREFERENCES_GROUP_KEY);
+
+ file_list_mutex = g_mutex_new();
+}
+
+static gboolean lock_file(const char *fn)
+{
+ gboolean locked = FALSE;
+ g_mutex_lock(file_list_mutex);
+ if (g_list_find_custom(file_list, fn, (GCompareFunc)g_strcmp0) == NULL)
+ {
+ // The filename is not yet locked
+ file_list = g_list_append(file_list, (gpointer)fn),
+ locked = TRUE;
+ }
+ g_mutex_unlock(file_list_mutex);
+ return locked;
+}
+
+static void unlock_file(const char *fn)
+{
+ g_mutex_lock(file_list_mutex);
+ file_list = g_list_remove(file_list, (gconstpointer)fn);
+ g_mutex_unlock(file_list_mutex);
+}
+
+static int download( const char *hostname, const char *uri, const char *fn, DownloadMapOptions *options, gboolean ftp, void *handle)