messagingapp/msgui/msgapp/src/msglistview.cpp
changeset 44 36f374c67aa8
parent 34 84197e66a4bd
child 47 5b14749788d7
child 52 12db4185673b
equal deleted inserted replaced
43:35b64624a9e7 44:36f374c67aa8
    58 
    58 
    59 //itemspecific menu
    59 //itemspecific menu
    60 #define LOC_OPEN hbTrId("txt_common_menu_open")
    60 #define LOC_OPEN hbTrId("txt_common_menu_open")
    61 #define LOC_SAVETO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
    61 #define LOC_SAVETO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
    62 #define LOC_DELETE_CONVERSATION hbTrId("txt_messaging_menu_delete_conversation")
    62 #define LOC_DELETE_CONVERSATION hbTrId("txt_messaging_menu_delete_conversation")
    63 #define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info")
    63 #define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info")
    64 
       
    65 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
       
    66 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
       
    67 
    64 
    68 //main menu
    65 //main menu
    69 #define LOC_SETTINGS    hbTrId("txt_messaging_opt_settings")
    66 #define LOC_SETTINGS    hbTrId("txt_messaging_opt_settings")
    70 
    67 
    71 #define LOC_TB_VIEW_EXTN hbTrId("txt_messaging_button_view")
    68 #define LOC_TB_VIEW_EXTN hbTrId("txt_messaging_button_view")
    79 // MsgListView::MsgListView
    76 // MsgListView::MsgListView
    80 // @see header
    77 // @see header
    81 //---------------------------------------------------------------
    78 //---------------------------------------------------------------
    82 MsgListView::MsgListView(QGraphicsItem *parent) :
    79 MsgListView::MsgListView(QGraphicsItem *parent) :
    83     MsgBaseView(parent)
    80     MsgBaseView(parent)
    84 {
    81     {
    85     //These changes are needed for splash implementation to avoid flicker
    82     //These changes are needed for splash implementation to avoid flicker
    86     setupToolBar();    
    83     setupToolBar();
    87     setupMenu();
    84     setupMenu();
    88 
    85 
    89     // Create parent layout.
    86     // Create parent layout.
    90     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
    87     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
    91     mMainLayout->setContentsMargins(0, 0, 0, 0);
    88     mMainLayout->setContentsMargins(0, 0, 0, 0);
    92     mMainLayout->setSpacing(0);
    89     mMainLayout->setSpacing(0);
    93     
    90 
    94     // Create view heading.
    91     // Create view heading.
    95     HbGroupBox *viewHeading = new HbGroupBox();
    92     HbGroupBox *viewHeading = new HbGroupBox();
    96     viewHeading->setHeading(LOC_VIEW_HEADING);
    93     viewHeading->setHeading(LOC_VIEW_HEADING);
    97     
    94 
    98     // Add view heading widget to main layout.
    95     // Add view heading widget to main layout.
    99     mMainLayout->addItem(viewHeading);
    96     mMainLayout->addItem(viewHeading);
   100 
    97 
   101     this->setLayout(mMainLayout);
    98     this->setLayout(mMainLayout);
   102 
    99 
   103     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
   100     connect(this->mainWindow(), SIGNAL(viewReady()), this,
   104 }
   101             SLOT(doDelayedConstruction()));
       
   102     }
   105 
   103 
   106 //---------------------------------------------------------------
   104 //---------------------------------------------------------------
   107 // MsgListView::~MsgListView
   105 // MsgListView::~MsgListView
   108 // @see header
   106 // @see header
   109 //---------------------------------------------------------------
   107 //---------------------------------------------------------------
   228 #ifdef _DEBUG_TRACES_
   226 #ifdef _DEBUG_TRACES_
   229     qDebug() << "Inside MsgListView::deleteItem";
   227     qDebug() << "Inside MsgListView::deleteItem";
   230 #endif
   228 #endif
   231     //confirmation dialog.
   229     //confirmation dialog.
   232     HbMessageBox::question(LOC_DIALOG_DELETE_CONVERSATION,
   230     HbMessageBox::question(LOC_DIALOG_DELETE_CONVERSATION,
   233                                 this,SLOT(onDialogDeleteMsg(HbAction*)),
   231                            this,SLOT(onDialogDeleteMsg(HbAction*)),
   234                                 LOC_BUTTON_DELETE, LOC_BUTTON_CANCEL);    
   232                            HbMessageBox::Delete | HbMessageBox::Cancel);    
   235 #ifdef _DEBUG_TRACES_	
   233 #ifdef _DEBUG_TRACES_	
   236     qDebug() << " Leaving MsgConversationView::deleteItem";
   234     qDebug() << " Leaving MsgConversationView::deleteItem";
   237 #endif
   235 #endif
   238 }
   236 }
   239 
   237 
   240 //---------------------------------------------------------------
   238 //---------------------------------------------------------------
   241 // MsgListView::setupView
   239 // MsgListView::setupView
   242 // @see header
   240 // @see header
   243 //---------------------------------------------------------------
   241 //---------------------------------------------------------------
   244 void MsgListView::setupListView()
   242 void MsgListView::setupListView()
   245 {
   243     {
   246     // Register the custorm css path.
   244     // Register the custorm css path.
   247     HbStyleLoader::registerFilePath(":/clv");
   245     HbStyleLoader::registerFilePath(":/clv");
   248 
   246 
   249     mMsgList = new HbListView(this);
   247     mMsgList = new HbListView(this);
   250     mMsgList->setScrollingStyle(HbScrollArea::PanOrFlick);
   248     mMsgList->setScrollingStyle(HbScrollArea::PanOrFlick);
   251     mMsgList->setClampingStyle(HbScrollArea::BounceBackClamping);
   249     mMsgList->setClampingStyle(HbScrollArea::BounceBackClamping);
   252 
   250 
   253     mMsgList->setLayoutName("custom");
   251     mMsgList->setLayoutName("custom");
   254     mMsgList->setItemRecycling(true);
   252     mMsgList->setItemRecycling(true);
   255     mMsgList->setUniformItemSizes(true);   
   253     mMsgList->setUniformItemSizes(true);
   256 
   254 
   257     MsgListViewItem *prototype = new MsgListViewItem(this);
   255     MsgListViewItem *prototype = new MsgListViewItem(this);
   258     mMsgList->setItemPrototype(prototype);
   256     mMsgList->setItemPrototype(prototype);
   259 
   257     mMsgList->setModel(ConversationsEngine::instance()->getConversationsSummaryModel());
   260     // Set proxy model
   258     
   261     QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this);
       
   262     proxyModel->setDynamicSortFilter(true);
       
   263     proxyModel->setSourceModel(ConversationsEngine::instance()->getConversationsSummaryModel());
       
   264     proxyModel->setSortRole(TimeStamp);
       
   265     proxyModel->sort(0, Qt::DescendingOrder);
       
   266 
       
   267     mMsgList->setModel(proxyModel);
       
   268 
       
   269     connect(ConversationsEngine::instance(), SIGNAL(conversationListModelPopulated()),
       
   270             this, SLOT(populateListView()));
       
   271 
       
   272     // Single tap list item
   259     // Single tap list item
   273     connect(mMsgList, SIGNAL(activated(const QModelIndex&)),
   260     connect(mMsgList, SIGNAL(activated(const QModelIndex&)), this,
   274             this, SLOT(openConversation(const QModelIndex&)));
   261             SLOT(openConversation(const QModelIndex&)));
   275 
   262 
   276     // Long tap list item
   263     // Long tap list item
   277     connect(mMsgList, SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)),
   264     connect(mMsgList,
   278             this, SLOT(longPressed(HbAbstractViewItem*, const QPointF&)));
   265             SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)), this,
       
   266             SLOT(longPressed(HbAbstractViewItem*, const QPointF&)));
       
   267 
       
   268     // enable tap after delete is completed
       
   269     connect(ConversationsEngine::instance(),
       
   270             SIGNAL(conversationListEntryDeleted( int )), this,
       
   271             SLOT(enableListitem( int )));
   279 
   272 
   280     // Add list view to main layout.
   273     // Add list view to main layout.
   281     mMainLayout->addItem(mMsgList);
   274     mMainLayout->addItem(mMsgList);
   282 }
   275     }
   283 
   276 
   284 //---------------------------------------------------------------
   277 //---------------------------------------------------------------
   285 // MsgListView::addMenu
   278 // MsgListView::addMenu
   286 // @see header
   279 // @see header
   287 //---------------------------------------------------------------
   280 //---------------------------------------------------------------
   306     HbToolBarExtension *viewExtn = new HbToolBarExtension();
   299     HbToolBarExtension *viewExtn = new HbToolBarExtension();
   307     HbAction *viewAction = toolBar->addExtension(viewExtn);
   300     HbAction *viewAction = toolBar->addExtension(viewExtn);
   308     viewAction->setIcon(HbIcon(SORT_ICON));
   301     viewAction->setIcon(HbIcon(SORT_ICON));
   309 
   302 
   310     mViewExtnList = new HbListWidget();
   303     mViewExtnList = new HbListWidget();
       
   304     mViewExtnList->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
   311     mViewExtnList->addItem(LOC_TB_EXTN_DRAFTS);
   305     mViewExtnList->addItem(LOC_TB_EXTN_DRAFTS);
   312     mViewExtnList->addItem(LOC_TB_EXTN_CONVERSATIONS);
   306     mViewExtnList->addItem(LOC_TB_EXTN_CONVERSATIONS);
   313 
   307 
   314     HbListViewItem *prototype = mViewExtnList->listItemPrototype();
   308     HbListViewItem *prototype = mViewExtnList->listItemPrototype();
   315     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
   309     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
   420 //---------------------------------------------------------------
   414 //---------------------------------------------------------------
   421 // MsgListView::onDialogDeleteMsg
   415 // MsgListView::onDialogDeleteMsg
   422 // @see header
   416 // @see header
   423 //---------------------------------------------------------------
   417 //---------------------------------------------------------------
   424 void MsgListView::onDialogDeleteMsg(HbAction* action)
   418 void MsgListView::onDialogDeleteMsg(HbAction* action)
   425 {
   419     {
   426     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
   420     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
   427     if (action == dlg->actions().at(0)) {
   421     if (action == dlg->actions().at(0))
       
   422         {
   428         QModelIndex index = mMsgList->currentIndex();
   423         QModelIndex index = mMsgList->currentIndex();
   429         if(index.isValid())
   424         if (index.isValid())
       
   425             {
       
   426             HbAbstractViewItem *item = mMsgList->currentViewItem();
       
   427             item->ungrabGesture(Qt::TapGesture);
       
   428             qint64 conversationId = index.data(ConversationId).toLongLong();
       
   429 
       
   430             ConversationsEngine::instance()->deleteConversations(
       
   431                     conversationId);
       
   432 
       
   433             }
       
   434 
       
   435         }
       
   436     }
       
   437 
       
   438 //---------------------------------------------------------------
       
   439 // MsgListView::enableListitem
       
   440 // @see header
       
   441 //---------------------------------------------------------------
       
   442 void MsgListView::enableListitem(int conversationId)
       
   443     {
       
   444     QAbstractItemModel* proxyModel = mMsgList->model();
       
   445     QModelIndexList indexList = proxyModel->match(proxyModel->index(0, 0),
       
   446             ConversationId, conversationId, 1, Qt::MatchExactly);
       
   447     HbAbstractViewItem* item = NULL;
       
   448     int count = indexList.count();
       
   449 	// only item is expected to be the result of the above match function
       
   450     if (1 == count)
   430         {
   451         {
   431             qint64 conversationId = index.data(ConversationId).toLongLong();
   452         item = mMsgList->itemByIndex(indexList[0]);
   432                     ConversationsEngine::instance()->deleteConversations(conversationId);    
   453         if (item)
       
   454             {
       
   455             item->grabGesture(Qt::TapGesture);
       
   456             }
   433         }
   457         }
   434         
   458 
   435     }
   459     }
   436 }
       
   437 
   460 
   438 //EOF
   461 //EOF