Changeset View
Changeset View
Standalone View
Standalone View
src/core/slavebase.cpp
Show All 29 Lines | |||||
30 | 30 | | |||
31 | #include <stdlib.h> | 31 | #include <stdlib.h> | ||
32 | #include <qplatformdefs.h> | 32 | #include <qplatformdefs.h> | ||
33 | #include <signal.h> | 33 | #include <signal.h> | ||
34 | #ifdef Q_OS_WIN | 34 | #ifdef Q_OS_WIN | ||
35 | #include <process.h> | 35 | #include <process.h> | ||
36 | #endif | 36 | #endif | ||
37 | 37 | | |||
38 | #include <QtGlobal> | ||||
dfaure: what is this used for? | |||||
38 | #include <QFile> | 39 | #include <QFile> | ||
39 | #include <QList> | 40 | #include <QList> | ||
40 | #include <QDateTime> | 41 | #include <QDateTime> | ||
41 | #include <QElapsedTimer> | 42 | #include <QElapsedTimer> | ||
42 | #include <QCoreApplication> | 43 | #include <QCoreApplication> | ||
43 | #include <QDataStream> | 44 | #include <QDataStream> | ||
45 | #include <QMap> | ||||
44 | 46 | | |||
45 | #include <kconfig.h> | 47 | #include <kconfig.h> | ||
46 | #include <kconfiggroup.h> | 48 | #include <kconfiggroup.h> | ||
47 | #include <kcrash.h> | 49 | #include <kcrash.h> | ||
48 | #include <klocalizedstring.h> | 50 | #include <klocalizedstring.h> | ||
49 | 51 | | |||
50 | #include "kremoteencoding.h" | 52 | #include "kremoteencoding.h" | ||
51 | 53 | | |||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 84 | public: | |||
110 | bool needSendCanResume: 1; | 112 | bool needSendCanResume: 1; | ||
111 | bool onHold: 1; | 113 | bool onHold: 1; | ||
112 | bool wasKilled: 1; | 114 | bool wasKilled: 1; | ||
113 | bool inOpenLoop: 1; | 115 | bool inOpenLoop: 1; | ||
114 | bool exit_loop: 1; | 116 | bool exit_loop: 1; | ||
115 | MetaData configData; | 117 | MetaData configData; | ||
116 | KConfig *config; | 118 | KConfig *config; | ||
117 | KConfigGroup *configGroup; | 119 | KConfigGroup *configGroup; | ||
120 | QMap<QString, QVariant> mapConfig; | ||||
118 | QUrl onHoldUrl; | 121 | QUrl onHoldUrl; | ||
119 | 122 | | |||
120 | QElapsedTimer lastTimeout; | 123 | QElapsedTimer lastTimeout; | ||
121 | QElapsedTimer nextTimeout; | 124 | QElapsedTimer nextTimeout; | ||
122 | qint64 nextTimeoutMsecs; | 125 | qint64 nextTimeoutMsecs; | ||
123 | KIO::filesize_t totalSize; | 126 | KIO::filesize_t totalSize; | ||
124 | KRemoteEncoding *remotefile; | 127 | KRemoteEncoding *remotefile; | ||
125 | enum { Idle, InsideMethod, FinishedCalled, ErrorCalled } m_state; | 128 | enum { Idle, InsideMethod, FinishedCalled, ErrorCalled } m_state; | ||
Show All 39 Lines | 165 | #endif | |||
165 | bool hasTempAuth() const | 168 | bool hasTempAuth() const | ||
166 | { | 169 | { | ||
167 | return !m_tempAuths.isEmpty(); | 170 | return !m_tempAuths.isEmpty(); | ||
168 | } | 171 | } | ||
169 | 172 | | |||
170 | // Reconstructs configGroup from configData and mIncomingMetaData | 173 | // Reconstructs configGroup from configData and mIncomingMetaData | ||
171 | void rebuildConfig() | 174 | void rebuildConfig() | ||
172 | { | 175 | { | ||
173 | configGroup->deleteGroup(KConfigGroup::WriteConfigFlags()); | 176 | mapConfig.clear(); | ||
174 | 177 | | |||
175 | // mIncomingMetaData cascades over config, so we write config first, | 178 | // mIncomingMetaData cascades over config, so we write config first, | ||
176 | // to let it be overwritten | 179 | // to let it be overwritten | ||
177 | MetaData::ConstIterator end = configData.constEnd(); | 180 | MetaData::ConstIterator end = configData.constEnd(); | ||
178 | for (MetaData::ConstIterator it = configData.constBegin(); it != end; ++it) { | 181 | for (MetaData::ConstIterator it = configData.constBegin(); it != end; ++it) { | ||
179 | configGroup->writeEntry(it.key(), it->toUtf8(), KConfigGroup::WriteConfigFlags()); | 182 | mapConfig.insert(it.key(), it->toUtf8()); | ||
180 | } | 183 | } | ||
181 | 184 | | |||
182 | end = q->mIncomingMetaData.constEnd(); | 185 | end = q->mIncomingMetaData.constEnd(); | ||
183 | for (MetaData::ConstIterator it = q->mIncomingMetaData.constBegin(); it != end; ++it) { | 186 | for (MetaData::ConstIterator it = q->mIncomingMetaData.constBegin(); it != end; ++it) { | ||
184 | configGroup->writeEntry(it.key(), it->toUtf8(), KConfigGroup::WriteConfigFlags()); | 187 | mapConfig.insert(it.key(), it->toUtf8()); | ||
185 | } | 188 | } | ||
189 | | ||||
broulik: `delete nullptr` is fine, no need to check first | |||||
190 | delete configGroup; | ||||
191 | configGroup = nullptr; | ||||
missing config = nullptr so the delete config in the destructor doesn't crash. Same with configGroup. dfaure: missing `config = nullptr` so the `delete config` in the destructor doesn't crash.
Same with… | |||||
192 | delete config; | ||||
193 | config = nullptr; | ||||
186 | } | 194 | } | ||
187 | 195 | | |||
188 | void verifyState(const char *cmdName) | 196 | void verifyState(const char *cmdName) | ||
189 | { | 197 | { | ||
190 | if ((m_state != FinishedCalled) && (m_state != ErrorCalled)) { | 198 | if ((m_state != FinishedCalled) && (m_state != ErrorCalled)) { | ||
191 | qCWarning(KIO_CORE) << cmdName << "did not call finished() or error()! Please fix the" << QCoreApplication::applicationName() << "KIO slave"; | 199 | qCWarning(KIO_CORE) << cmdName << "did not call finished() or error()! Please fix the" << QCoreApplication::applicationName() << "KIO slave"; | ||
192 | } | 200 | } | ||
193 | } | 201 | } | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 272 | #endif | |||
266 | globalSlave = this; | 274 | globalSlave = this; | ||
267 | 275 | | |||
268 | d->isConnectedToApp = true; | 276 | d->isConnectedToApp = true; | ||
269 | 277 | | |||
270 | // by kahl for netmgr (need a way to identify slaves) | 278 | // by kahl for netmgr (need a way to identify slaves) | ||
271 | d->slaveid = QString::fromUtf8(protocol) + QString::number(getpid()); | 279 | d->slaveid = QString::fromUtf8(protocol) + QString::number(getpid()); | ||
272 | d->resume = false; | 280 | d->resume = false; | ||
273 | d->needSendCanResume = false; | 281 | d->needSendCanResume = false; | ||
274 | d->config = new KConfig(QString(), KConfig::SimpleConfig); | 282 | d->mapConfig = QMap<QString, QVariant>(); | ||
broulik: This is initialized automatically like this | |||||
That's on purpose, the first use of mapConfig is in rebuildConfig and is a clear() call. meven: That's on purpose, the first use of mapConfig is in rebuildConfig and is a clear() call. | |||||
So? This line is not needed, an empty map is an empty map, no need to assign an empty map to it. dfaure: So? This line is not needed, an empty map is an empty map, no need to assign an empty map to it. | |||||
275 | // The KConfigGroup needs the KConfig to exist during its whole lifetime. | | |||
276 | d->configGroup = new KConfigGroup(d->config, QString()); | | |||
277 | d->onHold = false; | 283 | d->onHold = false; | ||
278 | d->wasKilled = false; | 284 | d->wasKilled = false; | ||
279 | // d->processed_size = 0; | 285 | // d->processed_size = 0; | ||
280 | d->totalSize = 0; | 286 | d->totalSize = 0; | ||
281 | connectSlave(QFile::decodeName(app_socket)); | 287 | connectSlave(QFile::decodeName(app_socket)); | ||
282 | 288 | | |||
283 | d->remotefile = nullptr; | 289 | d->remotefile = nullptr; | ||
284 | d->inOpenLoop = false; | 290 | d->inOpenLoop = false; | ||
285 | d->exit_loop = false; | 291 | d->exit_loop = false; | ||
286 | } | 292 | } | ||
287 | 293 | | |||
288 | SlaveBase::~SlaveBase() | 294 | SlaveBase::~SlaveBase() | ||
289 | { | 295 | { | ||
290 | delete d->configGroup; | 296 | delete d->configGroup; | ||
broulik: Don't you still want this? | |||||
291 | delete d->config; | 297 | delete d->config; | ||
292 | delete d->remotefile; | 298 | delete d->remotefile; | ||
293 | delete d; | 299 | delete d; | ||
294 | s_protocol = ""; | 300 | s_protocol = ""; | ||
295 | } | 301 | } | ||
296 | 302 | | |||
297 | void SlaveBase::dispatchLoop() | 303 | void SlaveBase::dispatchLoop() | ||
298 | { | 304 | { | ||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 404 | if (mIncomingMetaData.contains(key)) { | |||
399 | return true; | 405 | return true; | ||
400 | } | 406 | } | ||
401 | if (d->configData.contains(key)) { | 407 | if (d->configData.contains(key)) { | ||
402 | return true; | 408 | return true; | ||
403 | } | 409 | } | ||
404 | return false; | 410 | return false; | ||
405 | } | 411 | } | ||
406 | 412 | | |||
413 | QMap<QString, QVariant> SlaveBase::mapConfig() const | ||||
That is a weird abuse of const. If the member wasn't in a d pointer, this wouldn't compile. If the slave is supposed to only read from the map, then it should be a value or const ref. dfaure: That is a weird abuse of const. If the member wasn't in a d pointer, this wouldn't compile.
If… | |||||
414 | { | ||||
415 | return d->mapConfig; | ||||
416 | } | ||||
417 | | ||||
407 | KConfigGroup *SlaveBase::config() | 418 | KConfigGroup *SlaveBase::config() | ||
408 | { | 419 | { | ||
420 | if (!d->config) { | ||||
broulik: Just check `if (!d->config)` | |||||
421 | d->config = new KConfig(QString(), KConfig::SimpleConfig); | ||||
422 | | ||||
423 | d->configGroup = new KConfigGroup(d->config, QString()); | ||||
424 | | ||||
425 | auto end = d->mapConfig.cend(); | ||||
426 | for (auto it = d->mapConfig.cbegin(); it != end; ++it) | ||||
427 | { | ||||
428 | d->configGroup->writeEntry(it.key(), it->toString().toUtf8(), KConfigGroup::WriteConfigFlags()); | ||||
429 | } | ||||
430 | } | ||||
431 | | ||||
409 | return d->configGroup; | 432 | return d->configGroup; | ||
410 | } | 433 | } | ||
411 | 434 | | |||
412 | void SlaveBase::sendMetaData() | 435 | void SlaveBase::sendMetaData() | ||
413 | { | 436 | { | ||
414 | sendAndKeepMetaData(); | 437 | sendAndKeepMetaData(); | ||
415 | mOutgoingMetaData.clear(); | 438 | mOutgoingMetaData.clear(); | ||
416 | } | 439 | } | ||
▲ Show 20 Lines • Show All 1067 Lines • Show Last 20 Lines |
what is this used for?