Changeset View
Changeset View
Standalone View
Standalone View
kcms/componentchooser/componentchooserfilemanager.cpp
Show All 38 Lines | |||||
39 | 39 | | |||
40 | void CfgFileManager::selectFileManager(int index) | 40 | void CfgFileManager::selectFileManager(int index) | ||
41 | { | 41 | { | ||
42 | if (index == count() -1) { | 42 | if (index == count() -1) { | ||
43 | 43 | | |||
44 | KOpenWithDialog dlg({}, i18n("Select preferred file manager:"), QString(), this); | 44 | KOpenWithDialog dlg({}, i18n("Select preferred file manager:"), QString(), this); | ||
45 | dlg.setSaveNewApplications(true); | 45 | dlg.setSaveNewApplications(true); | ||
46 | if (dlg.exec() != QDialog::Accepted) { | 46 | if (dlg.exec() != QDialog::Accepted) { | ||
47 | setCurrentIndex(m_currentIndex); | 47 | setCurrentIndex(m_currentIndex == -1 ? 0 : m_currentIndex); | ||
48 | return; | 48 | return; | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | const auto service = dlg.service(); | 51 | const auto service = dlg.service(); | ||
52 | 52 | | |||
53 | // if the selected service is already in the list | 53 | // if the selected service is already in the list | ||
54 | const auto matching = model()->match(model()->index(0,0), Qt::UserRole, service->storageId()); | 54 | const auto matching = model()->match(model()->index(0,0), Qt::UserRole, service->storageId()); | ||
55 | if (!matching.isEmpty()) { | 55 | if (!matching.isEmpty()) { | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 74 | { | |||
108 | emit changed(false); | 108 | emit changed(false); | ||
109 | } | 109 | } | ||
110 | 110 | | |||
111 | static const char s_DefaultApplications[] = "Default Applications"; | 111 | static const char s_DefaultApplications[] = "Default Applications"; | ||
112 | static const char s_AddedAssociations[] = "Added Associations"; | 112 | static const char s_AddedAssociations[] = "Added Associations"; | ||
113 | 113 | | |||
114 | void CfgFileManager::save(KConfig *) | 114 | void CfgFileManager::save(KConfig *) | ||
115 | { | 115 | { | ||
116 | if (currentIndex() == count() - 1) { | ||||
117 | // no filemanager installed, nor selected | ||||
118 | return; | ||||
119 | } | ||||
120 | | ||||
116 | const QString storageId = currentData().toString(); | 121 | const QString storageId = currentData().toString(); | ||
117 | if (!storageId.isEmpty()) { | | |||
crossi: I would have kept this test that is more clearer than `if (currentIndex() == count() - 1) {}`… | |||||
It would test twice the same thing : only the last value in the combobox can have an empty currendData. meven: It would test twice the same thing : only the last value in the combobox can have an empty… | |||||
118 | m_currentIndex = currentIndex(); | 122 | m_currentIndex = currentIndex(); | ||
119 | 123 | | |||
120 | // This is taken from filetypes/mimetypedata.cpp | 124 | // This is taken from filetypes/mimetypedata.cpp | ||
121 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | 125 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | ||
122 | if (!profile->isConfigWritable(true)) // warn user if mimeapps.list is root-owned (#155126/#94504) | 126 | if (!profile->isConfigWritable(true)) // warn user if mimeapps.list is root-owned (#155126/#94504) | ||
123 | return; | 127 | return; | ||
124 | KConfigGroup addedApps(profile, s_AddedAssociations); | 128 | KConfigGroup addedApps(profile, s_AddedAssociations); | ||
125 | QStringList userApps = addedApps.readXdgListEntry(mime); | 129 | QStringList userApps = addedApps.readXdgListEntry(mime); | ||
126 | userApps.removeAll(storageId); // remove if present, to make it first in the list | 130 | userApps.removeAll(storageId); // remove if present, to make it first in the list | ||
127 | userApps.prepend(storageId); | 131 | userApps.prepend(storageId); | ||
128 | addedApps.writeXdgListEntry(mime, userApps); | 132 | addedApps.writeXdgListEntry(mime, userApps); | ||
129 | 133 | | |||
130 | // Save the default file manager as per mime-apps spec 1.0.1 | 134 | // Save the default file manager as per mime-apps spec 1.0.1 | ||
131 | KConfigGroup defaultApp(profile, s_DefaultApplications); | 135 | KConfigGroup defaultApp(profile, s_DefaultApplications); | ||
132 | defaultApp.writeXdgListEntry(mime, QStringList(storageId)); | 136 | defaultApp.writeXdgListEntry(mime, QStringList(storageId)); | ||
133 | 137 | | |||
134 | profile->sync(); | 138 | profile->sync(); | ||
135 | 139 | | |||
136 | emit changed(false); | 140 | emit changed(false); | ||
137 | } | 141 | } | ||
138 | } | |
I would have kept this test that is more clearer than if (currentIndex() == count() - 1) {} if you confirm it works the same.