summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/lib
authorzecke <zecke>2004-03-22 23:32:41 (UTC)
committer zecke <zecke>2004-03-22 23:32:41 (UTC)
commit428b687982966dc2efabaf6dbcc55ad0ea30aa10 (patch) (side-by-side diff)
tree86da20abd2e4b97a59dc32e17996bde5ee74cc91 /noncore/graphics/opie-eye/lib
parent7ce623c6351646ce738a81e103632d73c5454ecc (diff)
downloadopie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.zip
opie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.tar.gz
opie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.tar.bz2
Initial Check in of the Eye Of Zilla. This ImageViewer features
Image Infos, EXIF, Jpeg,Png,Gif support. It supports scaled loading of Jpegs. an smart image cache.... GUI needs some work and we need to find a bug in QCOP as well. TODO: Add Image Service for example Mailer Add ImageCanvas/Zoomer/Display
Diffstat (limited to 'noncore/graphics/opie-eye/lib') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/lib/imagecache.cpp87
-rw-r--r--noncore/graphics/opie-eye/lib/imagecache.h46
-rw-r--r--noncore/graphics/opie-eye/lib/slavemaster.cpp145
-rw-r--r--noncore/graphics/opie-eye/lib/slavemaster.h43
-rw-r--r--noncore/graphics/opie-eye/lib/viewmap.cpp25
5 files changed, 346 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/lib/imagecache.cpp b/noncore/graphics/opie-eye/lib/imagecache.cpp
new file mode 100644
index 0000000..3b74a83
--- a/dev/null
+++ b/noncore/graphics/opie-eye/lib/imagecache.cpp
@@ -0,0 +1,87 @@
+/*
+ * GPLv2 zecke@handhelds.org
+ * No WArranty...
+ */
+
+#include <iface/dirview.h>
+#include <iface/dirlister.h>
+
+#include "imagecache.h"
+
+namespace {
+ PImageCache * _imgCache = 0;
+ PPixmapCache* _pxmCache = 0;
+}
+
+
+PImageCache::PImageCache()
+ : QCache<QImage>()
+{
+ /* just to set an initial value.. 4 big images */
+ setMaxCost( (1024*1024*16)/8*4 );
+}
+
+PImageCache::~PImageCache() {
+}
+
+PImageCache* PImageCache::self() {
+ if ( !_imgCache )
+ _imgCache = new PImageCache;
+ return _imgCache;
+}
+
+QImage* PImageCache::cachedImage( const QString& _path, int ori, int max ) {
+ QString path = QString( "%1_%2:" ).arg( ori ).arg( max );
+ path += _path;
+
+ QImage* img = find( path );
+ if ( !img ) {
+// img = currentView()->dirLister()->image( _path, PDirLister::Factor(ori), max);
+// insertImage( _path, img, ori, max );
+ currentView()->dirLister()->image( _path, PDirLister::Factor( ori ), max );
+ }
+
+
+ return img;
+}
+
+void PImageCache::insertImage( const QString& _path, const QImage* img, int ori, int max ) {
+ QString path = QString("%1_%2:" ).arg( ori ).arg( max );
+ path += _path;
+ insert( path, img, (img->height()*img->width()*img->depth())/8 );
+}
+
+
+PPixmapCache::PPixmapCache() {
+ /*
+ * 20 64x64 16 bit images
+ */
+ setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 );
+}
+
+PPixmapCache::~PPixmapCache() {
+}
+
+PPixmapCache* PPixmapCache::self() {
+ if ( !_pxmCache )
+ _pxmCache = new PPixmapCache;
+
+ return _pxmCache;
+}
+
+QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) {
+ QString path = QString( "%1_%2:" ).arg( width ).arg( height );
+ path += _path;
+
+ QPixmap* pxm = find( path );
+
+
+
+ return pxm;
+}
+
+void PPixmapCache::insertImage( const QString& _path, const QPixmap* pix, int width, int height ) {
+ QString path = QString("%1_%2:" ).arg( width ).arg( height );
+ path += _path;
+ insert( path, pix, (pix->height()*pix->width()*pix->depth())/8 );
+}
diff --git a/noncore/graphics/opie-eye/lib/imagecache.h b/noncore/graphics/opie-eye/lib/imagecache.h
new file mode 100644
index 0000000..076ecd3
--- a/dev/null
+++ b/noncore/graphics/opie-eye/lib/imagecache.h
@@ -0,0 +1,46 @@
+/*
+ * GPLv2 zecke@handhelds.org
+ * No WArranty...
+ */
+
+#ifndef PHUNK_IMAGE_CACHE_H
+#define PHUNK_IMAGE_CACHE_H
+
+#include <qimage.h>
+#include <qpixmap.h>
+#include <qcache.h>
+
+
+class PImageCache : public QCache<QImage> {
+private:
+ PImageCache();
+ ~PImageCache();
+
+public:
+ static PImageCache *self();
+ QImage* cachedImage( const QString& path, int orientation = 3, int max = 0); //const;
+ void insertImage( const QString& path, const QImage &, int orien = 3, int max = 0);
+ void insertImage( const QString& path, const QImage *, int orien=3, int max = 0 );
+};
+
+
+class PPixmapCache : public QCache<QPixmap> {
+private:
+ PPixmapCache();
+ ~PPixmapCache();
+public:
+ static PPixmapCache *self();
+ QPixmap* cachedImage( const QString& path, int width, int height );
+ void insertImage( const QString& path, const QPixmap &, int width, int height );
+ void insertImage( const QString& path, const QPixmap *, int width, int height );
+};
+
+inline void PPixmapCache::insertImage( const QString& path, const QPixmap& p, int width, int height ) {
+ insertImage( path, new QPixmap( p ), width, height );
+}
+
+inline void PImageCache::insertImage( const QString& path, const QImage& p, int width, int height ) {
+ insertImage( path, new QImage( p ), width, height );
+}
+
+#endif
diff --git a/noncore/graphics/opie-eye/lib/slavemaster.cpp b/noncore/graphics/opie-eye/lib/slavemaster.cpp
new file mode 100644
index 0000000..18dc883
--- a/dev/null
+++ b/noncore/graphics/opie-eye/lib/slavemaster.cpp
@@ -0,0 +1,145 @@
+#include "slavemaster.h"
+
+#include <qpe/qpeapplication.h>
+#include <qpe/qcopenvelope_qws.h>
+
+#include <qcopchannel_qws.h>
+#include <qtimer.h>
+
+QDataStream & operator << (QDataStream & str, bool b)
+{
+ str << Q_INT8(b);
+ return str;
+}
+QDataStream & operator >> (QDataStream & str, bool & b)
+{
+ Q_INT8 l;
+ str >> l;
+ b = bool(l);
+ return str;
+}
+QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) {
+ return s << inf.file << inf.pixmap << inf.width << inf.height;
+}
+QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) {
+ s >> inf.file >> inf.pixmap >> inf.width >> inf.height;
+ return s;
+}
+QDataStream &operator<<( QDataStream& s, const ImageInfo& i) {
+ return s << i.kind << i.file << i.info;
+}
+QDataStream &operator>>( QDataStream& s, ImageInfo& i ) {
+ s >> i.kind >> i.file >> i.info;
+ return s;
+}
+
+
+
+SlaveMaster* SlaveMaster::m_master = 0;
+
+SlaveMaster::SlaveMaster()
+ : m_started( false )
+{
+ QCopChannel *chan= new QCopChannel( "QPE/opie-eye",this );
+ connect(chan, SIGNAL(received(const QCString&,const QByteArray&)),
+ this, SLOT(recieve(const QCString&,const QByteArray&)) );
+}
+
+SlaveMaster::~SlaveMaster() {
+}
+
+SlaveMaster* SlaveMaster::self() {
+ if ( !m_master )
+ m_master = new SlaveMaster;
+ return m_master;
+}
+
+void SlaveMaster::thumbInfo( const QString& str) {
+ m_inThumbInfo.append( str );
+
+ if ( !m_started ) {
+ QTimer::singleShot( 0, this, SLOT(slotTimerStart()));
+ m_started = true;
+ }
+}
+
+void SlaveMaster::imageInfo( const QString& str ) {
+ m_inImageInfo.append( str );
+ if ( !m_started ) {
+ QTimer::singleShot( 0, this, SLOT(slotTimerStart()));
+ m_started = true;
+ }
+}
+
+void SlaveMaster::thumbNail( const QString& str, int w, int h ) {
+ if ( str.isEmpty() ) {
+ qWarning( "Asking for empty nail" );
+ return;
+ }
+ qWarning( "Asking for thumbNail in size %d %d" + str, w,h );
+ PixmapInfo item;
+ item.file = str; item.width = w; item.height = h;
+ item.pixmap = QPixmap();
+ m_inThumbNail.append( item );
+
+ if ( !m_started ) {
+ QTimer::singleShot( 0, this, SLOT(slotTimerStart()));
+ m_started = true;
+ }
+}
+
+
+void SlaveMaster::recieve( const QCString& str, const QByteArray& at) {
+
+ ImageInfos infos;
+ PixmapInfos pixinfos;
+
+ QDataStream stream( at, IO_ReadOnly );
+ if ( str == "pixmapsHandled(PixmapList)" )
+ stream >> pixinfos;
+ else if ( str == "pixmapsHandled(StringList)" )
+ stream >> infos;
+
+ qWarning( "PixInfos %d", pixinfos.count() );
+
+ bool got_data = ( !infos.isEmpty() || !pixinfos.isEmpty() );
+ if ( got_data ) {
+ emit sig_start();
+ for ( ImageInfos::Iterator _it = infos.begin(); _it != infos.end(); ++_it ) {
+ if ( (*_it).kind )
+ emit sig_fullInfo( (*_it).file, (*_it).info );
+ else
+ emit sig_thumbInfo( (*_it).file, (*_it).info );
+ }
+
+ for ( PixmapInfos::Iterator it = pixinfos.begin(); it != pixinfos.end(); ++it )
+ emit sig_thumbNail( (*it).file, (*it).pixmap );
+ emit sig_end();
+ }
+}
+
+void SlaveMaster::slotTimerStart() {
+ m_started = false;
+
+ if ( !m_inThumbInfo.isEmpty() ) {
+ QCopEnvelope env("QPE/opie-eye_slave", "thumbInfos(QStringList)" );
+ env << m_inThumbInfo;
+ }
+ if ( !m_inImageInfo.isEmpty() ) {
+ QCopEnvelope env("QPE/opie-eye_slave", "fullInfos(QStringList)" );
+ env << m_inImageInfo;
+ }
+ if ( !m_inThumbNail.isEmpty() ) {
+ QCopEnvelope env("QPE/opie-eye_slave", "pixmapInfos(PixmapInfos)" );
+ env << m_inThumbNail;
+ }
+
+
+ m_inThumbInfo.clear();
+ m_inImageInfo.clear();
+ m_inThumbNail.clear();
+}
+
+QImage SlaveMaster::image( const QString& str, PDirLister::Factor, int ) {
+ return QImage();
+}
diff --git a/noncore/graphics/opie-eye/lib/slavemaster.h b/noncore/graphics/opie-eye/lib/slavemaster.h
new file mode 100644
index 0000000..f5284a6
--- a/dev/null
+++ b/noncore/graphics/opie-eye/lib/slavemaster.h
@@ -0,0 +1,43 @@
+#ifndef OPIE_EYE_SLAVE_MASTER_H
+#define OPIE_EYE_SLAVE_MASTER_H
+
+#include <iface/dirlister.h>
+#include <iface/slaveiface.h>
+
+#include <qobject.h>
+#include <qstring.h>
+#include <qsize.h>
+
+class SlaveMaster : public QObject {
+ Q_OBJECT
+ typedef QValueList<ImageInfo> ImageInfos;
+ typedef QValueList<PixmapInfo> PixmapInfos;
+public:
+ static SlaveMaster *self();
+
+ void thumbInfo( const QString& );
+ void imageInfo( const QString& );
+ void thumbNail( const QString&, int w, int h );
+ QImage image( const QString&, PDirLister::Factor, int );
+signals:
+ void sig_start();
+ void sig_end();
+
+ void sig_thumbInfo( const QString&, const QString& );
+ void sig_fullInfo( const QString&, const QString& );
+ void sig_thumbNail( const QString&, const QPixmap& );
+private slots:
+ void recieve( const QCString&, const QByteArray& );
+ void slotTimerStart();
+private:
+ SlaveMaster();
+ ~SlaveMaster();
+ static SlaveMaster *m_master;
+ bool m_started : 1;
+ QStringList m_inThumbInfo;
+ QStringList m_inImageInfo;
+ PixmapInfos m_inThumbNail;
+};
+
+
+#endif
diff --git a/noncore/graphics/opie-eye/lib/viewmap.cpp b/noncore/graphics/opie-eye/lib/viewmap.cpp
new file mode 100644
index 0000000..ca242b7
--- a/dev/null
+++ b/noncore/graphics/opie-eye/lib/viewmap.cpp
@@ -0,0 +1,25 @@
+#include <iface/dirview.h>
+
+
+namespace {
+ ViewMap *_viewMap = 0;
+ PDirView *_dirView = 0;
+}
+
+
+ViewMap *viewMap() {
+ if ( !_viewMap )
+ _viewMap = new ViewMap;
+
+ return _viewMap;
+}
+
+
+PDirView* currentView(){
+ return _dirView;
+}
+
+
+void setCurrentView( PDirView* view ) {
+ _dirView = view;
+}