Logo Search packages:      
Sourcecode: qlix version File versions  Download package

void MtpDevice::createTrackBasedStructures (  )  [private]

Retreives the album and track list then Iterates over all the Albums and their tracks. Each track is looked up in the object map and added to the Album's list of child tracks

Definition at line 550 of file MtpDevice.cpp.

References MTP::Playlist::AddTrack(), MTP::Album::AddTrack(), MTP::Playlist::ChildTrackID(), MTP::Album::ChildTrackID(), find(), MTP::Album::Name(), MTP::Track::Name(), MTP::Playlist::SetInitialized(), MTP::Album::SetInitialized(), MTP::Playlist::SetRowIndex(), MTP::Album::SetRowIndex(), MTP::Playlist::TrackCount(), and MTP::Album::TrackCount().

Referenced by createObjectStructure().

{
  LIBMTP_album_t* albumRoot= LIBMTP_Get_Album_List(_device);
  LIBMTP_track_t* trackRoot = LIBMTP_Get_Tracklisting_With_Callback(_device, NULL, NULL);
  LIBMTP_playlist_t* playlistRoot = LIBMTP_Get_Playlist_List(_device);

  //create the wrapper tracks
  while (trackRoot)
  {
    MTP::Track* currentTrack = new MTP::Track(trackRoot);
    cout <<"Creating track: " << currentTrack << endl;
    cout << "Inserting track with ID: " << currentTrack->ID() << endl;

    MTP::Track * prev_track = 
                             (MTP::Track*) find(currentTrack->ID(), MtpTrack);

    MTP::File * previousFile =  
                                (MTP::File*) find(currentTrack->ID(), MtpFile);

    //ensure that there exists a file association                                
    if(!previousFile || previousFile->ID() != currentTrack->ID())
    {
      cerr << "Qlix internal database corruption! please report this to: " <<
              "caffein@gmail.com as this is a fairly serious error!" << endl;
      assert(false);
    }

    //crosslink check with previous tracks 
    if (prev_track)
    {
      cerr << "Track crosslinked with another track! Please report this to" 
           << "caffein@gmail.com" << endl;
      cerr << "Previous tracks's name: " << prev_track->Name() << endl;
      cerr << "New track's name: " << currentTrack->Name() << endl;
      assert(false);
    }

    //now crossreference the track with the file and the file with the track
    previousFile->Associate(currentTrack);
    currentTrack->Associate(previousFile);
    cout <<"Track:" << currentTrack << " associated with file: " << previousFile<< endl;
    cout <<"File:" << previousFile << " associated with Track: " << currentTrack <<endl;
    MTP::GenericObject* previousTrack = _trackMap[currentTrack->ID()];
    if (previousTrack)
    {
      cerr << "Track crosslinked with another track! please report this to " 
           <<" caffein@gmail.com"<< endl;
      assert(false);
    }
    _trackMap[currentTrack->ID()] = currentTrack;
    trackRoot = trackRoot->next;
  }

  //create the wrapper albums and add its child tracks 
  while (albumRoot)
  {
    LIBMTP_filesampledata_t temp;
    LIBMTP_Get_Representative_Sample(_device, albumRoot->album_id, &temp); 
#ifdef QLIX_DEBUG
    cout << "Discovered a sample of type: " << temp.filetype 
         << " with height: " << temp.height << " and width: "
         << temp.width << " with size: " << temp.size << endl;
#endif

    MTP::Album* currentAlbum = new MTP::Album(albumRoot, temp);
    currentAlbum->SetRowIndex( _albums.size());
    _albums.push_back(currentAlbum);

    MTP::Album * const prev_album = 
                             (MTP::Album*) find(currentAlbum->ID(), MtpAlbum);
    MTP::File * const file_association =
                               (MTP::File*) find(currentAlbum->ID(), MtpFile);

    //crosslink check with file database
    if(!file_association)
    {
      cerr << "Album not crosslinked with file as expected!" << 
               " Please report this to caffein@gmail.com" << endl;
      cerr << "New album's name: " << currentAlbum->Name() << endl;
      assert(false);
    }

    //crosslink check with albums
    if (prev_album)
    {
      cerr << "Album crosslinked with another album! Please report this to" 
           << "caffein@gmail.com" << endl;
      cerr << "Previous album's name: " << prev_album->Name() << endl;
      cerr << "New album's name: " << currentAlbum->Name() << endl;
      assert(false);
    }

    //now crossreference the album with the file and the file with the album 
    file_association->Associate(currentAlbum);
    currentAlbum->Associate(file_association);

    _albumMap[currentAlbum->ID()] = currentAlbum; 


    //now iterate over the albums's children..
    for (count_t j = 0; j < currentAlbum->TrackCount(); j++)
    {
      uint32_t track_id = currentAlbum->ChildTrackID(j);
      //sanity check
      //This is not a const * const as it will be modified once its added
      MTP::Track * const track = (MTP::Track*) find(track_id, MtpTrack);
      if(!track)
      {
        cerr << "Current track: " << track_id << " does not exist.. skipping"
        << " this usually happens when MTP programs do not remove files " 
        << " correctly" << endl;
        //TODO add an autocorrect option here
        //report this to caffein@gmail.com" << endl;
        //assert(false);
        continue;
      }
      currentAlbum->AddTrack(track);
    }

    currentAlbum->SetInitialized();
    albumRoot = albumRoot->next;
  }

  while(playlistRoot)
  {

    MTP::Playlist* currentPlaylist = new MTP::Playlist(playlistRoot);
    //set the row index first, as it is zero based
    currentPlaylist->SetRowIndex(_playlists.size());
    _playlists.push_back(currentPlaylist);

    MTP::Playlist* prev_playlist= (MTP::Playlist*) find(currentPlaylist->ID(), MtpPlaylist);
    MTP::File* file_association= (MTP::File*) find(currentPlaylist->ID(), MtpFile);
    
    //crosslink check with file database
    if (file_association)
    {
       cerr << "Playlist not crosslinked with file as expected!" << 
               " Please report this to caffein@gmail.com" << endl;
       assert(false);
    }

    //crosslink check with albums
    if (prev_playlist)
    {
      cerr << "Playlist crosslinked with another playlist! Please report this "
           << "to caffein@gmail.com" << endl;
      assert(false);
    }

    //now crossreference the playlist with the file
    //and crossreference the file with the playlist 
    currentPlaylist->Associate(file_association);
    file_association->Associate(currentPlaylist);

    _playlistMap[currentPlaylist->ID()] = currentPlaylist; 

    //now iterate over the playlist's children..
    for (count_t j = 0; j < currentPlaylist->TrackCount(); j++)
    {
      uint32_t track_id = currentPlaylist->ChildTrackID(j);
      //sanity check
      MTP::Track const * const track = (MTP::Track*) find(track_id, MtpTrack);

      if (!track)
      {
        cerr << "Current track: " << track_id << "belongs to a playlist but"
             << " does not exist on the device. This usually happens when"
             << " faulty MTP programs delete items from the device."
             << " Please report this to caffein@gmail.com" << endl;
        assert(false);
        //TODO add an autocorrect option
      }
      currentPlaylist->AddTrack( (MTP::Track*) track );
    }
    currentPlaylist->SetInitialized();

    playlistRoot = playlistRoot->next;
  }
}


Generated by  Doxygen 1.6.0   Back to index