not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / klipper / klipper.h
blobf04af391ee535f677d71d73bd05c21b599a4cbc8
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) by Andrew Stanley-Jones
4 Copyright (C) 2004 Esben Mose Hansen <kde@mosehansen.dk>
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.
21 #ifndef KLIPPER_H
22 #define KLIPPER_H
24 #include <QKeyEvent>
25 #include <QMenu>
26 #include <QTimer>
28 #include <KApplication>
29 #include <KIcon>
31 class QClipboard;
32 class KToggleAction;
33 class KAboutData;
34 class KActionCollection;
35 class URLGrabber;
36 class ClipboardPoll;
37 class QTime;
38 class History;
39 class QAction;
40 class QMimeData;
41 class HistoryItem;
42 class KlipperSessionManager;
44 class Klipper : public QObject
46 Q_OBJECT
47 Q_CLASSINFO("D-Bus Interface", "org.kde.klipper.klipper")
49 public Q_SLOTS:
50 Q_SCRIPTABLE QString getClipboardContents();
51 Q_SCRIPTABLE void setClipboardContents(QString s);
52 Q_SCRIPTABLE void clearClipboardContents();
53 Q_SCRIPTABLE void clearClipboardHistory();
54 Q_SCRIPTABLE QStringList getClipboardHistoryMenu();
55 Q_SCRIPTABLE QString getClipboardHistoryItem(int i);
56 Q_SCRIPTABLE void showKlipperPopupMenu();
57 Q_SCRIPTABLE void showKlipperManuallyInvokeActionMenu();
59 public:
60 Klipper(QObject *parent, const KSharedConfigPtr &config);
61 ~Klipper();
63 /**
64 * Get clipboard history (the "document")
66 History* history() { return m_history; }
68 static void updateTimestamp();
69 static void createAboutData();
70 static void destroyAboutData();
71 static KAboutData* aboutData();
73 public Q_SLOTS:
74 void saveSession();
75 void slotSettingsChanged( int category );
76 void slotHistoryTopChanged();
77 void slotConfigure();
79 protected:
80 /**
81 * The selection modes
83 * Don't use 1, as I use that as a guard against passing
84 * a boolean true as a mode.
86 enum SelectionMode { Clipboard = 2, Selection = 4 };
88 void readProperties(KConfig *);
89 void readConfiguration(KConfig *);
91 /**
92 * Loads history from disk.
94 bool loadHistory();
96 /**
97 * Save history to disk
99 void saveHistory();
101 void writeConfiguration(KConfig *);
103 * @returns the contents of the selection or, if empty, the contents of
104 * the clipboard.
106 QString clipboardContents( bool *isSelection = 0L );
108 void removeFromHistory( const QString& text );
109 void setEmptyClipboard();
111 void clipboardSignalArrived( bool selectionMode );
114 * Check data in clipboard, and if it passes these checks,
115 * store the data in the clipboard history.
117 void checkClipData( bool selectionMode );
120 * Enter clipboard data in the history.
122 void applyClipChanges( const QMimeData* data );
124 void setClipboard( const HistoryItem& item, int mode );
125 bool ignoreClipboardChanges() const;
127 KSharedConfigPtr config() const { return m_config; }
128 bool isApplet() const { return m_config != KGlobal::config(); }
130 public Q_SLOTS:
131 void slotPopupMenu();
133 protected Q_SLOTS:
134 void showPopupMenu( QMenu * );
135 void slotRepeatAction();
136 void setURLGrabberEnabled( bool );
137 void toggleURLGrabber();
138 void disableURLGrabber();
140 private Q_SLOTS:
141 void newClipData( bool selectionMode );
142 void slotClearClipboard();
144 void slotSelectionChanged() {
145 clipboardSignalArrived( true );
147 void slotClipboardChanged() {
148 clipboardSignalArrived( false );
151 void slotQuit();
152 void slotStartHideTimer();
153 void slotStartShowTimer();
155 void slotClearOverflow();
156 void slotCheckPending();
158 private:
160 QClipboard *m_clip;
162 QTime *m_hideTimer;
163 QTime *m_showTimer;
165 int m_lastClipboard;
166 int m_lastSelection;
167 History* m_history;
168 int m_overflowCounter;
169 KToggleAction *m_toggleURLGrabAction;
170 QAction* m_clearHistoryAction;
171 QAction* m_configureAction;
172 QAction* m_quitAction;
173 QPixmap m_pixmap;
174 bool m_bPopupAtMouse :1;
175 bool m_bKeepContents :1;
176 bool m_bURLGrabber :1;
177 bool m_bReplayActionInHistory :1;
178 bool m_bUseGUIRegExpEditor :1;
179 bool m_bNoNullClipboard :1;
180 bool m_bTearOffHandle :1;
181 bool m_bIgnoreSelection :1;
182 bool m_bSynchronize :1;
183 bool m_bSelectionTextOnly :1;
184 bool m_bIgnoreImages :1;
187 * Avoid reacting to our own changes, using this
188 * lock.
189 * Don't manupulate this object directly... use the Ignore struct
190 * instead
192 int m_locklevel;
194 URLGrabber *m_myURLGrabber;
195 QString m_lastURLGrabberTextSelection;
196 QString m_lastURLGrabberTextClipboard;
197 KSharedConfigPtr m_config;
198 QTimer m_overflowClearTimer;
199 QTimer m_pendingCheckTimer;
200 bool m_pendingContentsCheck;
201 ClipboardPoll* m_poll;
202 static KAboutData* m_about_data;
204 bool blockFetchingNewData();
205 KlipperSessionManager* m_session_managed;
206 KActionCollection *m_collection;
209 #endif