bool entryLessThan(const Protos::Common::Entry& e1, const Protos::Common::Entry& e2) { std::string s1; std::string s2; if (e1.has_shared_dir() && e2.has_shared_dir()) { s1 = e1.shared_dir().shared_name(); s2 = e2.shared_dir().shared_name(); std::transform(s1.begin(), s1.end(), s1.begin(), tolower); std::transform(s2.begin(), s2.end(), s2.begin(), tolower); } if (s1 == s2) { std::string p1 = e1.path(); std::string p2 = e2.path(); std::transform(p1.begin(), p1.end(), p1.begin(), tolower); std::transform(p2.begin(), p2.end(), p2.begin(), tolower); if (p1 == p2) { std::string n1 = e1.name(); std::string n2 = e2.name(); std::transform(n1.begin(), n1.end(), n1.begin(), tolower); std::transform(n2.begin(), n2.end(), n2.begin(), tolower); return n1 < n2; } else return p1 < p2; } else return s1 < s2; }
/** * To know if a given entry is already in queue. It depends of (shared dir id, name, path). */ bool DownloadQueue::isEntryAlreadyQueued(const Protos::Common::Entry& localEntry) { QMap<std::string, Download*>::const_iterator i = this->downloadsIndexedByName.constFind(localEntry.name()); while (i != this->downloadsIndexedByName.constEnd() && i.key() == localEntry.name()) { if ( i.value()->getLocalEntry().path() == localEntry.path() && (!localEntry.has_shared_dir() || i.value()->getLocalEntry().shared_dir().id().hash() == localEntry.shared_dir().id().hash()) ) return true; ++i; } return false; }
/** * Try to select an entry from a remote peer in the browse tab. * The entry to browse is set in 'this->remoteEntryToBrowse'. */ void BrowseWidget::tryToReachEntryToBrowse() { if (!this->tryingToReachEntryToBrowse) return; // First we search for the shared directory of the entry. for (int r = 0; r < this->browseModel.rowCount(); r++) { QModelIndex currentIndex = this->browseModel.index(r, 0); Protos::Common::Entry root = this->browseModel.getEntry(currentIndex); if (root.has_shared_dir() && this->remoteEntryToBrowse.has_shared_dir() && root.shared_dir().id().hash() == this->remoteEntryToBrowse.shared_dir().id().hash()) { // Then we try to match each folder name. If a folder cannot be reached then we ask to expand the last folder. // After the folder entries are loaded, 'tryToReachEntryToBrowse()' will be recalled via the signal 'BrowseModel::loadingResultFinished()'. const QStringList& path = Common::ProtoHelper::getStr(this->remoteEntryToBrowse, &Protos::Common::Entry::path).append(Common::ProtoHelper::getStr(this->remoteEntryToBrowse, &Protos::Common::Entry::name)).split('/', QString::SkipEmptyParts); for (QStringListIterator i(path); i.hasNext();) { QModelIndex childIndex = this->browseModel.searchChild(i.next(), currentIndex); if (!childIndex.isValid()) { this->ui->treeView->expand(currentIndex); return; } currentIndex = childIndex; // We reach the last entry name (file or directory), we just have to show and select it. if (!i.hasNext()) { this->ui->treeView->scrollTo(currentIndex); this->ui->treeView->selectionModel()->select(currentIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } } } } this->tryingToReachEntryToBrowse = false; }