[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Support for animated icons (on mouseover)
From: David Faure <david () mandrakesoft ! com>
Date: 2002-01-18 14:16:43
[Download RAW message or body]
On Friday 18 January 2002 01:36, Dirk Mueller wrote:
> On Don, 17 Jan 2002, Waldo Bastian wrote:
>
> > I don't know the level of caching that QMovie does internally (e.g.
whether it
> > keeps decoded frames around).
>
> it does not.
>
> > If it does then caching might save you some CPU
> > cycles there but I doubt that it does. Better let the disk cache do its
work.
>
> yeah, but if you don't have it in the disk cache and heavy I/O going on
> it's looking jumpy. thats where caching the thing in iconview for some
> limited time is good.
I implemented the cache now - and checked with strace() that it didn't open
the folder.mng animation more than once. Having it cached in the iconview
saves a pointer in each iconview item anyway, which is a good memory saving.
Yes, the disk cache was working quite well, but it's indeed only performant on
a relatively idle machine.
The new patches attached implement all the requests I got:
* fixed bug with the Trash (KFileItem bug) + some KFileItem restructuring
(bitfield)
* moved movie to the iconview
* d pointer in kiconviewitem
* configuration option, with all the code needed for dynamic updates
* fixed a bug that made the previous patch break the
delayed-mimetype-determination
I don't think the movie takes much memory - does it ? If yes, discarding the
movie if unused after some time (how much?) should be implemented, that might
be the only missing thing now. Difficult choice - the usual memory vs speed
tradeoff.
Ok, it's not a very small patch anymore, but I have tested it quite
intensively now (including checking with strace to check the disk accesses).
The question of the default setting (on or off) remains - but in fact with
KPersonalizer the question is rather void: all that's needed is that someone
makes KPersonalizer save the value for animated icons depending on the level
of gimmicks selected (kdeglobals, [DesktopIcon], Animated=true or false).
Can someone take care of that ? I don't know KPersonalizer at all.
Ah, forgot to include the am_edit patch again, see previous mail ;)
--
David FAURE, david@mandrakesoft.com, faure@kde.org
http://people.mandrakesoft.com/~david, http://www.konqueror.org
KDE 3.0: Konquering the Desktops
["animated_icons_iconview.diff" (text/x-diff)]
Index: konq_iconview.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/iconview/konq_iconview.cc,v
retrieving revision 1.373
diff -u -p -r1.373 konq_iconview.cc
--- konq_iconview.cc 2002/01/16 10:30:43 1.373
+++ konq_iconview.cc 2002/01/18 14:09:55
@@ -663,7 +663,7 @@ void KonqKfmIconView::slotNewItems( cons
item->setKey( key );
- //kdDebug() << "KonqKfmIconView::slotNewItems " << _fileitem->url().url() << \
" " << _fileitem->mimeTypePtr()->name() << endl; + //kdDebug() << \
"KonqKfmIconView::slotNewItems " << (*it)->url().url() << " " << \
(*it)->mimeTypePtr()->name() << " mimetypeknown:" << (*it)->isMimeTypeKnown() << \
endl; if ( !(*it)->isMimeTypeKnown() )
m_mimeTypeResolver->m_lstPendingMimeIconItems.append( item );
@@ -742,11 +742,13 @@ void KonqKfmIconView::slotSelectionChang
void KonqKfmIconView::determineIcon( KFileIVI * item )
{
+ // kdDebug() << "KonqKfmIconView::determineIcon " << item->item()->name() << endl;
int oldSerial = item->pixmap()->serialNumber();
(void) item->item()->determineMimeType();
item->setIcon( iconSize(), item->state(), true, true );
+ item->setMouseOverAnimation( item->item()->iconName() );
}
void KonqKfmIconView::mimeTypeDeterminationFinished()
["animated_icons_kcontrol.diff" (text/x-diff)]
Index: icons.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/icons/icons.cpp,v
retrieving revision 1.16
diff -u -p -r1.16 icons.cpp
--- icons.cpp 2001/10/23 22:48:28 1.16
+++ icons.cpp 2002/01/18 13:59:48
@@ -89,13 +89,17 @@ KIconConfig::KIconConfig(QWidget *parent
mpDPCheck = new QCheckBox(i18n("Double-sized pixels"), m_pTab1);
connect(mpDPCheck, SIGNAL(toggled(bool)), SLOT(slotDPCheck(bool)));
- grid->addWidget(mpDPCheck, 1, 0, Qt::AlignLeft);
+ grid->addMultiCellWidget(mpDPCheck, 1, 1, 0, 1, Qt::AlignLeft);
mpAlphaBCheck = new QCheckBox(i18n("Blend alpha channel"), m_pTab1);
connect(mpAlphaBCheck, SIGNAL(toggled(bool)), SLOT(slotAlphaBCheck(bool)));
- grid->addWidget(mpAlphaBCheck, 2, 0, Qt::AlignLeft);
+ grid->addMultiCellWidget(mpAlphaBCheck, 2, 2, 0, 1, Qt::AlignLeft);
disableAlphaBlending = (QPixmap::defaultDepth()<=8);
+ mpAnimatedCheck = new QCheckBox(i18n("Animate icons"), m_pTab1);
+ connect(mpAnimatedCheck, SIGNAL(toggled(bool)), SLOT(slotAnimatedCheck(bool)));
+ grid->addMultiCellWidget(mpAnimatedCheck, 3, 3, 0, 1, Qt::AlignLeft);
+
top->activate();
init();
@@ -168,12 +172,17 @@ void KIconConfig::initDefaults()
mbDP[i] = false;
mbAlphaB[i] = false;
mbChanged[i] = true;
+ mbAnimated[i] = false;
mSizes[i] = mpTheme->defaultSize(i);
mEffects[i][0] = mDefaultEffect[0];
mEffects[i][1] = mDefaultEffect[1];
mEffects[i][2] = mDefaultEffect[2];
}
+ // Animate desktop icons by default
+ int group = mGroups.findIndex( "Desktop" );
+ if ( group != -1 )
+ mbAnimated[group] = true;
// This is the new default in KDE 2.2, in sync with the kiconeffect of kdelibs Nolden 2001/06/11
int activeState = mStates.findIndex( "Active" );
@@ -215,6 +224,7 @@ void KIconConfig::read()
mSizes[i] = mpConfig->readNumEntry("Size", mSizes[i]);
mbDP[i] = mpConfig->readBoolEntry("DoublePixels", mbDP[i]);
mbAlphaB[i] = mpConfig->readBoolEntry("AlphaBlending", mbAlphaB[i]);
+ mbAnimated[i] = mpConfig->readBoolEntry("Animated", mbAnimated[i]);
for (it2=mStates.begin(), j=0; it2!=mStates.end(); it2++, j++)
{
@@ -264,6 +274,7 @@ void KIconConfig::apply()
}
mpDPCheck->setChecked(mbDP[mUsage]);
mpAlphaBCheck->setChecked(mbAlphaB[mUsage]);
+ mpAnimatedCheck->setChecked(mbAnimated[mUsage]);
}
void KIconConfig::preview(int i)
@@ -313,6 +324,7 @@ void KIconConfig::save()
mpConfig->writeEntry("Size", mSizes[i], true, true);
mpConfig->writeEntry("DoublePixels", mbDP[i], true, true);
mpConfig->writeEntry("AlphaBlending", mbAlphaB[i], true, true);
+ mpConfig->writeEntry("Animated", mbAnimated[i], true, true);
for (it2=mStates.begin(), j=0; it2!=mStates.end(); it2++, j++)
{
QString tmp;
@@ -373,13 +385,15 @@ void KIconConfig::slotUsage(int index)
mpDPCheck->setEnabled(false);
if (!disableAlphaBlending)
mpAlphaBCheck->setEnabled(true);
+ mpAnimatedCheck->setEnabled(false);
}
else
{
mpSizeBox->setEnabled(true);
mpDPCheck->setEnabled(true);
if (!disableAlphaBlending)
- mpAlphaBCheck->setEnabled( (mUsage==KIcon::Desktop)? true : false);
+ mpAlphaBCheck->setEnabled( mUsage==KIcon::Desktop );
+ mpAnimatedCheck->setEnabled( mUsage==KIcon::Desktop );
}
if (disableAlphaBlending)
mpAlphaBCheck->setEnabled(false);
@@ -440,6 +454,13 @@ void KIconConfig::slotAlphaBCheck(bool c
// take effect when restarting KDE.
// preview();
+ emit changed(true);
+ mbChanged[mUsage] = true;
+}
+
+void KIconConfig::slotAnimatedCheck(bool check)
+{
+ mbAnimated[mUsage] = check;
emit changed(true);
mbChanged[mUsage] = true;
}
Index: icons.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/icons/icons.h,v
retrieving revision 1.6
diff -u -p -r1.6 icons.h
--- icons.h 2001/07/20 17:57:50 1.6
+++ icons.h 2002/01/18 13:59:48
@@ -75,6 +75,7 @@ private slots:
void slotSize(int index);
void slotDPCheck(bool check);
void slotAlphaBCheck(bool check);
+ void slotAnimatedCheck(bool check);
private:
void preview(int i);
@@ -86,7 +87,7 @@ private:
void apply();
- bool mbDP[6], mbAlphaB[6], mbChanged[6];
+ bool mbDP[6], mbAlphaB[6], mbChanged[6], mbAnimated[6];
int mSizes[6];
QValueList<int> mAvSizes[6];
@@ -107,7 +108,7 @@ private:
QListBox *mpUsageList;
QComboBox *mpSizeBox;
- QCheckBox *mpDPCheck, *wordWrapCB, *underlineCB, *mpAlphaBCheck;
+ QCheckBox *mpDPCheck, *wordWrapCB, *underlineCB, *mpAlphaBCheck, *mpAnimatedCheck;
bool disableAlphaBlending;
QTabWidget *m_pTabWidget;
QWidget *m_pTab1;
["animated_icons_kdelibs.diff" (text/x-diff)]
Index: kiconview.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kiconview.cpp,v
retrieving revision 1.50
diff -u -p -r1.50 kiconview.cpp
--- kiconview.cpp 2001/12/10 23:10:28 1.50
+++ kiconview.cpp 2002/01/18 14:08:54
@@ -19,6 +19,7 @@
#include <qpainter.h>
#include <qpixmapcache.h>
#include <qcleanuphandler.h>
+#include <qmovie.h>
#include "kiconview.h"
#include "kwordwrap.h"
@@ -31,6 +32,8 @@
#include <kcursor.h>
#include <kpixmap.h>
#include <kpixmapeffect.h>
+#include <kicontheme.h>
+#include <kiconloader.h>
#ifdef Q_WS_X11
#include <X11/Xlib.h>
@@ -41,11 +44,16 @@ class KIconView::KIconViewPrivate
public:
KIconViewPrivate() {
mode = KIconView::Execute;
- doAutoSelect = TRUE;
+ doAutoSelect = true;
+ doAnimations = true;
fm = 0L;
+ m_movie = 0L;
}
KIconView::Mode mode;
bool doAutoSelect;
+ bool doAnimations;
+ QMovie* m_movie;
+ QString movieFileName;
QFontMetrics *fm;
QPixmapCache maskCache;
};
@@ -60,8 +68,11 @@ KIconView::KIconView( QWidget *parent, c
connect( this, SIGNAL( onItem( QIconViewItem * ) ),
this, SLOT( slotOnItem( QIconViewItem * ) ) );
slotSettingsChanged( KApplication::SETTINGS_MOUSE );
+ slotIconChanged( KIcon::Desktop );
connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) \
); + connect( kapp, SIGNAL( iconChanged(int) ), SLOT( slotIconChanged(int) ) );
kapp->addKipcEventMask( KIPC::SettingsChanged );
+ kapp->addKipcEventMask( KIPC::IconChanged );
m_pCurrentItem = 0L;
@@ -72,6 +83,7 @@ KIconView::KIconView( QWidget *parent, c
KIconView::~KIconView()
{
+ delete d->m_movie;
delete d->fm;
delete d;
}
@@ -89,24 +101,72 @@ KIconView::Mode KIconView::mode() const
void KIconView::slotOnItem( QIconViewItem *item )
{
- if ( item && m_bChangeCursorOverItem && m_bUseSingle )
- viewport()->setCursor( KCursor().handCursor() );
+ if ( item ) {
+ if ( m_bUseSingle ) {
+ if ( m_bChangeCursorOverItem )
+ viewport()->setCursor( KCursor().handCursor() );
- if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
- m_pAutoSelect->start( m_autoSelectDelay, true );
- m_pCurrentItem = item;
+ if ( (m_autoSelectDelay > -1) ) {
+ m_pAutoSelect->start( m_autoSelectDelay, true );
+ }
+ }
+ if ( d->doAnimations && m_pCurrentItem != item ) {
+ KIconViewItem *kivi = dynamic_cast<KIconViewItem *>( item );
+ if ( kivi && kivi->hasAnimation() )
+ {
+ // Check if cached movie can be used
+ if ( d->m_movie && d->movieFileName == kivi->mouseOverAnimation() )
+ {
+ d->m_movie->restart();
+ }
+ else
+ {
+ // If the file can't be loaded (e.g. no mng support), the movie \
will + // simply never call updatePixmap, so no problem.
+ QMovie movie = KGlobal::iconLoader()->loadMovie( \
kivi->mouseOverAnimation(), KIcon::Desktop, kivi->iconSize() ); + \
if ( !movie.isNull() ) + {
+ delete d->m_movie;
+ d->m_movie = new QMovie( movie ); // shallow copy, don't \
worry + d->m_movie->connectUpdate( this, SLOT( \
slotMovieUpdate() ) ); + d->movieFileName = \
kivi->mouseOverAnimation(); + }
+ else
+ {
+ // No movie available, remember it
+ kivi->setMouseOverAnimation( QString::null );
+ }
+ }
+ }
+ }
+ m_pCurrentItem = item;
}
}
void KIconView::slotOnViewport()
{
- if ( m_bChangeCursorOverItem )
+ if ( m_bUseSingle && m_bChangeCursorOverItem )
viewport()->unsetCursor();
+ if ( m_pCurrentItem && d->doAnimations && d->m_movie ) {
+ d->m_movie->pause();
+ //delete d->m_movie;
+ //d->m_movie = 0L;
+ // TODO a timer to delete the movie after some time if unused?
+ }
m_pAutoSelect->stop();
m_pCurrentItem = 0L;
}
+void KIconView::slotMovieUpdate()
+{
+ Q_ASSERT( d );
+ Q_ASSERT( d->m_movie );
+ KIconViewItem *kivi = dynamic_cast<KIconViewItem *>( m_pCurrentItem );
+ if ( kivi && d->m_movie ) // seems stopAnimation triggers one last update
+ kivi->setPixmap( d->m_movie->framePixmap() );
+}
+
void KIconView::slotSettingsChanged(int category)
{
if ( category != KApplication::SETTINGS_MOUSE )
@@ -143,6 +203,14 @@ void KIconView::slotSettingsChanged(int
viewport()->unsetCursor();
}
+void KIconView::slotIconChanged( int group )
+{
+ if ( group != KIcon::Desktop )
+ return;
+ KConfigGroup cfgGroup( KGlobal::config(), "DesktopIcons" );
+ d->doAnimations = cfgGroup.readBoolEntry( "Animated", true /*default*/ );
+}
+
void KIconView::slotAutoSelect()
{
// check that the item still exists
@@ -340,15 +408,24 @@ QPixmap KIconView::selectedIconPixmap( Q
/////////////
+struct KIconViewItem::KIconViewItemPrivate
+{
+ QString m_animatedIcon;
+ // Warning: if you add anything here, remove the "create d on demand
+ // and delete d in setMouseOverAnimation(QString::null)" code
+};
+
void KIconViewItem::init()
{
m_wordWrap = 0L;
+ d = 0L; // currently created on demand
calcRect();
}
KIconViewItem::~KIconViewItem()
{
delete m_wordWrap;
+ delete d;
}
void KIconViewItem::calcRect( const QString& text_ )
@@ -556,6 +633,32 @@ void KIconViewItem::paintItem( QPainter
m_wordWrap->drawText( p, textX, textY, align );
p->restore();
+}
+
+bool KIconViewItem::hasAnimation() const
+{
+ return d && !d->m_animatedIcon.isEmpty();
+}
+
+void KIconViewItem::setMouseOverAnimation( const QString& movieFileName )
+{
+ if ( movieFileName.isEmpty() ) {
+ // Only valid because we have nothing else in 'd'
+ delete d;
+ d = 0L;
+ } else {
+ if (!d)
+ d = new KIconViewItemPrivate;
+ //kdDebug() << "KIconViewItem::setMouseOverAnimation " << movieFileName << \
endl; + d->m_animatedIcon = movieFileName;
+ }
+}
+
+QString KIconViewItem::mouseOverAnimation() const
+{
+ if (!d)
+ return QString::null;
+ return d->m_animatedIcon;
}
#include "kiconview.moc"
Index: kiconview.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kiconview.h,v
retrieving revision 1.28
diff -u -p -r1.28 kiconview.h
--- kiconview.h 2001/12/10 23:10:28 1.28
+++ kiconview.h 2002/01/18 14:08:54
@@ -117,8 +117,9 @@ signals:
protected slots:
void slotOnItem( QIconViewItem *item );
void slotOnViewport();
-
+ void slotMovieUpdate();
void slotSettingsChanged(int);
+ void slotIconChanged( int );
/**
* Auto selection happend.
@@ -134,14 +135,6 @@ protected:
virtual void contentsMouseDoubleClickEvent ( QMouseEvent * e );
virtual void contentsMouseReleaseEvent( QMouseEvent *e );
- bool m_bUseSingle;
- bool m_bChangeCursorOverItem;
-
- QIconViewItem* m_pCurrentItem;
-
- QTimer* m_pAutoSelect;
- int m_autoSelectDelay;
-
private slots:
void slotMouseButtonClicked( int btn, QIconViewItem *item, const QPoint &pos );
@@ -155,6 +148,14 @@ private:
*/
QPixmap selectedIconPixmap( QPixmap *pix, const QColor &col ) const;
+ bool m_bUseSingle;
+ bool m_bChangeCursorOverItem;
+
+ QIconViewItem* m_pCurrentItem;
+
+ QTimer* m_pAutoSelect;
+ int m_autoSelectDelay;
+
class KIconViewPrivate;
KIconViewPrivate *d;
};
@@ -164,6 +165,8 @@ class KWordWrap;
* KIconViewItem exists to improve the word-wrap functionality of QIconViewItem
* Use KIconViewItem instead of QIconViewItem for any iconview item you might have \
:)
*
+ * This class also provides support for animated icons.
+ *
* @short A variant of QIconViewItem that wraps words better.
* @author David Faure <david@mandrakesoft.com>
*/
@@ -188,12 +191,36 @@ public:
KIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text, \
const QPicture &picture ) : QIconViewItem( parent, after, text, picture ) { init(); \
} virtual ~KIconViewItem();
+
+ /**
+ * Return the theorical size in pixels, if setSize() was called.
+ * 0 means the globally configured default size.
+ */
+ int iconSize() const { return m_size; }
+
+ /**
+ * Enable an animation on mouseover, if there is an available mng.
+ * @param movieFileName the base name for the mng, e.g. "folder".
+ * Nothing happens if there is no animation available.
+ */
+ void setMouseOverAnimation( const QString& movieFileName );
+ QString mouseOverAnimation() const;
+ bool hasAnimation() const;
+
protected:
+ /**
+ * Set the theorical size in pixels - this is only useful for derived classes
+ */
+ void setIconSize( int size ) { m_size = size; }
+
void init();
virtual void calcRect( const QString& text_ = QString::null );
virtual void paintItem( QPainter *p, const QColorGroup &c );
private:
+ int m_size; // theorical size in pixels. Zero means the globally configured \
default size. KWordWrap* m_wordWrap;
+ class KIconViewItemPrivate;
+ KIconViewItemPrivate* d;
};
#endif
["animated_icons_libkonq.diff" (text/x-diff)]
Index: kfileivi.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/kfileivi.cc,v
retrieving revision 1.63
diff -u -p -r1.63 kfileivi.cc
--- kfileivi.cc 2002/01/10 14:46:47 1.63
+++ kfileivi.cc 2002/01/18 14:00:03
@@ -26,6 +26,7 @@
#include <kurldrag.h>
#include <kiconeffect.h>
#include <kfileitem.h>
+#include <kdebug.h>
#undef Bool
@@ -43,15 +44,20 @@ struct KFileIVI::Private
KFileIVI::KFileIVI( KonqIconViewWidget *iconview, KFileItem* fileitem, int size )
: KIconViewItem( iconview, fileitem->text(),
fileitem->pixmap( size, KIcon::DefaultState ) ),
- m_size(size), m_state( KIcon::DefaultState ),
+ m_state( KIcon::DefaultState ),
m_bDisabled( false ), m_bThumbnail( false ), m_fileitem( fileitem )
{
+ setIconSize( size );
setDropEnabled( S_ISDIR( m_fileitem->mode() ) );
d = new KFileIVI::Private;
// Cache entry for the icon effects
d->icons.reset( *pixmap(), QIconSet::Large );
d->state = KIcon::DefaultState;
+
+ // iconName() requires the mimetype to be known
+ if ( fileitem->isMimeTypeKnown() )
+ setMouseOverAnimation( fileitem->iconName() );
}
KFileIVI::~KFileIVI()
@@ -87,7 +93,7 @@ void KFileIVI::invalidateThumb( int stat
void KFileIVI::setIcon( int size, int state, bool recalc, bool redraw )
{
- m_size = size;
+ setIconSize( size );
m_bThumbnail = false;
if ( m_bDisabled )
m_state = KIcon::DisabledState;
@@ -113,7 +119,7 @@ void KFileIVI::setIcon( int size, int st
// called with any state and not just normal state. So we just
// create a dummy empty iconset as base object.
d->icons = QIconSet();
- d->icons.setPixmap( m_fileitem->pixmap( m_size, m_state ),
+ d->icons.setPixmap( m_fileitem->pixmap( iconSize(), m_state ),
QIconSet::Large, mode );
d->state = m_state;
QIconViewItem::setPixmap( d->icons.pixmap( QIconSet::Large, mode ),
@@ -126,7 +132,7 @@ void KFileIVI::setDisabled( bool disable
{
m_bDisabled = disabled;
m_state = m_bDisabled ? KIcon::DisabledState : KIcon::DefaultState;
- QIconViewItem::setPixmap( m_fileitem->pixmap( m_size, m_state ), false, true );
+ QIconViewItem::setPixmap( m_fileitem->pixmap( iconSize(), m_state ), false, true );
}
}
@@ -186,7 +192,7 @@ void KFileIVI::setEffect( int group, int
else
{
if( d->icons.isGenerated( QIconSet::Large, mode ) )
- d->icons.setPixmap( m_fileitem->pixmap( m_size, state ),
+ d->icons.setPixmap( m_fileitem->pixmap( iconSize(), state ),
QIconSet::Large, mode );
}
QIconViewItem::setPixmap( d->icons.pixmap( QIconSet::Large, mode ) );
@@ -197,7 +203,7 @@ void KFileIVI::setEffect( int group, int
void KFileIVI::refreshIcon( bool redraw )
{
if ( !isThumbnail())
- setIcon( m_size, m_state, true, redraw );
+ setIcon( iconSize(), m_state, true, redraw );
}
bool KFileIVI::acceptDrop( const QMimeSource *mime ) const
Index: kfileivi.h
===================================================================
RCS file: /home/kde/kdebase/libkonq/kfileivi.h,v
retrieving revision 1.41
diff -u -p -r1.41 kfileivi.h
--- kfileivi.h 2002/01/10 14:46:47 1.41
+++ kfileivi.h 2002/01/18 14:00:03
@@ -138,7 +138,7 @@ private:
virtual void setPixmap ( const QPixmap & icon ) { KIconViewItem::setPixmap( icon ); }
virtual void setPixmap ( const QPixmap & icon, bool recalc, bool redraw = TRUE )
{ KIconViewItem::setPixmap( icon, recalc, redraw ); }
- int m_size, m_state;
+ int m_state;
bool m_bDisabled;
bool m_bThumbnail;
/** Pointer to the file item in KDirLister's list */
["animated_icons_kfileitem.diff" (text/x-diff)]
Index: kfileitem.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kfileitem.cpp,v
retrieving revision 1.112
diff -u -p -r1.112 kfileitem.cpp
--- kfileitem.cpp 2002/01/18 03:24:04 1.112
+++ kfileitem.cpp 2002/01/18 14:10:12
@@ -47,14 +47,12 @@ class KFileItem::KFileItemPrivate
{
public:
KFileItemPrivate() {
- bMimeTypeKnown = false;
refresh();
}
void operator=( const KFileItemPrivate& d ) {
guessedMimeType = d.guessedMimeType;
access = d.access;
- bMimeTypeKnown = d.bMimeTypeKnown;
for ( int i = 0; i < NumFlags; i++ )
time[i] = d.time[i];
size = d.size;
@@ -72,7 +70,6 @@ public:
// For special case like link to dirs over FTP
QString guessedMimeType;
QString access;
- bool bMimeTypeKnown;
QMap<const void*, void*> extra;
KFileMetaInfo metaInfo;
@@ -85,12 +82,13 @@ KFileItem::KFileItem( const KIO::UDSEntr
bool _determineMimeTypeOnDemand, bool _urlIsDirectory ) :
m_entry( _entry ),
m_url( _url ),
- m_bIsLocalURL( _url.isLocalFile() ),
+ m_pMimeType( 0 ),
m_fileMode( (mode_t)-1 ),
m_permissions( (mode_t)-1 ),
- m_bLink( false ),
- m_pMimeType( 0 ),
m_bMarked( false ),
+ m_bLink( false ),
+ m_bIsLocalURL( _url.isLocalFile() ),
+ m_bMimeTypeKnown( false ),
d(new KFileItemPrivate)
{
bool UDS_URL_seen = false;
@@ -127,7 +125,7 @@ KFileItem::KFileItem( const KIO::UDSEntr
case KIO::UDS_MIME_TYPE:
m_pMimeType = KMimeType::mimeType((*it).m_str);
- d->bMimeTypeKnown = true;
+ m_bMimeTypeKnown = true;
break;
case KIO::UDS_GUESSED_MIME_TYPE:
@@ -149,13 +147,14 @@ KFileItem::KFileItem( const KIO::UDSEntr
KFileItem::KFileItem( mode_t _mode, mode_t _permissions, const KURL& _url, bool \
_determineMimeTypeOnDemand ) : m_entry(), // warning !
m_url( _url ),
- m_bIsLocalURL( _url.isLocalFile() ),
m_strName( _url.fileName() ),
m_strText( KIO::decodeFileName( m_strName ) ),
m_fileMode ( _mode ),
m_permissions( _permissions ),
- m_bLink( false ),
m_bMarked( false ),
+ m_bLink( false ),
+ m_bIsLocalURL( _url.isLocalFile() ),
+ m_bMimeTypeKnown( false ),
d(new KFileItemPrivate)
{
init( _determineMimeTypeOnDemand );
@@ -163,13 +162,14 @@ KFileItem::KFileItem( mode_t _mode, mode
KFileItem::KFileItem( const KURL &url, const QString &mimeType, mode_t mode )
: m_url( url ),
- m_bIsLocalURL( url.isLocalFile() ),
m_strName( url.fileName() ),
m_strText( KIO::decodeFileName( m_strName ) ),
m_fileMode( mode ),
m_permissions( 0 ),
- m_bLink( false ),
m_bMarked( false ),
+ m_bLink( false ),
+ m_bIsLocalURL( url.isLocalFile() ),
+ m_bMimeTypeKnown( false ),
d(new KFileItemPrivate)
{
m_pMimeType = KMimeType::mimeType( mimeType );
@@ -231,7 +231,7 @@ void KFileItem::init( bool _determineMim
_determineMimeTypeOnDemand );
// if we didn't use fast mode, or if we got a result, then this is the \
mimetype // otherwise, determineMimeType will be able to do better.
- d->bMimeTypeKnown = (!_determineMimeTypeOnDemand) || (m_pMimeType->name() != \
KMimeType::defaultMimeType()); + m_bMimeTypeKnown = \
(!_determineMimeTypeOnDemand) || (m_pMimeType->name() != \
KMimeType::defaultMimeType()); }
}
@@ -391,11 +391,11 @@ QString KFileItem::mimetype() const
KMimeType::Ptr KFileItem::determineMimeType()
{
- if ( !m_pMimeType || !d->bMimeTypeKnown )
+ if ( !m_pMimeType || !m_bMimeTypeKnown )
{
- //kdDebug(1203) << "finding mimetype for " << m_url.url() << endl;
m_pMimeType = KMimeType::findByURL( m_url, m_fileMode, m_bIsLocalURL );
- d->bMimeTypeKnown = true;
+ kdDebug(1203) << "finding mimetype for " << m_url.url() << ":" << \
m_pMimeType->name() << endl; + m_bMimeTypeKnown = true;
}
return m_pMimeType;
@@ -406,13 +406,13 @@ bool KFileItem::isMimeTypeKnown() const
// The mimetype isn't known if determineMimeType was never called (on-demand \
determination) // or if this fileitem has a guessed mimetype (e.g. ftp symlink) - in \
which case // it always remains "not fully determined"
- return d->bMimeTypeKnown && d->guessedMimeType.isEmpty();
+ return m_bMimeTypeKnown && d->guessedMimeType.isEmpty();
}
QString KFileItem::mimeComment()
{
KMimeType::Ptr mType = determineMimeType();
- QString comment = mType->comment( m_url, false );
+ QString comment = mType->comment( m_url, m_bIsLocalURL );
if (!comment.isEmpty())
return comment;
else
@@ -421,7 +421,7 @@ QString KFileItem::mimeComment()
QString KFileItem::iconName()
{
- return determineMimeType()->icon(m_url, false);
+ return determineMimeType()->icon(m_url, m_bIsLocalURL);
}
QPixmap KFileItem::pixmap( int _size, int _state ) const
@@ -448,7 +448,7 @@ QPixmap KFileItem::pixmap( int _size, in
KMimeType::Ptr mime;
// Use guessed mimetype if the main one hasn't been determined for sure
- if ( !d->bMimeTypeKnown && !d->guessedMimeType.isEmpty() )
+ if ( !m_bMimeTypeKnown && !d->guessedMimeType.isEmpty() )
mime = KMimeType::mimeType( d->guessedMimeType );
else
mime = m_pMimeType;
@@ -462,6 +462,7 @@ QPixmap KFileItem::pixmap( int _size, in
_state |= KIcon::ZipOverlay;
}
+ kdDebug(1203) << "KFileItem::pixmap using mime " << mime->name() << endl;
QPixmap p = mime->pixmap( m_url, KIcon::Desktop, _size, _state );
if (p.isNull())
kdWarning() << "Pixmap not found for mimetype " << m_pMimeType->name() << \
endl; @@ -492,7 +493,7 @@ bool KFileItem::isReadable() const
bool KFileItem::isDir() const
{
- if ( !d->bMimeTypeKnown && !d->guessedMimeType.isEmpty() )
+ if ( !m_bMimeTypeKnown && !d->guessedMimeType.isEmpty() )
{
kdDebug() << " KFileItem::isDir can't say -> false " << endl;
return false; // can't say for sure, so no
@@ -527,7 +528,7 @@ bool KFileItem::acceptsDrops()
QString KFileItem::getStatusBarInfo()
{
- QString comment = determineMimeType()->comment( m_url, false );
+ QString comment = determineMimeType()->comment( m_url, m_bIsLocalURL );
QString text = m_strText;
// Extract from the KIO::UDSEntry the additional info we didn't get previously
QString myLinkDest = linkDest();
@@ -582,7 +583,7 @@ QString KFileItem::getToolTipText(int ma
}
QStringList keys;
-
+
tip = "<table cellspacing=0 cellpadding=0>"
"<tr>"
"<th colspan=2>"
@@ -665,7 +666,7 @@ QString KFileItem::getToolTipText(int ma
s = value.toString();
break;
}
-
+
if ( !s.isEmpty() )
{
count++;
@@ -724,6 +725,7 @@ void KFileItem::assign( const KFileItem
m_bLink = item.m_bLink;
m_pMimeType = item.m_pMimeType;
m_strLowerCaseName = item.m_strLowerCaseName;
+ m_bMimeTypeKnown = item.m_bMimeTypeKnown;
*d = *item.d; // Note: d->extra is just a shallow copy...
// We had a mimetype previously (probably), so we need to re-determine it
determineMimeType();
Index: kfileitem.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kfileitem.h,v
retrieving revision 1.73
diff -u -p -r1.73 kfileitem.h
--- kfileitem.h 2002/01/18 03:24:04 1.73
+++ kfileitem.h 2002/01/18 14:10:12
@@ -259,7 +259,7 @@ public:
* e.g. when the mouse is over this item
*/
QString getStatusBarInfo();
-
+
/**
* @param maxcount the maximum number of entries shown
*
@@ -282,20 +282,6 @@ public:
*/
void run();
- /*
- * Gives the file a "hidden" flag, so that a view doesn't show it.
- * E.g. a filefilter sets this flag if this item matches *.cpp or not.
- * @see #isHidden
- */
- // void setHidden( bool b ) { m_bHidden = b; }
-
- /*
- * @returns this item's hidden flag. True if a view shall not show it, false
- * otherwise.
- * @see #setHidden
- */
- // bool isHidden() const { return m_bHidden; }
-
/**
* Returns the UDS entry. Used by the tree view to access all details
* by position.
@@ -391,6 +377,7 @@ protected:
*/
QString parsePermissions( mode_t perm ) const;
+private:
/**
* We keep a copy of the UDSEntry since we need it for @ref #getStatusBarInfo
*/
@@ -399,29 +386,17 @@ protected:
* The url of the file
*/
KURL m_url;
- /**
- * True if local file
- */
- bool m_bIsLocalURL;
/**
* The text for this item, i.e. the file name without path,
*/
QString m_strName;
- /**
- * The text for this item, i.e. the file name without path, encoded
- */
- QString m_strText;
-
/**
- * The file mode
+ * The text for this item, i.e. the file name without path, decoded
+ * ('%%' becomes '%', '%2F' becomes '/')
*/
- mode_t m_fileMode;
- /**
- * The permissions
- */
- mode_t m_permissions;
+ QString m_strText;
/**
* the user and group assigned to the file.
@@ -429,29 +404,38 @@ protected:
mutable QString m_user, m_group;
/**
- * Whether the file is a link
+ * The filename in lower case (to speed up sorting)
*/
- bool m_bLink;
+ mutable QString m_strLowerCaseName;
+
/**
* The mimetype of the file
*/
KMimeType::Ptr m_pMimeType;
/**
- * The filename in lower case (to speed up sorting)
+ * The file mode
*/
- mutable QString m_strLowerCaseName;
+ mode_t m_fileMode;
+ /**
+ * The permissions
+ */
+ mode_t m_permissions;
-private:
/**
* Marked : see @ref #mark()
*/
- bool m_bMarked;
-
+ bool m_bMarked:1;
/**
- * Hidden : see @ref #setHidden(), @ref #isHidden()
+ * Whether the file is a link
*/
- // bool m_bHidden;
+ bool m_bLink:1;
+ /**
+ * True if local file
+ */
+ bool m_bIsLocalURL:1;
+
+ bool m_bMimeTypeKnown:1;
class KFileItemPrivate;
KFileItemPrivate * d;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic