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 ); } }
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); } }
MainWindow::MainWindow() : KXmlGuiWindow() , _bookmarkHandler(0) , _pluggedController(0) , _menuBarInitialVisibility(true) , _menuBarInitialVisibilityApplied(false) { if (!KonsoleSettings::saveGeometryOnExit()) { // If we are not using the global Konsole save geometry on exit, // remove all Height and Width from [MainWindow] from konsolerc // Each screen resolution will have entries (Width 1280=619) KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig("konsolerc"); KConfigGroup group = konsoleConfig->group("MainWindow"); QMap<QString, QString> configEntries = group.entryMap(); QMapIterator<QString, QString> i(configEntries); while (i.hasNext()) { i.next(); if (i.key().startsWith(QLatin1String("Width")) || i.key().startsWith(QLatin1String("Height"))) { group.deleteEntry(i.key()); } } } if (useTransparency()) { // It is useful to have translucent terminal area setAttribute(Qt::WA_TranslucentBackground, true); // But it is mostly annoying to have translucent menubar and tabbar setAttribute(Qt::WA_NoSystemBackground, false); } // create actions for menus setupActions(); // create view manager _viewManager = new ViewManager(this, actionCollection()); connect(_viewManager, SIGNAL(empty()), this, SLOT(close())); connect(_viewManager, SIGNAL(activeViewChanged(SessionController*)), this, SLOT(activeViewChanged(SessionController*))); connect(_viewManager, SIGNAL(unplugController(SessionController*)), this, SLOT(disconnectController(SessionController*))); connect(_viewManager, SIGNAL(viewPropertiesChanged(QList<ViewProperties*>)), bookmarkHandler(), SLOT(setViews(QList<ViewProperties*>))); connect(_viewManager, SIGNAL(updateWindowIcon()), this, SLOT(updateWindowIcon())); connect(_viewManager, SIGNAL(newViewRequest(Profile::Ptr)), this, SLOT(newFromProfile(Profile::Ptr))); connect(_viewManager, SIGNAL(newViewRequest()), this, SLOT(newTab())); connect(_viewManager, SIGNAL(viewDetached(Session*)), this, SIGNAL(viewDetached(Session*))); // create the main widget setupMainWidget(); // disable automatically generated accelerators in top-level // menu items - to avoid conflicting with Alt+[Letter] shortcuts // in terminal applications KAcceleratorManager::setNoAccel(menuBar()); // create menus createGUI(); // remember the original menu accelerators for later use rememberMenuAccelerators(); // replace standard shortcuts which cannot be used in a terminal // emulator (as they are reserved for use by terminal applications) correctStandardShortcuts(); setProfileList(new ProfileList(true, this)); // this must come at the end applyKonsoleSettings(); connect(KonsoleSettings::self(), SIGNAL(configChanged()), this, SLOT(applyKonsoleSettings())); }
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; } else { for (QMap<QString, QString>::const_iterator it = map.constBegin(), end = map.constEnd(); it != end; ++it) { if (key.isEmpty() || it.key().contains(key, Qt::CaseInsensitive)) { std::cout << CHAR(it.key()) << std::endl; } } } break; } case ListGroups: { QStringList groups = grp.parent().exists() ? grp.parent().groupList() : grp.config()->groupList(); foreach (const QString &s, groups) if (key.isEmpty() || s.contains(key, Qt::CaseInsensitive)) std::cout << CHAR(s) << std::endl; exit(0); } case Replace: { if (grp.isImmutable()) { std::cout << "The component/group " << CHAR(path(grp)) << " cannot be modified" << std::endl; exit(1); } QStringList match = key.split("="); if (match.count() != 2) { std::cout << "The match sequence must be of the form <key regexp>=<value regexp>" << std::endl; exit(1); } QRegExp keyMatch(match.at(0), Qt::CaseInsensitive); QRegExp valueMatch(match.at(1), Qt::CaseInsensitive); QStringList replace = value.split("="); if (replace.count() != 2) { std::cout << "The replace sequence must be of the form <key string>=<value string>" << std::endl; exit(1); } QMap<QString, QString> map = grp.entryMap(); QStringList keys; for (QMap<QString, QString>::const_iterator it = map.constBegin(), end = map.constEnd(); it != end; ++it) { if (keyMatch.exactMatch(it.key()) && valueMatch.exactMatch(it.value())) { keys << it.key(); } } foreach (const QString &key, keys) { QString newKey = key; newKey.replace(keyMatch, replace.at(0)); QString newValue = grp.readEntry(key); const QString oldValue = newValue; newValue.replace(valueMatch, replace.at(1)); if (key != newKey) grp.deleteEntry(key); grp.writeEntry(newKey, newValue); std::cout << CHAR(key) << ": " << CHAR(oldValue) << " -> " << CHAR(newKey) << ": " << CHAR(grp.readEntry(newKey)) << std::endl; grp.sync(); } break; } Invalid: default: break; }
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; }
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; }
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); }