]> cloud.milkyroute.net Git - dolphin.git/blob - src/admin/bar.h
Add a SetFolderIcon ItemAction plugin
[dolphin.git] / src / admin / bar.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2024 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 ADMINBAR_H
9 #define ADMINBAR_H
10
11 #include "animatedheightwidget.h"
12
13 class DolphinViewContainer;
14 class QLabel;
15 class QPushButton;
16 class QResizeEvent;
17 class QToolButton;
18
19 namespace Admin
20 {
21
22 /**
23 * @brief A bar appearing above the view while the user is acting with administrative privileges.
24 *
25 * It contains a warning and allows revoking this administrative mode by closing this bar.
26 */
27 class Bar : public AnimatedHeightWidget
28 {
29 Q_OBJECT
30
31 public:
32 explicit Bar(DolphinViewContainer *parentViewContainer);
33
34 /** Used to recolor this bar when this application's color scheme changes. */
35 bool event(QEvent *event) override;
36
37 protected:
38 /** Calls updateLabelString() */
39 void resizeEvent(QResizeEvent *resizeEvent) override;
40
41 private:
42 /**
43 * Makes sure this admin bar hides itself when the elevated privileges expire so the user doesn't mistakenly assume that they are still acting with
44 * administrative rights. The view container is also changed to a non-admin url, so no password prompts will pop up unexpectedly.
45 * Then this method shows a message to the user to explain this.
46 * The mechanism of this method only fires once and will need to be called again the next time the user regains administrative rights for this view.
47 */
48 void hideTheNextTimeAuthorizationExpires();
49
50 /** Recolors this bar based on the current color scheme. */
51 void updateColors();
52
53 /** Decides whether the m_fullLabelString or m_shortLabelString should be used based on available width. */
54 void updateLabelString();
55
56 /** @see AnimatedHeightWidget::preferredHeight() */
57 inline int preferredHeight() const override
58 {
59 return m_preferredHeight;
60 };
61
62 private:
63 /** The text on this bar */
64 QLabel *m_label = nullptr;
65 /** Shows a warning about the dangers of acting with administrative privileges. */
66 QToolButton *m_warningButton = nullptr;
67 /** Closes this bar and exits the administrative mode. */
68 QPushButton *m_closeButton = nullptr;
69
70 /** @see updateLabelString() */
71 QString m_fullLabelString;
72 /** @see updateLabelString() */
73 QString m_shortLabelString;
74
75 /** @see preferredHeight() */
76 int m_preferredHeight;
77
78 /**
79 * A proxy action for the real actAsAdminAction.
80 * This proxy action can be used to reenable admin mode for the view belonging to this bar object specifically.
81 */
82 QAction *m_reenableActAsAdminAction = nullptr;
83
84 /**
85 * The parent of this bar. The bar acts on the DolphinViewContainer to exit the admin mode. This can happen in two ways:
86 * 1. The user closes the bar which implies exiting of the admin mode.
87 * 2. The admin authorization expires so all views can factually no longer be in admin mode.
88 */
89 DolphinViewContainer *m_parentViewContainer;
90 };
91
92 }
93
94 #endif // ADMINBAR_H