|
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 <HbPushButton> |
|
25 #include <HbFrameDrawer> |
|
26 #include <HbMenu> |
|
27 #include <MsgMimeTypes.h> |
|
28 |
|
29 // USER INCLUDES |
|
30 #include "msgunieditorattachment.h" |
|
31 #include "unieditorgenutils.h" |
|
32 #include "s60qconversions.h" |
|
33 |
|
34 // Constants |
|
35 #define BYTES_TO_KBYTES_FACTOR 1024 |
|
36 #define BG_FRAME "qtg_fr_groupbox" |
|
37 |
|
38 MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& pluginPath, |
|
39 const QString& attachmentpath, |
|
40 const int filesize, |
|
41 QGraphicsItem *parent ) : |
|
42 HbWidget(parent), |
|
43 mPluginPath(pluginPath), |
|
44 mPath(attachmentpath), |
|
45 mSize(filesize), |
|
46 mMimeType(QString()), |
|
47 mAttachmentIcon(0), |
|
48 mAttachmentName(0), |
|
49 mFrameItem(0) |
|
50 { |
|
51 #ifdef _DEBUG_TRACES_ |
|
52 qDebug() << "MsgUnifiedEditorAttachment calling HbStyle::registerPlugin"; |
|
53 #endif |
|
54 |
|
55 setPluginBaseId(style()->registerPlugin(mPluginPath)); |
|
56 |
|
57 mAttachmentIcon = new HbIconItem(":/qtg_small_attachment.svg", this); |
|
58 HbStyle::setItemName(mAttachmentIcon,"attachmentIcon"); |
|
59 |
|
60 // TODO: use utility to get mimetype and size |
|
61 int at_size = 0; |
|
62 TMsgMediaType mediaType = EMsgMediaUnknown; |
|
63 UniEditorGenUtils* genUtils = new UniEditorGenUtils; |
|
64 TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size, |
|
65 mMimeType,mediaType)); |
|
66 delete genUtils; |
|
67 QFileInfo fileinfo(attachmentpath); |
|
68 QString filename = fileinfo.fileName(); |
|
69 mAttachmentName = new HbTextItem(filename,this); |
|
70 HbStyle::setItemName(mAttachmentName,"attachmentName"); |
|
71 mAttachmentName->setElideMode(Qt::ElideRight); |
|
72 |
|
73 int sizeInKb = mSize/BYTES_TO_KBYTES_FACTOR; |
|
74 QString fileDetails; |
|
75 if(sizeInKb > 1) |
|
76 { |
|
77 fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb)); |
|
78 } |
|
79 else |
|
80 { |
|
81 fileDetails = QString().append(QString("(%1 B)").arg(mSize)); |
|
82 } |
|
83 |
|
84 mAttachmentDetails = new HbTextItem(fileDetails, this); |
|
85 HbStyle::setItemName(mAttachmentDetails,"attachmentDetails"); |
|
86 mAttachmentDetails->setElideMode(Qt::ElideNone); |
|
87 |
|
88 // set underlined font |
|
89 QFont underlinedFont(this->font()); |
|
90 underlinedFont.setUnderline(true); |
|
91 mAttachmentName->setFont(underlinedFont); |
|
92 mAttachmentDetails->setFont(underlinedFont); |
|
93 |
|
94 mFrameItem = new HbPushButton(this); |
|
95 HbStyle::setItemName(mFrameItem, "bgFrame"); |
|
96 HbFrameDrawer *fd = new HbFrameDrawer(BG_FRAME, HbFrameDrawer::NinePieces); |
|
97 mFrameItem->setFrameBackground(fd); |
|
98 connect(mFrameItem, SIGNAL(clicked(bool)), this, SIGNAL(clicked())); |
|
99 connect(mFrameItem, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF))); |
|
100 } |
|
101 |
|
102 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment() |
|
103 { |
|
104 style()->unregisterPlugin(mPluginPath); |
|
105 } |
|
106 |
|
107 const QString& MsgUnifiedEditorAttachment::path() |
|
108 { |
|
109 return mPath; |
|
110 } |
|
111 |
|
112 qreal MsgUnifiedEditorAttachment::size() |
|
113 { |
|
114 return mSize; |
|
115 } |
|
116 |
|
117 const QString& MsgUnifiedEditorAttachment::mimeType() |
|
118 { |
|
119 return mMimeType; |
|
120 } |
|
121 |
|
122 void MsgUnifiedEditorAttachment::longPressed(QPointF position) |
|
123 { |
|
124 HbMenu* menu = new HbMenu; |
|
125 menu->addAction(tr("Open"), this, SLOT(openAttachment())); |
|
126 menu->addAction(tr("Remove"), this, SLOT(removeAttachment())); |
|
127 menu->addAction(tr("View details"), this, SLOT(viewDetails())); |
|
128 menu->setDismissPolicy(HbPopup::TapAnywhere); |
|
129 menu->setAttribute(Qt::WA_DeleteOnClose, true); |
|
130 menu->setPreferredPos(position); |
|
131 menu->show(); |
|
132 } |
|
133 |
|
134 void MsgUnifiedEditorAttachment::removeAttachment() |
|
135 { |
|
136 emit deleteMe(this); |
|
137 } |
|
138 |
|
139 void MsgUnifiedEditorAttachment::openAttachment() |
|
140 { |
|
141 //open corresponding viewer app. |
|
142 } |
|
143 |
|
144 void MsgUnifiedEditorAttachment::viewDetails() |
|
145 { |
|
146 //open details view. |
|
147 } |
|
148 |
|
149 bool MsgUnifiedEditorAttachment::isMultimediaContent() |
|
150 { |
|
151 bool ret = true; |
|
152 QString vcard = S60QConversions::s60Desc8ToQString(KMsgMimeVCard()); |
|
153 QString vcal = S60QConversions::s60Desc8ToQString(KMsgMimeVCal()); |
|
154 QString ical = S60QConversions::s60Desc8ToQString(KMsgMimeICal()); |
|
155 if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) || |
|
156 !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) || |
|
157 !QString::compare(mMimeType, ical, Qt::CaseInsensitive) ) |
|
158 { |
|
159 // vcard, vcal are not mm content |
|
160 ret = false; |
|
161 } |
|
162 return ret; |
|
163 } |
|
164 |
|
165 // EOF |