|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 #include "debugtraces.h" |
|
20 #include <HbTextItem> |
|
21 #include <HbIconItem> |
|
22 #include <QFileInfo> |
|
23 #include <QFont> |
|
24 #include <HbFrameDrawer> |
|
25 #include <HbMenu> |
|
26 #include <MsgMimeTypes.h> |
|
27 #include <HbFrameItem> |
|
28 //#include <HbGestureSceneFilter> |
|
29 //#include <HbGesture> |
|
30 #include <QGraphicsSceneMouseEvent> |
|
31 #include <HbWidgetFeedback> |
|
32 |
|
33 // USER INCLUDES |
|
34 #include "msgunieditorattachment.h" |
|
35 #include "unieditorgenutils.h" |
|
36 #include "s60qconversions.h" |
|
37 |
|
38 // Constants |
|
39 #define BYTES_TO_KBYTES_FACTOR 1024 |
|
40 #define BG_FRAME "qtg_fr_groupbox" |
|
41 |
|
42 //Localized Constants for item specific menu |
|
43 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
44 #define LOC_REMOVE hbTrId("txt_common_menu_remove") |
|
45 #define LOC_DETAILS hbTrId("txt_common_menu_details") |
|
46 |
|
47 const QString LIST_ITEM_BG_FRAME_NORMAL ("qtg_fr_list_normal"); |
|
48 const QString LIST_ITEM_BG_FRAME_PRESSED("qtg_fr_list_pressed"); |
|
49 |
|
50 const QString ATTACHMENT_ICON("qtg_small_attachment"); |
|
51 |
|
52 MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& attachmentpath, |
|
53 const int filesize, |
|
54 QGraphicsItem *parent ) : |
|
55 HbWidget(parent), |
|
56 mPath(attachmentpath), |
|
57 mSize(filesize), |
|
58 mAttachmentIcon(0), |
|
59 mAttachmentName(0), |
|
60 //mGestureFilter(0), |
|
61 mMaxSmsSize(KFirstNormalSmsLength) |
|
62 { |
|
63 //back ground |
|
64 HbFrameItem* backGround = new HbFrameItem(this); |
|
65 backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL); |
|
66 backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
67 this->setBackgroundItem(backGround); |
|
68 |
|
69 mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this); |
|
70 HbStyle::setItemName(mAttachmentIcon,"attachmentIcon"); |
|
71 |
|
72 int at_size = 0; |
|
73 TMsgMediaType mediaType = EMsgMediaUnknown; |
|
74 UniEditorGenUtils* genUtils = new UniEditorGenUtils; |
|
75 TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size, |
|
76 mMimeType,mediaType)); |
|
77 TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); |
|
78 delete genUtils; |
|
79 QFileInfo fileinfo(attachmentpath); |
|
80 QString filename = fileinfo.fileName(); |
|
81 mAttachmentName = new HbTextItem(filename,this); |
|
82 HbStyle::setItemName(mAttachmentName,"attachmentName"); |
|
83 mAttachmentName->setElideMode(Qt::ElideRight); |
|
84 |
|
85 // for sms, pure size should be shown |
|
86 // for mms, additional mimeheader size must be included |
|
87 qreal displaySize = mSize; |
|
88 if(!isMultimediaContent()) |
|
89 { |
|
90 displaySize = fileinfo.size(); |
|
91 } |
|
92 int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR; |
|
93 QString fileDetails; |
|
94 // if size exceeds 1kb, then show kb or else only bytes |
|
95 if(sizeInKb >= 1) |
|
96 { |
|
97 fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb)); |
|
98 } |
|
99 else |
|
100 { |
|
101 fileDetails = QString().append(QString("(%1 B)").arg(displaySize)); |
|
102 } |
|
103 |
|
104 mAttachmentDetails = new HbTextItem(fileDetails, this); |
|
105 HbStyle::setItemName(mAttachmentDetails,"attachmentDetails"); |
|
106 mAttachmentDetails->setElideMode(Qt::ElideNone); |
|
107 |
|
108 initGesture(); |
|
109 } |
|
110 |
|
111 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment() |
|
112 { |
|
113 /* if(mGestureFilter) |
|
114 { |
|
115 removeSceneEventFilter(mGestureFilter); |
|
116 }*/ |
|
117 } |
|
118 |
|
119 const QString& MsgUnifiedEditorAttachment::path() |
|
120 { |
|
121 return mPath; |
|
122 } |
|
123 |
|
124 qreal MsgUnifiedEditorAttachment::size() |
|
125 { |
|
126 return mSize; |
|
127 } |
|
128 |
|
129 const QString& MsgUnifiedEditorAttachment::mimeType() |
|
130 { |
|
131 return mMimeType; |
|
132 } |
|
133 |
|
134 void MsgUnifiedEditorAttachment::longPressed(QPointF position) |
|
135 { |
|
136 HbMenu* menu = new HbMenu; |
|
137 menu->addAction(LOC_OPEN, this, SLOT(openAttachment())); |
|
138 menu->addAction(LOC_REMOVE, this, SLOT(removeAttachment())); |
|
139 menu->addAction(LOC_DETAILS, this, SLOT(viewDetails())); |
|
140 menu->setDismissPolicy(HbPopup::TapAnywhere); |
|
141 menu->setAttribute(Qt::WA_DeleteOnClose, true); |
|
142 menu->setPreferredPos(position); |
|
143 menu->show(); |
|
144 } |
|
145 |
|
146 void MsgUnifiedEditorAttachment::removeAttachment() |
|
147 { |
|
148 emit deleteMe(this); |
|
149 } |
|
150 |
|
151 void MsgUnifiedEditorAttachment::openAttachment() |
|
152 { |
|
153 //open corresponding viewer app. |
|
154 } |
|
155 |
|
156 void MsgUnifiedEditorAttachment::viewDetails() |
|
157 { |
|
158 //open details view. |
|
159 } |
|
160 |
|
161 bool MsgUnifiedEditorAttachment::isMultimediaContent() |
|
162 { |
|
163 bool ret = true; |
|
164 QString vcard = S60QConversions::s60Desc8ToQString(KMsgMimeVCard()); |
|
165 QString vcal = S60QConversions::s60Desc8ToQString(KMsgMimeVCal()); |
|
166 QString ical = S60QConversions::s60Desc8ToQString(KMsgMimeICal()); |
|
167 if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) || |
|
168 !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) || |
|
169 !QString::compare(mMimeType, ical, Qt::CaseInsensitive) ) |
|
170 { |
|
171 QFileInfo fileinfo(mPath); |
|
172 int fSize = fileinfo.size(); |
|
173 |
|
174 // if filesize is within sms size-limit, then |
|
175 // it is not mm content, else it is mm attachment |
|
176 if(fSize <= mMaxSmsSize) |
|
177 { |
|
178 ret = false; |
|
179 } |
|
180 } |
|
181 return ret; |
|
182 } |
|
183 |
|
184 void MsgUnifiedEditorAttachment::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
185 { |
|
186 HbWidgetFeedback::triggered(this, Hb::InstantPressed); |
|
187 |
|
188 HbFrameItem* backGround = new HbFrameItem(this); |
|
189 backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED); |
|
190 backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
191 this->setBackgroundItem(backGround); |
|
192 |
|
193 event->accept(); |
|
194 } |
|
195 |
|
196 void MsgUnifiedEditorAttachment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
197 { |
|
198 HbFrameItem* backGround = new HbFrameItem(this); |
|
199 backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL); |
|
200 backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
201 this->setBackgroundItem(backGround); |
|
202 |
|
203 if(this->rect().contains(event->pos())) |
|
204 { |
|
205 HbWidgetFeedback::triggered(this, Hb::InstantClicked); |
|
206 emit clicked(); |
|
207 } |
|
208 |
|
209 event->accept(); |
|
210 } |
|
211 |
|
212 void MsgUnifiedEditorAttachment::initGesture() |
|
213 { |
|
214 // Create gesture filter |
|
215 /* mGestureFilter = new HbGestureSceneFilter( Qt::LeftButton, this ); |
|
216 |
|
217 // Add gestures for longpress |
|
218 HbGesture* gestureLongpressed = new HbGesture( HbGesture::longpress,5 ); |
|
219 |
|
220 mGestureFilter->addGesture( gestureLongpressed ); |
|
221 |
|
222 connect( gestureLongpressed, SIGNAL(longPress(QPointF)), |
|
223 this, SLOT(longPressed(QPointF)) ); |
|
224 |
|
225 //install gesture filter. |
|
226 this->installSceneEventFilter(mGestureFilter);*/ |
|
227 } |
|
228 |
|
229 /*HbFeedback::InstantEffect MsgUnifiedEditorAttachment::overrideFeedback(Hb::InstantInteraction interaction) const |
|
230 { |
|
231 switch(interaction) |
|
232 { |
|
233 case Hb::InstantPressed: |
|
234 case Hb::InstantClicked: |
|
235 return HbFeedback::Basic; |
|
236 default: |
|
237 return HbFeedback::None; |
|
238 } |
|
239 }*/ |
|
240 |
|
241 // EOF |