summaryrefslogtreecommitdiff
path: root/core
authoralwin <alwin>2004-11-10 21:18:37 (UTC)
committer alwin <alwin>2004-11-10 21:18:37 (UTC)
commit660b61a7f8b9fb885226507d7f6716ab2dcedbb8 (patch) (side-by-side diff)
tree5ebbfc6ca71b1a2205d5f2516b919c9c2dd4fced /core
parentd2f3b6f525be4d652fbac7c87ab0ad40e21af184 (diff)
downloadopie-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
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcher.cpp43
-rw-r--r--core/launcher/launcher.h4
-rw-r--r--core/launcher/launcherview.cpp109
-rw-r--r--core/launcher/launcherview.h7
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
@@ -56,49 +56,49 @@
#include <qwidgetstack.h>
#include <qregexp.h>
#include <qmessagebox.h>
#include <qframe.h>
#include <qpainter.h>
#include <qlabel.h>
#include <qtextstream.h>
#include <qpopupmenu.h>
/* STD */
#include <stdlib.h>
#include <assert.h>
#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()) );
categoryBar->show();
stack->show();
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
QCopChannel *channel = new QCopChannel( "QPE/Launcher", this );
connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT(launcherMessage(const QCString&,const QByteArray&)) );
connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
this, SLOT(appMessage(const QCString&,const QByteArray&)));
#endif
createDocLoadingWidget();
@@ -107,174 +107,177 @@ LauncherTabWidget::LauncherTabWidget( Launcher* parent ) :
void LauncherTabWidget::createDocLoadingWidget()
{
// Construct the 'doc loading widget' shown when finding documents
// ### LauncherView class needs changing to be more generic so
// this widget can change its background similar to the iconviews
// so the background for this matches
docLoadingWidget = new LauncherView( stack );
docLoadingWidget->hideIcons();
QVBox *docLoadingVBox = new QVBox( docLoadingWidget );
docLoadingVBox->setSpacing( 20 );
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>" ) );
}
else
{
textLabel->setText( tr( "<b>The Documents Tab<p>has been disabled.<p>"
"Use Settings->Launcher->DocTab<p>to reenable it.</b></center>" ) );
docLoadingWidgetProgress->hide();
docLoadingWidgetEnabled = true;
}
QWidget *space2 = new QWidget( docLoadingVBox );
docLoadingVBox->setStretchFactor( space2, 1 );
cfg.setGroup( "Tab Documents" ); // No tr
setTabViewAppearance( docLoadingWidget, cfg );
stack->addWidget( docLoadingWidget, 0 );
}
void LauncherTabWidget::initLayout()
{
layout()->activate();
docView()->setFocus();
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 );
cfg.setGroup( "GUI" );
view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) );
return view;
}
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 );
}
// ### this function could more to LauncherView
void LauncherTabWidget::setTabViewAppearance( LauncherView *v, Config &cfg )
{
// View
QString view = cfg.readEntry( "View", "Icon" );
if ( view == "List" ) // No tr
v->setViewMode( LauncherView::List );
QString bgType = cfg.readEntry( "BackgroundType", "Image" );
if ( bgType == "Image" ) { // No tr
QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" );
v->setBackgroundType( LauncherView::Image, pm );
} else if ( bgType == "SolidColor" ) {
QString c = cfg.readEntry( "BackgroundColor" );
v->setBackgroundType( LauncherView::SolidColor, c );
} else {
v->setBackgroundType( LauncherView::Ruled, QString::null );
@@ -583,49 +586,48 @@ void Launcher::select( const AppLnk *appLnk )
tr("<p>No application is defined for this document."
"<p>Type is %1.").arg(appLnk->type()), tr("OK"), tr("View as text"), 0, 0, 1);
/* ### Fixme */
if ( i == 1 )
Global::execute("textedit",appLnk->file());
return;
}
tabs->setBusy(TRUE);
emit executing( appLnk );
appLnk->execute();
}
}
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 );
if ( msg == "busy()" ) {
tb->startWait();
} else if ( msg == "notBusy(QString)" ) {
QString app;
stream >> app;
tabs->setBusy(FALSE);
tb->stopWait(app);
} else if (msg == "applyStyle()") {
tabs->currentView()->relayout();
}
}
@@ -700,50 +702,55 @@ void Launcher::aboutToAddBegin()
void Launcher::aboutToAddEnd()
{
tabs->docView()->setUpdatesEnabled( true );
}
void Launcher::showLoadingDocs()
{
tabs->docView()->hide();
}
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 );
}
void Launcher::applicationScanningProgress( int percent )
{
switch ( percent ) {
case 0: {
for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) {
tabs->view( (*it) )->setUpdatesEnabled( FALSE );
tabs->view( (*it) )->setSortEnabled( FALSE );
}
break;
}
case 100: {
for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) {
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
@@ -69,88 +69,90 @@ signals:
void rightPressed(AppLnk*);
protected slots:
void raiseTabWidget();
void tabProperties();
void initLayout();
private slots:
void launcherMessage( const QCString &, const QByteArray &);
void appMessage( const QCString &, const QByteArray &);
void setProgressStyle();
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();
void typeAdded( const QString& type, const QString& name, const QPixmap& pixmap, const QPixmap& bgPixmap );
void typeRemoved( const QString& type );
void applicationAdded( const QString& type, const AppLnk& doc );
void applicationRemoved( const QString& type, const AppLnk& doc );
void allApplicationsRemoved();
void applicationStateChanged( const QString& name, ApplicationState state );
void documentAdded( const DocLnk& doc );
void documentRemoved( const DocLnk& doc );
void aboutToAddBegin();
void aboutToAddEnd();
void allDocumentsRemoved();
void documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc );
void storageChanged( const QList<FileSystem> & );
void applicationScanningProgress( int percent );
void documentScanningProgress( int percent );
bool requiresApplications() const { return TRUE; }
bool requiresDocuments() const;
void showLoadingDocs();
void showDocTab();
QStringList idList() const { return ids; }
public slots:
void viewSelected(const QString&);
void showTab(const QString&);
void select( const AppLnk * );
void properties( AppLnk * );
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();
void loadDocs();
void updateDocs();
void updateTabs();
LauncherTabWidget *tabs;
QStringList ids;
TaskBar *tb;
bool docTabEnabled;
};
#endif // LAUNCHERVIEW_H
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
@@ -23,48 +23,49 @@
/* OPIE */
#include <opie2/odebug.h>
#include <qtopia/qpeapplication.h>
#include <qtopia/private/categories.h>
#include <qtopia/categoryselect.h>
#include <qtopia/mimetype.h>
#include <qtopia/resource.h>
using namespace Opie::Core;
#include <qpe/qcopenvelope_qws.h>
/* QT */
#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;
static void cleanup_cache()
{
QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
while ( it != bgCache->end() ) {
QMap<QString,BgPixmap*>::Iterator curr = it;
++it;
delete (*curr);
bgCache->remove( curr );
}
delete bgCache;
bgCache = 0;
}
@@ -84,67 +85,69 @@ public:
AppLnk *appLnk() const { return app; }
AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; }
void animateIcon();
void resetIcon();
bool isEyeImage()const{return m_EyeImage;}
virtual int compare ( QIconViewItem * i ) const;
void paintItem( QPainter *p, const QColorGroup &cg );
void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
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
{
if (m_EyeImage && m_EyeImageSet == BASE_ICON) {
LauncherIconView* liv = (LauncherIconView*)iconView();
liv->requestEyePix(this);
}
return QIconViewItem::pixmap();
}
int LauncherItem::compare ( QIconViewItem * i ) const
{
LauncherIconView* view = (LauncherIconView*)iconView();
return view->compare(app,((LauncherItem *)i)->appLnk());
@@ -192,102 +195,118 @@ void LauncherItem::paintAnimatedIcon( QPainter *p )
#ifdef BOUNCE_BUSY_ICON
if ( busyType == BIT_Animated ) {
bounceY = 4 - ((iteration+2)%8);
bounceY = bounceY < 0 ? -bounceY : bounceY;
}
#endif
p2.drawPixmap( x1, y1 + bounceY, *pixmap() );
#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h );
#else
Q_UNUSED( pic )
#endif
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)
QColor c(*rgb);
int h, s, v;
c.hsv(&h,&s,&v);
c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255));
*rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb));
#elif defined(ALPHA_FADE_BUSY_ICON)
*rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2);
#endif
}
src.convertFromImage( img );
setPixmap( src );
}
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);
AppLnk* l;
while ((l=it.current())) {
++it;
//odebug << "" << l << ": hidden (should remove)" << oendl;
}
#endif
}
int LauncherIconView::compare(const AppLnk* a, const AppLnk* b)
{
switch (sortmeth) {
case Name:
@@ -411,185 +430,207 @@ QStringList LauncherIconView::mimeTypes() const
++it;
}
r.sort();
return r;
}
LauncherItem*LauncherIconView::findDocItem(const QString&fname)
{
LauncherItem* item = (LauncherItem*)firstItem();
while (item) {
if (item->appLnk()->file()==fname) {
break;
}
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())) {
addCatsAndMimes(l);
++it;
}
}
void LauncherIconView::hideOrShowItems(bool resort)
{
viewport()->setUpdatesEnabled( FALSE );
hidden.setAutoDelete(FALSE);
QList<AppLnk> links=hidden;
hidden.clear();
hidden.setAutoDelete(TRUE);
LauncherItem* item = (LauncherItem*)firstItem();
while (item) {
links.append(item->takeAppLnk());
item = (LauncherItem*)item->nextItem();
}
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; }
void LauncherIconView::calculateGrid( ItemTextPos pos )
{
int dw = QApplication::desktop()->width();
int viewerWidth = dw-style().scrollBarExtent().width();
if ( pos == Bottom ) {
int cols = 3;
if ( viewerWidth <= 200 )
cols = 2;
else if ( viewerWidth >= 400 )
cols = viewerWidth/96;
setSpacing( 4 );
@@ -735,50 +776,53 @@ void LauncherView::updateTools()
if ( app )
t = app->name();
else
t = t.mid(12);
} else {
t[0] = t[0].upper();
}
types += t;
}
types << tr("All types");
prev = typemb->currentText();
typemb->clear();
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() );
connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int)));
connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
}
void LauncherView::sortBy(int s)
{
icons->setSortMethod((LauncherIconView::SortMethod)s);
}
void LauncherView::showType(int t)
{
@@ -999,97 +1043,102 @@ void LauncherView::selectionChanged()
AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
if ( icons->inKeyEvent() ) // not for mouse press
emit clicked( appLnk );
item->setSelected(FALSE);
}
}
void LauncherView::returnPressed( QIconViewItem *item )
{
if ( item ) {
AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
emit clicked( appLnk );
}
}
void LauncherView::itemClicked( int btn, QIconViewItem *item )
{
if ( 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 ) {
AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
if ( btn == RightButton )
emit rightPressed( appLnk );
else if ( btn == ShiftButton )
emit rightPressed( appLnk );
item->setSelected(FALSE);
}
}
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&)
{
odebug << "LauncherView::fontChanged()" << oendl;
icons->hideOrShowItems( FALSE );
}
void LauncherView::relayout(void)
{
icons->hideOrShowItems(FALSE);
}
void LauncherView::flushBgCache()
{
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
@@ -35,48 +35,50 @@ class QIconViewItem;
class QLabel;
class QWidgetStack;
class MenuButton;
class QComboBox;
enum BusyIndicatorType {
BIT_Normal = 0,
BIT_Animated
};
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 };
void setViewMode( ViewMode m );
ViewMode viewMode() const { return vmode; }
enum BackgroundType { Ruled, SolidColor, Image };
void setBackgroundType( BackgroundType t, const QString & );
BackgroundType backgroundType() const { return bgType; }
void setTextColor( const QColor & );
QColor textColor() const { return textCol; }
void setViewFont( const QFont & );
void clearViewFont();
@@ -155,78 +157,81 @@ protected:
};
class LauncherIconView : public QIconView {
Q_OBJECT
public:
LauncherIconView( QWidget* parent, const char* name=0 );
~LauncherIconView();
QIconViewItem* busyItem() const;
#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
QPixmap busyPixmap() const { return busyPix; }
#endif
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;
}
void setBackgroundColor( const QColor &c ) {
bgColor = c;
}
void drawBackground( QPainter *p, const QRect &r );
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:
void setEyePixmap(const QPixmap&,const QString&,int width);
void stopEyeTimer();
private:
QList<AppLnk> hidden;
QDict<void> mimes;
QDict<void> cats;
SortMethod sortmeth;
QRegExp tf;
int cf;
LauncherItem* bsy;
int busyTimer;