Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommand.cpp
Show First 20 Lines • Show All 177 Lines • ▼ Show 20 Line(s) | 176 | { | |||
---|---|---|---|---|---|
178 | 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 | ||
179 | 179 | | |||
180 | if (!QDBusConnection::systemBus().isConnected()) { | 180 | if (!QDBusConnection::systemBus().isConnected()) { | ||
181 | qWarning() << QDBusConnection::systemBus().lastError().message(); | 181 | qWarning() << QDBusConnection::systemBus().lastError().message(); | ||
182 | return false; | 182 | return false; | ||
183 | } | 183 | } | ||
184 | 184 | | |||
185 | auto interface = new org::kde::kpmcore::externalcommand(QStringLiteral("org.kde.kpmcore.externalcommand"), | 185 | auto interface = new org::kde::kpmcore::externalcommand(QStringLiteral("org.kde.kpmcore.externalcommand"), | ||
186 | | ||||
187 | | ||||
188 | | ||||
189 | | ||||
190 | QStringLiteral("/Helper"), QDBusConnection::systemBus(), this); | 186 | QStringLiteral("/Helper"), QDBusConnection::systemBus(), this); | ||
191 | interface->setTimeout(10 * 24 * 3600 * 1000); // 10 days | 187 | interface->setTimeout(10 * 24 * 3600 * 1000); // 10 days | ||
192 | 188 | | |||
193 | QDBusPendingCall pcall = interface->copyblocks(source.path(), source.firstByte(), source.length(), | 189 | QDBusPendingCall pcall = interface->copyblocks(source.path(), source.firstByte(), source.length(), | ||
194 | target.path(), target.firstByte(), blockSize); | 190 | target.path(), target.firstByte(), blockSize); | ||
195 | 191 | | |||
196 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); | 192 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); | ||
197 | QEventLoop loop; | 193 | QEventLoop loop; | ||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Line(s) | 346 | { | |||
368 | 364 | | |||
369 | // initialize KDE Polkit daemon | 365 | // initialize KDE Polkit daemon | ||
370 | m_authJob->initPolkitAgent(QStringLiteral("org.kde.kpmcore.externalcommand.init"), parent); | 366 | m_authJob->initPolkitAgent(QStringLiteral("org.kde.kpmcore.externalcommand.init"), parent); | ||
371 | 367 | | |||
372 | bool isActionAuthorized = m_authJob->authorizeAction(QStringLiteral("org.kde.kpmcore.externalcommand.init"), m_authJob->callerID()); | 368 | bool isActionAuthorized = m_authJob->authorizeAction(QStringLiteral("org.kde.kpmcore.externalcommand.init"), m_authJob->callerID()); | ||
373 | 369 | | |||
374 | auto authResult = m_authJob->actionStatus(QStringLiteral("org.kde.kpmcore.externalcommand.init"), m_authJob->callerID()); | 370 | auto authResult = m_authJob->actionStatus(QStringLiteral("org.kde.kpmcore.externalcommand.init"), m_authJob->callerID()); | ||
375 | 371 | | |||
376 | 372 | // Wait until ExternalCommand Helper is ready and sends signal(Connect to newData signal) | |||
377 | // Wait until ExternalCommand Helper is ready and sends signal | | |||
378 | QEventLoop loop; | 373 | QEventLoop loop; | ||
379 | auto exitLoop = [&] () { loop.exit(); }; | 374 | auto exitLoop = [&] () { loop.exit(); }; | ||
380 | 375 | | |||
376 | ExternalCommand cmd; | ||||
377 | auto conn = QObject::connect(&cmd, &ExternalCommand::newData, exitLoop); | ||||
stikonas: Fix this, this will give you infinite recursion. | |||||
381 | 378 | | |||
382 | loop.exec(); | 379 | loop.exec(); | ||
383 | 380 | | |||
381 | QObject::disconnect(conn); | ||||
382 | | ||||
384 | if (!isActionAuthorized || authResult == PolkitQt1::Authority::No || authResult == PolkitQt1::Authority::Unknown) { | 383 | if (!isActionAuthorized || authResult == PolkitQt1::Authority::No || authResult == PolkitQt1::Authority::Unknown) { | ||
385 | qDebug() << "Unable to obtain Administrative privileges, the action can not be executed!!"; | 384 | qDebug() << "Unable to obtain Administrative privileges, the action can not be executed!!"; | ||
386 | } | 385 | } | ||
387 | 386 | | |||
388 | helperStarted = true; | 387 | helperStarted = true; | ||
389 | return true; | 388 | return true; | ||
390 | } | 389 | } | ||
391 | 390 | | |||
392 | void ExternalCommand::stopHelper() | 391 | void ExternalCommand::stopHelper() | ||
393 | { | 392 | { | ||
394 | auto interface = new org::kde::kpmcore::externalcommand(QStringLiteral("org.kde.kpmcore.externalcommand"), | 393 | auto interface = new org::kde::kpmcore::externalcommand(QStringLiteral("org.kde.kpmcore.externalcommand"), | ||
395 | QStringLiteral("/Helper"), QDBusConnection::systemBus()); | 394 | QStringLiteral("/Helper"), QDBusConnection::systemBus()); | ||
396 | interface->exit(); | 395 | interface->exit(); | ||
397 | 396 | | |||
398 | } | 397 | } | ||
399 | 398 | | |||
399 | void ExternalCommand::emitNewData(int percent) | ||||
400 | { | ||||
401 | Q_UNUSED(percent) | ||||
402 | emit newData(); | ||||
403 | } | ||||
404 | | ||||
405 | void ExternalCommand::emitNewData(QString& message) | ||||
406 | { | ||||
407 | Q_UNUSED(message) | ||||
408 | emit newData(); | ||||
409 | } | ||||
410 | | ||||
400 | void DBusThread::run() | 411 | void DBusThread::run() | ||
401 | { | 412 | { | ||
402 | if (!QDBusConnection::systemBus().registerService(QStringLiteral("org.kde.kpmcore.applicationinterface")) || | 413 | if (!QDBusConnection::systemBus().registerService(QStringLiteral("org.kde.kpmcore.applicationinterface")) || | ||
403 | !QDBusConnection::systemBus().registerObject(QStringLiteral("/Application"), this, QDBusConnection::ExportAllSlots)) { | 414 | !QDBusConnection::systemBus().registerObject(QStringLiteral("/Application"), this, QDBusConnection::ExportAllSlots)) { | ||
404 | qWarning() << QDBusConnection::systemBus().lastError().message(); | 415 | qWarning() << QDBusConnection::systemBus().lastError().message(); | ||
405 | return; | 416 | return; | ||
406 | } | 417 | } | ||
407 | 418 | | |||
408 | QEventLoop loop; | 419 | QEventLoop loop; | ||
409 | loop.exec(); | 420 | loop.exec(); | ||
410 | } | 421 | } |
Fix this, this will give you infinite recursion.