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

void MtpDevice::createFolderStructure ( MTP::Folder in_root,
bool  firstRun 
) [private]

Recursively builds the folder structure

Parameters:
in_root the root folder on the device
firstRun whether to retreive a fresh list of folders from the device

Definition at line 395 of file MtpDevice.cpp.

References MTP::Folder::AddChildFolder(), find(), MTP::Folder::FolderCount(), MTP::Folder::Name(), MTP::Folder::RawFolder(), and MTP::Folder::SetRowIndex().

Referenced by createObjectStructure().

{
  if (!_device)
    return;
  vector<MTP::Folder*> curLevelFolders;
  LIBMTP_folder_t* rootFolder;
  if (!in_root && firstRun)
  {
     rootFolder= LIBMTP_Get_Folder_List(_device);
     LIBMTP_folder_t* fakeRoot = LIBMTP_new_folder_t();
     fakeRoot->folder_id = 0;
     fakeRoot->parent_id = 0;
     fakeRoot->name = strdup(_name);
     fakeRoot->sibling= NULL;
     fakeRoot->child = rootFolder;
     rootFolder = fakeRoot;
  }
  else
    rootFolder = in_root->RawFolder()->child;

  while (rootFolder)
  {
    //if there is a parent, set the new folder's parent. And add to the 
    //parent's childlist
    MTP::Folder* currentFolder;
    if(in_root)
    {
      currentFolder =  new MTP::Folder(rootFolder, in_root);
      currentFolder->SetRowIndex(in_root->FolderCount());
      in_root->AddChildFolder(currentFolder);
    }
    else //else set the child's parent to NULL indicating its at the root
    {
      assert(_rootFolder ==NULL);
      currentFolder =  new MTP::Folder(rootFolder, NULL);
      //set the row index first as it is zero based
      currentFolder->SetRowIndex(0);
      //set the root folder
      _rootFolder = currentFolder;
    }

    //add this folder to the list of folders at this level
    curLevelFolders.push_back(currentFolder);
    
    //find
    MTP::Folder* const previous = (MTP::Folder*) (find(currentFolder->ID(), 
                                                     MtpFolder));
    if(previous)
    {
      cerr << "Folder crosslinked with another folder please file a bug report at: "
           << "caffein@gmail.com" << endl;
      cerr << " Previous folder's name: " << previous->Name() << endl;
      cerr << " New file's name: " << currentFolder->Name() << endl;
      assert(false);

    }

    _folderMap[currentFolder->ID()] = currentFolder; 

    rootFolder = rootFolder->sibling;
  }
  for (count_t i =0; i < curLevelFolders.size(); i++)
      createFolderStructure(curLevelFolders[i], false);
}


Generated by  Doxygen 1.6.0   Back to index