Changeset View
Changeset View
Standalone View
Standalone View
kcms/colors/colors.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include <KLocalizedString> | 42 | #include <KLocalizedString> | ||
43 | #include <KPluginFactory> | 43 | #include <KPluginFactory> | ||
44 | #include <KWindowSystem> | 44 | #include <KWindowSystem> | ||
45 | 45 | | |||
46 | #include <KIO/FileCopyJob> | 46 | #include <KIO/FileCopyJob> | ||
47 | #include <KIO/DeleteJob> | 47 | #include <KIO/DeleteJob> | ||
48 | #include <KIO/JobUiDelegate> | 48 | #include <KIO/JobUiDelegate> | ||
49 | 49 | | |||
50 | #include <knewstuffcore_version.h> | ||||
51 | #if KNEWSTUFFCORE_VERSION_MAJOR==5 && KNEWSTUFFCORE_VERSION_MINOR>=67 | ||||
52 | #include <KNSCore/EntryWrapper> | ||||
53 | #endif | ||||
54 | | ||||
50 | #include <algorithm> | 55 | #include <algorithm> | ||
51 | 56 | | |||
52 | #include "../krdb/krdb.h" | 57 | #include "../krdb/krdb.h" | ||
53 | 58 | | |||
54 | #include "colorsmodel.h" | 59 | #include "colorsmodel.h" | ||
55 | #include "filterproxymodel.h" | 60 | #include "filterproxymodel.h" | ||
56 | #include "colorssettings.h" | 61 | #include "colorssettings.h" | ||
57 | 62 | | |||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 113 | { | |||
109 | return m_settings; | 114 | return m_settings; | ||
110 | } | 115 | } | ||
111 | 116 | | |||
112 | bool KCMColors::downloadingFile() const | 117 | bool KCMColors::downloadingFile() const | ||
113 | { | 118 | { | ||
114 | return m_tempCopyJob; | 119 | return m_tempCopyJob; | ||
115 | } | 120 | } | ||
116 | 121 | | |||
117 | void KCMColors::getNewStuff(QQuickItem *ctx) | 122 | void KCMColors::reloadModel(const QQmlListReference &changedEntries) | ||
118 | { | 123 | { | ||
119 | if (!m_newStuffDialog) { | | |||
120 | m_newStuffDialog = new KNS3::DownloadDialog(QStringLiteral("colorschemes.knsrc")); | | |||
121 | m_newStuffDialog.data()->setWindowTitle(i18n("Download New Color Schemes")); | | |||
122 | m_newStuffDialog->setWindowModality(Qt::WindowModal); | | |||
123 | m_newStuffDialog->winId(); // so it creates the windowHandle(); | | |||
124 | | ||||
125 | connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::accepted, this, [this] { | | |||
126 | m_model->load(); | 124 | m_model->load(); | ||
127 | 125 | | |||
128 | const auto newEntries = m_newStuffDialog->installedEntries(); | 126 | #if KNEWSTUFFCORE_VERSION_MAJOR==5 && KNEWSTUFFCORE_VERSION_MINOR>=67 | ||
129 | // If one new theme was installed, select the first color file in it | 127 | // If one new theme was installed, select the first color file in it | ||
130 | if (newEntries.count() == 1) { | 128 | if (changedEntries.count() > 1) { | ||
131 | QStringList installedThemes; | 129 | QStringList installedThemes; | ||
ngraham: This wraps a lot of existing functionality into that conditional as well. Was all of that stuff… | |||||
All the code inside this conditional is for setting the most recent newly installed theme as the currently selected - perhaps a slightly long winded way of doing so, but yup, that's really all it does :) (and if it can't use the data being pulled out of the changedEntries, there doesn't seem any good reason to run the rest of the code which arguably would build and run, as it just wouldn't do anything) leinir: All the code inside this conditional is for setting the most recent newly installed theme as… | |||||
132 | 130 | | |||
133 | const QString suffix = QStringLiteral(".colors"); | 131 | const QString suffix = QStringLiteral(".colors"); | ||
134 | 132 | | |||
135 | for (const QString &path : newEntries.first().installedFiles()) { | 133 | for (int i = 0; i < changedEntries.count(); ++i) { | ||
134 | KNSCore::EntryWrapper* entry = qobject_cast<KNSCore::EntryWrapper*>(changedEntries.at(i)); | ||||
135 | if (entry && entry->entry().status() == KNS3::Entry::Installed) { | ||||
136 | for (const QString &path : entry->entry().installedFiles()) { | ||||
136 | const QString fileName = path.section(QLatin1Char('/'), -1, -1); | 137 | const QString fileName = path.section(QLatin1Char('/'), -1, -1); | ||
137 | 138 | | |||
138 | const int suffixPos = fileName.indexOf(suffix); | 139 | const int suffixPos = fileName.indexOf(suffix); | ||
139 | if (suffixPos != fileName.length() - suffix.length()) { | 140 | if (suffixPos != fileName.length() - suffix.length()) { | ||
140 | continue; | 141 | continue; | ||
141 | } | 142 | } | ||
142 | 143 | | |||
143 | installedThemes.append(fileName.left(suffixPos)); | 144 | installedThemes.append(fileName.left(suffixPos)); | ||
144 | } | 145 | } | ||
145 | 146 | | |||
146 | if (!installedThemes.isEmpty()) { | 147 | if (!installedThemes.isEmpty()) { | ||
147 | // The list is sorted by (potentially translated) name | 148 | // The list is sorted by (potentially translated) name | ||
148 | // but that would require us parse every file, so this should be close enough | 149 | // but that would require us parse every file, so this should be close enough | ||
149 | std::sort(installedThemes.begin(), installedThemes.end()); | 150 | std::sort(installedThemes.begin(), installedThemes.end()); | ||
150 | 151 | | |||
151 | m_model->setSelectedScheme(installedThemes.constFirst()); | 152 | m_model->setSelectedScheme(installedThemes.constFirst()); | ||
152 | } | 153 | } | ||
154 | // Only do this for the first newly installed theme we find | ||||
155 | break; | ||||
153 | } | 156 | } | ||
154 | }); | | |||
155 | } | 157 | } | ||
156 | | ||||
157 | if (ctx && ctx->window()) { | | |||
158 | m_newStuffDialog->windowHandle()->setTransientParent(ctx->window()); | | |||
159 | } | 158 | } | ||
160 | 159 | #endif | |||
161 | m_newStuffDialog.data()->show(); | | |||
162 | } | 160 | } | ||
163 | 161 | | |||
164 | void KCMColors::installSchemeFromFile(const QUrl &url) | 162 | void KCMColors::installSchemeFromFile(const QUrl &url) | ||
165 | { | 163 | { | ||
166 | if (url.isLocalFile()) { | 164 | if (url.isLocalFile()) { | ||
167 | installSchemeFile(url.toLocalFile()); | 165 | installSchemeFile(url.toLocalFile()); | ||
168 | return; | 166 | return; | ||
169 | } | 167 | } | ||
▲ Show 20 Lines • Show All 311 Lines • Show Last 20 Lines |
This wraps a lot of existing functionality into that conditional as well. Was all of that stuff broken and useless without D26543?
Everything seems to work anyway, but I'm curious to know if everything here needs to be wrapped up in this.