not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / klipper / urlgrabber.h
blob57f00cef6c83b928accdab077e574a65a7b4fce1
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) 2000 by Carsten Pfeiffer <pfeiffer@kde.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
20 #ifndef URLGRABBER_H
21 #define URLGRABBER_H
23 #include <QHash>
24 #include <QRegExp>
26 #include <kconfig.h>
28 class QTimer;
30 class KConfig;
31 class KMenu;
33 class ClipAction;
34 struct ClipCommand;
35 typedef QList<ClipAction*> ActionList;
36 typedef QListIterator<ClipAction*> ActionListIterator;
38 class URLGrabber : public QObject
40 Q_OBJECT
42 public:
43 URLGrabber(const KSharedConfigPtr &config);
44 ~URLGrabber();
46 /**
47 * Checks a given string whether it matches any of the user-defined criteria.
48 * If it does, the configured action will be executed.
49 * @returns false if the string should be put into the popupmenu or not,
50 * otherwise true.
52 bool checkNewData( const QString& clipData );
53 void invokeAction( const QString& clip = QString() );
55 const ActionList * actionList() const { return m_myActions; }
56 void setActionList( ActionList * );
57 void readConfiguration( KConfig * );
58 void writeConfiguration( KConfig * );
60 int popupTimeout() const { return m_myPopupKillTimeout; }
61 void setPopupTimeout( int timeout ) { m_myPopupKillTimeout = timeout; }
63 const QStringList& avoidWindows() const { return m_myAvoidWindows; }
64 void setAvoidWindows( const QStringList& list ) { m_myAvoidWindows = list; }
66 bool trimmed() const { return m_trimmed; }
67 void setStripWhiteSpace( bool enable ) { m_trimmed = enable; }
69 private:
70 const ActionList& matchingActions( const QString& );
71 void execute( const struct ClipCommand *command ) const;
72 bool isAvoidedWindow() const;
73 void actionMenu( bool wm_class_check );
75 ActionList *m_myActions;
76 ActionList m_myMatches;
77 QStringList m_myAvoidWindows;
78 QString m_myClipData;
79 ClipAction *m_myCurrentAction;
80 QHash<QString, ClipCommand*> m_myCommandMapper;
81 KMenu *m_myMenu;
82 QTimer *m_myPopupKillTimer;
83 int m_myPopupKillTimeout;
84 bool m_trimmed;
85 KSharedConfigPtr m_config;
87 private Q_SLOTS:
88 void slotActionMenu() { actionMenu( true ); }
89 void slotItemSelected(QAction *action);
90 void slotKillPopupMenu();
91 void editData();
94 Q_SIGNALS:
95 void sigPopup( QMenu * );
96 void sigDisablePopup();
101 struct ClipCommand
103 ClipCommand( ClipAction *, const QString &, const QString &, bool = true, const QString & = QString() );
104 ClipAction *parent;
105 QString command;
106 QString description;
107 bool isEnabled;
108 QString pixmap;
112 * Represents one configured action. An action consists of one regular
113 * expression, an (optional) description and a list of ClipCommands
114 * (a command to be executed, a description and an enabled/disabled flag).
116 class ClipAction
118 public:
119 ClipAction( const QString& regExp, const QString& description );
120 ClipAction( const ClipAction& );
121 ClipAction( KConfig *kc, const QString& );
122 ~ClipAction();
124 void setRegExp( const QString& r) { m_myRegExp = QRegExp( r ); }
125 QString regExp() const { return m_myRegExp.pattern(); }
126 inline bool matches( const QString& string ) const {
127 return ( m_myRegExp.indexIn( string ) != -1 );
129 QStringList regExpMatches() { return m_myRegExp.capturedTexts(); }
131 void setDescription( const QString& d) { m_myDescription = d; }
132 const QString& description() const { return m_myDescription; }
135 * Removes all ClipCommands associated with this ClipAction.
137 void clearCommands() { m_myCommands.clear(); }
139 void addCommand( const QString& command, const QString& description, bool, const QString& icon = QString() );
140 const QList<ClipCommand*>& commands() const { return m_myCommands; }
143 * Saves this action to a a given KConfig object
145 void save( KConfig *, const QString& ) const;
148 private:
149 QRegExp m_myRegExp;
150 QString m_myDescription;
151 QList<ClipCommand*> m_myCommands;
156 #endif // URLGRABBER_H