Commit 4cd93027 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Component Chooser] Add ComboBox with browsers

This makes the dialog more user-friendly by providing a ComboBox with applications that provide the
"WebBrowser" category instead of only providing a "guess contents" and "custom command" text field.

Differential Revision: https://phabricator.kde.org/D6917
parent dbfedb1b
......@@ -2,8 +2,25 @@
<ui version="4.0">
<class>BrowserConfig_UI</class>
<widget class="QWidget" name="BrowserConfig_UI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>218</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
......@@ -23,10 +40,44 @@
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioService">
<property name="text">
<string>in the following application:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="browserCombo">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="radioExec">
<property name="text">
<string>in the following browser:</string>
<string>with the following command:</string>
</property>
</widget>
</item>
......@@ -56,7 +107,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="btnSelectBrowser">
<widget class="QToolButton" name="btnSelectApplication">
<property name="enabled">
<bool>false</bool>
</property>
......@@ -94,6 +145,22 @@
</customwidgets>
<resources/>
<connections>
<connection>
<sender>radioService</sender>
<signal>toggled(bool)</signal>
<receiver>browserCombo</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioExec</sender>
<signal>toggled(bool)</signal>
......@@ -113,7 +180,7 @@
<connection>
<sender>radioExec</sender>
<signal>toggled(bool)</signal>
<receiver>btnSelectBrowser</receiver>
<receiver>btnSelectApplication</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
......
......@@ -19,6 +19,7 @@
#include <kconfiggroup.h>
#include <KLocalizedString>
#include <KServiceTypeTrader>
#include "../migrationlib/kdelibs4config.h"
......@@ -30,8 +31,15 @@ CfgBrowser::CfgBrowser(QWidget *parent)
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<void(QComboBox::*)(int)>(&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,37 +55,44 @@ void CfgBrowser::defaults()
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 = KServiceTypeTrader::self()->query(QStringLiteral("Application"),
QStringLiteral("'WebBrowser' in Categories"));
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);
}
......@@ -86,13 +101,17 @@ 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 +131,17 @@ void CfgBrowser::selectBrowser()
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();
}
......
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