/* TODO: don't delete them when they don't exist. * we need to warn the user, but we should keep them in the GList. * we need to know that they weren't referenced though when we * do the a_dems_list_free(). */ int a_dems_load_list ( GList **dems, gpointer threaddata ) { GList *iter = *dems; guint dem_count = 0; const guint dem_total = g_list_length ( *dems ); while ( iter ) { if ( ! a_dems_load((const gchar *) (iter->data)) ) { GList *iter_temp = iter->next; g_free ( iter->data ); (*dems) = g_list_remove_link ( (*dems), iter ); iter = iter_temp; } else { iter = iter->next; } /* When running a thread - inform of progress */ if ( threaddata ) { dem_count++; /* NB Progress also detects abort request via the returned value */ int result = a_background_thread_progress ( threaddata, ((gdouble)dem_count) / dem_total ); if ( result != 0 ) return -1; /* Abort thread */ } } return 0; }
GList *a_dems_list_copy ( GList *dems ) { GList *rv = g_list_copy ( dems ); GList *iter = rv; while ( iter ) { if ( ! a_dems_load((const gchar *) (iter->data)) ) { GList *iter_temp = iter->next; /* delete link, don't bother strdup'ing and free'ing string */ rv = g_list_remove_link ( rv, iter ); iter = iter_temp; } else { iter->data = g_strdup((gchar *)iter->data); /* copy the string too. */ iter = iter->next; } } return rv; }
/* Try to add file full_path. * filename will be copied. * returns FALSE if file does not exists, TRUE otherwise. */ static gboolean dem_layer_add_file ( VikDEMLayer *vdl, const gchar *filename ) { if ( g_file_test(filename, G_FILE_TEST_EXISTS) == TRUE ) { /* only load if file size is not 0 (not in progress) */ struct stat sb; stat ( filename, &sb ); if ( sb.st_size ) { gchar *duped_path = g_strdup(filename); vdl->files = g_list_prepend ( vdl->files, duped_path ); a_dems_load ( duped_path ); g_debug("%s: %s", __FUNCTION__, duped_path); } return TRUE; } else return FALSE; }