Add (and install) svg for the new krunner interface.
[kdebase/uwolfer.git] / workspace / klipper / urlgrabber.h
bloba4beefb8134b2c4476fda44330eaf146a4e49b31
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 myActions; }
56 void setActionList( ActionList * );
57 void readConfiguration( KConfig * );
58 void writeConfiguration( KConfig * );
60 int popupTimeout() const { return myPopupKillTimeout; }
61 void setPopupTimeout( int timeout ) { myPopupKillTimeout = timeout; }
63 const QStringList& avoidWindows() const { return myAvoidWindows; }
64 void setAvoidWindows( const QStringList& list ) { 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 *myActions;
76 ActionList myMatches;
77 QStringList myAvoidWindows;
78 QString myClipData;
79 ClipAction *myCurrentAction;
80 QHash<QString, ClipCommand*> myCommandMapper;
81 KMenu *myMenu;
82 QTimer *myPopupKillTimer;
83 int 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( const QString &, const QString &, bool = true, const QString & = "" );
104 QString command;
105 QString description;
106 bool isEnabled;
107 QString pixmap;
111 * Represents one configured action. An action consists of one regular
112 * expression, an (optional) description and a list of ClipCommands
113 * (a command to be executed, a description and an enabled/disabled flag).
115 class ClipAction
117 public:
118 ClipAction( const QString& regExp, const QString& description );
119 ClipAction( const ClipAction& );
120 ClipAction( KConfig *kc, const QString& );
121 ~ClipAction();
123 void setRegExp( const QString& r) { myRegExp = QRegExp( r ); }
124 QString regExp() const { return myRegExp.pattern(); }
125 inline bool matches( const QString& string ) const {
126 return ( myRegExp.indexIn( string ) != -1 );
129 void setDescription( const QString& d) { myDescription = d; }
130 const QString& description() const { return myDescription; }
133 * Removes all ClipCommands associated with this ClipAction.
135 void clearCommands() { myCommands.clear(); }
137 void addCommand( const QString& command, const QString& description, bool, const QString& icon = "" );
138 const QList<ClipCommand*>& commands() const { return myCommands; }
141 * Saves this action to a a given KConfig object
143 void save( KConfig *, const QString& ) const;
146 private:
147 QRegExp myRegExp;
148 QString myDescription;
149 QList<ClipCommand*> myCommands;
154 #endif // URLGRABBER_H