phonebookui/pbkcommonui/src/cnthistoryview.cpp
changeset 27 de1630741fbe
parent 25 76a2435edfd4
child 31 2a11b5b00470
equal deleted inserted replaced
25:76a2435edfd4 27:de1630741fbe
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "cnthistoryview.h"
    18 #include "cnthistoryview.h"
    19 
    19 
    20 #include <QSqlDatabase>
       
    21 #include <hblistview.h>
    20 #include <hblistview.h>
    22 #include <hbgroupbox.h>
    21 #include <hbgroupbox.h>
    23 #include <hblistviewitem.h>
    22 #include <hbdocumentloader.h>
    24 #include <hbabstractviewitem.h>
       
    25 #include <hbmenu.h>
    23 #include <hbmenu.h>
       
    24 #include <hbview.h>
       
    25 #include <hbmessagebox.h>
       
    26 #include <hbaction.h>
    26 #include <xqservicerequest.h>
    27 #include <xqservicerequest.h>
    27 #include <mobhistorymodel.h>
    28 #include <cnthistorymodel.h>
    28 #include "cnthistoryviewitem.h" 
    29 
       
    30 #include "cnthistoryviewitem.h"
       
    31 #include "qtpbkglobal.h"
    29 
    32 
    30 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
    33 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
    31 
    34 
    32 /*!
    35 /*!
    33 Constructor, initialize member variables.
    36 Constructor, initialize member variables.
    34 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
    37 */
    35 */
    38 CntHistoryView::CntHistoryView() : 
    36 CntHistoryView::CntHistoryView(CntViewManager *viewManager, QGraphicsItem *parent) : 
    39     mHistoryListView(NULL),
    37     CntBaseView(viewManager, parent),
    40     mHistoryModel(NULL),
    38     mHistoryListView(0),
    41     mDocumentLoader(NULL),
    39     mHistoryModel(0),
    42     mViewMgr(NULL),
    40     mContact(0),
    43     mContact(NULL)
    41     mIsMyCard(false)
       
    42 {
    44 {
    43     bool ok = false;
    45     bool ok = false;
    44     ok = loadDocument(CNT_HISTORYVIEW_XML);
    46     
    45 
    47     docLoader()->load(CNT_HISTORYVIEW_XML, &ok);
       
    48     
    46     if (ok)
    49     if (ok)
    47     {
    50     {
    48         QGraphicsWidget *content = findWidget(QString("content"));
    51         mView = static_cast<HbView*>(docLoader()->findWidget(QString("view")));
    49         setWidget(content);
    52         
       
    53         // Create a back key action an set it as the default navigation
       
    54         // action once the back key is pressed
       
    55         mBackKey = new HbAction(Hb::BackNaviAction, mView);
       
    56         mView->setNavigationAction(mBackKey);        
       
    57         connect(mBackKey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    50     }
    58     }
    51     else
    59     else
    52     {
    60     {
    53         qFatal("Unable to read :/xml/contacts_history.docml");
    61         qFatal("Unable to read :/xml/contacts_history.docml");
    54     }
    62     }
    57 /*!
    65 /*!
    58 Destructor
    66 Destructor
    59 */
    67 */
    60 CntHistoryView::~CntHistoryView()
    68 CntHistoryView::~CntHistoryView()
    61 {
    69 {
    62     delete mContact;
    70     if (mDocumentLoader) {
    63     delete mHistoryModel;
    71         delete mDocumentLoader;
    64 }
    72         mDocumentLoader = NULL;
    65 
    73     }
    66 /*!
    74     if (mHistoryModel) {
    67 Activates a previous view
    75         delete mHistoryModel;
    68 */
    76         mHistoryModel = NULL;
    69 void CntHistoryView::aboutToCloseView()
    77     }
    70 {
    78     if (mContact) {
    71     CntViewParameters args;//( CntViewParameters::commLauncherView );
    79         delete mContact;
    72     args.setSelectedContact( *mContact );
    80         mContact = NULL;
    73     viewManager()->back( args );
    81     }
    74         /*
    82 }
    75     viewManager()->previousViewParameters().setSelectedContact(*mContact);
    83 
    76     viewManager()->onActivatePreviousView();
    84 /*!
    77     */
    85  * Deactivate the view
    78 }
    86  */
    79 
    87 void CntHistoryView::deactivate()
    80 void CntHistoryView::activateView(const CntViewParameters &viewParameters)
    88 {
    81 { 
    89 }
    82     QContact contact = viewParameters.selectedContact();
    90 
    83     mContact = new QContact(contact);
    91 /**
    84     
    92  * Activate the view
    85     //group box
    93  */
    86     HbGroupBox* groupBox = static_cast<HbGroupBox *>(findWidget(QString("cnt_groupbox_history")));
    94 void CntHistoryView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
    87     QString text = hbTrId("History with %1").arg(contactManager()->synthesizedDisplayLabel(contact));
    95 {
    88     groupBox->setHeading(text);
    96     mViewMgr = aMgr;
       
    97     mContact = new QContact(aArgs.value(ESelectedContact).value<QContact>());
       
    98     
       
    99     // Set history view heading
       
   100     HbGroupBox* groupBox = static_cast<HbGroupBox*>(docLoader()->findWidget(QString("groupBox")));
       
   101     groupBox->setHeading(hbTrId("txt_phob_subtitle_history_with_1").arg(mContact->displayLabel()));
    89     
   102     
    90     //construct listview
   103     //construct listview
    91     mHistoryListView = static_cast<HbListView*>(findWidget(QString("cnt_listview_history")));
   104     mHistoryListView = static_cast<HbListView*>(docLoader()->findWidget(QString("listView")));
    92     
       
    93     //bubble graphics - create our custom list view item to have different bubbles
       
    94     //for incoming and outgoing messages 
       
    95     CntHistoryViewItem *item = new CntHistoryViewItem;
   105     CntHistoryViewItem *item = new CntHistoryViewItem;
    96     mHistoryListView->setItemPrototype(item); //ownership is taken
   106     mHistoryListView->setItemPrototype(item); //ownership is taken
    97     connect(mHistoryListView, SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
   107     mHistoryListView->setUniformItemSizes(true);
    98                       this,  SLOT(longPressed(HbAbstractViewItem *, const QPointF &)));
   108     
       
   109     // Connect listview items to respective slots
    99     connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
   110     connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
   100                       this,  SLOT(pressed(const QModelIndex &)));
   111                       this,  SLOT(itemActivated(const QModelIndex &)));
   101     
   112     mHistoryModel = new CntHistoryModel(mContact->localId(),
   102     mHistoryModel = new MobHistoryModel(contact.localId(), contactManager());
   113                                         mViewMgr->contactManager(SYMBIAN_BACKEND));
   103     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
   114     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
   104     
   115     
   105     //start listening to the events amount changing in the model
   116     //start listening to the events amount changing in the model
   106     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
   117     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
   107         this, SLOT(updateScrollingPosition()));
   118         this, SLOT(updateScrollingPosition()));
   108     connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
   119     connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
   109         this, SLOT(rowsRemoved(const QModelIndex &, int, int)));
       
   110     connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
       
   111         this, SLOT(updateScrollingPosition()));
   120         this, SLOT(updateScrollingPosition()));
       
   121     connect(mHistoryModel, SIGNAL(layoutChanged()),
       
   122         this, SLOT(updateScrollingPosition()));
       
   123     
       
   124     // Connect the menu options to respective slots
       
   125     HbAction* clearHistory = static_cast<HbAction*>(docLoader()->findObject("cnt:clearhistory"));
       
   126     connect(clearHistory, SIGNAL(triggered()), this, SLOT(clearHistory()));
   112 }
   127 }
   113 
   128 
   114 /*!
   129 /*!
   115 Called after new items are added to or removed from comm history view
   130 Called after new items are added to or removed from comm history view
   116 */
   131 */
   117 void CntHistoryView::updateScrollingPosition()
   132 void CntHistoryView::updateScrollingPosition()
   118 {
   133 {
   119     int rowCnt = mHistoryModel->rowCount();
   134     int rowCnt = mHistoryModel->rowCount();
       
   135     
       
   136     // Scroll to the last item in the list
   120     mHistoryListView->scrollTo(mHistoryModel->index(rowCnt - 1, 0), 
   137     mHistoryListView->scrollTo(mHistoryModel->index(rowCnt - 1, 0), 
   121         HbAbstractItemView::PositionAtBottom);
   138         HbAbstractItemView::PositionAtBottom);
   122 }
   139 }
   123 
   140 
   124 /*!
       
   125 Add actions to menu
       
   126 */
       
   127 void CntHistoryView::addMenuItems()
       
   128 {
       
   129     CntActions* acts = actions();
       
   130     acts->clearActionList();
       
   131     acts->actionList() << acts->baseAction("cnt:clearhistory");
       
   132     acts->addActionsToMenu(menu());
       
   133         
       
   134     connect(acts->baseAction("cnt:clearhistory"), SIGNAL(triggered()),
       
   135             this, SLOT (clearHistory()));
       
   136 }
       
   137 
       
   138 /*
   141 /*
   139 Clear communications history
   142 Clear communications history
   140 */
   143 */
   141 void CntHistoryView::clearHistory()
   144 void CntHistoryView::clearHistory()
   142 {
   145 {
   143     mHistoryModel->clearHistory();
   146     // Ask the use if they want to clear the history
   144 }
   147     HbMessageBox *note = new HbMessageBox(hbTrId("txt_phob_info_clear_communications_history_with_1"),
   145 
   148                 HbMessageBox::MessageTypeQuestion);
   146 /*!
   149     
   147 Called when a list item is longpressed
   150     note->setPrimaryAction(new HbAction(hbTrId("txt_phob_button_delete"), note));
   148 */
   151     note->setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), note));
   149 void CntHistoryView::longPressed(HbAbstractViewItem *item, const QPointF &coords)
   152     HbAction *selected = note->exec();
   150 {
   153     if (selected == note->primaryAction())
   151     Q_UNUSED(item);
   154     {
   152     
       
   153     HbMenu* menu = new HbMenu();
       
   154     HbAction* clearAction = menu->addAction(hbTrId("txt_phob_menu_clear_history"));
       
   155     
       
   156     HbAction* selectedAction = menu->exec(coords);
       
   157     
       
   158     if (selectedAction && selectedAction == clearAction) {
       
   159         // Clear comm history
   155         // Clear comm history
   160         mHistoryModel->clearHistory();
   156         mHistoryModel->clearHistory();
   161     }
   157     }
   162     
   158     delete note;
   163     menu->deleteLater();
   159 }
   164 }
   160 
   165 
   161 /*!
   166 void CntHistoryView::pressed(const QModelIndex &index)
   162 Once list item is pressed on the list view this slot handles the 
   167 {
   163 emitted signal
   168     QVariant itemType = mHistoryModel->data(index, MobHistoryModel::ItemTypeRole);
   164  */
   169     
   165 void CntHistoryView::itemActivated(const QModelIndex &index)
   170     if (itemType.toInt() == MobHistoryModel::CallLog) {
   166 {
       
   167     QVariant itemType = index.data(CntHistoryModel::ItemTypeRole);
       
   168     
       
   169     if (!itemType.isValid())
       
   170         return;
       
   171     
       
   172     // If the list item is a call log a call is made to that item
       
   173     if (itemType.toInt() == CntHistoryModel::CallLog) {
   171         // Make a call
   174         // Make a call
   172         QVariant v = mHistoryModel->data(index, MobHistoryModel::PhoneNumberRole);
   175         QVariant v = index.data(CntHistoryModel::PhoneNumberRole);
       
   176         if (!v.isValid())
       
   177             return;
       
   178         
   173         QString service("com.nokia.services.telephony");
   179         QString service("com.nokia.services.telephony");
   174         QString type("dial(QString)");
   180         QString type("dial(QString)");
   175         XQServiceRequest snd(service, type, false);
   181         XQServiceRequest snd(service, type, false);
   176         snd << v.toString();
   182         snd << v.toString();
   177         snd.send();
   183         snd.send();
   178     }
   184     }
   179 }
   185 }
   180 
   186 
       
   187 /*!
       
   188 Go back to previous view
       
   189 */
       
   190 void CntHistoryView::showPreviousView()
       
   191 {
       
   192     CntViewParameters viewParameters;
       
   193     QVariant var;
       
   194     var.setValue(*mContact);
       
   195     viewParameters.insert(ESelectedContact, var);
       
   196     mViewMgr->back(viewParameters);
       
   197 }
       
   198 
       
   199 /*!
       
   200  * Document loader
       
   201  */
       
   202 HbDocumentLoader* CntHistoryView::docLoader()
       
   203 {
       
   204     if (!mDocumentLoader) {
       
   205         mDocumentLoader = new HbDocumentLoader();
       
   206     }
       
   207     return mDocumentLoader;
       
   208 }
       
   209 
   181 // end of file
   210 // end of file