diff --git a/kcms/componentchooser/componentchooser.h b/kcms/componentchooser/componentchooser.h --- a/kcms/componentchooser/componentchooser.h +++ b/kcms/componentchooser/componentchooser.h @@ -35,9 +35,10 @@ virtual ~CfgPlugin(){} virtual void load(KConfig *cfg)=0; virtual void save(KConfig *cfg)=0; + bool hasChanged() const { - return m_currentIndex != -1 && m_currentIndex != currentIndex(); + return count() > 1 && m_currentIndex != currentIndex(); } void defaults() diff --git a/kcms/componentchooser/componentchooserbrowser.cpp b/kcms/componentchooser/componentchooserbrowser.cpp --- a/kcms/componentchooser/componentchooserbrowser.cpp +++ b/kcms/componentchooser/componentchooserbrowser.cpp @@ -41,7 +41,7 @@ KOpenWithDialog dlg(QStringLiteral("x-scheme-handler/http"), QString(), this); dlg.setSaveNewApplications(true); if (dlg.exec() != QDialog::Accepted) { - setCurrentIndex(m_currentIndex); + setCurrentIndex(m_currentIndex == -1 ? 0 : m_currentIndex); return; } @@ -104,6 +104,11 @@ void CfgBrowser::save(KConfig *) { + if (currentIndex() == count() - 1) { + // no browser installed, nor selected + return; + } + const QString browserStorageId = currentData().toString(); BrowserSettings settings; diff --git a/kcms/componentchooser/componentchooseremail.cpp b/kcms/componentchooser/componentchooseremail.cpp --- a/kcms/componentchooser/componentchooseremail.cpp +++ b/kcms/componentchooser/componentchooseremail.cpp @@ -117,7 +117,7 @@ if (dlg.exec() != QDialog::Accepted) { // restore previous setting - setCurrentIndex(m_currentIndex); + setCurrentIndex(m_currentIndex == -1 ? 0 : m_currentIndex); emit changed(false); } else { const auto service = dlg.service(); @@ -138,6 +138,11 @@ void CfgEmailClient::save(KConfig *) { + if (currentIndex() == count() - 1) { + // no email client installed, nor selected + return; + } + const QString &storageId = currentData().toString(); const KService::Ptr emailClientService = KService::serviceByStorageId(storageId); @@ -152,7 +157,7 @@ // Save the default email client in mimeapps.list KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); - if (profile->isConfigWritable(true) && emailClientService) { + if (profile->isConfigWritable(true)) { KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); diff --git a/kcms/componentchooser/componentchooserfilemanager.cpp b/kcms/componentchooser/componentchooserfilemanager.cpp --- a/kcms/componentchooser/componentchooserfilemanager.cpp +++ b/kcms/componentchooser/componentchooserfilemanager.cpp @@ -44,7 +44,7 @@ KOpenWithDialog dlg({}, i18n("Select preferred file manager:"), QString(), this); dlg.setSaveNewApplications(true); if (dlg.exec() != QDialog::Accepted) { - setCurrentIndex(m_currentIndex); + setCurrentIndex(m_currentIndex == -1 ? 0 : m_currentIndex); return; } @@ -113,26 +113,29 @@ void CfgFileManager::save(KConfig *) { + if (currentIndex() == count() - 1) { + // no filemanager installed, nor selected + return; + } + const QString storageId = currentData().toString(); - if (!storageId.isEmpty()) { - m_currentIndex = currentIndex(); + m_currentIndex = currentIndex(); - // This is taken from filetypes/mimetypedata.cpp - KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); - if (!profile->isConfigWritable(true)) // warn user if mimeapps.list is root-owned (#155126/#94504) - return; - KConfigGroup addedApps(profile, s_AddedAssociations); - QStringList userApps = addedApps.readXdgListEntry(mime); - userApps.removeAll(storageId); // remove if present, to make it first in the list - userApps.prepend(storageId); - addedApps.writeXdgListEntry(mime, userApps); + // This is taken from filetypes/mimetypedata.cpp + KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); + if (!profile->isConfigWritable(true)) // warn user if mimeapps.list is root-owned (#155126/#94504) + return; + KConfigGroup addedApps(profile, s_AddedAssociations); + QStringList userApps = addedApps.readXdgListEntry(mime); + userApps.removeAll(storageId); // remove if present, to make it first in the list + userApps.prepend(storageId); + addedApps.writeXdgListEntry(mime, userApps); - // Save the default file manager as per mime-apps spec 1.0.1 - KConfigGroup defaultApp(profile, s_DefaultApplications); - defaultApp.writeXdgListEntry(mime, QStringList(storageId)); + // Save the default file manager as per mime-apps spec 1.0.1 + KConfigGroup defaultApp(profile, s_DefaultApplications); + defaultApp.writeXdgListEntry(mime, QStringList(storageId)); - profile->sync(); + profile->sync(); - emit changed(false); - } + emit changed(false); } diff --git a/kcms/componentchooser/componentchooserterminal.cpp b/kcms/componentchooser/componentchooserterminal.cpp --- a/kcms/componentchooser/componentchooserterminal.cpp +++ b/kcms/componentchooser/componentchooserterminal.cpp @@ -89,8 +89,12 @@ void CfgTerminalEmulator::save(KConfig *) { + if (currentIndex() == count() - 1) { + // no terminal installed, nor selected + return; + } + const QString terminal = currentData().toString(); - m_currentIndex = currentIndex(); TerminalSettings settings; settings.setTerminalApplication(terminal); @@ -114,7 +118,7 @@ dlg.hideRunInTerminal(); dlg.setSaveNewApplications(true); if (dlg.exec() != QDialog::Accepted) { - setCurrentIndex(m_currentIndex); + setCurrentIndex(m_currentIndex == -1 ? 0 : m_currentIndex); return; } const auto service = dlg.service();