Location * LocationsFactory::setNewPath(const QString& uPath, const QString& authUser, const QString& passwd, bool savePassword) { storeValidFileInfo(0); CleanUrl url(uPath); m_lastUrlNeedsAuthentication = false; NetAuthenticationData authData(authUser, passwd); if (authData.isEmpty() && url.hasAuthenticationData()) { authData.user = url.user(); authData.password = url.password(); } Location *location = parse(url.cleanUrl()); if (location) { DirItemInfo *item = validateCurrentUrl(location,authData); if (item) { //now if there is Authentication Data //at this point item is ready and authentication if necessary worked if (item && !authData.isEmpty()) { m_authDataStore->store(item->authenticationPath(), authData.user, authData.password, savePassword); } //isContentReadable() must already carry execution permission if (item->isValid() && item->isBrowsable() && item->isContentReadable()) { location->setInfoItem(item); if (location != m_curLoc) { if (m_curLoc) { m_curLoc->stopWorking(); } emit locationChanged(m_curLoc, location); location->startWorking(); m_curLoc = location; } } else { storeValidFileInfo(item); location = 0; } } else { // not valid location = 0; } } #if DEBUG_MESSAGES qDebug() << Q_FUNC_INFO << "input path:" << uPath << "location result:" << location; #endif return location; }
DirItemInfo * LocationsFactory::validateCurrentUrl(Location *location, const NetAuthenticationData &authData) { //when there is authentication data, set the authentication before validating an item if (location->isRemote()) { if (!authData.isEmpty()) { location->setAuthentication(authData.user, authData.password); } else { //reset the password even it was set before, it is necessary to browse other items location->setAuthentication(NetAuthenticationData::currentUser(), NetAuthenticationData::noPassword()); } } DirItemInfo *item = location->validateUrlPath(m_tmpPath); //for remote loacations, authentication might have failed //if so try to use a stored authentication data and authenticate it again if (location->isRemote() && item != 0) { if ( item->needsAuthentication() && location->useAuthenticationDataIfExists(*item)) { delete item; item = location->validateUrlPath(m_tmpPath); } //if failed it is necessary to ask the user to provide user/password if ( item != 0 && item->needsAuthentication() ) { location->notifyItemNeedsAuthentication(item); delete item; item = 0; } } //now just see if the item is readable if (item != 0 && !item->isContentReadable()) { delete item; item = 0; } return item; }
DirItemInfo * DiskLocation::validateUrlPath(const QString& uPath) { QString myPath(uPath); QFileInfo tmpUrl(uPath); if (tmpUrl.isRelative() && m_info) { tmpUrl.setFile(m_info->absoluteFilePath(), uPath); myPath = tmpUrl.absoluteFilePath(); } #if DEBUG_MESSAGES qDebug() << Q_FUNC_INFO << "path:" << myPath; #endif DirItemInfo * item = new DirItemInfo(myPath); if (!item->isValid() || !item->exists() || !item->isContentReadable()) { delete item; item = 0; } return item; }