Remove commented out code.
[geeqie.git] / src / filedata.c
index 3ec68b2..13bab82 100644 (file)
@@ -266,13 +266,9 @@ static void file_data_set_collate_keys(FileData *fd)
        g_free(fd->collate_key_name);
        g_free(fd->collate_key_name_nocase);
 
-#if 0 && GLIB_CHECK_VERSION(2, 8, 0)
-       fd->collate_key_name = g_utf8_collate_key_for_filename(valid_name, -1);
-       fd->collate_key_name_nocase = g_utf8_collate_key_for_filename(caseless_name, -1);
-#else
        fd->collate_key_name = g_utf8_collate_key(valid_name, -1);
        fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1);
-#endif
+       
        g_free(valid_name);
        g_free(caseless_name);
 }
@@ -392,7 +388,7 @@ static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean
        fd->date = st->st_mtime;
        fd->mode = st->st_mode;
        fd->ref = 1;
-       fd->magick = 0x12345678;
+       fd->magick = FD_MAGICK;
        
        if (disable_sidecars) fd->disable_grouping = TRUE;
 
@@ -410,7 +406,8 @@ static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolea
        return ret;
 }
 
-void init_exif_time_data(GList *files) {
+void init_exif_time_data(GList *files)
+{
        FileData *file;
        DEBUG_1("%s init_exif_time_data: ...", get_exec_time());
        while (files)
@@ -424,47 +421,52 @@ void init_exif_time_data(GList *files) {
                }
 }
 
-void set_exif_time_data(GList *files) {
-       gchar *tmp;
-       uint year, month, day, hour, min, sec;
-       struct tm time_str;
-       FileData *file;
-       DEBUG_1("%s set_exif_time_data: ...", get_exec_time());
-       while (files)
+void read_exif_time_data(FileData *file)
+{
+       if (file->exifdate > 0)
                {
-               file = files->data;
-
-               if (file->exifdate > 0)
-                       {
-                       files = files->next;
-                       DEBUG_1("%s set_exif_time_data: Already exists for %s", get_exec_time(), file->path);
-                       continue;
-                       }
-
-               DEBUG_1("%s set_exif_time_data: Getting exiftime for %s", get_exec_time(), file->path);
+               DEBUG_1("%s set_exif_time_data: Already exists for %s", get_exec_time(), file->path);
+               return;
+               }
+       
+       file->exif = exif_read_fd(file);
 
-               file->exif = exif_read_fd(file);
+       if (file->exif)
+               {
+               gchar *tmp = exif_get_data_as_text(file->exif, "Exif.Photo.DateTimeOriginal");
+               DEBUG_2("%s set_exif_time_data: reading %p %s", get_exec_time(), file, file->path);
 
-               if (file->exif)
+               if (tmp)
                        {
-                       tmp = exif_get_data_as_text(file->exif, "Exif.Photo.DateTimeOriginal");
-                       if (tmp)
-                               {
-                               sscanf(tmp, "%4d:%2d:%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
-                               time_str.tm_year = year - 1900;
-                               time_str.tm_mon = month - 1;
-                               time_str.tm_mday = day;
-                               time_str.tm_hour = hour;
-                               time_str.tm_min = min;
-                               time_str.tm_sec = sec;
-                               time_str.tm_isdst = 0;
-
-                               file->exifdate = mktime(&time_str);
-                               }
+                       struct tm time_str;
+                       uint year, month, day, hour, min, sec;
+       
+                       sscanf(tmp, "%4d:%2d:%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
+                       time_str.tm_year  = year - 1900;
+                       time_str.tm_mon   = month - 1;
+                       time_str.tm_mday  = day;
+                       time_str.tm_hour  = hour;
+                       time_str.tm_min   = min;
+                       time_str.tm_sec   = sec;
+                       time_str.tm_isdst = 0;
+       
+                       file->exifdate = mktime(&time_str);
+                       g_free(tmp);
                        }
-               files = files->next;
                }
+}
 
+void set_exif_time_data(GList *files)
+{
+       DEBUG_1("%s set_exif_time_data: ...", get_exec_time());
+       
+       while (files)
+               {
+               FileData *file = files->data;
+               
+               read_exif_time_data(file);
+               files = files->next;
+               }
 }
 
 FileData *file_data_new_no_grouping(const gchar *path_utf8)
@@ -509,24 +511,26 @@ FileData *file_data_ref(FileData *fd)
 #endif
 {
        if (fd == NULL) return NULL;
+       if (fd->magick != FD_MAGICK)
 #ifdef DEBUG_FILEDATA
-       if (fd->magick != 0x12345678)
-               DEBUG_0("fd magick mismatch at %s:%d", file, line);
+               DEBUG_0("fd magick mismatch @ %s:%d  fd=%p", file, line, fd);
+#else
+               DEBUG_0("fd magick mismatch fd=%p", fd);
 #endif
-       g_assert(fd->magick == 0x12345678);
+       g_assert(fd->magick == FD_MAGICK);
        fd->ref++;
 
 #ifdef DEBUG_FILEDATA
-       DEBUG_2("file_data_ref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line);
+       DEBUG_2("file_data_ref fd=%p (%d): '%s' @ %s:%d", fd, fd->ref, fd->path, file, line);
 #else
-       DEBUG_2("file_data_ref (%d): '%s'", fd->ref, fd->path);
+       DEBUG_2("file_data_ref fd=%p (%d): '%s'", fd, fd->ref, fd->path);
 #endif
        return fd;
 }
 
 static void file_data_free(FileData *fd)
 {
-       g_assert(fd->magick == 0x12345678);
+       g_assert(fd->magick == FD_MAGICK);
        g_assert(fd->ref == 0);
 
        metadata_cache_free(fd);
@@ -552,17 +556,19 @@ void file_data_unref(FileData *fd)
 #endif
 {
        if (fd == NULL) return;
+       if (fd->magick != FD_MAGICK)
 #ifdef DEBUG_FILEDATA
-       if (fd->magick != 0x12345678)
-               DEBUG_0("fd magick mismatch @ %s:%d", file, line);
+               DEBUG_0("fd magick mismatch @ %s:%d  fd=%p", file, line, fd);
+#else
+               DEBUG_0("fd magick mismatch fd=%p", fd);
 #endif
-       g_assert(fd->magick == 0x12345678);
+       g_assert(fd->magick == FD_MAGICK);
        
        fd->ref--;
 #ifdef DEBUG_FILEDATA
-       DEBUG_2("file_data_unref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line);
+       DEBUG_2("file_data_unref fd=%p (%d): '%s' @ %s:%d", fd, fd->ref, fd->path, file, line);
 #else
-       DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path);
+       DEBUG_2("file_data_unref fd=%p (%d): '%s'", fd, fd->ref, fd->path);
 #endif
        if (fd->ref == 0)
                {
@@ -656,11 +662,11 @@ static void file_data_check_sidecars(const GList *basename_list)
                {
                FileData *fd = work->data;
                work = work->next;
-               g_assert(fd->magick == 0x12345678);
+               g_assert(fd->magick == FD_MAGICK);
                DEBUG_2("basename: %p %s", fd, fd->name);
                if (fd->parent) 
                        {
-                       g_assert(fd->parent->magick == 0x12345678);
+                       g_assert(fd->parent->magick == FD_MAGICK);
                        DEBUG_2("                  parent: %p", fd->parent);
                        }
                s_work = fd->sidecar_files;
@@ -668,7 +674,7 @@ static void file_data_check_sidecars(const GList *basename_list)
                        {
                        FileData *sfd = s_work->data;
                        s_work = s_work->next;
-                       g_assert(sfd->magick == 0x12345678);
+                       g_assert(sfd->magick == FD_MAGICK);
                        DEBUG_2("                  sidecar: %p %s", sfd, sfd->name);
                        }
                
@@ -736,7 +742,7 @@ static void file_data_check_sidecars(const GList *basename_list)
        while (work)
                {
                FileData *sfd = work->data;
-               g_assert(sfd->magick == 0x12345678);
+               g_assert(sfd->magick == FD_MAGICK);
                g_assert(sfd->parent == NULL && sfd->sidecar_files == NULL);
                sfd->parent = parent_fd;
                new_sidecars = g_list_prepend(new_sidecars, sfd);
@@ -750,8 +756,8 @@ static void file_data_check_sidecars(const GList *basename_list)
 
 static void file_data_disconnect_sidecar_file(FileData *target, FileData *sfd)
 {
-       g_assert(target->magick == 0x12345678);
-       g_assert(sfd->magick == 0x12345678);
+       g_assert(target->magick == FD_MAGICK);
+       g_assert(sfd->magick == FD_MAGICK);
        g_assert(g_list_find(target->sidecar_files, sfd));
 
        file_data_ref(target);
@@ -957,31 +963,6 @@ static GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileDat
        return list;
 }
 
-#if 0
-static void file_data_basename_hash_remove(GHashTable *basename_hash, FileData *fd)
-{
-       GList *list;
-       gchar *basename = g_strndup(fd->path, fd->extension - fd->path);
-       
-       list = g_hash_table_lookup(basename_hash, basename);
-       
-       if (!g_list_find(list, fd)) return;
-       
-       list = g_list_remove(list, fd);
-       file_data_unref(fd);
-       
-       if (list)
-               {
-               g_hash_table_insert(basename_hash, basename, list);
-               }
-       else 
-               {
-               g_hash_table_remove(basename_hash, basename);
-               g_free(basename);
-               }
-}
-#endif
-
 static void file_data_basename_hash_remove_list(gpointer key, gpointer value, gpointer data)
 {
        filelist_free((GList *)value);
@@ -1123,6 +1104,7 @@ static gboolean filelist_read_real(const gchar *dir_path, GList **files, GList *
        g_free(pathl);
 
        if (dirs) *dirs = dlist;
+
        if (files) 
                {
                g_hash_table_foreach(basename_hash, file_data_basename_hash_to_sidecars, NULL); 
@@ -2598,29 +2580,6 @@ static gboolean file_data_list_contains_whole_group(GList *list, FileData *fd)
        return TRUE;
 }
 
-#if 0
-static gboolean file_data_list_dump(GList *list)
-{
-       GList *work, *work2;
-
-       work = list;
-       while (work)
-               {
-               FileData *fd = work->data;
-               printf("%s\n", fd->name);
-               work2 = fd->sidecar_files;
-               while (work2)
-                       {
-                       FileData *fd = work2->data;
-                       printf("       %s\n", fd->name);
-                       work2 = work2->next;
-                       }
-               work = work->next;
-               }
-       return TRUE;
-}
-#endif
-
 GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GList **ungrouped_list)
 {
        GList *out = NULL;