]> cloud.milkyroute.net Git - dolphin.git/blob - src/admin/workerintegration.h
"Group by - Type" now respects "Folders first" setting. Minor code cleanup
[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 * Used with the KMessageBox API so users can disable the warning.
27 * @see KMessageBox::saveDontShowAgainContinue()
28 * @see KMessageBox::enableMessage()
29 */
30 constexpr QLatin1String warningDontShowAgainName{"warnAboutRisksBeforeActingAsAdmin"};
31
32 /** @returns an elaborate warning about the dangers of acting with administrative privileges. */
33 QString warningMessage();
34
35 /**
36 * @brief A class encapsulating the "Act as Admin"-toggle action.
37 *
38 * @see https://commits.kde.org/kio-admin
39 */
40 class WorkerIntegration : public QObject
41 {
42 Q_OBJECT
43
44 public:
45 /**
46 * Adds a toggle action to the \a actionCollection.
47 * The action switches between acting as a normal user or acting as an administrator.
48 */
49 static void createActAsAdminAction(KActionCollection *actionCollection, DolphinMainWindow *dolphinMainWindow);
50
51 /**
52 * Triggers the m_actAsAdminAction only if it is currently checked.
53 */
54 static void exitAdminMode();
55
56 private:
57 WorkerIntegration(DolphinMainWindow *parent, QAction *actAsAdminAction);
58
59 /**
60 * Toggles between acting with admin rights or not.
61 * This enables editing more files than the normal user account would be allowed to but requires re-authorization.
62 */
63 void toggleActAsAdmin();
64
65 /** Updates the toggled/checked state of the action depending on the state of the currently active view. */
66 static void updateActAsAdminAction();
67
68 private:
69 /** @see createActAsAdminAction() */
70 QAction *const m_actAsAdminAction = nullptr;
71 };
72
73 }
74
75 #endif // ADMINWORKERINTEGRATION_H