Logo Search packages:      
Sourcecode: libgphoto2 version File versions

int gp_filesystem_list_folders ( CameraFilesystem fs,
const char *  folder,
CameraList *  list,
GPContext context 
)

gp_filesystem_list_folders: : a CameraFilesystem : a folder : a CameraList where subfolders should be listed : a GPContext

Generates a list of subfolders of the supplied either using cached values (if there are any) or the folder_list_func if it has been supplied previously. If not, it is assumed that only a root folder exists (which is the case for many cameras).

Return value: a gphoto2 error code.

Definition at line 879 of file gphoto2-filesys.c.

References _CameraFilesystem::count, _CameraFilesystem::folder, _CameraFilesystem::folder_list_func, and _CameraFilesystem::list_data.

Referenced by gp_camera_folder_list_folders().

{
      int x, y, j, offset, count;
      char buf[1024];
      const char *name;
      unsigned int len;

      gp_log (GP_LOG_DEBUG, "gphoto2-filesystem",
            "Listing folders in '%s'...", folder);

      CHECK_NULL (fs && folder && list);
      CC (context);
      CA (folder, context);

      /* Guard against trailing slashes */
      len = strlen (folder);
      if ((len > 1) && (folder[len - 1] == '/'))
            len--;

      gp_list_reset (list);

      /* Search the folder */
      CR (x = gp_filesystem_folder_number (fs, folder, context));

      /* If the folder is dirty, query the contents. */
      if (fs->folder[x].folders_dirty && fs->folder_list_func) {
            CR (fs->folder_list_func (fs, folder, list,
                                fs->list_data, context));
            CR (delete_all_folders (fs, folder, context));
            CR (count = gp_list_count (list));
            for (y = 0; y < count; y++) {
                  CR (gp_list_get_name (list, y, &name));
                  memset (buf, 0, sizeof (buf));
                  strncpy (buf, folder, MIN (sizeof (buf), len));
                  if (buf[strlen (buf) - 1] != '/')
                        strncat (buf, "/", sizeof (buf));
                  strncat (buf, name, sizeof (buf));
                  CR (append_folder (fs, buf, context));
            }
            gp_list_reset (list);
      }

      for (x = 0; x < fs->count; x++)
            if (!strncmp (fs->folder[x].name, folder, len)) {
                  
                  /*
                   * Is this really a subfolder (and not the folder
                   * itself)?
                   */
                  if (strlen (fs->folder[x].name) <= len)
                        continue;

                  /*
                   * Is this really a direct subfolder (and not a 
                   * subsubfolder)?
                   */
                  for (j = len + 1; fs->folder[x].name[j] != '\0'; j++)
                        if (fs->folder[x].name[j] == '/')
                              break;
                  if (j == strlen (fs->folder[x].name)) {
                        if (!strcmp (folder, "/"))
                              offset = 1;
                        else
                              offset = len + 1;
                        CR (gp_list_append (list,
                                    fs->folder[x].name + offset,
                                    NULL));
                  }
            }

      /* The folder is clean now */
      CR (x = gp_filesystem_folder_number (fs, folder, context));
      fs->folder[x].folders_dirty = 0;

      gp_log (GP_LOG_DEBUG, "gphoto2-filesystem", "Folder %s contains %i "
            "files.", folder, fs->folder[x].count);

      return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index