Commit 62931997 authored by Kavindra Devi Palaraja's avatar Kavindra Devi Palaraja
Browse files

Doc - More of Part 7

Reviewed-By: TrustMe
parent 08345a27
......@@ -881,10 +881,13 @@
\gui{Save...} respectively. Ideally, it would be more user-friendly to set
the push buttons' labels to \gui{Load contacts from file} and
\gui{Save contacts to file}. However, due to the size of our push buttons,
we set the labels to \gui{Load...} and \gui{Save...} instead. Fortunately,
Qt Creator's \QD plugin provides a simple way to set tooltips with the
\c toolTip property. To test your tooltip, use \key{Ctrl+Alt+R} and hover
your mouse cursor on the push buttons.
we set the labels to \gui{Load...} and \gui{Save...} instead.
Fortunately, Qt Creator's \QD plugin provides a simple way to set tooltips
with the \c toolTip property. So, we set our buttons' tooltips to
\gui{Load contacts from file} and \gui{Save contacts to file} respectively.
To test your tooltip, use \key{Ctrl+Alt+R} and hover your mouse cursor on
the push buttons.
# screenshot of property editor
......@@ -894,7 +897,7 @@
We declare two public slots, \c saveToFile() and \c loadFromFile().
# code
\snippet examples/addressbook-sdk/part6/addressbook.h slot definition
Now lets look at the \c saveToFile() and \c loadFromFile() functions in
detail.
......@@ -988,7 +991,8 @@
\section1 Placing Widgets on The Form
We add a push button into our layout by dragging and dropping it in, with
\c exportButton as its \c objectName.
\c exportButton as its \c objectName. The \c toolTip property is set to
\gui{Export as vCard}.
# screenshot
......
......@@ -31,6 +31,8 @@ AddressBook::AddressBook(QWidget *parent)
SLOT(removeContact()));
connect(ui->findButton, SIGNAL(clicked()), this,
SLOT(findContact()));
connect(ui->exportButton, SIGNAL(clicked()), this,
SLOT(exportAsVCard()));
setWindowTitle(tr("Simple Address Book"));
}
......@@ -281,7 +283,7 @@ void AddressBook::loadFromFile()
in >> contacts;
if (contacts.isEmpty()) {
QMessagebox::information(this, tr("No contacts in file"),
QMessageBox::information(this, tr("No contacts in file"),
tr("The file you are attempting to open contains no contacts."));
} else {
QMap<QString, QString>::iterator i = contacts.begin();
......@@ -292,3 +294,59 @@ void AddressBook::loadFromFile()
updateInterface(NavigationMode);
}
void AddressBook::exportAsVCard()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
QString firstName;
QString lastName;
QStringList nameList;
int index = name.indexOf(" ");
if (index != -1) {
nameList = name.split(QRegExp("\\s+"), QString::SkipEmptyParts);
firstName = nameList.first();
lastName = nameList.last();
} else {
firstName = name;
lastName = "";
}
QString fileName = QFileDialog::getSaveFileName(this,
tr("Export Coontact"), "",
tr("vCard files (*.vcf);;All Files (*)"));
if (fileName.isEmpty())
return;
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
QTextStream out(&file);
out << "BEGIN:VCARD" << "\n";
out << "VERSION:2.1" << "\n";
out << "N:" << lastName << ";" << firstName << "\n";
if (!nameList.isEmpty())
out << "FN:" << nameList.join(" ") << "\n";
else
out << "FN:" << firstName << "\n";
address.replace(";", "\\;", Qt::CaseInsensitive);
address.replace("\n", ";", Qt::CaseInsensitive);
address.replace(",", " ", Qt::CaseInsensitive);
out << "ADR;HOME:;" << address << "\n";
out << "END;VCARD" << "\n";
QMessageBox::information(this, tr("Export Successful"),
tr("\%1\" has been exported as a vCard.").arg(name));
}
......@@ -29,10 +29,11 @@ public slots:
void next();
void previous();
void findContact();
//! [slot definition]
void saveToFile();
void loadFromFile();
//! [slot definition]
void exportAsVCard();
//! [slot definition]
private:
Ui::AddressBook *ui;
......
......@@ -103,6 +103,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportButton">
<property name="toolTip">
<string>Export as vCard</string>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment