Changeset View
Changeset View
Standalone View
Standalone View
kcms/keys/shortcutsmodel.cpp
Show First 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | 146 | for (auto& component : m_components) { | |||
---|---|---|---|---|---|
149 | } | 149 | } | ||
150 | for (auto& shortcut : component.shortcuts) { | 150 | for (auto& shortcut : component.shortcuts) { | ||
151 | if (shortcut.initialShortcuts != shortcut.activeShortcuts) { | 151 | if (shortcut.initialShortcuts != shortcut.activeShortcuts) { | ||
152 | const QStringList actionId = buildActionId(component.uniqueName, component.friendlyName, | 152 | const QStringList actionId = buildActionId(component.uniqueName, component.friendlyName, | ||
153 | shortcut.uniqueName, shortcut.friendlyName); | 153 | shortcut.uniqueName, shortcut.friendlyName); | ||
154 | //operator int of QKeySequence | 154 | //operator int of QKeySequence | ||
155 | QList<int> keys(shortcut.activeShortcuts.cbegin(), shortcut.activeShortcuts.cend()); | 155 | QList<int> keys(shortcut.activeShortcuts.cbegin(), shortcut.activeShortcuts.cend()); | ||
156 | qCDebug(KCMKEYS) << "Saving" << actionId << shortcut.activeShortcuts << keys; | 156 | qCDebug(KCMKEYS) << "Saving" << actionId << shortcut.activeShortcuts << keys; | ||
157 | auto watcher = new QDBusPendingCallWatcher(m_globalAccelInterface->setForeignShortcut(actionId, keys)); | 157 | auto reply = m_globalAccelInterface->setForeignShortcut(actionId, keys); | ||
158 | connect(watcher, &QDBusPendingCallWatcher::finished, this, [&, watcher] { | 158 | reply.waitForFinished(); | ||
159 | QDBusPendingReply<> reply = *watcher; | | |||
160 | if (!reply.isValid()) { | 159 | if (!reply.isValid()) { | ||
161 | qCCritical(KCMKEYS) << "Error while saving"; | 160 | qCCritical(KCMKEYS) << "Error while saving"; | ||
162 | if (reply.error().isValid()) { | 161 | if (reply.error().isValid()) { | ||
163 | qCCritical(KCMKEYS) << reply.error().name() << reply.error().message(); | 162 | qCCritical(KCMKEYS) << reply.error().name() << reply.error().message(); | ||
164 | } | 163 | } | ||
165 | emit errorOccured(i18nc("%1 is the name of the component, %2 is the action for which saving failed", | 164 | emit errorOccured(i18nc("%1 is the name of the component, %2 is the action for which saving failed", | ||
166 | "Error while saving shortcut %1: %2", component.friendlyName, shortcut.friendlyName)); | 165 | "Error while saving shortcut %1: %2", component.friendlyName, shortcut.friendlyName)); | ||
167 | } else { | 166 | } else { | ||
168 | shortcut.initialShortcuts = shortcut.activeShortcuts; | 167 | shortcut.initialShortcuts = shortcut.activeShortcuts; | ||
169 | } | 168 | } | ||
170 | watcher->deleteLater(); | | |||
171 | }); | | |||
172 | } | 169 | } | ||
173 | } | 170 | } | ||
174 | } | 171 | } | ||
175 | } | 172 | } | ||
176 | 173 | | |||
177 | void ShortcutsModel::defaults() { | 174 | void ShortcutsModel::defaults() { | ||
178 | for (auto component = m_components.begin(); component != m_components.end(); ++component) { | 175 | for (auto component = m_components.begin(); component != m_components.end(); ++component) { | ||
179 | auto componentIndex = index(component - m_components.begin(), 0); | 176 | auto componentIndex = index(component - m_components.begin(), 0); | ||
▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Line(s) | 431 | connect(infoWatcher, &QDBusPendingCallWatcher::finished, this, [=] { | |||
445 | emit endInsertRows(); | 442 | emit endInsertRows(); | ||
446 | }); | 443 | }); | ||
447 | }); | 444 | }); | ||
448 | } | 445 | } | ||
449 | 446 | | |||
450 | void ShortcutsModel::removeComponent(const Component &component) | 447 | void ShortcutsModel::removeComponent(const Component &component) | ||
451 | { | 448 | { | ||
452 | const QString &uniqueName = component.uniqueName; | 449 | const QString &uniqueName = component.uniqueName; | ||
453 | auto watcher = new QDBusPendingCallWatcher(m_globalAccelInterface->getComponent(uniqueName)); | 450 | auto componentReply = m_globalAccelInterface->getComponent(uniqueName); | ||
454 | connect(watcher, &QDBusPendingCallWatcher::finished, this, [=] { | 451 | componentReply.waitForFinished(); | ||
455 | QDBusPendingReply<QDBusObjectPath> reply = *watcher; | 452 | if (!componentReply.isValid()) { | ||
456 | watcher->deleteLater(); | 453 | genericErrorOccured(QStringLiteral("Error while calling objectPath of component") + uniqueName, componentReply.error()); | ||
457 | if (!reply.isValid()) { | | |||
458 | genericErrorOccured(QStringLiteral("Error while calling objectPath of component") + uniqueName, reply.error()); | | |||
459 | return; | 454 | return; | ||
460 | } | 455 | } | ||
461 | KGlobalAccelComponentInterface component(m_globalAccelInterface->service(), reply.value().path(), m_globalAccelInterface->connection()); | 456 | KGlobalAccelComponentInterface componentInterface(m_globalAccelInterface->service(), componentReply.value().path(), m_globalAccelInterface->connection()); | ||
462 | qCDebug(KCMKEYS) << "Cleaning up component at" << reply.value(); | 457 | qCDebug(KCMKEYS) << "Cleaning up component at" << componentReply.value(); | ||
463 | auto cleanUpWatcher = new QDBusPendingCallWatcher(component.cleanUp()); | 458 | auto cleanUpReply = componentInterface.cleanUp(); | ||
464 | connect(cleanUpWatcher, &QDBusPendingCallWatcher::finished, this, [=] { | 459 | cleanUpReply.waitForFinished(); | ||
465 | QDBusPendingReply<bool> reply = *cleanUpWatcher; | 460 | if (!cleanUpReply.isValid()) { | ||
466 | cleanUpWatcher->deleteLater(); | 461 | genericErrorOccured(QStringLiteral("Error while calling cleanUp of component") + uniqueName, cleanUpReply.error()); | ||
467 | if (!reply.isValid()) { | | |||
468 | genericErrorOccured(QStringLiteral("Error while calling cleanUp of component") + uniqueName, reply.error()); | | |||
469 | return; | 462 | return; | ||
470 | } | 463 | } | ||
471 | auto it = std::find_if(m_components.begin(), m_components.end(), [&](const Component &c) { | 464 | auto it = std::find_if(m_components.begin(), m_components.end(), [&](const Component &c) { | ||
472 | return c.uniqueName == uniqueName; | 465 | return c.uniqueName == uniqueName; | ||
473 | }); | 466 | }); | ||
474 | const int row = it - m_components.begin(); | 467 | const int row = it - m_components.begin(); | ||
475 | beginRemoveRows(QModelIndex(), row, row); | 468 | beginRemoveRows(QModelIndex(), row, row); | ||
476 | m_components.remove(row); | 469 | m_components.remove(row); | ||
477 | endRemoveRows(); | 470 | endRemoveRows(); | ||
478 | }); | | |||
479 | }); | | |||
480 | } | 471 | } | ||
481 | 472 | | |||
482 | void ShortcutsModel::genericErrorOccured(const QString &description, const QDBusError &error) | 473 | void ShortcutsModel::genericErrorOccured(const QString &description, const QDBusError &error) | ||
483 | { | 474 | { | ||
484 | qCCritical(KCMKEYS) << description; | 475 | qCCritical(KCMKEYS) << description; | ||
485 | if (error.isValid()) { | 476 | if (error.isValid()) { | ||
486 | qCCritical(KCMKEYS) << error.name() << error.message(); | 477 | qCCritical(KCMKEYS) << error.name() << error.message(); | ||
487 | } | 478 | } | ||
488 | emit this->errorOccured(i18n("Error while communicating with the global shortcuts service")); | 479 | emit this->errorOccured(i18n("Error while communicating with the global shortcuts service")); | ||
489 | } | 480 | } |