author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
child 33 | 3e2da88830cd |
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 |
||
149 |
if (name == "" || address == "") { |
|
150 |
QMessageBox::information(this, tr("Empty Field"), |
|
151 |
tr("Please enter a name and address.")); |
|
152 |
} |
|
153 |
||
154 |
if (currentMode == AddingMode) { |
|
155 |
||
156 |
if (!contacts.contains(name)) { |
|
157 |
contacts.insert(name, address); |
|
158 |
QMessageBox::information(this, tr("Add Successful"), |
|
159 |
tr("\"%1\" has been added to your address book.").arg(name)); |
|
160 |
} else { |
|
161 |
QMessageBox::information(this, tr("Add Unsuccessful"), |
|
162 |
tr("Sorry, \"%1\" is already in your address book.").arg(name)); |
|
163 |
} |
|
164 |
} else if (currentMode == EditingMode) { |
|
165 |
||
166 |
if (oldName != name) { |
|
167 |
if (!contacts.contains(name)) { |
|
168 |
QMessageBox::information(this, tr("Edit Successful"), |
|
169 |
tr("\"%1\" has been edited in your address book.").arg(oldName)); |
|
170 |
contacts.remove(oldName); |
|
171 |
contacts.insert(name, address); |
|
172 |
} else { |
|
173 |
QMessageBox::information(this, tr("Edit Unsuccessful"), |
|
174 |
tr("Sorry, \"%1\" is already in your address book.").arg(name)); |
|
175 |
} |
|
176 |
} else if (oldAddress != address) { |
|
177 |
QMessageBox::information(this, tr("Edit Successful"), |
|
178 |
tr("\"%1\" has been edited in your address book.").arg(name)); |
|
179 |
contacts[name] = address; |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
updateInterface(NavigationMode); |
|
184 |
} |
|
185 |
||
186 |
void AddressBook::cancel() |
|
187 |
{ |
|
188 |
nameLine->setText(oldName); |
|
189 |
addressText->setText(oldAddress); |
|
190 |
updateInterface(NavigationMode); |
|
191 |
} |
|
192 |
||
193 |
void AddressBook::removeContact() |
|
194 |
{ |
|
195 |
QString name = nameLine->text(); |
|
196 |
QString address = addressText->toPlainText(); |
|
197 |
||
198 |
if (contacts.contains(name)) { |
|
199 |
||
200 |
int button = QMessageBox::question(this, |
|
201 |
tr("Confirm Remove"), |
|
202 |
tr("Are you sure you want to remove \"%1\"?").arg(name), |
|
203 |
QMessageBox::Yes | QMessageBox::No); |
|
204 |
||
205 |
if (button == QMessageBox::Yes) { |
|
206 |
||
207 |
previous(); |
|
208 |
contacts.remove(name); |
|
209 |
||
210 |
QMessageBox::information(this, tr("Remove Successful"), |
|
211 |
tr("\"%1\" has been removed from your address book.").arg(name)); |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
updateInterface(NavigationMode); |
|
216 |
} |
|
217 |
||
218 |
void AddressBook::next() |
|
219 |
{ |
|
220 |
QString name = nameLine->text(); |
|
221 |
QMap<QString, QString>::iterator i = contacts.find(name); |
|
222 |
||
223 |
if (i != contacts.end()) |
|
224 |
i++; |
|
225 |
||
226 |
if (i == contacts.end()) |
|
227 |
i = contacts.begin(); |
|
228 |
||
229 |
nameLine->setText(i.key()); |
|
230 |
addressText->setText(i.value()); |
|
231 |
} |
|
232 |
||
233 |
void AddressBook::previous() |
|
234 |
{ |
|
235 |
QString name = nameLine->text(); |
|
236 |
QMap<QString, QString>::iterator i = contacts.find(name); |
|
237 |
||
238 |
if (i == contacts.end()) { |
|
239 |
nameLine->clear(); |
|
240 |
addressText->clear(); |
|
241 |
return; |
|
242 |
} |
|
243 |
||
244 |
if (i == contacts.begin()) |
|
245 |
i = contacts.end(); |
|
246 |
||
247 |
i--; |
|
248 |
nameLine->setText(i.key()); |
|
249 |
addressText->setText(i.value()); |
|
250 |
} |
|
251 |
||
252 |
void AddressBook::findContact() |
|
253 |
{ |
|
254 |
dialog->show(); |
|
255 |
||
256 |
if (dialog->exec() == 1) { |
|
257 |
QString contactName = dialog->getFindText(); |
|
258 |
||
259 |
if (contacts.contains(contactName)) { |
|
260 |
nameLine->setText(contactName); |
|
261 |
addressText->setText(contacts.value(contactName)); |
|
262 |
} else { |
|
263 |
QMessageBox::information(this, tr("Contact Not Found"), |
|
264 |
tr("Sorry, \"%1\" is not in your address book.").arg(contactName)); |
|
265 |
return; |
|
266 |
} |
|
267 |
} |
|
268 |
||
269 |
updateInterface(NavigationMode); |
|
270 |
} |
|
271 |
void AddressBook::updateInterface(Mode mode) |
|
272 |
{ |
|
273 |
currentMode = mode; |
|
274 |
||
275 |
switch (currentMode) { |
|
276 |
||
277 |
case AddingMode: |
|
278 |
case EditingMode: |
|
279 |
||
280 |
nameLine->setReadOnly(false); |
|
281 |
nameLine->setFocus(Qt::OtherFocusReason); |
|
282 |
addressText->setReadOnly(false); |
|
283 |
||
284 |
addButton->setEnabled(false); |
|
285 |
editButton->setEnabled(false); |
|
286 |
removeButton->setEnabled(false); |
|
287 |
||
288 |
nextButton->setEnabled(false); |
|
289 |
previousButton->setEnabled(false); |
|
290 |
||
291 |
submitButton->show(); |
|
292 |
cancelButton->show(); |
|
293 |
||
294 |
loadButton->setEnabled(false); |
|
295 |
saveButton->setEnabled(false); |
|
296 |
exportButton->setEnabled(false); |
|
297 |
break; |
|
298 |
||
299 |
case NavigationMode: |
|
300 |
||
301 |
if (contacts.isEmpty()) { |
|
302 |
nameLine->clear(); |
|
303 |
addressText->clear(); |
|
304 |
} |
|
305 |
||
306 |
nameLine->setReadOnly(true); |
|
307 |
addressText->setReadOnly(true); |
|
308 |
addButton->setEnabled(true); |
|
309 |
||
310 |
int number = contacts.size(); |
|
311 |
editButton->setEnabled(number >= 1); |
|
312 |
removeButton->setEnabled(number >= 1); |
|
313 |
findButton->setEnabled(number > 2); |
|
314 |
nextButton->setEnabled(number > 1); |
|
315 |
previousButton->setEnabled(number > 1); |
|
316 |
||
317 |
submitButton->hide(); |
|
318 |
cancelButton->hide(); |
|
319 |
||
320 |
exportButton->setEnabled(number >= 1); |
|
321 |
||
322 |
loadButton->setEnabled(true); |
|
323 |
saveButton->setEnabled(number >= 1); |
|
324 |
break; |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
void AddressBook::saveToFile() |
|
329 |
{ |
|
330 |
QString fileName = QFileDialog::getSaveFileName(this, |
|
331 |
tr("Save Address Book"), "", |
|
332 |
tr("Address Book (*.abk);;All Files (*)")); |
|
333 |
||
334 |
if (fileName.isEmpty()) |
|
335 |
return; |
|
336 |
else { |
|
337 |
QFile file(fileName); |
|
338 |
||
339 |
if (!file.open(QIODevice::WriteOnly)) { |
|
340 |
QMessageBox::information(this, tr("Unable to open file"), |
|
341 |
file.errorString()); |
|
342 |
return; |
|
343 |
} |
|
344 |
||
345 |
QDataStream out(&file); |
|
346 |
out.setVersion(QDataStream::Qt_4_3); |
|
347 |
out << contacts; |
|
348 |
} |
|
349 |
||
350 |
updateInterface(NavigationMode); |
|
351 |
} |
|
352 |
||
353 |
void AddressBook::loadFromFile() |
|
354 |
{ |
|
355 |
QString fileName = QFileDialog::getOpenFileName(this, |
|
356 |
tr("Open Address Book"), "", |
|
357 |
tr("Address Book (*.abk);;All Files (*)")); |
|
358 |
||
359 |
if (fileName.isEmpty()) |
|
360 |
return; |
|
361 |
else { |
|
362 |
QFile file(fileName); |
|
363 |
||
364 |
if (!file.open(QIODevice::ReadOnly)) { |
|
365 |
QMessageBox::information(this, tr("Unable to open file"), |
|
366 |
file.errorString()); |
|
367 |
return; |
|
368 |
} |
|
369 |
||
370 |
QDataStream in(&file); |
|
371 |
in.setVersion(QDataStream::Qt_4_3); |
|
372 |
contacts.empty(); // empty existing contacts |
|
373 |
in >> contacts; |
|
374 |
||
375 |
QMap<QString, QString>::iterator i = contacts.begin(); |
|
376 |
nameLine->setText(i.key()); |
|
377 |
addressText->setText(i.value()); |
|
378 |
} |
|
379 |
||
380 |
updateInterface(NavigationMode); |
|
381 |
} |
|
382 |
||
383 |
//! [export function part1] |
|
384 |
void AddressBook::exportAsVCard() |
|
385 |
{ |
|
386 |
QString name = nameLine->text(); |
|
387 |
QString address = addressText->toPlainText(); |
|
388 |
QString firstName; |
|
389 |
QString lastName; |
|
390 |
QStringList nameList; |
|
391 |
||
392 |
int index = name.indexOf(" "); |
|
393 |
||
394 |
if (index != -1) { |
|
395 |
nameList = name.split(QRegExp("\\s+"), QString::SkipEmptyParts); |
|
396 |
firstName = nameList.first(); |
|
397 |
lastName = nameList.last(); |
|
398 |
} else { |
|
399 |
firstName = name; |
|
400 |
lastName = ""; |
|
401 |
} |
|
402 |
||
403 |
QString fileName = QFileDialog::getSaveFileName(this, |
|
404 |
tr("Export Contact"), "", |
|
405 |
tr("vCard Files (*.vcf);;All Files (*)")); |
|
406 |
||
407 |
if (fileName.isEmpty()) |
|
408 |
return; |
|
409 |
||
410 |
QFile file(fileName); |
|
411 |
//! [export function part1] |
|
412 |
||
413 |
//! [export function part2] |
|
414 |
if (!file.open(QIODevice::WriteOnly)) { |
|
415 |
QMessageBox::information(this, tr("Unable to open file"), |
|
416 |
file.errorString()); |
|
417 |
return; |
|
418 |
} |
|
419 |
||
420 |
QTextStream out(&file); |
|
421 |
//! [export function part2] |
|
422 |
||
423 |
//! [export function part3] |
|
424 |
out << "BEGIN:VCARD" << "\n"; |
|
425 |
out << "VERSION:2.1" << "\n"; |
|
426 |
out << "N:" << lastName << ";" << firstName << "\n"; |
|
427 |
||
428 |
if (!nameList.isEmpty()) |
|
429 |
out << "FN:" << nameList.join(" ") << "\n"; |
|
430 |
else |
|
431 |
out << "FN:" << firstName << "\n"; |
|
432 |
//! [export function part3] |
|
433 |
||
434 |
//! [export function part4] |
|
435 |
address.replace(";", "\\;", Qt::CaseInsensitive); |
|
436 |
address.replace("\n", ";", Qt::CaseInsensitive); |
|
437 |
address.replace(",", " ", Qt::CaseInsensitive); |
|
438 |
||
439 |
out << "ADR;HOME:;" << address << "\n"; |
|
440 |
out << "END:VCARD" << "\n"; |
|
441 |
||
442 |
QMessageBox::information(this, tr("Export Successful"), |
|
443 |
tr("\"%1\" has been exported as a vCard.").arg(name)); |
|
444 |
} |
|
445 |
//! [export function part4] |