-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/slavemaster.cpp | 7 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/slave/slavereciever.cpp | 7 |
3 files changed, 17 insertions, 3 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index 0b80012..38a621e 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp @@ -1,296 +1,300 @@ /* * GPLv2 zecke@handhelds.org * No WArranty... */ #include "iconview.h" #include <lib/imagecache.h> #include <iface/dirview.h> #include <iface/dirlister.h> #include <qpe/config.h> #include <qpe/resource.h> #include <qpe/qpemessagebox.h> #include <qpe/ir.h> #include <qpe/qcopenvelope_qws.h> #include <qiconview.h> #include <qlabel.h> #include <qhbox.h> #include <qcombobox.h> #include <qdir.h> #include <qapplication.h> #include <qmainwindow.h> #include <qtimer.h> #include <qstyle.h> namespace { QPixmap* _dirPix = 0; QPixmap* _unkPix = 0; class IconViewItem : public QIconViewItem { public: IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); QPixmap* pixmap()const; QString path()const { return m_path; } bool isDir()const { return m_isDir; } void setText( const QString& ); private: mutable QPixmap* m_pix; QString m_path; bool m_isDir : 1; bool m_noInfo :1; }; /* * If we request an Image or String * we add it to the map */ QMap<QString, IconViewItem*> g_stringInf; QMap<QString, IconViewItem*> g_stringPix; IconViewItem::IconViewItem( QIconView* view,const QString& path, const QString& name, bool isDir ) : QIconViewItem( view ), m_path( path ), m_isDir( isDir ), m_noInfo( false ) { QIconViewItem::setText( name ); if ( isDir && !_dirPix ) _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); else if ( !isDir && !_unkPix ) _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); } inline QPixmap* IconViewItem::pixmap()const { if ( m_isDir ) return _dirPix; else{ if (!m_noInfo && !g_stringInf.contains( m_path ) ) { currentView()->dirLister()->imageInfo( m_path ); g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); } m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); if ( !m_pix && !g_stringPix.contains( m_path )) { currentView()->dirLister()->thumbNail( m_path, 64, 64 ); g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); } return m_pix ? m_pix : _unkPix; } } inline void IconViewItem::setText( const QString& str ) { QString text = QIconViewItem::text()+"\n"+str; m_noInfo = true; QIconViewItem::setText( text ); } } PIconView::PIconView( QWidget* wid, Config* cfg ) : QVBox( wid ), m_cfg( cfg ) { { - QCopEnvelope( "QPE/Application/opie-eye_slave", "foo()" ); +// QCopEnvelope( "QPE/Application/opie-eye_slave", "foo()" ); } m_path = QDir::homeDirPath(); QHBox *hbox = new QHBox( this ); QLabel* lbl = new QLabel( hbox ); lbl->setText( tr("View as" ) ); m_views = new QComboBox( hbox, "View As" ); connect( m_views, SIGNAL(activated(int)), this, SLOT(slotViewChanged(int)) ); m_view= new QIconView( this ); connect(m_view, SIGNAL(clicked(QIconViewItem*) ), this, SLOT(slotClicked(QIconViewItem*)) ); m_view->setArrangement( QIconView::LeftToRight ); m_view->setItemTextPos( QIconView::Right ); int dw = QApplication::desktop()->width(); int viewerWidth = dw-style().scrollBarExtent().width(); m_view->setGridX( viewerWidth-2*m_view->spacing() ); m_view->setGridY( fontMetrics().height()*2+40 ); loadViews(); slotViewChanged( m_views->currentItem() ); } PIconView::~PIconView() { } void PIconView::slotDirUp() { QDir dir( m_path ); dir.cdUp(); slotChangeDir( dir.absPath() ); } void PIconView::slotChangeDir(const QString& path) { if ( !currentView() ) return; PDirLister *lister = currentView()->dirLister(); if (!lister ) return; lister->setStartPath( path ); m_path = lister->currentPath(); m_view->clear(); addFolders( lister->folders() ); addFiles( lister->files() ); + // Also invalidate the cache. We can't cancel the operations anyway + g_stringPix.clear(); + g_stringInf.clear(); + // looks ugly static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); } QString PIconView::currentFileName(bool &isDir)const { isDir = false; QIconViewItem* _it = m_view->currentItem(); if ( !_it ) return QString::null; IconViewItem* it = static_cast<IconViewItem*>( _it ); isDir = it->isDir(); return it->path(); } void PIconView::slotTrash() { bool isDir; QString pa = currentFileName( isDir ); if ( isDir && pa.isEmpty() ) return; if (!QPEMessageBox::confirmDelete( this, tr("Delete Image" ), tr("the Image %1" ).arg(pa))) return currentView()->dirLister()->deleteImage( pa ); delete m_view->currentItem(); } void PIconView::loadViews() { ViewMap::Iterator it; ViewMap* map = viewMap(); for ( it = map->begin(); it != map->end(); ++it ) m_views->insertItem( QObject::tr(it.key() ) ); } void PIconView::resetView() { slotViewChanged(m_views->currentItem()); } void PIconView::slotViewChanged( int i) { if (!m_views->count() ) { setCurrentView( 0l); return; } PDirView* cur = currentView(); delete cur; QString str = m_views->text(i); cur = (*(*viewMap())[str])(*m_cfg); setCurrentView( cur ); /* connect to the signals of the lister */ PDirLister* lis = cur->dirLister(); connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), this, SLOT( slotThumbInfo(const QString&, const QString&))); connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), this, SLOT(slotThumbNail(const QString&, const QPixmap&))); connect(lis, SIGNAL(sig_start()), this, SLOT(slotStart())); connect(lis, SIGNAL(sig_end()) , this, SLOT(slotEnd()) ); /* reload now */ QTimer::singleShot( 0, this, SLOT(slotReloadDir())); } void PIconView::slotReloadDir() { slotChangeDir( m_path ); } void PIconView::addFolders( const QStringList& lst) { QStringList::ConstIterator it; for(it=lst.begin(); it != lst.end(); ++it ) { (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); } } void PIconView::addFiles( const QStringList& lst) { QStringList::ConstIterator it; for (it=lst.begin(); it!= lst.end(); ++it ) (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); } void PIconView::slotClicked(QIconViewItem* _it) { if(!_it ) return; IconViewItem* it = static_cast<IconViewItem*>(_it); if( it->isDir() ) slotChangeDir( it->path() ); else // view image ; } void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { if ( g_stringInf.contains( _path ) ) { IconViewItem* item = g_stringInf[_path]; item->setText( str ); item->repaint(); g_stringInf.remove( _path ); } } void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { if ( g_stringPix.contains( _path ) ) { IconViewItem* item = g_stringPix[_path]; PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); item->repaint(); g_stringPix.remove( _path ); } } void PIconView::slotRename() { } void PIconView::slotBeam() { bool isDir; QString pa = currentFileName( isDir ); if ( isDir && pa.isEmpty() ) return; Ir* ir = new Ir( this ); connect( ir, SIGNAL(done(Ir*)), this, SLOT(slotBeamDone(Ir*))); ir->send(pa, tr( "Image" ) ); } void PIconView::slotBeamDone( Ir* ir) { delete ir; } void PIconView::slotStart() { m_view->setUpdatesEnabled( false ); } void PIconView::slotEnd() { m_view->setUpdatesEnabled( true ); } diff --git a/noncore/graphics/opie-eye/lib/slavemaster.cpp b/noncore/graphics/opie-eye/lib/slavemaster.cpp index 18dc883..4e28535 100644 --- a/noncore/graphics/opie-eye/lib/slavemaster.cpp +++ b/noncore/graphics/opie-eye/lib/slavemaster.cpp @@ -1,145 +1,150 @@ #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; } + +/* + * ! We don't put a Pixmap in!!!! + */ QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) { - return s << inf.file << inf.pixmap << inf.width << inf.height; + qWarning( "Image request is %s %d %d", inf.file.latin1(), inf.width, inf.height ); + return s << inf.file << 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/slave/slavereciever.cpp b/noncore/graphics/opie-eye/slave/slavereciever.cpp index 951f3df..c8e33d4 100644 --- a/noncore/graphics/opie-eye/slave/slavereciever.cpp +++ b/noncore/graphics/opie-eye/slave/slavereciever.cpp @@ -1,214 +1,219 @@ /* * GPLv2 zecke@handhelds.org */ #include "slavereciever.h" #include "slaveiface.h" #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qtimer.h> static SlaveObjects* _slaveObj = 0; 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; } + +/* + * GUI sends no QPIxmap!!! + */ QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) { - s >> inf.file >> inf.pixmap >> inf.width >> inf.height; + s >> inf.file >> inf.width >> inf.height; + qWarning( "Recieved %s %d %d", inf.file.latin1(), 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; } SlaveObjects* slaveObjects() { if ( !_slaveObj ) _slaveObj = new SlaveObjects; return _slaveObj; } SlaveReciever::SlaveReciever( QObject* par) : QObject( par ) { m_inf = new QTimer(this); connect(m_inf,SIGNAL(timeout()), this, SLOT(slotImageInfo())); m_pix = new QTimer(this); connect(m_pix,SIGNAL(timeout()), this, SLOT(slotThumbNail())); m_out = new QTimer(this); connect(m_out,SIGNAL(timeout()), this, SLOT(slotSend())); SlaveObjects *obj = slaveObjects(); // won't be changed SlaveMap::Iterator it; SlaveMap* map = slaveMap(); // SlaveMap won't be changed during execution!!! for(it = map->begin(); it != map->end(); ++it ) { obj->insert( it.key(), (*it.data())() ); } } SlaveReciever::~SlaveReciever() { } void SlaveReciever::recieveAnswer( const QCString& string, const QByteArray& ar) { qWarning( "String is %s", string.data() ); QDataStream stream(ar, IO_ReadOnly ); QStringList lst; static ImageInfo inf; static PixmapInfo pix; if ( string == "thumbInfo(QString)" ) { stream >> inf.file; m_inList.append(inf); }else if ( string == "thumbInfos(QStringList)" ) { stream >> lst; for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { qWarning( "Adding thumbinfo for file "+ *it ); inf.file = (*it); m_inList.append(inf); } }else if ( string == "fullInfo(QString)" ) { inf.kind = true; stream >> inf.file; m_inList.append(inf); }else if ( string == "fullInfos(QStringList)" ) { stream >> lst; for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { qWarning( "Adding fullInfo for"+ *it ); inf.file = (*it); inf.kind = true; m_inList.append(inf); } }else if ( string == "pixmapInfo(QString,int,int)" ) { stream >> pix.file >> pix.width >> pix.height; m_inPix.append(pix); }else if ( string == "pixmapInfos(PixmapInfos)" ) { PixmapList list; stream >> list; for(PixmapList::Iterator it = list.begin(); it != list.end(); ++it ) { qWarning( "Got %d %d " + (*it).file, (*it).width , (*it).height ); m_inPix.append(*it); } } if (!m_inf->isActive() && !m_inList.isEmpty() ) m_inf->start(5); if (!m_pix->isActive() && !m_inPix.isEmpty() ) m_pix->start(5); QPEApplication::setKeepRunning(); } PixmapList SlaveReciever::outPix()const { return m_outPix; } StringList SlaveReciever::outInf()const{ return m_outList; } void SlaveReciever::slotImageInfo() { ImageInfo inf = m_inList.first(); m_inList.remove( inf ); static SlaveObjects::Iterator it; static SlaveObjects* map = slaveObjects(); // SlaveMap won't be changed during execution!!! for(it = map->begin(); it != map->end(); ++it ) { if( (*it)->supports(inf.file ) ) { /* full image info */ if (inf.kind ) inf.info = (*it)->fullImageInfo( inf.file ); else inf.info = (*it)->iconViewName( inf.file ); m_outList.append( inf ); break; } } if (m_inList.isEmpty() ) m_inf->stop(); if (!m_out->isActive() && !m_outList.isEmpty() ) m_out->start( 100 ); } void SlaveReciever::slotThumbNail() { PixmapInfo inf = m_inPix.first(); m_inPix.remove( inf ); static SlaveObjects::Iterator it; static SlaveObjects* map = slaveObjects(); // SlaveMap won't be changed during execution!!! for(it = map->begin(); it != map->end(); ++it ) { SlaveInterface* iface = it.data(); if( iface->supports(inf.file ) ) { /* pixmap */ qWarning( "Asking for thumbNail in size %d %d for "+inf.file, inf.width, inf.height ); inf.pixmap = iface->pixmap(inf.file, 64, 64); m_outPix.append( inf ); break; } } if(m_inPix.isEmpty() ) m_pix->stop(); if(!m_out->isActive() && !m_outPix.isEmpty() ) m_out->start(100); } void SlaveReciever::slotSend() { m_out->stop(); qWarning( "Sending %d %d", outPix().count(), outInf().count() ); /* queue it and send */ /* if this ever gets a service introduce request queues * so we can differinatate between different clients */ if (! m_outPix.isEmpty() ) { QCopEnvelope answer("QPE/opie-eye", "pixmapsHandled(PixmapList)" ); answer << outPix(); for ( PixmapList::Iterator it = m_outPix.begin();it!=m_outPix.end();++it ) { qWarning( "Sending out %s %d %d", (*it).file.latin1(), (*it).width, (*it).height ); } } if ( !m_outList.isEmpty() ) { QCopEnvelope answer("QPE/opie-eye", "pixmapsHandled(StringList)" ); answer << outInf(); for ( StringList::Iterator it = m_outList.begin();it!=m_outList.end();++it ) { qWarning( "Sending out2 " + (*it).file ); } } m_outList.clear(); m_outPix.clear(); } |