File indexing completed on 2024-04-28 05:50:45
0001 /* 0002 SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef PROFILELIST_H 0008 #define PROFILELIST_H 0009 0010 // Qt 0011 #include <QAction> 0012 #include <QList> 0013 #include <QObject> 0014 #include <QSet> 0015 0016 // Konsole 0017 #include "Profile.h" 0018 0019 class QActionGroup; 0020 class QKeySequence; 0021 0022 namespace Konsole 0023 { 0024 /** 0025 * ProfileList provides a list of actions which represent session profiles 0026 * that a SessionManager can create a session from. 0027 * 0028 * These actions can be plugged into a GUI. 0029 * 0030 * Currently only profiles marked as favorites in the SessionManager are included. 0031 * 0032 * The user-data associated with each session can be passed to the createProfile() method of the 0033 * SessionManager to create a new terminal session. 0034 */ 0035 class KONSOLEPRIVATE_EXPORT ProfileList : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 /** 0041 * Constructs a new profile list which displays profiles 0042 * that can be used to create session 0043 * 0044 * @param addShortcuts True if the shortcuts associated with profiles 0045 * in the session manager should be added to the actions 0046 * @param parent The parent GUI object 0047 */ 0048 ProfileList(bool addShortcuts, QObject *parent); 0049 0050 /** 0051 * Returns a list of actions representing profiles, sorted by profile 0052 * name. 0053 * 0054 * The user-data associated with each action is the corresponding profile. 0055 */ 0056 QList<QAction *> actions(); 0057 0058 /** TODO: Document me */ 0059 void syncWidgetActions(QWidget *widget, bool sync); 0060 Q_SIGNALS: 0061 /** 0062 * Emitted when the user selects an action from the list. 0063 * 0064 * @param profile The profile to select 0065 */ 0066 void profileSelected(const Profile::Ptr &profile); 0067 /** 0068 * Emitted when the list of actions changes. 0069 */ 0070 void actionsChanged(const QList<QAction *> &actions); 0071 0072 private Q_SLOTS: 0073 void triggered(QAction *action); 0074 void profileChanged(const Profile::Ptr &profile); 0075 void shortcutChanged(const Profile::Ptr &profile, const QKeySequence &sequence); 0076 void addShortcutAction(const Profile::Ptr &profile); 0077 void removeShortcutAction(const Profile::Ptr &profile); 0078 0079 private: 0080 Q_DISABLE_COPY(ProfileList) 0081 0082 QAction *actionForProfile(const Profile::Ptr &profile) const; 0083 void updateAction(QAction *action, Profile::Ptr profile); 0084 void updateEmptyAction(); 0085 0086 QActionGroup *_group; 0087 bool _addShortcuts; 0088 0089 // action to show when the list is empty 0090 QAction *_emptyListAction; 0091 QSet<QWidget *> _registeredWidgets; 0092 }; 0093 } 0094 0095 #endif // PROFILELIST_H