Commit 967b6ac0 authored by Méven Car's avatar Méven Car
Browse files

[KCM/Component] Convert to KConfigXT browser cfg and make default and reinit buttons work properly

Test Plan: kcmshell5 componentchooser

Reviewers: crossi, #plasma, ngraham, ervin

Reviewed By: ervin

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26100
parent b616999b
......@@ -15,6 +15,7 @@ set(kcm_componentchooser_SRCS
componentchooserterminal.cpp
kcm_componentchooser.cpp
)
kconfig_add_kcfg_files(kcm_componentchooser_SRCS browser_settings.kcfgc GENERATE_MOC)
ki18n_wrap_ui(kcm_componentchooser_SRCS
browserconfig_ui.ui
......@@ -46,4 +47,5 @@ install(TARGETS kcm_componentchooser DESTINATION ${KDE_INSTALL_PLUGINDIR} )
########### install files ###############
install( FILES componentchooser.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )
install(FILES browser_settings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kdeglobals"/>
<group name="General">
<entry name="browserApplication" key="BrowserApplication" type="String">
<label>Default web browser</label>
<default></default>
</entry>
</group>
</kcfg>
File=browser_settings.kcfg
ClassName=BrowserSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
......@@ -109,6 +109,11 @@ void CfgComponent::defaults()
//todo
}
bool CfgComponent::isDefaults() const
{
return false;
}
//END General kpart based Component selection
......@@ -196,8 +201,10 @@ void ComponentChooser::slotServiceSelected(QListWidgetItem* it) {
configWidget = configWidgetMap.value(service);
if (configWidget) {
configContainer->setCurrentWidget(configWidget);
dynamic_cast<CfgPlugin*>(configWidget)->load(&cfg);
configContainer->setCurrentWidget(configWidget);
const auto plugin = dynamic_cast<CfgPlugin*>(configWidget);
plugin->load(&cfg);
emit defaulted(plugin->isDefaults());
}
emitChanged(false);
......@@ -208,6 +215,9 @@ void ComponentChooser::slotServiceSelected(QListWidgetItem* it) {
void ComponentChooser::emitChanged(bool val) {
somethingChanged=val;
emit changed(val);
CfgPlugin *plugin = dynamic_cast<CfgPlugin *>( configWidget );
emit defaulted(plugin->isDefaults());
}
......
......@@ -39,6 +39,7 @@ public:
virtual void load(KConfig *cfg)=0;
virtual void save(KConfig *cfg)=0;
virtual void defaults()=0;
virtual bool isDefaults() const=0;
};
class CfgComponent: public QWidget, public Ui::ComponentConfig_UI, public CfgPlugin
......@@ -50,6 +51,7 @@ public:
void load(KConfig *cfg) override;
void save(KConfig *cfg) override;
void defaults() override;
bool isDefaults() const override;
protected:
QHash<QString, QString> m_lookupDict,m_revLookupDict;
......@@ -58,6 +60,7 @@ protected Q_SLOTS:
void slotComponentChanged(const QString&);
Q_SIGNALS:
void changed(bool);
void defaulted(bool);
};
class ComponentChooser : public QWidget, public Ui::ComponentChooser_UI
......@@ -87,6 +90,7 @@ protected Q_SLOTS:
Q_SIGNALS:
void changed(bool);
void defaulted(bool);
};
......
......@@ -15,7 +15,7 @@
#include "componentchooserbrowser.h"
#include <kopenwithdialog.h>
#include <kconfiggroup.h>
#include "browser_settings.h"
#include <KBuildSycocaProgressDialog>
#include <KLocalizedString>
......@@ -52,18 +52,38 @@ void CfgBrowser::selectBrowserApp()
void CfgBrowser::configChanged()
{
emit changed(true);
bool hasChanged = false;
const BrowserSettings settings;
const QString exec = settings.browserApplication();
if (exec.isEmpty()) {
hasChanged |= !radioKIO->isChecked();
} else {
if (exec.startsWith('!')) {
hasChanged |= lineExec->text() != exec;
} else {
hasChanged |= KService::serviceByStorageId(lineExec->text()) != KService::serviceByStorageId( exec );
}
}
emit changed(hasChanged);
}
void CfgBrowser::defaults()
{
load(nullptr);
emit changed(!radioKIO->isChecked());
radioKIO->setChecked(true);
}
bool CfgBrowser::isDefaults() const
{
return radioKIO->isChecked();
}
void CfgBrowser::load(KConfig *)
{
const KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") );
const QString exec = config.readPathEntry( QStringLiteral("BrowserApplication"), QString() );
const BrowserSettings settings;
const QString exec = settings.browserApplication();
if (exec.isEmpty()) {
radioKIO->setChecked(true);
m_browserExec = exec;
......@@ -87,8 +107,9 @@ void CfgBrowser::load(KConfig *)
browserCombo->clear();
const auto &browsers = KServiceTypeTrader::self()->query(QStringLiteral("Application"),
QStringLiteral("'WebBrowser' in Categories"));
const auto constraint = QStringLiteral("'WebBrowser' in Categories and"
" ('x-scheme-handler/http' in ServiceTypes or 'x-scheme-handler/https' in ServiceTypes)");
const auto browsers = KServiceTypeTrader::self()->query(QStringLiteral("Application"), constraint);
for (const auto &service : browsers) {
browserCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId());
......@@ -103,8 +124,7 @@ void CfgBrowser::load(KConfig *)
void CfgBrowser::save(KConfig *)
{
KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("kdeglobals"));
KConfigGroup config(profile, QStringLiteral("General"));
BrowserSettings settings;
QString exec;
if (radioService->isChecked()) {
if (m_browserService) {
......@@ -118,8 +138,8 @@ void CfgBrowser::save(KConfig *)
exec = '!' + exec; // Literal command
}
}
config.writePathEntry( QStringLiteral("BrowserApplication"), exec); // KConfig::Normal|KConfig::Global
config.sync();
settings.setBrowserApplication(exec);
settings.save();
// Save the default browser as scheme handler for http(s) in mimeapps.list
KSharedConfig::Ptr mimeAppList = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation);
......
......@@ -28,6 +28,7 @@ public:
void load(KConfig *cfg) override;
void save(KConfig *cfg) override;
void defaults() override;
bool isDefaults() const override;
protected Q_SLOTS:
void selectBrowser();
......
......@@ -60,6 +60,11 @@ void CfgEmailClient::defaults()
load(nullptr);
}
bool CfgEmailClient::isDefaults() const
{
return false;
}
void CfgEmailClient::load(KConfig *)
{
QString emailClient = pSettings->getSetting(KEMailSettings::ClientProgram);
......
......@@ -30,6 +30,7 @@ public:
void load(KConfig *cfg) override;
void save(KConfig *cfg) override;
void defaults() override;
bool isDefaults() const override;
private:
KEMailSettings *pSettings;
......
......@@ -50,6 +50,11 @@ void CfgFileManager::defaults()
load(nullptr);
}
bool CfgFileManager::isDefaults() const
{
return false;
}
static KService::List appOffers()
{
return KMimeTypeTrader::self()->query(QStringLiteral("inode/directory"), QStringLiteral("Application"));
......
......@@ -33,6 +33,7 @@ public:
void load(KConfig *cfg) override;
void save(KConfig *cfg) override;
void defaults() override;
bool isDefaults() const override;
protected Q_SLOTS:
void slotAddFileManager();
......
......@@ -57,6 +57,11 @@ void CfgTerminalEmulator::defaults()
load(nullptr);
}
bool CfgTerminalEmulator::isDefaults() const
{
return false;
}
void CfgTerminalEmulator::load(KConfig *) {
KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "General");
......
......@@ -30,6 +30,7 @@ public:
void load(KConfig *cfg) override;
void save(KConfig *cfg) override;
void defaults() override;
bool isDefaults() const override;
protected Q_SLOTS:
void selectTerminalApp();
......
......@@ -37,7 +37,7 @@ KCMComponentChooser::KCMComponentChooser(QWidget *parent, const QVariantList &):
m_chooser=new ComponentChooser(this);
lay->addWidget(m_chooser);
connect(m_chooser,SIGNAL(changed(bool)),this,SIGNAL(changed(bool)));
setButtons( Default|Apply|Help );
connect(m_chooser, &ComponentChooser::defaulted, this, &KCModule::defaulted);
KAboutData *about =
new KAboutData( QStringLiteral("kcmcomponentchooser"), i18n("Component Chooser"), QStringLiteral("1.0"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment