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 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
; }
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
;
79 ClipAction
*m_myCurrentAction
;
80 QHash
<QString
, ClipCommand
*> m_myCommandMapper
;
82 QTimer
*m_myPopupKillTimer
;
83 int m_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( ClipAction
*, const QString
&, const QString
&, bool = true, const QString
& = QString() );
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).
119 ClipAction( const QString
& regExp
, const QString
& description
);
120 ClipAction( const ClipAction
& );
121 ClipAction( KConfig
*kc
, const QString
& );
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;
150 QString m_myDescription
;
151 QList
<ClipCommand
*> m_myCommands
;
156 #endif // URLGRABBER_H