- memset(buf, 0, sizeof(buf));
- fgetpos(f, &pos);
- rewind(f);
- nr = fread(buf, 1, sizeof(buf) - 1, f);
- fsetpos(f, &pos);
- for (bp = buf; (bp < (buf + sizeof(buf) - 1)) && (nr > (bp - buf)); bp++) {
- if (!(isspace(*bp)))
- break;
- }
- if ((bp >= (buf + sizeof(buf) -1)) || ((bp - buf) >= nr))
- return FALSE;
- for (s = html_str; *s; s++) {
- if (strncasecmp(*s, bp, strlen(*s)) == 0)
- return TRUE;
- }
- return FALSE;
+ return check_file_first_line(f, kml_str);
+}
+
+static GList *file_list = NULL;
+static GMutex *file_list_mutex = NULL;
+
+/* spin button scales */
+static VikLayerParamScale params_scales[] = {
+ {1, 365, 1, 0}, /* download_tile_age */
+};
+
+static VikLayerParamData convert_to_display ( VikLayerParamData value )
+{
+ // From seconds into days
+ return VIK_LPD_UINT ( value.u / 86400 );
+}
+
+static VikLayerParamData convert_to_internal ( VikLayerParamData value )
+{
+ // From days into seconds
+ return VIK_LPD_UINT ( 86400 * value.u );
+}
+
+static VikLayerParam prefs[] = {
+ { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_NAMESPACE "download_tile_age", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Tile age (days):"), VIK_LAYER_WIDGET_SPINBUTTON, ¶ms_scales[0], NULL, NULL, NULL, convert_to_display, convert_to_internal },
+};
+
+void a_download_init (void)
+{
+ VikLayerParamData tmp;
+ tmp.u = VIK_CONFIG_DEFAULT_TILE_AGE / 86400; // Now in days
+ a_preferences_register(prefs, tmp, VIKING_PREFERENCES_GROUP_KEY);
+ file_list_mutex = vik_mutex_new();
+}
+
+void a_download_uninit (void)
+{
+ vik_mutex_free(file_list_mutex);
+}
+
+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);