phonebookui/pbkcommonui/src/cnthistoryview.cpp
changeset 53 e6aff7b69165
parent 50 77bc263e1626
child 61 d30183af6ca6
equal deleted inserted replaced
51:81c360d47083 53:e6aff7b69165
    28 #include <xqservicerequest.h>
    28 #include <xqservicerequest.h>
    29 #include <cnthistorymodel.h>
    29 #include <cnthistorymodel.h>
    30 #include <hbparameterlengthlimiter.h>
    30 #include <hbparameterlengthlimiter.h>
    31 #include <hbmainwindow.h>
    31 #include <hbmainwindow.h>
    32 #include <hbframebackground.h>
    32 #include <hbframebackground.h>
       
    33 #include <QTimer>
       
    34 #include <qtcontacts.h>
    33 
    35 
    34 #include "cnthistoryviewitem.h"
    36 #include "cnthistoryviewitem.h"
    35 #include "cntglobal.h"
    37 #include "cntglobal.h"
       
    38 #include "cntdebug.h"
    36 
    39 
    37 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
    40 const char *CNT_HISTORYVIEW_XML = ":/xml/contacts_history.docml";
    38 
    41 
    39 /*!
    42 /*!
    40 Constructor, initialize member variables.
    43 Constructor, initialize member variables.
    97 /*!
   100 /*!
    98  * Deactivate the view
   101  * Deactivate the view
    99  */
   102  */
   100 void CntHistoryView::deactivate()
   103 void CntHistoryView::deactivate()
   101 {
   104 {
       
   105     QContactManager* cm = mViewMgr->contactManager(SYMBIAN_BACKEND);
       
   106     disconnect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
       
   107             this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
   102 }
   108 }
   103 
   109 
   104 /**
   110 /**
   105  * Activate the view
   111  * Activate the view
   106  */
   112  */
   107 void CntHistoryView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
   113 void CntHistoryView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
   108 {
   114 {
   109     mViewMgr = aMgr;
   115     mViewMgr = aMgr;
   110     mArgs = aArgs;
   116     mArgs = aArgs;
       
   117     
       
   118     QContactManager* cm = mViewMgr->contactManager(SYMBIAN_BACKEND);
   111     mContact = new QContact(mArgs.value(ESelectedContact).value<QContact>());
   119     mContact = new QContact(mArgs.value(ESelectedContact).value<QContact>());
   112     
   120     
   113     // Set history view heading
   121     // Set history view heading
   114     HbGroupBox* groupBox = static_cast<HbGroupBox*>(docLoader()->findWidget(QString("groupBox")));
   122     HbGroupBox* groupBox = static_cast<HbGroupBox*>(docLoader()->findWidget(QString("groupBox")));
   115     QString name = mContact->displayLabel();
   123     QString name = mContact->displayLabel();
   128     mHistoryListView->setItemPrototype(item); //ownership is taken
   136     mHistoryListView->setItemPrototype(item); //ownership is taken
   129     
   137     
   130     // Connect listview items to respective slots
   138     // Connect listview items to respective slots
   131     connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
   139     connect(mHistoryListView, SIGNAL(activated(const QModelIndex &)),
   132                       this,  SLOT(itemActivated(const QModelIndex &)));
   140                       this,  SLOT(itemActivated(const QModelIndex &)));
   133     mHistoryModel = new CntHistoryModel(mContact->localId(),
   141     mHistoryModel = new CntHistoryModel(mContact->localId(), cm);
   134                                         mViewMgr->contactManager(SYMBIAN_BACKEND));
       
   135     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
   142     mHistoryListView->setModel(mHistoryModel); //ownership is not taken
   136     
   143     
   137     //start listening to the events amount changing in the model
   144     //start listening to the events amount changing in the model
   138     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
   145     connect(mHistoryModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
   139         this, SLOT(updateScrollingPosition()));
   146         this, SLOT(updateScrollingPosition()));
   153     showClearHistoryMenu();
   160     showClearHistoryMenu();
   154     
   161     
   155     HbMainWindow* mainWindow = mView->mainWindow();
   162     HbMainWindow* mainWindow = mView->mainWindow();
   156     connect(mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), 
   163     connect(mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), 
   157             this, SLOT(updateScrollingPosition()));
   164             this, SLOT(updateScrollingPosition()));
       
   165     
       
   166     connect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), 
       
   167         this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
   158 }
   168 }
   159 
   169 
   160 /*!
   170 /*!
   161 Called after new items are added to or removed from comm history view
   171 Called after new items are added to or removed from comm history view
   162 */
   172 */
   218         if ( number.isValid() ) {        
   228         if ( number.isValid() ) {        
   219             interface = "com.nokia.symbian.ICallDial";
   229             interface = "com.nokia.symbian.ICallDial";
   220             operation = "dial(QString)";
   230             operation = "dial(QString)";
   221             args << number;
   231             args << number;
   222             createRequest = true;
   232             createRequest = true;
       
   233             
       
   234             // TODO: Using XQApplicationManager is not working with calls
       
   235             // The factory method cannot create a request. Find out why
       
   236             createRequest = false;
       
   237             QString service("com.nokia.symbian.ICallDial");
       
   238             QString type("dial(QString,int)");
       
   239             XQServiceRequest snd(interface, operation, false);
       
   240             snd << number.toString() << mContact->localId();
       
   241             snd.send();
   223         }
   242         }
   224         
       
   225         // TODO: Using XQApplicationManager is not working with calls
       
   226         // The factory method cannot create a request. Find out why
       
   227         createRequest = false;
       
   228         QString service("com.nokia.symbian.ICallDial");
       
   229         QString type("dial(QString)");
       
   230         XQServiceRequest snd(interface, operation, false);
       
   231         snd << number.toString();
       
   232         snd.send();
       
   233         
   243         
   234     } else if ( flags & CntMessage ) {
   244     } else if ( flags & CntMessage ) {
   235         // Open conversation view
   245         // Open conversation view
   236         QVariant id = index.data(CntConverstaionIdRole);
   246         QVariant id = index.data(CntConverstaionIdRole);
   237         
   247         
   267     mArgs.insert(ESelectedContact, var);
   277     mArgs.insert(ESelectedContact, var);
   268     mViewMgr->back( mArgs );
   278     mViewMgr->back( mArgs );
   269 }
   279 }
   270 
   280 
   271 /*!
   281 /*!
       
   282 Go back to the root view
       
   283 */
       
   284 void CntHistoryView::showRootView()
       
   285 {   
       
   286     mViewMgr->back( mArgs, true );
       
   287 }
       
   288 
       
   289 
       
   290 void CntHistoryView::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds)
       
   291 {
       
   292     CNT_ENTRY
       
   293     if ( contactIds.contains(mContact->localId()) )
       
   294     {
       
   295         // Do not switch to the previous view immediately. List views are
       
   296         // not updated properly if this is not done in the event loop
       
   297         QTimer::singleShot(0, this, SLOT(showRootView()));
       
   298     }
       
   299     CNT_EXIT
       
   300 }
       
   301 
       
   302 /*!
   272 Show or hide the clear history menu
   303 Show or hide the clear history menu
   273 */
   304 */
   274 void CntHistoryView::showClearHistoryMenu()
   305 void CntHistoryView::showClearHistoryMenu()
   275 {
   306 {
   276     if (mHistoryModel->rowCount() > 0) {
   307     if (mHistoryModel->rowCount() > 0) {