Diffstat (limited to 'noncore/graphics/opie-eye/lib/slavemaster.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/graphics/opie-eye/lib/slavemaster.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
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 @@ | |||
1 | #include "slavemaster.h" | ||
2 | |||
3 | #include <qpe/qpeapplication.h> | ||
4 | #include <qpe/qcopenvelope_qws.h> | ||
5 | |||
6 | #include <qcopchannel_qws.h> | ||
7 | #include <qtimer.h> | ||
8 | |||
9 | QDataStream & operator << (QDataStream & str, bool b) | ||
10 | { | ||
11 | str << Q_INT8(b); | ||
12 | return str; | ||
13 | } | ||
14 | QDataStream & operator >> (QDataStream & str, bool & b) | ||
15 | { | ||
16 | Q_INT8 l; | ||
17 | str >> l; | ||
18 | b = bool(l); | ||
19 | return str; | ||
20 | } | ||
21 | QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) { | ||
22 | return s << inf.file << inf.pixmap << inf.width << inf.height; | ||
23 | } | ||
24 | QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) { | ||
25 | s >> inf.file >> inf.pixmap >> inf.width >> inf.height; | ||
26 | return s; | ||
27 | } | ||
28 | QDataStream &operator<<( QDataStream& s, const ImageInfo& i) { | ||
29 | return s << i.kind << i.file << i.info; | ||
30 | } | ||
31 | QDataStream &operator>>( QDataStream& s, ImageInfo& i ) { | ||
32 | s >> i.kind >> i.file >> i.info; | ||
33 | return s; | ||
34 | } | ||
35 | |||
36 | |||
37 | |||
38 | SlaveMaster* SlaveMaster::m_master = 0; | ||
39 | |||
40 | SlaveMaster::SlaveMaster() | ||
41 | : m_started( false ) | ||
42 | { | ||
43 | QCopChannel *chan= new QCopChannel( "QPE/opie-eye",this ); | ||
44 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&)), | ||
45 | this, SLOT(recieve(const QCString&,const QByteArray&)) ); | ||
46 | } | ||
47 | |||
48 | SlaveMaster::~SlaveMaster() { | ||
49 | } | ||
50 | |||
51 | SlaveMaster* SlaveMaster::self() { | ||
52 | if ( !m_master ) | ||
53 | m_master = new SlaveMaster; | ||
54 | return m_master; | ||
55 | } | ||
56 | |||
57 | void SlaveMaster::thumbInfo( const QString& str) { | ||
58 | m_inThumbInfo.append( str ); | ||
59 | |||
60 | if ( !m_started ) { | ||
61 | QTimer::singleShot( 0, this, SLOT(slotTimerStart())); | ||
62 | m_started = true; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | void SlaveMaster::imageInfo( const QString& str ) { | ||
67 | m_inImageInfo.append( str ); | ||
68 | if ( !m_started ) { | ||
69 | QTimer::singleShot( 0, this, SLOT(slotTimerStart())); | ||
70 | m_started = true; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | void SlaveMaster::thumbNail( const QString& str, int w, int h ) { | ||
75 | if ( str.isEmpty() ) { | ||
76 | qWarning( "Asking for empty nail" ); | ||
77 | return; | ||
78 | } | ||
79 | qWarning( "Asking for thumbNail in size %d %d" + str, w,h ); | ||
80 | PixmapInfo item; | ||
81 | item.file = str; item.width = w; item.height = h; | ||
82 | item.pixmap = QPixmap(); | ||
83 | m_inThumbNail.append( item ); | ||
84 | |||
85 | if ( !m_started ) { | ||
86 | QTimer::singleShot( 0, this, SLOT(slotTimerStart())); | ||
87 | m_started = true; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | |||
92 | void SlaveMaster::recieve( const QCString& str, const QByteArray& at) { | ||
93 | |||
94 | ImageInfos infos; | ||
95 | PixmapInfos pixinfos; | ||
96 | |||
97 | QDataStream stream( at, IO_ReadOnly ); | ||
98 | if ( str == "pixmapsHandled(PixmapList)" ) | ||
99 | stream >> pixinfos; | ||
100 | else if ( str == "pixmapsHandled(StringList)" ) | ||
101 | stream >> infos; | ||
102 | |||
103 | qWarning( "PixInfos %d", pixinfos.count() ); | ||
104 | |||
105 | bool got_data = ( !infos.isEmpty() || !pixinfos.isEmpty() ); | ||
106 | if ( got_data ) { | ||
107 | emit sig_start(); | ||
108 | for ( ImageInfos::Iterator _it = infos.begin(); _it != infos.end(); ++_it ) { | ||
109 | if ( (*_it).kind ) | ||
110 | emit sig_fullInfo( (*_it).file, (*_it).info ); | ||
111 | else | ||
112 | emit sig_thumbInfo( (*_it).file, (*_it).info ); | ||
113 | } | ||
114 | |||
115 | for ( PixmapInfos::Iterator it = pixinfos.begin(); it != pixinfos.end(); ++it ) | ||
116 | emit sig_thumbNail( (*it).file, (*it).pixmap ); | ||
117 | emit sig_end(); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | void SlaveMaster::slotTimerStart() { | ||
122 | m_started = false; | ||
123 | |||
124 | if ( !m_inThumbInfo.isEmpty() ) { | ||
125 | QCopEnvelope env("QPE/opie-eye_slave", "thumbInfos(QStringList)" ); | ||
126 | env << m_inThumbInfo; | ||
127 | } | ||
128 | if ( !m_inImageInfo.isEmpty() ) { | ||
129 | QCopEnvelope env("QPE/opie-eye_slave", "fullInfos(QStringList)" ); | ||
130 | env << m_inImageInfo; | ||
131 | } | ||
132 | if ( !m_inThumbNail.isEmpty() ) { | ||
133 | QCopEnvelope env("QPE/opie-eye_slave", "pixmapInfos(PixmapInfos)" ); | ||
134 | env << m_inThumbNail; | ||
135 | } | ||
136 | |||
137 | |||
138 | m_inThumbInfo.clear(); | ||
139 | m_inImageInfo.clear(); | ||
140 | m_inThumbNail.clear(); | ||
141 | } | ||
142 | |||
143 | QImage SlaveMaster::image( const QString& str, PDirLister::Factor, int ) { | ||
144 | return QImage(); | ||
145 | } | ||