diff --git a/kcms/componentchooser/browserconfig_ui.ui b/kcms/componentchooser/browserconfig_ui.ui --- a/kcms/componentchooser/browserconfig_ui.ui +++ b/kcms/componentchooser/browserconfig_ui.ui @@ -2,8 +2,25 @@ BrowserConfig_UI + + + 0 + 0 + 432 + 218 + + - + + 0 + + + 0 + + + 0 + + 0 @@ -24,9 +41,43 @@ + + + in the following application: + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 0 + + + + + + + + false + + + + + + - in the following browser: + with the following command: @@ -56,7 +107,7 @@ - + false @@ -95,6 +146,22 @@ + radioService + toggled(bool) + browserCombo + setEnabled(bool) + + + 20 + 20 + + + 20 + 20 + + + + radioExec toggled(bool) lineExec @@ -113,7 +180,7 @@ radioExec toggled(bool) - btnSelectBrowser + btnSelectApplication setEnabled(bool) diff --git a/kcms/componentchooser/componentchooserbrowser.cpp b/kcms/componentchooser/componentchooserbrowser.cpp --- a/kcms/componentchooser/componentchooserbrowser.cpp +++ b/kcms/componentchooser/componentchooserbrowser.cpp @@ -19,6 +19,7 @@ #include #include +#include #include "../migrationlib/kdelibs4config.h" @@ -30,8 +31,15 @@ setupUi(this); connect(lineExec, &KLineEdit::textChanged, this, &CfgBrowser::configChanged); connect(radioKIO, &QRadioButton::toggled, this, &CfgBrowser::configChanged); + connect(radioService, &QRadioButton::toggled, this, &CfgBrowser::configChanged); + connect(browserCombo, static_cast(&QComboBox::activated), this, [this](int index) { + const QString &storageId = browserCombo->itemData(index).toString(); + m_browserService = KService::serviceByStorageId(storageId); + m_browserExec.clear(); + emit configChanged(); + }); connect(radioExec, &QRadioButton::toggled, this, &CfgBrowser::configChanged); - connect(btnSelectBrowser, &QToolButton::clicked, this, &CfgBrowser::selectBrowser); + connect(btnSelectApplication, &QToolButton::clicked, this, &CfgBrowser::selectBrowser); } CfgBrowser::~CfgBrowser() { @@ -47,52 +55,62 @@ load(0); } - void CfgBrowser::load(KConfig *) { const KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") ); const QString exec = config.readPathEntry( QStringLiteral("BrowserApplication"), QString() ); - if (exec.isEmpty()) - { + if (exec.isEmpty()) { radioKIO->setChecked(true); m_browserExec = exec; m_browserService = 0; - } - else - { + } else { radioExec->setChecked(true); - if (exec.startsWith('!')) - { + if (exec.startsWith('!')) { m_browserExec = exec.mid(1); m_browserService = 0; - } - else - { + } else { m_browserService = KService::serviceByStorageId( exec ); - if (m_browserService) + if (m_browserService) { m_browserExec = m_browserService->desktopEntryName(); - else + } else { m_browserExec.clear(); + } } } lineExec->setText(m_browserExec); + browserCombo->clear(); + + const auto &browsers = KMimeTypeTrader::self()->query(QStringLiteral("text/html"), QStringLiteral("Application"));; + for (const auto &service : browsers) { + browserCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); + + if ((m_browserService && m_browserService->storageId() == service->storageId()) || service->exec() == m_browserExec) { + browserCombo->setCurrentIndex(browserCombo->count() - 1); + radioService->setChecked(true); + } + } + emit changed(false); } void CfgBrowser::save(KConfig *) { KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); KConfigGroup config(profile, QStringLiteral("General")); QString exec; - if (radioExec->isChecked()) - { + if (radioService->isChecked()) { + if (m_browserService) { + exec = m_browserService->storageId(); + } + } else if (radioExec->isChecked()) { exec = lineExec->text(); - if (m_browserService && (exec == m_browserExec)) + if (m_browserService && (exec == m_browserExec)) { exec = m_browserService->storageId(); // Use service - else if (!exec.isEmpty()) + } else if (!exec.isEmpty()) { exec = '!' + exec; // Literal command + } } config.writePathEntry( QStringLiteral("BrowserApplication"), exec); // KConfig::Normal|KConfig::Global config.sync(); @@ -112,9 +130,17 @@ return; m_browserService = dlg.service(); if (m_browserService) { - m_browserExec = m_browserService->desktopEntryName(); - if (m_browserExec.isEmpty()) - m_browserExec = m_browserService->exec(); + // check if we have listed it in the browser combo, if so, put it there instead + const int index = browserCombo->findData(m_browserService->storageId()); + if (index > -1) { + browserCombo->setCurrentIndex(index); + radioService->setChecked(true); + } else { + m_browserExec = m_browserService->desktopEntryName(); + if (m_browserExec.isEmpty()) { + m_browserExec = m_browserService->exec(); + } + } } else { m_browserExec = dlg.text(); }