emailuis/nmailuiengine/src/nmmailboxlistmodel.cpp
changeset 30 759dc5235cdb
parent 27 9ba4404ef423
child 76 38bf5461e270
equal deleted inserted replaced
27:9ba4404ef423 30:759dc5235cdb
    32  */
    32  */
    33 NmMailboxListModel::NmMailboxListModel(NmDataManager &dataManager, QObject *parent)
    33 NmMailboxListModel::NmMailboxListModel(NmDataManager &dataManager, QObject *parent)
    34 :QStandardItemModel(parent),
    34 :QStandardItemModel(parent),
    35 mDataManager(dataManager)
    35 mDataManager(dataManager)
    36 {
    36 {
       
    37     NM_FUNCTION;
    37 }
    38 }
    38 
    39 
    39 /*!
    40 /*!
    40 	Destructor
    41 	Destructor
    41  */
    42  */
    42 NmMailboxListModel::~NmMailboxListModel()
    43 NmMailboxListModel::~NmMailboxListModel()
    43 {
    44 {
       
    45     NM_FUNCTION;
       
    46     
    44     clear();
    47     clear();
    45 }
    48 }
    46 
    49 
    47 /*!
    50 /*!
    48     Returns data specified by \a index. Only Qt::DisplayRole is supported in \a role.
    51     Returns data specified by \a index. Only Qt::DisplayRole is supported in \a role.
    49     The refresh method must have been called before this method can return any real data.
    52     The refresh method must have been called before this method can return any real data.
    50  */
    53  */
    51 QVariant NmMailboxListModel::data(const QModelIndex &index, int role) const
    54 QVariant NmMailboxListModel::data(const QModelIndex &index, int role) const
    52 {
    55 {
       
    56     NM_FUNCTION;
       
    57     
    53     QVariant qVariant;
    58     QVariant qVariant;
    54     if (index.isValid() && Qt::DisplayRole == role) {
    59     if (index.isValid() && Qt::DisplayRole == role) {
    55         NmMailboxListModelItem *item = static_cast<NmMailboxListModelItem*>(itemFromIndex(index));
    60         NmMailboxListModelItem *item = static_cast<NmMailboxListModelItem*>(itemFromIndex(index));
    56         NmMailboxMetaData *mailbox = item->itemMetaData();
    61         NmMailboxMetaData *mailbox = item->itemMetaData();
    57         qVariant = QVariant::fromValue(mailbox);
    62         qVariant = QVariant::fromValue(mailbox);
    63     This refreshes the data of the model.
    68     This refreshes the data of the model.
    64  */
    69  */
    65 void NmMailboxListModel::refresh(
    70 void NmMailboxListModel::refresh(
    66         QList<NmMailbox*> &mailboxList)
    71         QList<NmMailbox*> &mailboxList)
    67 {
    72 {
    68     NMLOG("nmuiengine: mailbox list model refresh");
    73     NM_FUNCTION;
       
    74     
    69     clear();
    75     clear();
    70     for (int i(0); i < mailboxList.count(); i++) {
    76     for (int i(0); i < mailboxList.count(); i++) {
    71         NmMailbox *mailbox = mailboxList[i];
    77         NmMailbox *mailbox = mailboxList[i];
    72         if (mailbox) {
    78         if (mailbox) {
    73             NmMailboxListModelItem *item = createMailboxItem(mailbox);
    79             NmMailboxListModelItem *item = createMailboxItem(mailbox);
    77 }
    83 }
    78 
    84 
    79 /*!
    85 /*!
    80     Updates specific model item.
    86     Updates specific model item.
    81     \param mailboxId Mailbox id.
    87     \param mailboxId Mailbox id.
    82     \param allowEmitDataChanged If <code>true</code> data changed signal
       
    83            is emitted \sa QStandardItem, otherwise signal is not send.
       
    84  */
    88  */
    85 void NmMailboxListModel::refreshModelItem(const NmId &mailboxId, bool allowEmitDataChanged)
    89 void NmMailboxListModel::refreshModelItem(const NmId &mailboxId)
    86 {
    90 {
    87     NMLOG("NmMailboxListModel::refreshModelItem");
    91     NM_FUNCTION;
    88 
    92     
    89     // Get correct mailbox data.
    93     // Get correct mailbox data.
    90     NmMailbox* mailbox = mDataManager.mailbox(mailboxId);
    94     NmMailbox* mailbox = mDataManager.mailbox(mailboxId);
    91     NmMailboxListModelItem *entryItem(NULL);
    95     NmMailboxListModelItem *entryItem(NULL);
    92 
    96 
    93     // Get correct entry item.
    97     // Get correct entry item.
   100         entryItem = NULL;
   104         entryItem = NULL;
   101     }
   105     }
   102 
   106 
   103     // Update entry item's data.
   107     // Update entry item's data.
   104     if (mailbox && entryItem) {
   108     if (mailbox && entryItem) {
   105         if (allowEmitDataChanged) {
   109         // Changes data and emits datachanged.
   106             // Changes data and emits datachanged.
   110         NmMailboxMetaData *metaData = new NmMailboxMetaData;
   107             NmMailboxMetaData *metaData = new NmMailboxMetaData;
   111         metaData->setId(mailbox->id());
   108             metaData->setId(mailbox->id());
   112         metaData->setName(mailbox->name());
   109             metaData->setName(mailbox->name());
   113         metaData->setAddress(mailbox->address().address());
   110             entryItem->setItemMetaData(metaData);
   114         entryItem->setItemMetaData(metaData);
   111         } else {
       
   112             // Only changes meta data information (mailbox name).
       
   113             // No need for updating mailbox id.
       
   114             // Do not call emitDataChanged, because it seems that if
       
   115             // emitDataChanged is called twice, it leads to KERN-EXEC 3 Panic.
       
   116             entryItem->itemMetaData()->setName(mailbox->name());
       
   117        }
       
   118     }
   115     }
   119     NMLOG("NmMailboxListModel::refreshModelItem - OK");
       
   120 }
   116 }
   121 
   117 
   122 /*!
   118 /*!
   123     Function handles mailbox events such as created, renamed and deleted
   119     Function handles mailbox events such as created, renamed and deleted
   124  */
   120  */
   125 void NmMailboxListModel::handleMailboxEvent(NmMailboxEvent event, const QList<NmId> &mailboxIds)
   121 void NmMailboxListModel::handleMailboxEvent(NmMailboxEvent event, const QList<NmId> &mailboxIds)
   126 {
   122 {
   127     NMLOG("NmMailboxListModel::handleMailboxEvent");
   123     NM_FUNCTION;
       
   124     
   128     for (int a(0); a < mailboxIds.count(); a++) {
   125     for (int a(0); a < mailboxIds.count(); a++) {
   129         NmId mailboxId = mailboxIds[a];
   126         NmId mailboxId = mailboxIds[a];
   130         switch (event) {
   127         switch (event) {
   131             case NmMailboxCreated: {
   128             case NmMailboxCreated: {
   132                 NmMailbox* mailbox = mDataManager.mailbox(mailboxId);
   129                 NmMailbox* mailbox = mDataManager.mailbox(mailboxId);
   172     Create mailbox item
   169     Create mailbox item
   173     \param mailbox
   170     \param mailbox
   174  */
   171  */
   175 NmMailboxListModelItem *NmMailboxListModel::createMailboxItem(const NmMailbox *mailbox)
   172 NmMailboxListModelItem *NmMailboxListModel::createMailboxItem(const NmMailbox *mailbox)
   176 {
   173 {
       
   174     NM_FUNCTION;
       
   175     
   177     NmMailboxMetaData *newMeta = new NmMailboxMetaData();
   176     NmMailboxMetaData *newMeta = new NmMailboxMetaData();
   178     newMeta->setId(mailbox->id());
   177     newMeta->setId(mailbox->id());
   179     newMeta->setName(mailbox->name());
   178     newMeta->setName(mailbox->name());
   180     newMeta->setAddress(mailbox->address().address());
   179     newMeta->setAddress(mailbox->address().address());
   181 
   180