]> git.street.me.uk Git - andy/viking.git/blobdiff - src/dems.c
Tidy up: simpler and better use of trackpoint free methods in TRW Layer.
[andy/viking.git] / src / dems.c
index 7906e0c875e71518f2c4cc13a4e85ee849de45ba..08605e0d263b64aa957177cda5c19429723740c1 100644 (file)
@@ -2,6 +2,7 @@
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2003-2008, Evan Battaglia <gtoevan@gmx.net>
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2003-2008, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (C) 2007, Quy Tonthat <qtonthat@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,7 @@
 #include <glib.h>
 
 #include "dems.h"
 #include <glib.h>
 
 #include "dems.h"
+#include "background.h"
 
 typedef struct {
   VikDEM *dem;
 
 typedef struct {
   VikDEM *dem;
@@ -72,8 +74,11 @@ VikDEM *a_dems_load(const gchar *filename)
 void a_dems_unref(const gchar *filename)
 {
   LoadedDEM *ldem = (LoadedDEM *) g_hash_table_lookup ( loaded_dems, filename );
 void a_dems_unref(const gchar *filename)
 {
   LoadedDEM *ldem = (LoadedDEM *) g_hash_table_lookup ( loaded_dems, filename );
-  g_assert ( ldem );
-  ldem->ref_count --;
+  if ( !ldem ) {
+    /* This is fine - probably means the loaded list was aborted / not completed for some reason */
+    return;
+  }
+  ldem->ref_count--;
   if ( ldem->ref_count == 0 )
     g_hash_table_remove ( loaded_dems, filename );
 }
   if ( ldem->ref_count == 0 )
     g_hash_table_remove ( loaded_dems, filename );
 }
@@ -102,9 +107,11 @@ VikDEM *a_dems_get(const gchar *filename)
  * we need to know that they weren't referenced though when we
  * do the a_dems_list_free().
  */
  * we need to know that they weren't referenced though when we
  * do the a_dems_list_free().
  */
-void a_dems_load_list ( GList **dems )
+int a_dems_load_list ( GList **dems, gpointer threaddata )
 {
   GList *iter = *dems;
 {
   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;
   while ( iter ) {
     if ( ! a_dems_load((const gchar *) (iter->data)) ) {
       GList *iter_temp = iter->next;
@@ -114,7 +121,16 @@ void a_dems_load_list ( GList **dems )
     } else {
       iter = iter->next;
     }
     } 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;
 }
 
 /* Takes a string list (GList of strings) of dems (filenames).
 }
 
 /* Takes a string list (GList of strings) of dems (filenames).