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" | 24 | #include "../migrationlib/kdelibs4config.h" | ||
25 | 25 | | |||
26 | #include <QUrl> | 26 | #include <QUrl> | ||
Show All 20 Lines | 46 | { | |||
47 | const QString &storageId = browserCombo->currentData().toString(); | 47 | const QString &storageId = browserCombo->currentData().toString(); | ||
48 | m_browserService = KService::serviceByStorageId(storageId); | 48 | m_browserService = KService::serviceByStorageId(storageId); | ||
49 | m_browserExec.clear(); | 49 | m_browserExec.clear(); | ||
50 | configChanged(); | 50 | configChanged(); | ||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | void CfgBrowser::configChanged() | 53 | void CfgBrowser::configChanged() | ||
54 | { | 54 | { | ||
55 | emit changed(true); | 55 | bool hasChanged = false; | ||
56 | const BrowserSettings settings; | ||||
57 | const QString exec = settings.browserApplication(); | ||||
58 | | ||||
59 | if (exec.isEmpty()) { | ||||
60 | hasChanged |= !radioKIO->isChecked(); | ||||
61 | } else { | ||||
62 | if (exec.startsWith('!')) { | ||||
63 | hasChanged |= lineExec->text() != exec; | ||||
64 | } else { | ||||
65 | hasChanged |= KService::serviceByStorageId(lineExec->text()) != KService::serviceByStorageId( exec ); | ||||
66 | } | ||||
67 | } | ||||
68 | | ||||
69 | emit changed(hasChanged); | ||||
56 | } | 70 | } | ||
57 | 71 | | |||
58 | void CfgBrowser::defaults() | 72 | void CfgBrowser::defaults() | ||
59 | { | 73 | { | ||
60 | load(nullptr); | 74 | emit changed(!radioKIO->isChecked()); | ||
75 | radioKIO->setChecked(true); | ||||
76 | } | ||||
77 | | ||||
78 | bool CfgBrowser::isDefaults() const | ||||
79 | { | ||||
80 | return radioKIO->isChecked(); | ||||
61 | } | 81 | } | ||
62 | 82 | | |||
63 | void CfgBrowser::load(KConfig *) | 83 | void CfgBrowser::load(KConfig *) | ||
64 | { | 84 | { | ||
65 | const KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") ); | 85 | const BrowserSettings settings; | ||
66 | const QString exec = config.readPathEntry( QStringLiteral("BrowserApplication"), QString() ); | 86 | const QString exec = settings.browserApplication(); | ||
67 | if (exec.isEmpty()) { | 87 | if (exec.isEmpty()) { | ||
68 | radioKIO->setChecked(true); | 88 | radioKIO->setChecked(true); | ||
69 | m_browserExec = exec; | 89 | m_browserExec = exec; | ||
70 | m_browserService = nullptr; | 90 | m_browserService = nullptr; | ||
71 | } else { | 91 | } else { | ||
72 | radioExec->setChecked(true); | 92 | radioExec->setChecked(true); | ||
73 | if (exec.startsWith('!')) { | 93 | if (exec.startsWith('!')) { | ||
74 | m_browserExec = exec.mid(1); | 94 | m_browserExec = exec.mid(1); | ||
75 | m_browserService = nullptr; | 95 | m_browserService = nullptr; | ||
76 | } else { | 96 | } else { | ||
77 | m_browserService = KService::serviceByStorageId( exec ); | 97 | m_browserService = KService::serviceByStorageId( exec ); | ||
78 | if (m_browserService) { | 98 | if (m_browserService) { | ||
79 | m_browserExec = m_browserService->desktopEntryName(); | 99 | m_browserExec = m_browserService->desktopEntryName(); | ||
80 | } else { | 100 | } else { | ||
81 | m_browserExec.clear(); | 101 | m_browserExec.clear(); | ||
82 | } | 102 | } | ||
83 | } | 103 | } | ||
84 | } | 104 | } | ||
85 | 105 | | |||
86 | lineExec->setText(m_browserExec); | 106 | lineExec->setText(m_browserExec); | ||
87 | 107 | | |||
88 | browserCombo->clear(); | 108 | browserCombo->clear(); | ||
89 | 109 | | |||
90 | const auto &browsers = KServiceTypeTrader::self()->query(QStringLiteral("Application"), | 110 | const auto constraint = QStringLiteral("'WebBrowser' in Categories and" | ||
91 | QStringLiteral("'WebBrowser' in Categories")); | 111 | " ('x-scheme-handler/http' in ServiceTypes or 'x-scheme-handler/https' in ServiceTypes)"); | ||
112 | const auto &browsers = KServiceTypeTrader::self()->query(QStringLiteral("Application"), constraint); | ||||
92 | for (const auto &service : browsers) { | 113 | for (const auto &service : browsers) { | ||
93 | browserCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); | 114 | browserCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->storageId()); | ||
94 | 115 | | |||
95 | if ((m_browserService && m_browserService->storageId() == service->storageId()) || service->exec() == m_browserExec) { | 116 | if ((m_browserService && m_browserService->storageId() == service->storageId()) || service->exec() == m_browserExec) { | ||
96 | browserCombo->setCurrentIndex(browserCombo->count() - 1); | 117 | browserCombo->setCurrentIndex(browserCombo->count() - 1); | ||
97 | radioService->setChecked(true); | 118 | radioService->setChecked(true); | ||
98 | } | 119 | } | ||
99 | } | 120 | } | ||
100 | 121 | | |||
101 | emit changed(false); | 122 | emit changed(false); | ||
102 | } | 123 | } | ||
103 | 124 | | |||
104 | void CfgBrowser::save(KConfig *) | 125 | void CfgBrowser::save(KConfig *) | ||
105 | { | 126 | { | ||
106 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); | 127 | BrowserSettings settings; | ||
107 | KConfigGroup config(profile, QStringLiteral("General")); | | |||
108 | QString exec; | 128 | QString exec; | ||
109 | if (radioService->isChecked()) { | 129 | if (radioService->isChecked()) { | ||
110 | if (m_browserService) { | 130 | if (m_browserService) { | ||
111 | exec = m_browserService->storageId(); | 131 | exec = m_browserService->storageId(); | ||
112 | } | 132 | } | ||
113 | } else if (radioExec->isChecked()) { | 133 | } else if (radioExec->isChecked()) { | ||
114 | exec = lineExec->text(); | 134 | exec = lineExec->text(); | ||
115 | if (m_browserService && (exec == m_browserExec)) { | 135 | if (m_browserService && (exec == m_browserExec)) { | ||
116 | exec = m_browserService->storageId(); // Use service | 136 | exec = m_browserService->storageId(); // Use service | ||
117 | } else if (!exec.isEmpty()) { | 137 | } else if (!exec.isEmpty()) { | ||
118 | exec = '!' + exec; // Literal command | 138 | exec = '!' + exec; // Literal command | ||
119 | } | 139 | } | ||
120 | } | 140 | } | ||
121 | config.writePathEntry( QStringLiteral("BrowserApplication"), exec); // KConfig::Normal|KConfig::Global | 141 | settings.setBrowserApplication(exec); | ||
122 | config.sync(); | 142 | settings.save(); | ||
123 | 143 | | |||
124 | // Save the default browser as scheme handler for http(s) in mimeapps.list | 144 | // 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); | 145 | KSharedConfig::Ptr mimeAppList = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | ||
126 | if (mimeAppList->isConfigWritable(true /*warn user if not writable*/)) { | 146 | if (mimeAppList->isConfigWritable(true /*warn user if not writable*/)) { | ||
127 | KConfigGroup defaultApp(mimeAppList, "Default Applications"); | 147 | KConfigGroup defaultApp(mimeAppList, "Default Applications"); | ||
128 | 148 | | |||
129 | if (m_browserService) { | 149 | if (m_browserService) { | ||
130 | defaultApp.writeXdgListEntry(QStringLiteral("x-scheme-handler/http"), QStringList(m_browserService->storageId())); | 150 | defaultApp.writeXdgListEntry(QStringLiteral("x-scheme-handler/http"), QStringList(m_browserService->storageId())); | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |