20 #include <tqlistbox.h>
23 #include <tdeglobal.h>
24 #include <kiconloader.h>
25 #include <tdelocale.h>
26 #include <kmimetype.h>
28 #include <kurlcombobox.h>
30 class KURLComboBox::KURLComboBoxPrivate
33 KURLComboBoxPrivate() {
34 dirpix = SmallIcon(TQString::fromLatin1(
"folder"));
42 : KComboBox( parent, name )
50 : KComboBox( rw, parent, name )
62 void KURLComboBox::init( Mode mode )
64 d =
new KURLComboBoxPrivate();
69 itemList.setAutoDelete(
true );
70 defaultList.setAutoDelete(
true );
71 setInsertionPolicy( NoInsertion );
72 setTrapReturnKey(
true );
73 setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
75 opendirPix = SmallIcon(TQString::fromLatin1(
"folder_open"));
77 connect(
this, TQ_SIGNAL( activated(
int )), TQ_SLOT( slotActivated(
int )));
83 kdDebug(250) <<
"::urls()" << endl;
87 for (
int i = defaultList.count(); i < count(); i++ ) {
89 if ( !url.isEmpty() ) {
108 const TQString& text )
110 KURLComboItem *item =
new KURLComboItem;
113 if ( text.isEmpty() )
114 if ( url.isLocalFile() )
115 item->text = url.path( myMode );
117 item->text = url.prettyURL( myMode );
121 defaultList.append( item );
131 for (
unsigned int id = 0;
id < defaultList.count();
id++ ) {
132 item = defaultList.at(
id );
133 insertURLItem( item );
147 if (
urls.isEmpty() )
150 TQStringList::Iterator it =
urls.begin();
154 while ( it !=
urls.end() ) {
155 while (
urls.contains( *it ) > 1 ) {
156 it =
urls.remove( it );
165 int Overload =
urls.count() - myMaximum + defaultList.count();
166 while ( Overload > 0 ) {
167 urls.remove((remove == RemoveBottom) ?
urls.fromLast() :
urls.begin());
173 KURLComboItem *item = 0L;
176 while ( it !=
urls.end() ) {
177 if ( (*it).isEmpty() ) {
181 u = KURL::fromPathOrURL( *it );
184 if (u.isLocalFile() && !TQFile::exists(u.path())) {
189 item =
new KURLComboItem;
193 if ( u.isLocalFile() )
194 item->text = u.path( myMode );
198 insertURLItem( item );
199 itemList.append( item );
210 blockSignals(
true );
213 TQMap<int,const KURLComboItem*>::ConstIterator mit = itemMapper.begin();
214 TQString urlToInsert = url.url(-1);
215 while ( mit != itemMapper.end() ) {
216 if ( urlToInsert == mit.data()->url.url(-1) ) {
217 setCurrentItem( mit.key() );
219 if ( myMode == Directories )
220 updateItem( mit.data(), mit.key(), opendirPix );
222 blockSignals(
false );
232 itemList.removeLast();
238 TQPtrListIterator<KURLComboItem> it( itemList );
239 for( ; it.current(); ++it )
240 insertURLItem( it.current() );
242 KURLComboItem *item =
new KURLComboItem;
245 if ( url.isLocalFile() )
246 item->text = url.path( myMode );
248 item->text = url.prettyURL( myMode );
249 kdDebug(250) <<
"setURL: text=" << item->text << endl;
252 TQString text = item->text;
254 if ( myMode == Directories )
255 KComboBox::insertItem( opendirPix, text,
id );
257 KComboBox::insertItem( item->pixmap, text,
id );
258 itemMapper.insert(
id, item );
259 itemList.append( item );
261 setCurrentItem(
id );
263 blockSignals(
false );
267 void KURLComboBox::slotActivated(
int index )
269 const KURLComboItem *item = itemMapper[ index ];
278 void KURLComboBox::insertURLItem(
const KURLComboItem *item )
282 KComboBox::insertItem( item->pixmap, item->text,
id );
283 itemMapper.insert(
id, item );
291 if ( count() > myMaximum ) {
292 int oldCurrent = currentItem();
296 TQPtrListIterator<KURLComboItem> it( itemList );
297 int Overload = itemList.count() - myMaximum + defaultList.count();
298 for (
int i = 0; i <= Overload; i++ )
301 for( ; it.current(); ++it )
302 insertURLItem( it.current() );
305 if ( oldCurrent >= count() )
306 oldCurrent = count() -1;
307 setCurrentItem( oldCurrent );
315 TQMap<int,const KURLComboItem*>::ConstIterator mit = itemMapper.begin();
316 while ( mit != itemMapper.end() ) {
317 if ( url.url(-1) == mit.data()->url.url(-1) ) {
318 if ( !itemList.remove( mit.data() ) && checkDefaultURLs )
319 defaultList.remove( mit.data() );
324 blockSignals(
true );
326 TQPtrListIterator<KURLComboItem> it( itemList );
327 while ( it.current() ) {
328 insertURLItem( *it );
331 blockSignals(
false );
337 if ( myMode == Directories )
340 return KMimeType::pixmapForURL( url, 0, TDEIcon::Small );
347 int index,
const TQPixmap& pixmap )
354 item->url.isLocalFile() ? item->url.path( myMode ) :
355 item->url.prettyURL( myMode ),
359 changeItem( pixmap, item->text, index );
363 #include "kurlcombobox.moc"
void addDefaultURL(const KURL &url, const TQString &text=TQString::null)
Adds a url that will always be shown in the combobox, it can't be "rotated away".
OverLoadResolving
This Enumeration is used in setURL() to determine which items will be removed when the given list is ...
~KURLComboBox()
Destructs the combo box.
void setDefaults()
Clears all items and inserts the default urls into the combo.
void setURLs(TQStringList urls)
Inserts urls into the combobox below the "default urls" (see addDefaultURL).
void urlActivated(const KURL &url)
Emitted when an item was clicked at.
void setURL(const KURL &url)
Sets the current url.
TQStringList urls() const
Mode
This enum describes which kind of items is shown in the combo box.
void setMaxItems(int)
Sets how many items should be handled and displayed by the combobox.
void updateItem(const KURLComboItem *item, int index, const TQPixmap &pix)
Updates item with pixmap and sets the url instead of the text of the KURLComboItem.
KURLComboBox(Mode mode, TQWidget *parent=0, const char *name=0)
Constructs a KURLComboBox.
void removeURL(const KURL &url, bool checkDefaultURLs=true)
Removes any occurrence of url.
TQPixmap getPixmap(const KURL &url) const
Uses KMimeType::pixmapForURL() to return a proper pixmap for url.