diff --git a/src/ioslaves/trash/kcmtrash.cpp b/src/ioslaves/trash/kcmtrash.cpp index da8655f3..fcfd15a2 100644 --- a/src/ioslaves/trash/kcmtrash.cpp +++ b/src/ioslaves/trash/kcmtrash.cpp @@ -1,313 +1,313 @@ /*************************************************************************** * Copyright (C) 2008 by Tobias Koenig * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "kcmtrash.h" #include "discspaceutil.h" #include "trashimpl.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(KCMTrashConfigFactory, registerPlugin(QStringLiteral("trash"));) TrashConfigModule::TrashConfigModule(QWidget *parent, const QVariantList &) : KCModule( //KCMTrashConfigFactory::componentData(), parent), trashInitialize(false) { mTrashImpl = new TrashImpl(); mTrashImpl->init(); readConfig(); setupGui(); useTypeChanged(); connect(mUseTimeLimit, &QAbstractButton::toggled, - this, QOverload<>::of(&TrashConfigModule::changed)); + this, &TrashConfigModule::markAsChanged); connect(mUseTimeLimit, &QAbstractButton::toggled, this, &TrashConfigModule::useTypeChanged); connect(mDays, QOverload::of(&QSpinBox::valueChanged), - this, QOverload<>::of(&TrashConfigModule::changed)); + this, &TrashConfigModule::markAsChanged); connect(mUseSizeLimit, &QAbstractButton::toggled, - this, QOverload<>::of(&TrashConfigModule::changed)); + this, &TrashConfigModule::markAsChanged); connect(mUseSizeLimit, &QAbstractButton::toggled, this, &TrashConfigModule::useTypeChanged); connect(mPercent, QOverload::of(&QDoubleSpinBox::valueChanged), this, &TrashConfigModule::percentChanged); connect(mPercent, QOverload::of(&QDoubleSpinBox::valueChanged), - this, QOverload<>::of(&TrashConfigModule::changed)); + this, &TrashConfigModule::markAsChanged); connect(mLimitReachedAction, QOverload::of(&QComboBox::currentIndexChanged), - this, QOverload<>::of(&TrashConfigModule::changed)); + this, &TrashConfigModule::markAsChanged); trashChanged(0); trashInitialize = true; } TrashConfigModule::~TrashConfigModule() { } void TrashConfigModule::save() { if (!mCurrentTrash.isEmpty()) { ConfigEntry entry; entry.useTimeLimit = mUseTimeLimit->isChecked(); entry.days = mDays->value(); entry.useSizeLimit = mUseSizeLimit->isChecked(); entry.percent = mPercent->value(), entry.actionType = mLimitReachedAction->currentIndex(); mConfigMap.insert(mCurrentTrash, entry); } writeConfig(); } void TrashConfigModule::defaults() { ConfigEntry entry; entry.useTimeLimit = false; entry.days = 7; entry.useSizeLimit = true; entry.percent = 10.0; entry.actionType = 0; mConfigMap.insert(mCurrentTrash, entry); trashInitialize = false; trashChanged(0); } void TrashConfigModule::percentChanged(double percent) { DiscSpaceUtil util(mCurrentTrash); qulonglong partitionSize = util.size(); double size = ((double)(partitionSize / 100)) * percent; KFormat format; mSizeLabel->setText(QLatin1Char('(') + format.formatByteSize(size, 2) + QLatin1Char(')')); } void TrashConfigModule::trashChanged(QListWidgetItem *item) { trashChanged(item->data(Qt::UserRole).toInt()); } void TrashConfigModule::trashChanged(int value) { const TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories(); if (!mCurrentTrash.isEmpty() && trashInitialize) { ConfigEntry entry; entry.useTimeLimit = mUseTimeLimit->isChecked(); entry.days = mDays->value(); entry.useSizeLimit = mUseSizeLimit->isChecked(); entry.percent = mPercent->value(), entry.actionType = mLimitReachedAction->currentIndex(); mConfigMap.insert(mCurrentTrash, entry); } mCurrentTrash = map[ value ]; const auto currentTrashIt = mConfigMap.constFind(mCurrentTrash); if (currentTrashIt != mConfigMap.constEnd()) { const ConfigEntry &entry = *currentTrashIt; mUseTimeLimit->setChecked(entry.useTimeLimit); mDays->setValue(entry.days); mUseSizeLimit->setChecked(entry.useSizeLimit); mPercent->setValue(entry.percent); mLimitReachedAction->setCurrentIndex(entry.actionType); } else { mUseTimeLimit->setChecked(false); mDays->setValue(7); mUseSizeLimit->setChecked(true); mPercent->setValue(10.0); mLimitReachedAction->setCurrentIndex(0); } mDays->setSuffix(i18n(" days")); // missing in Qt: plural form handling percentChanged(mPercent->value()); } void TrashConfigModule::useTypeChanged() { mDays->setEnabled(mUseTimeLimit->isChecked()); mPercent->setEnabled(mUseSizeLimit->isChecked()); mSizeLabel->setEnabled(mUseSizeLimit->isChecked()); } void TrashConfigModule::readConfig() { KConfig config(QStringLiteral("ktrashrc")); mConfigMap.clear(); const QStringList groups = config.groupList(); for (int i = 0; i < groups.count(); ++i) { if (groups[ i ].startsWith(QLatin1Char('/'))) { const KConfigGroup group = config.group(groups[ i ]); ConfigEntry entry; entry.useTimeLimit = group.readEntry("UseTimeLimit", false); entry.days = group.readEntry("Days", 7); entry.useSizeLimit = group.readEntry("UseSizeLimit", true); entry.percent = group.readEntry("Percent", 10.0); entry.actionType = group.readEntry("LimitReachedAction", 0); mConfigMap.insert(groups[ i ], entry); } } } void TrashConfigModule::writeConfig() { KConfig config(QStringLiteral("ktrashrc")); // first delete all existing groups const QStringList groups = config.groupList(); for (int i = 0; i < groups.count(); ++i) if (groups[ i ].startsWith(QLatin1Char('/'))) { config.deleteGroup(groups[ i ]); } QMapIterator it(mConfigMap); while (it.hasNext()) { it.next(); KConfigGroup group = config.group(it.key()); group.writeEntry("UseTimeLimit", it.value().useTimeLimit); group.writeEntry("Days", it.value().days); group.writeEntry("UseSizeLimit", it.value().useSizeLimit); group.writeEntry("Percent", it.value().percent); group.writeEntry("LimitReachedAction", it.value().actionType); } config.sync(); } void TrashConfigModule::setupGui() { QVBoxLayout *layout = new QVBoxLayout(this); #ifdef Q_OS_OSX QLabel *infoText = new QLabel( i18n( "KDE's wastebin is configured to use the Finder's Trash.
" ) ); infoText->setWhatsThis( i18nc( "@info:whatsthis", "Emptying KDE's wastebin will remove only KDE's trash items, while
" "emptying the Trash through the Finder will delete everything.
" "KDE's trash items will show up in a folder called KDE.trash, in the Trash can." ) ); layout->addWidget( infoText ); #endif TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories(); if (map.count() != 1) { // If we have multiple trashes, we setup a widget to choose // which trash to configure QListWidget *mountPoints = new QListWidget(this); layout->addWidget(mountPoints); QMapIterator it(map); while (it.hasNext()) { it.next(); DiscSpaceUtil util(it.value()); QListWidgetItem *item = new QListWidgetItem(QIcon(QStringLiteral("folder")), util.mountPoint()); item->setData(Qt::UserRole, it.key()); mountPoints->addItem(item); } mountPoints->setCurrentRow(0); connect(mountPoints, &QListWidget::currentItemChanged, this, QOverload::of(&TrashConfigModule::trashChanged)); } else { mCurrentTrash = map.value(0); } QFormLayout* formLayout = new QFormLayout(); layout->addLayout(formLayout); QHBoxLayout *daysLayout = new QHBoxLayout(); mUseTimeLimit = new QCheckBox(i18n("Delete files older than"), this); mUseTimeLimit->setWhatsThis(xi18nc("@info:whatsthis", "Check this box to allow automatic deletion of files that are older than the value specified. " "Leave this disabled to not automatically delete any items after a certain timespan")); daysLayout->addWidget(mUseTimeLimit); mDays = new QSpinBox(this); mDays->setRange(1, 365); mDays->setSingleStep(1); mDays->setSuffix(i18np(" day", " days", mDays->value())); mDays->setWhatsThis(xi18nc("@info:whatsthis", "Set the number of days that files can remain in the trash. " "Any files older than this will be automatically deleted.")); daysLayout->addWidget(mDays); daysLayout->addStretch(); formLayout->addRow(i18n("Cleanup:"), daysLayout); QHBoxLayout *maximumSizeLayout = new QHBoxLayout(); mUseSizeLimit = new QCheckBox(i18n("Limit to"), this); mUseSizeLimit->setWhatsThis(xi18nc("@info:whatsthis", "Check this box to limit the trash to the maximum amount of disk space that you specify below. " "Otherwise, it will be unlimited.")); maximumSizeLayout->addWidget(mUseSizeLimit); formLayout->addRow(i18n("Size:"), maximumSizeLayout); mPercent = new QDoubleSpinBox(this); mPercent->setRange(0.001, 100); mPercent->setDecimals(3); mPercent->setSingleStep(1); mPercent->setSuffix(QStringLiteral(" %")); mPercent->setWhatsThis(xi18nc("@info:whatsthis", "This is the maximum percent of disk space that will be used for the trash.")); maximumSizeLayout->addWidget(mPercent); mSizeLabel = new QLabel(this); mSizeLabel->setWhatsThis(xi18nc("@info:whatsthis", "This is the calculated amount of disk space that will be allowed for the trash, the maximum.")); maximumSizeLayout->addWidget(mSizeLabel); mLimitReachedAction = new QComboBox(); mLimitReachedAction->addItem(i18n("Show a Warning")); mLimitReachedAction->addItem(i18n("Delete Oldest Files From Trash")); mLimitReachedAction->addItem(i18n("Delete Biggest Files From Trash")); mLimitReachedAction->setWhatsThis(xi18nc("@info:whatsthis", "When the size limit is reached, it will prefer to delete the type of files that you specify, first. " "If this is set to warn you, it will do so instead of automatically deleting files.")); formLayout->addRow(i18n("Full Trash:"), mLimitReachedAction); layout->addStretch(); } #include "kcmtrash.moc" diff --git a/src/urifilters/ikws/ikwsopts.cpp b/src/urifilters/ikws/ikwsopts.cpp index d6f090bf..bea5e66b 100644 --- a/src/urifilters/ikws/ikwsopts.cpp +++ b/src/urifilters/ikws/ikwsopts.cpp @@ -1,457 +1,457 @@ /* * Copyright (c) 2000 Yves Arrouye * Copyright (c) 2001, 2002 Dawit Alemayehu * Copyright (c) 2009 Nick Shaforostoff * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ikwsopts.h" #include "ikwsopts_p.h" #include "kuriikwsfiltereng.h" #include "searchprovider.h" #include "searchproviderdlg.h" #include #include #include #include #include #include #include #include //BEGIN ProvidersModel ProvidersModel::~ProvidersModel() { } QVariant ProvidersModel::headerData(int section, Qt::Orientation orientation, int role) const { Q_UNUSED(orientation); if (role == Qt::DisplayRole) { switch (section) { case Name: return i18nc("@title:column Name label from web shortcuts column", "Name"); case Shortcuts: return i18nc("@title:column", "Shortcuts"); case Preferred: return i18nc("@title:column", "Preferred"); default: break; } } return QVariant(); } Qt::ItemFlags ProvidersModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::ItemIsEnabled; } if (index.column() == Preferred) { return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; } return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } bool ProvidersModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (role == Qt::CheckStateRole) { if (value.toInt() == Qt::Checked) { m_favoriteEngines.insert(m_providers.at(index.row())->desktopEntryName()); } else { m_favoriteEngines.remove(m_providers.at(index.row())->desktopEntryName()); } emit dataModified(); return true; } return false; } QVariant ProvidersModel::data(const QModelIndex &index, int role) const { if (index.isValid()) { if (role == Qt::CheckStateRole && index.column() == Preferred) { return m_favoriteEngines.contains(m_providers.at(index.row())->desktopEntryName()) ? Qt::Checked : Qt::Unchecked; } if (role == Qt::DisplayRole) { if (index.column() == Name) { return m_providers.at(index.row())->name(); } if (index.column() == Shortcuts) { return m_providers.at(index.row())->keys().join(QLatin1Char(',')); } } if (role == Qt::ToolTipRole || role == Qt::WhatsThisRole) { if (index.column() == Preferred) { return xi18nc("@info:tooltip", "Check this box to select the highlighted web shortcut " "as preferred.Preferred web shortcuts are used in " "places where only a few select shortcuts can be shown " "at one time."); } } if (role == Qt::UserRole) { return index.row();//a nice way to bypass proxymodel } } return QVariant(); } void ProvidersModel::setProviders(const QList &providers, const QStringList &favoriteEngines) { m_providers = providers; setFavoriteProviders(favoriteEngines); } void ProvidersModel::setFavoriteProviders(const QStringList &favoriteEngines) { beginResetModel(); m_favoriteEngines = QSet::fromList(favoriteEngines); endResetModel(); } int ProvidersModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return m_providers.size(); } QAbstractListModel *ProvidersModel::createListModel() { ProvidersListModel *pListModel = new ProvidersListModel(m_providers, this); connect(this, &QAbstractItemModel::modelAboutToBeReset, pListModel, &QAbstractItemModel::modelAboutToBeReset); connect(this, &QAbstractItemModel::modelReset, pListModel, &QAbstractItemModel::modelReset); // TODO: next two are private signals, does this still work? and is this needed? connect(this, SIGNAL(layoutAboutToBeChanged()), pListModel, SIGNAL(modelReset())); connect(this, SIGNAL(layoutChanged()), pListModel, SIGNAL(modelReset())); connect(this, &QAbstractItemModel::dataChanged, pListModel, &ProvidersListModel::emitDataChanged); connect(this, &QAbstractItemModel::rowsAboutToBeInserted, pListModel, &ProvidersListModel::emitRowsAboutToBeInserted); connect(this, &QAbstractItemModel::rowsAboutToBeRemoved, pListModel, &ProvidersListModel::emitRowsAboutToBeRemoved); connect(this, &QAbstractItemModel::rowsInserted, pListModel, &ProvidersListModel::emitRowsInserted); connect(this, &QAbstractItemModel::rowsRemoved, pListModel, &ProvidersListModel::emitRowsRemoved); return pListModel; } void ProvidersModel::deleteProvider(SearchProvider *p) { const int row = m_providers.indexOf(p); beginRemoveRows(QModelIndex(), row, row); m_favoriteEngines.remove(m_providers.takeAt(row)->desktopEntryName()); endRemoveRows(); delete p; emit dataModified(); } void ProvidersModel::addProvider(SearchProvider *p) { beginInsertRows(QModelIndex(), m_providers.size(), m_providers.size()); m_providers.append(p); endInsertRows(); emit dataModified(); } void ProvidersModel::changeProvider(SearchProvider *p) { const int row = m_providers.indexOf(p); emit dataChanged(index(row, 0), index(row, ColumnCount-1)); emit dataModified(); } QStringList ProvidersModel::favoriteEngines() const { return m_favoriteEngines.toList(); } //END ProvidersModel //BEGIN ProvidersListModel ProvidersListModel::ProvidersListModel(QList &providers, QObject *parent) : QAbstractListModel(parent) , m_providers(providers) { } QVariant ProvidersListModel::data(const QModelIndex &index, int role) const { if (index.isValid()) { if (role == Qt::DisplayRole) { if (index.row() == m_providers.size()) { return i18nc("@item:inlistbox No default web shortcut", "None"); } return m_providers.at(index.row())->name(); } if (role == ShortNameRole) { if (index.row() == m_providers.size()) { return QString(); } return m_providers.at(index.row())->desktopEntryName(); } } return QVariant(); } int ProvidersListModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return m_providers.size() + 1; } //END ProvidersListModel static QSortFilterProxyModel *wrapInProxyModel(QAbstractItemModel *model) { QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(model); proxyModel->setSourceModel(model); proxyModel->setDynamicSortFilter(true); proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); proxyModel->setFilterKeyColumn(-1); return proxyModel; } FilterOptions::FilterOptions(const KAboutData *about, QWidget *parent) : KCModule(about, parent) , m_providersModel(new ProvidersModel(this)) { m_dlg.setupUi(this); QSortFilterProxyModel *searchProviderModel = wrapInProxyModel(m_providersModel); m_dlg.lvSearchProviders->setModel(searchProviderModel); m_dlg.cmbDefaultEngine->setModel(wrapInProxyModel(m_providersModel->createListModel())); // Connect all the signals/slots... - connect(m_dlg.cbEnableShortcuts, &QAbstractButton::toggled, this, QOverload<>::of(&FilterOptions::changed)); + connect(m_dlg.cbEnableShortcuts, &QAbstractButton::toggled, this, &FilterOptions::markAsChanged); connect(m_dlg.cbEnableShortcuts, &QAbstractButton::toggled, this, &FilterOptions::updateSearchProviderEditingButons); - connect(m_dlg.cbUseSelectedShortcutsOnly, &QAbstractButton::toggled, this, QOverload<>::of(&FilterOptions::changed)); + connect(m_dlg.cbUseSelectedShortcutsOnly, &QAbstractButton::toggled, this, &FilterOptions::markAsChanged); - connect(m_providersModel, &ProvidersModel::dataModified, this, QOverload<>::of(&FilterOptions::changed)); - connect(m_dlg.cmbDefaultEngine, QOverload::of(&QComboBox::currentIndexChanged), this, QOverload<>::of(&FilterOptions::changed)); - connect(m_dlg.cmbDelimiter, QOverload::of(&QComboBox::currentIndexChanged), this, QOverload<>::of(&FilterOptions::changed)); + connect(m_providersModel, &ProvidersModel::dataModified, this, &FilterOptions::markAsChanged); + connect(m_dlg.cmbDefaultEngine, QOverload::of(&QComboBox::currentIndexChanged), this, &FilterOptions::markAsChanged); + connect(m_dlg.cmbDelimiter, QOverload::of(&QComboBox::currentIndexChanged), this, &FilterOptions::markAsChanged); connect(m_dlg.pbNew, &QAbstractButton::clicked, this, &FilterOptions::addSearchProvider); connect(m_dlg.pbDelete, &QAbstractButton::clicked, this, &FilterOptions::deleteSearchProvider); connect(m_dlg.pbChange, &QAbstractButton::clicked, this, &FilterOptions::changeSearchProvider); connect(m_dlg.lvSearchProviders->selectionModel(), &QItemSelectionModel::currentChanged, this, &FilterOptions::updateSearchProviderEditingButons); connect(m_dlg.lvSearchProviders, &QAbstractItemView::doubleClicked, this, &FilterOptions::changeSearchProvider); connect(m_dlg.searchLineEdit, &QLineEdit::textEdited, searchProviderModel, &QSortFilterProxyModel::setFilterFixedString); } QString FilterOptions::quickHelp() const { return xi18nc("@info:whatsthis", "In this module you can configure the web shortcuts feature. " "Web shortcuts allow you to quickly search or lookup words on " "the Internet. For example, to search for information about the " "KDE project using the Google engine, you simply type gg:KDE " "or google:KDE." "If you select a default search engine, then you can search for " "normal words or phrases by simply typing them into the input widget " "of applications that have built-in support for such a feature, e.g " "Konqueror."); } void FilterOptions::setDefaultEngine(int index) { QSortFilterProxyModel *proxy = qobject_cast(m_dlg.cmbDefaultEngine->model()); if (index == -1) { index = proxy->rowCount()-1;//"None" is the last } const QModelIndex modelIndex = proxy->mapFromSource(proxy->sourceModel()->index(index, 0)); m_dlg.cmbDefaultEngine->setCurrentIndex(modelIndex.row()); m_dlg.cmbDefaultEngine->view()->setCurrentIndex(modelIndex); //TODO: remove this when Qt bug is fixed } void FilterOptions::load() { KConfig config(QString::fromUtf8(KURISearchFilterEngine::self()->name()) + QLatin1String("rc"), KConfig::NoGlobals); KConfigGroup group = config.group("General"); const QString defaultSearchEngine = group.readEntry("DefaultWebShortcut"); const QStringList favoriteEngines = group.readEntry("PreferredWebShortcuts", DEFAULT_PREFERRED_SEARCH_PROVIDERS); const QList providers = m_registry.findAll(); int defaultProviderIndex = providers.size(); //default is "None", it is last in the list for (SearchProvider *provider : providers) { if (defaultSearchEngine == provider->desktopEntryName()) { defaultProviderIndex = providers.size(); } } m_providersModel->setProviders(providers, favoriteEngines); m_dlg.lvSearchProviders->setColumnWidth(0, 200); m_dlg.lvSearchProviders->resizeColumnToContents(1); m_dlg.lvSearchProviders->sortByColumn(0, Qt::AscendingOrder); m_dlg.cmbDefaultEngine->model()->sort(0, Qt::AscendingOrder); setDefaultEngine(defaultProviderIndex); m_dlg.cbEnableShortcuts->setChecked(group.readEntry("EnableWebShortcuts", true)); m_dlg.cbUseSelectedShortcutsOnly->setChecked(group.readEntry("UsePreferredWebShortcutsOnly", false)); const QString delimiter = group.readEntry("KeywordDelimiter", ":"); setDelimiter(delimiter.at(0).toLatin1()); } char FilterOptions::delimiter() { const char delimiters[] = {':', ' '}; return delimiters[m_dlg.cmbDelimiter->currentIndex()]; } void FilterOptions::setDelimiter(char sep) { m_dlg.cmbDelimiter->setCurrentIndex(sep == ' '); } void FilterOptions::save() { KConfig config(QString::fromUtf8(KURISearchFilterEngine::self()->name()) + QLatin1String("rc"), KConfig::NoGlobals); KConfigGroup group = config.group("General"); group.writeEntry("EnableWebShortcuts", m_dlg.cbEnableShortcuts->isChecked()); group.writeEntry("KeywordDelimiter", QString(QLatin1Char(delimiter()))); group.writeEntry("DefaultWebShortcut", m_dlg.cmbDefaultEngine->view()->currentIndex().data(ProvidersListModel::ShortNameRole)); group.writeEntry("PreferredWebShortcuts", m_providersModel->favoriteEngines()); group.writeEntry("UsePreferredWebShortcutsOnly", m_dlg.cbUseSelectedShortcutsOnly->isChecked()); int changedProviderCount = 0; const QList providers = m_providersModel->providers(); const QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kservices5/searchproviders/"); for (SearchProvider *provider : providers) { if (!provider->isDirty()) { continue; } changedProviderCount++; KConfig _service(path + provider->desktopEntryName() + QLatin1String(".desktop"), KConfig::SimpleConfig); KConfigGroup service(&_service, "Desktop Entry"); service.writeEntry("Type", "Service"); service.writeEntry("X-KDE-ServiceTypes", "SearchProvider"); service.writeEntry("Name", provider->name()); service.writeEntry("Query", provider->query()); service.writeEntry("Keys", provider->keys()); service.writeEntry("Charset", provider->charset()); service.writeEntry("Hidden", false); // we might be overwriting a hidden entry } const QStringList servicesDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kservices5/searchproviders/"), QStandardPaths::LocateDirectory); for (const QString &providerName : qAsConst(m_deletedProviders)) { QStringList matches; for (const QString &dir : servicesDirs) { QString current = dir + QLatin1Char('/') + providerName + QLatin1String(".desktop"); if (QFile::exists(current)) { matches += current; } } // Shouldn't happen if (matches.isEmpty()) { continue; } changedProviderCount++; if (matches.size() == 1 && matches.first().startsWith(path)) { // If only the local copy existed, unlink it // TODO: error handling QFile::remove(matches.first()); continue; } KConfig _service(path + providerName + QLatin1String(".desktop"), KConfig::SimpleConfig); KConfigGroup service(&_service, "Desktop Entry"); service.writeEntry("Type", "Service"); service.writeEntry("X-KDE-ServiceTypes", "SearchProvider"); service.writeEntry("Hidden", true); } config.sync(); emit changed(false); // Update filters in running applications... QDBusMessage msg = QDBusMessage::createSignal(QStringLiteral("/"), QStringLiteral("org.kde.KUriFilterPlugin"), QStringLiteral("configure")); QDBusConnection::sessionBus().send(msg); // If the providers changed, tell sycoca to rebuild its database... if (changedProviderCount) { KBuildSycocaProgressDialog::rebuildKSycoca(this); } } void FilterOptions::defaults() { m_dlg.cbEnableShortcuts->setChecked(true); m_dlg.cbUseSelectedShortcutsOnly->setChecked(false); m_providersModel->setFavoriteProviders(DEFAULT_PREFERRED_SEARCH_PROVIDERS); setDelimiter(':'); setDefaultEngine(-1); } void FilterOptions::addSearchProvider() { QList providers = m_providersModel->providers(); QPointer dlg = new SearchProviderDialog(nullptr, providers, this); if (dlg->exec()) { m_providersModel->addProvider(dlg->provider()); m_providersModel->changeProvider(dlg->provider()); } delete dlg; } void FilterOptions::changeSearchProvider() { QList providers = m_providersModel->providers(); SearchProvider *provider = providers.at(m_dlg.lvSearchProviders->currentIndex().data(Qt::UserRole).toInt()); QPointer dlg = new SearchProviderDialog(provider, providers, this); if (dlg->exec()) { m_providersModel->changeProvider(dlg->provider()); } delete dlg; } void FilterOptions::deleteSearchProvider() { SearchProvider *provider = m_providersModel->providers().at(m_dlg.lvSearchProviders->currentIndex().data(Qt::UserRole).toInt()); m_deletedProviders.append(provider->desktopEntryName()); m_providersModel->deleteProvider(provider); } void FilterOptions::updateSearchProviderEditingButons() { const bool enable = (m_dlg.cbEnableShortcuts->isChecked() && m_dlg.lvSearchProviders->currentIndex().isValid()); m_dlg.pbChange->setEnabled(enable); m_dlg.pbDelete->setEnabled(enable); }