File indexing completed on 2024-05-12 05:20:37
0001 /* SPDX-FileCopyrightText: 2010 Thomas McGuire <mcguire@kde.org> 0002 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 #pragma once 0006 0007 #include "kmail_export.h" 0008 0009 #include <Akonadi/Collection> 0010 0011 #include <QHash> 0012 #include <QModelIndex> 0013 #include <QObject> 0014 0015 class QAction; 0016 0017 class KActionCollection; 0018 0019 namespace KMail 0020 { 0021 class FolderShortcutCommand : public QObject 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 explicit FolderShortcutCommand(QWidget *mainwidget, const Akonadi::Collection &col); 0027 ~FolderShortcutCommand() override; 0028 0029 public Q_SLOTS: 0030 void start(); 0031 /** Assign a QAction to the command which is used to trigger it. This 0032 * action will be deleted along with the command, so you don't need to 0033 * keep track of it separately. */ 0034 void setAction(QAction *); 0035 0036 Q_SIGNALS: 0037 void selectCollectionFolder(const Akonadi::Collection &col); 0038 0039 private: 0040 const Akonadi::Collection mCollectionFolder; 0041 QWidget *const mMainWidget; 0042 QAction *mAction = nullptr; 0043 }; 0044 0045 class KMAIL_EXPORT FolderShortcutActionManager : public QObject 0046 { 0047 Q_OBJECT 0048 0049 public: 0050 explicit FolderShortcutActionManager(QWidget *parent, KActionCollection *actionCollection); 0051 void createActions(); 0052 0053 public Q_SLOTS: 0054 0055 /** 0056 * Updates the shortcut action for this collection. Call this when a shortcut was 0057 * added, removed or changed. 0058 */ 0059 void shortcutChanged(const Akonadi::Collection &collection); 0060 0061 private: 0062 /** 0063 * Removes the shortcut actions associated with a folder. 0064 */ 0065 void slotCollectionRemoved(const Akonadi::Collection &collection); 0066 0067 void slotRowsInserted(const QModelIndex &parent, int start, int end); 0068 0069 private: 0070 void updateShortcutsForIndex(const QModelIndex &parent, int start, int end); 0071 QHash<Akonadi::Collection::Id, FolderShortcutCommand *> mFolderShortcutCommands; 0072 KActionCollection *mActionCollection = nullptr; 0073 QWidget *mParent = nullptr; 0074 }; 0075 }