messagingapp/msgui/msgapp/src/msglistview.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 48 4f501b74aeb1
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    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     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
    82     //These changes are needed for splash implementation to avoid flicker
    86 }
    83     setupToolBar();
       
    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     }
    87 
   103 
    88 //---------------------------------------------------------------
   104 //---------------------------------------------------------------
    89 // MsgListView::~MsgListView
   105 // MsgListView::~MsgListView
    90 // @see header
   106 // @see header
    91 //---------------------------------------------------------------
   107 //---------------------------------------------------------------
   105         // By default it will not be set.
   121         // By default it will not be set.
   106         mMsgList->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Select);
   122         mMsgList->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Select);
   107 
   123 
   108         // Create new menu
   124         // Create new menu
   109         HbMenu *contextMenu = new HbMenu();
   125         HbMenu *contextMenu = new HbMenu();
   110 
   126         contextMenu->setAttribute(Qt::WA_DeleteOnClose);
   111         //open menu option
   127         //open menu option
   112         contextMenu->addAction(LOC_OPEN,this,SLOT(openConversation()));
   128         contextMenu->addAction(LOC_OPEN,this,SLOT(openConversation()));
   113         
   129         
   114         //save to contacts for unresolved.
   130         //save to contacts for unresolved.
   115         int msgType = viewItem->modelIndex().data(MessageType).toInt();
   131         int msgType = viewItem->modelIndex().data(MessageType).toInt();
   129             }
   145             }
   130         
   146         
   131         //delete conversation
   147         //delete conversation
   132         contextMenu->addAction(LOC_DELETE_CONVERSATION,this,SLOT(deleteItem()));
   148         contextMenu->addAction(LOC_DELETE_CONVERSATION,this,SLOT(deleteItem()));
   133 
   149 
   134         contextMenu->exec(point);
   150         contextMenu->setPreferredPos(point);    
   135         // Cleanup
   151         contextMenu->show();
   136         delete contextMenu;
       
   137     }
   152     }
   138 }
   153 }
   139 
   154 
   140 //---------------------------------------------------------------
   155 //---------------------------------------------------------------
   141 // MsgListView::openConversation
   156 // MsgListView::openConversation
   209 void MsgListView::deleteItem()
   224 void MsgListView::deleteItem()
   210 {
   225 {
   211 #ifdef _DEBUG_TRACES_
   226 #ifdef _DEBUG_TRACES_
   212     qDebug() << "Inside MsgListView::deleteItem";
   227     qDebug() << "Inside MsgListView::deleteItem";
   213 #endif
   228 #endif
   214 
       
   215     QModelIndex index = mMsgList->currentIndex();
       
   216     qint64 conversationId = index.data(ConversationId).toLongLong();
       
   217 
       
   218     //confirmation dialog.
   229     //confirmation dialog.
   219     bool result = HbMessageBox::question(LOC_DIALOG_DELETE_CONVERSATION,
   230     HbMessageBox::question(LOC_DIALOG_DELETE_CONVERSATION,
   220                                          LOC_BUTTON_DELETE, LOC_BUTTON_CANCEL);
   231                            this,SLOT(onDialogDeleteMsg(HbAction*)),
   221     if (result) 
   232                            HbMessageBox::Delete | HbMessageBox::Cancel);    
   222         {
       
   223         ConversationsEngine::instance()->deleteConversations(conversationId);
       
   224         }
       
   225     
       
   226 #ifdef _DEBUG_TRACES_	
   233 #ifdef _DEBUG_TRACES_	
   227     qDebug() << " Leaving MsgConversationView::deleteItem";
   234     qDebug() << " Leaving MsgConversationView::deleteItem";
   228 #endif
   235 #endif
   229 }
   236 }
   230 
   237 
   231 //---------------------------------------------------------------
   238 //---------------------------------------------------------------
   232 // MsgListView::setupView
   239 // MsgListView::setupView
   233 // @see header
   240 // @see header
   234 //---------------------------------------------------------------
   241 //---------------------------------------------------------------
   235 void MsgListView::setupListView()
   242 void MsgListView::setupListView()
   236 {
   243     {
   237     // Create parent layout.
       
   238     QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
   239     mainLayout->setContentsMargins(0, 0, 0, 0);
       
   240     mainLayout->setSpacing(0);
       
   241 
       
   242     // Create view heading.
       
   243     HbGroupBox *viewHeading = new HbGroupBox();
       
   244     viewHeading->setHeading(LOC_VIEW_HEADING);
       
   245 
       
   246     // Register the custorm css path.
   244     // Register the custorm css path.
   247     HbStyleLoader::registerFilePath(":/xml/msglistviewitem.css");
   245     HbStyleLoader::registerFilePath(":/clv");
   248     HbStyleLoader::registerFilePath(":/xml/msglistviewitem.widgetml");
       
   249 
   246 
   250     mMsgList = new HbListView(this);
   247     mMsgList = new HbListView(this);
   251     mMsgList->setScrollingStyle(HbScrollArea::PanOrFlick);
   248     mMsgList->setScrollingStyle(HbScrollArea::PanOrFlick);
   252     mMsgList->setClampingStyle(HbScrollArea::BounceBackClamping);
   249     mMsgList->setClampingStyle(HbScrollArea::BounceBackClamping);
   253 
   250 
   254     mMsgList->setLayoutName("custom");
   251     mMsgList->setLayoutName("custom");
   255     mMsgList->setItemRecycling(true);
   252     mMsgList->setItemRecycling(true);
   256     mMsgList->setUniformItemSizes(true);   
   253     mMsgList->setUniformItemSizes(true);
   257 
   254 
   258     MsgListViewItem *prototype = new MsgListViewItem(this);
   255     MsgListViewItem *prototype = new MsgListViewItem(this);
   259     mMsgList->setItemPrototype(prototype);
   256     mMsgList->setItemPrototype(prototype);
   260 
   257     mMsgList->setModel(ConversationsEngine::instance()->getConversationsSummaryModel());
   261     // Set proxy model
   258     
   262     QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this);
       
   263     proxyModel->setDynamicSortFilter(true);
       
   264     proxyModel->setSourceModel(ConversationsEngine::instance()->getConversationsSummaryModel());
       
   265     proxyModel->setSortRole(TimeStamp);
       
   266     proxyModel->sort(0, Qt::DescendingOrder);
       
   267 
       
   268     mMsgList->setModel(proxyModel);
       
   269 
       
   270     connect(ConversationsEngine::instance(), SIGNAL(conversationListModelPopulated()),
       
   271             this, SLOT(populateListView()));
       
   272 
       
   273     // Single tap list item
   259     // Single tap list item
   274     connect(mMsgList, SIGNAL(activated(const QModelIndex&)),
   260     connect(mMsgList, SIGNAL(activated(const QModelIndex&)), this,
   275             this, SLOT(openConversation(const QModelIndex&)));
   261             SLOT(openConversation(const QModelIndex&)));
   276 
   262 
   277     // Long tap list item
   263     // Long tap list item
   278     connect(mMsgList, SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)),
   264     connect(mMsgList,
   279             this, SLOT(longPressed(HbAbstractViewItem*, const QPointF&)));
   265             SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)), this,
   280 
   266             SLOT(longPressed(HbAbstractViewItem*, const QPointF&)));
   281     // Add all widgets to main layout.
   267 
   282     mainLayout->addItem(viewHeading);
   268     // enable tap after delete is completed
   283     mainLayout->addItem(mMsgList);
   269     connect(ConversationsEngine::instance(),
   284 
   270             SIGNAL(conversationListEntryDeleted( int )), this,
   285     this->setLayout(mainLayout);
   271             SLOT(enableListitem( int )));
   286 }
   272 
       
   273     // Add list view to main layout.
       
   274     mMainLayout->addItem(mMsgList);
       
   275     }
   287 
   276 
   288 //---------------------------------------------------------------
   277 //---------------------------------------------------------------
   289 // MsgListView::addMenu
   278 // MsgListView::addMenu
   290 // @see header
   279 // @see header
   291 //---------------------------------------------------------------
   280 //---------------------------------------------------------------
   310     HbToolBarExtension *viewExtn = new HbToolBarExtension();
   299     HbToolBarExtension *viewExtn = new HbToolBarExtension();
   311     HbAction *viewAction = toolBar->addExtension(viewExtn);
   300     HbAction *viewAction = toolBar->addExtension(viewExtn);
   312     viewAction->setIcon(HbIcon(SORT_ICON));
   301     viewAction->setIcon(HbIcon(SORT_ICON));
   313 
   302 
   314     mViewExtnList = new HbListWidget();
   303     mViewExtnList = new HbListWidget();
       
   304     mViewExtnList->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
   315     mViewExtnList->addItem(LOC_TB_EXTN_DRAFTS);
   305     mViewExtnList->addItem(LOC_TB_EXTN_DRAFTS);
   316     mViewExtnList->addItem(LOC_TB_EXTN_CONVERSATIONS);
   306     mViewExtnList->addItem(LOC_TB_EXTN_CONVERSATIONS);
   317 
   307 
   318     HbListViewItem *prototype = mViewExtnList->listItemPrototype();
   308     HbListViewItem *prototype = mViewExtnList->listItemPrototype();
   319     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
   309     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
   348 //---------------------------------------------------------------
   338 //---------------------------------------------------------------
   349 // MsgListView::doDelayedConstruction
   339 // MsgListView::doDelayedConstruction
   350 // @see header
   340 // @see header
   351 //---------------------------------------------------------------
   341 //---------------------------------------------------------------
   352 void MsgListView::doDelayedConstruction()
   342 void MsgListView::doDelayedConstruction()
   353     {
   343     {    
   354     setupToolBar();    
       
   355     setupListView();
   344     setupListView();
   356     setupMenu();
       
   357     
   345     
   358     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
   346     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
   359     }
   347     }
   360 
   348 
   361 //---------------------------------------------------------------
   349 //---------------------------------------------------------------
   421     request->send();
   409     request->send();
   422     
   410     
   423     delete request;
   411     delete request;
   424     }
   412     }
   425 
   413 
       
   414 //---------------------------------------------------------------
       
   415 // MsgListView::onDialogDeleteMsg
       
   416 // @see header
       
   417 //---------------------------------------------------------------
       
   418 void MsgListView::onDialogDeleteMsg(HbAction* action)
       
   419     {
       
   420     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   421     if (action == dlg->actions().at(0))
       
   422         {
       
   423         QModelIndex index = mMsgList->currentIndex();
       
   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)
       
   451         {
       
   452         item = mMsgList->itemByIndex(indexList[0]);
       
   453         if (item)
       
   454             {
       
   455             item->grabGesture(Qt::TapGesture);
       
   456             }
       
   457         }
       
   458 
       
   459     }
       
   460 
   426 //EOF
   461 //EOF