15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "nmuiheaders.h" |
18 #include "nmuiheaders.h" |
19 |
19 |
|
20 #define AttachmentFileNameMaxLength 17 |
|
21 |
20 /*! |
22 /*! |
21 \class NmAttachmentList |
23 \class NmAttachmentList |
22 \brief Class for handling the attachment list |
24 \brief Class for handling the attachment list |
23 */ |
25 */ |
24 |
26 |
25 /*! |
27 /*! |
26 Constructor |
28 Constructor |
27 */ |
29 */ |
28 NmAttachmentList::NmAttachmentList(NmAttachmentListWidget *listWidget) |
30 NmAttachmentList::NmAttachmentList(NmAttachmentListWidget &listWidget) |
29 : mListWidget(listWidget) |
31 : mListWidget(listWidget) |
30 { |
32 { |
31 updateLayout(); |
33 updateLayout(); |
32 } |
34 } |
33 |
35 |
50 QString displayName = fullNameToDisplayName(fullFileName); |
52 QString displayName = fullNameToDisplayName(fullFileName); |
51 mFullFileName.append(fullFileName); |
53 mFullFileName.append(fullFileName); |
52 mDisplayFileName.append(displayName); |
54 mDisplayFileName.append(displayName); |
53 mAttachmentPartId.append(attachmentPartId); |
55 mAttachmentPartId.append(attachmentPartId); |
54 mFileSize.append(fileSize); |
56 mFileSize.append(fileSize); |
55 mListWidget->insertAttachment(count() - 1, displayName, createSizeString(fileSize)); |
57 mListWidget.insertAttachment( |
|
58 count() - 1, |
|
59 NmUtilities::truncate(displayName, AttachmentFileNameMaxLength), |
|
60 NmUtilities::attachmentSizeString(fileSize.toDouble())); |
56 updateLayout(); |
61 updateLayout(); |
57 return count() - 1; |
62 return count() - 1; |
58 } |
63 } |
59 |
64 |
60 /*! |
65 /*! |
61 Set attachmentPartId of the list item. Because there can be several attachments with |
66 Set attachmentPartId of the list item. Because there can be several attachments with |
62 same filename, function will search the one which nmid is not set. |
67 same filename, function will search the one which nmid is not set. |
63 */ |
68 */ |
64 void NmAttachmentList::setAttachmentPartId(const QString fullFileName, const NmId &attachmentPartId) |
69 void NmAttachmentList::setAttachmentPartId(const QString fullFileName, |
|
70 const NmId &attachmentPartId) |
65 { |
71 { |
66 for (int i=0; i<count(); ++i) { |
72 for (int i=0; i<count(); ++i) { |
67 if (mFullFileName.at(i) == fullFileName && mAttachmentPartId.at(i).id() == 0) { |
73 if (mFullFileName.at(i) == fullFileName && mAttachmentPartId.at(i).id() == 0) { |
68 mAttachmentPartId.replace(i, attachmentPartId); |
74 mAttachmentPartId.replace(i, attachmentPartId); |
69 } |
75 } |
76 void NmAttachmentList::setAttachmentSize(const NmId &attachmentPartId, const QString &size) |
82 void NmAttachmentList::setAttachmentSize(const NmId &attachmentPartId, const QString &size) |
77 { |
83 { |
78 for (int i=0; i<count(); ++i) { |
84 for (int i=0; i<count(); ++i) { |
79 if (mAttachmentPartId.at(i) == attachmentPartId) { |
85 if (mAttachmentPartId.at(i) == attachmentPartId) { |
80 mFileSize.replace(i, size); |
86 mFileSize.replace(i, size); |
|
87 mListWidget.setAttachmentSize(i, NmUtilities::attachmentSizeString(size.toDouble())); |
81 } |
88 } |
82 } |
89 } |
83 } |
90 } |
84 |
91 |
85 /*! |
92 /*! |
87 */ |
94 */ |
88 void NmAttachmentList::removeAttachment(int arrayIndex) |
95 void NmAttachmentList::removeAttachment(int arrayIndex) |
89 { |
96 { |
90 if (arrayIndex < count()) { |
97 if (arrayIndex < count()) { |
91 // Remove UI |
98 // Remove UI |
92 mListWidget->removeAttachment(arrayIndex); |
99 mListWidget.removeAttachment(arrayIndex); |
93 // Remove from data structure |
100 // Remove from data structure |
94 mFullFileName.removeAt(arrayIndex); |
101 mFullFileName.removeAt(arrayIndex); |
95 mDisplayFileName.removeAt(arrayIndex); |
102 mDisplayFileName.removeAt(arrayIndex); |
96 mAttachmentPartId.removeAt(arrayIndex); |
103 mAttachmentPartId.removeAt(arrayIndex); |
97 updateLayout(); |
104 updateLayout(); |
98 } |
105 } |
99 } |
106 } |
100 |
107 |
101 /*! |
108 /*! |
|
109 Return full filename of the list item |
|
110 */ |
|
111 QString NmAttachmentList::getFullFileNameByIndex(int arrayIndex) |
|
112 { |
|
113 QString result; |
|
114 |
|
115 if ( arrayIndex >= 0 && arrayIndex < mFullFileName.count() ) { |
|
116 result.append(mFullFileName.at(arrayIndex)); |
|
117 } |
|
118 return result; |
|
119 } |
|
120 |
|
121 /*! |
102 Remove attachment which have same fullFileName from list |
122 Remove attachment which have same fullFileName from list |
103 */ |
123 */ |
104 void NmAttachmentList::removeAttachment(const QString &fullFileName) |
124 void NmAttachmentList::removeAttachment(const QString &fullFileName) |
105 { |
125 { |
106 for (int i=0; i<count(); ++i) { |
126 for (int i=0; i<count(); ++i) { |
127 */ |
147 */ |
128 void NmAttachmentList::clearList() |
148 void NmAttachmentList::clearList() |
129 { |
149 { |
130 for (int i=count()-1; i>=0; --i) { |
150 for (int i=count()-1; i>=0; --i) { |
131 // Remove from UI |
151 // Remove from UI |
132 mListWidget->removeAttachment(i); |
152 mListWidget.removeAttachment(i); |
133 // Remove from data structure |
153 // Remove from data structure |
134 mFullFileName.removeAt(i); |
154 mFullFileName.removeAt(i); |
135 mDisplayFileName.removeAt(i); |
155 mDisplayFileName.removeAt(i); |
136 mAttachmentPartId.removeAt(i); |
156 mAttachmentPartId.removeAt(i); |
137 updateLayout(); |
157 updateLayout(); |
182 { |
202 { |
183 return fullName.section('\\', -1); |
203 return fullName.section('\\', -1); |
184 } |
204 } |
185 |
205 |
186 /*! |
206 /*! |
187 Create string for showing the size information |
|
188 */ |
|
189 QString NmAttachmentList::createSizeString(const QString &sizeInBytes) |
|
190 { |
|
191 double sizeMb = sizeInBytes.toDouble() / 1000000; |
|
192 if (sizeMb < 0.1) { |
|
193 // 0.1 Mb is the minimum size shown for attachment |
|
194 sizeMb = 0.1; |
|
195 } |
|
196 return QString().sprintf("(%.1f Mb)", sizeMb); // Use loc string when available |
|
197 } |
|
198 |
|
199 /*! |
|
200 Update the list layout height |
207 Update the list layout height |
201 */ |
208 */ |
202 void NmAttachmentList::updateLayout() |
209 void NmAttachmentList::updateLayout() |
203 { |
210 { |
204 // Fix this when progress bar is used |
211 // Fix this when progress bar is used |
205 mListWidget->setMaximumHeight(count() * 29); |
212 mListWidget.setMaximumHeight(count() * 56); |
206 QTimer::singleShot(1, this, SLOT(delayedLayoutChangeInfo())); |
213 QTimer::singleShot(1, this, SLOT(delayedLayoutChangeInfo())); |
207 } |
214 } |
208 |
215 |
209 /*! |
216 /*! |
210 Send delayed signal about attachment list layout change |
217 Send delayed signal about attachment list layout change |
211 */ |
218 */ |
212 void NmAttachmentList::delayedLayoutChangeInfo() |
219 void NmAttachmentList::delayedLayoutChangeInfo() |
213 { |
220 { |
214 emit attachmentListLayoutChanged(); |
221 emit attachmentListLayoutChanged(); |
215 } |
222 } |
|
223 |