30 #include <HbMainWindow> |
31 #include <HbMainWindow> |
31 #include <HbInstance> |
32 #include <HbInstance> |
32 #include <HbGesture> |
33 #include <HbGesture> |
33 #include <HbGestureSceneFilter> |
34 #include <HbGestureSceneFilter> |
34 |
35 |
35 #include "debugtraces.h" |
36 #include <xqaiwrequest.h> |
|
37 #include <xqrequestinfo.h> |
|
38 #include <xqappmgr.h> |
|
39 |
36 #include "univiewertextitem.h" |
40 #include "univiewertextitem.h" |
37 |
41 #include "msgmediautil.h" |
38 // LOCAL CONSTANTS |
42 // LOCAL CONSTANTS |
39 const QString AUDIO_ICON("qtg_mono_audio.svg"); |
43 const QString AUDIO_ICON("qtg_mono_audio"); |
|
44 |
|
45 // Localization |
|
46 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
40 |
47 |
41 //--------------------------------------------------------------- |
48 //--------------------------------------------------------------- |
42 //UniViewerBodyWidget::UniViewerBodyWidget |
49 //UniViewerBodyWidget::UniViewerBodyWidget |
43 // @see header file |
50 // @see header file |
44 //--------------------------------------------------------------- |
51 //--------------------------------------------------------------- |
45 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : |
52 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : |
46 HbWidget(parent), mHasText(false), mTextItem(0), mIconItem(0), mAudioItem(0) |
53 HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0), |
47 { |
54 mIconItem(0), mAudioItem(0) |
48 //This is permanent item in the widget |
55 { |
49 mTextItem = new UniViewerTextItem(this); |
|
50 HbStyle::setItemName(mTextItem, "textItem"); |
|
51 |
|
52 //Gesture filter for the image |
56 //Gesture filter for the image |
53 gestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this); |
57 gestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this); |
54 gestureFilter->setLongpressAnimation(true); |
58 gestureFilter->setLongpressAnimation(true); |
55 HbGesture *gesture = new HbGesture(HbGesture::longpress, 20); |
59 HbGesture *gesture = new HbGesture(HbGesture::longpress, 20); |
56 gestureFilter->addGesture(gesture); |
60 gestureFilter->addGesture(gesture); |
57 connect(gesture, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF))); |
61 connect(gesture, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF))); |
58 |
62 // Signal mapper for opening media files |
59 connect(mTextItem,SIGNAL(sendMessage(const QString&)), |
63 mSignalMapper = new QSignalMapper(this); |
60 this, SIGNAL(sendMessage(const QString&))); |
64 connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &))); |
61 } |
65 } |
62 |
66 |
63 //--------------------------------------------------------------- |
67 //--------------------------------------------------------------- |
64 //UniViewerBodyWidget::~UniViewerBodyWidget |
68 //UniViewerBodyWidget::~UniViewerBodyWidget |
65 // @see header file |
69 // @see header file |
72 //UniViewerBodyWidget::setImage |
76 //UniViewerBodyWidget::setImage |
73 // @see header file |
77 // @see header file |
74 //--------------------------------------------------------------- |
78 //--------------------------------------------------------------- |
75 void UniViewerBodyWidget::setImage(QString imagefile) |
79 void UniViewerBodyWidget::setImage(QString imagefile) |
76 { |
80 { |
|
81 setHasPixmap(true); |
77 //create image item instance |
82 //create image item instance |
78 if (!mIconItem) { |
83 if (!mIconItem) { |
79 mIconItem = new HbIconItem(this); |
84 mIconItem = new HbIconItem(this); |
80 HbStyle::setItemName(mIconItem, "pixmap"); |
85 HbStyle::setItemName(mIconItem, "pixmap"); |
81 } |
86 } |
82 |
87 |
83 QPixmap pixmap(imagefile); |
88 QPixmap pixmap(imagefile); |
84 mIconItem->setIcon(HbIcon(pixmap)); |
89 mIconItem->setIcon(HbIcon(pixmap)); |
|
90 |
|
91 // TODO |
|
92 // Implementation for short tap action is unclear |
|
93 // Connect to signal mapper |
|
94 |
85 this->repolish(); |
95 this->repolish(); |
86 } |
96 } |
87 |
97 |
88 //--------------------------------------------------------------- |
98 //--------------------------------------------------------------- |
89 //UniViewerBodyWidget::setAudio |
99 //UniViewerBodyWidget::setAudio |
96 HbStyle::setItemName(mAudioItem, "audioItem"); |
106 HbStyle::setItemName(mAudioItem, "audioItem"); |
97 } |
107 } |
98 QFileInfo fileInfo(audiofile); |
108 QFileInfo fileInfo(audiofile); |
99 mAudioItem->setIcon(HbIcon(AUDIO_ICON)); |
109 mAudioItem->setIcon(HbIcon(AUDIO_ICON)); |
100 mAudioItem->setText(fileInfo.baseName()); |
110 mAudioItem->setText(fileInfo.baseName()); |
101 mAudioItem->setAdditionalText("00:00"); |
111 MsgMediaUtil mediaUtil; |
|
112 mAudioItem->setAdditionalText(mediaUtil.mediaDuration(audiofile)); |
102 mAudioItem->setTextAlignment(Qt::AlignLeft); |
113 mAudioItem->setTextAlignment(Qt::AlignLeft); |
|
114 |
|
115 // Connect to signal mapper with file name |
|
116 mSignalMapper->setMapping(mAudioItem, audiofile); |
|
117 connect(mAudioItem, SIGNAL(clicked()), mSignalMapper, SLOT(map())); |
|
118 |
103 this->repolish(); |
119 this->repolish(); |
104 } |
120 } |
105 |
121 |
106 //--------------------------------------------------------------- |
122 //--------------------------------------------------------------- |
107 //UniViewerBodyWidget::setVideo |
123 //UniViewerBodyWidget::setVideo |
108 // @see header file |
124 // @see header file |
109 //--------------------------------------------------------------- |
125 //--------------------------------------------------------------- |
110 void UniViewerBodyWidget::setVideo(QString videofile) |
126 void UniViewerBodyWidget::setVideo(QString videofile) |
111 { |
127 { |
112 Q_UNUSED(videofile) |
128 Q_UNUSED(videofile) |
|
129 } |
|
130 |
|
131 //--------------------------------------------------------------- |
|
132 //UniViewerBodyWidget::setTextContent |
|
133 // @see header file |
|
134 //--------------------------------------------------------------- |
|
135 void UniViewerBodyWidget::setTextContent(QString text) |
|
136 { |
|
137 setHasText(true); |
|
138 |
|
139 if (!mTextItem) { |
|
140 mTextItem = new UniViewerTextItem(this); |
|
141 HbStyle::setItemName(mTextItem, "textItem"); |
|
142 connect(mTextItem, SIGNAL(sendMessage(const QString&)), this, |
|
143 SIGNAL(sendMessage(const QString&))); |
|
144 } |
|
145 text.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
|
146 text.replace('\r', QChar::LineSeparator); |
|
147 mTextItem->setText(text); |
|
148 this->repolish(); |
|
149 } |
|
150 |
|
151 //--------------------------------------------------------------- |
|
152 //UniViewerBodyWidget::setTextContent |
|
153 // @see header file |
|
154 //--------------------------------------------------------------- |
|
155 void UniViewerBodyWidget::setSlideCounter(QString &slideCounter) |
|
156 { |
|
157 if (!mSlideCounter) { |
|
158 mSlideCounter = new HbTextItem(this); |
|
159 HbStyle::setItemName(mSlideCounter, "slideCounter"); |
|
160 } |
|
161 |
|
162 mSlideCounter->setText(slideCounter); |
|
163 this->repolish(); |
|
164 } |
|
165 |
|
166 //--------------------------------------------------------------- |
|
167 // UniViewerBodyWidget::setHasText |
|
168 // @see header file |
|
169 //--------------------------------------------------------------- |
|
170 void UniViewerBodyWidget::setHasText(bool text) |
|
171 { |
|
172 mHasText = text; |
|
173 } |
|
174 |
|
175 //--------------------------------------------------------------- |
|
176 // UniViewerBodyWidget::hasText |
|
177 // @see header file |
|
178 //--------------------------------------------------------------- |
|
179 bool UniViewerBodyWidget::hasText() |
|
180 { |
|
181 return mHasText; |
|
182 } |
|
183 |
|
184 //--------------------------------------------------------------- |
|
185 // UniViewerBodyWidget::setHasPixmap |
|
186 // @see header file |
|
187 //--------------------------------------------------------------- |
|
188 void UniViewerBodyWidget::setHasPixmap(bool pixmap) |
|
189 { |
|
190 mHasPixmap = pixmap; |
|
191 } |
|
192 |
|
193 //--------------------------------------------------------------- |
|
194 // UniViewerBodyWidget::hasPixmap |
|
195 // @see header file |
|
196 //--------------------------------------------------------------- |
|
197 bool UniViewerBodyWidget::hasPixmap() |
|
198 { |
|
199 return mHasPixmap; |
|
200 } |
|
201 |
|
202 //--------------------------------------------------------------- |
|
203 // UniViewerBodyWidget::setSlideContents |
|
204 // @see header file |
|
205 //--------------------------------------------------------------- |
|
206 void UniViewerBodyWidget::setSlideContents(UniMessageInfoList objList, QString slideString) |
|
207 { |
|
208 if (!slideString.isEmpty()) { |
|
209 setSlideCounter(slideString); |
|
210 } |
|
211 |
|
212 int count = objList.count(); |
|
213 for (int a = 0; a < count; ++a) { |
|
214 UniMessageInfo* info = objList.at(a); |
|
215 QString type = info->mimetype(); |
|
216 |
|
217 if (type.contains("text")) { |
|
218 QFile file(info->path()); |
|
219 if (file.open(QIODevice::ReadOnly)) |
|
220 { |
|
221 QString textContent(file.readAll()); |
|
222 setTextContent(textContent); |
|
223 } |
|
224 |
|
225 } |
|
226 else if (type.contains("video")) { |
|
227 setVideo(info->path()); |
|
228 } |
|
229 else if (type.contains("audio")) { |
|
230 setAudio(info->path()); |
|
231 } |
|
232 else if (type.contains("image")) { |
|
233 setImage(info->path()); |
|
234 } |
|
235 |
|
236 delete info; |
|
237 } |
|
238 } |
|
239 |
|
240 //--------------------------------------------------------------- |
|
241 //UniViewerBodyWidget :: clearContent |
|
242 // @see header file |
|
243 //--------------------------------------------------------------- |
|
244 void UniViewerBodyWidget::clearContent() |
|
245 { |
|
246 // delete the temp items(pixmap) & clear permanent items(text) |
|
247 if (mIconItem) { |
|
248 mIconItem->setParent(NULL); |
|
249 delete mIconItem; |
|
250 mIconItem = NULL; |
|
251 } |
|
252 |
|
253 if (mAudioItem) { |
|
254 mAudioItem->setParent(NULL); |
|
255 delete mAudioItem; |
|
256 mAudioItem = NULL; |
|
257 } |
|
258 |
|
259 if (mTextItem) { |
|
260 mTextItem->setParent(NULL); |
|
261 delete mTextItem; |
|
262 mTextItem = NULL; |
|
263 } |
|
264 |
|
265 setHasText(false); |
|
266 setHasPixmap(false); |
|
267 repolish(); |
113 } |
268 } |
114 |
269 |
115 //--------------------------------------------------------------- |
270 //--------------------------------------------------------------- |
116 //UniViewerBodyWidget::resizeEvent |
271 //UniViewerBodyWidget::resizeEvent |
117 // @see header file |
272 // @see header file |
127 qreal leftMargin = 0.0; |
282 qreal leftMargin = 0.0; |
128 qreal rightMargin = 0.0; |
283 qreal rightMargin = 0.0; |
129 qreal chromeHeight = 0.0; |
284 qreal chromeHeight = 0.0; |
130 qreal toolbarHeight = 0.0; |
285 qreal toolbarHeight = 0.0; |
131 qreal iconSize = 0.0; |
286 qreal iconSize = 0.0; |
|
287 qreal unitSize = HbDeviceProfile::profile(mIconItem).unitValue(); |
132 style()->parameter("hb-param-screen-width", screenWidth); |
288 style()->parameter("hb-param-screen-width", screenWidth); |
133 style()->parameter("hb-param-screen-height", screenHeight); |
289 style()->parameter("hb-param-screen-height", screenHeight); |
134 style()->parameter("hb-param-margin-gene-left", leftMargin); |
290 style()->parameter("hb-param-margin-gene-left", leftMargin); |
135 style()->parameter("hb-param-margin-gene-right", rightMargin); |
291 style()->parameter("hb-param-margin-gene-right", rightMargin); |
136 style()->parameter("hb-param-widget-chrome-height", chromeHeight); |
292 style()->parameter("hb-param-widget-chrome-height", chromeHeight); |
190 } |
349 } |
191 if (heightToSet == maxHeight) { |
350 if (heightToSet == maxHeight) { |
192 widthToSet = heightToSet * (imageWidth / imageHeight); |
351 widthToSet = heightToSet * (imageWidth / imageHeight); |
193 } |
352 } |
194 |
353 |
195 mIconItem->setMinimumWidth(widthToSet); |
354 mIconItem->setPreferredWidth(widthToSet); |
196 mIconItem->setMinimumHeight(heightToSet); |
355 mIconItem->setPreferredHeight(heightToSet); |
197 mIconItem->setMaximumWidth(widthToSet); |
|
198 mIconItem->setMaximumHeight(heightToSet); |
|
199 } |
356 } |
200 } |
357 } |
201 } |
358 } |
202 |
359 |
203 //--------------------------------------------------------------- |
360 //--------------------------------------------------------------- |
204 //UniViewerBodyWidget::longPressed |
361 //UniViewerBodyWidget::longPressed |
205 // @see header file |
362 // @see header file |
206 //--------------------------------------------------------------- |
363 //--------------------------------------------------------------- |
207 void UniViewerBodyWidget::longPressed(QPointF position) |
364 void UniViewerBodyWidget::longPressed(QPointF position) |
208 { |
365 { |
|
366 |
209 HbMenu* menu = new HbMenu; |
367 HbMenu* menu = new HbMenu; |
210 menu->addAction(tr("Open"), this, SLOT(openMedia())); |
368 menu->addAction(tr("Open"), this, SLOT(openMedia())); |
211 menu->addAction(tr("View details"), this, SLOT(viewDetails())); |
369 menu->addAction(tr("View details"), this, SLOT(viewDetails())); |
212 menu->exec(position); |
370 menu->exec(position); |
213 delete menu; |
371 delete menu; |
217 //UniViewerBodyWidget::openMedia |
375 //UniViewerBodyWidget::openMedia |
218 // @see header file |
376 // @see header file |
219 //--------------------------------------------------------------- |
377 //--------------------------------------------------------------- |
220 void UniViewerBodyWidget::openMedia() |
378 void UniViewerBodyWidget::openMedia() |
221 { |
379 { |
222 //open corresponding viewer app. |
380 } |
|
381 |
|
382 //--------------------------------------------------------------- |
|
383 //UniViewerBodyWidget::openMedia |
|
384 // @see header file |
|
385 //--------------------------------------------------------------- |
|
386 void UniViewerBodyWidget::openMedia(const QString& fileName) |
|
387 { |
|
388 XQSharableFile sf; |
|
389 XQAiwRequest* request = 0; |
|
390 |
|
391 if (!sf.open(fileName)) { |
|
392 return; |
|
393 } |
|
394 |
|
395 // Get handlers |
|
396 XQApplicationManager appManager; |
|
397 QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf); |
|
398 if (fileHandlers.count() > 0) { |
|
399 XQAiwInterfaceDescriptor d = fileHandlers.first(); |
|
400 request = appManager.create(sf, d); |
|
401 |
|
402 if (!request) { |
|
403 sf.close(); |
|
404 return; |
|
405 } |
|
406 } |
|
407 else { |
|
408 sf.close(); |
|
409 return; |
|
410 } |
|
411 |
|
412 // Result handlers |
|
413 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
414 connect(request, SIGNAL(requestError(const QVariant&)), this, |
|
415 SLOT(handleError(const QVariant&))); |
|
416 |
|
417 request->setEmbedded(true); |
|
418 request->setSynchronous(true); |
|
419 |
|
420 // Fill args |
|
421 QList<QVariant> args; |
|
422 args << qVariantFromValue(sf); |
|
423 request->setArguments(args); |
|
424 |
|
425 // Fill headers |
|
426 QString key("WindowTitle"); |
|
427 QVariant value(QString(LOC_TITLE)); |
|
428 XQRequestInfo info; |
|
429 info.setInfo(key, value); |
|
430 request->setInfo(info); |
|
431 |
|
432 request->send(); |
|
433 |
|
434 // Cleanup |
|
435 sf.close(); |
|
436 delete request; |
223 } |
437 } |
224 |
438 |
225 //--------------------------------------------------------------- |
439 //--------------------------------------------------------------- |
226 //UniViewerBodyWidget::viewDetails |
440 //UniViewerBodyWidget::viewDetails |
227 // @see header file |
441 // @see header file |
230 { |
444 { |
231 //open details view. |
445 //open details view. |
232 } |
446 } |
233 |
447 |
234 //--------------------------------------------------------------- |
448 //--------------------------------------------------------------- |
235 //UniViewerBodyWidget::setTextContent |
449 // UniViewerBodyWidget :: handleOk |
236 // @see header file |
450 // @see header file |
237 //--------------------------------------------------------------- |
451 //--------------------------------------------------------------- |
238 void UniViewerBodyWidget::setTextContent(QString text) |
452 void UniViewerBodyWidget::handleOk(const QVariant& result) |
239 { |
453 { |
240 text.replace('\n', QChar::LineSeparator); |
454 Q_UNUSED(result) |
241 mTextItem->setText(text); |
455 } |
242 setHasText(true); |
456 |
243 } |
457 //--------------------------------------------------------------- |
244 |
458 // UniViewerBodyWidget :: handleError |
245 //--------------------------------------------------------------- |
459 // @see header file |
246 // UniViewerBodyWidget::hasText |
460 //--------------------------------------------------------------- |
247 // @see header file |
461 void UniViewerBodyWidget::handleError(int errorCode, const QString& errorMessage) |
248 //--------------------------------------------------------------- |
462 { |
249 bool UniViewerBodyWidget::hasText() |
463 Q_UNUSED(errorMessage) |
250 { |
464 Q_UNUSED(errorCode) |
251 return mHasText; |
465 } |
252 } |
|
253 |
|
254 //--------------------------------------------------------------- |
|
255 // UniViewerBodyWidget::setHasText |
|
256 // @see header file |
|
257 //--------------------------------------------------------------- |
|
258 void UniViewerBodyWidget::setHasText(bool text) |
|
259 { |
|
260 mHasText = text; |
|
261 } |
|
262 |
|
263 //--------------------------------------------------------------- |
|
264 // UniViewerBodyWidget::setSlideContents |
|
265 // @see header file |
|
266 //--------------------------------------------------------------- |
|
267 void UniViewerBodyWidget::setSlideContents(UniMessageInfoList objList, QString slideString) |
|
268 { |
|
269 Q_UNUSED(slideString) |
|
270 |
|
271 int count = objList.count(); |
|
272 |
|
273 for (int a = 0; a < count; ++a) { |
|
274 UniMessageInfo* info = objList.at(a); |
|
275 QString type = info->mimetype(); |
|
276 |
|
277 if (type.contains("video")) { |
|
278 setVideo(info->path()); |
|
279 } |
|
280 else if (type.contains("audio")) { |
|
281 setAudio(info->path()); |
|
282 } |
|
283 if (type.contains("image")) { |
|
284 setImage(info->path()); |
|
285 } |
|
286 else if (type.contains("text")) { |
|
287 QFile file(info->path()); |
|
288 file.open(QIODevice::ReadOnly); |
|
289 QString textContent(file.readAll()); |
|
290 setTextContent(textContent); |
|
291 } |
|
292 delete info; |
|
293 } |
|
294 } |
|
295 |
|
296 //--------------------------------------------------------------- |
|
297 //UniViewerBodyWidget :: clearContent |
|
298 // @see header file |
|
299 //--------------------------------------------------------------- |
|
300 void UniViewerBodyWidget::clearContent() |
|
301 { |
|
302 // delete the temp items(pixmap) & clear permanent items(text) |
|
303 if (mIconItem) { |
|
304 mIconItem->setParent(NULL); |
|
305 delete mIconItem; |
|
306 mIconItem = NULL; |
|
307 } |
|
308 |
|
309 if (mAudioItem) { |
|
310 mAudioItem->setParent(NULL); |
|
311 delete mAudioItem; |
|
312 mAudioItem = NULL; |
|
313 } |
|
314 |
|
315 mTextItem->setText(QString()); |
|
316 setHasText(false); |
|
317 } |
|
318 |
|
319 // EOF |
466 // EOF |