Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommand.cpp
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | |||||
114 | */ | 114 | */ | ||
115 | 115 | | |||
116 | /** Executes the external command. | 116 | /** Executes the external command. | ||
117 | @param timeout timeout to wait for the process to start | 117 | @param timeout timeout to wait for the process to start | ||
118 | @return true on success | 118 | @return true on success | ||
119 | */ | 119 | */ | ||
120 | bool ExternalCommand::start(int timeout) | 120 | bool ExternalCommand::start(int timeout) | ||
121 | { | 121 | { | ||
122 | Q_UNUSED(timeout) | | |||
123 | | ||||
124 | if (command().isEmpty()) | 122 | if (command().isEmpty()) | ||
125 | return false; | 123 | return false; | ||
126 | 124 | | |||
127 | if (!QDBusConnection::systemBus().isConnected()) { | 125 | if (!QDBusConnection::systemBus().isConnected()) { | ||
128 | qWarning() << QDBusConnection::systemBus().lastError().message(); | 126 | qWarning() << QDBusConnection::systemBus().lastError().message(); | ||
127 | QTimer::singleShot(timeout, this, &ExternalCommand::quit); | ||||
stikonas: &ExternalCommand::quit | |||||
129 | return false; | 128 | return false; | ||
130 | } | 129 | } | ||
131 | 130 | | |||
132 | if (report()) | 131 | if (report()) | ||
133 | report()->setCommand(xi18nc("@info:status", "Command: %1 %2", command(), args().join(QStringLiteral(" ")))); | 132 | report()->setCommand(xi18nc("@info:status", "Command: %1 %2", command(), args().join(QStringLiteral(" ")))); | ||
134 | 133 | | |||
135 | if ( qEnvironmentVariableIsSet( "KPMCORE_DEBUG" )) | 134 | if ( qEnvironmentVariableIsSet( "KPMCORE_DEBUG" )) | ||
136 | qDebug() << xi18nc("@info:status", "Command: %1 %2", command(), args().join(QStringLiteral(" "))); | 135 | qDebug() << xi18nc("@info:status", "Command: %1 %2", command(), args().join(QStringLiteral(" "))); | ||
Show All 26 Lines | 158 | else { | |||
163 | setExitCode(reply.value()[QStringLiteral("exitCode")].toInt()); | 162 | setExitCode(reply.value()[QStringLiteral("exitCode")].toInt()); | ||
164 | rval = reply.value()[QStringLiteral("success")].toBool(); | 163 | rval = reply.value()[QStringLiteral("success")].toBool(); | ||
165 | } | 164 | } | ||
166 | }; | 165 | }; | ||
167 | 166 | | |||
168 | connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop); | 167 | connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop); | ||
169 | loop.exec(); | 168 | loop.exec(); | ||
170 | 169 | | |||
170 | QTimer::singleShot(timeout, this, &ExternalCommand::quit); | ||||
171 | | ||||
171 | return rval; | 172 | return rval; | ||
172 | } | 173 | } | ||
173 | 174 | | |||
174 | bool ExternalCommand::copyBlocks(const CopySource& source, CopyTarget& target) | 175 | bool ExternalCommand::copyBlocks(const CopySource& source, CopyTarget& target) | ||
175 | { | 176 | { | ||
176 | bool rval = true; | 177 | bool rval = true; | ||
177 | const qint64 blockSize = 10 * 1024 * 1024; // number of bytes per block to copy | 178 | const qint64 blockSize = 10 * 1024 * 1024; // number of bytes per block to copy | ||
178 | 179 | | |||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | |||||
265 | } | 266 | } | ||
266 | 267 | | |||
267 | /** Runs the command. | 268 | /** Runs the command. | ||
268 | @param timeout timeout to use for waiting when starting and when waiting for the process to finish | 269 | @param timeout timeout to use for waiting when starting and when waiting for the process to finish | ||
269 | @return true on success | 270 | @return true on success | ||
270 | */ | 271 | */ | ||
271 | bool ExternalCommand::run(int timeout) | 272 | bool ExternalCommand::run(int timeout) | ||
272 | { | 273 | { | ||
274 | QTimer::singleShot(timeout, this, &ExternalCommand::quit); | ||||
273 | return start(timeout) /* && exitStatus() == 0*/; | 275 | return start(timeout) /* && exitStatus() == 0*/; | ||
274 | } | 276 | } | ||
275 | 277 | | |||
276 | void ExternalCommand::onReadOutput() | 278 | void ExternalCommand::onReadOutput() | ||
277 | { | 279 | { | ||
278 | // const QByteArray s = readAllStandardOutput(); | 280 | // const QByteArray s = readAllStandardOutput(); | ||
279 | // | 281 | // | ||
280 | // if(m_Output.length() > 10*1024*1024) { // prevent memory overflow for badly corrupted file systems | 282 | // if(m_Output.length() > 10*1024*1024) { // prevent memory overflow for badly corrupted file systems | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 335 | { | |||
334 | return d->m_Report; | 336 | return d->m_Report; | ||
335 | } | 337 | } | ||
336 | 338 | | |||
337 | void ExternalCommand::setExitCode(int i) | 339 | void ExternalCommand::setExitCode(int i) | ||
338 | { | 340 | { | ||
339 | d->m_ExitCode = i; | 341 | d->m_ExitCode = i; | ||
340 | } | 342 | } | ||
341 | 343 | | |||
344 | /**< Dummy function for QTimer when needed. */ | ||||
345 | void ExternalCommand::quit() | ||||
346 | { | ||||
347 | | ||||
348 | } | ||||
349 | | ||||
342 | bool ExternalCommand::startHelper() | 350 | bool ExternalCommand::startHelper() | ||
343 | { | 351 | { | ||
344 | if (!QDBusConnection::systemBus().isConnected()) { | 352 | if (!QDBusConnection::systemBus().isConnected()) { | ||
345 | qWarning() << QDBusConnection::systemBus().lastError().message(); | 353 | qWarning() << QDBusConnection::systemBus().lastError().message(); | ||
346 | return false; | 354 | return false; | ||
347 | } | 355 | } | ||
348 | 356 | | |||
349 | QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"), QStringLiteral("/Helper"), QStringLiteral("org.kde.kpmcore.externalcommand"), QDBusConnection::systemBus()); | 357 | QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"), QStringLiteral("/Helper"), QStringLiteral("org.kde.kpmcore.externalcommand"), QDBusConnection::systemBus()); | ||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |
&ExternalCommand::quit