void Konsole::sync() { if(!KileConfig::syncConsoleDirWithTabs()) { return; } KTextEditor::Document *doc = m_ki->activeTextDocument(); KTextEditor::View *view = Q_NULLPTR; if(doc) { view = doc->views().first(); } if(view) { QString finame; QUrl url = view->document()->url(); if(url.path().isEmpty()) { return; } QFileInfo fic(url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path()); if(fic.isReadable()) { setDirectory(url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path()); } } }
// copy a file to the vfs (physical) void ftp_vfs::vfs_addFiles(const QList<QUrl> &fileUrls, KIO::CopyJob::CopyMode mode, QObject* toNotify, QString dir, PreserveMode /*pmode*/) { QUrl destUrl = vfs_origin; if (!dir.isEmpty()) { destUrl.setPath(QDir::cleanPath(destUrl.path() + '/' + dir)); if (destUrl.scheme() == "tar" || destUrl.scheme() == "zip" || destUrl.scheme() == "krarc") { if (QDir(destUrl.adjusted(QUrl::StripTrailingSlash).path()).exists()) destUrl.setScheme("file"); // if we get out from the archive change the protocol } } KIO::Job* job = 0; switch (mode) { case KIO::CopyJob::Copy: job = KIO::copy(fileUrls, destUrl); break; case KIO::CopyJob::Move: job = KIO::move(fileUrls, destUrl); break; case KIO::CopyJob::Link: job = KIO::link(fileUrls, destUrl); break; } connect(job, SIGNAL(result(KJob*)), this, SLOT(vfs_refresh(KJob*))); if (mode == KIO::CopyJob::Move) // notify the other panel connect(job, SIGNAL(result(KJob*)), toNotify, SLOT(vfs_refresh(KJob*))); }
bool MercurialPlugin::isValidDirectory(const QUrl &directory) { // Mercurial uses the same test, so we don't lose any functionality static const QString hgDir(".hg"); if (m_lastRepoRoot.isParentOf(directory)) return true; const QString initialPath(directory.adjusted(QUrl::StripTrailingSlash).toLocalFile()); const QFileInfo finfo(initialPath); QDir dir; if (finfo.isFile()) { dir = finfo.absoluteDir(); } else { dir = QDir(initialPath); dir.makeAbsolute(); } while (!dir.cd(hgDir) && dir.cdUp()) {} // cdUp, until there is a sub-directory called .hg if (hgDir != dir.dirName()) return false; dir.cdUp(); // Leave .hg // TODO: Check whether this is the right port, original code was: m_lastRepoRoot.setDirectory(dir.absolutePath()); m_lastRepoRoot.setPath(dir.absolutePath()); return true; }
bool Manager::copyAppData(const QUrl &src, const QString& subdir, const QString& fileName) { //let saveLocation find and create the appropriate place to //store the templates (usually $HOME/.kde/share/apps/kile/templates) QString dir = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + '/' + subdir; QUrl targetURL = QUrl::fromUserInput(dir); targetURL = targetURL.adjusted(QUrl::StripTrailingSlash); targetURL.setPath(targetURL.path() + '/' + fileName); //if a directory is found if (!dir.isNull()) { // create dir if not existing, needed for copyjob QDir testDir(dir); if (!testDir.exists()){ testDir.mkpath(dir); } // copy file KIO::FileCopyJob* copyJob = KIO::file_copy(src, targetURL); KJobWidgets::setWindow(copyJob, m_kileInfo->mainWindow()); return copyJob->exec(); } else { KMessageBox::error(Q_NULLPTR, i18n("Could not find a folder to save %1 to.\nCheck whether you have a .kde folder with write permissions in your home folder.", fileName)); return false; } }
QString CoreDbUrl::album() const { // obey trailing slash in the path - albums have a trailing slash // get result without trailing slash QUrl url = adjusted(QUrl::RemoveFilename); return ( url.adjusted(QUrl::StripTrailingSlash).path() ); }
void MainWindow::save(QUrl url) { //if saving process was aborted if(!url.isValid()) return; QString path = url.toLocalFile(); //if no file suffix was chosen, automatically use the PNG format QFileInfo file(path); if(!file.baseName().isEmpty() && file.suffix().isEmpty()) path += ".png"; QString suffix = file.suffix(); //Qt can only read tga, saving is not supported if(suffix.toLower() == "tga") suffix = "png"; //append a suffix to the map names (result: path/original_normal.png) QString name_normal = file.absolutePath() + "/" + file.baseName() + "_normal." + suffix; QString name_specular = file.absolutePath() + "/" + file.baseName() + "_spec." + suffix; QString name_displace = file.absolutePath() + "/" + file.baseName() + "_displace." + suffix; bool successfullySaved = true; if(ui->checkBox_queue_generateNormal->isChecked()) { if(normalmap.isNull()) ui->statusBar->showMessage("calculating normalmap..."); calcNormal(); successfullySaved &= normalmap.save(name_normal); } if(ui->checkBox_queue_generateSpec->isChecked()) { if(specmap.isNull()) ui->statusBar->showMessage("calculating specularmap..."); calcSpec(); successfullySaved &= specmap.save(name_specular); } if(ui->checkBox_queue_generateDisplace->isChecked()) { if(displacementmap.isNull()) ui->statusBar->showMessage("calculating displacementmap..."); calcDisplace(); successfullySaved &= displacementmap.save(name_displace); } if(successfullySaved) ui->statusBar->showMessage("Maps successfully saved", 4000); else QMessageBox::information(this, "Maps not saved", "One or more of the maps was NOT saved!"); //store export path setExportPath(url.adjusted(QUrl::RemoveFilename)); //enable "Open Export Folder" gui button ui->pushButton_openExportFolder->setEnabled(true); }
CamItemInfo& ImportIconView::camItemInfoRef(const QString& folder, const QString& file) { QUrl url = QUrl::fromLocalFile(folder); url = url.adjusted(QUrl::StripTrailingSlash); url.setPath(url.path() + QLatin1Char('/') + (file)); QModelIndex indexForCamItemInfo = importFilterModel()->indexForPath(url.toLocalFile()); QModelIndex mappedIndex = importFilterModel()->mapToSource(indexForCamItemInfo); return importImageModel()->camItemInfoRef(mappedIndex); }
bool CliInterface::extractFiles(const QVector<Archive::Entry*> &files, const QString &destinationDirectory, const ExtractionOptions &options) { qCDebug(ARK) << Q_FUNC_INFO << "to" << destinationDirectory; m_operationMode = Extract; m_extractionOptions = options; m_extractedFiles = files; m_extractDestDir = destinationDirectory; if (!m_cliProps->property("passwordSwitch").toString().isEmpty() && options.encryptedArchiveHint() && password().isEmpty()) { qCDebug(ARK) << "Password hint enabled, querying user"; if (!passwordQuery()) { return false; } } QUrl destDir = QUrl(destinationDirectory); QDir::setCurrent(destDir.adjusted(QUrl::RemoveScheme).url()); const bool useTmpExtractDir = options.isDragAndDropEnabled() || options.alwaysUseTempDir(); if (useTmpExtractDir) { // Create an hidden temp folder in the current directory. m_extractTempDir.reset(new QTemporaryDir(QStringLiteral(".%1-").arg(QCoreApplication::applicationName()))); qCDebug(ARK) << "Using temporary extraction dir:" << m_extractTempDir->path(); if (!m_extractTempDir->isValid()) { qCDebug(ARK) << "Creation of temporary directory failed."; emit finished(false); return false; } m_oldWorkingDir = QDir::currentPath(); destDir = QUrl(m_extractTempDir->path()); QDir::setCurrent(destDir.adjusted(QUrl::RemoveScheme).url()); } return runProcess(m_cliProps->property("extractProgram").toString(), m_cliProps->extractArgs(filename(), extractFilesList(files), options.preservePaths(), password())); }
KIO::TransferJob * Resource::getTransferJob(const QString &uri, const QString &token) const { QUrl url = baseUrl; url = url.adjusted(QUrl::StripTrailingSlash); url.setPath(url.path() + '/' + uri); KIO::TransferJob *job = KIO::get(url, KIO::Reload, KIO::HideProgressInfo); if (!token.isEmpty()) job->addMetaData("customHTTPHeader", "Authorization: token " + token); return job; }
QUrl normalizeUrl(QUrl url) { url = url.adjusted(QUrl::RemoveFragment | QUrl::NormalizePathSegments | QUrl::StripTrailingSlash); if (url.path() == QLatin1String("/")) { url.setPath(QString()); } return url; }
// This function should only be called when: // - KFileItem is called with a QUrl object directly! // - refresh is called. // This is done to re-populate the UDSEntry object. void KFileItemPrivate::stat() { if(m_url.isLocalFile()) { QT_STATBUF buf; const QString path = m_url.adjusted(QUrl::StripTrailingSlash).toLocalFile(); const QByteArray pathBA = QFile::encodeName(path); if (QT_LSTAT(pathBA.constData(), &buf) == 0) { m_entry = KIO::UDSEntry(buf, m_url.fileName()); } } }
void Resource::authenticate(const QString &name, const QString &password) { QUrl url = baseUrl; url = url.adjusted(QUrl::StripTrailingSlash); url.setPath(url.path() + '/' + "/authorizations"); QByteArray data = "{ \"scopes\": [\"repo\"], \"note\": \"KDevelop Github Provider\" }"; KIO::StoredTransferJob *job = KIO::storedHttpPost(data, url, KIO::HideProgressInfo); job->addMetaData("customHTTPHeader", "Authorization: Basic " + QString (name + ':' + password).toUtf8().toBase64()); connect(job, &KIO::StoredTransferJob::result, this, &Resource::slotAuthenticate); job->start(); }
bool BupSlave::checkCorrectRepository(const QUrl &pUrl, QStringList &pPathInRepository) { // make this slave accept most URLs.. even incorrect ones. (no slash (wrong), // one slash (correct), two slashes (wrong), three slashes (correct)) QString lPath; if(!pUrl.host().isEmpty()) { lPath = QStringLiteral("/") + pUrl.host() + pUrl.adjusted(QUrl::StripTrailingSlash).path() + '/'; } else { lPath = pUrl.adjusted(QUrl::StripTrailingSlash).path() + '/'; if(!lPath.startsWith(QLatin1Char('/'))) { lPath.prepend(QLatin1Char('/')); } } if(mRepository && mRepository->isValid()) { if(lPath.startsWith(mRepository->objectName())) { lPath.remove(0, mRepository->objectName().length()); pPathInRepository = lPath.split(QLatin1Char('/'), QString::SkipEmptyParts); return true; } else { delete mRepository; mRepository = NULL; } } pPathInRepository = lPath.split(QLatin1Char('/'), QString::SkipEmptyParts); QString lRepoPath = QStringLiteral("/"); while(!pPathInRepository.isEmpty()) { // make sure the repo path will end with a slash lRepoPath += pPathInRepository.takeFirst(); lRepoPath += QStringLiteral("/"); if((QFile::exists(lRepoPath + QStringLiteral("objects")) && QFile::exists(lRepoPath + QStringLiteral("refs"))) || (QFile::exists(lRepoPath + QStringLiteral(".git/objects")) && QFile::exists(lRepoPath + QStringLiteral(".git/refs")))) { mRepository = new Repository(NULL, lRepoPath); return mRepository->isValid(); } } return false; }
void KFileItemPrivate::init() { m_access.clear(); // metaInfo = KFileMetaInfo(); // stat() local files if needed // TODO: delay this until requested if (m_fileMode == KFileItem::Unknown || m_permissions == KFileItem::Unknown || m_entry.count() == 0) { if (m_url.isLocalFile()) { /* directories may not have a slash at the end if * we want to stat() them; it requires that we * change into it .. which may not be allowed * stat("/is/unaccessible") -> rwx------ * stat("/is/unaccessible/") -> EPERM H.Z. * This is the reason for the StripTrailingSlash */ QT_STATBUF buf; const QString path = m_url.adjusted(QUrl::StripTrailingSlash).toLocalFile(); const QByteArray pathBA = QFile::encodeName(path); if (QT_LSTAT(pathBA.constData(), &buf) == 0) { m_entry.insert(KIO::UDSEntry::UDS_DEVICE_ID, buf.st_dev); m_entry.insert(KIO::UDSEntry::UDS_INODE, buf.st_ino); mode_t mode = buf.st_mode; if ((buf.st_mode & QT_STAT_MASK) == QT_STAT_LNK) { m_bLink = true; if (QT_STAT(pathBA, &buf) == 0) { mode = buf.st_mode; } else {// link pointing to nowhere (see FileProtocol::createUDSEntry() in ioslaves/file/file.cpp) mode = (QT_STAT_MASK - 1) | S_IRWXU | S_IRWXG | S_IRWXO; } } m_entry.insert(KIO::UDSEntry::UDS_SIZE, buf.st_size); m_entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, buf.st_mode & QT_STAT_MASK); // extract file type m_entry.insert(KIO::UDSEntry::UDS_ACCESS, buf.st_mode & 07777); // extract permissions m_entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, buf.st_mtime); // TODO: we could use msecs too... m_entry.insert(KIO::UDSEntry::UDS_ACCESS_TIME, buf.st_atime); #ifndef Q_OS_WIN m_entry.insert(KIO::UDSEntry::UDS_USER, KUser(buf.st_uid).loginName()); m_entry.insert(KIO::UDSEntry::UDS_GROUP, KUserGroup(buf.st_gid).name()); #endif // TODO: these can be removed, we can use UDS_FILE_TYPE and UDS_ACCESS everywhere if (m_fileMode == KFileItem::Unknown) { m_fileMode = mode & QT_STAT_MASK; // extract file type } if (m_permissions == KFileItem::Unknown) { m_permissions = mode & 07777; // extract permissions } } } } }
bool ftp_vfs::populateVfsList(const QUrl &origin, bool showHidden) { QString errorMsg; if (!origin.isValid()) errorMsg = i18n("Malformed URL:\n%1", origin.url()); if (!KProtocolManager::supportsListing(origin)) { if (origin.scheme() == "ftp" && KProtocolManager::supportsReading(origin)) errorMsg = i18n("Krusader does not support FTP access via HTTP.\nIf it is not the case, please check and change the proxy settings in the System Settings."); else errorMsg = i18n("Protocol not supported by Krusader:\n%1", origin.url()); } if (!errorMsg.isEmpty()) { printf("error\n"); if (!quietMode) emit error(errorMsg); return false; } busy = true; vfs_origin = origin.adjusted(QUrl::StripTrailingSlash); //QTimer::singleShot( 0,this,SLOT(startLister()) ); listError = false; // Open the directory marked by origin KIO::Job *job = KIO::listDir(vfs_origin, KIO::HideProgressInfo, showHidden); connect(job, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)), this, SLOT(slotAddFiles(KIO::Job*, const KIO::UDSEntryList&))); connect(job, SIGNAL(redirection(KIO::Job*, const QUrl&)), this, SLOT(slotRedirection(KIO::Job*, const QUrl&))); connect(job, SIGNAL(permanentRedirection(KIO::Job*, const QUrl&, const QUrl&)), this, SLOT(slotPermanentRedirection(KIO::Job*, const QUrl&, const QUrl&))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotListResult(KJob*))); if(!parentWindow.isNull()) { KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(job->uiDelegate()); ui->setWindow(parentWindow); } if (!quietMode) { emit startJob(job); } while (busy && vfs_processEvents()); if (listError) return false; return true; }
void KonqPopupMenuPrivate::slotShowOriginalFile() { const KFileItem item = m_popupItemProperties.items().first(); QUrl destUrl = QUrl::fromLocalFile(item.linkDest()); if (!destUrl.isValid()) { return; } // Now destUrl points to the target file, let's go up to parent dir destUrl = destUrl.adjusted(QUrl::RemoveFilename); KRun::runUrl(destUrl, QStringLiteral("inode/directory"), m_parentWidget); }
CamItemInfo ImportIconView::camItemInfo(const QString& folder, const QString& file) { QUrl url = QUrl::fromLocalFile(folder); url = url.adjusted(QUrl::StripTrailingSlash); url.setPath(url.path() + QLatin1Char('/') + (file)); QModelIndex indexForCamItemInfo = importFilterModel()->indexForPath(url.toLocalFile()); if(indexForCamItemInfo.isValid()) { return importFilterModel()->camItemInfo(indexForCamItemInfo); } return CamItemInfo(); }
void QmlFile::setUrl(const QString& text) { QString textWithSlashes = text; QUrl url = textWithSlashes.replace('\\', "/"); QUrl::FormattingOptions options = QUrl::RemoveScheme | QUrl::RemovePassword | QUrl::RemoveUserInfo | QUrl::RemovePort | QUrl::RemoveAuthority | QUrl::RemoveQuery; #ifdef Q_OS_WIN // If the scheme is a drive letter, do not remove it. if (url.scheme().size() == 1) options ^= QUrl::RemoveScheme; QUrl adj = url.adjusted(options); QString s = adj.toString(); // If there is a slash before a drive letter. // On Windows, file URLs look like file:///C:/Users/.... // The scheme is removed but only "://" (not 3 slashes) between scheme and path. if (s.size() > 2 && s[0] == '/' && s[2] == ':') { // Remove the leading slash. s = s.right(s.size() - 1); adj = QUrl(s); } #else QUrl adj = url.adjusted(options); #endif if(m_url != adj) { m_url = adj; emit urlChanged(m_url); } }
Groups::Groups(QSharedPointer<Zotero::API> api, QObject *parent) : QObject(parent), d(new Zotero::Groups::Private(api, this)) { QUrl url = api->baseUrl(); Q_ASSERT_X(url.path().contains(QLatin1String("users/")), "Groups::Groups(QSharedPointer<Zotero::API> api, QObject *parent)", "Provided base URL does not contain 'users/' as expected"); url = url.adjusted(QUrl::StripTrailingSlash); url.setPath(url.path() + QStringLiteral("/groups")); if (d->api->inBackoffMode()) QTimer::singleShot((d->api->backoffSecondsLeft() + 1) * 1000, [ = ]() { d->requestZoteroUrl(url); }); else d->requestZoteroUrl(url); }
void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value) { if (role == "text") { const KFileItem item = m_model->fileItem(index); const QString newName = value.toString(); if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) { const QUrl oldUrl = item.url(); QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename); newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); KIO::Job* job = KIO::moveAs(oldUrl, newUrl); KJobWidgets::setWindow(job, this); KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); job->ui()->setAutoErrorHandlingEnabled(true); } } }
FSTBaker::FSTBaker(const QUrl& inputMappingURL, const QString& bakedOutputDirectory, const QString& originalOutputDirectory, bool hasBeenBaked) : ModelBaker(inputMappingURL, bakedOutputDirectory, originalOutputDirectory, hasBeenBaked) { if (hasBeenBaked) { // Look for the original model file one directory higher. Perhaps this is an oven output directory. QUrl originalRelativePath = QUrl("../original/" + inputMappingURL.fileName().replace(BAKED_FST_EXTENSION, FST_EXTENSION)); QUrl newInputMappingURL = inputMappingURL.adjusted(QUrl::RemoveFilename).resolved(originalRelativePath); _modelURL = newInputMappingURL; } _mappingURL = _modelURL; { // Unused, but defined for consistency auto bakedFilename = _modelURL.fileName(); bakedFilename.replace(FST_EXTENSION, BAKED_FST_EXTENSION); _bakedModelURL = _bakedOutputDir + "/" + bakedFilename; } }
QList< ReferencedTopDUContext > ParseSession::contextForThisPackage(IndexedString package) { QList<ReferencedTopDUContext> contexts; QUrl url = package.toUrl(); QDir path(url.adjusted(QUrl::RemoveFilename).path()); if(path.exists()) { int priority = BackgroundParser::WorstPriority; if(!forExport) priority = -1; //import this package as soon as possible else if(m_priority<=-1) priority = BackgroundParser::WorstPriority-2;//all needed files should be scheduled already else priority = m_priority;//currently parsejob does not get created in this cases to reduce recursion QStringList files = path.entryList(QStringList("*.go"), QDir::Files | QDir::NoSymLinks); bool shouldReparse=false; for(QString filename : files) { filename = path.filePath(filename); QFile file(filename); if(!file.exists()) continue; if(forExport && filename.endsWith("_test.go")) continue; IndexedString url(filename); DUChainReadLocker lock; ReferencedTopDUContext context = DUChain::self()->chainForDocument(url); lock.unlock(); if(context) contexts.append(context); else { if(scheduleForParsing(url, priority, (TopDUContext::Features)(TopDUContext::ForceUpdate | TopDUContext::AllDeclarationsAndContexts))) shouldReparse=true; } } if(shouldReparse) scheduleForParsing(m_document, priority+1, (TopDUContext::Features)(m_features | TopDUContext::ForceUpdate)); } return contexts; }
void KexiStartupFileHandler::saveRecentDir() { if (!d->recentDirClass.isEmpty()) { qDebug() << d->recentDirClass; QUrl dirUrl; if (d->requester) dirUrl = d->requester->url(); //removed in KEXI3 else if (d->dialog) //removed in KEXI3 dirUrl = d->dialog->selectedUrl(); qDebug() << dirUrl; if (dirUrl.isValid() && dirUrl.isLocalFile()) { dirUrl = dirUrl.adjusted(QUrl::RemoveFilename); dirUrl.setPath(dirUrl.path() + QString()); qDebug() << "Added" << dirUrl.url() << "to recent dirs class" << d->recentDirClass; KRecentDirs::add(d->recentDirClass, dirUrl.url()); } } }
void MainWindow::addBookmark(const QUrl &url, const QString &title, const QString &description, bool warn) { const QUrl bookmarkUrl = (url.isValid() ? url.adjusted(QUrl::RemovePassword) : m_windowsManager->getUrl().adjusted(QUrl::RemovePassword)); if (bookmarkUrl.isEmpty() || (warn && BookmarksManager::hasBookmark(bookmarkUrl) && QMessageBox::warning(this, tr("Warning"), tr("You already have this address in your bookmarks.\nDo you want to continue?"), (QMessageBox::Yes | QMessageBox::Cancel)) == QMessageBox::Cancel)) { return; } BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, bookmarkUrl, (url.isValid() ? title : m_windowsManager->getTitle())); bookmark->setData(description, BookmarksModel::DescriptionRole); BookmarkPropertiesDialog dialog(bookmark, BookmarkPropertiesDialog::AddBookmarkMode, this); if (dialog.exec() == QDialog::Rejected) { bookmark->remove(); } }
void KFileItemPrivate::init() { m_access.clear(); // metaInfo = KFileMetaInfo(); // determine mode and/or permissions if unknown // TODO: delay this until requested if (m_fileMode == KFileItem::Unknown || m_permissions == KFileItem::Unknown) { mode_t mode = 0; if (m_url.isLocalFile()) { /* directories may not have a slash at the end if * we want to stat() them; it requires that we * change into it .. which may not be allowed * stat("/is/unaccessible") -> rwx------ * stat("/is/unaccessible/") -> EPERM H.Z. * This is the reason for the StripTrailingSlash */ QT_STATBUF buf; const QString path = m_url.adjusted(QUrl::StripTrailingSlash).toLocalFile(); const QByteArray pathBA = QFile::encodeName(path); if (QT_LSTAT(pathBA.constData(), &buf) == 0) { mode = buf.st_mode; if ((buf.st_mode & QT_STAT_MASK) == QT_STAT_LNK) { m_bLink = true; if (QT_STAT(pathBA, &buf) == 0) { mode = buf.st_mode; } else {// link pointing to nowhere (see FileProtocol::createUDSEntry() in kioslave/file/file.cpp) mode = (QT_STAT_MASK - 1) | S_IRWXU | S_IRWXG | S_IRWXO; } } // While we're at it, store the times setTime(KFileItem::ModificationTime, buf.st_mtime); setTime(KFileItem::AccessTime, buf.st_atime); if (m_fileMode == KFileItem::Unknown) { m_fileMode = mode & QT_STAT_MASK; // extract file type } if (m_permissions == KFileItem::Unknown) { m_permissions = mode & 07777; // extract permissions } } } } }
QUrl setUpRemoteTestDir(const QString& testFile) { QWidget* authWindow = 0; if (qgetenv("GV_REMOTE_TESTS_BASE_URL").isEmpty()) { qWarning() << "Environment variable GV_REMOTE_TESTS_BASE_URL not set: remote tests disabled"; return QUrl(); } QUrl baseUrl(QString::fromLocal8Bit(qgetenv("GV_REMOTE_TESTS_BASE_URL"))); baseUrl = baseUrl.adjusted(QUrl::StripTrailingSlash); baseUrl.setPath(baseUrl.path() + "/gwenview-remote-tests"); KIO::StatJob *statJob = KIO::stat(baseUrl, KIO::StatJob::DestinationSide, 0); KJobWidgets::setWindow(statJob, authWindow); if (statJob->exec()) { KIO::DeleteJob *deleteJob = KIO::del(baseUrl); KJobWidgets::setWindow(deleteJob, authWindow); deleteJob->exec(); } KIO::MkdirJob *mkdirJob = KIO::mkdir(baseUrl); KJobWidgets::setWindow(mkdirJob, authWindow); if (!mkdirJob->exec()) { qCritical() << "Could not create dir" << baseUrl << ":" << mkdirJob->errorString(); return QUrl(); } if (!testFile.isEmpty()) { QUrl dstUrl = baseUrl; dstUrl = dstUrl.adjusted(QUrl::StripTrailingSlash); dstUrl.setPath(dstUrl.path() + '/' + testFile); KIO::FileCopyJob *copyJob = KIO::file_copy(urlForTestFile(testFile), dstUrl); KJobWidgets::setWindow(copyJob, authWindow); if (!copyJob->exec()) { qCritical() << "Could not copy" << testFile << "to" << dstUrl << ":" << copyJob->errorString(); return QUrl(); } } return baseUrl; }
void ImageViewer::saveFileToDisc() { QFileDialog dialog; dialog.selectFile(m_ImageUrl.fileName().remove(m_ImageUrl.path())); dialog.setFileMode(QFileDialog::AnyFile); QUrl newURL = dialog.getSaveFileUrl(KStars::Instance(), i18n("Save Image")); // save-dialog with default filename if (!newURL.isEmpty()) { QFile f (newURL.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path() + '/' + newURL.fileName()); if (f.exists()) { int r=KMessageBox::warningContinueCancel(static_cast<QWidget *>(parent()), i18n( "A file named \"%1\" already exists. " "Overwrite it?" , newURL.fileName()), i18n( "Overwrite File?" ), KStandardGuiItem::overwrite() ); if(r==KMessageBox::Cancel) return; f.remove(); } saveFile (newURL); } }
CoreDbUrl CoreDbUrl::fromAlbumAndName(const QString& name, const QString& album, const QUrl& albumRoot, int albumRootId, const DbEngineParameters& parameters) { CoreDbUrl url; url.setScheme(QLatin1String("digikamalbums")); url.setPath(QLatin1String("/")); url.setPath(url.path() + QLatin1Char('/') + album + QLatin1Char('/')); url.setPath(url.path() + QLatin1Char('/') + name); QUrlQuery q(url); q.addQueryItem(QLatin1String("albumRoot"), albumRoot.adjusted(QUrl::StripTrailingSlash).toLocalFile()); q.addQueryItem(QLatin1String("albumRootId"), QString::number(albumRootId)); url.setQuery(q); url.setParameters(parameters); // qCDebug(DIGIKAM_COREDB_LOG) << "CoreDbUrl::fromAlbumAndName : " << url.toDisplayString(); return url; }
CoreDbUrl CoreDbUrl::fromFileUrl(const QUrl& fileUrl, const QUrl& albumRoot, int albumRootId, const DbEngineParameters& parameters) { CoreDbUrl url; url.setScheme(QLatin1String("digikamalbums")); // get album root path without trailing slash QString albumRootPath = albumRoot.adjusted(QUrl::StripTrailingSlash).toLocalFile(); // get the hierarchy below the album root QString pathUnderRoot = fileUrl.toLocalFile().remove(albumRootPath); url.setPath(pathUnderRoot); QUrlQuery q(url); q.addQueryItem(QLatin1String("albumRoot"), albumRootPath); q.addQueryItem(QLatin1String("albumRootId"), QString::number(albumRootId)); url.setQuery(q); url.setParameters(parameters); // qCDebug(DIGIKAM_COREDB_LOG) << "CoreDbUrl::fromFileUrl : " << url.toDisplayString(); return url; }
QString CodeRepresentation::artificialPath(const QString& name) { QUrl url = QUrl::fromLocalFile(name); return QLatin1String("/kdev-artificial/") + url.adjusted(QUrl::NormalizePathSegments).path(); }