diff options
Diffstat (limited to 'src/admin')
| -rw-r--r-- | src/admin/bar.cpp | 6 | ||||
| -rw-r--r-- | src/admin/workerintegration.cpp | 10 | ||||
| -rw-r--r-- | src/admin/workerintegration.h | 20 |
3 files changed, 23 insertions, 13 deletions
diff --git a/src/admin/bar.cpp b/src/admin/bar.cpp index 52bbc3772..e01ef81a5 100644 --- a/src/admin/bar.cpp +++ b/src/admin/bar.cpp @@ -58,7 +58,7 @@ Bar::Bar(DolphinViewContainer *parentViewContainer) m_closeButton->setFlat(true); connect(m_closeButton, &QAbstractButton::clicked, m_parentViewContainer, [this]() { m_parentViewContainer->setActive(true); // Make sure the view connected to this bar is active before exiting admin mode. - QAction *actAsAdminAction = WorkerIntegration::actAsAdminAction(); + QAction *actAsAdminAction = WorkerIntegration::FriendAccess::actAsAdminAction(); if (actAsAdminAction->isChecked()) { actAsAdminAction->trigger(); } @@ -134,8 +134,8 @@ void Bar::hideTheNextTimeAuthorizationExpires() m_parentViewContainer->setUrl(viewContainerUrl); // Explain to users that their admin authorization expired. - if (!m_reenableActAsAdminAction) { - auto actAsAdminAction = WorkerIntegration::actAsAdminAction(); + if (!m_reenableActAsAdminAction) { // This code is similar to parts of DolphinViewContainer::slotViewErrorMessage(). + auto actAsAdminAction = WorkerIntegration::FriendAccess::actAsAdminAction(); m_reenableActAsAdminAction = new QAction{actAsAdminAction->icon(), i18nc("@action:button shown after acting as admin ended", "Act as Administrator Again"), this}; m_reenableActAsAdminAction->setToolTip(actAsAdminAction->toolTip()); diff --git a/src/admin/workerintegration.cpp b/src/admin/workerintegration.cpp index 0b95ec782..80d8fda1b 100644 --- a/src/admin/workerintegration.cpp +++ b/src/admin/workerintegration.cpp @@ -134,6 +134,11 @@ void WorkerIntegration::createActAsAdminAction(KActionCollection *actionCollecti } } +QAction *WorkerIntegration::FriendAccess::actAsAdminAction() +{ + return instance->m_actAsAdminAction; +} + void WorkerIntegration::toggleActAsAdmin() { auto dolphinMainWindow = static_cast<DolphinMainWindow *>(parent()); @@ -187,8 +192,3 @@ void WorkerIntegration::updateActAsAdminAction() } } } - -QAction *WorkerIntegration::actAsAdminAction() -{ - return instance->m_actAsAdminAction; -} diff --git a/src/admin/workerintegration.h b/src/admin/workerintegration.h index 19cc5c172..1e32c33d3 100644 --- a/src/admin/workerintegration.h +++ b/src/admin/workerintegration.h @@ -11,6 +11,7 @@ #include <QObject> class DolphinMainWindow; +class DolphinViewContainer; class KActionCollection; class QAction; class QUrl; @@ -57,6 +58,20 @@ public: */ static void createActAsAdminAction(KActionCollection *actionCollection, DolphinMainWindow *dolphinMainWindow); + /** + * An interface that only allows friend classes to show the WorkerIntegration::m_actAsAdminAction to users. + * Aside from these friend classes the action is only accessible through the actionCollection of DolphinMainWindow. + */ + class FriendAccess + { + /** @returns WorkerIntegration::m_actAsAdminAction or crashes if WorkerIntegration::createActAsAdminAction() has not been called previously. */ + static QAction *actAsAdminAction(); + + friend class Bar; /// Allows the bar to access the actAsAdminAction, so users can use the bar to change who they are acting as. + friend DolphinViewContainer; // Allows the view container to access the actAsAdminAction, so the action can be shown to users when they are trying to + // view a folder for which they are lacking read permissions. + }; + private: WorkerIntegration(DolphinMainWindow *parent, QAction *actAsAdminAction); @@ -69,14 +84,9 @@ private: /** Updates the toggled/checked state of the action depending on the state of the currently active view. */ static void updateActAsAdminAction(); - /** Used by the friend class Bar to show the m_actAsAdminAction to users. */ - static QAction *actAsAdminAction(); - private: /** @see createActAsAdminAction() */ QAction *const m_actAsAdminAction = nullptr; - - friend class Bar; // Allows the bar to access the actAsAdminAction, so users can use the bar to change who they are acting as. }; } |
