本文整理汇总了C++中QScopedPointer::directory方法的典型用法代码示例。如果您正苦于以下问题:C++ QScopedPointer::directory方法的具体用法?C++ QScopedPointer::directory怎么用?C++ QScopedPointer::directory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScopedPointer
的用法示例。
在下文中一共展示了QScopedPointer::directory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extractTemplate
void TemplatePage::extractTemplate()
{
QModelIndex index = ui->treeView->currentIndex();
QString archiveName= ui->treeView->model()->data(index, KDevelop::TemplatesModel::ArchiveFileRole).toString();
QFileInfo info(archiveName);
if (!info.exists())
{
ui->extractButton->setEnabled(false);
return;
}
QScopedPointer<KArchive> archive;
if (info.suffix() == QLatin1String("zip"))
{
archive.reset(new KZip(archiveName));
}
else
{
archive.reset(new KTar(archiveName));
}
archive->open(QIODevice::ReadOnly);
KUrl destination = KUrl::fromLocalFile(KFileDialog::getExistingDirectory());
destination.addPath(info.baseName());
archive->directory()->copyTo(destination.toLocalFile());
}
示例2: installtheme
ActionReply SddmAuthHelper::installtheme(const QVariantMap &args)
{
const QString filePath = args["filePath"].toString();
if (filePath.isEmpty()) {
return ActionReply::HelperErrorReply();
}
const QString themesBaseDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "sddm/themes", QStandardPaths::LocateDirectory);
QDir dir(themesBaseDir);
if (!dir.exists()) {
return ActionReply::HelperErrorReply();
}
qDebug() << "Installing " << filePath << " into " << themesBaseDir;
if (!QFile::exists(filePath)) {
return ActionReply::HelperErrorReply();
}
QMimeDatabase db;
QMimeType mimeType = db.mimeTypeForFile(filePath);
qWarning() << "Postinstallation: uncompress the file";
QScopedPointer<KArchive> archive;
//there must be a better way to do this? If not, make a static bool KZip::supportsMimeType(const QMimeType &type); ?
//or even a factory class in KArchive
if (mimeType.inherits(QStringLiteral("application/zip"))) {
archive.reset(new KZip(filePath));
} else if (mimeType.inherits(QStringLiteral("application/tar"))
|| mimeType.inherits(QStringLiteral("application/x-gzip"))
|| mimeType.inherits(QStringLiteral("application/x-bzip"))
|| mimeType.inherits(QStringLiteral("application/x-lzma"))
|| mimeType.inherits(QStringLiteral("application/x-xz"))
|| mimeType.inherits(QStringLiteral("application/x-bzip-compressed-tar"))
|| mimeType.inherits(QStringLiteral("application/x-compressed-tar"))) {
archive.reset(new KTar(filePath));
} else {
auto e = ActionReply::HelperErrorReply();
e.setErrorDescription(i18n("Invalid theme package"));
return e; }
if (!archive->open(QIODevice::ReadOnly)) {
auto e = ActionReply::HelperErrorReply();
e.setErrorDescription("Could not open file");
return e;
}
auto directory = archive->directory();
QStringList installedPaths;
//some basic validation
//the top level should only have folders, and those folders should contain a valid metadata.desktop file
//if we get anything else, abort everything before copying
for(const QString &name: directory->entries()) {
auto entry = directory->entry(name);
if (!entry->isDirectory()) {
auto e = ActionReply::HelperErrorReply();
e.setErrorDescription(i18n("Invalid theme package"));
return e;
}
auto subDirectory = static_cast<const KArchiveDirectory*>(entry);
auto metadataFile = subDirectory->file("metadata.desktop");
if(!metadataFile || !metadataFile->data().contains("[SddmGreeterTheme]")) {
auto e = ActionReply::HelperErrorReply();
e.setErrorDescription(i18n("Invalid theme package"));
return e;
}
installedPaths.append(themesBaseDir + '/' + name);
}
if (!directory->copyTo(themesBaseDir)) {
auto e = ActionReply::HelperErrorReply();
e.setErrorDescription(i18n("Could not decompress archive"));
return e;
}
auto rc = ActionReply::SuccessReply();
rc.addData(QStringLiteral("installedPaths"), installedPaths);
return rc;
}