author | alwin <alwin> | 2004-11-10 21:18:37 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-11-10 21:18:37 (UTC) |
commit | 660b61a7f8b9fb885226507d7f6716ab2dcedbb8 (patch) (side-by-side diff) | |
tree | 5ebbfc6ca71b1a2205d5f2516b919c9c2dd4fced | |
parent | d2f3b6f525be4d652fbac7c87ab0ad40e21af184 (diff) | |
download | opie-660b61a7f8b9fb885226507d7f6716ab2dcedbb8.zip opie-660b61a7f8b9fb885226507d7f6716ab2dcedbb8.tar.gz opie-660b61a7f8b9fb885226507d7f6716ab2dcedbb8.tar.bz2 |
implemented icon cache so it will not scan every time when changing the
doctab categorie
ToDo: implement a cache flush
-rw-r--r-- | core/launcher/launcher.cpp | 43 | ||||
-rw-r--r-- | core/launcher/launcher.h | 4 | ||||
-rw-r--r-- | core/launcher/launcherview.cpp | 109 | ||||
-rw-r--r-- | core/launcher/launcherview.h | 7 |
4 files changed, 113 insertions, 50 deletions
diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp index 5ec1cf8..ccc2114 100644 --- a/core/launcher/launcher.cpp +++ b/core/launcher/launcher.cpp @@ -74,13 +74,13 @@ static bool isVisibleWindow( int ); //=========================================================================== LauncherTabWidget::LauncherTabWidget( Launcher* parent ) : - QVBox( parent ), docview( 0 ) + QVBox( parent ), docview( 0 ),docTabEnabled(true),m_DocumentTabId(0) { docLoadingWidgetEnabled = false; docLoadingWidget = 0; docLoadingWidgetProgress = 0; launcher = parent; categoryBar = new LauncherTabBar( this ); @@ -125,13 +125,13 @@ void LauncherTabWidget::createDocLoadingWidget() waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) ); waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) ); waitPixmap->setAlignment( int( QLabel::AlignCenter ) ); Config cfg( "Launcher" ); cfg.setGroup( "DocTab" ); - bool docTabEnabled = cfg.readBoolEntry( "Enable", true ); + docTabEnabled = cfg.readBoolEntry( "Enable", true ); QLabel *textLabel = new QLabel( docLoadingVBox ); textLabel->setAlignment( int( QLabel::AlignCenter ) ); docLoadingWidgetProgress = new QProgressBar( docLoadingVBox ); docLoadingWidgetProgress->setProgress( 0 ); docLoadingWidgetProgress->setCenterIndicator( TRUE ); @@ -166,67 +166,70 @@ void LauncherTabWidget::initLayout() categoryBar->showTab("Documents"); } void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&) { if ( message == "nextView()" ) - categoryBar->nextTab(); + categoryBar->nextTab(); } void LauncherTabWidget::raiseTabWidget() { if ( categoryBar->currentView() == docView() - && docLoadingWidgetEnabled ) { - stack->raiseWidget( docLoadingWidget ); - docLoadingWidget->updateGeometry(); + && docLoadingWidgetEnabled ) { + stack->raiseWidget( docLoadingWidget ); + docLoadingWidget->updateGeometry(); } else { - stack->raiseWidget( categoryBar->currentView() ); + stack->raiseWidget( categoryBar->currentView() ); } } void LauncherTabWidget::tabProperties() { LauncherView *view = categoryBar->currentView(); QPopupMenu *m = new QPopupMenu( this ); m->insertItem( tr("Icon View"), LauncherView::Icon ); m->insertItem( tr("List View"), LauncherView::List ); m->setItemChecked( (int)view->viewMode(), TRUE ); int rv = m->exec( QCursor::pos() ); if ( rv >= 0 && rv != view->viewMode() ) { - view->setViewMode( (LauncherView::ViewMode)rv ); + view->setViewMode( (LauncherView::ViewMode)rv ); } delete m; } void LauncherTabWidget::deleteView( const QString& id ) { LauncherTab *t = categoryBar->launcherTab(id); if ( t ) { - stack->removeWidget( t->view ); - delete t->view; - categoryBar->removeTab( t ); + stack->removeWidget( t->view ); + delete t->view; + categoryBar->removeTab( t ); } } LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label ) { LauncherView* view = new LauncherView( stack ); connect( view, SIGNAL(clicked(const AppLnk*)), this, SIGNAL(clicked(const AppLnk*))); connect( view, SIGNAL(rightPressed(AppLnk*)), this, SIGNAL(rightPressed(AppLnk*))); + int n = categoryBar->count(); + stack->addWidget( view, n ); LauncherTab *tab = new LauncherTab( id, view, pm, label ); categoryBar->insertTab( tab, n-1 ); - - if ( id == "Documents" ) - docview = view; + if ( id == "Documents" ) { + docview = view; + m_DocumentTabId = n; + } odebug << "inserting " << id << " at " << n-1 << "" << oendl; Config cfg("Launcher"); setTabAppearance( tab, cfg ); @@ -237,26 +240,26 @@ LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, } LauncherView *LauncherTabWidget::view( const QString &id ) { LauncherTab *t = categoryBar->launcherTab(id); if ( !t ) - return 0; + return 0; return t->view; } LauncherView *LauncherTabWidget::docView() { return docview; } void LauncherTabWidget::setLoadingWidgetEnabled( bool v ) { if ( v != docLoadingWidgetEnabled && docLoadingWidget ) { - docLoadingWidgetEnabled = v; - raiseTabWidget(); + docLoadingWidgetEnabled = v; + raiseTabWidget(); } } void LauncherTabWidget::setLoadingProgress( int percent ) { docLoadingWidgetProgress->setProgress( (percent / 4) * 4 ); @@ -601,13 +604,12 @@ void Launcher::properties( AppLnk *appLnk ) // Not supported: flat is simpler for the user } else { /* ### libqtopia FIXME also moving docLnks... */ LnkProperties prop(appLnk,0 ); if (QPEApplication::execDialog( &prop )==QDialog::Accepted && tabs->currentView()==tabs->docView()) { - tabs->docView()->updateTools(); } } } void Launcher::storageChanged( const QList<FileSystem> & ) { @@ -718,14 +720,19 @@ void Launcher::documentRemoved( const DocLnk& doc ) { tabs->docView()->removeLink( doc.linkFile() ); } void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc ) { +#if 0 documentRemoved( oldDoc ); documentAdded( newDoc ); +// tabs->docView()->updateTools(); +#else + tabs->docView()->changeItem(oldDoc,new DocLnk(newDoc)); +#endif } void Launcher::allDocumentsRemoved() { tabs->docView()->removeAllItems(); } diff --git a/core/launcher/launcher.h b/core/launcher/launcher.h index 2eaf77c..db6ac54 100644 --- a/core/launcher/launcher.h +++ b/core/launcher/launcher.h @@ -87,12 +87,14 @@ private: LauncherView *docview; QWidgetStack *stack; LauncherView *docLoadingWidget; QProgressBar *docLoadingWidgetProgress; bool docLoadingWidgetEnabled; + bool docTabEnabled; + int m_DocumentTabId; }; class Launcher : public QMainWindow, public ServerInterface { Q_OBJECT public: @@ -132,13 +134,13 @@ public slots: void makeVisible(); signals: void executing( const AppLnk * ); private slots: - void systemMessage( const QCString &, const QByteArray &); + void systemMessage( const QCString &, const QByteArray &); protected: bool eventFilter( QObject *o, QEvent *ev ); private: void updateApps(); diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index ff26133..c9efacb 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp @@ -41,12 +41,13 @@ using namespace Opie::Core; // These define how the busy icon is animated and highlighted #define BRIGHTEN_BUSY_ICON //#define ALPHA_FADE_BUSY_ICON //#define USE_ANIMATED_BUSY_ICON_OVERLAY #define BOUNCE_BUSY_ICON +typedef QMap<QString,QPixmap>::Iterator pixiter; class BgPixmap { public: BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} QPixmap pm; @@ -102,31 +103,33 @@ protected: AppLnk* app; private: void paintAnimatedIcon( QPainter *p ); BusyIndicatorType busyType; int psize; - QPixmap m_iPixmap; bool m_EyeImage; iconstate_t m_EyeImageSet; }; LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) : QIconViewItem( parent, applnk->name(), bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), isBigIcon( bigIcon ), iteration(0), app(applnk), // Takes ownership psize( (bigIcon ? applnk->bigPixmap().width() :applnk->pixmap().width() ) ), - m_iPixmap(), m_EyeImage(false), m_EyeImageSet(BASE_ICON) { if (applnk->type().lower().startsWith("image/") && applnk->exec().contains("opie-eye",false)) { m_EyeImage = true; - m_iPixmap = (bigIcon ? applnk->bigPixmap():applnk->pixmap()); + QMap<QString,QPixmap>::Iterator it = LauncherIconView::sm_EyeCache->find(applnk->file()); + if (it != LauncherIconView::sm_EyeCache->end()) { + m_EyeImageSet = EYE_ICON; + setPixmap(*it); + } } } LauncherItem::~LauncherItem() { LauncherIconView* liv = (LauncherIconView*)iconView(); @@ -210,13 +213,19 @@ void LauncherItem::animateIcon() if ( liv->busyItem() != this || !app ) return; // Highlight the icon if ( iteration == 0 ) { - QPixmap src = (isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap())); + QPixmap src; + pixiter it; + if (isEyeImage() && (it=LauncherIconView::sm_EyeCache->find(appLnk()->file()))!=LauncherIconView::sm_EyeCache->end()) { + src = (*it); + } else { + src = ((isBigIcon ? app->bigPixmap() : app->pixmap())); + } QImage img = src.convertToImage(); QRgb *rgb; int count; if ( img.depth() == 32 ) { rgb = (QRgb*)img.bits(); count = img.bytesPerLine()/sizeof(QRgb)*img.height(); @@ -246,30 +255,40 @@ void LauncherItem::animateIcon() paintAnimatedIcon( &p ); } void LauncherItem::resetIcon() { iteration = 0; - setPixmap((isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap()))); + if (isEyeImage()) { + QMap<QString,QPixmap>::Iterator it = LauncherIconView::sm_EyeCache->find(appLnk()->file()); + if (it != LauncherIconView::sm_EyeCache->end()) { + setPixmap(*it); + return; + } + } + setPixmap(isBigIcon ? app->bigPixmap() : app->pixmap()); } void LauncherItem::setEyePixmap(const QPixmap&aIcon) { if (!isEyeImage()) return; - m_iPixmap = aIcon; setPixmap(aIcon); m_EyeImageSet = EYE_ICON; } //=========================================================================== // Implemantation of LauncherIconview start //=========================================================================== + +QMap<QString,QPixmap>* LauncherIconView::sm_EyeCache=0; + LauncherIconView::LauncherIconView( QWidget* parent, const char* name ) : QIconView(parent,name),tf(""),cf(0),bsy(0),busyTimer(0),bigIcns(TRUE),bgColor(white) { m_EyeCallBack = 0; + if (!sm_EyeCache) sm_EyeCache = new QMap<QString,QPixmap>(); sortmeth = Name; hidden.setAutoDelete(TRUE); ike = FALSE; calculateGrid( Bottom ); connect(&m_eyeTimer,SIGNAL(timeout()),this,SLOT(stopEyeTimer())); } @@ -429,23 +448,24 @@ LauncherItem*LauncherIconView::findDocItem(const QString&fname) void LauncherIconView::setEyePixmap(const QPixmap&aPixmap,const QString&aFile,int width) { int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); if (s!=width) return; LauncherItem*item = findDocItem(aFile); if (!item||!item->isEyeImage()) return; + (*sm_EyeCache)[aFile]=aPixmap; item->setEyePixmap(aPixmap); } void LauncherIconView::checkCallback() { if (!m_EyeCallBack) { m_EyeCallBack = new LauncherThumbReceiver(); connect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&,int)), this,SLOT(setEyePixmap(const QPixmap&,const QString&,int))); - m_eyeTimer.changeInterval(600000); } + m_eyeTimer.changeInterval(600000); } void LauncherIconView::addCheckItem(AppLnk* app) { LauncherItem*item = new LauncherItem( this, app, bigIcns ); if (item->isEyeImage()) { @@ -463,33 +483,20 @@ void LauncherIconView::requestEyePix(const LauncherItem*item) } } void LauncherIconView::stopEyeTimer() { if (m_EyeCallBack) { + disconnect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&,int)), + this,SLOT(setEyePixmap(const QPixmap&,const QString&,int))); delete m_EyeCallBack; m_EyeCallBack=0; } m_eyeTimer.stop(); } -void LauncherIconView::addItem(AppLnk* app, bool resort) -{ - addCatsAndMimes(app); - if ( (tf.isEmpty() || tf.match(app->type()) >= 0) - && (cf == 0 || app->categories().contains(cf) - || cf == -1 && app->categories().count() == 0 ) ) { - addCheckItem(app); - } else { - hidden.append(app); - } - if ( resort ){ - sort(); - } -} - void LauncherIconView::updateCategoriesAndMimeTypes() { mimes.clear(); cats.clear(); LauncherItem* item = (LauncherItem*)firstItem(); while (item) { @@ -525,23 +532,24 @@ void LauncherIconView::hideOrShowItems(bool resort) } if ( resort && !autoArrange() ) sort(); viewport()->setUpdatesEnabled( TRUE ); } -bool LauncherIconView::removeLink(const QString& linkfile) +bool LauncherIconView::removeLink(const QString& linkfile,bool removeCache) { LauncherItem* item = (LauncherItem*)firstItem(); AppLnk* l; bool did = FALSE; DocLnk dl(linkfile); while (item) { l = item->appLnk(); LauncherItem *nextItem = (LauncherItem *)item->nextItem(); if ( l->linkFileKnown() && l->linkFile() == linkfile || l->fileKnown() && ( l->file() == linkfile || dl.isValid() && dl.file() == l->file() ) ) { + if (removeCache) sm_EyeCache->remove(l->file()); delete item; did = TRUE; } item = nextItem; } QListIterator<AppLnk> it(hidden); @@ -554,24 +562,57 @@ bool LauncherIconView::removeLink(const QString& linkfile) did = TRUE; } } return did; } +void LauncherIconView::addItem(AppLnk* app, bool resort) +{ + addCatsAndMimes(app); + if ( (tf.isEmpty() || tf.match(app->type()) >= 0) + && (cf == 0 || app->categories().contains(cf) + || cf == -1 && app->categories().count() == 0 ) ) { + addCheckItem(app); + } else { + hidden.append(app); + } + if ( resort ){ + sort(); + } +} + +void LauncherIconView::changeItem(const AppLnk&old,AppLnk*nlink) +{ + QString oldfile = old.file(); + QString newfile = nlink->file(); + + if (newfile != oldfile) { + QMap<QString,QPixmap>::Iterator it = sm_EyeCache->find(oldfile); + if (it != sm_EyeCache->end()) { + (*sm_EyeCache)[newfile]=(*it); + } + removeLink(old.linkFile()); + } else { + removeLink(old.linkFile(),false); + } + addItem(nlink,false); +} + void LauncherIconView::timerEvent( QTimerEvent *te ) { if ( te->timerId() == busyTimer ) { if ( bsy ) bsy->animateIcon(); } else { QIconView::timerEvent( te ); } } void LauncherIconView::setBigIcons( bool bi ) { + sm_EyeCache->clear(); bigIcns = bi; #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY busyPix.resize(0,0); #endif } @@ -753,14 +794,17 @@ void LauncherView::updateTools() } if ( prev.isNull() ) { typemb->setCurrentItem(typemb->count()-1); } int pcat = catmb ? catmb->currentCategory() : -2; - if ( !catmb ) + if ( !catmb ) { catmb = new CategorySelect(tools); + } else if (pcat!=-2) { + + } Categories cats( 0 ); cats.load( categoryFileName() ); QArray<int> vl( 0 ); catmb->setCategories( vl, "Document View", // No tr tr("Document View") ); catmb->setRemoveCategoryEdit( TRUE ); @@ -1017,13 +1061,13 @@ void LauncherView::itemClicked( int btn, QIconViewItem *item ) AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); if ( btn == LeftButton ) { // Make sure it's the item we execute that gets highlighted icons->setCurrentItem( item ); emit clicked( appLnk ); } - item->setSelected(FALSE); + item->setSelected(FALSE); } } void LauncherView::itemPressed( int btn, QIconViewItem *item ) { if ( item ) { @@ -1044,12 +1088,22 @@ void LauncherView::removeAllItems() bool LauncherView::removeLink(const QString& linkfile) { return icons->removeLink(linkfile); } +void LauncherView::addItem(AppLnk* app, bool resort) +{ + icons->addItem(app,resort); +} + +void LauncherView::changeItem(const AppLnk&old,AppLnk*nlink) +{ + icons->changeItem(old,nlink); +} + void LauncherView::setSortEnabled( bool v ) { icons->setSorting( v ); if ( v ) sort(); } @@ -1061,17 +1115,12 @@ void LauncherView::setUpdatesEnabled( bool u ) void LauncherView::sort() { icons->sort(); } -void LauncherView::addItem(AppLnk* app, bool resort) -{ - icons->addItem(app,resort); -} - void LauncherView::paletteChange( const QPalette &p ) { icons->unsetPalette(); QVBox::paletteChange( p ); if ( bgType == Ruled ) setBackgroundType( Ruled, QString::null ); diff --git a/core/launcher/launcherview.h b/core/launcher/launcherview.h index 6d94539..05073ab 100644 --- a/core/launcher/launcherview.h +++ b/core/launcher/launcherview.h @@ -53,12 +53,14 @@ public: ~LauncherView(); void hideIcons(); bool removeLink(const QString& linkfile); void addItem(AppLnk* app, bool resort=TRUE); + void changeItem(const AppLnk&old,AppLnk*nlink); + void removeAllItems(); void setSortEnabled(bool); void setUpdatesEnabled(bool); void sort(); void setToolsEnabled(bool); @@ -173,13 +175,14 @@ public: } void setBusy(bool on); bool inKeyEvent() const { return ike; } void addItem(AppLnk* app, bool resort=TRUE); - bool removeLink(const QString& linkfile); + bool removeLink(const QString& linkfile,bool removeCache = true); + void changeItem(const AppLnk&old,AppLnk*nlink); QStringList mimeTypes() const; QStringList categories() const; void clear(); void addCatsAndMimes(AppLnk* app); @@ -203,12 +206,14 @@ public: enum SortMethod { Name, Date, Type }; void setSortMethod( SortMethod m ); int compare(const AppLnk* a, const AppLnk* b); void requestEyePix(const LauncherItem*which); + static QMap<QString,QPixmap>* sm_EyeCache; + protected: virtual void timerEvent( QTimerEvent *te ); void styleChange( QStyle &old ); void calculateGrid( ItemTextPos pos ); void focusInEvent( QFocusEvent * ) {} void focusOutEvent( QFocusEvent * ) {} |