本文整理汇总了C++中KStandardDirs::locate方法的典型用法代码示例。如果您正苦于以下问题:C++ KStandardDirs::locate方法的具体用法?C++ KStandardDirs::locate怎么用?C++ KStandardDirs::locate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KStandardDirs
的用法示例。
在下文中一共展示了KStandardDirs::locate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
void DesktopThemeDetails::save()
{
QString themeRoot;
KStandardDirs dirs;
if (m_newThemeName->text().isEmpty()) {
themeRoot = ".customized";
//Toggle customized theme directory name to ensure theme reload
if (QDir(dirs.locateLocal("data", "desktoptheme/" + themeRoot + '/', false)).exists()) {
themeRoot = themeRoot + '1';
}
} else {
themeRoot = m_newThemeName->text().replace(' ',"_").remove(QRegExp("[^A-Za-z0-9_]"));
}
//Save theme items
QFile customSettingsFile;
bool customSettingsFileOpen = false;
if (m_themeCustomized || !m_newThemeName->text().isEmpty()) {
clearCustomized(themeRoot);
//Copy all files from the base theme
QString baseSource = dirs.locate("data", "desktoptheme/" + m_baseTheme + "/metadata.desktop");
baseSource = baseSource.left(baseSource.lastIndexOf('/', -1));
KIO::CopyJob *copyBaseTheme = KIO::copyAs(QUrl::fromLocalFile(baseSource), QUrl::fromLocalFile(dirs.locateLocal("data", "desktoptheme/" + themeRoot, true)), KIO::HideProgressInfo);
KIO::NetAccess::synchronousRun(copyBaseTheme, this);
//Prepare settings file for customized theme
if (isCustomized(themeRoot)) {
customSettingsFile.setFileName(dirs.locateLocal("data", "desktoptheme/" + themeRoot + "/settings"));
customSettingsFileOpen = customSettingsFile.open(QFile::WriteOnly);
if (customSettingsFileOpen) {
QTextStream out(&customSettingsFile);
out << "baseTheme=" + m_baseTheme + "\r\n";;
}
}
QString settingsSource;
//Copy each item theme file to new theme folder
QHashIterator<int, int> i(m_itemThemeReplacements);
while (i.hasNext()) {
i.next();
//Get root directory where item should reside (relative to theme root)
QString itemRoot = "";
if (m_itemPaths[i.key()].lastIndexOf('/', -1) != -1) {
itemRoot= m_itemPaths[i.key()].left(m_itemPaths[i.key()].lastIndexOf('/', -1));
}
//Setup source and destination
QString source;
QString dest;
if (i.value() != -1) {
//Source is a theme
source = "desktoptheme/" + m_themeRoots[i.value()] + '/' + m_itemPaths[i.key()] + '*';
dest = "desktoptheme/" + themeRoot + '/' + itemRoot + '/';
settingsSource = m_themeRoots[i.value()];
} else {
//Source is a file
source = m_itemFileReplacements[i.key()];
dest = "desktoptheme/" + themeRoot + '/' + itemRoot + '/';
settingsSource = m_itemFileReplacements[i.key()];
}
//Delete item files at destination before copying (possibly there from base theme copy)
const QStringList deleteFiles = dirs.findAllResources("data", "desktoptheme/" + themeRoot + '/' + m_itemPaths[i.key()] + '*',
KStandardDirs::NoDuplicates);
for (int j = 0; j < deleteFiles.size(); ++j) {
KIO::DeleteJob *dj = KIO::del(QUrl::fromLocalFile(deleteFiles.at(j)), KIO::HideProgressInfo);
KIO::NetAccess::synchronousRun(dj, this);
}
//Copy item(s)
dest = dirs.locateLocal("data", dest, true);
QStringList copyFiles;
if (i.value() != -1) {
copyFiles = dirs.findAllResources("data", source, KStandardDirs::NoDuplicates); //copy from theme
} else {
copyFiles << source; //copy from file
}
for (int j = 0; j < copyFiles.size(); ++j) {
KIO::CopyJob *cj = KIO::copy(QUrl::fromLocalFile(copyFiles.at(j)), QUrl::fromLocalFile(dest), KIO::HideProgressInfo);
KIO::NetAccess::synchronousRun(cj, this);
}
//Record settings file
if (customSettingsFileOpen) {
QTextStream out(&customSettingsFile);
out << m_items.key(i.key()) + "=" + settingsSource +"\r\n";
}
}
if (customSettingsFileOpen) customSettingsFile.close();
// Create new theme FDO desktop file
QFile::remove(dirs.locateLocal("data", "desktoptheme/" + themeRoot + "/metadata.desktop", false));
KDesktopFile df(dirs.locateLocal("data", "desktoptheme/" + themeRoot + "/metadata.desktop"));
KConfigGroup cg = df.desktopGroup();
if (isCustomized(themeRoot)) {
cg.writeEntry("Name",i18n("(Customized)"));
cg.writeEntry("Comment", i18n("User customized theme"));
//.........这里部分代码省略.........