phonebookui/pbkcommonui/src/cnthistoryview.cpp
changeset 25 76a2435edfd4
parent 24 0ba2181d7c28
child 27 de1630741fbe
equal deleted inserted replaced
24:0ba2181d7c28 25:76a2435edfd4
    19 
    19 
    20 #include <QSqlDatabase>
    20 #include <QSqlDatabase>
    21 #include <hblistview.h>
    21 #include <hblistview.h>
    22 #include <hbgroupbox.h>
    22 #include <hbgroupbox.h>
    23 #include <hblistviewitem.h>
    23 #include <hblistviewitem.h>
       
    24 #include <hbabstractviewitem.h>
       
    25 #include <hbmenu.h>
       
    26 #include <xqservicerequest.h>
    24 #include <mobhistorymodel.h>
    27 #include <mobhistorymodel.h>
    25 #include "cnthistoryviewitem.h" 
    28 #include "cnthistoryviewitem.h" 
    26 
    29 
    27 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
    30 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
    28 //const QString db_path("c:\\conversations.sqlite");
       
    29 
    31 
    30 /*!
    32 /*!
    31 Constructor, initialize member variables.
    33 Constructor, initialize member variables.
    32 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
    34 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
    33 */
    35 */
    64 /*!
    66 /*!
    65 Activates a previous view
    67 Activates a previous view
    66 */
    68 */
    67 void CntHistoryView::aboutToCloseView()
    69 void CntHistoryView::aboutToCloseView()
    68 {
    70 {
       
    71     CntViewParameters args;//( CntViewParameters::commLauncherView );
       
    72     args.setSelectedContact( *mContact );
       
    73     viewManager()->back( args );
       
    74         /*
    69     viewManager()->previousViewParameters().setSelectedContact(*mContact);
    75     viewManager()->previousViewParameters().setSelectedContact(*mContact);
    70     viewManager()->onActivatePreviousView();
    76     viewManager()->onActivatePreviousView();
       
    77     */
    71 }
    78 }
    72 
    79 
    73 void CntHistoryView::activateView(const CntViewParameters &viewParameters)
    80 void CntHistoryView::activateView(const CntViewParameters &viewParameters)
    74 { 
    81 { 
    75     QContact contact = viewParameters.selectedContact();
    82     QContact contact = viewParameters.selectedContact();
    76     mContact = new QContact(contact);
    83     mContact = new QContact(contact);
    77     
    84     
    78     //group box
    85     //group box
    79     HbGroupBox* groupBox = static_cast<HbGroupBox *>(findWidget(QString("cnt_groupbox_history")));
    86     HbGroupBox* groupBox = static_cast<HbGroupBox *>(findWidget(QString("cnt_groupbox_history")));
    80     QString text;
    87     QString text = hbTrId("History with %1").arg(contactManager()->synthesizedDisplayLabel(contact));
    81     if (mContact->localId() == contactManager()->selfContactId()) {
       
    82         //My card
       
    83         text.append(hbTrId("All history"));
       
    84     }
       
    85     else {
       
    86         text.append(hbTrId("History: "));
       
    87         text.append(contactManager()->synthesizeDisplayLabel(contact));
       
    88     }
       
    89     groupBox->setHeading(text);
    88     groupBox->setHeading(text);
    90     
    89     
    91     //construct listview
    90     //construct listview
    92     mHistoryListView = static_cast<HbListView*>(findWidget(QString("cnt_listview_history")));
    91     mHistoryListView = static_cast<HbListView*>(findWidget(QString("cnt_listview_history")));
    93     
    92     
    94     //QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
       
    95     //db.setDatabaseName(db_path);
       
    96     //db.open();
       
    97     
       
    98     //bubble graphics - create our custom list view item to have different bubbles
    93     //bubble graphics - create our custom list view item to have different bubbles
    99     //for incoming and outgoing messages 
    94     //for incoming and outgoing messages 
   100     CntHistoryViewItem *item = new CntHistoryViewItem;
    95     CntHistoryViewItem *item = new CntHistoryViewItem;
   101     mHistoryListView->setItemPrototype(item); //ownership is taken
    96     mHistoryListView->setItemPrototype(item); //ownership is taken
       
    97     connect(mHistoryListView, SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
       
    98                       this,  SLOT(longPressed(HbAbstractViewItem *, const QPointF &)));
       
    99     connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
       
   100                       this,  SLOT(pressed(const QModelIndex &)));
   102     
   101     
   103     //create and set model for the list
       
   104     mHistoryModel = new MobHistoryModel(contact.localId(), contactManager());
   102     mHistoryModel = new MobHistoryModel(contact.localId(), contactManager());
   105     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
   103     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
   106     
   104     
   107     //start listening to the events amount changing in the model
   105     //start listening to the events amount changing in the model
   108     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
   106     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
   109         this, SLOT(updateScrollingPosition()));
   107         this, SLOT(updateScrollingPosition()));
       
   108     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()));
   110 }
   112 }
   111 
   113 
   112 /*!
   114 /*!
   113 Called after new items were added to comm history view
   115 Called after new items are added to or removed from comm history view
   114 */
   116 */
   115 void CntHistoryView::updateScrollingPosition()
   117 void CntHistoryView::updateScrollingPosition()
   116 {
   118 {
   117     int rowCnt = mHistoryModel->rowCount();
   119     int rowCnt = mHistoryModel->rowCount();
   118     mHistoryListView->scrollTo(mHistoryModel->index(rowCnt - 1, 0), 
   120     mHistoryListView->scrollTo(mHistoryModel->index(rowCnt - 1, 0), 
   119         HbAbstractItemView::PositionAtBottom);
   121         HbAbstractItemView::PositionAtBottom);
   120 }
   122 }
       
   123 
       
   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 /*
       
   139 Clear communications history
       
   140 */
       
   141 void CntHistoryView::clearHistory()
       
   142 {
       
   143     mHistoryModel->clearHistory();
       
   144 }
       
   145 
       
   146 /*!
       
   147 Called when a list item is longpressed
       
   148 */
       
   149 void CntHistoryView::longPressed(HbAbstractViewItem *item, const QPointF &coords)
       
   150 {
       
   151     Q_UNUSED(item);
       
   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
       
   160         mHistoryModel->clearHistory();
       
   161     }
       
   162     
       
   163     menu->deleteLater();
       
   164 }
       
   165 
       
   166 void CntHistoryView::pressed(const QModelIndex &index)
       
   167 {
       
   168     QVariant itemType = mHistoryModel->data(index, MobHistoryModel::ItemTypeRole);
       
   169     
       
   170     if (itemType.toInt() == MobHistoryModel::CallLog) {
       
   171         // Make a call
       
   172         QVariant v = mHistoryModel->data(index, MobHistoryModel::PhoneNumberRole);
       
   173         QString service("com.nokia.services.telephony");
       
   174         QString type("dial(QString)");
       
   175         XQServiceRequest snd(service, type, false);
       
   176         snd << v.toString();
       
   177         snd.send();
       
   178     }
       
   179 }
       
   180 
   121 // end of file
   181 // end of file