emailuis/nmsettingui/src/nmmailboxsettingview.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <qinputcontext.h>
       
    19 
       
    20 #include <hbinstance.h>
       
    21 #include <hbmainwindow.h>
       
    22 #include <hbaction.h>
       
    23 #include <hbdataform.h>
       
    24 #include <hbdataformmodel.h>
       
    25 #include <hbdocumentloader.h>
       
    26 
       
    27 #include "nmmailboxsettingview.h"
       
    28 #include "nmmailboxsettingsmanager.h"
       
    29 #include "nmsettingsformcustomitems.h"
       
    30 
       
    31 
       
    32 static const char *NMSETTINGUI_SETTING_VIEW_XML = ":/docml/nmmailboxsettingview.docml";
       
    33 static const char *NMSETTINGUI_SETTING_VIEW_FORM = "mailboxSettingViewForm";
       
    34 
       
    35 
       
    36 /*!
       
    37     \class NmMailboxSettingView
       
    38     \brief Setting view for the mailbox specific settings.
       
    39 
       
    40 */
       
    41 
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 /*!
       
    46     Constructor of NmMailboxSettingView.
       
    47 
       
    48     Creates the setting form and form model that contain the setting items.
       
    49     Populates the form model items from the correct settings plug-in through
       
    50     NmMailboxSettingsManager.
       
    51 */
       
    52 NmMailboxSettingView::NmMailboxSettingView(const NmId &mailboxId,
       
    53     const QString &mailboxName,
       
    54     NmMailboxSettingsManager& settingsManager,
       
    55     QGraphicsItem *parent)
       
    56     : CpBaseSettingView(0, parent),
       
    57       mForm(NULL),
       
    58       mModel(NULL),
       
    59       mMailboxId(mailboxId.id())
       
    60 {
       
    61     NM_FUNCTION;
       
    62     
       
    63     setTitle(mailboxName);
       
    64 
       
    65     HbDocumentLoader documentLoader;
       
    66     bool documentLoaded = false;
       
    67     QObjectList objectList;
       
    68     objectList.append(this);
       
    69 
       
    70     documentLoader.setObjectTree(objectList);
       
    71     QObjectList widgetList =
       
    72         documentLoader.load(NMSETTINGUI_SETTING_VIEW_XML, &documentLoaded);
       
    73 
       
    74     if (documentLoaded && widgetList.count()) {
       
    75         // Get the form widget.
       
    76         mForm = qobject_cast<HbDataForm*>(
       
    77             documentLoader.findWidget(NMSETTINGUI_SETTING_VIEW_FORM));
       
    78     }
       
    79 
       
    80     if (mForm) {
       
    81         
       
    82         connect(mForm, SIGNAL(pressed(QModelIndex)),
       
    83                 this, SLOT(itemPress(QModelIndex)));
       
    84         
       
    85         // Fix for dataform item recycling.
       
    86         mForm->setItemRecycling(false);
       
    87 
       
    88         // Set the form for the view.
       
    89         setWidget(mForm);
       
    90 
       
    91         // Make the custom items available.
       
    92         NmSettingsFormCustomItems *customItems = new NmSettingsFormCustomItems(mForm);
       
    93         QList<HbAbstractViewItem *> prototypes  = mForm->itemPrototypes();
       
    94         prototypes.append(customItems);
       
    95         mForm->setItemPrototypes(prototypes);
       
    96 
       
    97         // Set up the model.
       
    98         mModel = new HbDataFormModel();
       
    99         settingsManager.populateModel(*mModel, *mForm, mailboxId);
       
   100         mForm->setModel(mModel);
       
   101     }
       
   102 }
       
   103 
       
   104 
       
   105 /*!
       
   106     Destructor of NmMailboxSettingView.
       
   107 */
       
   108 NmMailboxSettingView::~NmMailboxSettingView()
       
   109 {
       
   110     NM_FUNCTION;
       
   111     
       
   112     delete mForm;
       
   113     delete mModel;
       
   114 }
       
   115 
       
   116 
       
   117 /*!
       
   118     Private slot for handling mailbox list event changes.
       
   119 
       
   120     \param mailboxId The ID of the mailbox of which list has been changed.
       
   121     \param type The type of the change.
       
   122 */
       
   123 void NmMailboxSettingView::mailboxListChanged(const NmId &mailboxId,
       
   124     NmSettings::MailboxEventType type)
       
   125 {
       
   126     NM_FUNCTION;
       
   127     
       
   128     Q_UNUSED(mailboxId);
       
   129     Q_UNUSED(type);
       
   130 
       
   131     HbAction *action = navigationAction();
       
   132     if (action) {
       
   133         action->activate(QAction::Trigger);
       
   134     }
       
   135 }
       
   136 
       
   137 
       
   138 /*!
       
   139     Private slot for handling mailbox property changes.
       
   140 
       
   141     \param mailboxId The ID of the mailbox of which property was changed.
       
   142     \param property The type of the property that changed.
       
   143     \param value The new value related to the change.
       
   144 */
       
   145 void NmMailboxSettingView::mailboxPropertyChanged(const NmId &mailboxId,
       
   146                                                   QVariant property,
       
   147                                                   QVariant value)
       
   148 {
       
   149     NM_FUNCTION;
       
   150     
       
   151     Q_UNUSED(mailboxId);
       
   152 
       
   153     switch (property.toInt()) {
       
   154         case NmSettings::MailboxName: {
       
   155             setTitle(value.toString());
       
   156             break;
       
   157         }
       
   158         default: {
       
   159             break;
       
   160         }
       
   161     }
       
   162 }
       
   163 
       
   164 /*!
       
   165     Returns the mailbox id for this mailbox setting view.    
       
   166 */
       
   167 NmId NmMailboxSettingView::mailboxId()
       
   168 {
       
   169     return mMailboxId;
       
   170 }
       
   171 
       
   172 /*!
       
   173     Called when item is pressed on the view.
       
   174 
       
   175     \param index Index to the pressed item.
       
   176 */
       
   177 void NmMailboxSettingView::itemPress(const QModelIndex &index)
       
   178 {
       
   179     NM_FUNCTION;
       
   180     
       
   181     int type(index.data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   182     
       
   183     if (type == HbDataFormModelItem::GroupItem) {
       
   184         // Scroll the groupitem to top if needed.
       
   185         HbDataFormViewItem *item = static_cast<HbDataFormViewItem *>(mForm->itemByIndex(index));
       
   186         
       
   187         if (!item->isExpanded()) {
       
   188             mForm->scrollTo(index, HbAbstractItemView::PositionAtTop);
       
   189         }else {
       
   190             // Hide the virtual keyboard
       
   191             QInputContext *ic = qApp->inputContext();
       
   192             if (ic) {
       
   193                 QEvent *closeEvent = new QEvent(QEvent::CloseSoftwareInputPanel);
       
   194                 ic->filterEvent(closeEvent);
       
   195                 delete closeEvent;
       
   196             }
       
   197         }
       
   198     }
       
   199     
       
   200     if (type == HbDataFormModelItem::TextItem) {
       
   201         // Turn off predictive input for line-edit.
       
   202         HbDataFormViewItem *item = static_cast<HbDataFormViewItem *>(mForm->itemByIndex(index));
       
   203         HbWidget *widget = item->dataItemContentWidget();
       
   204         widget->setInputMethodHints(Qt::ImhNoPredictiveText);
       
   205     }
       
   206 }
       
   207 // End of file.