┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/admin/workerintegration.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/admin/workerintegration.h')
-rw-r--r--src/admin/workerintegration.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/admin/workerintegration.h b/src/admin/workerintegration.h
new file mode 100644
index 000000000..512303744
--- /dev/null
+++ b/src/admin/workerintegration.h
@@ -0,0 +1,75 @@
+/*
+ This file is part of the KDE project
+ SPDX-FileCopyrightText: 2022 Felix Ernst <[email protected]>
+
+ SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#ifndef ADMINWORKERINTEGRATION_H
+#define ADMINWORKERINTEGRATION_H
+
+#include <QObject>
+
+class DolphinMainWindow;
+class KActionCollection;
+class QAction;
+class QUrl;
+
+/**
+ * @brief This namespace contains everything that is necessary to nicely integrate "KIO Admin Worker" into Dolphin.
+ *
+ * @see https://commits.kde.org/kio-admin
+ */
+namespace Admin
+{
+/**
+ * Used with the KMessageBox API so users can disable the warning.
+ * @see KMessageBox::saveDontShowAgainContinue()
+ * @see KMessageBox::enableMessage()
+ */
+constexpr QLatin1String warningDontShowAgainName{"warnAboutRisksBeforeActingAsAdmin"};
+
+/** @returns an elaborate warning about the dangers of acting with administrative privileges. */
+QString warningMessage();
+
+/**
+ * @brief A class encapsulating the "Act as Admin"-toggle action.
+ *
+ * @see https://commits.kde.org/kio-admin
+ */
+class WorkerIntegration : public QObject
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Adds a toggle action to the \a actionCollection.
+ * The action switches between acting as a normal user or acting as an administrator.
+ */
+ static void createActAsAdminAction(KActionCollection *actionCollection, DolphinMainWindow *dolphinMainWindow);
+
+ /**
+ * Triggers the m_actAsAdminAction only if it is currently checked.
+ */
+ static void exitAdminMode();
+
+private:
+ WorkerIntegration(DolphinMainWindow *parent, QAction *actAsAdminAction);
+
+ /**
+ * Toggles between acting with admin rights or not.
+ * This enables editing more files than the normal user account would be allowed to but requires re-authorization.
+ */
+ void toggleActAsAdmin();
+
+ /** Updates the toggled/checked state of the action depending on the state of the currently active view. */
+ static void updateActAsAdminAction();
+
+private:
+ /** @see createActAsAdminAction() */
+ QAction *const m_actAsAdminAction = nullptr;
+};
+
+}
+
+#endif // ADMINWORKERINTEGRATION_H