1 /* 2 SPDX-FileCopyrightText: 2004 Esben Mose Hansen <kde@mosehansen.dk> 3 SPDX-FileCopyrightText: Andrew Stanley-Jones <asj@cban.com> 4 5 SPDX-License-Identifier: GPL-2.0-or-later 6 */ 7 #pragma once 8 9 #include <QByteArray> 10 #include <QHash> 11 #include <QObject> 12 13 class HistoryItem; 14 class HistoryModel; 15 class QAction; 16 17 class History : public QObject 18 { 19 Q_OBJECT 20 public: 21 explicit History(QObject *parent); 22 ~History() override; 23 24 /** 25 * Inserts item into clipboard history top 26 * if duplicate entry exist, the older duplicate is deleted. 27 * The duplicate concept is "deep", so that two text string 28 * are considerd duplicate if identical. 29 */ 30 void insert(QSharedPointer<HistoryItem> item); 31 32 /** 33 * Inserts item into clipboard without any checks 34 * Used when restoring a saved history and internally. 35 * Don't use this unless you're reasonable certain 36 * that no duplicates are introduced 37 */ 38 void forceInsert(QSharedPointer<HistoryItem> item); 39 40 /** 41 * Remove (first) history item equal to item from history 42 */ 43 void remove(const QSharedPointer<const HistoryItem> &item); 44 45 /** 46 * Traversal: Get first item 47 */ 48 QSharedPointer<const HistoryItem> first() const; 49 50 /** 51 * Get item identified by uuid 52 */ 53 QSharedPointer<const HistoryItem> find(const QByteArray &uuid) const; 54 55 /** 56 * @return next item in cycle, or null if at end 57 */ 58 QSharedPointer<const HistoryItem> nextInCycle() const; 59 60 /** 61 * @return previous item in cycle, or null if at top 62 */ 63 QSharedPointer<const HistoryItem> prevInCycle() const; 64 65 /** 66 * True if no history items 67 */ 68 bool empty() const; 69 70 /** 71 * Set maximum history size 72 */ 73 void setMaxSize(unsigned max_size); 74 75 /** 76 * Get the maximum history size 77 */ 78 unsigned maxSize() const; 79 80 /** 81 * returns true if the user has selected the top item 82 */ topIsUserSelected()83 bool topIsUserSelected() 84 { 85 return m_topIsUserSelected; 86 } 87 88 /** 89 * Cycle to next item 90 */ 91 void cycleNext(); 92 93 /** 94 * Cycle to prev item 95 */ 96 void cyclePrev(); 97 model()98 HistoryModel *model() 99 { 100 return m_model; 101 } 102 103 public Q_SLOTS: 104 /** 105 * move the history in position pos to top 106 */ 107 void slotMoveToTop(QAction *action); 108 109 /** 110 * move the history in position pos to top 111 */ 112 void slotMoveToTop(const QByteArray &uuid); 113 114 /** 115 * Clear history 116 */ 117 void slotClear(); 118 119 Q_SIGNALS: 120 void changed(); 121 122 /** 123 * Emitted when the first history item has changed. 124 */ 125 void topChanged(); 126 127 void topIsUserSelectedSet(); 128 129 private: 130 /** 131 * True if the top is selected by the user 132 */ 133 bool m_topIsUserSelected; 134 135 HistoryModel *m_model; 136 137 QByteArray m_cycleStartUuid; 138 }; 139