Changeset View
Changeset View
Standalone View
Standalone View
kcms/componentchooser/componentchooserbrowser.cpp
Show All 13 Lines | |||||
14 | ***************************************************************************/ | 14 | ***************************************************************************/ | ||
15 | 15 | | |||
16 | #include "componentchooserbrowser.h" | 16 | #include "componentchooserbrowser.h" | ||
17 | #include <kopenwithdialog.h> | 17 | #include <kopenwithdialog.h> | ||
18 | #include <kglobalsettings.h> | 18 | #include <kglobalsettings.h> | ||
19 | #include <kconfiggroup.h> | 19 | #include <kconfiggroup.h> | ||
20 | 20 | | |||
21 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
22 | #include <KMimeTypeTrader> | ||||
22 | 23 | | |||
23 | #include "../migrationlib/kdelibs4config.h" | 24 | #include "../migrationlib/kdelibs4config.h" | ||
24 | 25 | | |||
25 | #include <QUrl> | 26 | #include <QUrl> | ||
26 | 27 | | |||
27 | CfgBrowser::CfgBrowser(QWidget *parent) | 28 | CfgBrowser::CfgBrowser(QWidget *parent) | ||
28 | : QWidget(parent), Ui::BrowserConfig_UI(),CfgPlugin() | 29 | : QWidget(parent), Ui::BrowserConfig_UI(),CfgPlugin() | ||
29 | { | 30 | { | ||
30 | setupUi(this); | 31 | setupUi(this); | ||
31 | connect(lineExec, &KLineEdit::textChanged, this, &CfgBrowser::configChanged); | 32 | connect(lineExec, &KLineEdit::textChanged, this, &CfgBrowser::configChanged); | ||
32 | connect(radioKIO, &QRadioButton::toggled, this, &CfgBrowser::configChanged); | 33 | connect(radioKIO, &QRadioButton::toggled, this, &CfgBrowser::configChanged); | ||
34 | connect(radioService, &QRadioButton::toggled, this, &CfgBrowser::configChanged); | ||||
35 | connect(browserCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), this, [this](int index) { | ||||
36 | const QString &storageId = browserCombo->itemData(index).toString(); | ||||
37 | m_browserService = KService::serviceByStorageId(storageId); | ||||
38 | m_browserExec.clear(); | ||||
39 | emit configChanged(); | ||||
40 | }); | ||||
33 | connect(radioExec, &QRadioButton::toggled, this, &CfgBrowser::configChanged); | 41 | connect(radioExec, &QRadioButton::toggled, this, &CfgBrowser::configChanged); | ||
34 | connect(btnSelectBrowser, &QToolButton::clicked, this, &CfgBrowser::selectBrowser); | 42 | connect(btnSelectApplication, &QToolButton::clicked, this, &CfgBrowser::selectBrowser); | ||
35 | } | 43 | } | ||
36 | 44 | | |||
37 | CfgBrowser::~CfgBrowser() { | 45 | CfgBrowser::~CfgBrowser() { | ||
38 | } | 46 | } | ||
39 | 47 | | |||
40 | void CfgBrowser::configChanged() | 48 | void CfgBrowser::configChanged() | ||
41 | { | 49 | { | ||
42 | emit changed(true); | 50 | emit changed(true); | ||
43 | } | 51 | } | ||
44 | 52 | | |||
45 | void CfgBrowser::defaults() | 53 | void CfgBrowser::defaults() | ||
46 | { | 54 | { | ||
47 | load(0); | 55 | load(0); | ||
48 | } | 56 | } | ||
49 | 57 | | |||
50 | | ||||
51 | void CfgBrowser::load(KConfig *) | 58 | void CfgBrowser::load(KConfig *) | ||
52 | { | 59 | { | ||
53 | const KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") ); | 60 | const KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") ); | ||
54 | const QString exec = config.readPathEntry( QStringLiteral("BrowserApplication"), QString() ); | 61 | const QString exec = config.readPathEntry( QStringLiteral("BrowserApplication"), QString() ); | ||
55 | if (exec.isEmpty()) | 62 | if (exec.isEmpty()) { | ||
56 | { | | |||
57 | radioKIO->setChecked(true); | 63 | radioKIO->setChecked(true); | ||
58 | m_browserExec = exec; | 64 | m_browserExec = exec; | ||
59 | m_browserService = 0; | 65 | m_browserService = 0; | ||
60 | } | 66 | } else { | ||
61 | else | | |||
62 | { | | |||
63 | radioExec->setChecked(true); | 67 | radioExec->setChecked(true); | ||
64 | if (exec.startsWith('!')) | 68 | if (exec.startsWith('!')) { | ||
65 | { | | |||
66 | m_browserExec = exec.mid(1); | 69 | m_browserExec = exec.mid(1); | ||
67 | m_browserService = 0; | 70 | m_browserService = 0; | ||
68 | } | 71 | } else { | ||
69 | else | | |||
70 | { | | |||
71 | m_browserService = KService::serviceByStorageId( exec ); | 72 | m_browserService = KService::serviceByStorageId( exec ); | ||
72 | if (m_browserService) | 73 | if (m_browserService) { | ||
73 | m_browserExec = m_browserService->desktopEntryName(); | 74 | m_browserExec = m_browserService->desktopEntryName(); | ||
74 | else | 75 | } else { | ||
75 | m_browserExec.clear(); | 76 | m_browserExec.clear(); | ||
76 | } | 77 | } | ||
77 | } | 78 | } | ||
79 | } | ||||
78 | 80 | | |||
79 | lineExec->setText(m_browserExec); | 81 | lineExec->setText(m_browserExec); | ||
80 | 82 | | |||
83 | browserCombo->clear(); | ||||
84 | | ||||
85 | const auto &browsers = KMimeTypeTrader::self()->query(QStringLiteral("text/html"), QStringLiteral("Application"));; | ||||
broulik: One could also instead use
```
KServiceTypeTrader::self()->query(QStringLiteral("Application")… | |||||
dfaure: I like this idea, it sounds more user-friendly indeed.
| |||||
86 | for (const auto &service : browsers) { | ||||
87 | browserCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); | ||||
88 | | ||||
89 | if ((m_browserService && m_browserService->storageId() == service->storageId()) || service->exec() == m_browserExec) { | ||||
90 | browserCombo->setCurrentIndex(browserCombo->count() - 1); | ||||
91 | radioService->setChecked(true); | ||||
92 | } | ||||
93 | } | ||||
94 | | ||||
81 | emit changed(false); | 95 | emit changed(false); | ||
82 | } | 96 | } | ||
83 | 97 | | |||
84 | void CfgBrowser::save(KConfig *) | 98 | void CfgBrowser::save(KConfig *) | ||
85 | { | 99 | { | ||
86 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); | 100 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); | ||
87 | KConfigGroup config(profile, QStringLiteral("General")); | 101 | KConfigGroup config(profile, QStringLiteral("General")); | ||
88 | QString exec; | 102 | QString exec; | ||
89 | if (radioExec->isChecked()) | 103 | if (radioService->isChecked()) { | ||
90 | { | 104 | if (m_browserService) { | ||
105 | exec = m_browserService->storageId(); | ||||
106 | } | ||||
107 | } else if (radioExec->isChecked()) { | ||||
91 | exec = lineExec->text(); | 108 | exec = lineExec->text(); | ||
92 | if (m_browserService && (exec == m_browserExec)) | 109 | if (m_browserService && (exec == m_browserExec)) { | ||
93 | exec = m_browserService->storageId(); // Use service | 110 | exec = m_browserService->storageId(); // Use service | ||
94 | else if (!exec.isEmpty()) | 111 | } else if (!exec.isEmpty()) { | ||
95 | exec = '!' + exec; // Literal command | 112 | exec = '!' + exec; // Literal command | ||
96 | } | 113 | } | ||
114 | } | ||||
97 | config.writePathEntry( QStringLiteral("BrowserApplication"), exec); // KConfig::Normal|KConfig::Global | 115 | config.writePathEntry( QStringLiteral("BrowserApplication"), exec); // KConfig::Normal|KConfig::Global | ||
98 | config.sync(); | 116 | config.sync(); | ||
99 | 117 | | |||
100 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("General"), "kdeglobals"); | 118 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("General"), "kdeglobals"); | ||
101 | 119 | | |||
102 | KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged); | 120 | KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged); | ||
103 | 121 | | |||
104 | emit changed(false); | 122 | emit changed(false); | ||
105 | } | 123 | } | ||
106 | 124 | | |||
107 | void CfgBrowser::selectBrowser() | 125 | void CfgBrowser::selectBrowser() | ||
108 | { | 126 | { | ||
109 | QList<QUrl> urlList; | 127 | QList<QUrl> urlList; | ||
110 | KOpenWithDialog dlg(urlList, i18n("Select preferred Web browser application:"), QString(), this); | 128 | KOpenWithDialog dlg(urlList, i18n("Select preferred Web browser application:"), QString(), this); | ||
111 | if (dlg.exec() != QDialog::Accepted) | 129 | if (dlg.exec() != QDialog::Accepted) | ||
112 | return; | 130 | return; | ||
113 | m_browserService = dlg.service(); | 131 | m_browserService = dlg.service(); | ||
114 | if (m_browserService) { | 132 | if (m_browserService) { | ||
133 | // check if we have listed it in the browser combo, if so, put it there instead | ||||
134 | const int index = browserCombo->findData(m_browserService->storageId()); | ||||
135 | if (index > -1) { | ||||
136 | browserCombo->setCurrentIndex(index); | ||||
137 | radioService->setChecked(true); | ||||
138 | } else { | ||||
115 | m_browserExec = m_browserService->desktopEntryName(); | 139 | m_browserExec = m_browserService->desktopEntryName(); | ||
116 | if (m_browserExec.isEmpty()) | 140 | if (m_browserExec.isEmpty()) { | ||
117 | m_browserExec = m_browserService->exec(); | 141 | m_browserExec = m_browserService->exec(); | ||
142 | } | ||||
143 | } | ||||
118 | } else { | 144 | } else { | ||
119 | m_browserExec = dlg.text(); | 145 | m_browserExec = dlg.text(); | ||
120 | } | 146 | } | ||
121 | lineExec->setText(m_browserExec); | 147 | lineExec->setText(m_browserExec); | ||
122 | } | 148 | } |
One could also instead use
to really list only web browsers. (I wouldn't mind either), currently it lists all browsers I have plus Kate and Kwrite