diff options
Diffstat (limited to 'extra/kde301')
-rw-r--r-- | extra/kde301/kaccelaction.h | 202 | ||||
-rw-r--r-- | extra/kde301/kaccelbase.h | 233 | ||||
-rw-r--r-- | extra/kde301/kicontheme.h | 217 | ||||
-rw-r--r-- | extra/kde301/kkeyserver_x11.h | 131 | ||||
-rw-r--r-- | extra/kde301/konsole_part.h | 223 | ||||
-rw-r--r-- | extra/kde301/krecentdirs.h | 68 | ||||
-rw-r--r-- | extra/kde301/ksycocafactory.h | 135 | ||||
-rw-r--r-- | extra/kde301/ktoolbarbutton.h | 313 | ||||
-rw-r--r-- | extra/kde301/kurifilter.h | 593 |
9 files changed, 2115 insertions, 0 deletions
diff --git a/extra/kde301/kaccelaction.h b/extra/kde301/kaccelaction.h new file mode 100644 index 0000000..139d7f7 --- /dev/null +++ b/extra/kde301/kaccelaction.h @@ -0,0 +1,202 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _KACCELACTION_H +#define _KACCELACTION_H + +#include <qmap.h> +#include <qptrvector.h> +#include <qstring.h> +#include <qvaluevector.h> + +#include <kshortcut.h> + +class KAccelBase; + +class QObject; +class KConfig; +class KConfigBase; + +/* + KAccelAction holds information an a given action, such as "Execute Command" + + 1) KAccelAction = "Execute Command" + Default3 = "Alt+F2" + Default4 = "Meta+Enter;Alt+F2" + 1) KShortcut = "Meta+Enter" + 1) KKeySequence = "Meta+Enter" + 1) KKey = "Meta+Enter" + 1) Meta+Enter + 2) Meta+Keypad_Enter + 2) KShortcut = "Alt+F2" + 1) KKeySequence = "Alt+F2" + 1) Alt+F2 + 2) KAccelAction = "Something" + Default3 = "" + Default4 = "" + 1) KShortcut = "Meta+X,Asterisk" + 1) KKeySequence = "Meta+X,Asterisk" + 1) KKey = "Meta+X" + 1) Meta+X + 2) KKey = "Asterisk" + 1) Shift+8 (English layout) + 2) Keypad_Asterisk +*/ + +//--------------------------------------------------------------------- +// KAccelAction +//--------------------------------------------------------------------- + +class KAccelAction +{ + public: + KAccelAction(); + KAccelAction( const KAccelAction& ); + KAccelAction( const QString& sName, const QString& sLabel, const QString& sWhatsThis, + const KShortcut& cutDef3, const KShortcut& cutDef4, + const QObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ); + ~KAccelAction(); + + void clear(); + bool init( const QString& sName, const QString& sLabel, const QString& sWhatsThis, + const KShortcut& cutDef3, const KShortcut& cutDef4, + const QObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ); + + KAccelAction& operator=( const KAccelAction& ); + + const QString& name() const { return m_sName; } + const QString& label() const { return m_sLabel; } + const QString& whatsThis() const { return m_sWhatsThis; } + const KShortcut& shortcut() const { return m_cut; } + const KShortcut& shortcutDefault() const; + const KShortcut& shortcutDefault3() const { return m_cutDefault3; } + const KShortcut& shortcutDefault4() const { return m_cutDefault4; } + const QObject* objSlotPtr() const { return m_pObjSlot; } + const char* methodSlotPtr() const { return m_psMethodSlot; } + bool isConfigurable() const { return m_bConfigurable; } + bool isEnabled() const { return m_bEnabled; } + + void setName( const QString& ); + void setLabel( const QString& ); + void setWhatsThis( const QString& ); + bool setShortcut( const KShortcut& rgCuts ); + void setSlot( const QObject* pObjSlot, const char* psMethodSlot ); + void setConfigurable( bool ); + void setEnabled( bool ); + + int getID() const { return m_nIDAccel; } + void setID( int n ) { m_nIDAccel = n; } + bool isConnected() const; + + bool setKeySequence( uint i, const KKeySequence& ); + void clearShortcut(); + bool contains( const KKeySequence& ); + + QString toString() const; + QString toStringInternal() const; + + static bool useFourModifierKeys(); + static void useFourModifierKeys( bool ); + + protected: + QString m_sName, + m_sLabel, + m_sWhatsThis; + KShortcut m_cut; + KShortcut m_cutDefault3, m_cutDefault4; + const QObject* m_pObjSlot; + const char* m_psMethodSlot; + bool m_bConfigurable, + m_bEnabled; + int m_nIDAccel; + uint m_nConnections; + + void incConnections(); + void decConnections(); + + private: + static int g_bUseFourModifierKeys; + class KAccelActionPrivate* d; + + friend class KAccelActions; + friend class KAccelBase; +}; + +//--------------------------------------------------------------------- +// KAccelActions +//--------------------------------------------------------------------- + +class KAccelActions +{ + public: + KAccelActions(); + KAccelActions( const KAccelActions& ); + virtual ~KAccelActions(); + + void clear(); + bool init( const KAccelActions& ); + bool init( KConfigBase& config, const QString& sGroup ); + + void updateShortcuts( KAccelActions& ); + + int actionIndex( const QString& sAction ) const; + KAccelAction* actionPtr( uint ); + const KAccelAction* actionPtr( uint ) const; + KAccelAction* actionPtr( const QString& sAction ); + const KAccelAction* actionPtr( const QString& sAction ) const; + KAccelAction* actionPtr( KKeySequence cut ); + KAccelAction& operator []( uint ); + const KAccelAction& operator []( uint ) const; + + KAccelAction* insert( const QString& sAction, const QString& sLabel, const QString& sWhatsThis, + const KShortcut& rgCutDefaults3, const KShortcut& rgCutDefaults4, + const QObject* pObjSlot = 0, const char* psMethodSlot = 0, + bool bConfigurable = true, bool bEnabled = true ); + KAccelAction* insert( const QString& sName, const QString& sLabel ); + bool remove( const QString& sAction ); + + bool readActions( const QString& sConfigGroup = "Shortcuts", KConfigBase* pConfig = 0 ); + bool writeActions( const QString& sConfigGroup = "Shortcuts", KConfigBase* pConfig = 0, + bool bWriteAll = false, bool bGlobal = false ) const; + + void emitKeycodeChanged(); + + uint count() const; + + protected: + KAccelBase* m_pKAccelBase; + KAccelAction** m_prgActions; + uint m_nSizeAllocated, m_nSize; + + void resize( uint ); + void insertPtr( KAccelAction* ); + + private: + class KAccelActionsPrivate* d; + + KAccelActions( KAccelBase* ); + void initPrivate( KAccelBase* ); + KAccelActions& operator =( KAccelActions& ); + + friend class KAccelBase; +}; + +#endif // _KACCELACTION_H diff --git a/extra/kde301/kaccelbase.h b/extra/kde301/kaccelbase.h new file mode 100644 index 0000000..1a80eee --- /dev/null +++ b/extra/kde301/kaccelbase.h @@ -0,0 +1,233 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001 Ellis Whitehead <ellis@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _KACCELBASE_H +#define _KACCELBASE_H + +#include <qmap.h> +#include <qptrvector.h> +#include <qstring.h> +#include <qvaluevector.h> +#include <qvaluelist.h> + +#include "kaccelaction.h" +#include "kkeyserver_x11.h" + +class QPopupMenu; +class QWidget; + +//---------------------------------------------------- + +class KAccelBasePrivate; +/** + * Handle keyboard accelerators. + * + * Allow an user to configure + * key bindings through application configuration files or through the + * @ref KKeyChooser GUI. + * + * A @ref KAccel contains a list of accelerator items. Each accelerator item + * consists of an action name and a keyboard code combined with modifiers + * (Shift, Ctrl and Alt.) + * + * For example, "Ctrl+P" could be a shortcut for printing a document. The key + * codes are listed in ckey.h. "Print" could be the action name for printing. + * The action name identifies the key binding in configuration files and the + * @ref KKeyChooser GUI. + * + * When pressed, an accelerator key calls the slot to which it has been + * connected. Accelerator items can be connected so that a key will activate + * two different slots. + * + * A KAccel object handles key events sent to its parent widget and to all + * children of this parent widget. + * + * Key binding reconfiguration during run time can be prevented by specifying + * that an accelerator item is not configurable when it is inserted. A special + * group of non-configurable key bindings are known as the + * standard accelerators. + * + * The standard accelerators appear repeatedly in applications for + * standard document actions such as printing and saving. Convenience methods are + * available to insert and connect these accelerators which are configurable on + * a desktop-wide basis. + * + * It is possible for a user to choose to have no key associated with + * an action. + * + * The translated first argument for @ref insertItem() is used only + * in the configuration dialog. + *<pre> + * KAccel *a = new KAccel( myWindow ); + * // Insert an action "Scroll Up" which is associated with the "Up" key: + * a->insertItem( i18n("Scroll up"), "Scroll Up", "Up" ); + * // Insert an action "Scroll Down" which is not associated with any key: + * a->insertItem( i18n("Scroll down"), "Scroll Down", 0); + * a->connectItem( "Scroll up", myWindow, SLOT( scrollUp() ) ); + * // a->insertStdItem( KStdAccel::Print ); //not necessary, since it + * // is done automatially with the + * // connect below! + * a->connectItem(KStdAccel::Print, myWindow, SLOT( printDoc() ) ); + * + * a->readSettings(); + *</pre> + * + * If a shortcut has a menu entry as well, you could insert them like + * this. The example is again the @ref KStdAccel::Print from above. + * + * <pre> + * int id; + * id = popup->insertItem("&Print",this, SLOT(printDoc())); + * a->changeMenuAccel(popup, id, KStdAccel::Print ); + * </pre> + * + * If you want a somewhat "exotic" name for your standard print action, like + * id = popup->insertItem(i18n("Print &Document"),this, SLOT(printDoc())); + * it might be a good idea to insert the standard action before as + * a->insertStdItem( KStdAccel::Print, i18n("Print Document") ) + * as well, so that the user can easily find the corresponding function. + * + * This technique works for other actions as well. Your "scroll up" function + * in a menu could be done with + * + * <pre> + * id = popup->insertItem(i18n"Scroll &up",this, SLOT(scrollUp())); + * a->changeMenuAccel(popup, id, "Scroll Up" ); + * </pre> + * + * Please keep the order right: First insert all functions in the + * acceleratior, then call a -> @ref readSettings() and @em then build your + * menu structure. + * + * @short Configurable key binding support. + * @version $Id: kaccelbase.h,v 1.20 2002/03/03 21:20:25 lunakl Exp $ + */ + +class KAccelBase +{ + public: + enum Init { QT_KEYS = 0x00, NATIVE_KEYS = 0x01 }; + enum Signal { KEYCODE_CHANGED }; + + KAccelBase( int fInitCode ); + virtual ~KAccelBase(); + + uint actionCount() const; + KAccelActions& actions(); + bool isEnabled() const; + + KAccelAction* actionPtr( const QString& sAction ); + const KAccelAction* actionPtr( const QString& sAction ) const; + KAccelAction* actionPtr( const KKey& key ); + KAccelAction* actionPtr( const KKeyServer::Key& key ); + + const QString& configGroup() const { return m_sConfigGroup; } + void setConfigGroup( const QString& group ); + void setConfigGlobal( bool global ); + virtual void setEnabled( bool bEnabled ) = 0; + bool getAutoUpdate() { return m_bAutoUpdate; } + // return value of AutoUpdate flag before this call. + bool setAutoUpdate( bool bAuto ); + +// Procedures for manipulating Actions. + //void clearActions(); + + KAccelAction* insert( const QString& sName, const QString& sDesc ); + KAccelAction* insert( + const QString& sAction, const QString& sDesc, const QString& sHelp, + const KShortcut& rgCutDefaults3, const KShortcut& rgCutDefaults4, + const QObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable = true, bool bEnabled = true ); + bool remove( const QString& sAction ); + bool setActionSlot( const QString& sAction, const QObject* pObjSlot, const char* psMethodSlot ); + + bool updateConnections(); + + bool setShortcut( const QString& sAction, const KShortcut& cut ); + +// Modify individual Action sub-items + bool setActionEnabled( const QString& sAction, bool bEnable ); + + /** + * Read all key associations from @p config, or (if @p config + * is zero) from the application's configuration file + * @ref KGlobal::config(). + * + * The group in which the configuration is stored can be + * set with @ref setConfigGroup(). + */ + void readSettings( KConfigBase* pConfig = 0 ); + + /** + * Write the current configurable associations to @p config, + * or (if @p config is zero) to the application's + * configuration file. + */ + void writeSettings( KConfigBase* pConfig = 0 ) const; + + QPopupMenu* createPopupMenu( QWidget* pParent, const KKeySequence& ); + + // Protected methods + protected: + void slotRemoveAction( KAccelAction* ); + + void createKeyList( QValueVector<struct X>& rgKeys ); + bool insertConnection( KAccelAction* ); + bool removeConnection( KAccelAction* ); + + virtual bool emitSignal( Signal ) = 0; + virtual bool connectKey( KAccelAction&, const KKeyServer::Key& ) = 0; + virtual bool connectKey( const KKeyServer::Key& ) = 0; + virtual bool disconnectKey( KAccelAction&, const KKeyServer::Key& ) = 0; + virtual bool disconnectKey( const KKeyServer::Key& ) = 0; + + protected: + struct ActionInfo + { + KAccelAction* pAction; + uint iSeq, iVariation; + //ActionInfo* pInfoNext; // nil if only one action uses this key. + + ActionInfo() { pAction = 0; iSeq = 0xffff; iVariation = 0xffff; } + ActionInfo( KAccelAction* _pAction, uint _iSeq, uint _iVariation ) + { pAction = _pAction; iSeq = _iSeq; iVariation = _iVariation; } + }; + typedef QMap<KKeyServer::Key, ActionInfo> KKeyToActionMap; + + KAccelActions m_rgActions; + KKeyToActionMap m_mapKeyToAction; + QValueList<KAccelAction*> m_rgActionsNonUnique; + bool m_bNativeKeys; // Use native key codes instead of Qt codes + bool m_bEnabled; + bool m_bConfigIsGlobal; + QString m_sConfigGroup; + bool m_bAutoUpdate; + KAccelAction* mtemp_pActionRemoving; + + private: + KAccelBase& operator =( const KAccelBase& ); + + friend class KAccelActions; + protected: + virtual void virtual_hook( int id, void* data ); + private: + KAccelBasePrivate* d; +}; + +#endif // _KACCELBASE_H diff --git a/extra/kde301/kicontheme.h b/extra/kde301/kicontheme.h new file mode 100644 index 0000000..78fc8f1 --- /dev/null +++ b/extra/kde301/kicontheme.h @@ -0,0 +1,217 @@ +/* vi: ts=8 sts=4 sw=4 + * + * $Id: kicontheme.h,v 1.19 2002/03/05 23:13:26 rich Exp $ + * + * This file is part of the KDE project, module kdecore. + * Copyright (C) 2000 Geert Jansen <jansen@kde.org> + * Antonio Larrosa <larrosa@kde.org> + * + * This is free software; it comes under the GNU Library General + * Public License, version 2. See the file "COPYING.LIB" for the + * exact licensing terms. + * + */ + +#ifndef __KIconTheme_h_Included__ +#define __KIconTheme_h_Included__ + +#include <qstring.h> +#include <qstringlist.h> +#include <qptrlist.h> + +class KConfig; +//class KIconThemeDir; + +class KIconThemePrivate; + +class KIconPrivate; + +/** + * One icon as found by KIconTheme. Also serves as a namespace containing + * icon related constants. + */ +class KIcon +{ +public: + KIcon() { size = 0; } + + /** + * Return true if this icon is valid, false otherwise. + */ + bool isValid() const { return size != 0; } + + enum Context { Any, Action, Application, Device, FileSystem, MimeType }; + enum Type { Fixed, Scalable, Threshold }; + enum MatchType { MatchExact, MatchBest }; + // if you add a group here, make sure to change the config reading in + // KIconLoader too + enum Group { NoGroup=-1, Desktop=0, FirstGroup=Desktop, Toolbar, + MainToolbar, Small, Panel, LastGroup, User }; + enum StdSizes { SizeSmall=16, SizeMedium=32, SizeLarge=48 }; + enum States { DefaultState, ActiveState, DisabledState, LastState }; + enum Overlays { LockOverlay=0x100, ZipOverlay=0x200, LinkOverlay=0x400, + HiddenOverlay=0x800, OverlayMask = ~0xff }; + + /** + * The size in pixels of the icon. + */ + int size; + + /** + * The context of the icon. + */ + Context context; + + /** + * The type of the icon: Fixed, Scalable or Threshold. + **/ + Type type; + + /** + * The threshold in case type == Threshold + */ + int threshold; + + /** + * The full path of the icon. + */ + QString path; + +private: + KIconPrivate *d; +}; + +inline KIcon::Group& operator++(KIcon::Group& group) { group = static_cast<KIcon::Group>(group+1); return group; } +inline KIcon::Group operator++(KIcon::Group& group,int) { KIcon::Group ret = group; ++group; return ret; } + +/** + * Class to use/access icon themes in KDE. This class is used by the + * iconloader but can be used by others too. + */ +class KIconTheme +{ +public: + /** + * Load an icon theme by name. + */ + KIconTheme(const QString& name, const QString& appName=QString::null); + ~KIconTheme(); + + /** + * The stylized name of the icon theme. + */ + QString name() const { return mName; } + + /** + * A description for the icon theme. + */ + QString description() const { return mDesc; } + + /** + * Return the name of the "example" icon. + */ + QString example() const; + + /** + * Return the name of the screenshot. + */ + QString screenshot() const; + + /** + * Returns the name of this theme's link overlay. + */ + QString linkOverlay() const; + + /** + * Returns the name of this theme's zip overlay. + */ + QString zipOverlay() const; + + /** + * Returns the name of this theme's lock overlay. + */ + QString lockOverlay() const; + + /** + * Returns the toplevel theme directory. + */ + QString dir() const { return mDir; } + + /** + * The themes this icon theme falls back on. + */ + QStringList inherits() const { return mInherits; } + + /** + * The icon theme exists? + */ + bool isValid() const; + + /** + * The minimum display depth required for this theme. This can either + * be 8 or 32. + */ + int depth() const { return mDepth; } + + /** + * The default size of this theme for a certain icon group. + * @param group The icon group. See @ref #KIcon::Group. + * @return The default size in pixels for the given icon group. + */ + int defaultSize(KIcon::Group group) const; + + /** + * Query available sizes for a group. + */ + QValueList<int> querySizes(KIcon::Group group) const; + + /** + * Query available icons for a size and context. + */ + QStringList queryIcons(int size, KIcon::Context context = KIcon::Any) const; + + /** + * Query available icons for a context and preferred size. + */ + QStringList queryIconsByContext(int size, KIcon::Context context = KIcon::Any) const; + + + /** + * Lookup an icon in the theme. + * @param name The name of the icon, without extension. + * @param size The desired size of the icon. + * @param match The matching mode. KIcon::MatchExact returns an icon + * only if matches exactly. KIcon::MatchBest returns the best matching + * icon. + * @return A KIcon class that describes the icon. If an icon is found, + * @ref #KIcon::isValid will return true, and false otherwise. + */ + KIcon iconPath(const QString& name, int size, KIcon::MatchType match) const; + + /** + * List all icon themes installed on the system, global and local. + */ + static QStringList list(); + + /** + * Returns the current icon theme. + */ + static QString current(); + + static void reconfigure(); + +private: + int mDefSize[8]; + QValueList<int> mSizes[8]; + + int mDepth; + QString mDir, mName, mDesc; + QStringList mInherits; +// QPtrList<KIconThemeDir> mDirs; + KIconThemePrivate *d; + + static QString *_theme; + static QStringList *_theme_list; +}; + +#endif diff --git a/extra/kde301/kkeyserver_x11.h b/extra/kde301/kkeyserver_x11.h new file mode 100644 index 0000000..faeb99c --- /dev/null +++ b/extra/kde301/kkeyserver_x11.h @@ -0,0 +1,131 @@ +#ifndef _KKEYSERVER_X11_H +#define _KKEYSERVER_X11_H + +#include "kshortcut.h" +#include "kkeynative.h" + +namespace KKeyServer +{ + struct CodeMod { int code, mod; }; + + struct Sym + { + public: + uint m_sym; + + Sym() + { m_sym = 0; } + Sym( uint sym ) + { m_sym = sym; } + Sym( const QString& s ) + { init( s ); } + + bool initQt( int keyQt ); + bool init( const QString& ); + + int qt() const; + QString toStringInternal() const; + QString toString() const; + + uint getModsRequired() const; + uint getSymVariation() const; + + operator uint() const { return m_sym; } + Sym& operator =( uint sym ) { m_sym = sym; return *this; } + + private: + QString toString( bool bUserSpace ) const; + + static void capitalizeKeyname( QString& ); + }; + + struct Key + { + enum { CODE_FOR_QT = 256 }; + + uint m_code; + uint m_mod; + uint m_sym; + + bool init( const KKey& key, bool bQt ); + + bool isNative() const { return m_code != CODE_FOR_QT; } + + uint code() const { return m_code; } + uint mod() const { return m_mod; } + uint sym() const { return m_sym; } + int keyCodeQt() const { return (int) m_sym; } + + void setKeycodeQt( int keyQt ) + { m_code = CODE_FOR_QT; m_sym = keyQt; } + + Key& operator =( const KKeyNative& key ); + int compare( const Key& ) const; + + bool operator ==( const Key& b ) const + { return compare( b ) == 0; } + bool operator <( const Key& b ) const + { return compare( b ) < 0; } + + KKey key() const; + }; + + struct Variations + { + enum { MAX_VARIATIONS = 4 }; + + Key m_rgkey[MAX_VARIATIONS]; + uint m_nVariations; + + Variations() { m_nVariations = 0; } + + void init( const KKey&, bool bQt ); + + uint count() const { return m_nVariations; } + const Key& key( uint i ) const { return m_rgkey[i]; } + }; + + bool initializeMods(); + + /** + * Returns the equivalent X modifier mask of the given modifier flag. + */ + uint modX( KKey::ModFlag ); + /** + * Returns true if the current keyboard layout supports the Win key. + * Specifically, whether the Super or Meta keys are assigned to an X modifier. + */ + bool keyboardHasWinKey(); + uint modXShift(); + uint modXLock(); + uint modXCtrl(); + uint modXAlt(); + uint modXNumLock(); + uint modXWin(); + uint modXScrollLock(); + /** + * Returns bitwise OR'ed mask containing Shift, Ctrl, Alt, and + * Win (if available). + */ + uint accelModMaskX(); + + bool keyQtToSym( int keyQt, uint& sym ); + bool keyQtToMod( int keyQt, uint& mod ); + bool symToKeyQt( uint sym, int& keyQt ); + + bool modToModQt( uint mod, int& modQt ); + bool modToModX( uint mod, uint& modX ); + bool modXToModQt( uint modX, int& modQt ); + bool modXToMod( uint modX, uint& mod ); + + bool codeXToSym( uchar codeX, uint modX, uint& symX ); + + QString modToStringInternal( uint mod ); + QString modToStringUser( uint mod ); + + bool stringToSymMod( const QString&, uint& sym, uint& mod ); + + void keyQtToKeyX( uint keyCombQt, unsigned char *pKeyCodeX, uint *pKeySymX, uint *pKeyModX ); +}; + +#endif // !_KKEYSERVER_X11_H diff --git a/extra/kde301/konsole_part.h b/extra/kde301/konsole_part.h new file mode 100644 index 0000000..ba89800 --- /dev/null +++ b/extra/kde301/konsole_part.h @@ -0,0 +1,223 @@ +/* + This file is part of the KDE system + Copyright (C) 1999,2000 Boloni Laszlo + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef __KONSOLE_PART_H__ +#define __KONSOLE_PART_H__ + +#include <kparts/browserextension.h> +#include <kparts/factory.h> + + +#include <kdialogbase.h> + +#include <kde_terminal_interface.h> + +//#include "schema.h" +//#include "session.h" + +class KInstance; +class konsoleBrowserExtension; +class QPushButton; +class QSpinBox; +class KPopupMenu; +class QCheckBox; +class KRootPixmap; +class KToggleAction; +class KSelectAction; + +namespace KParts { class GUIActivateEvent; } + +class konsoleFactory : public KParts::Factory +{ + Q_OBJECT +public: + konsoleFactory(); + virtual ~konsoleFactory(); + + virtual KParts::Part* createPartObject(QWidget *parentWidget = 0, const char *widgetName = 0, + QObject* parent = 0, const char* name = 0, + const char* classname = "KParts::Part", + const QStringList &args = QStringList()); + + static KInstance *instance(); + + private: + static KInstance *s_instance; + static KAboutData *s_aboutData; +}; + +////////////////////////////////////////////////////////////////////// + +class konsolePart: public KParts::ReadOnlyPart, public TerminalInterface +{ + Q_OBJECT + public: + konsolePart(QWidget *parentWidget, const char *widgetName, QObject * parent, const char *name, const char *classname = 0); + virtual ~konsolePart(); + +signals: + void processExited(); + void receivedData( const QString& s ); + protected: + virtual bool openURL( const KURL & url ); + virtual bool openFile() {return false;} // never used + virtual bool closeURL() {return true;} + virtual void guiActivateEvent( KParts::GUIActivateEvent * event ); + + protected slots: + void showShell(); + void slotProcessExited(); + void slotReceivedData( const QString& s ); + +// void doneSession(TESession*); + void sessionDestroyed(); +// void configureRequest(TEWidget*,int,int x,int y); + void updateTitle(); + void enableMasterModeConnections(); + + private slots: + void emitOpenURLRequest(const QString &url); + + void readProperties(); + void saveProperties(); + + void sendSignal(int n); + void closeCurrentSession(); + + void notifySize(int,int); + + void slotToggleFrame(); + void slotSelectScrollbar(); + void slotSelectFont(); + void schema_menu_check(); + void keytab_menu_activated(int item); + void updateSchemaMenu(); + void setSchema(int n); + void pixmap_menu_activated(int item); + void schema_menu_activated(int item); + void slotHistoryType(); + void slotSelectBell(); + void slotSelectLineSpacing(); + void slotBlinkingCursor(); + void slotWordSeps(); + void fontNotFound(); + + private: + konsoleBrowserExtension *m_extension; + KURL currentURL; + + void makeGUI(); + void applySettingsToGUI(); + + void setFont(int fontno); +// void setSchema(ColorSchema* s); + void updateKeytabMenu(); + + bool doOpenStream( const QString& ); + bool doWriteStream( const QByteArray& ); + bool doCloseStream(); + + QWidget* parentWidget; +// TEWidget* te; +// TESession* se; +// ColorSchemaList* colors; + KRootPixmap* rootxpm; + + KToggleAction* blinkingCursor; + KToggleAction* showFrame; + + KSelectAction* selectBell; + KSelectAction* selectFont; + KSelectAction* selectLineSpacing; + KSelectAction* selectScrollbar; + + KPopupMenu* m_keytab; + KPopupMenu* m_schema; + KPopupMenu* m_signals; + KPopupMenu* m_options; + KPopupMenu* m_popupMenu; + + QFont defaultFont; + + QString pmPath; // pixmap path + QString s_schema; + QString s_kconfigSchema; + QString s_word_seps; // characters that are considered part of a word + QString fontNotFound_par; + + bool b_framevis:1; + bool b_histEnabled:1; + + int curr_schema; // current schema no + int n_bell; + int n_font; + int n_keytab; + int n_render; + int n_scroll; + unsigned m_histSize; + bool m_runningShell; + bool m_streamEnabled; +public: + // these are the implementations for the TermEmuInterface + // functions... + void startProgram( const QString& program, + const QStrList& args ); + void showShellInDir( const QString& dir ); + void sendInput( const QString& text ); +}; + +////////////////////////////////////////////////////////////////////// + +/*class HistoryTypeDialog : public KDialogBase +{ + Q_OBJECT +public: + HistoryTypeDialog(const HistoryType& histType, + unsigned int histSize, + QWidget *parent); + +public slots: + void slotDefault(); + void slotSetUnlimited(); + void slotHistEnable(bool); + + unsigned int nbLines() const; + bool isOn() const; + +protected: + QCheckBox* m_btnEnable; + QSpinBox* m_size; + QPushButton* m_setUnlimited; +};*/ + +////////////////////////////////////////////////////////////////////// + +class konsoleBrowserExtension : public KParts::BrowserExtension +{ + Q_OBJECT + friend class konsolePart; + public: + konsoleBrowserExtension(konsolePart *parent); + virtual ~konsoleBrowserExtension(); + + void emitOpenURLRequest(const KURL &url); +}; + +#endif diff --git a/extra/kde301/krecentdirs.h b/extra/kde301/krecentdirs.h new file mode 100644 index 0000000..71f771b --- /dev/null +++ b/extra/kde301/krecentdirs.h @@ -0,0 +1,68 @@ +/* -*- c++ -*- + * Copyright (C)2000 Waldo Bastian <bastian@kde.org> + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#ifndef __KRECENTDIRS_H +#define __KRECENTDIRS_H + +#include <qstringlist.h> + +/** + * The goal of this class is to make sure that, when the user needs to + * specify a file via the file selection dialog, this dialog will start + * in the directory most likely to contain the desired files. + * + * This works as follows: Each time the file selection dialog is + * shown, the programmer can specify a "file-class". The file-dialog will + * then start with the directory associated with this file-class. When + * the dialog closes, the directory currently shown in the file-dialog + * will be associated with the file-class. + * + * A file-class can either start with ':' or with '::'. If it starts with + * a single ':' the file-class is specific to the current application. + * If the file-class starts with '::' it is global to all applications. + */ +class KRecentDirs +{ +public: + /** + * Returns a list of directories associated with this file-class. + * The most recently used directory is at the front of the list. + */ + static QStringList list(const QString &fileClass); + + /** + * Returns the most recently used directory accociated with this file-class. + */ + static QString dir(const QString &fileClass); + + /** + * Associates @p directory with @p fileClass + */ + static void add(const QString &fileClass, const QString &directory); +}; + +#endif diff --git a/extra/kde301/ksycocafactory.h b/extra/kde301/ksycocafactory.h new file mode 100644 index 0000000..af33ca8 --- /dev/null +++ b/extra/kde301/ksycocafactory.h @@ -0,0 +1,135 @@ +/* This file is part of the KDE libraries + * Copyright (C) 1999 Waldo Bastian <bastian@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation; + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + **/ + +#ifndef __ksycocafactory_h__ +#define __ksycocafactory_h__ "$Id: ksycocafactory.h,v 1.12 2002/03/03 21:20:26 lunakl Exp $" + +#include "ksycocatype.h" +#include "ksycocaentry.h" + +#include <qdict.h> +#include <qptrlist.h> +class KSycoca; +class QStringList; +class QString; +class KSycocaDict; +class KSycocaResourceList; + +typedef QDict<KSycocaEntry::Ptr> KSycocaEntryDict; + +/** + * @internal + * Base class for sycoca factories + */ +class KSycocaFactory +{ +public: + virtual KSycocaFactoryId factoryId() const = 0; + +protected: // virtual class + /** + * Create a factory which can be used to lookup from/create a database + * (depending on KSycoca::isBuilding()) + */ + KSycocaFactory( KSycocaFactoryId factory_id ); + +public: + virtual ~KSycocaFactory(); + + /** + * @return the position of the factory in the sycoca file + */ + int offset() { return mOffset; } + + /** + * @return the dict, for special use by KBuildSycoca + */ + KSycocaEntryDict * entryDict() { return m_entryDict; } + + /** + * Construct an entry from a config file. + * To be implemented in the real factories. + */ + virtual KSycocaEntry *createEntry(const QString &file, const char *resource) = 0; + + /** + * Add an entry + */ + virtual void addEntry(KSycocaEntry *newEntry, const char *resource); + + /** + * Read an entry from the database + */ + virtual KSycocaEntry *createEntry(int offset)=0; + + /** + * Get a list of all entries from the database. + */ + KSycocaEntry::List allEntries(); + + /** + * Saves all entries it maintains as well as index files + * for these entries to the stream 'str'. + * + * Also sets mOffset to the starting position. + * + * The stream is positioned at the end of the last index. + * + * Don't forget to call the parent first when you override + * this function. + */ + virtual void save(QDataStream &str); + + /** + * Writes out a header to the stream 'str'. + * The baseclass positions the stream correctly. + * + * Don't forget to call the parent first when you override + * this function. + */ + virtual void saveHeader(QDataStream &str); + + /** + * @return the resources for which this factory is responsible. + */ + virtual const KSycocaResourceList * resourceList() const { return m_resourceList; } + +private: + int mOffset; + +protected: + int m_sycocaDictOffset; + int m_beginEntryOffset; + int m_endEntryOffset; + QDataStream *m_str; + + KSycocaResourceList *m_resourceList; + KSycocaEntryDict *m_entryDict; + KSycocaDict *m_sycocaDict; +protected: + virtual void virtual_hook( int id, void* data ); +}; + +// This, instead of a typedef, allows to declare "class ..." in header files +class KSycocaFactoryList : public QPtrList<KSycocaFactory> +{ +public: + KSycocaFactoryList() { } +}; + +#endif diff --git a/extra/kde301/ktoolbarbutton.h b/extra/kde301/ktoolbarbutton.h new file mode 100644 index 0000000..bb6806b --- /dev/null +++ b/extra/kde301/ktoolbarbutton.h @@ -0,0 +1,313 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) + (C) 1997, 1998 Sven Radej (radej@kde.org) + (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) + (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) + (C) 2000 Kurt Granroth (granroth@kde.org) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// $Id: ktoolbarbutton.h,v 1.21.2.1 2002/04/28 20:59:16 wtrobin Exp $ +#ifndef _KTOOLBARBUTTON_H +#define _KTOOLBARBUTTON_H + +#include <qpixmap.h> +#include <qtoolbutton.h> +#include <qintdict.h> +#include <qstring.h> +#include <kglobal.h> + +class KToolBar; +class KToolBarButtonPrivate; +class KInstance; +class QEvent; +class QPopupMenu; +class QPainter; + +/** + * A toolbar button. This is used internally by @ref KToolBar, use the + * KToolBar methods instead. + * @internal + */ +class KToolBarButton : public QToolButton +{ + Q_OBJECT + +public: + /** + * Construct a button with an icon loaded by the button itself. + * This will trust the button to load the correct icon with the + * correct size. + * + * @param icon Name of icon to load (may be absolute or relative) + * @param id Id of this button + * @param parent This button's parent + * @param name This button's internal name + * @param txt This button's text (in a tooltip or otherwise) + */ + KToolBarButton(const QString& icon, int id, QWidget *parent, + const char *name=0L, const QString &txt=QString::null, + KInstance *_instance = KGlobal::instance()); + + /** + * Construct a button with an existing pixmap. It is not + * recommended that you use this as the internal icon loading code + * will almost always get it "right". + * + * @param icon Name of icon to load (may be absolute or relative) + * @param id Id of this button + * @param parent This button's parent + * @param name This button's internal name + * @param txt This button's text (in a tooltip or otherwise) + */ + KToolBarButton(const QPixmap& pixmap, int id, QWidget *parent, + const char *name=0L, const QString &txt=QString::null); + + /** + * Construct a separator button + * + * @param parent This button's parent + * @param name This button's internal name + */ + KToolBarButton(QWidget *parent=0L, const char *name=0L); + + /** + * Standard destructor + */ + ~KToolBarButton(); + +#ifndef KDE_NO_COMPAT + /** + * @deprecated + * Set the pixmap directly for this button. This pixmap should be + * the active one... the dimmed and disabled pixmaps are constructed + * based on this one. However, don't use this function unless you + * are positive that you don't want to use @ref setIcon. + * + * @param pixmap The active pixmap + */ + // this one is from QButton, so #ifdef-ing it out doesn't break BC + virtual void setPixmap(const QPixmap &pixmap); + + /** + * @deprecated + * Force the button to use this pixmap as the default one rather + * then generating it using effects. + * + * @param pixmap The pixmap to use as the default (normal) one + */ + void setDefaultPixmap(const QPixmap& pixmap); + + /** + * @deprecated + * Force the button to use this pixmap when disabled one rather then + * generating it using effects. + * + * @param pixmap The pixmap to use when disabled + */ + void setDisabledPixmap(const QPixmap& pixmap); +#endif + + /** + * Set the text for this button. The text will be either used as a + * tooltip (IconOnly) or will be along side the icon + * + * @param text The button (or tooltip) text + */ + virtual void setText(const QString &text); + + /** + * Set the icon for this button. The icon will be loaded internally + * with the correct size. This function is preferred over @ref setIconSet + * + * @param icon The name of the icon + */ + virtual void setIcon(const QString &icon); + + virtual void setIcon( const QPixmap &pixmap ) + { return QToolButton::setIcon( pixmap ); } + + /** + * Set the pixmaps for this toolbar button from a QIconSet. + * If you call this you don't need to call any of the other methods + * that set icons or pixmaps. + * @param iconset The iconset to use + */ + virtual void setIconSet( const QIconSet &iconset ); + +#ifndef KDE_NO_COMPAT + /** + * @deprecated + * Set the active icon for this button. The pixmap itself is loaded + * internally based on the icon size... .. the disabled and default + * pixmaps, however will only be constructed if @ref #generate is + * true. This function is preferred over @ref setPixmap + * + * @param icon The name of the active icon + * @param generate If true, then the other icons are automagically + * generated from this one + */ + void setIcon(const QString &icon, bool /*generate*/ ) { setIcon( icon ); } + + /** + * @deprecated + * Force the button to use this icon as the default one rather + * then generating it using effects. + * + * @param icon The icon to use as the default (normal) one + */ + void setDefaultIcon(const QString& icon); + + /** + * @deprecated + * Force the button to use this icon when disabled one rather then + * generating it using effects. + * + * @param icon The icon to use when disabled + */ + void setDisabledIcon(const QString& icon); +#endif + + /** + * Turn this button on or off + * + * @param flag true or false + */ + void on(bool flag = true); + + /** + * Toggle this button + */ + void toggle(); + + /** + * Turn this button into a toggle button or disable the toggle + * aspects of it. This does not toggle the button itself. Use @ref + * toggle for that. + * + * @param toggle true or false + */ + void setToggle(bool toggle = true); + + /** + * Return a pointer to this button's popup menu (if it exists) + */ + QPopupMenu *popup(); + + /** + * Give this button a popup menu. There will not be a delay when + * you press the button. Use @ref setDelayedPopup if you want that + * behavior. You can also make the popup-menu + * "sticky", i.e. visible until a selection is made or the mouse is + * clikced elsewhere, by simply setting the second argument to true. + * This "sticky" button feature allows you to make a selection without + * having to press and hold down the mouse while making a selection. + * + * @param p The new popup menu + * @param toggle if true, makes the button "sticky" (toggled) + */ + void setPopup (QPopupMenu *p, bool toggle = false); + + /** + * Gives this button a delayed popup menu. + * + * This function allows you to add a delayed popup menu to the button. + * The popup menu is then only displayed when the button is pressed and + * held down for about half a second. You can also make the popup-menu + * "sticky", i.e. visible until a selection is made or the mouse is + * clikced elsewhere, by simply setting the second argument to true. + * This "sticky" button feature allows you to make a selection without + * having to press and hold down the mouse while making a selection. + * + * @param p the new popup menu + * @param toggle if true, makes the button "sticky" (toggled) + */ + void setDelayedPopup(QPopupMenu *p, bool toggle = false); + + /** + * Turn this button into a radio button + * + * @param f true or false + */ + void setRadio(bool f = true); + + /** + * Toolbar buttons naturally will assume the global styles + * concerning icons, icons sizes, etc. You can use this function to + * explicitely turn this off, if you like. + * + * @param no_style Will disable styles if true + */ + void setNoStyle(bool no_style = true); + +signals: + void clicked(int); + void doubleClicked(int); + void pressed(int); + void released(int); + void toggled(int); + void highlighted(int, bool); + +public slots: + /** + * This slot should be called whenever the toolbar mode has + * potentially changed. This includes such events as text changing, + * orientation changing, etc. + */ + void modeChange(); + virtual void setTextLabel(const QString&, bool tipToo); + +protected: + void paletteChange(const QPalette &); + void leaveEvent(QEvent *e); + void enterEvent(QEvent *e); + void drawButton(QPainter *p); + bool eventFilter (QObject *o, QEvent *e); + void showMenu(); + QSize sizeHint() const; + QSize minimumSizeHint() const; + QSize minimumSize() const; + + bool isRaised() const; + bool isActive() const; + int iconTextMode() const; + +protected slots: + void slotClicked(); + void slotPressed(); + void slotReleased(); + void slotToggled(); + void slotDelayTimeout(); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + KToolBarButtonPrivate *d; +}; + +/** +* List of @ref KToolBarButton objects. +* @internal +* @version $Id: ktoolbarbutton.h,v 1.21.2.1 2002/04/28 20:59:16 wtrobin Exp $ +*/ +class KToolBarButtonList : public QIntDict<KToolBarButton> +{ +public: + KToolBarButtonList(); + ~KToolBarButtonList() {} +}; + +#endif diff --git a/extra/kde301/kurifilter.h b/extra/kde301/kurifilter.h new file mode 100644 index 0000000..b013817 --- /dev/null +++ b/extra/kde301/kurifilter.h @@ -0,0 +1,593 @@ +/* + * This file is part of the KDE libraries + * Copyright (C) 2000 Yves Arrouye <yves@realnames.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + **/ + +#ifndef __kurifilter_h__ +#define __kurifilter_h__ "$Id: kurifilter.h,v 1.23 2002/03/04 04:17:37 lunakl Exp $" + +#include <qptrlist.h> +#include <qobject.h> + +#include <kurl.h> + +class KURIFilterPrivate; +class KURIFilterDataPrivate; + +class QStringList; +class KCModule; + +/** +* This is a basic message object used for exchanging filtering +* information between the filter plugins and the application +* whenever the application requires more information about the +* URI than just a filtered version of it. Any application can +* create an instance of this class and send it to @ref KURIFilter +* to have the filter plugins fill the necessary information. +* +* @sect Example +* <pre> +* QString text = "kde.org"; +* KURIFilterData d = text; +* bool filtered = KURIFilter::self()->filter( d ); +* if( filtered ) +* print ( "URI: %s\n"Filtered URI: %s\n URI Type: %i\n"Was Filtered: %i" +* text.latin1(), d.uri().url().latin1(), d.uriType(), filtered ); +* </pre> +* +* The above code should yield the following output: +* <pre> +* URI: kde.org +* Filtered URI: http://kde.org +* URI Type: 0 <== means NET_PROTOCOL +* Was Filtered: 1 <== means the URL was successfully filtered +* </pre> +* +* @short A message object for exchanging filtering URI info. +*/ + +class KURIFilterData +{ +friend class KURIFilterPlugin; + +public: + /** + * Describes the type of URI to be filtered. + * + * This enumerator prvoides the return value for + * @ref uriType. A breif description for each value: + * + * @li NET_PROTOCOL - Any network protocol: http, ftp, nttp, pop3, etc... + * @li LOCAL_FILE - A local file whose executable flag is not set + * @li LOCAL_DIR - A local directory + * @li EXECUTABLE - A local file whose executable flag is set + * @li HELP - A man or info page + * @li SHELL - A shell executable (ex: echo "Test..." >> ~/testfile) + * @li BLOCKED - A URI that should be blocked/filtered (ex: ad filtering) + * @li ERROR - An incorrect URI (ex: "~johndoe" when user johndoe + * does not exist in that system ) + * @li UNKNOWN - A URI that is not identified. Default value when + * a KURIFilterData is first created. + */ + enum URITypes { NET_PROTOCOL=0, LOCAL_FILE, LOCAL_DIR, EXECUTABLE, HELP, SHELL, BLOCKED, ERROR, UNKNOWN }; + + /** + * Default constructor. + * + * Creates a URIFilterData object. + */ + KURIFilterData() { init(); } + + /** + * Creates a URIFilterData object from the given URL. + * + * @param url is the URL to be filtered. + */ + KURIFilterData( const KURL& url ) { init( url); } + + /** + * Creates a URIFilterData object from the given string. + * + * @param url is the string to be filtered. + */ + KURIFilterData( const QString& url ) { init( url ); } + + /** + * Copy constructor. + * + * Creates a URIFilterData object from another + * URI filter data object. + * + * @param data the uri filter data to be copied. + */ + KURIFilterData( const KURIFilterData& /*data*/); + + /** + * Destructor. + */ + ~KURIFilterData(); + + /** + * This method has been deprecated and will always return + * TRUE. You should instead use the result from the + * @ref KURIFilter::filterURI() calls. + * + * @deprecated + */ + bool hasBeenFiltered() const { return m_bFiltered; } + + /** + * Returns the filtered or the original URL. + * + * This function returns the filtered url if one + * of the plugins sucessfully filtered the original + * URL. Otherwise, it returns the original URL. + * See @ref #hasBeenFiltered() and + * + * @return the filtered or original url. + */ + KURL uri() const { return m_pURI; } + + /** + * Returns an error message. + * + * This functions returns the error message set + * by the plugin whenever the uri type is set to + * KURIFilterData::ERROR. Otherwise, it returns + * a QString::null. + * + * @return the error message or a NULL when there is none. + */ + QString errorMsg() const { return m_strErrMsg; } + + /** + * Returns the URI type. + * + * This method always returns KURIFilterData::UNKNOWN + * if the given URL was not filtered. + */ + URITypes uriType() const { return m_iType; } + + /** + * Sets the URL to be filtered. + * + * Use this function to set the string to be + * filtered when you construct an empty filter + * object. + * + * @param url the string to be filtered. + */ + void setData( const QString& url ) { init( url ); } + + /** + * Same as above except the argument is a URL. + * + * Use this function to set the string to be + * filtered when you construct an empty filter + * object. + * + * @param url the URL to be filtered. + */ + void setData( const KURL& url ) { init( url ); } + + /** + * Sets the absolute path to be used whenever the supplied + * data is a relative local URL. + * + * NOTE: This function works only for a local resource and + * expects the absolute path to the relative URL set in this + * meta object. If you are extracting the absolute path from + * a KURL object, make sure you always set the argument below + * using KURL::path() instead of KURL::url() so that "file:/" + * would not be appended! Otherwise, the filter might not be + * able to make correct determination whether the relative URL + * locally exists! + * + * @param abs_path the abolute path to the local resource. + * @return true if absolute path is successfully set. Otherwise, false. + */ + bool setAbsolutePath( const QString& /* abs_path */ ); + + /** + * Returns the absolute path if one has already been set. + */ + QString absolutePath() const; + + /** + * Returns true if the supplied data has an absolute path. + */ + bool hasAbsolutePath() const; + + /** + * Returns the command line options and arguments for a + * local resource when present. + * + * @return options and arguments when present, otherwise QString::null + */ + QString argsAndOptions() const; + + /** + * Returns true if the current data is a local resource with + * command line options and arguments. + */ + bool hasArgsAndOptions() const; + + /** + * Returns the name of the icon that matches + * the current filtered URL. + * + * NOTE that this function will return a NULL + * string by default and when no associated icon + * is found. + * + * @return the name of the icon associated with the resource + */ + QString iconName(); + + /** + * Overloaded assigenment operator. + * + * This function allows you to easily assign a KURL + * to a KURIFilterData object. + * + * @return an instance of a KURIFilterData object. + */ + KURIFilterData& operator=( const KURL& url ) { init( url ); return *this; } + + /** + * Overloaded assigenment operator. + * + * This function allows you to easily assign a QString + * to a KURIFilterData object. + * + * @return an instance of a KURIFilterData object. + */ + KURIFilterData& operator=( const QString& url ) { init( url ); return *this; } + +protected: + + /** + * Initializes the KURIFilterData on construction. + */ + void init( const KURL& url = QString::null ); + +private: + bool m_bFiltered; + bool m_bChanged; + + QString m_strErrMsg; + QString m_strIconName; + + KURL m_pURI; + URITypes m_iType; + KURIFilterDataPrivate *d; +}; + + +/** + * Base class for URI filter plugins. + * + * This class applies a single filter to a URI. All + * plugins designed to provide URI filtering functionalities + * should inherit from this abstract class and provide a + * specific filtering implementation. + * + * All inheriting classes need to implement the pure + * virtual function @ref filterURI. Otherwise, they + * would also become abstract. + * + * @short Abstract class for URI filter plugins. + */ +class KURIFilterPlugin : public QObject +{ + Q_OBJECT + +public: + + /** + * Constructs a filter plugin with a given name and + * priority. + * + * @param parent the parent object. + * @param name the name of the plugin. + * @param pri the priority of the plugin. + */ + KURIFilterPlugin( QObject *parent = 0, const char *name = 0, double pri = 1.0 ); + + /** + * Returns the filter's name. + * + * @return A string naming the filter. + */ + virtual QString name() const { return m_strName; } + + /** + * Returns the filter's priority. + * + * Each filter has an assigned priority, a float from 0 to 1. Filters + * with the lowest priority are first given a chance to filter a URI. + * + * @return The priority of the filter. + */ + virtual double priority() const { return m_dblPriority; } + + /** + * Filters a URI. + * + * @param data the URI data to be filtered. + * @return A boolean indicating whether the URI has been changed. + */ + virtual bool filterURI( KURIFilterData& data ) const = 0; + + /** + * Creates a configuration module for the filter. + * + * It is the responsability of the caller to delete the module + * once it is not needed anymore. + * + * @return A configuration module, @p null if the filter isn't configurable. + */ + virtual KCModule *configModule( QWidget*, const char* ) const { return 0; } + + /** + * Returns the name of the configuration module for the filter. + * + * @return the name of a configuration module or @p null if none. + */ + virtual QString configName() const { return name(); } + +protected: + + /** + * Sets the the URL in @p data to @p uri. + */ + void setFilteredURI ( KURIFilterData& data, const KURL& uri ) const; + + /** + * Sets the error message in @p data to @p errormsg. + */ + void setErrorMsg ( KURIFilterData& data, const QString& errmsg ) const { + data.m_strErrMsg = errmsg; + } + + /** + * Sets the URI type in @p data to @p type. + */ + void setURIType ( KURIFilterData& data, KURIFilterData::URITypes type) const { + data.m_iType = type; + data.m_bChanged = true; + } + + /** + * Sets the arguments and options string in @p data + * to @p args if any were found during filterting. + */ + void setArguments( KURIFilterData& data, const QString& args ) const; + + QString m_strName; + double m_dblPriority; + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class KURIFilterPluginPrivate *d; +}; + + +class KURIFilterPluginList : public QPtrList<KURIFilterPlugin> +{ +public: + virtual int compareItems(Item a, Item b) + { + double diff = ((KURIFilterPlugin *) a)->priority() - ((KURIFilterPlugin *) b)->priority(); + return diff < 0 ? -1 : (diff > 0 ? 1 : 0); + } + +private: + KURIFilterPrivate *d; + +}; + +/** + * Manages the filtering of a URI. + * + * The intention of this plugin class is to allow people to extend + * the functionality of KURL without modifying it directly. This + * way KURL will remain a generic parser capable of parsing any + * generic URL that adheres to specifications. + * + * The KURIFilter class applies a number of filters to a URI, + * and returns the filtered version whenever possible. The filters + * are implemented using plugins to provide easy extensibility + * of the filtering mechanism. That is, new filters can be added in + * the future by simply inheriting from @ref KURIFilterPlugin and + * implementing the @ref KURIFilterPlugin::filterURI method. + * + * Use of this plugin-manager class is straight forward. Since + * it is a singleton object, all you have to do is obtain an instance + * by doing @p KURIFilter::self() and use any of the public member + * functions to preform the filtering. + * + * @sect Example + * + * To simply filter a given string: + * <pre> + * bool filtered = KURIFilter::self()->filterURI( "kde.org" ); + * </pre> + * + * You can alternatively use a KURL: + * <pre> + * KURL url = "kde.org"; + * bool filtered = KURIFilter::self()->filterURI( url ); + * </pre> + * + * If you have a constant string or a constant URL, + * simply invoke the corresponding function to obtain + * the filtered string or URL instead of a boolean flag: + * <pre> + * QString u = KURIFilter::self()->filteredURI( "kde.org" ); + * </pre> + * + * You can also specify only specific filter(s) to be applied + * by supplying the name(s) of the filter(s). By defualt all + * filters that are found are loaded when the KURIFilter object + * is created will be used. These names are taken from the + * enteries in the \".desktop\" files. Here are a couple of + * examples: + * <pre> + * QString text = "kde.org"; + * bool filtered = KURIFilter::self()->filterURI( text, "KShortURIFilter" ); + * + * QStringList list; + * list << "KShortURIFilter" << "MyFilter"; + * bool filtered = KURIFilter::self()->filterURI( text, list ); + * </pre> + * + * KURIFilter also allows richer data exchange through a simple + * meta-object called @p KURIFilterData. Using this meta-object + * you can find out more information about the URL you want to + * filter. See @ref KURIFilterData for examples and details. + * + * @short Filters a given URL into its proper format whenever possible. + */ + +class KURIFilter +{ +public: + /** + * Destructor + */ + ~KURIFilter (); + + /** + * Return a static instance of KURIFilter. + */ + static KURIFilter* self(); + + /** + * Filters the URI given by the object URIFilterData. + * + * This filters the given data based on the specified + * filter list. If the list is empty all avaliable + * filter plugins would be used. If not, only those + * given in the list are used. + * + * @param data object that contains the URI to be filtered. + * @param filters specify the list filters to be used + * + * @return a boolean indicating whether the URI has been changed + */ + bool filterURI( KURIFilterData& data, const QStringList& filters = QStringList() ); + + /** + * Filters the URI given by the URL. + * + * This filters the given URL based on the specified + * filter list. If the list is empty all avaliable + * filter plugins would be used. If not, only those + * given in the list are used. + * + * @param uri the URI to filter. + * @param filters specify the list of filters to be used + * + * @return a boolean indicating whether the URI has been changed + */ + bool filterURI( KURL &uri, const QStringList& filters = QStringList() ); + + /** + * Filters a string representing a URI. + * + * This filters the given string based on the specified + * filter list. If the list is empty all avaliable + * filter plugins would be used. If not, only those + * given in the list are used. + * + * @param uri The URI to filter. + * @param filters specify the list filters to be used + * + * @return a boolean indicating whether the URI has been changed + */ + bool filterURI( QString &uri, const QStringList& filters = QStringList() ); + + /** + * Returns the filtered URI. + * + * This filters the given URL based on the specified + * filter list. If the list is empty all avaliable + * filter plugins would be used. If not, only those + * given in the list are used. + * + * @param uri The URI to filter. + * @param filters specify the list filters to be used + * + * @return the filtered URI or null if it cannot be filtered + */ + KURL filteredURI( const KURL &uri, const QStringList& filters = QStringList() ); + + /** + * Return a filtered string representation of a URI. + * + * This filters the given URL based on the specified + * filter list. If the list is empty all avaliable + * filter plugins would be used. If not, only those + * given in the list are used. + * + * @param uri the URI to filter. + * @param filters specify the list filters to be used + * + * @return the filtered URI or null if it cannot be filtered + */ + QString filteredURI( const QString &uri, const QStringList& filters = QStringList() ); + + /** + * Return an iterator to iterate over all loaded + * plugins. + * + * @return a plugin iterator. + */ + QPtrListIterator<KURIFilterPlugin> pluginsIterator() const; + +protected: + + /** + * A protected constructor. + * + * This constructor creates a KURIFilter and + * initializes all plugins it can find by invoking + * @ref loadPlugins. + */ + KURIFilter(); + + /** + * Loads all allowed plugins. + * + * This function loads all filters that have not + * been dis + */ + void loadPlugins(); + +private: + + static KURIFilter *m_self; + KURIFilterPluginList m_lstPlugins; + KURIFilterPrivate *d; + +}; + +#endif + |