|
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 "univiewerattachmentcontainer.h" |
|
28 #include "univiewerdetailswidget.h" |
|
29 #include "univiewerfeeder.h" |
|
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), |
|
47 mAddressContainer(0), mAttachmentContainer(0) |
|
48 { |
|
49 this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
50 |
|
51 HbFrameItem *bgItem = new HbFrameItem(BG_FRAME_GRAPHICS, HbFrameDrawer::NinePieces, this); |
|
52 this->setBackgroundItem(bgItem); |
|
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 } |
|
135 if (mAttachmentContainer) { |
|
136 mAttachmentContainer->clearContent(); |
|
137 } |
|
138 } |
|
139 |
|
140 //--------------------------------------------------------------- |
|
141 // UniViewerHeaderContainer :: populateSubject |
|
142 // @see header file |
|
143 //--------------------------------------------------------------- |
|
144 void UniViewerHeaderContainer::populateSubject() |
|
145 { |
|
146 if (KSenduiMtmSmsUidValue == mViewFeeder->msgType()) { |
|
147 if ((ConvergedMessage::Failed == mViewFeeder->sendingState()) && !mViewFeeder->isIncoming()) { |
|
148 mViewerDetails->setSubject(LOC_SEND_FAILED); |
|
149 } |
|
150 } |
|
151 else if (KSenduiMtmMmsUidValue == mViewFeeder->msgType()) { |
|
152 QString subject; |
|
153 if (ConvergedMessage::Failed == mViewFeeder->sendingState()) { |
|
154 subject.append(LOC_SEND_FAILED); |
|
155 subject.append(QChar::LineSeparator); |
|
156 } |
|
157 subject.append(mViewFeeder->subject()); |
|
158 if (!subject.isEmpty()) { |
|
159 mViewerDetails->setSubject(subject); |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 //--------------------------------------------------------------- |
|
165 // UniViewerHeaderContainer :: populateAttachments |
|
166 // @see header file |
|
167 //--------------------------------------------------------------- |
|
168 void UniViewerHeaderContainer::populateAttachments() |
|
169 { |
|
170 if (!mAttachmentContainer) { |
|
171 // Attachment Container |
|
172 mAttachmentContainer = new UniViewerAttachmentContainer(this); |
|
173 mMainLayout->addItem(mAttachmentContainer); |
|
174 } |
|
175 |
|
176 UniMessageInfoList attachList = mViewFeeder->attachmentsList(); |
|
177 for (int a = 0; a < attachList.count(); ++a) { |
|
178 UniMessageInfo* info = attachList.at(a); |
|
179 mAttachmentContainer->addAttachmentWidget(info->mimetype(), info->path()); |
|
180 delete info; |
|
181 } |
|
182 } |
|
183 |
|
184 //--------------------------------------------------------------- |
|
185 // UniViewerHeaderContainer :: populateAttachments |
|
186 // @see header file |
|
187 //--------------------------------------------------------------- |
|
188 void UniViewerHeaderContainer::populateAddressContainer() |
|
189 { |
|
190 QString from, alias; |
|
191 mViewFeeder->fromAddressAndAlias(from, alias); |
|
192 ConvergedMessageAddressList toList = mViewFeeder->toAddressList(); |
|
193 |
|
194 // From field is added ONLY for incoming messages. |
|
195 if (mViewFeeder->isIncoming()) { |
|
196 mAddressContainer->setFromField(from, alias); |
|
197 } |
|
198 // For outgoing SMS messages add TO field. |
|
199 else if (mViewFeeder->msgType() == KSenduiMtmSmsUidValue && !toList.isEmpty()) { |
|
200 mAddressContainer->setToField(toList); |
|
201 } |
|
202 |
|
203 // For MMS messages add TO, CC, BCC fields irrespective of incoming/outgoing. |
|
204 if (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) { |
|
205 if (!toList.isEmpty()) { |
|
206 mAddressContainer->setToField(toList); |
|
207 } |
|
208 ConvergedMessageAddressList ccList = mViewFeeder->ccAddressList(); |
|
209 if (!ccList.isEmpty()) { |
|
210 mAddressContainer->setCcField(ccList); |
|
211 } |
|
212 } |
|
213 |
|
214 } |
|
215 //--------------------------------------------------------------- |
|
216 // UniViewerHeaderContainer :: setAddrGroupBoxHeading |
|
217 // @see header file |
|
218 //--------------------------------------------------------------- |
|
219 void UniViewerHeaderContainer::setAddrGroupBoxHeading() |
|
220 { |
|
221 if (mViewFeeder->isIncoming()) { |
|
222 QString from, alias; |
|
223 mViewFeeder->fromAddressAndAlias(from, alias); |
|
224 (alias.isEmpty()) ? mHeaderGroupBox->setHeading(from) : mHeaderGroupBox->setHeading(alias); |
|
225 } |
|
226 else { |
|
227 QString toAddrList = createAddressList(mViewFeeder->toAddressList()); |
|
228 QString ccAddrList = createAddressList(mViewFeeder->ccAddressList()); |
|
229 |
|
230 if (!ccAddrList.isEmpty()) { |
|
231 toAddrList.append(ADDR_LIST_SEPARATOR); |
|
232 toAddrList.append(ccAddrList); |
|
233 } |
|
234 mHeaderGroupBox->setHeading(toAddrList); |
|
235 } |
|
236 } |
|
237 |
|
238 //--------------------------------------------------------------- |
|
239 // UniViewerHeaderContainer :: createAddressList |
|
240 // @see header file |
|
241 //--------------------------------------------------------------- |
|
242 QString UniViewerHeaderContainer::createAddressList(const ConvergedMessageAddressList &addressList) |
|
243 { |
|
244 QString address; |
|
245 for (int i = 0; i < addressList.count(); ++i) { |
|
246 address.append((addressList[i]->alias().isEmpty()) ? addressList[i]->address() |
|
247 : addressList[i]->alias()); |
|
248 address.append(ADDR_LIST_SEPARATOR); |
|
249 } |
|
250 address.chop(ADDR_LIST_SEPARATOR.size()); |
|
251 return address; |
|
252 } |
|
253 |
|
254 //--------------------------------------------------------------- |
|
255 // UniViewerHeaderContainer :: addressBoxToggled |
|
256 // @see header file |
|
257 //--------------------------------------------------------------- |
|
258 void UniViewerHeaderContainer::addressBoxToggled(bool state) |
|
259 { |
|
260 (state) ? mSeparator->hide() : mSeparator->show(); |
|
261 } |