qtmobility/examples/samplephonebook/contactlistpage.cpp
changeset 5 453da2cfceef
parent 4 90517678cc4f
child 11 06b8e2af4411
--- a/qtmobility/examples/samplephonebook/contactlistpage.cpp	Mon May 03 13:18:40 2010 +0300
+++ b/qtmobility/examples/samplephonebook/contactlistpage.cpp	Fri May 14 16:41:33 2010 +0300
@@ -6,35 +6,34 @@
 **
 ** This file is part of the Qt Mobility Components.
 **
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
 **
-** In addition, as a special exception, Nokia gives you certain additional
-** rights.  These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**   * Redistributions of source code must retain the above copyright
+**     notice, this list of conditions and the following disclaimer.
+**   * Redistributions in binary form must reproduce the above copyright
+**     notice, this list of conditions and the following disclaimer in
+**     the documentation and/or other materials provided with the
+**     distribution.
+**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+**     the names of its contributors may be used to endorse or promote
+**     products derived from this software without specific prior written
+**     permission.
 **
-**
-**
-**
-**
-**
-**
-**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
@@ -124,22 +123,13 @@
 
     // Add items to the menu
     if (m_mainWindow) {
-#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
+#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_OS_WINCE)
+        // These platforms need their menu items added directly to the menu bar.
         QMenuBar *optionsMenu = m_mainWindow->menuBar();
 #else
         QMenu *optionsMenu = new QMenu(tr("&Contacts"), this);
         m_mainWindow->menuBar()->addMenu(optionsMenu);
 #endif
-        QAction* addAction = new QAction(tr("&Add Contact..."), this);
-        connect(addAction, SIGNAL(triggered()), this, SLOT(addClicked()));
-        optionsMenu->addAction(addAction);
-        QAction* editAction = new QAction(tr("&Edit Contact..."), this);
-        connect(editAction, SIGNAL(triggered()), this, SLOT(editClicked()));
-        optionsMenu->addAction(editAction);
-        QAction* deleteAction = new QAction(tr("&Delete Contact"), this);
-        connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteClicked()));
-        optionsMenu->addAction(deleteAction);
-        optionsMenu->addSeparator();
         QAction* filterAction = new QAction(tr("Apply &Filter..."), this);
         connect(filterAction, SIGNAL(triggered()), this, SLOT(filterClicked()));
         optionsMenu->addAction(filterAction);
@@ -157,9 +147,12 @@
         optionsMenu->addAction(exportAction);
         optionsMenu->addSeparator();
 #endif
+#if !(defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6))
+        // Maemo applications don't have an Exit button in the menu.
         QAction* exitAction = new QAction(tr("E&xit"), this);
         connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
         optionsMenu->addAction(exitAction);
+#endif
     }
 
     // force update to backend.
@@ -210,16 +203,14 @@
 
     m_filterActiveLabel->setVisible(m_currentFilter != QContactFilter());
 
-    QContact currContact;
     m_contactsList->clear();
     m_idToListIndex.clear();
-    QList<QContactLocalId> contactIds = m_manager->contactIds(m_currentFilter);
-    foreach (const QContactLocalId& id, contactIds) {
+    m_contacts = m_manager->contacts(m_currentFilter);
+    foreach (QContact contact, m_contacts) {
         QListWidgetItem *currItem = new QListWidgetItem;
-        currContact = m_manager->contact(id);
-        currItem->setData(Qt::DisplayRole, currContact.displayLabel());
-        currItem->setData(Qt::UserRole, currContact.localId()); // also store the id of the contact.
-        m_idToListIndex.insert(currContact.localId(), m_contactsList->count());
+        currItem->setData(Qt::DisplayRole, contact.displayLabel());
+        currItem->setData(Qt::UserRole, contact.localId()); // also store the id of the contact.
+        m_idToListIndex.insert(contact.localId(), m_contactsList->count());
         m_contactsList->addItem(currItem);
     }
 }
@@ -283,6 +274,11 @@
             if (importer.importDocuments(reader.results())) {
                 QList<QContact> contacts = importer.contacts();
                 QMap<int, QContactManager::Error> errorMap;
+                QList<QContact>::iterator it = contacts.begin();
+                while (it != contacts.end()) {
+                    *it = m_manager->compatibleContact(*it);
+                    it++;
+                }
                 m_manager->saveContacts(&contacts, &errorMap);
                 rebuildList(m_currentFilter);
             }
@@ -295,10 +291,9 @@
 {
 #ifdef BUILD_VERSIT
     if (!m_manager) {
-        qWarning() << "No manager selected; cannot import";
+        qWarning() << "No manager selected; cannot export";
         return;
     }
-    QList<QContact> contacts = m_manager->contacts(QList<QContactSortOrder>(), QContactFetchHint());
     QString fileName = QFileDialog::getSaveFileName(this, tr("Save vCard"),
                                                     "./contacts.vcf",
                                                     tr("vCards (*.vcf)"));
@@ -306,7 +301,7 @@
     file.open(QIODevice::WriteOnly);
     if (file.isWritable()) {
         QVersitContactExporter exporter;
-        if(exporter.exportContacts(contacts, QVersitDocument::VCard30Type)) {
+        if(exporter.exportContacts(m_contacts, QVersitDocument::VCard30Type)) {
             QList<QVersitDocument> documents = exporter.documents();
             QVersitWriter writer;
             writer.setDevice(&file);