OSDN Git Service

Doc - More on Part 5
authorKavindra Devi Palaraja <kavindra.palaraja@nokia.com>
Wed, 10 Jun 2009 15:06:25 +0000 (17:06 +0200)
committerKavindra Devi Palaraja <kavindra.palaraja@nokia.com>
Mon, 15 Jun 2009 15:48:09 +0000 (17:48 +0200)
RevBy:    TrustMe

doc/examples/addressbook-sdk/part5/addressbook.cpp
doc/examples/addressbook-sdk/part5/addressbook.h
doc/examples/addressbook-sdk/part5/finddialog.cpp

index 5509ff4..e14d950 100644 (file)
@@ -41,6 +41,11 @@ AddressBook::AddressBook(QWidget *parent)
     removeButton = ui->removeButton;
     removeButton->setEnabled(false);
 
+    findButton = new QPushButton;
+    findButton = ui->findButton;
+
+    dialog = new FindDialog;
+
     connect(addButton, SIGNAL(clicked()), this,
                 SLOT(addContact()));
     connect(submitButton, SIGNAL(clicked()), this,
@@ -55,6 +60,8 @@ AddressBook::AddressBook(QWidget *parent)
                 SLOT(editContact()));
     connect(removeButton, SIGNAL(clicked()), this,
                 SLOT(removeContact()));
+    connect(findButton, SIGNAL(clicked()), this,
+                SLOT(findContact()));
 
     setWindowTitle(tr("Simple Address Book"));
 }
@@ -235,3 +242,23 @@ void AddressBook::updateInterface(Mode mode)
         break;
     }
 }
+
+void AddressBook::findContact()
+{
+    dialog->show();
+
+    if (dialog->exec() == QDialog::Accepted) {
+        QString contactName = dialog->getFindText();
+
+        if (contacts.contains(contactName)) {
+            nameLine->setText(contactName);
+            addressText->setText(contacts.value(contactName));
+        } else {
+            QMessageBox::information(this, tr("Contact Not Found"),
+                tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
+            return;
+        }
+    }
+
+    updateInterface(NavigationMode);
+}
index 7958cb6..9bc1f75 100644 (file)
@@ -6,6 +6,7 @@
 #include <QtGui/QLineEdit>
 #include <QtGui/QTextEdit>
 #include <QtGui/QMessageBox>
+#include "finddialog.h"
 
 
 namespace Ui
@@ -30,6 +31,7 @@ public slots:
     void removeContact();
     void next();
     void previous();
+    void findContact();
 
 private:
     Ui::AddressBook *ui;
@@ -42,6 +44,7 @@ private:
     QPushButton *removeButton;
     QPushButton *nextButton;
     QPushButton *previousButton;
+    QPushButton *findButton;
     QLineEdit *nameLine;
     QTextEdit *addressText;
 
@@ -49,6 +52,7 @@ private:
     QString oldName;
     QString oldAddress;
     Mode currentMode;
+    FindDialog *dialog;
 };
 
 #endif // ADDRESSBOOK_H
index 15002d6..89ee5e0 100644 (file)
@@ -6,6 +6,17 @@ FindDialog::FindDialog(QWidget *parent) :
     m_ui(new Ui::FindDialog)
 {
     m_ui->setupUi(this);
+    lineEdit = new QLineEdit;
+    lineEdit = m_ui->lineEdit;
+
+    findButton = new QPushButton;
+    findButton = m_ui->findButton;
+
+    findText = "";
+
+    connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
+
+    setWindowTItle(tr("Find a Contact"));
 }
 
 FindDialog::~FindDialog()
@@ -15,8 +26,20 @@ FindDialog::~FindDialog()
 
 void FindDialog::findClicked()
 {
+    QString text = lineEdit->text();
+
+    if (text.isEmpty()) {
+        QMessageBox::information(this, tr("Empty Field"),
+            tr("Please enter a name."));
+        return;
+    } else {
+        findText = text;
+        lineEdit->clear();
+        hide();
+    }
 }
 
 QString FindDialog::getFindText()
 {
+    return findText;
 }