-rw-r--r-- | core/launcher/launcher.cpp | 17 | ||||
-rw-r--r-- | core/launcher/launcher.h | 2 | ||||
-rw-r--r-- | core/launcher/launcherview.cpp | 107 | ||||
-rw-r--r-- | core/launcher/launcherview.h | 7 |
4 files changed, 98 insertions, 35 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 @@ -68,25 +68,25 @@ #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) #include <unistd.h> #include <stdio.h> #include <sys/vfs.h> #include <mntent.h> #endif 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 ); QPalette pal = categoryBar->palette(); pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); categoryBar->setPalette( pal ); stack = new QWidgetStack(this); connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) ); @@ -119,25 +119,25 @@ void LauncherTabWidget::createDocLoadingWidget() docLoadingVBox->setMargin( 10 ); QWidget *space1 = new QWidget( docLoadingVBox ); docLoadingVBox->setStretchFactor( space1, 1 ); QLabel *waitPixmap = new QLabel( docLoadingVBox ); 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 ); docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker setProgressStyle(); if ( docTabEnabled ) { textLabel->setText( tr( "<b>Finding Documents...</b>" ) ); @@ -207,32 +207,35 @@ void LauncherTabWidget::deleteView( const QString& id ) 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" ) + if ( id == "Documents" ) { docview = view; + m_DocumentTabId = n; + } odebug << "inserting " << id << " at " << n-1 << "" << oendl; Config cfg("Launcher"); setTabAppearance( tab, cfg ); cfg.setGroup( "GUI" ); view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) ); return view; } @@ -595,25 +598,24 @@ void Launcher::select( const AppLnk *appLnk ) } } void Launcher::properties( AppLnk *appLnk ) { if ( appLnk->type() == "Folder" ) { // No tr // 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> & ) { // ### update combo boxes if we had a combo box for the storage type } void Launcher::systemMessage( const QCString &msg, const QByteArray &data) { QDataStream stream( data, IO_ReadOnly ); @@ -712,26 +714,31 @@ void Launcher::showDocTab() { if ( tabs->categoryBar->currentView() == tabs->docView() ) tabs->docView()->show(); } 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(); } void Launcher::applicationStateChanged( const QString& name, ApplicationState state ) { tb->setApplicationState( name, state ); } 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 @@ -81,24 +81,26 @@ private slots: protected: void paletteChange( const QPalette &p ); void styleChange( QStyle & ); private: Launcher *launcher; LauncherView *docview; QWidgetStack *stack; LauncherView *docLoadingWidget; QProgressBar *docLoadingWidgetProgress; bool docLoadingWidgetEnabled; + bool docTabEnabled; + int m_DocumentTabId; }; class Launcher : public QMainWindow, public ServerInterface { Q_OBJECT public: Launcher(); ~Launcher(); // implementing ServerInterface void createGUI(); void destroyGUI(); 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 @@ -35,24 +35,25 @@ using namespace Opie::Core; #include <qtimer.h> #include <qfileinfo.h> #include <qiconview.h> #include <qobjectlist.h> // 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; int ref; }; static QMap<QString,BgPixmap*> *bgCache = 0; @@ -96,43 +97,45 @@ public: void setEyePixmap(const QPixmap&aIcon); virtual QPixmap*pixmap()const; protected: bool isBigIcon; int iteration; 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(); if ( liv->busyItem() == this ) liv->setBusy(FALSE); delete app; } QPixmap*LauncherItem::pixmap()const @@ -204,25 +207,31 @@ void LauncherItem::paintAnimatedIcon( QPainter *p ) p->drawPixmap( x1, y1, dblBuf ); } void LauncherItem::animateIcon() { LauncherIconView* liv = (LauncherIconView*)iconView(); 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(); } else { rgb = img.colorTable(); count = img.numColors(); } for ( int r = 0; r < count; r++, rgb++ ) { #if defined(BRIGHTEN_BUSY_ICON) @@ -240,42 +249,52 @@ void LauncherItem::animateIcon() } iteration++; // Paint animation overlay QPainter p( liv->viewport() ); 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())); } LauncherIconView::~LauncherIconView() { odebug << "LauncherIconView::~LauncherIconView()" << oendl; #if 0 // debuggery QListIterator<AppLnk> it(hidden); @@ -423,79 +442,67 @@ LauncherItem*LauncherIconView::findDocItem(const QString&fname) } item = (LauncherItem*)item->nextItem(); } return item; } 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()) { checkCallback(); } } void LauncherIconView::requestEyePix(const LauncherItem*item) { if (!item) return; if (item->isEyeImage()) { checkCallback(); int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); m_EyeCallBack->requestThumb(item->appLnk()->file(),s,s); } } 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) { addCatsAndMimes(item->appLnk()); item = (LauncherItem*)item->nextItem(); } QListIterator<AppLnk> it(hidden); AppLnk* l; while ((l=it.current())) { @@ -519,65 +526,99 @@ void LauncherIconView::hideOrShowItems(bool resort) clear(); QListIterator<AppLnk> it(links); AppLnk* l; while ((l=it.current())) { addItem(l,FALSE); ++it; } 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); while ((l=it.current())) { ++it; if ( l->linkFileKnown() && l->linkFile() == linkfile || l->file() == linkfile || dl.isValid() && dl.file() == l->file() ) { hidden.removeRef(l); 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 } QIconViewItem* LauncherIconView::busyItem() const { return bsy; } void LauncherIconView::setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } @@ -747,26 +788,29 @@ void LauncherView::updateTools() typemb->insertStringList(types); for (int i=0; i<typemb->count(); i++) { if ( typemb->text(i) == prev ) { typemb->setCurrentItem(i); break; } } 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 ); catmb->setAllCategories( TRUE ); catmb->setCurrentCategory(pcat); // if type has changed we need to redisplay if ( typemb->currentText() != prev ) showType( typemb->currentItem() ); @@ -1038,46 +1082,51 @@ void LauncherView::itemPressed( int btn, QIconViewItem *item ) void LauncherView::removeAllItems() { odebug << "LauncherView::removeAllItems()" << oendl; icons->clear(); } 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(); } void LauncherView::setUpdatesEnabled( bool u ) { icons->setUpdatesEnabled( 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 ); QColorGroup cg = icons->colorGroup(); cg.setColor( QColorGroup::Text, textCol ); icons->setPalette( QPalette(cg,cg,cg) ); } void LauncherView::fontChanged(const QFont&) 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 @@ -47,24 +47,26 @@ enum BusyIndicatorType { class LauncherView : public QVBox { Q_OBJECT public: LauncherView( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~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); void updateTools(); void setBusy(bool); void setBusyIndicatorType( const QString& ); enum ViewMode { Icon, List }; @@ -167,25 +169,26 @@ public: void setBigIcons( bool bi ); void updateCategoriesAndMimeTypes(); void setBusyIndicatorType ( BusyIndicatorType t ); void doAutoScroll() { // We don't want rubberbanding (yet) } 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); void setBackgroundOrigin( QWidget::BackgroundOrigin ) {} void setBackgroundPixmap( const QPixmap &pm ) { bgPixmap = pm; } @@ -197,24 +200,26 @@ public: void setItemTextPos( ItemTextPos pos ); void hideOrShowItems(bool resort); void setTypeFilter(const QString& typefilter, bool resort); void setCategoryFilter( int catfilter, bool resort ); 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 * ) {} LauncherItem*findDocItem(const QString&); void addCheckItem(AppLnk* app); void checkCallback(); virtual void keyPressEvent(QKeyEvent* e); protected slots: |