Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

slavemaster.cpp

Go to the documentation of this file.
00001 #include "slavemaster.h"
00002 
00003 /* OPIE */
00004 #include <opie2/odebug.h>
00005 #include <qpe/qpeapplication.h>
00006 #include <qpe/qcopenvelope_qws.h>
00007 using namespace Opie::Core;
00008 
00009 /* QT */
00010 #include <qcopchannel_qws.h>
00011 #include <qtimer.h>
00012 
00013 QDataStream & operator << (QDataStream & str, bool b)
00014 {
00015   str << Q_INT8(b);
00016   return str;
00017 }
00018 QDataStream & operator >> (QDataStream & str, bool & b)
00019 {
00020   Q_INT8 l;
00021   str >> l;
00022   b = bool(l);
00023   return str;
00024 }
00025 
00026 /*
00027  * ! We don't put a Pixmap in!!!!
00028  */
00029 QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) {
00030     owarn << "Image request is " << inf.file.latin1() << " " << inf.width << " " << inf.height << "" << oendl;
00031     return s << inf.file  << inf.width << inf.height;
00032 }
00033 QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) {
00034     s >> inf.file >> inf.pixmap >> inf.width >> inf.height;
00035     return s;
00036 }
00037 QDataStream &operator<<( QDataStream& s, const ImageInfo& i) {
00038     return s << i.kind << i.file << i.info;
00039 }
00040 QDataStream &operator>>( QDataStream& s, ImageInfo& i ) {
00041     s >> i.kind >> i.file >> i.info;
00042     return s;
00043 }
00044 
00045 
00046 
00047 SlaveMaster* SlaveMaster::m_master = 0;
00048 
00049 SlaveMaster::SlaveMaster()
00050     : m_started( false )
00051 {
00052     QCopChannel *chan= new QCopChannel( "QPE/opie-eye",this );
00053     connect(chan, SIGNAL(received(const QCString&,const QByteArray&)),
00054             this, SLOT(recieve(const QCString&,const QByteArray&)) );
00055 }
00056 
00057 SlaveMaster::~SlaveMaster() {
00058 }
00059 
00060 SlaveMaster* SlaveMaster::self() {
00061     if ( !m_master )
00062         m_master = new SlaveMaster;
00063     return m_master;
00064 }
00065 
00066 void SlaveMaster::thumbInfo( const QString& str) {
00067     m_inThumbInfo.append( str );
00068 
00069     if ( !m_started ) {
00070         QTimer::singleShot( 0, this, SLOT(slotTimerStart()));
00071         m_started = true;
00072     }
00073 }
00074 
00075 void SlaveMaster::imageInfo( const QString& str ) {
00076     m_inImageInfo.append( str );
00077     if ( !m_started ) {
00078         QTimer::singleShot( 0, this, SLOT(slotTimerStart()));
00079         m_started = true;
00080     }
00081 }
00082 
00083 void SlaveMaster::thumbNail( const QString& str, int w, int h ) {
00084     if ( str.isEmpty() ) {
00085         owarn << "Asking for empty nail" << oendl;
00086         return;
00087     }
00088     owarn << "Asking for thumbNail in size " << w << " " << h << "" + str << oendl;
00089     PixmapInfo item;
00090     item.file = str; item.width = w; item.height = h;
00091     item.pixmap = QPixmap();
00092     m_inThumbNail.append( item );
00093 
00094     if ( !m_started ) {
00095         QTimer::singleShot( 0, this, SLOT(slotTimerStart()));
00096         m_started = true;
00097     }
00098 }
00099 
00100 
00101 void SlaveMaster::recieve( const QCString& str, const QByteArray& at) {
00102 
00103     ImageInfos infos;
00104     PixmapInfos pixinfos;
00105 
00106     QDataStream stream( at, IO_ReadOnly );
00107     if ( str == "pixmapsHandled(PixmapList)" )
00108         stream >> pixinfos;
00109     else if ( str == "pixmapsHandled(StringList)" )
00110         stream >> infos;
00111 
00112     owarn << "PixInfos " << pixinfos.count() << "" << oendl;
00113 
00114     bool got_data = ( !infos.isEmpty() || !pixinfos.isEmpty() );
00115     if ( got_data ) {
00116         emit sig_start();
00117         for ( ImageInfos::Iterator _it = infos.begin(); _it != infos.end(); ++_it ) {
00118             if (  (*_it).kind )
00119                 emit  sig_fullInfo( (*_it).file, (*_it).info );
00120             else
00121                 emit sig_thumbInfo( (*_it).file, (*_it).info );
00122         }
00123 
00124         for ( PixmapInfos::Iterator it = pixinfos.begin(); it != pixinfos.end(); ++it )
00125             emit sig_thumbNail(  (*it).file, (*it).pixmap );
00126         emit sig_end();
00127     }
00128 }
00129 
00130 void SlaveMaster::slotTimerStart() {
00131     m_started = false;
00132 
00133     if ( !m_inThumbInfo.isEmpty() ) {
00134         QCopEnvelope env("QPE/opie-eye_slave", "thumbInfos(QStringList)" );
00135         env << m_inThumbInfo;
00136     }
00137     if ( !m_inImageInfo.isEmpty() ) {
00138         QCopEnvelope env("QPE/opie-eye_slave", "fullInfos(QStringList)" );
00139         env << m_inImageInfo;
00140     }
00141     if ( !m_inThumbNail.isEmpty() ) {
00142         QCopEnvelope env("QPE/opie-eye_slave", "pixmapInfos(PixmapInfos)" );
00143         env << m_inThumbNail;
00144     }
00145 
00146 
00147     m_inThumbInfo.clear();
00148     m_inImageInfo.clear();
00149     m_inThumbNail.clear();
00150 }
00151 
00152 QImage SlaveMaster::image( const QString& , PDirLister::Factor, int ) {
00153     return QImage();
00154 }
00155 
00156 
00157 namespace SlaveHelper {
00158 void slaveConnectSignals( QObject* target ) {
00159     SlaveMaster* master = SlaveMaster::self();
00160 
00161     QObject::connect( master, SIGNAL(sig_start()), target, SIGNAL(sig_start()) );
00162     QObject::connect( master, SIGNAL(sig_end()), target, SIGNAL(sig_end()) );
00163     QObject::connect( master, SIGNAL(sig_thumbInfo(const QString&, const QString&)),
00164                       target, SIGNAL(sig_thumbInfo(const QString&, const QString&)) );
00165     QObject::connect( master, SIGNAL(sig_fullInfo(const QString&, const QString&)),
00166                       target, SIGNAL(sig_fullInfo(const QString&, const QString&)) );
00167     QObject::connect( master, SIGNAL(sig_thumbNail(const QString&, const QPixmap&)),
00168                       target, SIGNAL(sig_thumbNail(const QString&, const QPixmap&)) );
00169 }
00170 }

Generated on Sat Nov 5 16:17:30 2005 for OPIE by  doxygen 1.4.2