~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to klipper/history.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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.
 
20
*/
 
21
#ifndef HISTORY_H
 
22
#define HISTORY_H
 
23
 
 
24
#include <QAction>
 
25
#include <QList>
 
26
 
 
27
#include "historyitem.h"
 
28
 
 
29
class KlipperPopup;
 
30
 
 
31
class History : public QObject
 
32
{
 
33
    Q_OBJECT
 
34
public:
 
35
    History( QObject* parent );
 
36
    ~History();
 
37
 
 
38
    /**
 
39
     * Return (toplevel) popup menu (or default view, of you like)
 
40
     */
 
41
    KlipperPopup* popup();
 
42
 
 
43
    /**
 
44
     * Inserts item into clipboard history top
 
45
     * if duplicate entry exist, the older duplicate is deleted.
 
46
     * The duplicate concept is "deep", so that two text string
 
47
     * are considerd duplicate if identical.
 
48
     */
 
49
    void insert( HistoryItem* item );
 
50
 
 
51
    /**
 
52
     * Inserts item into clipboard without any checks
 
53
     * Used when restoring a saved history and internally.
 
54
     * Don't use this unless you're reasonable certain
 
55
     * that no duplicates are introduced
 
56
     */
 
57
    void forceInsert( HistoryItem* item );
 
58
 
 
59
    /**
 
60
     * Remove (first) history item equal to item from history
 
61
     */
 
62
    void remove( const HistoryItem* item  );
 
63
 
 
64
    /**
 
65
     * Traversal: Get first item
 
66
     */
 
67
    const HistoryItem* first() const;
 
68
 
 
69
    /**
 
70
     * Get item identified by uuid
 
71
     */
 
72
    const HistoryItem* find(const QByteArray& uuid) const;
 
73
 
 
74
    /**
 
75
     * @return next item in cycle, or null if at end
 
76
     */
 
77
    const HistoryItem* nextInCycle() const;
 
78
 
 
79
    /**
 
80
     * @return previous item in cycle, or null if at top
 
81
     */
 
82
    const HistoryItem* prevInCycle() const;
 
83
 
 
84
    /**
 
85
     * True if no history items
 
86
     */
 
87
    bool empty() const { return m_items.isEmpty(); }
 
88
 
 
89
    /**
 
90
     * Set maximum history size
 
91
     */
 
92
    void setMaxSize( unsigned max_size );
 
93
 
 
94
    /**
 
95
     * Get the maximum history size
 
96
     */
 
97
    unsigned maxSize() const { return m_max_size; }
 
98
 
 
99
    /**
 
100
     * returns true if the user has selected the top item
 
101
     */
 
102
    bool topIsUserSelected() {
 
103
        return m_topIsUserSelected;
 
104
    }
 
105
 
 
106
    /**
 
107
     * Cycle to next item
 
108
     */
 
109
    void cycleNext();
 
110
 
 
111
    /**
 
112
     * Cycle to prev item
 
113
     */
 
114
    void cyclePrev();
 
115
 
 
116
public Q_SLOTS:
 
117
    /**
 
118
     * move the history in position pos to top
 
119
     */
 
120
    void slotMoveToTop(QAction *action);
 
121
 
 
122
    /**
 
123
     * move the history in position pos to top
 
124
     */
 
125
    void slotMoveToTop(const QByteArray& uuid);
 
126
 
 
127
    /**
 
128
     * Clear history
 
129
     */
 
130
    void slotClear();
 
131
 
 
132
Q_SIGNALS:
 
133
    void changed();
 
134
 
 
135
    /**
 
136
     * Emitted when the first history item has changed.
 
137
     */
 
138
    void topChanged();
 
139
 
 
140
private:
 
141
    /**
 
142
     * ensure that the number of items does not exceed max_size()
 
143
     * Deletes items from the end as necessary.
 
144
     */
 
145
    void trim();
 
146
 
 
147
private:
 
148
    typedef QHash<QByteArray, HistoryItem*> items_t;
 
149
    /**
 
150
     * The history
 
151
     */
 
152
    items_t m_items;
 
153
 
 
154
    /**
 
155
     * First item
 
156
     */
 
157
    HistoryItem* m_top;
 
158
 
 
159
    /**
 
160
     * "Default view" --- a popupmenu containing the clipboard history.
 
161
     */
 
162
    KlipperPopup* m_popup;
 
163
 
 
164
 
 
165
    /**
 
166
     * The number of clipboard items stored.
 
167
     */
 
168
    unsigned m_max_size;
 
169
 
 
170
    /**
 
171
     * True if the top is selected by the user
 
172
     */
 
173
    bool m_topIsUserSelected;
 
174
 
 
175
    /**
 
176
     * The "next" when cycling through the
 
177
     * history. May be 0, if history is empty
 
178
     */
 
179
    HistoryItem* m_nextCycle;
 
180
};
 
181
 
 
182
inline const HistoryItem* History::first() const { return m_top; }
 
183
 
 
184
#endif