Changeset View
Changeset View
Standalone View
Standalone View
kcms/componentchooser/componentchooserbrowser.cpp
Show All 9 Lines | |||||
10 | * This program is free software; you can redistribute it and/or modify * | 10 | * This program is free software; you can redistribute it and/or modify * | ||
11 | * it under the terms of the GNU General Public License version 2 as * | 11 | * it under the terms of the GNU General Public License version 2 as * | ||
12 | * published by the Free Software Foundationi * | 12 | * published by the Free Software Foundationi * | ||
13 | * * | 13 | * * | ||
14 | ***************************************************************************/ | 14 | ***************************************************************************/ | ||
15 | 15 | | |||
16 | #include "componentchooserbrowser.h" | 16 | #include "componentchooserbrowser.h" | ||
17 | #include <kopenwithdialog.h> | 17 | #include <kopenwithdialog.h> | ||
18 | #include <kconfiggroup.h> | 18 | #include "browser_settings.h" | ||
19 | 19 | | |||
20 | #include <KBuildSycocaProgressDialog> | 20 | #include <KBuildSycocaProgressDialog> | ||
21 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
22 | #include <KServiceTypeTrader> | 22 | #include <KServiceTypeTrader> | ||
23 | 23 | | |||
24 | #include "../migrationlib/kdelibs4config.h" | | |||
25 | | ||||
26 | #include <QUrl> | 24 | #include <QUrl> | ||
27 | #include <QDBusConnection> | 25 | #include <QDBusConnection> | ||
28 | #include <QDBusMessage> | 26 | #include <QDBusMessage> | ||
29 | 27 | | |||
30 | CfgBrowser::CfgBrowser(QWidget *parent) | 28 | CfgBrowser::CfgBrowser(QWidget *parent) | ||
31 | : QWidget(parent), Ui::BrowserConfig_UI(),CfgPlugin() | 29 | : QWidget(parent), Ui::BrowserConfig_UI(),CfgPlugin() | ||
32 | { | 30 | { | ||
33 | setupUi(this); | 31 | setupUi(this); | ||
Show All 13 Lines | 44 | { | |||
47 | const QString &storageId = browserCombo->currentData().toString(); | 45 | const QString &storageId = browserCombo->currentData().toString(); | ||
48 | m_browserService = KService::serviceByStorageId(storageId); | 46 | m_browserService = KService::serviceByStorageId(storageId); | ||
49 | m_browserExec.clear(); | 47 | m_browserExec.clear(); | ||
50 | configChanged(); | 48 | configChanged(); | ||
51 | } | 49 | } | ||
52 | 50 | | |||
53 | void CfgBrowser::configChanged() | 51 | void CfgBrowser::configChanged() | ||
54 | { | 52 | { | ||
55 | emit changed(true); | 53 | bool hasChanged = false; | ||
54 | const BrowserSettings settings; | ||||
55 | const QString exec = settings.browserApplication(); | ||||
56 | | ||||
57 | if (exec.isEmpty()) { | ||||
58 | hasChanged |= !radioKIO->isChecked(); | ||||
59 | } else { | ||||
60 | if (exec.startsWith('!')) { | ||||
61 | hasChanged |= lineExec->text() != exec; | ||||
62 | } else { | ||||
63 | hasChanged |= KService::serviceByStorageId(lineExec->text()) != KService::serviceByStorageId( exec ); | ||||
64 | } | ||||
65 | } | ||||
66 | | ||||
67 | emit changed(hasChanged); | ||||
56 | } | 68 | } | ||
57 | 69 | | |||
58 | void CfgBrowser::defaults() | 70 | void CfgBrowser::defaults() | ||
59 | { | 71 | { | ||
60 | load(nullptr); | 72 | emit changed(!radioKIO->isChecked()); | ||
73 | radioKIO->setChecked(true); | ||||
74 | } | ||||
75 | | ||||
76 | bool CfgBrowser::isDefaults() const | ||||
77 | { | ||||
78 | return radioKIO->isChecked(); | ||||
61 | } | 79 | } | ||
62 | 80 | | |||
63 | void CfgBrowser::load(KConfig *) | 81 | void CfgBrowser::load(KConfig *) | ||
64 | { | 82 | { | ||
65 | const KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") ); | 83 | const BrowserSettings settings; | ||
66 | const QString exec = config.readPathEntry( QStringLiteral("BrowserApplication"), QString() ); | 84 | const QString exec = settings.browserApplication(); | ||
67 | if (exec.isEmpty()) { | 85 | if (exec.isEmpty()) { | ||
68 | radioKIO->setChecked(true); | 86 | radioKIO->setChecked(true); | ||
69 | m_browserExec = exec; | 87 | m_browserExec = exec; | ||
70 | m_browserService = nullptr; | 88 | m_browserService = nullptr; | ||
71 | } else { | 89 | } else { | ||
72 | radioExec->setChecked(true); | 90 | radioExec->setChecked(true); | ||
73 | if (exec.startsWith('!')) { | 91 | if (exec.startsWith('!')) { | ||
74 | m_browserExec = exec.mid(1); | 92 | m_browserExec = exec.mid(1); | ||
75 | m_browserService = nullptr; | 93 | m_browserService = nullptr; | ||
76 | } else { | 94 | } else { | ||
77 | m_browserService = KService::serviceByStorageId( exec ); | 95 | m_browserService = KService::serviceByStorageId( exec ); | ||
78 | if (m_browserService) { | 96 | if (m_browserService) { | ||
79 | m_browserExec = m_browserService->desktopEntryName(); | 97 | m_browserExec = m_browserService->desktopEntryName(); | ||
80 | } else { | 98 | } else { | ||
81 | m_browserExec.clear(); | 99 | m_browserExec.clear(); | ||
82 | } | 100 | } | ||
83 | } | 101 | } | ||
84 | } | 102 | } | ||
85 | 103 | | |||
86 | lineExec->setText(m_browserExec); | 104 | lineExec->setText(m_browserExec); | ||
87 | 105 | | |||
88 | browserCombo->clear(); | 106 | browserCombo->clear(); | ||
89 | 107 | | |||
90 | const auto &browsers = KServiceTypeTrader::self()->query(QStringLiteral("Application"), | 108 | const auto constraint = QStringLiteral("'WebBrowser' in Categories and" | ||
91 | QStringLiteral("'WebBrowser' in Categories")); | 109 | " ('x-scheme-handler/http' in ServiceTypes or 'x-scheme-handler/https' in ServiceTypes)"); | ||
110 | const auto browsers = KServiceTypeTrader::self()->query(QStringLiteral("Application"), constraint); | ||||
92 | for (const auto &service : browsers) { | 111 | for (const auto &service : browsers) { | ||
93 | browserCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); | 112 | browserCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); | ||
94 | 113 | | |||
95 | if ((m_browserService && m_browserService->storageId() == service->storageId()) || service->exec() == m_browserExec) { | 114 | if ((m_browserService && m_browserService->storageId() == service->storageId()) || service->exec() == m_browserExec) { | ||
96 | browserCombo->setCurrentIndex(browserCombo->count() - 1); | 115 | browserCombo->setCurrentIndex(browserCombo->count() - 1); | ||
97 | radioService->setChecked(true); | 116 | radioService->setChecked(true); | ||
98 | } | 117 | } | ||
99 | } | 118 | } | ||
100 | 119 | | |||
101 | emit changed(false); | 120 | emit changed(false); | ||
102 | } | 121 | } | ||
103 | 122 | | |||
104 | void CfgBrowser::save(KConfig *) | 123 | void CfgBrowser::save(KConfig *) | ||
105 | { | 124 | { | ||
106 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); | 125 | BrowserSettings settings; | ||
107 | KConfigGroup config(profile, QStringLiteral("General")); | | |||
108 | QString exec; | 126 | QString exec; | ||
109 | if (radioService->isChecked()) { | 127 | if (radioService->isChecked()) { | ||
110 | if (m_browserService) { | 128 | if (m_browserService) { | ||
111 | exec = m_browserService->storageId(); | 129 | exec = m_browserService->storageId(); | ||
112 | } | 130 | } | ||
113 | } else if (radioExec->isChecked()) { | 131 | } else if (radioExec->isChecked()) { | ||
114 | exec = lineExec->text(); | 132 | exec = lineExec->text(); | ||
115 | if (m_browserService && (exec == m_browserExec)) { | 133 | if (m_browserService && (exec == m_browserExec)) { | ||
116 | exec = m_browserService->storageId(); // Use service | 134 | exec = m_browserService->storageId(); // Use service | ||
117 | } else if (!exec.isEmpty()) { | 135 | } else if (!exec.isEmpty()) { | ||
118 | exec = '!' + exec; // Literal command | 136 | exec = '!' + exec; // Literal command | ||
119 | } | 137 | } | ||
120 | } | 138 | } | ||
121 | config.writePathEntry( QStringLiteral("BrowserApplication"), exec); // KConfig::Normal|KConfig::Global | 139 | settings.setBrowserApplication(exec); | ||
122 | config.sync(); | 140 | settings.save(); | ||
123 | 141 | | |||
124 | // Save the default browser as scheme handler for http(s) in mimeapps.list | 142 | // Save the default browser as scheme handler for http(s) in mimeapps.list | ||
125 | KSharedConfig::Ptr mimeAppList = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | 143 | KSharedConfig::Ptr mimeAppList = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | ||
126 | if (mimeAppList->isConfigWritable(true /*warn user if not writable*/)) { | 144 | if (mimeAppList->isConfigWritable(true /*warn user if not writable*/)) { | ||
127 | KConfigGroup defaultApp(mimeAppList, "Default Applications"); | 145 | KConfigGroup defaultApp(mimeAppList, "Default Applications"); | ||
128 | 146 | | |||
129 | if (m_browserService) { | 147 | if (m_browserService) { | ||
130 | defaultApp.writeXdgListEntry(QStringLiteral("x-scheme-handler/http"), QStringList(m_browserService->storageId())); | 148 | defaultApp.writeXdgListEntry(QStringLiteral("x-scheme-handler/http"), QStringList(m_browserService->storageId())); | ||
131 | defaultApp.writeXdgListEntry(QStringLiteral("x-scheme-handler/https"), QStringList(m_browserService->storageId())); | 149 | defaultApp.writeXdgListEntry(QStringLiteral("x-scheme-handler/https"), QStringList(m_browserService->storageId())); | ||
132 | } else { | 150 | } else { | ||
133 | defaultApp.deleteEntry(QStringLiteral("x-scheme-handler/http")); | 151 | defaultApp.deleteEntry(QStringLiteral("x-scheme-handler/http")); | ||
134 | defaultApp.deleteEntry(QStringLiteral("x-scheme-handler/https")); | 152 | defaultApp.deleteEntry(QStringLiteral("x-scheme-handler/https")); | ||
135 | } | 153 | } | ||
136 | mimeAppList->sync(); | 154 | mimeAppList->sync(); | ||
137 | 155 | | |||
138 | KBuildSycocaProgressDialog::rebuildKSycoca(this); | 156 | KBuildSycocaProgressDialog::rebuildKSycoca(this); | ||
139 | } | 157 | } | ||
140 | 158 | | |||
141 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("General"), "kdeglobals"); | | |||
142 | | ||||
143 | QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.klauncher5"), | 159 | QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.klauncher5"), | ||
144 | QStringLiteral("/KLauncher"), | 160 | QStringLiteral("/KLauncher"), | ||
145 | QStringLiteral("org.kde.KLauncher"), | 161 | QStringLiteral("org.kde.KLauncher"), | ||
146 | QStringLiteral("reparseConfiguration")); | 162 | QStringLiteral("reparseConfiguration")); | ||
147 | QDBusConnection::sessionBus().send(message); | 163 | QDBusConnection::sessionBus().send(message); | ||
148 | 164 | | |||
149 | emit changed(false); | 165 | emit changed(false); | ||
150 | } | 166 | } | ||
Show All 25 Lines |