kurlcombobox.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2, as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef KURLCOMBOBOX_H 00020 #define KURLCOMBOBOX_H 00021 00022 #include <tqevent.h> 00023 #include <tqptrlist.h> 00024 #include <tqmap.h> 00025 #include <tqpixmap.h> 00026 #include <tqstringlist.h> 00027 00028 #include <kcombobox.h> 00029 #include <kurl.h> 00030 00041 class KIO_EXPORT KURLComboBox : public KComboBox 00042 { 00043 Q_OBJECT 00044 Q_PROPERTY(TQStringList urls READ urls WRITE setURLs DESIGNABLE true) 00045 Q_PROPERTY(int maxItems READ maxItems WRITE setMaxItems DESIGNABLE true) 00046 00047 public: 00051 enum Mode { Files = -1, Directories = 1, Both = 0 }; 00059 enum OverLoadResolving { RemoveTop, RemoveBottom }; 00060 00076 KURLComboBox( Mode mode, TQWidget *parent=0, const char *name=0 ); 00077 KURLComboBox( Mode mode, bool rw, TQWidget *parent=0, const char *name=0 ); 00081 ~KURLComboBox(); 00082 00095 void setURL( const KURL& url ); 00096 00104 void setURLs( TQStringList urls ); 00105 00113 void setURLs( TQStringList urls, OverLoadResolving remove ); 00114 00125 TQStringList urls() const; 00126 00131 void setMaxItems( int ); 00132 00137 int maxItems() const { return myMaximum; } 00138 00147 void addDefaultURL( const KURL& url, const TQString& text = TQString::null ); 00148 00157 void addDefaultURL( const KURL& url, const TQPixmap& pix, 00158 const TQString& text = TQString::null ); 00159 00165 void setDefaults(); 00166 00171 void removeURL( const KURL& url, bool checkDefaultURLs = true ); 00172 00173 signals: 00179 void urlActivated( const KURL& url ); 00180 00181 00182 protected slots: 00183 void slotActivated( int ); 00184 00185 00186 protected: 00187 struct _KURLComboItem { 00188 TQString text; 00189 KURL url; 00190 TQPixmap pixmap; 00191 }; 00192 typedef _KURLComboItem KURLComboItem; 00193 TQPtrList<KURLComboItem> itemList; 00194 TQPtrList<KURLComboItem> defaultList; 00195 TQMap<int,const KURLComboItem*> itemMapper; 00196 00197 void init( Mode mode ); 00198 void insertURLItem( const KURLComboItem * ); 00199 00204 TQPixmap getPixmap( const KURL& url ) const; 00205 00211 void updateItem( const KURLComboItem *item, int index, const TQPixmap& pix); 00212 00213 TQPixmap opendirPix; 00214 int firstItemIndex; 00215 00216 00217 private: 00218 bool urlAdded; 00219 int myMaximum; 00220 Mode myMode; // can be used as parameter to KUR::path( int ) or url( int ) 00221 // to specify if we want a trailing slash or not 00222 00223 private: 00224 class KURLComboBoxPrivate; 00225 KURLComboBoxPrivate *d; 00226 }; 00227 00228 00229 #endif // KURLCOMBOBOX_H