本文整理汇总了C++中KConfigGroup::entryMap方法的典型用法代码示例。如果您正苦于以下问题:C++ KConfigGroup::entryMap方法的具体用法?C++ KConfigGroup::entryMap怎么用?C++ KConfigGroup::entryMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KConfigGroup
的用法示例。
在下文中一共展示了KConfigGroup::entryMap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: KPageWidgetItem
RecentProjectsDialogPage::RecentProjectsDialogPage()
: KPageWidgetItem( new QWidget(), i18n( "Recent Projects" ) ),
d( new RecentProjectsDialogPagePrivate( this ) )
{
setIcon( KIcon( "document-open-recent" ) );
d->widget = new QListWidget( widget() );
connect( d->widget, SIGNAL( doubleClicked( QModelIndex ) ),
SLOT( projectDoubleClicked( QModelIndex ) ) );
QVBoxLayout* layout = new QVBoxLayout( widget() );
widget()->setLayout( layout );
layout->addWidget( d->widget );
const KConfigGroup group = KGlobal::config()->group( "Recent Files" );
const int entryCount = ( group.entryMap().count() / 2 );
for( int i = entryCount; i >= 1; --i )
{
const QString key = QString( "File%1" ).arg( i );
const QString path = group.readPathEntry( key, QString() );
QListWidgetItem* item = new QListWidgetItem;
item->setIcon( KIcon( "document-open-recent" ) );
QString projectName = KUrl( path ).directory().split( '/' ).last();
item->setText( QString( "%1\n%2" ).arg( projectName ).arg( path ) );
item->setData( Qt::UserRole, path );
d->widget->addItem( item );
}
}
示例2: copyGroup
void KonfUpdate::copyGroup(const KConfigGroup &cg1, KConfigGroup &cg2)
{
// Copy keys
QMap<QString, QString> list = cg1.entryMap();
for (QMap<QString, QString>::ConstIterator it = list.constBegin();
it != list.constEnd(); ++it) {
if (m_bOverwrite || !cg2.hasKey(it.key())) {
cg2.writeEntry(it.key(), it.value());
}
}
// Copy subgroups
Q_FOREACH(const QString &group, cg1.groupList()) {
copyGroup(&cg1, group, &cg2, group);
}
}
示例3: process
void process(Mode mode, KConfigGroup &grp, QString key, QString value)
{
switch (mode) {
case Read:
if (IS_A_TTY(1))
std::cout << CHAR(key) << ": " << CHAR(grp.readEntry(key, "does not exist")) << " (" << CHAR(path(grp)) << ")" << std::endl;
else
std::cout << CHAR(grp.readEntry(key, ""));
break;
case Write: {
if (grp.isImmutable()) {
std::cout << "The component/group " << CHAR(path(grp)) << " cannot be modified" << std::endl;
exit(1);
}
bool added = !grp.hasKey(key);
QString oldv;
if (!added) oldv = grp.readEntry(key);
grp.writeEntry(key, QString(value));
grp.sync();
if (added)
std::cout << "New " << CHAR(key) << ": " << CHAR(grp.readEntry(key)) << std::endl;
else
std::cout << CHAR(key) << ": " << CHAR(oldv) << " -> " << CHAR(grp.readEntry(key)) << std::endl;
break;
}
case Delete: {
if (grp.isImmutable()) {
std::cout << "The component/group " << CHAR(path(grp)) << " cannot be modified" << std::endl;
exit(1);
}
if (grp.hasKey(key)) {
std::cout << "Removed " << CHAR(key) << ": " << CHAR(grp.readEntry(key)) << std::endl;
grp.deleteEntry(key);
grp.sync();
} else if (grp.hasGroup(key)) {
std::cout << "There's a group, but no key: " << CHAR(key) << "\nPlease explicitly use deletegroup" << std::endl;
exit(1);
} else {
std::cout << "There's no key " << CHAR(key) << " in " << CHAR(path(grp)) << std::endl;
exit(1);
}
break;
}
case DeleteGroup: {
if (grp.hasGroup(key)) {
grp = grp.group(key);
if (grp.isImmutable()) {
std::cout << "The component/group " << CHAR(path(grp)) << " cannot be modified" << std::endl;
exit(1);
}
QMap<QString, QString> map = grp.entryMap();
std::cout << "Removed " << CHAR(key) << gs_separator << std::endl;
for (QMap<QString, QString>::const_iterator it = map.constBegin(), end = map.constEnd(); it != end; ++it) {
std::cout << CHAR(it.key()) << ": " << CHAR(it.value()) << std::endl;
}
grp.deleteGroup();
grp.sync();
} else {
std::cout << "There's no group " << CHAR(key) << " in " << CHAR(path(grp)) << std::endl;
exit(1);
}
break;
}
case List:
case ListKeys: {
if (!grp.exists()) { // could be parent group
if (mode == ListKeys)
exit(1);
QStringList groups = grp.parent().exists() ? grp.parent().groupList() : grp.config()->groupList();
if (groups.isEmpty()) {
std::cout << "The component/group " << CHAR(path(grp)) << " does not exist" << std::endl;
exit(1);
}
std::cout << "Groups in " << CHAR(path(grp)) << gs_separator << std::endl;
foreach (const QString &s, groups)
if (key.isEmpty() || s.contains(key, Qt::CaseInsensitive))
std::cout << CHAR(s) << std::endl;
exit(0);
}
QMap<QString, QString> map = grp.entryMap();
if (map.isEmpty()) {
std::cout << "The group " << CHAR(path(grp)) << " is empty" << std::endl;
break;
}
if (mode == List) {
bool matchFound = false;
for (QMap<QString, QString>::const_iterator it = map.constBegin(), end = map.constEnd(); it != end; ++it) {
if (key.isEmpty() || it.key().contains(key, Qt::CaseInsensitive)) {
if (!matchFound)
std::cout << std::endl << CHAR(path(grp)) << gs_separator << std::endl;
matchFound = true;
std::cout << CHAR(it.key()) << ": " << CHAR(it.value()) << std::endl;
}
}
if (!matchFound)
std::cout << "No present key matches \"" << CHAR(key) << "\" in " << CHAR(path(grp));
std::cout << std::endl;
//.........这里部分代码省略.........
示例4: readFromDesktopFile
bool KgTheme::readFromDesktopFile(const QString& path_)
{
if (path_.isEmpty())
{
qCDebug(GAMES_LIB) << "Refusing to load theme with no name";
return false;
}
//legacy support: relative paths are resolved with KStandardDirs/appdata
QString path(path_);
if (QFileInfo(path).isRelative())
{
path = QStandardPaths::locate(QStandardPaths::DataLocation, path);
if (path.isEmpty())
{
qCDebug(GAMES_LIB) << "Could not find theme description" << path;
return false;
}
}
//default group name
if (Private::s_configGroupNames.isEmpty())
{
Private::s_configGroupNames << QLatin1String("KGameTheme");
}
//open file, look for a known config group
KConfig config(path, KConfig::SimpleConfig);
KConfigGroup group;
foreach (const QString& groupName, Private::s_configGroupNames)
{
if (config.hasGroup(groupName))
{
group = config.group(groupName);
}
}
if (!group.isValid())
{
qCDebug(GAMES_LIB) << "Could not read theme description at" << path;
return false;
}
//check format version
if (group.readEntry("VersionFormat", 1) > 1)
{
qCDebug(GAMES_LIB) << "Format of theme description too new at" << path;
return false;
}
//resolve paths
const QFileInfo fi(path);
const QDir dir = fi.dir();
QString graphicsPath = group.readEntry("FileName", QString());
if (!graphicsPath.isEmpty() && QFileInfo(graphicsPath).isRelative())
graphicsPath = dir.absoluteFilePath(graphicsPath);
QString previewPath = group.readEntry("Preview", QString());
if (!previewPath.isEmpty() && QFileInfo(previewPath).isRelative())
previewPath = dir.absoluteFilePath(previewPath);
//create theme
setName(group.readEntry("Name", QString()));
setDescription(group.readEntry("Description", QString()));
setAuthor(group.readEntry("Author", QString()));
setAuthorEmail(group.readEntry("AuthorEmail", QString()));
setGraphicsPath(graphicsPath);
setPreviewPath(previewPath);
setCustomData(group.entryMap());
//store modification date of this file in private property (KGameRenderer
//wants to clear its cache also if the theme description changes)
setProperty("_k_themeDescTimestamp", fi.lastModified().toTime_t());
return true;
}
示例5: load
bool KGameTheme::load(const QString &fileName)
{
if (fileName.isEmpty()) {
qDebug() << "Refusing to load theme with no name";
return false;
}
QString filePath = QStandardPaths::locate(
QStandardPaths::DataLocation, fileName, QStandardPaths::LocateFile );
qDebug() << "Attempting to load .desktop at" << filePath;
if (filePath.isEmpty()) {
return false;
}
// verify if it is a valid file first and if we can open it
QFile themefile(filePath);
if (!themefile.open(QIODevice::ReadOnly)) {
qDebug() << "Could not open .desktop theme file" << filePath;
return false;
}
d->prefix = QFileInfo(themefile).absolutePath() + '/';
themefile.close();
KConfig themeconfig(filePath, KConfig::SimpleConfig);
if (!themeconfig.hasGroup(d->themeGroup)) {
qDebug() << "Config group" << d->themeGroup << "does not exist in" << filePath;
return false;
}
KConfigGroup group = themeconfig.group(d->themeGroup);
//Copy the whole entryMap, so we can inherit generic properties as well, reducing the need to subclass for simple implementations
d->themeproperties = group.entryMap();
//Version control
int themeversion = group.readEntry("VersionFormat", 0);
//Format is increased when we have incompatible changes, meaning that older clients are not able to use the remaining information safely
if (themeversion > kThemeVersionFormat) {
return false;
}
QString graphName = group.readEntry("FileName");
//d->graphics = KStandardDirs::locate("appdata", graphName);
d->graphics = d->prefix + graphName;
if (d->graphics.isEmpty()) return false;
// let's see if svg file exists and can be opened
QFile svgFile(d->graphics);
if (!svgFile.open(QIODevice::ReadOnly)) {
qDebug() << "Could not open file" << d->graphics;
return false;
}
QString previewName = group.readEntry("Preview");
//QString graphicsPath = KStandardDirs::locate("appdata", previewName);
QString graphicsPath = d->prefix + previewName;
d->preview = QPixmap(graphicsPath);
d->fileName = fileName;
d->fullPath = filePath;
d->loaded = true;
return true;
}
示例6: QStringListModel
MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags f)
: KParts::MainWindow(parent, f)
, m_recentFiles(0)
, m_close(0)
, m_allocatorModel(new QStringListModel(this))
, m_newAllocator(0)
, m_removeAllocator(0)
, m_shortenTemplates(0)
, m_selectPeak(0)
, m_currentDocument(0)
, m_dataTreeModel(new DataTreeModel(this))
, m_dataTreeFilterModel(new FilteredDataTreeModel(m_dataTreeModel))
, m_settingSelection(false)
{
ui.setupUi(this);
//BEGIN KGraphViewer
bool haveGraphViewer = false;
// NOTE: just check if kgraphviewer is available at runtime.
// The former logic has been moved to DocumentWidget constructor.
#ifdef HAVE_KGRAPHVIEWER
KPluginFactory *factory = KPluginLoader("kgraphviewerpart").factory();
if (factory) {
KParts::ReadOnlyPart* readOnlyPart = factory->create<KParts::ReadOnlyPart>("kgraphviewerpart", this);
if (readOnlyPart) {
readOnlyPart->widget()->hide();
haveGraphViewer = true;
}
}
#endif
if (!haveGraphViewer) {
// cleanup UI when we installed with kgraphviewer but it's not available at runtime
KToolBar* callgraphToolbar = toolBar(QStringLiteral("callgraphToolBar"));
removeToolBar(callgraphToolbar);
delete callgraphToolbar;
}
//END KGraphViewer
ui.documents->setMovable(true);
ui.documents->setTabsClosable(true);
connect(ui.documents, &QTabWidget::currentChanged,
this, &MainWindow::documentChanged);
connect(ui.documents, &QTabWidget::tabCloseRequested,
this, &MainWindow::closeFileTab);
//BEGIN custom allocators
tabifyDockWidget(ui.allocatorDock, ui.dataTreeDock);
ui.allocatorView->setModel(m_allocatorModel);
int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize);
ui.dockMenuBar->setIconSize(QSize(iconSize, iconSize));
ui.dockMenuBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
ui.dockMenuBar->setFloatable(false);
ui.dockMenuBar->setMovable(false);
KConfigGroup cfg = allocatorConfig();
m_allocatorModel->setStringList(cfg.entryMap().values());
connect(m_allocatorModel, &QStringListModel::modelReset,
this, &MainWindow::allocatorsChanged);
connect(m_allocatorModel, &QStringListModel::dataChanged,
this, &MainWindow::allocatorsChanged);
connect(ui.dataTreeView, &QTreeView::customContextMenuRequested,
this, &MainWindow::dataTreeContextMenuRequested);
ui.dataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui.allocatorView, &QTreeView::customContextMenuRequested,
this, &MainWindow::allocatorViewContextMenuRequested);
ui.allocatorView->setContextMenuPolicy(Qt::CustomContextMenu);
//END custom allocators
setupActions();
setupGUI(StandardWindowOptions(Default ^ StatusBar));
statusBar()->hide();
ui.dataTreeView->setModel(m_dataTreeFilterModel);
connect(ui.filterDataTree, &KLineEdit::textChanged,
m_dataTreeFilterModel, &FilteredDataTreeModel::setFilter);
connect(ui.dataTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &MainWindow::treeSelectionChanged);
// open page
ui.stackedWidget->setCurrentWidget(ui.openPage);
}