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, TQT_SIGNAL( activated(
int )), TQT_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"