]> cloud.milkyroute.net Git - dolphin.git/blob - src/admin/workerintegration.h
Stop acting as admin when the authorization expires
[dolphin.git] / src / admin / workerintegration.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8 #ifndef ADMINWORKERINTEGRATION_H
9 #define ADMINWORKERINTEGRATION_H
10
11 #include <QObject>
12
13 class DolphinMainWindow;
14 class KActionCollection;
15 class QAction;
16 class QUrl;
17
18 /**
19 * @brief This namespace contains everything that is necessary to nicely integrate "KIO Admin Worker" into Dolphin.
20 *
21 * @see https://commits.kde.org/kio-admin
22 */
23 namespace Admin
24 {
25 /**
26 * When a user starts Dolphin with arguments that imply that they want to use administrative rights, this method is called.
27 * This function acts like a command line program that guides users towards installing kio-admin. It will not return until this is accomplished.
28 * This function will do nothing if kio-admin is already installed.
29 */
30 void guideUserTowardsInstallingAdminWorker();
31
32 void guideUserTowardsUsingAdminWorker();
33
34 /**
35 * Used with the KMessageBox API so users can disable the warning.
36 * @see KMessageBox::saveDontShowAgainContinue()
37 * @see KMessageBox::enableMessage()
38 */
39 constexpr QLatin1String warningDontShowAgainName{"warnAboutRisksBeforeActingAsAdmin"};
40
41 /** @returns an elaborate warning about the dangers of acting with administrative privileges. */
42 QString warningMessage();
43
44 /**
45 * @brief A class encapsulating the "Act as Admin"-toggle action.
46 *
47 * @see https://commits.kde.org/kio-admin
48 */
49 class WorkerIntegration : public QObject
50 {
51 Q_OBJECT
52
53 public:
54 /**
55 * Adds a toggle action to the \a actionCollection.
56 * The action switches between acting as a normal user or acting as an administrator.
57 */
58 static void createActAsAdminAction(KActionCollection *actionCollection, DolphinMainWindow *dolphinMainWindow);
59
60 private:
61 WorkerIntegration(DolphinMainWindow *parent, QAction *actAsAdminAction);
62
63 /**
64 * Toggles between acting with admin rights or not.
65 * This enables editing more files than the normal user account would be allowed to but requires re-authorization.
66 */
67 void toggleActAsAdmin();
68
69 /** Updates the toggled/checked state of the action depending on the state of the currently active view. */
70 static void updateActAsAdminAction();
71
72 /** Used by the friend class Bar to show the m_actAsAdminAction to users. */
73 static QAction *actAsAdminAction();
74
75 private:
76 /** @see createActAsAdminAction() */
77 QAction *const m_actAsAdminAction = nullptr;
78
79 friend class Bar; // Allows the bar to access the actAsAdminAction, so users can use the bar to change who they are acting as.
80 };
81
82 }
83
84 #endif // ADMINWORKERINTEGRATION_H