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.
35 typedef QList
<ClipAction
*> ActionList
;
36 typedef QListIterator
<ClipAction
*> ActionListIterator
;
38 class URLGrabber
: public QObject
43 URLGrabber(const KSharedConfigPtr
&config
);
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,
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
; }
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
;
77 QStringList myAvoidWindows
;
79 ClipAction
*myCurrentAction
;
80 QHash
<QString
, ClipCommand
*> myCommandMapper
;
82 QTimer
*myPopupKillTimer
;
83 int myPopupKillTimeout
;
85 KSharedConfigPtr m_config
;
88 void slotActionMenu() { actionMenu( true ); }
89 void slotItemSelected(QAction
*action
);
90 void slotKillPopupMenu();
95 void sigPopup( QMenu
* );
96 void sigDisablePopup();
103 ClipCommand( const QString
&, const QString
&, bool = true, const QString
& = "" );
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).
118 ClipAction( const QString
& regExp
, const QString
& description
);
119 ClipAction( const ClipAction
& );
120 ClipAction( KConfig
*kc
, const QString
& );
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;
148 QString myDescription
;
149 QList
<ClipCommand
*> myCommands
;
154 #endif // URLGRABBER_H