phonebookui/pbkcommonui/src/cnthistoryview.cpp
changeset 31 2a11b5b00470
parent 27 de1630741fbe
child 37 fd64c38c277d
equal deleted inserted replaced
27:de1630741fbe 31:2a11b5b00470
    24 #include <hbview.h>
    24 #include <hbview.h>
    25 #include <hbmessagebox.h>
    25 #include <hbmessagebox.h>
    26 #include <hbaction.h>
    26 #include <hbaction.h>
    27 #include <xqservicerequest.h>
    27 #include <xqservicerequest.h>
    28 #include <cnthistorymodel.h>
    28 #include <cnthistorymodel.h>
       
    29 #include <hbparameterlengthlimiter.h>
       
    30 #include <hbmainwindow.h>
       
    31 #include <hbframebackground.h>
    29 
    32 
    30 #include "cnthistoryviewitem.h"
    33 #include "cnthistoryviewitem.h"
    31 #include "qtpbkglobal.h"
    34 #include "qtpbkglobal.h"
    32 
    35 
    33 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
    36 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
   100     HbGroupBox* groupBox = static_cast<HbGroupBox*>(docLoader()->findWidget(QString("groupBox")));
   103     HbGroupBox* groupBox = static_cast<HbGroupBox*>(docLoader()->findWidget(QString("groupBox")));
   101     groupBox->setHeading(hbTrId("txt_phob_subtitle_history_with_1").arg(mContact->displayLabel()));
   104     groupBox->setHeading(hbTrId("txt_phob_subtitle_history_with_1").arg(mContact->displayLabel()));
   102     
   105     
   103     //construct listview
   106     //construct listview
   104     mHistoryListView = static_cast<HbListView*>(docLoader()->findWidget(QString("listView")));
   107     mHistoryListView = static_cast<HbListView*>(docLoader()->findWidget(QString("listView")));
       
   108     mHistoryListView->setLayoutName("history");
   105     CntHistoryViewItem *item = new CntHistoryViewItem;
   109     CntHistoryViewItem *item = new CntHistoryViewItem;
       
   110     item->setSecondaryTextRowCount(1, 3);
       
   111     item->setGraphicsSize(HbListViewItem::SmallIcon);
   106     mHistoryListView->setItemPrototype(item); //ownership is taken
   112     mHistoryListView->setItemPrototype(item); //ownership is taken
   107     mHistoryListView->setUniformItemSizes(true);
       
   108     
   113     
   109     // Connect listview items to respective slots
   114     // Connect listview items to respective slots
   110     connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
   115     connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
   111                       this,  SLOT(itemActivated(const QModelIndex &)));
   116                       this,  SLOT(itemActivated(const QModelIndex &)));
   112     mHistoryModel = new CntHistoryModel(mContact->localId(),
   117     mHistoryModel = new CntHistoryModel(mContact->localId(),
   114     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
   119     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
   115     
   120     
   116     //start listening to the events amount changing in the model
   121     //start listening to the events amount changing in the model
   117     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
   122     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
   118         this, SLOT(updateScrollingPosition()));
   123         this, SLOT(updateScrollingPosition()));
       
   124     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
       
   125         this, SLOT(showClearHistoryMenu()));
   119     connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
   126     connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
   120         this, SLOT(updateScrollingPosition()));
   127         this, SLOT(updateScrollingPosition()));
       
   128     connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
       
   129         this, SLOT(showClearHistoryMenu()));
   121     connect(mHistoryModel, SIGNAL(layoutChanged()),
   130     connect(mHistoryModel, SIGNAL(layoutChanged()),
   122         this, SLOT(updateScrollingPosition()));
   131         this, SLOT(updateScrollingPosition()));
   123     
   132     
   124     // Connect the menu options to respective slots
   133     // Connect the menu options to respective slots
   125     HbAction* clearHistory = static_cast<HbAction*>(docLoader()->findObject("cnt:clearhistory"));
   134     mClearHistory = static_cast<HbAction*>(docLoader()->findObject("cnt:clearhistory"));
   126     connect(clearHistory, SIGNAL(triggered()), this, SLOT(clearHistory()));
   135     connect(mClearHistory, SIGNAL(triggered()), this, SLOT(clearHistory()));
       
   136     showClearHistoryMenu();
       
   137     
       
   138     HbMainWindow* mainWindow = mView->mainWindow();
       
   139     connect(mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), 
       
   140             this, SLOT(updateScrollingPosition()));
   127 }
   141 }
   128 
   142 
   129 /*!
   143 /*!
   130 Called after new items are added to or removed from comm history view
   144 Called after new items are added to or removed from comm history view
   131 */
   145 */
   137     mHistoryListView->scrollTo(mHistoryModel->index(rowCnt - 1, 0), 
   151     mHistoryListView->scrollTo(mHistoryModel->index(rowCnt - 1, 0), 
   138         HbAbstractItemView::PositionAtBottom);
   152         HbAbstractItemView::PositionAtBottom);
   139 }
   153 }
   140 
   154 
   141 /*
   155 /*
   142 Clear communications history
   156 Query the user for clearing communications history
   143 */
   157 */
   144 void CntHistoryView::clearHistory()
   158 void CntHistoryView::clearHistory()
   145 {
   159 {
   146     // Ask the use if they want to clear the history
   160     // Ask the use if they want to clear the history
   147     HbMessageBox *note = new HbMessageBox(hbTrId("txt_phob_info_clear_communications_history_with_1"),
   161     QString name = mContact->displayLabel();
   148                 HbMessageBox::MessageTypeQuestion);
   162     
   149     
   163     HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_clear_communications_history_with_1")).arg(name), this, 
   150     note->setPrimaryAction(new HbAction(hbTrId("txt_phob_button_delete"), note));
   164             SLOT(handleClearHistory(HbAction*)), hbTrId("txt_phob_button_delete"), hbTrId("txt_common_button_cancel"));
   151     note->setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), note));
   165 }
   152     HbAction *selected = note->exec();
   166 
   153     if (selected == note->primaryAction())
   167 /*
       
   168 Handle the selected action for clearing history
       
   169 */
       
   170 void CntHistoryView::handleClearHistory(HbAction *action)
       
   171 {
       
   172     HbMessageBox *note = static_cast<HbMessageBox*>(sender());
       
   173     
       
   174     if (note && action == note->actions().first())
   154     {
   175     {
   155         // Clear comm history
       
   156         mHistoryModel->clearHistory();
   176         mHistoryModel->clearHistory();
   157     }
   177     }
   158     delete note;
       
   159 }
   178 }
   160 
   179 
   161 /*!
   180 /*!
   162 Once list item is pressed on the list view this slot handles the 
   181 Once list item is pressed on the list view this slot handles the 
   163 emitted signal
   182 emitted signal
   164  */
   183  */
   165 void CntHistoryView::itemActivated(const QModelIndex &index)
   184 void CntHistoryView::itemActivated(const QModelIndex &index)
   166 {
   185 {
   167     QVariant itemType = index.data(CntHistoryModel::ItemTypeRole);
   186     int flags = index.data(CntHistoryModel::FlagsRole).toInt();
   168     
       
   169     if (!itemType.isValid())
       
   170         return;
       
   171     
   187     
   172     // If the list item is a call log a call is made to that item
   188     // If the list item is a call log a call is made to that item
   173     if (itemType.toInt() == CntHistoryModel::CallLog) {
   189     if (flags & CntHistoryModel::CallLog) {
   174         // Make a call
   190         // Make a call
   175         QVariant v = index.data(CntHistoryModel::PhoneNumberRole);
   191         QVariant v = index.data(CntHistoryModel::PhoneNumberRole);
   176         if (!v.isValid())
   192         if (!v.isValid())
   177             return;
   193             return;
   178         
   194         
   180         QString type("dial(QString)");
   196         QString type("dial(QString)");
   181         XQServiceRequest snd(service, type, false);
   197         XQServiceRequest snd(service, type, false);
   182         snd << v.toString();
   198         snd << v.toString();
   183         snd.send();
   199         snd.send();
   184     }
   200     }
       
   201     else if (flags & CntHistoryModel::Message) {
       
   202         // Open conversation view
       
   203         QVariant v = index.data(CntHistoryModel::PhoneNumberRole);
       
   204         if (!v.isValid())
       
   205             return;
       
   206         
       
   207         QString service("com.nokia.services.hbserviceprovider.conversationview");
       
   208         QString type("send(QString,qint32,QString)");
       
   209         XQServiceRequest snd(service, type, false);       
       
   210         snd << v.toString() << mContact->localId() << mContact->displayLabel();
       
   211         snd.send();
       
   212     }
   185 }
   213 }
   186 
   214 
   187 /*!
   215 /*!
   188 Go back to previous view
   216 Go back to previous view
   189 */
   217 */
   195     viewParameters.insert(ESelectedContact, var);
   223     viewParameters.insert(ESelectedContact, var);
   196     mViewMgr->back(viewParameters);
   224     mViewMgr->back(viewParameters);
   197 }
   225 }
   198 
   226 
   199 /*!
   227 /*!
       
   228 Show or hide the clear history menu
       
   229 */
       
   230 void CntHistoryView::showClearHistoryMenu()
       
   231 {
       
   232     if (mHistoryModel->rowCount() > 0) {
       
   233         mClearHistory->setEnabled(true);
       
   234     } else {
       
   235         mClearHistory->setEnabled(false);
       
   236     }
       
   237 }
       
   238 
       
   239 /*!
   200  * Document loader
   240  * Document loader
   201  */
   241  */
   202 HbDocumentLoader* CntHistoryView::docLoader()
   242 HbDocumentLoader* CntHistoryView::docLoader()
   203 {
   243 {
   204     if (!mDocumentLoader) {
   244     if (!mDocumentLoader) {