author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows: |
0 | 11 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
14 |
** met: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
19 |
** the documentation and/or other materials provided with the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
20 |
** distribution. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
23 |
** products derived from this software without specific prior written |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
24 |
** permission. |
0 | 25 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
0 | 37 |
** $QT_END_LICENSE$ |
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
||
41 |
#include <QtGui> |
|
42 |
#include "addressbook.h" |
|
43 |
||
44 |
AddressBook::AddressBook(QWidget *parent) |
|
45 |
: QWidget(parent) |
|
46 |
{ |
|
47 |
QLabel *nameLabel = new QLabel(tr("Name:")); |
|
48 |
nameLine = new QLineEdit; |
|
49 |
nameLine->setReadOnly(true); |
|
50 |
||
51 |
QLabel *addressLabel = new QLabel(tr("Address:")); |
|
52 |
addressText = new QTextEdit; |
|
53 |
addressText->setReadOnly(true); |
|
54 |
||
55 |
addButton = new QPushButton(tr("&Add")); |
|
56 |
||
57 |
editButton = new QPushButton(tr("&Edit")); |
|
58 |
editButton->setEnabled(false); |
|
59 |
removeButton = new QPushButton(tr("&Remove")); |
|
60 |
removeButton->setEnabled(false); |
|
61 |
findButton = new QPushButton(tr("&Find")); |
|
62 |
findButton->setEnabled(false); |
|
63 |
submitButton = new QPushButton(tr("&Submit")); |
|
64 |
submitButton->hide(); |
|
65 |
cancelButton = new QPushButton(tr("&Cancel")); |
|
66 |
cancelButton->hide(); |
|
67 |
||
68 |
nextButton = new QPushButton(tr("&Next")); |
|
69 |
nextButton->setEnabled(false); |
|
70 |
previousButton = new QPushButton(tr("&Previous")); |
|
71 |
previousButton->setEnabled(false); |
|
72 |
||
73 |
loadButton = new QPushButton(tr("&Load...")); |
|
74 |
loadButton->setToolTip(tr("Load contacts from a file")); |
|
75 |
saveButton = new QPushButton(tr("Sa&ve...")); |
|
76 |
saveButton->setToolTip(tr("Save contacts to a file")); |
|
77 |
saveButton->setEnabled(false); |
|
78 |
||
79 |
exportButton = new QPushButton(tr("E&xport")); |
|
80 |
exportButton->setToolTip(tr("Export as vCard")); |
|
81 |
exportButton->setEnabled(false); |
|
82 |
||
83 |
dialog = new FindDialog; |
|
84 |
||
85 |
connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); |
|
86 |
connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); |
|
87 |
connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); |
|
88 |
connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); |
|
89 |
connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); |
|
90 |
connect(findButton, SIGNAL(clicked()), this, SLOT(findContact())); |
|
91 |
connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); |
|
92 |
connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); |
|
93 |
connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile())); |
|
94 |
connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile())); |
|
95 |
connect(exportButton, SIGNAL(clicked()), this, SLOT(exportAsVCard())); |
|
96 |
||
97 |
QVBoxLayout *buttonLayout1 = new QVBoxLayout; |
|
98 |
buttonLayout1->addWidget(addButton); |
|
99 |
buttonLayout1->addWidget(editButton); |
|
100 |
buttonLayout1->addWidget(removeButton); |
|
101 |
buttonLayout1->addWidget(findButton); |
|
102 |
buttonLayout1->addWidget(submitButton); |
|
103 |
buttonLayout1->addWidget(cancelButton); |
|
104 |
buttonLayout1->addWidget(loadButton); |
|
105 |
buttonLayout1->addWidget(saveButton); |
|
106 |
buttonLayout1->addWidget(exportButton); |
|
107 |
buttonLayout1->addStretch(); |
|
108 |
||
109 |
QHBoxLayout *buttonLayout2 = new QHBoxLayout; |
|
110 |
buttonLayout2->addWidget(previousButton); |
|
111 |
buttonLayout2->addWidget(nextButton); |
|
112 |
||
113 |
QGridLayout *mainLayout = new QGridLayout; |
|
114 |
mainLayout->addWidget(nameLabel, 0, 0); |
|
115 |
mainLayout->addWidget(nameLine, 0, 1); |
|
116 |
mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop); |
|
117 |
mainLayout->addWidget(addressText, 1, 1); |
|
118 |
mainLayout->addLayout(buttonLayout1, 1, 2); |
|
119 |
mainLayout->addLayout(buttonLayout2, 2, 1); |
|
120 |
||
121 |
setLayout(mainLayout); |
|
122 |
setWindowTitle(tr("Simple Address Book")); |
|
123 |
} |
|
124 |
||
125 |
void AddressBook::addContact() |
|
126 |
{ |
|
127 |
oldName = nameLine->text(); |
|
128 |
oldAddress = addressText->toPlainText(); |
|
129 |
||
130 |
nameLine->clear(); |
|
131 |
addressText->clear(); |
|
132 |
||
133 |
updateInterface(AddingMode); |
|
134 |
} |
|
135 |
||
136 |
void AddressBook::editContact() |
|
137 |
{ |
|
138 |
oldName = nameLine->text(); |
|
139 |
oldAddress = addressText->toPlainText(); |
|
140 |
||
141 |
updateInterface(EditingMode); |
|
142 |
} |
|
143 |
||
144 |
void AddressBook::submitContact() |
|
145 |
{ |
|
146 |
QString name = nameLine->text(); |
|
147 |
QString address = addressText->toPlainText(); |
|
148 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
149 |
if (name.isEmpty() || address.isEmpty()) { |
0 | 150 |
QMessageBox::information(this, tr("Empty Field"), |
151 |
tr("Please enter a name and address.")); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
152 |
return; |
0 | 153 |
} |
154 |
||
155 |
if (currentMode == AddingMode) { |
|
156 |
||
157 |
if (!contacts.contains(name)) { |
|
158 |
contacts.insert(name, address); |
|
159 |
QMessageBox::information(this, tr("Add Successful"), |
|
160 |
tr("\"%1\" has been added to your address book.").arg(name)); |
|
161 |
} else { |
|
162 |
QMessageBox::information(this, tr("Add Unsuccessful"), |
|
163 |
tr("Sorry, \"%1\" is already in your address book.").arg(name)); |
|
164 |
} |
|
165 |
} else if (currentMode == EditingMode) { |
|
166 |
||
167 |
if (oldName != name) { |
|
168 |
if (!contacts.contains(name)) { |
|
169 |
QMessageBox::information(this, tr("Edit Successful"), |
|
170 |
tr("\"%1\" has been edited in your address book.").arg(oldName)); |
|
171 |
contacts.remove(oldName); |
|
172 |
contacts.insert(name, address); |
|
173 |
} else { |
|
174 |
QMessageBox::information(this, tr("Edit Unsuccessful"), |
|
175 |
tr("Sorry, \"%1\" is already in your address book.").arg(name)); |
|
176 |
} |
|
177 |
} else if (oldAddress != address) { |
|
178 |
QMessageBox::information(this, tr("Edit Successful"), |
|
179 |
tr("\"%1\" has been edited in your address book.").arg(name)); |
|
180 |
contacts[name] = address; |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
updateInterface(NavigationMode); |
|
185 |
} |
|
186 |
||
187 |
void AddressBook::cancel() |
|
188 |
{ |
|
189 |
nameLine->setText(oldName); |
|
190 |
addressText->setText(oldAddress); |
|
191 |
updateInterface(NavigationMode); |
|
192 |
} |
|
193 |
||
194 |
void AddressBook::removeContact() |
|
195 |
{ |
|
196 |
QString name = nameLine->text(); |
|
197 |
QString address = addressText->toPlainText(); |
|
198 |
||
199 |
if (contacts.contains(name)) { |
|
200 |
||
201 |
int button = QMessageBox::question(this, |
|
202 |
tr("Confirm Remove"), |
|
203 |
tr("Are you sure you want to remove \"%1\"?").arg(name), |
|
204 |
QMessageBox::Yes | QMessageBox::No); |
|
205 |
||
206 |
if (button == QMessageBox::Yes) { |
|
207 |
||
208 |
previous(); |
|
209 |
contacts.remove(name); |
|
210 |
||
211 |
QMessageBox::information(this, tr("Remove Successful"), |
|
212 |
tr("\"%1\" has been removed from your address book.").arg(name)); |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
updateInterface(NavigationMode); |
|
217 |
} |
|
218 |
||
219 |
void AddressBook::next() |
|
220 |
{ |
|
221 |
QString name = nameLine->text(); |
|
222 |
QMap<QString, QString>::iterator i = contacts.find(name); |
|
223 |
||
224 |
if (i != contacts.end()) |
|
225 |
i++; |
|
226 |
||
227 |
if (i == contacts.end()) |
|
228 |
i = contacts.begin(); |
|
229 |
||
230 |
nameLine->setText(i.key()); |
|
231 |
addressText->setText(i.value()); |
|
232 |
} |
|
233 |
||
234 |
void AddressBook::previous() |
|
235 |
{ |
|
236 |
QString name = nameLine->text(); |
|
237 |
QMap<QString, QString>::iterator i = contacts.find(name); |
|
238 |
||
239 |
if (i == contacts.end()) { |
|
240 |
nameLine->clear(); |
|
241 |
addressText->clear(); |
|
242 |
return; |
|
243 |
} |
|
244 |
||
245 |
if (i == contacts.begin()) |
|
246 |
i = contacts.end(); |
|
247 |
||
248 |
i--; |
|
249 |
nameLine->setText(i.key()); |
|
250 |
addressText->setText(i.value()); |
|
251 |
} |
|
252 |
||
253 |
void AddressBook::findContact() |
|
254 |
{ |
|
255 |
dialog->show(); |
|
256 |
||
257 |
if (dialog->exec() == 1) { |
|
258 |
QString contactName = dialog->getFindText(); |
|
259 |
||
260 |
if (contacts.contains(contactName)) { |
|
261 |
nameLine->setText(contactName); |
|
262 |
addressText->setText(contacts.value(contactName)); |
|
263 |
} else { |
|
264 |
QMessageBox::information(this, tr("Contact Not Found"), |
|
265 |
tr("Sorry, \"%1\" is not in your address book.").arg(contactName)); |
|
266 |
return; |
|
267 |
} |
|
268 |
} |
|
269 |
||
270 |
updateInterface(NavigationMode); |
|
271 |
} |
|
272 |
void AddressBook::updateInterface(Mode mode) |
|
273 |
{ |
|
274 |
currentMode = mode; |
|
275 |
||
276 |
switch (currentMode) { |
|
277 |
||
278 |
case AddingMode: |
|
279 |
case EditingMode: |
|
280 |
||
281 |
nameLine->setReadOnly(false); |
|
282 |
nameLine->setFocus(Qt::OtherFocusReason); |
|
283 |
addressText->setReadOnly(false); |
|
284 |
||
285 |
addButton->setEnabled(false); |
|
286 |
editButton->setEnabled(false); |
|
287 |
removeButton->setEnabled(false); |
|
288 |
||
289 |
nextButton->setEnabled(false); |
|
290 |
previousButton->setEnabled(false); |
|
291 |
||
292 |
submitButton->show(); |
|
293 |
cancelButton->show(); |
|
294 |
||
295 |
loadButton->setEnabled(false); |
|
296 |
saveButton->setEnabled(false); |
|
297 |
exportButton->setEnabled(false); |
|
298 |
break; |
|
299 |
||
300 |
case NavigationMode: |
|
301 |
||
302 |
if (contacts.isEmpty()) { |
|
303 |
nameLine->clear(); |
|
304 |
addressText->clear(); |
|
305 |
} |
|
306 |
||
307 |
nameLine->setReadOnly(true); |
|
308 |
addressText->setReadOnly(true); |
|
309 |
addButton->setEnabled(true); |
|
310 |
||
311 |
int number = contacts.size(); |
|
312 |
editButton->setEnabled(number >= 1); |
|
313 |
removeButton->setEnabled(number >= 1); |
|
314 |
findButton->setEnabled(number > 2); |
|
315 |
nextButton->setEnabled(number > 1); |
|
316 |
previousButton->setEnabled(number > 1); |
|
317 |
||
318 |
submitButton->hide(); |
|
319 |
cancelButton->hide(); |
|
320 |
||
321 |
exportButton->setEnabled(number >= 1); |
|
322 |
||
323 |
loadButton->setEnabled(true); |
|
324 |
saveButton->setEnabled(number >= 1); |
|
325 |
break; |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
void AddressBook::saveToFile() |
|
330 |
{ |
|
331 |
QString fileName = QFileDialog::getSaveFileName(this, |
|
332 |
tr("Save Address Book"), "", |
|
333 |
tr("Address Book (*.abk);;All Files (*)")); |
|
334 |
||
335 |
if (fileName.isEmpty()) |
|
336 |
return; |
|
337 |
else { |
|
338 |
QFile file(fileName); |
|
339 |
||
340 |
if (!file.open(QIODevice::WriteOnly)) { |
|
341 |
QMessageBox::information(this, tr("Unable to open file"), |
|
342 |
file.errorString()); |
|
343 |
return; |
|
344 |
} |
|
345 |
||
346 |
QDataStream out(&file); |
|
347 |
out.setVersion(QDataStream::Qt_4_3); |
|
348 |
out << contacts; |
|
349 |
} |
|
350 |
||
351 |
updateInterface(NavigationMode); |
|
352 |
} |
|
353 |
||
354 |
void AddressBook::loadFromFile() |
|
355 |
{ |
|
356 |
QString fileName = QFileDialog::getOpenFileName(this, |
|
357 |
tr("Open Address Book"), "", |
|
358 |
tr("Address Book (*.abk);;All Files (*)")); |
|
359 |
||
360 |
if (fileName.isEmpty()) |
|
361 |
return; |
|
362 |
else { |
|
363 |
QFile file(fileName); |
|
364 |
||
365 |
if (!file.open(QIODevice::ReadOnly)) { |
|
366 |
QMessageBox::information(this, tr("Unable to open file"), |
|
367 |
file.errorString()); |
|
368 |
return; |
|
369 |
} |
|
370 |
||
371 |
QDataStream in(&file); |
|
372 |
in.setVersion(QDataStream::Qt_4_3); |
|
373 |
contacts.empty(); // empty existing contacts |
|
374 |
in >> contacts; |
|
375 |
||
376 |
QMap<QString, QString>::iterator i = contacts.begin(); |
|
377 |
nameLine->setText(i.key()); |
|
378 |
addressText->setText(i.value()); |
|
379 |
} |
|
380 |
||
381 |
updateInterface(NavigationMode); |
|
382 |
} |
|
383 |
||
384 |
//! [export function part1] |
|
385 |
void AddressBook::exportAsVCard() |
|
386 |
{ |
|
387 |
QString name = nameLine->text(); |
|
388 |
QString address = addressText->toPlainText(); |
|
389 |
QString firstName; |
|
390 |
QString lastName; |
|
391 |
QStringList nameList; |
|
392 |
||
393 |
int index = name.indexOf(" "); |
|
394 |
||
395 |
if (index != -1) { |
|
396 |
nameList = name.split(QRegExp("\\s+"), QString::SkipEmptyParts); |
|
397 |
firstName = nameList.first(); |
|
398 |
lastName = nameList.last(); |
|
399 |
} else { |
|
400 |
firstName = name; |
|
401 |
lastName = ""; |
|
402 |
} |
|
403 |
||
404 |
QString fileName = QFileDialog::getSaveFileName(this, |
|
405 |
tr("Export Contact"), "", |
|
406 |
tr("vCard Files (*.vcf);;All Files (*)")); |
|
407 |
||
408 |
if (fileName.isEmpty()) |
|
409 |
return; |
|
410 |
||
411 |
QFile file(fileName); |
|
412 |
//! [export function part1] |
|
413 |
||
414 |
//! [export function part2] |
|
415 |
if (!file.open(QIODevice::WriteOnly)) { |
|
416 |
QMessageBox::information(this, tr("Unable to open file"), |
|
417 |
file.errorString()); |
|
418 |
return; |
|
419 |
} |
|
420 |
||
421 |
QTextStream out(&file); |
|
422 |
//! [export function part2] |
|
423 |
||
424 |
//! [export function part3] |
|
425 |
out << "BEGIN:VCARD" << "\n"; |
|
426 |
out << "VERSION:2.1" << "\n"; |
|
427 |
out << "N:" << lastName << ";" << firstName << "\n"; |
|
428 |
||
429 |
if (!nameList.isEmpty()) |
|
430 |
out << "FN:" << nameList.join(" ") << "\n"; |
|
431 |
else |
|
432 |
out << "FN:" << firstName << "\n"; |
|
433 |
//! [export function part3] |
|
434 |
||
435 |
//! [export function part4] |
|
436 |
address.replace(";", "\\;", Qt::CaseInsensitive); |
|
437 |
address.replace("\n", ";", Qt::CaseInsensitive); |
|
438 |
address.replace(",", " ", Qt::CaseInsensitive); |
|
439 |
||
440 |
out << "ADR;HOME:;" << address << "\n"; |
|
441 |
out << "END:VCARD" << "\n"; |
|
442 |
||
443 |
QMessageBox::information(this, tr("Export Successful"), |
|
444 |
tr("\"%1\" has been exported as a vCard.").arg(name)); |
|
445 |
} |
|
446 |
//! [export function part4] |