summaryrefslogtreecommitdiff
path: root/core/launcher/launcherview.cpp
authormickeyl <mickeyl>2005-07-03 22:13:00 (UTC)
committer mickeyl <mickeyl>2005-07-03 22:13:00 (UTC)
commit2cabd9ad4b49eefccdf99ad59550c76546b473c9 (patch) (side-by-side diff)
tree00bab275ac356aecc5a39b86ca22ce172d01f622 /core/launcher/launcherview.cpp
parent47011752d4457a1055894479e5bf855e100fddac (diff)
downloadopie-2cabd9ad4b49eefccdf99ad59550c76546b473c9.zip
opie-2cabd9ad4b49eefccdf99ad59550c76546b473c9.tar.gz
opie-2cabd9ad4b49eefccdf99ad59550c76546b473c9.tar.bz2
Resource -> OResource
This is a large diff and I'd appreciate some additional pairs of eyes checking it
Diffstat (limited to 'core/launcher/launcherview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index d960908..6275fcb 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,126 +1,133 @@
-/**********************************************************************
-** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
-**
-** This file is part of the Qtopia Environment.
-**
-** This file may be distributed and/or modified under the terms of the
-** GNU General Public License version 2 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** See http://www.trolltech.com/gpl/ for GPL licensing information.
-**
-** Contact info@trolltech.com if any conditions of this licensing are
-** not clear to you.
-**
-**********************************************************************/
-
+/*
+                 This file is part of the Opie Project
+ =. (C) 2000-2002 Trolltech AS
+ .=l. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This program is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+ :`=1 )Y*s>-.--   : the terms of the GNU Library General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; version 2 of the License.
+     ._= =}       :
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This program is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+ : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.=       =       ; Library General Public License for more
+++=   -.     .`     .: details.
+ :     =  ...= . :.=-
+ -.   .:....=;==+<; You should have received a copy of the GNU
+  -_. . .   )=.  = Library General Public License along with
+    --        :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
#include "launcherview.h"
/* OPIE */
#include <opie2/odebug.h>
+#include <opie2/oresource.h>
#include <qpe/config.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;
}
class LauncherItem : public QIconViewItem
{
public:
enum iconstate_t {
BASE_ICON,
WAITING_ICON,
EYE_ICON
};
LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
~LauncherItem();
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;
bool m_EyeImage;
iconstate_t m_EyeImageSet;
};
static bool s_IgnoreNextPix = false;
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_EyeImage(false),
m_EyeImageSet(BASE_ICON)
{
if (applnk->type().lower().startsWith("image/") && applnk->exec().contains("opie-eye",false)) {
@@ -333,193 +340,193 @@ void LauncherIconView::setStaticBackgroundPicture( bool enable )
{
setStaticBackground( true );
verticalScrollBar()->setTracking( false );
}
else
{
setStaticBackground( false );
verticalScrollBar()->setTracking( true );
}
}
int LauncherIconView::compare(const AppLnk* a, const AppLnk* b)
{
switch (sortmeth) {
case Name:
return a->name().lower().compare(b->name().lower());
case Date: {
QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
return fa.lastModified().secsTo(fb.lastModified());
}
case Type:
return a->type().compare(b->type());
}
return 0;
}
void LauncherIconView::setSortMethod( SortMethod m )
{
if ( sortmeth != m ) {
sortmeth = m;
sort();
}
}
void LauncherIconView::setCategoryFilter( int catfilter, bool resort )
{
if ( catfilter == -2 )
cf = 0;
else
cf = catfilter;
hideOrShowItems(resort);
}
void LauncherIconView::setTypeFilter(const QString& typefilter, bool resort)
{
tf = QRegExp(typefilter,FALSE,TRUE);
hideOrShowItems(resort);
}
void LauncherIconView::setItemTextPos( ItemTextPos pos )
{
calculateGrid( pos );
QIconView::setItemTextPos( pos );
}
void LauncherIconView::drawBackground( QPainter *p, const QRect &r )
{
if ( bgPixmap.isNull() )
{
p->fillRect( r, bgColor );
}
else
{
if ( staticBackground )
{
p->drawTiledPixmap( r, bgPixmap, QPoint( r.x() % bgPixmap.width(), r.y() % bgPixmap.height() ) );
}
else
{
p->drawTiledPixmap( r, bgPixmap, QPoint( (r.x() + contentsX()) % bgPixmap.width(),
(r.y() + contentsY()) % bgPixmap.height() ) );
}
}
}
void LauncherIconView::addCatsAndMimes(AppLnk* app)
{
// QStringList c = app->categories();
// for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
// cats.replace(*cit,(void*)1);
// }
QString maj=app->type();
int sl=maj.find('/');
if (sl>=0) {
QString k;
k = maj.left(12) == "application/" ? maj : maj.left(sl);
mimes.replace(k,(void*)1);
}
}
void LauncherIconView::setBusy(bool on)
{
#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
if ( busyPix.isNull() ) {
int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize();
- busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) );
+ busyPix.convertFromImage( OResource::loadImage( "busy", OResource::NoScale ).smoothScale( size * 16, size ) );
}
#endif
if ( on ) {
busyTimer = startTimer( 100 );
} else {
if ( busyTimer ) {
killTimer( busyTimer );
busyTimer = 0;
}
}
LauncherItem *c = on ? (LauncherItem*)currentItem() : 0;
if ( bsy != c ) {
LauncherItem *oldBusy = bsy;
bsy = c;
if ( oldBusy ) {
oldBusy->resetIcon();
}
if ( bsy ) {
bsy->setBusyIndicatorType( busyType ) ;
bsy->animateIcon();
}
}
}
void LauncherIconView::clear()
{
mimes.clear();
cats.clear();
QIconView::clear();
hidden.clear();
}
QStringList LauncherIconView::mimeTypes() const
{
QStringList r;
QDictIterator<void> it(mimes);
while (it.current()) {
r.append(it.currentKey());
++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);
}
}
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);
}
}
@@ -908,193 +915,193 @@ void LauncherView::setViewMode( ViewMode m )
//
QImage LauncherView::loadBackgroundImage(QString &bgName)
{
QImageIO imgio;
QSize ds = qApp->desktop()->size(); // should be launcher, not desktop
bool further_scaling = TRUE;
imgio.setFileName( bgName );
imgio.setParameters("GetHeaderInformation");
if (imgio.read() == FALSE) {
return imgio.image();
}
if (imgio.image().width() < ds.width() &&
imgio.image().height() < ds.height()) {
further_scaling = FALSE;
}
if (!imgio.image().bits()) {
//
// Scale and load. Note we don't scale up.
//
QString param( "Scale( %1, %2, ScaleMin )" ); // No tr
imgio.setParameters(further_scaling ?
param.arg(ds.width()).arg(ds.height()).latin1() :
"");
imgio.read();
} else {
if (further_scaling) {
int t1 = imgio.image().width() * ds.height();
int t2 = imgio.image().height() * ds.width();
int dsth = ds.height();
int dstw = ds.width();
if (t1 > t2) {
dsth = t2 / imgio.image().width();
} else {
dstw = t1 / imgio.image().height();
}
//
// Loader didn't scale for us. Do it manually.
//
return imgio.image().smoothScale(dstw, dsth);
}
}
return imgio.image();
}
void LauncherView::setBackgroundType( BackgroundType t, const QString &val )
{
if ( !bgCache ) {
bgCache = new QMap<QString,BgPixmap*>;
qAddPostRoutine( cleanup_cache );
}
if ( bgCache->contains( bgName ) )
(*bgCache)[bgName]->ref--;
bgName = "";
QPixmap bg;
switch ( t ) {
case Ruled: {
bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr
if ( bgCache->contains( bgName ) ) {
(*bgCache)[bgName]->ref++;
bg = (*bgCache)[bgName]->pm;
} else {
bg.resize( width(), 9 );
QPainter painter( &bg );
for ( int i = 0; i < 3; i++ ) {
painter.setPen( white );
painter.drawLine( 0, i*3, width()-1, i*3 );
painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
painter.setPen( colorGroup().background().light(105) );
painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
}
painter.end();
bgCache->insert( bgName, new BgPixmap(bg) );
}
break;
}
case Image:
if (!val.isEmpty()) {
bgName = val;
if ( bgCache->contains( bgName ) ) {
(*bgCache)[bgName]->ref++;
bg = (*bgCache)[bgName]->pm;
} else {
QString imgFile = bgName;
bool tile = FALSE;
if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) {
- imgFile = Resource::findPixmap( imgFile );
+ imgFile = OResource::findPixmap( imgFile );
tile = TRUE;
}
QImage img = loadBackgroundImage(imgFile);
if ( img.depth() == 1 )
img = img.convertDepth(8);
img.setAlphaBuffer(FALSE);
bg.convertFromImage(img);
bgCache->insert( bgName, new BgPixmap(bg) );
}
}
break;
case SolidColor:
default:
break;
}
const QObjectList *list = queryList( "QWidget", 0, FALSE );
QObject *obj;
for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) {
if ( obj->isWidgetType() ) {
QWidget *w = (QWidget*)obj;
w->setBackgroundPixmap( bg );
if ( bgName.isEmpty() ) {
// Solid Color
if ( val.isEmpty() )
w->setBackgroundColor( colorGroup().base() );
else
w->setBackgroundColor( val );
} else {
// Ruled or Image pixmap
w->setBackgroundOrigin( ParentOrigin );
}
}
}
delete list;
bgType = t;
icons->viewport()->update();
QTimer::singleShot( 1000, this, SLOT(flushBgCache()) );
}
void LauncherView::setColNumber( int num )
{
icons->setColNumber( num );
}
void LauncherIconView::setColNumber( int num )
{
numColumns = num;
calculateGrid( Bottom );
}
void LauncherView::setTextColor( const QColor &tc )
{
textCol = tc;
QColorGroup cg = icons->colorGroup();
cg.setColor( QColorGroup::Text, tc );
icons->setPalette( QPalette(cg,cg,cg) );
icons->viewport()->update();
}
void LauncherView::setViewFont( const QFont &f )
{
icons->setFont( f );
icons->hideOrShowItems( FALSE );
}
void LauncherView::clearViewFont()
{
icons->unsetFont();
icons->hideOrShowItems( FALSE );
}
void LauncherView::resizeEvent(QResizeEvent *e)
{
// qDebug("LauncherView resize event");
QVBox::resizeEvent( e );
// commented out for launcherview and qt/e 2.3.8 problems, probably needs real fixing somewhere...
// if ( e->size().width() != e->oldSize().width() )
sort();
}
void LauncherView::selectionChanged()
{
QIconViewItem* item = icons->currentItem();
if ( item && item->isSelected() ) {
AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
if ( icons->inKeyEvent() ) // not for mouse press
emit clicked( appLnk );
item->setSelected(FALSE);
}
}