diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 4aed2c8219774f5d797760606b8489a92ddc5163 (patch) | |
tree | 3f8c130f7d269626bf6a9447407ef6c35954426a /klipper/urlgrabber.h | |
download | tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'klipper/urlgrabber.h')
-rw-r--r-- | klipper/urlgrabber.h | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/klipper/urlgrabber.h b/klipper/urlgrabber.h new file mode 100644 index 000000000..ae39d648d --- /dev/null +++ b/klipper/urlgrabber.h @@ -0,0 +1,159 @@ +// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- +/* This file is part of the KDE project + Copyright (C) 2000 by Carsten Pfeiffer <[email protected]> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef URLGRABBER_H +#define URLGRABBER_H + +#include <qptrlist.h> +#include <qintdict.h> +#include <qregexp.h> +#include <qstring.h> +#include <qstringlist.h> + +#include <kprocess.h> + + +class QTimer; + +class KConfig; +class KPopupMenu; + +class ClipAction; +struct ClipCommand; +typedef QPtrList<ClipAction> ActionList; +typedef QPtrListIterator<ClipAction> ActionListIterator; + +class URLGrabber : public QObject +{ + Q_OBJECT + +public: + URLGrabber( KConfig* config ); + ~URLGrabber(); + + /** + * Checks a given string whether it matches any of the user-defined criteria. + * If it does, the configured action will be executed. + * @returns false if the string should be put into the popupmenu or not, + * otherwise true. + */ + bool checkNewData( const QString& clipData ); + void invokeAction( const QString& clip = QString::null ); + + const ActionList * actionList() const { return myActions; } + void setActionList( ActionList * ); + void readConfiguration( KConfig * ); + void writeConfiguration( KConfig * ); + + int popupTimeout() const { return myPopupKillTimeout; } + void setPopupTimeout( int timeout ) { myPopupKillTimeout = timeout; } + + const QStringList& avoidWindows() const { return myAvoidWindows; } + void setAvoidWindows( const QStringList& list ) { myAvoidWindows = list; } + + bool stripWhiteSpace() const { return m_stripWhiteSpace; } + void setStripWhiteSpace( bool enable ) { m_stripWhiteSpace = enable; } + +private: + const ActionList& matchingActions( const QString& ); + void execute( const struct ClipCommand *command ) const; + void editData(); + bool isAvoidedWindow() const; + void actionMenu( bool wm_class_check ); + + ActionList *myActions; + ActionList myMatches; + QStringList myAvoidWindows; + QString myClipData; + ClipAction *myCurrentAction; + QIntDict<ClipCommand> myCommandMapper; + KPopupMenu *myMenu; + QTimer *myPopupKillTimer; + int myPopupKillTimeout; + bool m_stripWhiteSpace; + KConfig* m_config; + +private slots: + void slotActionMenu() { actionMenu( true ); } + void slotItemSelected( int ); + void slotKillPopupMenu(); + + +signals: + void sigPopup( QPopupMenu * ); + void sigDisablePopup(); + +}; + + +struct ClipCommand +{ + ClipCommand( const QString &, const QString &, bool = true, const QString & = "" ); + QString command; + QString description; + bool isEnabled; + QString pixmap; + // int id; // the index reflecting the position in the list of commands +}; + +/** + * Represents one configured action. An action consists of one regular + * expression, an (optional) description and a list of ClipCommands + * (a command to be executed, a description and an enabled/disabled flag). + */ +class ClipAction +{ +public: + ClipAction( const QString& regExp, const QString& description ); + ClipAction( const ClipAction& ); + ClipAction( KConfig *kc ); + ~ClipAction(); + + void setRegExp( const QString& r) { myRegExp = QRegExp( r ); } + QString regExp() const { return myRegExp.pattern(); } + inline bool matches( const QString& string ) const { + return ( myRegExp.search( string ) != -1 ); + } + + void setDescription( const QString& d) { myDescription = d; } + const QString& description() const { return myDescription; } + + /** + * Removes all ClipCommands associated with this ClipAction. + */ + void clearCommands() { myCommands.clear(); } + + void addCommand( const QString& command, const QString& description, bool, const QString& icon = "" ); + const QPtrList<ClipCommand>& commands() const { return myCommands; } + + /** + * Saves this action to a a given KConfig object + */ + void save( KConfig * ) const; + + +private: + QRegExp myRegExp; + QString myDescription; + QPtrList<ClipCommand> myCommands; + +}; + + +#endif // URLGRABBER_H |