From b889a446bfe851a7f49821d469c5f3041b6e5774 Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Sat, 19 Apr 2025 14:32:25 +0200 Subject: Add Filelight menu to Tools menu The menu for installing and launching Filelight was only available through the status bar free space info button until now. By default we do no longer show the free space info button because the status bar has been changed to show less information by default. This commit adds the "Manage Disk Space Usage" menu to the "Tools" menu in the menu bar so it is more discoverable for users. --- src/statusbar/diskspaceusagemenu.h | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/statusbar/diskspaceusagemenu.h (limited to 'src/statusbar/diskspaceusagemenu.h') diff --git a/src/statusbar/diskspaceusagemenu.h b/src/statusbar/diskspaceusagemenu.h new file mode 100644 index 000000000..50984a734 --- /dev/null +++ b/src/statusbar/diskspaceusagemenu.h @@ -0,0 +1,76 @@ +/* + SPDX-FileCopyrightText: 2025 Felix Ernst + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef DISKSPACEUSAGEMENU_H +#define DISKSPACEUSAGEMENU_H + +#include + +#include +#include +#include + +class QShowEvent; +class QWidgetAction; + +/** + * A menu that allows launching tools to view disk usage statistics like Filelight and KDiskFree when those are installed. + * If none are installed, this menu instead allows installing Filelight. + */ +class DiskSpaceUsageMenu : public QMenu +{ + Q_OBJECT + +public: + explicit DiskSpaceUsageMenu(QWidget *parent); + + inline void setUrl(const QUrl &url) + { + m_url = url; + }; + +Q_SIGNALS: + /** + * Requests for @p message with the given @p messageType to be shown to the user in a non-modal way. + */ + void showMessage(const QString &message, KMessageWidget::MessageType messageType); + + /** + * Requests for a progress update to be shown to the user in a non-modal way. + * @param currentlyRunningTaskTitle The task that is currently progressing. + * @param installationProgressPercent The current percentage of completion. + */ + void showInstallationProgress(const QString ¤tlyRunningTaskTitle, int installationProgressPercent); + +private Q_SLOTS: + /** + * Asynchronously starts a Filelight installation using DolphinPackageInstaller. @see DolphinPackageInstaller. + * Installation success or failure is reported through showMessage(). @see StatusBarSpaceInfo::showMessage(). + * Installation progress is reported through showInstallationProgress(). @see StatusBarSpaceInfo::showInstallationProgress(). + */ + void slotInstallFilelightButtonClicked(); + + void updateMenu(); + +protected: + /** Moves keyboard focus to the "Install Filelight" button if the Installation UI is shown. */ + void showEvent(QShowEvent *event) override; + +private: + /** + * Creates a new QWidgetAction that contains a UI to install Filelight. + * m_installFilelightWidgetAction is initialised after calling this method once. + */ + void initialiseInstallFilelightWidgetAction(); + +private: + /** An action containing a UI to install Filelight. */ + QPointer m_installFilelightWidgetAction = nullptr; + /** The current url of the view. Filelight can be launched to show this directory. */ + QUrl m_url; +}; + +#endif // DISKSPACEUSAGEMENU_H -- cgit v1.3.1