1 // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*-
2 /* This file is part of the KDE project
3 Copyright (C) 2004 Esben Mose Hansen <kde@mosehansen.dk>
4 Copyright (C) Andrew Stanley-Jones
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
27 #include "historyitem.h"
31 class History
: public QObject
35 History( QObject
* parent
);
38 * Iterator for history
40 typedef QListIterator
<const HistoryItem
*> iterator
;
43 * Return (toplevel) popup menu (or default view, of you like)
45 KlipperPopup
* popup();
48 * Inserts item into clipboard history top
49 * if duplicate entry exist, the older duplicate is deleted.
50 * The duplicate concept is "deep", so that two text string
51 * are considerd duplicate if identical.
53 void insert( const HistoryItem
* item
);
56 * Inserts item into clipboard without any checks
57 * Used when restoring a saved history and internally.
58 * Don't use this unless you're reasonable certain
59 * that no duplicates are introduced
61 void forceInsert( const HistoryItem
* item
);
64 * Remove (first) history item equal to item from history
66 void remove( const HistoryItem
* item
);
69 * Traversal: Get first item
71 const HistoryItem
* first();
74 * Get an iterator pointing to the first (most recent) item
75 * This iterator should probably be a constant iterator, but
76 * the QTL doesn't support this easily.
78 * Anyway, if you modify the items via. the iterator, call changed()
79 * when you're done. Calling changed() multiple times doesn't hurt.
81 * iterator could be made into a proxy class that did the right thing.
86 * True if no history items
88 bool empty() const { return itemList
.isEmpty(); }
91 * Set maximum history size
93 void max_size( unsigned max_size
);
96 * Get the maximum history size
98 unsigned max_size() const { return m_max_size
; }
101 * returns true if the user has selected the top item
103 bool topIsUserSelected() {
104 return m_topIsUserSelected
;
109 * move the history in position pos to top
111 void slotMoveToTop(QAction
*action
);
122 * Emitted when the first history item has changed.
131 QList
<const HistoryItem
*> itemList
;
134 * ensure that the number of items does not exceed max_size()
135 * Deletes items from the end as necessary.
141 * "Default view" --- a popupmenu containing the clipboard history.
143 KlipperPopup
* m_popup
;
147 * The number of clipboard items stored.
152 * True if the top is selected by the user
154 bool m_topIsUserSelected
;
158 inline const HistoryItem
* History::first() { return itemList
.count() > 0 ? itemList
.first() : 0; }