messagingapp/msgui/msgapp/src/msglistview.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 27 e4592d119491
parent 44 36f374c67aa8
equal deleted inserted replaced
35:a32b19fb291e 47:5b14749788d7
    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")
    78 //---------------------------------------------------------------
    75 //---------------------------------------------------------------
    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     mItemLongPressed(false)
    81     {
    85 {
    82     //These changes are needed for splash implementation to avoid flicker
    86     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
    83     setupToolBar();
    87 }
    84     setupMenu();
       
    85 
       
    86     // Create parent layout.
       
    87     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    88     mMainLayout->setContentsMargins(0, 0, 0, 0);
       
    89     mMainLayout->setSpacing(0);
       
    90 
       
    91     // Create view heading.
       
    92     HbGroupBox *viewHeading = new HbGroupBox();
       
    93     viewHeading->setHeading(LOC_VIEW_HEADING);
       
    94 
       
    95     // Add view heading widget to main layout.
       
    96     mMainLayout->addItem(viewHeading);
       
    97 
       
    98     this->setLayout(mMainLayout);
       
    99 
       
   100     connect(this->mainWindow(), SIGNAL(viewReady()), this,
       
   101             SLOT(doDelayedConstruction()));
       
   102     }
    88 
   103 
    89 //---------------------------------------------------------------
   104 //---------------------------------------------------------------
    90 // MsgListView::~MsgListView
   105 // MsgListView::~MsgListView
    91 // @see header
   106 // @see header
    92 //---------------------------------------------------------------
   107 //---------------------------------------------------------------
    99 // MsgListView::longPressed
   114 // MsgListView::longPressed
   100 // @see header
   115 // @see header
   101 //---------------------------------------------------------------
   116 //---------------------------------------------------------------
   102 void MsgListView::longPressed(HbAbstractViewItem* viewItem, const QPointF& point)
   117 void MsgListView::longPressed(HbAbstractViewItem* viewItem, const QPointF& point)
   103 {
   118 {
   104     mItemLongPressed = true;
       
   105     if (this->isVisible()) {
   119     if (this->isVisible()) {
   106         // Set the current index as the present Item's index.
   120         // Set the current index as the present Item's index.
   107         // By default it will not be set.
   121         // By default it will not be set.
   108         mMsgList->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Select);
   122         mMsgList->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Select);
   109 
   123 
   142 // MsgListView::openConversation
   156 // MsgListView::openConversation
   143 // @see header
   157 // @see header
   144 //---------------------------------------------------------------
   158 //---------------------------------------------------------------
   145 void MsgListView::openConversation(const QModelIndex& index)
   159 void MsgListView::openConversation(const QModelIndex& index)
   146 {
   160 {
   147     if(mItemLongPressed)
       
   148      {
       
   149      mItemLongPressed = false;
       
   150      return;
       
   151      }
       
   152     //TODO: model populating possibilities.
   161     //TODO: model populating possibilities.
   153     if (index.isValid()) {
   162     if (index.isValid()) {
   154         QVariant conversationId = index.data(ConversationId);
   163         QVariant conversationId = index.data(ConversationId);
   155 
   164 
   156         // Launch conversation view
   165         // Launch conversation view
   217 #ifdef _DEBUG_TRACES_
   226 #ifdef _DEBUG_TRACES_
   218     qDebug() << "Inside MsgListView::deleteItem";
   227     qDebug() << "Inside MsgListView::deleteItem";
   219 #endif
   228 #endif
   220     //confirmation dialog.
   229     //confirmation dialog.
   221     HbMessageBox::question(LOC_DIALOG_DELETE_CONVERSATION,
   230     HbMessageBox::question(LOC_DIALOG_DELETE_CONVERSATION,
   222                                 this,SLOT(onDialogDeleteMsg(HbAction*)),
   231                            this,SLOT(onDialogDeleteMsg(HbAction*)),
   223                                 LOC_BUTTON_DELETE, LOC_BUTTON_CANCEL);    
   232                            HbMessageBox::Delete | HbMessageBox::Cancel);    
   224 #ifdef _DEBUG_TRACES_	
   233 #ifdef _DEBUG_TRACES_	
   225     qDebug() << " Leaving MsgConversationView::deleteItem";
   234     qDebug() << " Leaving MsgConversationView::deleteItem";
   226 #endif
   235 #endif
   227 }
   236 }
   228 
   237 
   229 //---------------------------------------------------------------
   238 //---------------------------------------------------------------
   230 // MsgListView::setupView
   239 // MsgListView::setupView
   231 // @see header
   240 // @see header
   232 //---------------------------------------------------------------
   241 //---------------------------------------------------------------
   233 void MsgListView::setupListView()
   242 void MsgListView::setupListView()
   234 {
   243     {
   235     // Create parent layout.
       
   236     QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
   237     mainLayout->setContentsMargins(0, 0, 0, 0);
       
   238     mainLayout->setSpacing(0);
       
   239 
       
   240     // Create view heading.
       
   241     HbGroupBox *viewHeading = new HbGroupBox();
       
   242     viewHeading->setHeading(LOC_VIEW_HEADING);
       
   243 
       
   244     // Register the custorm css path.
   244     // Register the custorm css path.
   245     HbStyleLoader::registerFilePath(":/clv");
   245     HbStyleLoader::registerFilePath(":/clv");
   246 
   246 
   247     mMsgList = new HbListView(this);
   247     mMsgList = new HbListView(this);
   248     mMsgList->setScrollingStyle(HbScrollArea::PanOrFlick);
   248     mMsgList->setScrollingStyle(HbScrollArea::PanOrFlick);
   249     mMsgList->setClampingStyle(HbScrollArea::BounceBackClamping);
   249     mMsgList->setClampingStyle(HbScrollArea::BounceBackClamping);
   250 
   250 
   251     mMsgList->setLayoutName("custom");
   251     mMsgList->setLayoutName("custom");
   252     mMsgList->setItemRecycling(true);
   252     mMsgList->setItemRecycling(true);
   253     mMsgList->setUniformItemSizes(true);   
   253     mMsgList->setUniformItemSizes(true);
   254 
   254 
   255     MsgListViewItem *prototype = new MsgListViewItem(this);
   255     MsgListViewItem *prototype = new MsgListViewItem(this);
   256     mMsgList->setItemPrototype(prototype);
   256     mMsgList->setItemPrototype(prototype);
   257 
   257     mMsgList->setModel(ConversationsEngine::instance()->getConversationsSummaryModel());
   258     // Set proxy model
   258     
   259     QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this);
       
   260     proxyModel->setDynamicSortFilter(true);
       
   261     proxyModel->setSourceModel(ConversationsEngine::instance()->getConversationsSummaryModel());
       
   262     proxyModel->setSortRole(TimeStamp);
       
   263     proxyModel->sort(0, Qt::DescendingOrder);
       
   264 
       
   265     mMsgList->setModel(proxyModel);
       
   266 
       
   267     connect(ConversationsEngine::instance(), SIGNAL(conversationListModelPopulated()),
       
   268             this, SLOT(populateListView()));
       
   269 
       
   270     // Single tap list item
   259     // Single tap list item
   271     connect(mMsgList, SIGNAL(activated(const QModelIndex&)),
   260     connect(mMsgList, SIGNAL(activated(const QModelIndex&)), this,
   272             this, SLOT(openConversation(const QModelIndex&)));
   261             SLOT(openConversation(const QModelIndex&)));
   273 
   262 
   274     // Long tap list item
   263     // Long tap list item
   275     connect(mMsgList, SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)),
   264     connect(mMsgList,
   276             this, SLOT(longPressed(HbAbstractViewItem*, const QPointF&)));
   265             SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)), this,
   277 
   266             SLOT(longPressed(HbAbstractViewItem*, const QPointF&)));
   278     // Add all widgets to main layout.
   267 
   279     mainLayout->addItem(viewHeading);
   268     // enable tap after delete is completed
   280     mainLayout->addItem(mMsgList);
   269     connect(ConversationsEngine::instance(),
   281 
   270             SIGNAL(conversationListEntryDeleted( int )), this,
   282     this->setLayout(mainLayout);
   271             SLOT(enableListitem( int )));
   283 }
   272 
       
   273     // Add list view to main layout.
       
   274     mMainLayout->addItem(mMsgList);
       
   275     }
   284 
   276 
   285 //---------------------------------------------------------------
   277 //---------------------------------------------------------------
   286 // MsgListView::addMenu
   278 // MsgListView::addMenu
   287 // @see header
   279 // @see header
   288 //---------------------------------------------------------------
   280 //---------------------------------------------------------------
   307     HbToolBarExtension *viewExtn = new HbToolBarExtension();
   299     HbToolBarExtension *viewExtn = new HbToolBarExtension();
   308     HbAction *viewAction = toolBar->addExtension(viewExtn);
   300     HbAction *viewAction = toolBar->addExtension(viewExtn);
   309     viewAction->setIcon(HbIcon(SORT_ICON));
   301     viewAction->setIcon(HbIcon(SORT_ICON));
   310 
   302 
   311     mViewExtnList = new HbListWidget();
   303     mViewExtnList = new HbListWidget();
       
   304     mViewExtnList->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
   312     mViewExtnList->addItem(LOC_TB_EXTN_DRAFTS);
   305     mViewExtnList->addItem(LOC_TB_EXTN_DRAFTS);
   313     mViewExtnList->addItem(LOC_TB_EXTN_CONVERSATIONS);
   306     mViewExtnList->addItem(LOC_TB_EXTN_CONVERSATIONS);
   314 
   307 
   315     HbListViewItem *prototype = mViewExtnList->listItemPrototype();
   308     HbListViewItem *prototype = mViewExtnList->listItemPrototype();
   316     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
   309     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
   345 //---------------------------------------------------------------
   338 //---------------------------------------------------------------
   346 // MsgListView::doDelayedConstruction
   339 // MsgListView::doDelayedConstruction
   347 // @see header
   340 // @see header
   348 //---------------------------------------------------------------
   341 //---------------------------------------------------------------
   349 void MsgListView::doDelayedConstruction()
   342 void MsgListView::doDelayedConstruction()
   350     {
   343     {    
   351     setupToolBar();    
       
   352     setupListView();
   344     setupListView();
   353     setupMenu();
       
   354     
   345     
   355     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
   346     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
   356     }
   347     }
   357 
   348 
   358 //---------------------------------------------------------------
   349 //---------------------------------------------------------------
   423 //---------------------------------------------------------------
   414 //---------------------------------------------------------------
   424 // MsgListView::onDialogDeleteMsg
   415 // MsgListView::onDialogDeleteMsg
   425 // @see header
   416 // @see header
   426 //---------------------------------------------------------------
   417 //---------------------------------------------------------------
   427 void MsgListView::onDialogDeleteMsg(HbAction* action)
   418 void MsgListView::onDialogDeleteMsg(HbAction* action)
   428 {
   419     {
   429     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
   420     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
   430     if (action == dlg->actions().at(0)) {
   421     if (action == dlg->actions().at(0))
       
   422         {
   431         QModelIndex index = mMsgList->currentIndex();
   423         QModelIndex index = mMsgList->currentIndex();
   432         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)
   433         {
   451         {
   434             qint64 conversationId = index.data(ConversationId).toLongLong();
   452         item = mMsgList->itemByIndex(indexList[0]);
   435                     ConversationsEngine::instance()->deleteConversations(conversationId);    
   453         if (item)
       
   454             {
       
   455             item->grabGesture(Qt::TapGesture);
       
   456             }
   436         }
   457         }
   437         
   458 
   438     }
   459     }
   439 }
       
   440 
   460 
   441 //EOF
   461 //EOF