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