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

slavereciever.cpp

Go to the documentation of this file.
00001 /*
00002  * GPLv2 zecke@handhelds.org
00003  */
00004 
00005 #include "slavereciever.h"
00006 #include "slaveiface.h"
00007 
00008 /* OPIE */
00009 #include <opie2/odebug.h>
00010 #include <qpe/qcopenvelope_qws.h>
00011 #include <qpe/qpeapplication.h>
00012 using namespace Opie::Core;
00013 
00014 /* QT */
00015 #include <qtimer.h>
00016 
00017 static SlaveObjects* _slaveObj = 0;
00018 
00019 QDataStream & operator << (QDataStream & str, bool b)
00020 {
00021   str << Q_INT8(b);
00022   return str;
00023 }
00024 
00025 QDataStream & operator >> (QDataStream & str, bool & b)
00026 {
00027   Q_INT8 l;
00028   str >> l;
00029   b = bool(l);
00030   return str;
00031 }
00032 
00033 
00034 
00035 QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) {
00036     return s << inf.file << inf.pixmap << inf.width << inf.height;
00037 }
00038 
00039 /*
00040  * GUI sends no QPIxmap!!!
00041  */
00042 QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) {
00043     s >> inf.file >> inf.width >> inf.height;
00044     return s;
00045 }
00046 QDataStream &operator<<( QDataStream& s, const ImageInfo& i) {
00047     return s << i.kind << i.file << i.info;
00048 }
00049 QDataStream &operator>>( QDataStream& s, ImageInfo& i ) {
00050     s >> i.kind >> i.file >> i.info;
00051     return s;
00052 }
00053 
00054 
00055 
00056 SlaveObjects* slaveObjects() {
00057     if ( !_slaveObj )
00058         _slaveObj = new SlaveObjects;
00059     return _slaveObj;
00060 }
00061 
00062 SlaveReciever::SlaveReciever( QObject* par)
00063     : QObject( par ), m_refs( 0 )
00064 {
00065     m_inf = new QTimer(this);
00066     connect(m_inf,SIGNAL(timeout()),
00067             this, SLOT(slotImageInfo()));
00068     m_pix = new QTimer(this);
00069     connect(m_pix,SIGNAL(timeout()),
00070             this, SLOT(slotThumbNail()));
00071 
00072     m_out = new QTimer(this);
00073     connect(m_out,SIGNAL(timeout()),
00074             this, SLOT(slotSend()));
00075 
00076     SlaveObjects *obj = slaveObjects(); // won't be changed
00077     SlaveMap::Iterator it;
00078     SlaveMap* map = slaveMap(); // SlaveMap won't be changed during execution!!!
00079     for(it = map->begin(); it != map->end(); ++it ) {
00080         obj->insert( it.key(),  (*it.data())() );
00081     }
00082 }
00083 
00084 SlaveReciever::~SlaveReciever() {
00085 }
00086 
00087 void SlaveReciever::recieveAnswer( const QCString& string, const QByteArray& ar) {
00088     QDataStream stream(ar, IO_ReadOnly );
00089     QStringList lst;
00090     static ImageInfo  inf;
00091     static PixmapInfo pix;
00092 
00093     if ( string == "thumbInfo(QString)" ) {
00094         stream >> inf.file;
00095         inf.kind = false;
00096         m_inList.append(inf);
00097     }else if ( string == "thumbInfos(QStringList)" ) {
00098         stream >> lst;
00099         for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
00100             inf.file = (*it);
00101             inf.kind = false;
00102             m_inList.append(inf);
00103         }
00104     }else if ( string == "fullInfo(QString)" ) {
00105         inf.kind = true;
00106         stream >> inf.file;
00107         m_inList.append(inf);
00108     }else if ( string == "fullInfos(QStringList)" ) {
00109         stream >> lst;
00110         for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
00111             inf.file = (*it);
00112             inf.kind = true;
00113             m_inList.append(inf);
00114         }
00115     }else if ( string == "pixmapInfo(QString,int,int)" ) {
00116         stream >> pix.file >> pix.width >> pix.height;
00117         m_inPix.append(pix);
00118     }else if ( string == "pixmapInfos(PixmapInfos)" ) {
00119         PixmapList list;
00120         stream >> list;
00121         for(PixmapList::Iterator it = list.begin(); it != list.end(); ++it ) {
00122             m_inPix.append(*it);
00123         }
00124     }else if ( string == "refUp()" ) {
00125         m_refs++;
00126     }else if ( string == "refDown()" ) {
00127         m_refs--;
00128     }
00129 
00130     if (!m_inf->isActive() && !m_inList.isEmpty() )
00131         m_inf->start(5);
00132 
00133     if (!m_pix->isActive() && !m_inPix.isEmpty() )
00134         m_pix->start(5);
00135 
00136     if ( m_refs )
00137         QPEApplication::setKeepRunning();
00138     else
00139         qApp->quit();
00140 
00141 }
00142 
00143 PixmapList SlaveReciever::outPix()const {
00144     return m_outPix;
00145 }
00146 
00147 StringList SlaveReciever::outInf()const{
00148     return m_outList;
00149 }
00150 
00151 void SlaveReciever::slotImageInfo() {
00152     ImageInfo inf = m_inList.first();
00153     m_inList.remove( inf );
00154 
00155     static SlaveObjects::Iterator it;
00156     static SlaveObjects* map = slaveObjects(); // SlaveMap won't be changed during execution!!!
00157     for(it = map->begin(); it != map->end(); ++it ) {
00158         if( (*it)->supports(inf.file ) ) {
00159             /* full image info */
00160             if (inf.kind )
00161                 inf.info = (*it)->fullImageInfo( inf.file );
00162             else
00163                 inf.info = (*it)->iconViewName( inf.file );
00164             m_outList.append( inf );
00165             break;
00166         }
00167     }
00168 
00169     if (m_inList.isEmpty() )
00170         m_inf->stop();
00171     if (!m_out->isActive() && !m_outList.isEmpty() )
00172         m_out->start( 100 );
00173 }
00174 
00175 void SlaveReciever::slotThumbNail() {
00176     PixmapInfo inf = m_inPix.first();
00177     m_inPix.remove( inf );
00178 
00179     static SlaveObjects::Iterator it;
00180     static SlaveObjects* map = slaveObjects(); // SlaveMap won't be changed during execution!!!
00181     for(it = map->begin(); it != map->end(); ++it ) {
00182         SlaveInterface* iface = it.data();
00183         if( iface->supports(inf.file ) ) {
00184             /* pixmap */
00185             if (inf.width>256||inf.height>256) {
00186                 owarn << "Scaling thumbnail to 64x64 'cause " << inf.width<<"x"<<inf.height<<
00187                     " may be nonsense";
00188                 inf.pixmap = iface->pixmap(inf.file, 64, 64);
00189             }else {
00190                 inf.pixmap = iface->pixmap(inf.file, inf.width, inf.height);
00191             }
00192             m_outPix.append( inf );
00193             break;
00194         }
00195     }
00196 
00197 
00198 
00199     if(m_inPix.isEmpty() )
00200         m_pix->stop();
00201     if(!m_out->isActive() && !m_outPix.isEmpty() )
00202         m_out->start(100);
00203 }
00204 
00205 void SlaveReciever::slotSend() {
00206 
00207     m_out->stop();
00208 
00209     /* queue it and send */
00210     /* if this ever gets a service introduce request queues
00211      * so we can differinatate between different clients
00212      */
00213     if (! m_outPix.isEmpty() ) {
00214         QCopEnvelope answer("QPE/opie-eye", "pixmapsHandled(PixmapList)" );
00215         answer << outPix();
00216 #if 0
00217         for ( PixmapList::Iterator it = m_outPix.begin();it!=m_outPix.end();++it ) {
00218             owarn << "Sending out " << (*it).file.latin1() << " " << (*it).width << " " << (*it).height << "" << oendl;
00219         }
00220 #endif
00221     }
00222     if ( !m_outList.isEmpty() ) {
00223         QCopEnvelope answer("QPE/opie-eye", "pixmapsHandled(StringList)" );
00224         answer << outInf();
00225 #if 0
00226         for ( StringList::Iterator it = m_outList.begin();it!=m_outList.end();++it ) {
00227             owarn << "Sending out2 " + (*it).file << oendl;
00228         }
00229 #endif
00230     }
00231 
00232     m_outList.clear();
00233     m_outPix.clear();
00234 }
00235 

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