Esempio n. 1
0
static void mtp_press (void)
{
    if(!mutex)
        return;
    g_mutex_lock(mutex);
    if(!mtp_initialised)
    {
#if DEBUG
        g_print("Initializing the MTP device...\n");
#endif
        LIBMTP_Init();
        mtp_device = LIBMTP_Get_First_Device();
        mtp_initialised = TRUE;
#if 0
        gtk_widget_show(mtp_submenu_item_free);
#endif
    }
    g_mutex_unlock(mutex);
    if(mtp_device == NULL)
    {
#if DEBUG
        g_print("No MTP devices have been found !!!\n");
#endif
        /* show_dialog("No MTP devices have been found !!!"); */
        mtp_initialised = FALSE;
        return;
    }
#if 0
    gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(mtp_submenu_item_up))), _("Upload in progress..."));
    gtk_widget_set_sensitive(mtp_submenu_item_up, FALSE);
#endif
    g_thread_create(upload,NULL,FALSE,NULL);
}
Esempio n. 2
0
int main(int argc, char const *argv[])
{
    LIBMTP_Init();
    printf("Searching for device...\n");
    LIBMTP_mtpdevice_t* device = LIBMTP_Get_First_Device();
    if (!device) {
        printf("Oops, no devices!\n");
        return 1;
    }
    /* Warning! This id is just for test! Remove it and put your value */
    const int id = 10494;
    int r = 0;
    LIBMTP_BeginEditObject(device, id);
    char s[64] = "The quick brown fox jumps over lazy dog\n";
    printf("Calling for LIBMTP_SendPartialObject...\n");
    r = LIBMTP_SendPartialObject(device, id, 0, (unsigned char *)s, strlen(s));
    if (r < 0) {
        printf("Oops, an error!\n");
        goto cleanup;
    } else
        printf("LIBMTP_SendPartialObject done successfully!\n");
    LIBMTP_EndEditObject(device, id);
cleanup:
    LIBMTP_Dump_Errorstack(device);
    LIBMTP_Clear_Errorstack(device);
    LIBMTP_Release_Device(device);
    return r < 0 ? -1 : 0;
}
Esempio n. 3
0
int main (int argc, char **argv)
{
  LIBMTP_mtpdevice_t *device;
  LIBMTP_playlist_t *playlists;

  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");

  LIBMTP_Init();
  device = LIBMTP_Get_First_Device();
  if (device == NULL) {
    printf("No devices.\n");
    exit (0);
  }
  
  // Get playlist listing.
  playlists = LIBMTP_Get_Playlist_List(device);
  if (playlists == NULL) {
    printf("No playlists.\n");
  } else {
    LIBMTP_playlist_t *pl, *tmp;
    pl = playlists;
    while (pl != NULL) {
      dump_plinfo(device, pl);
      tmp = pl;
      pl = pl->next;
      LIBMTP_destroy_playlist_t(tmp);
    }
  }
    
  LIBMTP_Release_Device(device);
  printf("OK.\n");
  exit (0);
}
Esempio n. 4
0
int main (int argc, char **argv)
{

    int do_delete = 0;
    int opt;

    fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");

    while ( (opt = getopt(argc, argv, "d")) != -1 ) {
        switch (opt) {
        case 'd':
            do_delete = 1;
            break;
        default:
            break;
        }
    }

    if(do_delete == 0) {
        printf("This is a dummy run. No folders will be deleted.\n");
        printf("To delete folders, use the '-d' option.\n");
    }

    LIBMTP_mtpdevice_t *device;
    LIBMTP_folder_t *folders;
    LIBMTP_file_t *files;

    LIBMTP_Init();
    device = LIBMTP_Get_First_Device();
    if (device == NULL) {
        printf("No devices.\n");
        exit (0);
    }


    files = LIBMTP_Get_Filelisting_With_Callback(device,NULL,NULL);


    folders = LIBMTP_Get_Folder_List(device);

    if(folders == NULL) {
        printf("No folders found\n");
    } else {
        prune_empty_folders(device,files,folders,do_delete);
    }

    LIBMTP_destroy_folder_t(folders);
    LIBMTP_destroy_file_t(files);

    LIBMTP_Release_Device(device);
    printf("OK.\n");
    exit (0);
}
Esempio n. 5
0
int main (int argc, char **argv)
{
  LIBMTP_mtpdevice_t *device;
  int ret;

  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");

  LIBMTP_Init();
  device = LIBMTP_Get_First_Device();
  if (device == NULL) {
    printf("No devices.\n");
    return 0;
  }

  printf("I will now format your device. This means that\n");
  printf("all content (and licenses) will be lost forever.\n");
  printf("you will not be able to undo this operation.\n");
  printf("Continue? (y/n)\n");
  if (prompt() == 0) {
    // This will just format the first storage.
    ret = LIBMTP_Format_Storage(device, device->storage);
  } else {
    printf("Aborted.\n");
    ret = 0;
  }

  if ( ret != 0 ) {
    printf("Failed to format device.\n");
    LIBMTP_Dump_Errorstack(device);
    LIBMTP_Clear_Errorstack(device);
    LIBMTP_Release_Device(device);
    return 1;
  }

  LIBMTP_Release_Device(device);
  printf("OK.\n");
  return 0;
}
Esempio n. 6
0
int main (int argc, char **argv) {
  int opt;
  extern int optind;
  extern char *optarg;
  LIBMTP_mtpdevice_t *device = NULL;
  int fd;
  uint32_t id = 0;
  uint64_t filesize;
  uint8_t *imagedata = NULL;
  char *path = NULL;
  char *rest;
  struct stat statbuff;
  int ret;

  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");

  while ( (opt = getopt(argc, argv, "hi:")) != -1 ) {
    switch (opt) {
    case 'h':
      usage();
    case 'i':
      id = strtoul(optarg, &rest, 0);
      break;
    default:
      usage();
    }
  }
  argc -= optind;
  argv += optind;

  if ( argc != 1 ) {
    printf("You need to pass a filename.\n");
    usage();
  }

  path = argv[0];

  if ( stat(path, &statbuff) == -1 ) {
    fprintf(stderr, "%s: ", path);
    perror("stat");
    exit(1);
  }
  filesize = (uint64_t) statbuff.st_size;
  imagedata = malloc(filesize * sizeof(uint16_t));

#ifdef __WIN32__
  if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
#else
  if ( (fd = open(path, O_RDONLY)) == -1) {
#endif
    printf("Couldn't open image file %s (%s)\n",path,strerror(errno));
    return 1;
  }
  else {
    read(fd, imagedata, filesize);
    close(fd);
  }

  LIBMTP_Init();
  device = LIBMTP_Get_First_Device();
  if (device == NULL) {
    printf("No devices.\n");
    return 0;
  }
  
  LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t();

  int i;
  thumb->data = malloc(sizeof(uint16_t) * filesize);
  for (i = 0; i < filesize; i++) {
    thumb->data[i] = imagedata[i];
  }

  thumb->size = filesize;
  thumb->filetype = LIBMTP_FILETYPE_JPEG;
  
  ret = LIBMTP_Send_Representative_Sample(device,id,thumb);
  if (ret != 0) {
    printf("Couldn't send thumbnail\n");
    LIBMTP_Dump_Errorstack(device);
    LIBMTP_Clear_Errorstack(device);
  }

  free(imagedata);
  LIBMTP_destroy_filesampledata_t(thumb);

  LIBMTP_Release_Device(device);
  printf("OK.\n");
  return 0;
}
Esempio n. 7
0
int main (int argc, char **argv) {
  int opt;
  extern int optind;
  extern char *optarg;
  LIBMTP_mtpdevice_t *device = NULL;
  int idcount = 0;
  uint32_t *ids = NULL;
  uint32_t *tmp = NULL;
  char *playlistname = NULL;
  char *rest;
  uint32_t storageid = 0;
  uint32_t parentid = 0;
 
  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");

  while ( (opt = getopt(argc, argv, "hn:i:s:p:")) != -1 ) {
    switch (opt) {
    case 'h':
      usage();
    case 'i':
      idcount++;
      if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) {
        printf("realloc failed\n");
        return 1;
      }
      ids = tmp;
      ids[(idcount-1)] = strtoul(optarg, &rest, 0);
      break;
    case 'n':
      playlistname = strdup(optarg);
      break;
    case 's':
      storageid = (uint32_t) strtoul(optarg, NULL, 0);
	  break;
    case 'p':
      parentid = (uint32_t) strtoul(optarg, NULL, 0);
	  break;
    default:
      usage();
    }
  }
  argc -= optind;
  argv += optind;

  if ( playlistname == NULL) {
    printf("You need to supply a playlist name.\n");
    usage();
  }

  if (idcount == 0) {
    printf("You need to supply one or more track IDs\n");
    usage();
  }

    
  LIBMTP_Init();
  device = LIBMTP_Get_First_Device();
  if (device == NULL) {
    printf("No devices.\n");
    return 0;
  }

  LIBMTP_playlist_t *playlist = LIBMTP_new_playlist_t();
  playlist->name = playlistname;
  playlist->no_tracks = idcount;
  playlist->tracks = ids;
  playlist->parent_id = parentid;
  playlist->storage_id = storageid;
  int ret = LIBMTP_Create_New_Playlist(device,playlist);
  if (ret != 0) {
    printf("Couldn't create playlist object\n");
    LIBMTP_Dump_Errorstack(device);
    LIBMTP_Clear_Errorstack(device);
  }
  else {
    printf("Created new playlist: %u\n", playlist->playlist_id);
  }

  LIBMTP_Release_Device(device);
  printf("OK.\n");
  return 0;
}