phonebookui/pbkcommonui/src/cnthistoryview.cpp
changeset 25 76a2435edfd4
parent 24 0ba2181d7c28
child 27 de1630741fbe
--- a/phonebookui/pbkcommonui/src/cnthistoryview.cpp	Fri Mar 19 09:27:18 2010 +0200
+++ b/phonebookui/pbkcommonui/src/cnthistoryview.cpp	Fri Apr 16 14:53:18 2010 +0300
@@ -21,11 +21,13 @@
 #include <hblistview.h>
 #include <hbgroupbox.h>
 #include <hblistviewitem.h>
+#include <hbabstractviewitem.h>
+#include <hbmenu.h>
+#include <xqservicerequest.h>
 #include <mobhistorymodel.h>
 #include "cnthistoryviewitem.h" 
 
 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
-//const QString db_path("c:\\conversations.sqlite");
 
 /*!
 Constructor, initialize member variables.
@@ -66,8 +68,13 @@
 */
 void CntHistoryView::aboutToCloseView()
 {
+    CntViewParameters args;//( CntViewParameters::commLauncherView );
+    args.setSelectedContact( *mContact );
+    viewManager()->back( args );
+        /*
     viewManager()->previousViewParameters().setSelectedContact(*mContact);
     viewManager()->onActivatePreviousView();
+    */
 }
 
 void CntHistoryView::activateView(const CntViewParameters &viewParameters)
@@ -77,40 +84,35 @@
     
     //group box
     HbGroupBox* groupBox = static_cast<HbGroupBox *>(findWidget(QString("cnt_groupbox_history")));
-    QString text;
-    if (mContact->localId() == contactManager()->selfContactId()) {
-        //My card
-        text.append(hbTrId("All history"));
-    }
-    else {
-        text.append(hbTrId("History: "));
-        text.append(contactManager()->synthesizeDisplayLabel(contact));
-    }
+    QString text = hbTrId("History with %1").arg(contactManager()->synthesizedDisplayLabel(contact));
     groupBox->setHeading(text);
     
     //construct listview
     mHistoryListView = static_cast<HbListView*>(findWidget(QString("cnt_listview_history")));
     
-    //QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
-    //db.setDatabaseName(db_path);
-    //db.open();
-    
     //bubble graphics - create our custom list view item to have different bubbles
     //for incoming and outgoing messages 
     CntHistoryViewItem *item = new CntHistoryViewItem;
     mHistoryListView->setItemPrototype(item); //ownership is taken
+    connect(mHistoryListView, SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
+                      this,  SLOT(longPressed(HbAbstractViewItem *, const QPointF &)));
+    connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
+                      this,  SLOT(pressed(const QModelIndex &)));
     
-    //create and set model for the list
     mHistoryModel = new MobHistoryModel(contact.localId(), contactManager());
     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
     
     //start listening to the events amount changing in the model
     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
         this, SLOT(updateScrollingPosition()));
+    connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
+        this, SLOT(rowsRemoved(const QModelIndex &, int, int)));
+    connect(mHistoryModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
+        this, SLOT(updateScrollingPosition()));
 }
 
 /*!
-Called after new items were added to comm history view
+Called after new items are added to or removed from comm history view
 */
 void CntHistoryView::updateScrollingPosition()
 {
@@ -118,4 +120,62 @@
     mHistoryListView->scrollTo(mHistoryModel->index(rowCnt - 1, 0), 
         HbAbstractItemView::PositionAtBottom);
 }
+
+/*!
+Add actions to menu
+*/
+void CntHistoryView::addMenuItems()
+{
+    CntActions* acts = actions();
+    acts->clearActionList();
+    acts->actionList() << acts->baseAction("cnt:clearhistory");
+    acts->addActionsToMenu(menu());
+        
+    connect(acts->baseAction("cnt:clearhistory"), SIGNAL(triggered()),
+            this, SLOT (clearHistory()));
+}
+
+/*
+Clear communications history
+*/
+void CntHistoryView::clearHistory()
+{
+    mHistoryModel->clearHistory();
+}
+
+/*!
+Called when a list item is longpressed
+*/
+void CntHistoryView::longPressed(HbAbstractViewItem *item, const QPointF &coords)
+{
+    Q_UNUSED(item);
+    
+    HbMenu* menu = new HbMenu();
+    HbAction* clearAction = menu->addAction(hbTrId("txt_phob_menu_clear_history"));
+    
+    HbAction* selectedAction = menu->exec(coords);
+    
+    if (selectedAction && selectedAction == clearAction) {
+        // Clear comm history
+        mHistoryModel->clearHistory();
+    }
+    
+    menu->deleteLater();
+}
+
+void CntHistoryView::pressed(const QModelIndex &index)
+{
+    QVariant itemType = mHistoryModel->data(index, MobHistoryModel::ItemTypeRole);
+    
+    if (itemType.toInt() == MobHistoryModel::CallLog) {
+        // Make a call
+        QVariant v = mHistoryModel->data(index, MobHistoryModel::PhoneNumberRole);
+        QString service("com.nokia.services.telephony");
+        QString type("dial(QString)");
+        XQServiceRequest snd(service, type, false);
+        snd << v.toString();
+        snd.send();
+    }
+}
+
 // end of file