summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/slave/slavereciever.cpp
authorzecke <zecke>2004-03-22 23:32:41 (UTC)
committer zecke <zecke>2004-03-22 23:32:41 (UTC)
commit428b687982966dc2efabaf6dbcc55ad0ea30aa10 (patch) (unidiff)
tree86da20abd2e4b97a59dc32e17996bde5ee74cc91 /noncore/graphics/opie-eye/slave/slavereciever.cpp
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/slave/slavereciever.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/slave/slavereciever.cpp214
1 files changed, 214 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/slave/slavereciever.cpp b/noncore/graphics/opie-eye/slave/slavereciever.cpp
new file mode 100644
index 0000000..951f3df
--- a/dev/null
+++ b/noncore/graphics/opie-eye/slave/slavereciever.cpp
@@ -0,0 +1,214 @@
1/*
2 * GPLv2 zecke@handhelds.org
3 */
4
5#include "slavereciever.h"
6#include "slaveiface.h"
7
8#include <qpe/qcopenvelope_qws.h>
9#include <qpe/qpeapplication.h>
10
11#include <qtimer.h>
12
13static SlaveObjects* _slaveObj = 0;
14
15QDataStream & operator << (QDataStream & str, bool b)
16{
17 str << Q_INT8(b);
18 return str;
19}
20
21QDataStream & operator >> (QDataStream & str, bool & b)
22{
23 Q_INT8 l;
24 str >> l;
25 b = bool(l);
26 return str;
27}
28
29
30
31QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) {
32 return s << inf.file << inf.pixmap << inf.width << inf.height;
33}
34QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) {
35 s >> inf.file >> inf.pixmap >> inf.width >> inf.height;
36 return s;
37}
38QDataStream &operator<<( QDataStream& s, const ImageInfo& i) {
39 return s << i.kind << i.file << i.info;
40}
41QDataStream &operator>>( QDataStream& s, ImageInfo& i ) {
42 s >> i.kind >> i.file >> i.info;
43 return s;
44}
45
46
47
48SlaveObjects* slaveObjects() {
49 if ( !_slaveObj )
50 _slaveObj = new SlaveObjects;
51 return _slaveObj;
52}
53
54SlaveReciever::SlaveReciever( QObject* par)
55 : QObject( par )
56{
57 m_inf = new QTimer(this);
58 connect(m_inf,SIGNAL(timeout()),
59 this, SLOT(slotImageInfo()));
60 m_pix = new QTimer(this);
61 connect(m_pix,SIGNAL(timeout()),
62 this, SLOT(slotThumbNail()));
63
64 m_out = new QTimer(this);
65 connect(m_out,SIGNAL(timeout()),
66 this, SLOT(slotSend()));
67
68 SlaveObjects *obj = slaveObjects(); // won't be changed
69 SlaveMap::Iterator it;
70 SlaveMap* map = slaveMap(); // SlaveMap won't be changed during execution!!!
71 for(it = map->begin(); it != map->end(); ++it ) {
72 obj->insert( it.key(), (*it.data())() );
73 }
74}
75
76SlaveReciever::~SlaveReciever() {
77}
78
79void SlaveReciever::recieveAnswer( const QCString& string, const QByteArray& ar) {
80 qWarning( "String is %s", string.data() );
81 QDataStream stream(ar, IO_ReadOnly );
82 QStringList lst;
83 static ImageInfo inf;
84 static PixmapInfo pix;
85
86 if ( string == "thumbInfo(QString)" ) {
87 stream >> inf.file;
88 m_inList.append(inf);
89 }else if ( string == "thumbInfos(QStringList)" ) {
90 stream >> lst;
91 for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
92 qWarning( "Adding thumbinfo for file "+ *it );
93 inf.file = (*it);
94 m_inList.append(inf);
95 }
96 }else if ( string == "fullInfo(QString)" ) {
97 inf.kind = true;
98 stream >> inf.file;
99 m_inList.append(inf);
100 }else if ( string == "fullInfos(QStringList)" ) {
101 stream >> lst;
102 for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
103 qWarning( "Adding fullInfo for"+ *it );
104 inf.file = (*it);
105 inf.kind = true;
106 m_inList.append(inf);
107 }
108 }else if ( string == "pixmapInfo(QString,int,int)" ) {
109 stream >> pix.file >> pix.width >> pix.height;
110 m_inPix.append(pix);
111 }else if ( string == "pixmapInfos(PixmapInfos)" ) {
112 PixmapList list;
113 stream >> list;
114 for(PixmapList::Iterator it = list.begin(); it != list.end(); ++it ) {
115 qWarning( "Got %d %d " + (*it).file, (*it).width , (*it).height );
116 m_inPix.append(*it);
117 }
118 }
119
120 if (!m_inf->isActive() && !m_inList.isEmpty() )
121 m_inf->start(5);
122
123 if (!m_pix->isActive() && !m_inPix.isEmpty() )
124 m_pix->start(5);
125
126 QPEApplication::setKeepRunning();
127
128}
129
130PixmapList SlaveReciever::outPix()const {
131 return m_outPix;
132}
133
134StringList SlaveReciever::outInf()const{
135 return m_outList;
136}
137
138void SlaveReciever::slotImageInfo() {
139 ImageInfo inf = m_inList.first();
140 m_inList.remove( inf );
141
142 static SlaveObjects::Iterator it;
143 static SlaveObjects* map = slaveObjects(); // SlaveMap won't be changed during execution!!!
144 for(it = map->begin(); it != map->end(); ++it ) {
145 if( (*it)->supports(inf.file ) ) {
146 /* full image info */
147 if (inf.kind )
148 inf.info = (*it)->fullImageInfo( inf.file );
149 else
150 inf.info = (*it)->iconViewName( inf.file );
151 m_outList.append( inf );
152 break;
153 }
154 }
155
156 if (m_inList.isEmpty() )
157 m_inf->stop();
158 if (!m_out->isActive() && !m_outList.isEmpty() )
159 m_out->start( 100 );
160}
161
162void SlaveReciever::slotThumbNail() {
163 PixmapInfo inf = m_inPix.first();
164 m_inPix.remove( inf );
165
166 static SlaveObjects::Iterator it;
167 static SlaveObjects* map = slaveObjects(); // SlaveMap won't be changed during execution!!!
168 for(it = map->begin(); it != map->end(); ++it ) {
169 SlaveInterface* iface = it.data();
170 if( iface->supports(inf.file ) ) {
171 /* pixmap */
172 qWarning( "Asking for thumbNail in size %d %d for "+inf.file, inf.width, inf.height );
173 inf.pixmap = iface->pixmap(inf.file, 64, 64);
174 m_outPix.append( inf );
175 break;
176 }
177 }
178
179
180
181 if(m_inPix.isEmpty() )
182 m_pix->stop();
183 if(!m_out->isActive() && !m_outPix.isEmpty() )
184 m_out->start(100);
185}
186
187void SlaveReciever::slotSend() {
188
189 m_out->stop();
190
191 qWarning( "Sending %d %d", outPix().count(), outInf().count() );
192 /* queue it and send */
193 /* if this ever gets a service introduce request queues
194 * so we can differinatate between different clients
195 */
196 if (! m_outPix.isEmpty() ) {
197 QCopEnvelope answer("QPE/opie-eye", "pixmapsHandled(PixmapList)" );
198 answer << outPix();
199 for ( PixmapList::Iterator it = m_outPix.begin();it!=m_outPix.end();++it ) {
200 qWarning( "Sending out %s %d %d", (*it).file.latin1(), (*it).width, (*it).height );
201 }
202 }
203 if ( !m_outList.isEmpty() ) {
204 QCopEnvelope answer("QPE/opie-eye", "pixmapsHandled(StringList)" );
205 answer << outInf();
206 for ( StringList::Iterator it = m_outList.begin();it!=m_outList.end();++it ) {
207 qWarning( "Sending out2 " + (*it).file );
208 }
209 }
210
211 m_outList.clear();
212 m_outPix.clear();
213}
214