File indexing completed on 2024-04-28 16:54:24
0001 /* 0002 SPDX-FileCopyrightText: 2004 Esben Mose Hansen <kde@mosehansen.dk> 0003 SPDX-FileCopyrightText: Andrew Stanley-Jones <asj@cban.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #pragma once 0008 0009 #include <QByteArray> 0010 #include <QHash> 0011 #include <QObject> 0012 0013 class HistoryItem; 0014 class HistoryModel; 0015 class QAction; 0016 0017 class History : public QObject 0018 { 0019 Q_OBJECT 0020 public: 0021 explicit History(QObject *parent); 0022 ~History() override; 0023 0024 /** 0025 * Inserts item into clipboard history top 0026 * if duplicate entry exist, the older duplicate is deleted. 0027 * The duplicate concept is "deep", so that two text string 0028 * are considerd duplicate if identical. 0029 */ 0030 void insert(QSharedPointer<HistoryItem> item); 0031 0032 /** 0033 * Inserts items into clipboard without any checks 0034 * Used when restoring a saved history and internally. 0035 * Don't use this unless you're reasonable the list 0036 * should be reset. 0037 */ 0038 void clearAndBatchInsert(const QVector<QSharedPointer<HistoryItem>> &items); 0039 0040 /** 0041 * Remove (first) history item equal to item from history 0042 */ 0043 void remove(const QSharedPointer<const HistoryItem> &item); 0044 0045 /** 0046 * Traversal: Get first item 0047 */ 0048 QSharedPointer<const HistoryItem> first() const; 0049 0050 /** 0051 * Get item identified by uuid 0052 */ 0053 QSharedPointer<const HistoryItem> find(const QByteArray &uuid) const; 0054 0055 /** 0056 * @return next item in cycle, or null if at end 0057 */ 0058 QSharedPointer<const HistoryItem> nextInCycle() const; 0059 0060 /** 0061 * @return previous item in cycle, or null if at top 0062 */ 0063 QSharedPointer<const HistoryItem> prevInCycle() const; 0064 0065 /** 0066 * True if no history items 0067 */ 0068 bool empty() const; 0069 0070 /** 0071 * Set maximum history size 0072 */ 0073 void setMaxSize(unsigned max_size); 0074 0075 /** 0076 * Get the maximum history size 0077 */ 0078 unsigned maxSize() const; 0079 0080 /** 0081 * returns true if the user has selected the top item 0082 */ 0083 bool topIsUserSelected() 0084 { 0085 return m_topIsUserSelected; 0086 } 0087 0088 /** 0089 * Cycle to next item 0090 */ 0091 void cycleNext(); 0092 0093 /** 0094 * Cycle to prev item 0095 */ 0096 void cyclePrev(); 0097 0098 HistoryModel *model() 0099 { 0100 return m_model; 0101 } 0102 0103 public Q_SLOTS: 0104 /** 0105 * move the history in position pos to top 0106 */ 0107 void slotMoveToTop(QAction *action); 0108 0109 /** 0110 * move the history in position pos to top 0111 */ 0112 void slotMoveToTop(const QByteArray &uuid); 0113 0114 /** 0115 * Clear history 0116 */ 0117 void slotClear(); 0118 0119 Q_SIGNALS: 0120 void changed(); 0121 0122 /** 0123 * Emitted when the first history item has changed. 0124 */ 0125 void topChanged(); 0126 0127 void topIsUserSelectedSet(); 0128 0129 private: 0130 /** 0131 * True if the top is selected by the user 0132 */ 0133 bool m_topIsUserSelected; 0134 0135 HistoryModel *m_model; 0136 0137 QByteArray m_cycleStartUuid; 0138 };