20 #include "tdefileivi.h"
21 #include "kivdirectoryoverlay.h"
22 #include "kivfreespaceoverlay.h"
23 #include "konq_iconviewwidget.h"
24 #include "konq_operations.h"
25 #include "konq_settings.h"
27 #include <tqpainter.h>
30 #include <kiconeffect.h>
31 #include <tdefileitem.h>
35 #include <kmimetype.h>
36 #include <kstandarddirs.h>
43 struct KFileIVI::Private
48 TQString m_animatedIcon;
50 KIVDirectoryOverlay* m_directoryOverlay;
51 KIVFreeSpaceOverlay* m_freeSpaceOverlay;
53 TQString m_overlayName;
58 : TDEIconViewItem( iconview, fileitem->text() ),
59 m_size( size ), m_state( TDEIcon::DefaultState ),
60 m_bDisabled( false ), m_bThumbnail( false ), m_fileitem( fileitem )
62 d =
new KFileIVI::Private;
65 setPixmap( m_fileitem->pixmap( m_size, m_state ) );
66 setDropEnabled( S_ISDIR( m_fileitem->mode() ) );
69 d->icons.reset( *pixmap(), TQIconSet::Large );
70 d->m_animated =
false;
73 if ( fileitem->isMimeTypeKnown() )
75 TQString icon = fileitem->iconName();
76 if ( !icon.isEmpty() )
82 d->m_directoryOverlay = 0;
83 d->m_freeSpaceOverlay = 0;
88 delete d->m_directoryOverlay;
89 delete d->m_freeSpaceOverlay;
98 case TDEIcon::DisabledState:
99 mode = TQIconSet::Disabled;
101 case TDEIcon::ActiveState:
102 mode = TQIconSet::Active;
104 case TDEIcon::DefaultState:
106 mode = TQIconSet::Normal;
109 d->icons = TQIconSet();
110 d->icons.setPixmap( TDEGlobal::iconLoader()->iconEffect()->
111 apply( d->thumb, TDEIcon::Desktop,
state ),
112 TQIconSet::Large, mode );
115 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ),
122 m_bThumbnail =
false;
124 m_state = TDEIcon::DisabledState;
128 if ( d->m_overlayName.isNull() )
129 d->m_overlay = TQPixmap();
133 halfSize = IconSize(TDEIcon::Desktop) / 2;
135 halfSize = m_size / 2;
137 d->m_overlay = DesktopIcon(d->m_overlayName, halfSize);
140 setPixmapDirect(m_fileitem->pixmap( m_size, m_state ) , recalc, redraw );
145 d->m_overlayName = iconName;
152 d->m_progress = progress;
159 if ( !m_fileitem->isDir() || m_fileitem->iconName() !=
"folder" )
163 if (!d->m_directoryOverlay)
164 d->m_directoryOverlay =
new KIVDirectoryOverlay(
this);
165 return d->m_directoryOverlay;
167 delete d->m_directoryOverlay;
168 d->m_directoryOverlay = 0;
174 bool KFileIVI::showDirectoryOverlay( )
176 return (
bool)d->m_directoryOverlay;
181 if ( !m_fileitem->mimetype().startsWith(
"media/") ) {
186 if (!d->m_freeSpaceOverlay)
187 d->m_freeSpaceOverlay =
new KIVFreeSpaceOverlay(
this);
188 return d->m_freeSpaceOverlay;
190 delete d->m_freeSpaceOverlay;
191 d->m_freeSpaceOverlay = 0;
197 bool KFileIVI::showFreeSpaceOverlay( )
199 return (
bool)d->m_freeSpaceOverlay;
204 TQIconSet::Mode mode;
207 case TDEIcon::DisabledState:
208 mode = TQIconSet::Disabled;
210 case TDEIcon::ActiveState:
211 mode = TQIconSet::Active;
213 case TDEIcon::DefaultState:
215 mode = TQIconSet::Normal;
222 d->icons = TQIconSet();
223 d->icons.setPixmap( pixmap, TQIconSet::Large, mode );
226 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ),
232 if ( m_bDisabled != disabled )
234 m_bDisabled = disabled;
235 bool active = ( m_state == TDEIcon::ActiveState );
236 setEffect( m_bDisabled ? TDEIcon::DisabledState :
237 ( active ? TDEIcon::ActiveState : TDEIcon::DefaultState ) );
247 d->icons = TQIconSet();
248 d->icons.setPixmap( TDEGlobal::iconLoader()->iconEffect()->
249 apply( pixmap, TDEIcon::Desktop, TDEIcon::DefaultState ),
250 TQIconSet::Large, TQIconSet::Normal );
252 m_state = TDEIcon::DefaultState;
256 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large,
257 TQIconSet::Normal ),
true );
265 setEffect( m_bDisabled ? TDEIcon::DisabledState : TDEIcon::DefaultState );
270 TQIconSet::Mode mode;
273 case TDEIcon::DisabledState:
274 mode = TQIconSet::Disabled;
276 case TDEIcon::ActiveState:
277 mode = TQIconSet::Active;
279 case TDEIcon::DefaultState:
281 mode = TQIconSet::Normal;
286 TDEIconEffect *effect = TDEGlobal::iconLoader()->iconEffect();
288 bool haveEffect = effect->hasEffect( TDEIcon::Desktop, m_state ) !=
289 effect->hasEffect( TDEIcon::Desktop,
state );
299 effect->fingerprint( TDEIcon::Desktop, m_state ) !=
300 effect->fingerprint( TDEIcon::Desktop,
state ) )
306 if( d->icons.isGenerated( TQIconSet::Large, mode ) )
307 d->icons.setPixmap( effect->apply( d->thumb, TDEIcon::Desktop,
state ),
308 TQIconSet::Large, mode );
312 if( d->icons.isGenerated( TQIconSet::Large, mode ) )
313 d->icons.setPixmap( m_fileitem->pixmap( m_size,
state ),
314 TQIconSet::Large, mode );
316 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ) );
324 setIcon( m_size, m_state,
true, redraw );
330 d->thumb = TQPixmap();
333 bool KFileIVI::isThumbnailInvalid()
const
335 return d->thumb.isNull();
340 if ( mime->provides(
"text/uri-list" ) )
342 if ( m_fileitem->acceptsDrops() )
350 KURL::List::Iterator it = uris.begin();
351 for ( ; it != uris.end() ; it++ )
353 if ( m_fileitem->url().equals( *it,
true ) )
357 return TQIconViewItem::acceptDrop( mime );
360 void KFileIVI::setKey(
const TQString &key )
362 TQString theKey = key;
364 TQVariant sortDirProp = iconView()->property(
"sortDirectoriesFirst" );
366 bool isdir = ( S_ISDIR( m_fileitem->mode() ) && ( !sortDirProp.isValid() || ( sortDirProp.type() == TQVariant::Bool && sortDirProp.toBool() ) ) );
369 int sortChar = isdir ? 1 : 3;
370 if ( m_fileitem->text()[0] ==
'.' )
373 if ( !iconView()->sortDirection() )
374 sortChar = 3 - sortChar;
376 theKey.prepend( TQChar( sortChar +
'0' ) );
378 TQIconViewItem::setKey( theKey );
381 void KFileIVI::dropped( TQDropEvent *e,
const TQValueList<TQIconDragItem> & )
389 KURL url = m_fileitem->url();
390 if (url.protocol() ==
"media") {
391 TQString mimetype = m_fileitem->mimetype();
392 TQString lockingAction = TQString::null;
393 if (mimetype.contains(
"encrypted_locked")) {
394 lockingAction =
"konqueror/servicemenus/media_unlock.desktop";
396 else if (mimetype.contains(
"encrypted_unlocked")) {
397 lockingAction =
"konqueror/servicemenus/media_lock.desktop";
399 if (!lockingAction.isEmpty()) {
400 TQString lockingService = TDEGlobal::dirs()->findResource(
"data", lockingAction);
401 if (!lockingService.isEmpty()) {
402 TQValueList<KDEDesktopMimeType::Service> serviceList = KDEDesktopMimeType::userDefinedServices(lockingService, m_fileitem->isLocalFile());
403 if (serviceList.count() == 1) {
404 KURL::List m_lstURLs;
405 m_lstURLs.append(m_fileitem->url());
406 KDEDesktopMimeType::executeService(m_lstURLs, serviceList[0]);
411 (void)
new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
417 if ( m_fileitem->isLink() && url.isLocalFile() ) {
418 url = KURL( url, m_fileitem->linkDest() );
421 (void)
new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
444 TDEIconViewItem::paintItem( p, cg );
452 if ( !d->m_overlay.isNull() ) {
453 TQRect rect = pixmapRect(
true);
454 p->drawPixmap(x() + rect.x() , y() + pixmapRect().height() - d->m_overlay.height(), d->m_overlay);
460 if (d->m_progress != -1) {
491 TQRect rect = pixmapRect(
true);
492 int horizontalOffset = 0;
493 int usedBarHeight = (((100-d->m_progress)*pixmapRect().height())/100);
494 int endPosition = y() + rect.y() + usedBarHeight;
498 p->setPen(TQPen::NoPen);
499 p->setBrush(TQt::green);
500 p->drawRect(TQRect(x() + rect.x() + (pixmapRect().width() - horizontalOffset), y() + rect.y(), 1, usedBarHeight));
501 p->setBrush(TQt::red);
502 p->drawRect(TQRect(x() + rect.x() + (pixmapRect().width() - horizontalOffset), endPosition, 1, pixmapRect().height() - usedBarHeight));
510 if ( m_fileitem->isLink() )
512 TQFont f( p->font() );
520 TQColorGroup cg( c );
521 cg.setColor( TQColorGroup::Text,
static_cast<KonqIconViewWidget*
>(iconView())->itemColor() );
525 bool KFileIVI::move(
int x,
int y )
530 if ( x > iconView()->viewport()->width() - ( width() + 5 ) )
531 x = iconView()->viewport()->width() - ( width() + 5 );
534 if ( y > iconView()->viewport()->height() - ( height() + 5 ) )
535 y = iconView()->viewport()->height() - ( height() + 5 );
537 return TQIconViewItem::move( x, y );
542 return !d->m_animatedIcon.isEmpty() && !m_bThumbnail;
547 if ( !movieFileName.isEmpty() )
550 d->m_animatedIcon = movieFileName;
554 TQString KFileIVI::mouseOverAnimation()
const
556 return d->m_animatedIcon;
561 return d->m_animated;
564 void KFileIVI::setAnimated(
bool a )
569 int KFileIVI::compare( TQIconViewItem *i )
const
572 if ( view->caseInsensitiveSort() )
573 return key().localeAwareCompare( i->key() );
575 return view->m_pSettings->caseSensitiveCompare( key(), i->key() );
578 void KFileIVI::updatePixmapSize()
580 int size = m_size ? m_size :
581 TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
585 bool mimeDetermined =
false;
586 if ( m_fileitem->isMimeTypeKnown() ) {
587 mimeDetermined =
true;
590 if (mimeDetermined) {
591 bool changed =
false;
592 if ( view && view->canPreview(
item() ) ) {
593 int previewSize = view->previewIconSize( size );
594 if (previewSize != size) {
595 setPixmapSize( TQSize( previewSize, previewSize ) );
600 TQSize pixSize = TQSize( size, size );
601 if ( pixSize != pixmapSize() ) {
602 setPixmapSize( pixSize );
611 TQSize pixSize = TQSize( size, size );
612 if ( pixSize != pixmapSize() ) {
613 setPixmapSize( pixSize );
618 void KFileIVI::mimeTypeAndIconDetermined()