┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/admin/workerintegration.h
blob: 0c87c2ecf28228780b86c91c45bad623608bf4fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
    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
{
/**
 * When a user starts Dolphin with arguments that imply that they want to use administrative rights, this method is called.
 * This function acts like a command line program that guides users towards installing kio-admin. It will not return until this is accomplished.
 * This function will do nothing if kio-admin is already installed.
 */
void guideUserTowardsInstallingAdminWorker();

void guideUserTowardsUsingAdminWorker();

/**
 * 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