examples/samplephonebook/phonebook.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:BSD$
       
    10 ** You may use this file under the terms of the BSD license as follows:
       
    11 **
       
    12 ** "Redistribution and use in source and binary forms, with or without
       
    13 ** modification, are permitted provided that the following conditions are
       
    14 ** met:
       
    15 **   * Redistributions of source code must retain the above copyright
       
    16 **     notice, this list of conditions and the following disclaimer.
       
    17 **   * Redistributions in binary form must reproduce the above copyright
       
    18 **     notice, this list of conditions and the following disclaimer in
       
    19 **     the documentation and/or other materials provided with the
       
    20 **     distribution.
       
    21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
       
    22 **     the names of its contributors may be used to endorse or promote
       
    23 **     products derived from this software without specific prior written
       
    24 **     permission.
       
    25 **
       
    26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
       
    37 ** $QT_END_LICENSE$
       
    38 **
       
    39 ****************************************************************************/
       
    40 
       
    41 #include "phonebook.h"
       
    42 #include "contactlistpage.h"
       
    43 #include "contacteditor.h"
       
    44 #include "filterpage.h"
       
    45 
       
    46 #include <QtGui>
       
    47 
       
    48 PhoneBook::PhoneBook(QWidget *parent)
       
    49         : QMainWindow(parent)
       
    50 {
       
    51     QWidget *centralWidget = new QWidget(this);
       
    52    
       
    53     m_editorPage = new ContactEditor(centralWidget);
       
    54     connect(m_editorPage, SIGNAL(showListPage()), this, SLOT(activateList()));
       
    55 
       
    56     m_filterPage = new FilterPage(centralWidget);
       
    57     connect(m_filterPage, SIGNAL(showListPage(QContactFilter)), this, SLOT(activateList(QContactFilter)));
       
    58 
       
    59     m_listPage = new ContactListPage(this, centralWidget);
       
    60     connect(m_listPage, SIGNAL(showEditorPage(QContactLocalId)), this, SLOT(activateEditor(QContactLocalId)));
       
    61     connect(m_listPage, SIGNAL(showFilterPage(QContactFilter)), this, SLOT(activateFind()));
       
    62     connect(m_listPage, SIGNAL(managerChanged(QContactManager*)), this, SLOT(managerChanged(QContactManager*)));
       
    63     connect(m_listPage, SIGNAL(clearFilter()), m_filterPage, SLOT(clearFilter()));
       
    64 
       
    65     m_stackedWidget = new QStackedWidget(centralWidget);
       
    66     m_stackedWidget->addWidget(m_listPage);
       
    67     m_stackedWidget->addWidget(m_editorPage);
       
    68     m_stackedWidget->addWidget(m_filterPage);
       
    69     m_stackedWidget->setCurrentIndex(0);
       
    70 
       
    71     QVBoxLayout *centralLayout = new QVBoxLayout;
       
    72     centralLayout->addWidget(m_stackedWidget);
       
    73     centralWidget->setLayout(centralLayout);
       
    74     
       
    75     setCentralWidget(centralWidget);
       
    76 }
       
    77 
       
    78 PhoneBook::~PhoneBook()
       
    79 {
       
    80 }
       
    81 
       
    82 void PhoneBook::activateEditor(QContactLocalId contactId)
       
    83 {
       
    84 #if !(defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5))
       
    85     menuBar()->setVisible(false);
       
    86 #endif
       
    87     m_editorPage->setCurrentContact(m_manager, contactId);
       
    88     m_stackedWidget->setCurrentIndex(1); // list = 0, editor = 1, find = 2.
       
    89 }
       
    90 
       
    91 void PhoneBook::activateList(const QContactFilter& filter)
       
    92 {
       
    93 #if !(defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5))
       
    94     menuBar()->setVisible(true);
       
    95 #endif
       
    96     m_currentFilter = filter;
       
    97     activateList(); // call base now.
       
    98 }
       
    99 
       
   100 void PhoneBook::activateList()
       
   101 {
       
   102 #if !(defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5))
       
   103     menuBar()->setVisible(true);
       
   104 #endif
       
   105     m_listPage->rebuildList(m_currentFilter);
       
   106     m_stackedWidget->setCurrentIndex(0); // list = 0, editor = 1, find = 2.
       
   107 }
       
   108 
       
   109 void PhoneBook::activateFind()
       
   110 {
       
   111 #if !(defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5))
       
   112     menuBar()->setVisible(false);
       
   113 #endif
       
   114     m_stackedWidget->setCurrentIndex(2); // list = 0, editor = 1, find = 2.
       
   115 }
       
   116 
       
   117 void PhoneBook::managerChanged(QContactManager *manager)
       
   118 {
       
   119     m_manager = manager;
       
   120     m_editorPage->setCurrentContact(m_manager, 0); // must reset the manager of the editor.
       
   121 }