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