37
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Widget for displaying attachment media objects.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "univiewerattachmentwidget.h"
|
|
19 |
|
|
20 |
// SYSTEM INCLUDES
|
|
21 |
#include <HbIconItem>
|
|
22 |
#include <HbTextItem>
|
|
23 |
#include <HbFrameItem>
|
|
24 |
#include <HbMenu>
|
|
25 |
#include <HbEffect>
|
|
26 |
#include <HbTapGesture>
|
|
27 |
#include <HbInstantFeedback>
|
|
28 |
|
|
29 |
#include <QFileInfo>
|
|
30 |
#include <QTimer>
|
|
31 |
|
|
32 |
// USER INCLUDES
|
|
33 |
#include "univiewerutils.h"
|
|
34 |
#include "unidatamodelplugininterface.h"
|
|
35 |
|
|
36 |
// LOCAL CONSTANTS
|
|
37 |
#define LOC_OPEN hbTrId("txt_common_menu_open")
|
|
38 |
#define LOC_SAVE_TO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
|
|
39 |
|
|
40 |
const QString BG_FRAME_NORMAL("qtg_fr_list_normal");
|
|
41 |
const QString BG_FRAME_PRESSED("qtg_fr_list_pressed");
|
|
42 |
const QString ATTACHMENT_ICON("qtg_small_attachment");
|
|
43 |
const QString CORRUPTED_ATTACH_ICON("qtg_small_corrupted");
|
|
44 |
const QString VCARD_MIMETYPE("text/X-vCard");
|
|
45 |
|
|
46 |
const int KILOBYTE = 1024;
|
|
47 |
|
|
48 |
//----------------------------------------------------------------------------
|
|
49 |
// UniViewerAttachmentWidget::UniViewerAttachmentWidget
|
|
50 |
// @see header file
|
|
51 |
//----------------------------------------------------------------------------
|
|
52 |
UniViewerAttachmentWidget::UniViewerAttachmentWidget(QGraphicsItem *parent) :
|
|
53 |
HbWidget(parent), mMediaIcon(0), mName(0), mInfo(0), mFrameItem(0), mViewerUtils(0)
|
|
54 |
{
|
|
55 |
this->grabGesture(Qt::TapGesture);
|
|
56 |
|
|
57 |
setProperty("state", "normal");
|
|
58 |
|
|
59 |
mMediaIcon = new HbIconItem(this);
|
|
60 |
HbStyle::setItemName(mMediaIcon, "mediaIcon");
|
|
61 |
|
|
62 |
mName = new HbTextItem(this);
|
|
63 |
HbStyle::setItemName(mName, "text-1");
|
|
64 |
|
|
65 |
mInfo = new HbTextItem(this);
|
|
66 |
HbStyle::setItemName(mInfo, "text-2");
|
|
67 |
|
|
68 |
mFrameItem = new HbFrameItem(BG_FRAME_NORMAL, HbFrameDrawer::NinePieces, this);
|
|
69 |
HbStyle::setItemName(mFrameItem, "bgFrame");
|
|
70 |
|
|
71 |
HbEffect::add("attachmentWidget", "listviewitem_press", "pressed");
|
|
72 |
HbEffect::add("attachmentWidget", "listviewitem_release", "released");
|
|
73 |
}
|
|
74 |
|
|
75 |
//----------------------------------------------------------------------------
|
|
76 |
// UniViewerAttachmentWidget::~UniViewerAttachmentWidget
|
|
77 |
// @see header file
|
|
78 |
//----------------------------------------------------------------------------
|
|
79 |
UniViewerAttachmentWidget::~UniViewerAttachmentWidget()
|
|
80 |
{
|
|
81 |
}
|
|
82 |
|
|
83 |
//----------------------------------------------------------------------------
|
|
84 |
// UniViewerAttachmentWidget::populate
|
|
85 |
// @see header file
|
|
86 |
//----------------------------------------------------------------------------
|
|
87 |
void UniViewerAttachmentWidget::populate(UniMessageInfo *info)
|
|
88 |
{
|
|
89 |
mMimeType = info->mimetype();
|
|
90 |
mMediaPath = info->path();
|
|
91 |
|
|
92 |
QString attachIcon;
|
|
93 |
if (info->isProtected()) {
|
|
94 |
attachIcon = ATTACHMENT_ICON;
|
|
95 |
}
|
|
96 |
else if (info->isCorrupted()) {
|
|
97 |
attachIcon = CORRUPTED_ATTACH_ICON;
|
|
98 |
}
|
|
99 |
else {
|
|
100 |
attachIcon = ATTACHMENT_ICON;
|
|
101 |
}
|
|
102 |
|
|
103 |
mMediaIcon->setIconName(attachIcon);
|
|
104 |
QFileInfo fileInfo(mMediaPath);
|
|
105 |
mName->setText(fileInfo.fileName());
|
|
106 |
|
|
107 |
QString sizeString('B');
|
|
108 |
int fileSize = fileInfo.size();
|
|
109 |
if (fileSize > KILOBYTE) {
|
|
110 |
// Convert to Kilobytes.
|
|
111 |
fileSize /= KILOBYTE;
|
|
112 |
sizeString = "Kb";
|
|
113 |
}
|
|
114 |
QString fileDetails = "(" + QString::number(fileSize) + sizeString + ")";
|
|
115 |
mInfo->setText(fileDetails);
|
|
116 |
}
|
|
117 |
|
|
118 |
//----------------------------------------------------------------------------
|
|
119 |
// UniViewerAttachmentWidget::resizeEvent
|
|
120 |
// @see header file
|
|
121 |
//----------------------------------------------------------------------------
|
|
122 |
void UniViewerAttachmentWidget::gestureEvent(QGestureEvent *event)
|
|
123 |
{
|
|
124 |
HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture));
|
|
125 |
if (tapGesture) {
|
|
126 |
switch (tapGesture->state()) {
|
|
127 |
case Qt::GestureStarted:
|
|
128 |
{
|
|
129 |
// Trigger haptic feedback.
|
|
130 |
HbInstantFeedback::play(HbFeedback::Basic);
|
|
131 |
setPressed(true);
|
|
132 |
break;
|
|
133 |
}
|
|
134 |
case Qt::GestureUpdated:
|
|
135 |
{
|
|
136 |
if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) {
|
|
137 |
// Handle longtap.
|
|
138 |
setPressed(false);
|
|
139 |
handleLongTap(tapGesture->scenePosition());
|
|
140 |
}
|
|
141 |
break;
|
|
142 |
}
|
|
143 |
case Qt::GestureFinished:
|
|
144 |
{
|
|
145 |
HbInstantFeedback::play(HbFeedback::Basic);
|
|
146 |
if (HbTapGesture::Tap == tapGesture->tapStyleHint()) {
|
|
147 |
// Handle short tap.
|
|
148 |
setPressed(false);
|
|
149 |
handleShortTap();
|
|
150 |
}
|
|
151 |
break;
|
|
152 |
}
|
|
153 |
case Qt::GestureCanceled:
|
|
154 |
{
|
|
155 |
HbInstantFeedback::play(HbFeedback::Basic);
|
|
156 |
setPressed(false);
|
|
157 |
break;
|
|
158 |
}
|
|
159 |
}
|
|
160 |
}
|
|
161 |
else {
|
|
162 |
HbWidget::gestureEvent(event);
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|
|
166 |
//----------------------------------------------------------------------------
|
|
167 |
// UniViewerAttachmentWidget::handleOpen
|
|
168 |
// @see header file
|
|
169 |
//----------------------------------------------------------------------------
|
|
170 |
void UniViewerAttachmentWidget::handleOpen()
|
|
171 |
{
|
|
172 |
this->ungrabGesture(Qt::TapGesture);
|
|
173 |
|
|
174 |
if (!mViewerUtils) {
|
|
175 |
mViewerUtils = new UniViewerUtils(this);
|
|
176 |
}
|
|
177 |
mViewerUtils->launchContentViewer(mMimeType, mMediaPath);
|
|
178 |
|
|
179 |
//fire timer to regrab gesture after some delay.
|
|
180 |
QTimer::singleShot(300,this,SLOT(regrabGesture()));
|
|
181 |
}
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
//----------------------------------------------------------------------------
|
|
186 |
// UniViewerAttachmentWidget::handleShortTap
|
|
187 |
// @see header file
|
|
188 |
//----------------------------------------------------------------------------
|
|
189 |
void UniViewerAttachmentWidget::handleShortTap()
|
|
190 |
{
|
|
191 |
emit shortTap(mMediaPath);
|
|
192 |
|
|
193 |
// Open the media.
|
|
194 |
handleOpen();
|
|
195 |
}
|
|
196 |
|
|
197 |
//----------------------------------------------------------------------------
|
|
198 |
// UniViewerAttachmentWidget::handleLongTap
|
|
199 |
// @see header file
|
|
200 |
//----------------------------------------------------------------------------
|
|
201 |
void UniViewerAttachmentWidget::handleLongTap(const QPointF &position)
|
|
202 |
{
|
|
203 |
emit longTap(position);
|
|
204 |
|
|
205 |
// Display context sensitive menu.
|
|
206 |
HbMenu* menu = new HbMenu;
|
|
207 |
menu->setAttribute(Qt::WA_DeleteOnClose);
|
|
208 |
menu->setPreferredPos(position);
|
|
209 |
|
|
210 |
if (mMimeType.contains(VCARD_MIMETYPE, Qt::CaseInsensitive)) {
|
|
211 |
// For vcard opening & saving is same.
|
|
212 |
menu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(handleOpen()));
|
|
213 |
}
|
|
214 |
else {
|
|
215 |
menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
|
62
|
216 |
|
37
|
217 |
}
|
|
218 |
|
|
219 |
menu->show();
|
|
220 |
}
|
|
221 |
|
|
222 |
//----------------------------------------------------------------------------
|
|
223 |
// UniViewerAttachmentWidget::setPressed
|
|
224 |
// @see header file
|
|
225 |
//----------------------------------------------------------------------------
|
|
226 |
void UniViewerAttachmentWidget::setPressed(bool pressed)
|
|
227 |
{
|
|
228 |
if (pressed) {
|
|
229 |
setProperty("state", "pressed");
|
|
230 |
mFrameItem->frameDrawer().setFrameGraphicsName(BG_FRAME_PRESSED);
|
|
231 |
HbEffect::cancel(mFrameItem, "released");
|
|
232 |
HbEffect::start(mFrameItem, "attachmentWidget", "pressed");
|
|
233 |
|
|
234 |
}
|
|
235 |
else {
|
|
236 |
setProperty("state", "normal");
|
|
237 |
mFrameItem->frameDrawer().setFrameGraphicsName(BG_FRAME_NORMAL);
|
|
238 |
HbEffect::cancel(mFrameItem, "pressed");
|
|
239 |
HbEffect::start(mFrameItem, "attachmentWidget", "released");
|
|
240 |
}
|
|
241 |
}
|
|
242 |
|
|
243 |
//---------------------------------------------------------------
|
|
244 |
// UniViewerAttachmentWidget::regrabGesture
|
|
245 |
// @see header file
|
|
246 |
//---------------------------------------------------------------
|
|
247 |
void UniViewerAttachmentWidget::regrabGesture()
|
|
248 |
{
|
|
249 |
this->grabGesture(Qt::TapGesture);
|
|
250 |
}
|
|
251 |
// EOF
|