author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 13:35:48 +0300 | |
changeset 34 | 84197e66a4bd |
parent 31 | ebfee66fde93 |
child 43 | 35b64624a9e7 |
permissions | -rw-r--r-- |
31 | 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: This widget holds the message header. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include "univiewerheadercontainer.h" |
|
19 |
||
20 |
// SYSTEM INCLUDES |
|
21 |
#include <QGraphicsLinearLayout> |
|
22 |
#include <HbGroupBox> |
|
23 |
#include <HbFrameItem> |
|
24 |
||
25 |
// USER INCLUDES |
|
26 |
#include "univieweraddresscontainer.h" |
|
27 |
#include "univiewerdetailswidget.h" |
|
28 |
#include "univiewerfeeder.h" |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
29 |
#include "univiewerattachmentwidget.h" |
31 | 30 |
|
31 |
#include "nativemessageconsts.h" |
|
32 |
||
33 |
// LOCALIZATION |
|
34 |
#define LOC_SEND_FAILED hbTrId("txt_messaging_formlabel_sending_failed") |
|
35 |
||
36 |
// LOCAL CONSTANTS |
|
37 |
const QString ADDR_LIST_SEPARATOR(", "); |
|
38 |
const QString BG_FRAME_GRAPHICS("qtg_fr_form_heading"); |
|
39 |
const QString DIVIDER_FRAME("qtg_graf_divider_h_thin"); |
|
40 |
||
41 |
//--------------------------------------------------------------- |
|
42 |
// UniViewerHeaderContainer :: UniViewerHeaderContainer |
|
43 |
// @see header file |
|
44 |
//--------------------------------------------------------------- |
|
45 |
UniViewerHeaderContainer::UniViewerHeaderContainer(UniViewerFeeder* feeder, QGraphicsItem *parent) : |
|
46 |
HbWidget(parent), mViewFeeder(feeder), mViewerDetails(0), mHeaderGroupBox(0), mSeparator(0), |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
47 |
mAddressContainer(0) |
31 | 48 |
{ |
49 |
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
50 |
||
51 |
HbFrameItem *bgItem = new HbFrameItem(BG_FRAME_GRAPHICS, HbFrameDrawer::NinePieces, this); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
52 |
this->setBackgroundItem(bgItem, -2.0); |
31 | 53 |
|
54 |
mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, this); |
|
55 |
mMainLayout->setSpacing(0); |
|
56 |
mMainLayout->setContentsMargins(0, 0, 0, 0); |
|
57 |
||
58 |
// Address Group box |
|
59 |
mHeaderGroupBox = new HbGroupBox(this); |
|
60 |
connect(mHeaderGroupBox, SIGNAL(toggled(bool)), this, SLOT(addressBoxToggled(bool))); |
|
61 |
||
62 |
// Address container |
|
63 |
mAddressContainer = new UniViewerAddressContainer(this); |
|
64 |
connect(mAddressContainer,SIGNAL(sendMessage(const QString&,const QString&)), |
|
65 |
this, SIGNAL(sendMessage(const QString&,const QString&))); |
|
66 |
||
67 |
mHeaderGroupBox->setContentWidget(mAddressContainer); |
|
68 |
||
69 |
// Separator |
|
70 |
mSeparator = new HbFrameItem(DIVIDER_FRAME, HbFrameDrawer::OnePiece, this); |
|
71 |
mSeparator->setMaximumHeight(1); |
|
72 |
mSeparator->hide(); |
|
73 |
||
74 |
// Viewer Details widget |
|
75 |
mViewerDetails = new UniViewerDetailsWidget(this); |
|
76 |
||
77 |
//Add address group box and insert into layout |
|
78 |
mMainLayout->addItem(mHeaderGroupBox); |
|
79 |
mMainLayout->addItem(mSeparator); |
|
80 |
mMainLayout->addItem(mViewerDetails); |
|
81 |
||
82 |
this->setLayout(mMainLayout); |
|
83 |
} |
|
84 |
||
85 |
//--------------------------------------------------------------- |
|
86 |
// UniViewerHeaderContainer :: ~UniViewerHeaderContainer |
|
87 |
// @see header file |
|
88 |
//--------------------------------------------------------------- |
|
89 |
UniViewerHeaderContainer::~UniViewerHeaderContainer() |
|
90 |
{ |
|
91 |
||
92 |
} |
|
93 |
||
94 |
//--------------------------------------------------------------- |
|
95 |
// UniViewerHeaderContainer :: populateContent |
|
96 |
// @see header file |
|
97 |
//--------------------------------------------------------------- |
|
98 |
void UniViewerHeaderContainer::populateContent() |
|
99 |
{ |
|
100 |
setAddrGroupBoxHeading(); |
|
101 |
||
102 |
// Address container |
|
103 |
populateAddressContainer(); |
|
104 |
||
105 |
// Time stamp |
|
106 |
mViewerDetails->setTimeStamp(mViewFeeder->timeStamp(), mViewFeeder->sendingState()); |
|
107 |
||
108 |
// Priority |
|
109 |
mViewerDetails->setPriorityIcon(mViewFeeder->priority()); |
|
110 |
||
111 |
// Subject |
|
112 |
populateSubject(); |
|
113 |
||
114 |
// Attachment list |
|
115 |
populateAttachments(); |
|
116 |
||
117 |
// Expand address group box for outgoing messages. |
|
118 |
if (mViewFeeder->isIncoming()) { |
|
119 |
mHeaderGroupBox->setCollapsed(true); |
|
120 |
} |
|
121 |
else { |
|
122 |
mHeaderGroupBox->setCollapsed(false); |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
//--------------------------------------------------------------- |
|
127 |
// UniViewerHeaderContainer :: clearContent |
|
128 |
// @see header file |
|
129 |
//--------------------------------------------------------------- |
|
130 |
void UniViewerHeaderContainer::clearContent() |
|
131 |
{ |
|
132 |
if (mViewerDetails) { |
|
133 |
mViewerDetails->clearContent(); |
|
134 |
} |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
135 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
136 |
// Clear the attachments. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
137 |
for (int i = 0; i < mUniViewerAttachmentstList.count(); ++i) { |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
138 |
mMainLayout->removeItem(mUniViewerAttachmentstList[i]); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
139 |
mUniViewerAttachmentstList[i]->setParent(NULL); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
140 |
delete mUniViewerAttachmentstList[i]; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
141 |
mUniViewerAttachmentstList[i] = NULL; |
31 | 142 |
} |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
143 |
mUniViewerAttachmentstList.clear(); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
144 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
145 |
resize(rect().width(), -1); |
31 | 146 |
} |
147 |
||
148 |
//--------------------------------------------------------------- |
|
149 |
// UniViewerHeaderContainer :: populateSubject |
|
150 |
// @see header file |
|
151 |
//--------------------------------------------------------------- |
|
152 |
void UniViewerHeaderContainer::populateSubject() |
|
153 |
{ |
|
154 |
if (KSenduiMtmSmsUidValue == mViewFeeder->msgType()) { |
|
155 |
if ((ConvergedMessage::Failed == mViewFeeder->sendingState()) && !mViewFeeder->isIncoming()) { |
|
156 |
mViewerDetails->setSubject(LOC_SEND_FAILED); |
|
157 |
} |
|
158 |
} |
|
159 |
else if (KSenduiMtmMmsUidValue == mViewFeeder->msgType()) { |
|
160 |
QString subject; |
|
161 |
if (ConvergedMessage::Failed == mViewFeeder->sendingState()) { |
|
162 |
subject.append(LOC_SEND_FAILED); |
|
163 |
subject.append(QChar::LineSeparator); |
|
164 |
} |
|
165 |
subject.append(mViewFeeder->subject()); |
|
166 |
if (!subject.isEmpty()) { |
|
167 |
mViewerDetails->setSubject(subject); |
|
168 |
} |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
//--------------------------------------------------------------- |
|
173 |
// UniViewerHeaderContainer :: populateAttachments |
|
174 |
// @see header file |
|
175 |
//--------------------------------------------------------------- |
|
176 |
void UniViewerHeaderContainer::populateAttachments() |
|
177 |
{ |
|
178 |
UniMessageInfoList attachList = mViewFeeder->attachmentsList(); |
|
179 |
for (int a = 0; a < attachList.count(); ++a) { |
|
180 |
UniMessageInfo* info = attachList.at(a); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
181 |
UniViewerAttachmentWidget *attachmentWidget = new UniViewerAttachmentWidget(this); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
182 |
mUniViewerAttachmentstList.append(attachmentWidget); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
183 |
attachmentWidget->populate(info->mimetype(), info->path()); |
31 | 184 |
delete info; |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
185 |
mMainLayout->addItem(attachmentWidget); |
31 | 186 |
} |
187 |
} |
|
188 |
||
189 |
//--------------------------------------------------------------- |
|
190 |
// UniViewerHeaderContainer :: populateAttachments |
|
191 |
// @see header file |
|
192 |
//--------------------------------------------------------------- |
|
193 |
void UniViewerHeaderContainer::populateAddressContainer() |
|
194 |
{ |
|
195 |
QString from, alias; |
|
196 |
mViewFeeder->fromAddressAndAlias(from, alias); |
|
197 |
ConvergedMessageAddressList toList = mViewFeeder->toAddressList(); |
|
198 |
||
199 |
// From field is added ONLY for incoming messages. |
|
200 |
if (mViewFeeder->isIncoming()) { |
|
201 |
mAddressContainer->setFromField(from, alias); |
|
202 |
} |
|
203 |
// For outgoing SMS messages add TO field. |
|
204 |
else if (mViewFeeder->msgType() == KSenduiMtmSmsUidValue && !toList.isEmpty()) { |
|
205 |
mAddressContainer->setToField(toList); |
|
206 |
} |
|
207 |
||
208 |
// For MMS messages add TO, CC, BCC fields irrespective of incoming/outgoing. |
|
209 |
if (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) { |
|
210 |
if (!toList.isEmpty()) { |
|
211 |
mAddressContainer->setToField(toList); |
|
212 |
} |
|
213 |
ConvergedMessageAddressList ccList = mViewFeeder->ccAddressList(); |
|
214 |
if (!ccList.isEmpty()) { |
|
215 |
mAddressContainer->setCcField(ccList); |
|
216 |
} |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
217 |
ConvergedMessageAddressList bccList = mViewFeeder->bccAddressList(); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
218 |
if (!bccList.isEmpty()) { |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
219 |
mAddressContainer->setBccField(bccList); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
220 |
} |
31 | 221 |
} |
222 |
||
223 |
} |
|
224 |
//--------------------------------------------------------------- |
|
225 |
// UniViewerHeaderContainer :: setAddrGroupBoxHeading |
|
226 |
// @see header file |
|
227 |
//--------------------------------------------------------------- |
|
228 |
void UniViewerHeaderContainer::setAddrGroupBoxHeading() |
|
229 |
{ |
|
230 |
if (mViewFeeder->isIncoming()) { |
|
231 |
QString from, alias; |
|
232 |
mViewFeeder->fromAddressAndAlias(from, alias); |
|
233 |
(alias.isEmpty()) ? mHeaderGroupBox->setHeading(from) : mHeaderGroupBox->setHeading(alias); |
|
234 |
} |
|
235 |
else { |
|
236 |
QString toAddrList = createAddressList(mViewFeeder->toAddressList()); |
|
237 |
QString ccAddrList = createAddressList(mViewFeeder->ccAddressList()); |
|
238 |
||
239 |
if (!ccAddrList.isEmpty()) { |
|
240 |
toAddrList.append(ADDR_LIST_SEPARATOR); |
|
241 |
toAddrList.append(ccAddrList); |
|
242 |
} |
|
243 |
mHeaderGroupBox->setHeading(toAddrList); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
//--------------------------------------------------------------- |
|
248 |
// UniViewerHeaderContainer :: createAddressList |
|
249 |
// @see header file |
|
250 |
//--------------------------------------------------------------- |
|
251 |
QString UniViewerHeaderContainer::createAddressList(const ConvergedMessageAddressList &addressList) |
|
252 |
{ |
|
253 |
QString address; |
|
254 |
for (int i = 0; i < addressList.count(); ++i) { |
|
255 |
address.append((addressList[i]->alias().isEmpty()) ? addressList[i]->address() |
|
256 |
: addressList[i]->alias()); |
|
257 |
address.append(ADDR_LIST_SEPARATOR); |
|
258 |
} |
|
259 |
address.chop(ADDR_LIST_SEPARATOR.size()); |
|
260 |
return address; |
|
261 |
} |
|
262 |
||
263 |
//--------------------------------------------------------------- |
|
264 |
// UniViewerHeaderContainer :: addressBoxToggled |
|
265 |
// @see header file |
|
266 |
//--------------------------------------------------------------- |
|
267 |
void UniViewerHeaderContainer::addressBoxToggled(bool state) |
|
268 |
{ |
|
269 |
(state) ? mSeparator->hide() : mSeparator->show(); |
|
270 |
} |