libmtp: folders.c

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Examples

# folders.c

    00001
    00023 #include "common.h"
    00024
    00025 static void dump_folder_list(LIBMTP_folder_t *folderlist, int level)
    00026 {
    00027   int i;
    00028   if(folderlist==NULL) {
    00029     return;
    00030   }
    00031
    00032   printf("%u\t", folderlist->folder_id);
    00033   for(i=0;i<level;i++) printf("  ");
    00034
    00035   printf("%s\n", folderlist->name);
    00036
    00037   dump_folder_list(folderlist->child, level+1);
    00038   dump_folder_list(folderlist->sibling, level);
    00039 }
    00040
    00041 int main (int argc, char **argv)
    00042 {
    00043   LIBMTP_mtpdevice_t *device, *iter;
    00044   LIBMTP_folder_t *folders;
    00045
    00046   LIBMTP_Init();
    00047   fprintf(stdout, "Attempting to connect device(s)\n");
    00048
    00049   switch(LIBMTP_Get_Connected_Devices(&device))
    00050   {
    00051   case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
    00052     fprintf(stdout, "mtp-folders: No Devices have been found\n");
    00053     return 0;
    00054   case LIBMTP_ERROR_CONNECTING:
    00055     fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n");
    00056     return 1;
    00057   case LIBMTP_ERROR_MEMORY_ALLOCATION:
    00058     fprintf(stderr, "mtp-folders: Memory Allocation Error. Exit\n");
    00059     return 1;
    00060
    00061   /* Unknown general errors - This should never execute */
    00062   case LIBMTP_ERROR_GENERAL:
    00063   default:
    00064     fprintf(stderr, "mtp-folders: Unknown error, please report "
    00065                     "this to the libmtp developers\n");
    00066   return 1;
    00067
    00068   /* Successfully connected at least one device, so continue */
    00069   case LIBMTP_ERROR_NONE:
    00070     fprintf(stdout, "mtp-folders: Successfully connected\n");
    00071     fflush(stdout);
    00072   }
    00073
    00074   /* iterate through connected MTP devices */
    00075   for(iter = device; iter != NULL; iter = iter->next)
    00076   {
    00077         char *friendlyname;
    00078     /* Echo the friendly name so we know which device we are working with */
    00079     friendlyname = LIBMTP_Get_Friendlyname(iter);
    00080     if (friendlyname == NULL) {
    00081       printf("Friendly name: (NULL)\n");
    00082     } else {
    00083       printf("Friendly name: %s\n", friendlyname);
    00084       free(friendlyname);
    00085     }
    00086
    00087     LIBMTP_Dump_Errorstack(iter);
    00088     LIBMTP_Clear_Errorstack(iter);    /* Get folder listing */
    00089
    00090     folders = LIBMTP_Get_Folder_List(iter);
    00091
    00092     if (folders == NULL) {
    00093       fprintf(stdout, "No folders found\n");
    00094       LIBMTP_Dump_Errorstack(iter);
    00095       LIBMTP_Clear_Errorstack(iter);
    00096     } else {
    00097       dump_folder_list(folders,0);
    00098     }
    00099
    00100     LIBMTP_destroy_folder_t(folders);
    00101   }
    00102
    00103
    00104   LIBMTP_Release_Device_List(device);
    00105   printf("OK.\n");
    00106
    00107   return 0;
    00108 }