logsui/logsapp/src/logsbaseview.cpp
changeset 0 4a5361db8937
child 2 7119b73b84d6
equal deleted inserted replaced
-1:000000000000 0:4a5361db8937
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 //USER
       
    18 #include "logsbaseview.h"
       
    19 #include "logscomponentrepository.h"
       
    20 #include "logsabstractviewmanager.h"
       
    21 #include "logsdefs.h"
       
    22 #include "logslogger.h"
       
    23 #include "logscall.h"
       
    24 #include "logsmessage.h"
       
    25 #include "logscontact.h"
       
    26 #include "logsabstractmodel.h"
       
    27 #include "logsdetailsmodel.h"
       
    28 
       
    29 //SYSTEM
       
    30 #include <hbaction.h>
       
    31 #include <hbmainwindow.h>
       
    32 #include <hbmessagebox.h>
       
    33 #include <hbtoolbar.h>
       
    34 #include <hbmenu.h>
       
    35 #include <dialpad.h>
       
    36 #include <hblineedit.h>
       
    37 #include <hbeffect.h>
       
    38 #include <hbabstractviewitem.h>
       
    39 #include <QSignalMapper>
       
    40 #include <xqservicerequest.h>
       
    41 #include <hblabel.h>
       
    42 #include <hblistview.h>
       
    43 #include <QGraphicsLinearLayout>
       
    44 #include <hbpushbutton.h>
       
    45 
       
    46 
       
    47 Q_DECLARE_METATYPE(LogsCall*)
       
    48 Q_DECLARE_METATYPE(LogsMessage*)
       
    49 Q_DECLARE_METATYPE(LogsContact*)
       
    50 Q_DECLARE_METATYPE(LogsDetailsModel*)
       
    51 
       
    52 const int contextMenuTimeout = 5000000; //5 secs
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // 
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 LogsBaseView::LogsBaseView( 
       
    59     LogsAppViewId viewId, 
       
    60     LogsComponentRepository& repository, 
       
    61     LogsAbstractViewManager& viewManager )
       
    62     : HbView(0),
       
    63       mViewId( viewId ),
       
    64       mRepository( repository ),
       
    65       mViewManager( viewManager ),
       
    66       mShowFilterMenu(0),
       
    67       mEmptyListLabel(0),
       
    68       mInitialized(false),
       
    69       mCall(0),
       
    70       mMessage(0),
       
    71       mContact(0),
       
    72       mDetailsModel(0),
       
    73       mCallTypeMapper(0)
       
    74 {
       
    75     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::LogsBaseView()" );
       
    76     
       
    77     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
       
    78     connect(mSoftKeyBackAction, SIGNAL(triggered()), this, 
       
    79             SLOT(handleBackSoftkey()));
       
    80 
       
    81     mDialpad =  mRepository.dialpad();
       
    82     
       
    83     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::LogsBaseView()" );
       
    84 }
       
    85     
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 LogsBaseView::~LogsBaseView()
       
    91 {
       
    92     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::~LogsBaseView()" );
       
    93 
       
    94     delete mCall;
       
    95     delete mMessage;
       
    96     delete mContact;
       
    97     delete mDetailsModel;    
       
    98     delete mCallTypeMapper;
       
    99 
       
   100     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::~LogsBaseView()" );
       
   101 }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 LogsAppViewId LogsBaseView::viewId() const
       
   108 {
       
   109     return mViewId;
       
   110 }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 bool LogsBaseView::isExitAllowed()
       
   117 {
       
   118     return true;
       
   119 }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void LogsBaseView::resetView()
       
   126 {
       
   127     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::resetView()" );
       
   128     mDialpad->editor().setText(QString());
       
   129     if ( mDialpad->isOpen() ){
       
   130         mDialpad->closeDialpad();
       
   131     }
       
   132     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::resetView()" );
       
   133 }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void LogsBaseView::activated(bool showDialer, QVariant args)
       
   140 {
       
   141     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::activated()" );
       
   142     Q_UNUSED(args);
       
   143     //we have to set object tree of the repository to the current view
       
   144     mRepository.setObjectTreeToView( mViewId );
       
   145 
       
   146     if (!mInitialized) {
       
   147         initView();
       
   148     }
       
   149         
       
   150     connect( mDialpad, SIGNAL( aboutToClose() ), this, 
       
   151             SLOT( dialpadClosed() ), Qt::QueuedConnection );
       
   152     connect( mDialpad, SIGNAL( aboutToOpen() ), this, 
       
   153             SLOT( dialpadOpened() ), Qt::QueuedConnection );
       
   154     connect( &mDialpad->editor(), SIGNAL( contentsChanged() ), this,
       
   155             SLOT( dialpadEditorTextChanged() ) );
       
   156 
       
   157     if ( navigationAction() != mSoftKeyBackAction ) {
       
   158         setNavigationAction(mSoftKeyBackAction);
       
   159     }
       
   160     
       
   161     if (showDialer && !mDialpad->isOpen()) {
       
   162         openDialpad();
       
   163     }
       
   164     
       
   165     updateWidgetsSizeAndLayout();
       
   166     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::activated()" );
       
   167 }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void LogsBaseView::deactivated()
       
   174 {
       
   175     LOGS_QDEBUG( "logs [UI] <-> LogsBaseView::deactivated()" );
       
   176     disconnect( mDialpad, SIGNAL( aboutToClose() ), this, 
       
   177             SLOT( dialpadClosed() ) );
       
   178     disconnect( mDialpad, SIGNAL( aboutToOpen() ), this, 
       
   179             SLOT( dialpadOpened() ) );
       
   180     disconnect( &mDialpad->editor(), SIGNAL( contentsChanged() ), this,
       
   181             SLOT( dialpadEditorTextChanged() ) );
       
   182 }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void LogsBaseView::notSupported()
       
   189 {
       
   190     HbMessageBox* messageBox = new HbMessageBox(QString("Not supported"));
       
   191     messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   192     messageBox->setTimeout( HbMessageBox::StandardTimeout );
       
   193     messageBox->show();
       
   194 }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void LogsBaseView::handleBackSoftkey()
       
   201 {
       
   202     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::handleBackSoftkey()" );
       
   203     mViewManager.activateView( LogsRecentViewId, false, QVariant() );
       
   204     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::handleBackSoftkey()" );
       
   205 }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void LogsBaseView::initFilterMenu()
       
   212 {
       
   213     mShowFilterMenu = 
       
   214         qobject_cast<HbMenu*>( mRepository.findWidget( logsShowFilterMenuId ) );
       
   215 }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void LogsBaseView::addActionNamesToMap()
       
   222 {
       
   223     mActionMap.clear();
       
   224     mActionMap.insert(LogsServices::ViewReceived, logsShowFilterReceivedMenuActionId);
       
   225     mActionMap.insert(LogsServices::ViewCalled, logsShowFilterDialledMenuActionId);
       
   226     mActionMap.insert(LogsServices::ViewMissed, logsShowFilterMissedMenuActionId);
       
   227     mActionMap.insert(LogsServices::ViewAll, logsShowFilterRecentMenuActionId);  
       
   228 }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void LogsBaseView::initView()
       
   235 {   
       
   236     Q_ASSERT_X( !mInitialized, "logs [UI] ", "view is already initialized!!" );
       
   237     mInitialized = true;
       
   238     initFilterMenu();
       
   239     addActionNamesToMap();
       
   240     connect(menu(), SIGNAL(aboutToShow()), this, 
       
   241             SLOT(closeEmptyMenu()), Qt::QueuedConnection);
       
   242 }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 QAbstractItemModel* LogsBaseView::model() const
       
   249 {
       
   250     LOGS_QDEBUG( "logs [UI] <-> LogsBaseView::model()" );
       
   251     return 0;
       
   252 }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void LogsBaseView::handleExit()
       
   259 {
       
   260     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::handleExit()" );   
       
   261     mViewManager.exitApplication();
       
   262     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::handleExit()" );
       
   263 }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void LogsBaseView::showFilterMenu()
       
   270 {
       
   271     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::showFilterMenu()" );
       
   272     if ( mShowFilterMenu ) {
       
   273         QRectF toolbarGeometry = toolBar()->geometry();
       
   274         QSizeF menuSize = mShowFilterMenu->size();
       
   275         LOGS_QDEBUG_2("logs [UI]    menusize:", menuSize)
       
   276         
       
   277         QPointF pos( toolbarGeometry.bottomRight().x(),
       
   278                      toolbarGeometry.topRight().y() ); 
       
   279                      
       
   280         pos.setX(toolbarGeometry.bottomRight().x());
       
   281         pos.setY(toolbarGeometry.topRight().y());
       
   282 
       
   283         mShowFilterMenu->setPreferredPos(pos,HbPopup::BottomRightCorner);
       
   284         LOGS_QDEBUG_2("logs [UI]    menupos:", pos)
       
   285         mShowFilterMenu->exec();
       
   286     }
       
   287     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::showFilterMenu()" );
       
   288 }
       
   289 // -----------------------------------------------------------------------------
       
   290 // LogsBaseView::closeEmptyMenu()
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void LogsBaseView::closeEmptyMenu()
       
   294 {
       
   295     bool visibleActionsExist = false;
       
   296     foreach (QAction* action, menu()->actions()) {
       
   297         if  (action->isVisible()) {
       
   298             visibleActionsExist = true ;
       
   299         }
       
   300     }
       
   301     
       
   302     if (!visibleActionsExist) {
       
   303         menu()->close();
       
   304     }
       
   305 }
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 void LogsBaseView::openDialpad()
       
   311 {
       
   312     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::openDialpad()" );
       
   313     updateCallButton();
       
   314     setDialpadPosition();
       
   315     mDialpad->openDialpad();
       
   316     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::openDialpad()" );
       
   317 }
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 void LogsBaseView::openContactsApp()
       
   324 {
       
   325     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::openContactsApp()" );
       
   326     
       
   327     // Need to do request in async manner, otherwise new phonebook ui process
       
   328     // will be started due bug(?) in highway.
       
   329     XQServiceRequest snd("com.nokia.services.phonebookappservices.Launch","launch()", false);
       
   330     int retValue;
       
   331     snd.send(retValue);
       
   332     
       
   333     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::openContactsApp()" );
       
   334 }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 void LogsBaseView::setDialpadPosition()
       
   341 {
       
   342     HbMainWindow& window = mViewManager.mainWindow(); 
       
   343     // layoutrect broken, fix will be in MCL wk14, use workaround meanwhile
       
   344     //QRectF screenRect = window.layoutRect();
       
   345     QRectF screenRect = (window.orientation() == Qt::Horizontal) ? 
       
   346         QRectF(0,0,640,360) : QRectF(0,0,360,640);
       
   347 
       
   348     LOGS_QDEBUG_2( "logs [UI] -> LogsBaseView::setDialpadPosition(), screenRect:", 
       
   349             screenRect );
       
   350     if (window.orientation() == Qt::Horizontal) {
       
   351         // dialpad takes half of the screen width    
       
   352         mDialpad->setPos(QPointF(screenRect.width()/2,
       
   353                                  this->scenePos().y()));
       
   354         mDialpad->setPreferredSize(screenRect.width()/2,
       
   355                                    (screenRect.height()-scenePos().y()));                                  
       
   356     } else {
       
   357         // dialpad takes 65% of the screen height
       
   358         qreal screenHeight = screenRect.height();
       
   359         mDialpad->setPos(QPointF(0, screenHeight/2.25));
       
   360         mDialpad->setPreferredSize(screenRect.width(),
       
   361                                    screenHeight-screenHeight/2.25);        
       
   362     }
       
   363     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::setDialpadPosition()" );
       
   364 }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 void LogsBaseView::dialpadOpened()
       
   371 {
       
   372     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::dialpadOpened()" );
       
   373     updateWidgetsSizeAndLayout();
       
   374     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::dialpadOpened()" );
       
   375 }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 void LogsBaseView::dialpadClosed()
       
   382 {
       
   383     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::dialpadClosed()" );
       
   384     mDialpad->editor().setText(QString());
       
   385     updateWidgetsSizeAndLayout();
       
   386     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::dialpadClosed()" );
       
   387 }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 // -----------------------------------------------------------------------------
       
   392 //
       
   393 void LogsBaseView::dialpadEditorTextChanged()
       
   394 {
       
   395     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::dialpadEditorTextChanged()" );
       
   396     if ( mDialpad->editor().text().length() > 0 ) {
       
   397         mViewManager.activateView( LogsMatchesViewId, true, QVariant() );      
       
   398     } else {
       
   399         updateCallButton();
       
   400     }
       
   401     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::dialpadEditorTextChanged()" );
       
   402 }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // 
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 void LogsBaseView::changeFilter(HbAction* action)
       
   409 {
       
   410     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::changeFilter()" );
       
   411     LogsServices::LogsView view = mActionMap.key( action->objectName(),
       
   412             LogsServices::ViewAll );
       
   413     QVariant args(view);
       
   414     mViewManager.activateView( LogsRecentViewId, false, args );
       
   415     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::changeFilter()" );
       
   416 }
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // 
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 void LogsBaseView::showListItemMenu(
       
   423         HbAbstractViewItem* item, const QPointF& coords )
       
   424 {
       
   425     HbMenu itemContextMenu(0);    
       
   426     itemContextMenu.setDismissPolicy(HbMenu::TapAnywhere);
       
   427     itemContextMenu.setTimeout(contextMenuTimeout);
       
   428 
       
   429     updateListItemData(item->modelIndex());    
       
   430     populateListItemMenu(itemContextMenu);
       
   431 
       
   432     if (mDialpad->isOpen()) {
       
   433         mDialpad->closeDialpad();
       
   434     }    
       
   435     if (itemContextMenu.actions().count() > 0) {
       
   436         itemContextMenu.exec(coords);
       
   437     }
       
   438 }
       
   439 
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void LogsBaseView::populateListItemMenu(HbMenu& menu)
       
   445 {
       
   446     delete mCallTypeMapper;
       
   447     mCallTypeMapper = 0;
       
   448 
       
   449     if (mCall) {
       
   450         mCallTypeMapper = new QSignalMapper();
       
   451                 
       
   452         foreach(LogsCall::CallType callType, mCall->allowedCallTypes()){
       
   453             HbAction* callAction = new HbAction;
       
   454             if (callType == LogsCall::TypeLogsVoiceCall){
       
   455                 callAction->setText(hbTrId("txt_common_menu_voice_call"));
       
   456             }
       
   457             else if (callType == LogsCall::TypeLogsVideoCall){
       
   458                 callAction->setText(hbTrId("txt_common_menu_video_call"));
       
   459             }
       
   460             else if (callType == LogsCall::TypeLogsVoIPCall){
       
   461                 callAction->setText(hbTrId("txt_common_menu_internet_call"));
       
   462             }
       
   463             
       
   464             connect(callAction, SIGNAL(triggered()),
       
   465                     mCallTypeMapper, SLOT( map()) );
       
   466             mCallTypeMapper->setMapping(callAction, callType);
       
   467             
       
   468             // Default call type must be the first item in context menu
       
   469             if (callType != mCall->defaultCallType() ||
       
   470                 menu.actions().count() == 0){
       
   471                 menu.addAction(callAction);
       
   472             } else {   
       
   473                 menu.insertAction(menu.actions().at(0), callAction);
       
   474             }           
       
   475         }    
       
   476         connect(mCallTypeMapper, SIGNAL(mapped(int)),
       
   477                 this, SLOT( initiateCall(int)) );
       
   478     }
       
   479     
       
   480     if (mMessage) {
       
   481         HbAction* messageAction = new HbAction;
       
   482         messageAction->setText(hbTrId("txt_common_menu_create_message"));
       
   483         menu.addAction(messageAction);
       
   484         QObject::connect( messageAction, SIGNAL(triggered()), 
       
   485                           this, SLOT( createMessage() ) );
       
   486     }
       
   487     if (mContact) {
       
   488         HbAction* contactAction = new HbAction;
       
   489         if (mContact->allowedRequestType() ==
       
   490                 LogsContact::TypeLogsContactOpen) {
       
   491             contactAction->setText(hbTrId("txt_dialer_ui_menu_open_contact"));
       
   492             QObject::connect( contactAction, SIGNAL(triggered()), 
       
   493                               mContact, SLOT(open()) );
       
   494         }
       
   495         else {
       
   496             contactAction->setText(hbTrId("txt_common_menu_add_to_contacts"));
       
   497             QObject::connect( contactAction, SIGNAL(triggered()), 
       
   498                               this, SLOT(saveContact()) );
       
   499         
       
   500         }
       
   501         menu.addAction(contactAction);
       
   502     }    
       
   503     if (mDetailsModel) {
       
   504         HbAction* callDetailsAction = new HbAction;
       
   505         callDetailsAction->setText(hbTrId("txt_dialer_ui_menu_call_details"));
       
   506         menu.addAction(callDetailsAction);
       
   507         QObject::connect(callDetailsAction, SIGNAL(triggered()), 
       
   508                          this, SLOT(showCallDetails()));
       
   509         
       
   510         HbAction* deleteAction = new HbAction;
       
   511         deleteAction->setText(hbTrId("txt_common_menu_delete"));
       
   512         menu.addAction(deleteAction);
       
   513         QObject::connect(deleteAction, SIGNAL(triggered()), 
       
   514                          this, SLOT(deleteEvent()));
       
   515     }
       
   516 }
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 //
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 void LogsBaseView::updateListItemData(const QModelIndex& listIndex)
       
   523 {
       
   524     updateCall(listIndex);
       
   525     updateMessage(listIndex);
       
   526     updateContact(listIndex);
       
   527     updateDetailsModel(listIndex);
       
   528 }
       
   529 
       
   530 // -----------------------------------------------------------------------------
       
   531 // 
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 void LogsBaseView::updateCallButton()
       
   535 {
       
   536     mDialpad->setCallButtonEnabled( !mDialpad->editor().text().isEmpty() );
       
   537 }
       
   538  
       
   539 // -----------------------------------------------------------------------------
       
   540 // 
       
   541 // -----------------------------------------------------------------------------
       
   542 //
       
   543 void LogsBaseView::initiateCallback(const QModelIndex& index)
       
   544 {
       
   545     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::initiateCallback()" );
       
   546     updateCall(index);
       
   547 
       
   548     if (mCall) {
       
   549         mCall->initiateCallback();
       
   550     }
       
   551     delete mCall;
       
   552     mCall = 0;
       
   553     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::initiateCallback()" );
       
   554 }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // 
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 void LogsBaseView::initiateCall(int callType)
       
   561 {       
       
   562     if (mCall) {
       
   563         mCall->call( static_cast<LogsCall::CallType>(callType) );
       
   564     }
       
   565 }
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 //
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 void LogsBaseView::createMessage()
       
   572 {
       
   573     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::createMessage()" );
       
   574     if (mMessage) {
       
   575         mMessage->sendMessage();
       
   576     }
       
   577     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::createMessage()" );   
       
   578 }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 void LogsBaseView::saveContact()
       
   585 {
       
   586     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::saveContact()" ); 
       
   587     
       
   588     if (mContact){
       
   589         HbDialog* popup = new HbDialog();
       
   590         popup->setDismissPolicy(HbDialog::NoDismiss);
       
   591         popup->setHeadingWidget(
       
   592                 new HbLabel(hbTrId("txt_dial_title_add_to_contacts"), popup));
       
   593         popup->setAttribute(Qt::WA_DeleteOnClose);
       
   594         popup->setTimeout( HbPopup::NoTimeout );
       
   595         popup->setSecondaryAction(
       
   596                 new HbAction(hbTrId("txt_dial_button_cancel"), popup));
       
   597 
       
   598         HbWidget* buttonWidget = new HbWidget(popup);
       
   599         QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
       
   600         
       
   601         HbPushButton* addButton = new HbPushButton(buttonWidget);
       
   602         addButton->setOrientation(Qt::Horizontal);
       
   603         addButton->setText(hbTrId("txt_dial_list_save_as_a_new_contact"));
       
   604         HbIcon plusIcon("qtg_mono_plus");
       
   605         addButton->setIcon(plusIcon);
       
   606         connect(addButton, SIGNAL(clicked()), popup, SLOT(close()));
       
   607         connect(addButton, SIGNAL(clicked()), mContact, SLOT(addNew()));
       
   608         
       
   609         HbPushButton* updateButton = new HbPushButton(buttonWidget);
       
   610         updateButton->setOrientation(Qt::Horizontal);
       
   611         updateButton->setText(hbTrId("txt_dial_list_update_existing_contact"));
       
   612         updateButton->setIcon(plusIcon);
       
   613         connect(updateButton, SIGNAL(clicked()), popup, SLOT(close()));
       
   614         connect(updateButton, SIGNAL(clicked()),
       
   615                 mContact, SLOT(updateExisting()));
       
   616         
       
   617         layout->addItem(addButton);
       
   618         layout->addItem(updateButton);
       
   619         
       
   620         buttonWidget->setLayout(layout);
       
   621         popup->setContentWidget(buttonWidget);
       
   622 
       
   623         popup->exec();
       
   624     }
       
   625     
       
   626     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::saveContact()" );
       
   627 }
       
   628 
       
   629 // -----------------------------------------------------------------------------
       
   630 //
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 void LogsBaseView::updateCall(const QModelIndex &listIndex)
       
   634 {
       
   635     delete mCall;
       
   636     mCall = 0;
       
   637     if ( model() ) {
       
   638         mCall = qVariantValue<LogsCall*>( model()->data( 
       
   639                 listIndex, LogsAbstractModel::RoleCall ) );    
       
   640     }
       
   641 }
       
   642 
       
   643 // -----------------------------------------------------------------------------
       
   644 //
       
   645 // -----------------------------------------------------------------------------
       
   646 //
       
   647 void LogsBaseView::updateMessage(const QModelIndex &listIndex)
       
   648 {
       
   649     delete mMessage;
       
   650     mMessage = 0;
       
   651     if ( model() ) {
       
   652         mMessage = qVariantValue<LogsMessage*>( model()->data( 
       
   653                 listIndex, LogsAbstractModel::RoleMessage ) );
       
   654     }
       
   655 }
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 //
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 void LogsBaseView::updateContact(const QModelIndex &listIndex)
       
   662 {
       
   663     delete mContact;
       
   664     mContact = 0;
       
   665     if ( model() ) {
       
   666         mContact = qVariantValue<LogsContact*>( model()->data( 
       
   667                 listIndex, LogsAbstractModel::RoleContact ) );    
       
   668     }
       
   669 }
       
   670 
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 // -----------------------------------------------------------------------------
       
   674 //
       
   675 void LogsBaseView::updateDetailsModel(const QModelIndex &listIndex)
       
   676 {
       
   677     delete mDetailsModel;
       
   678     mDetailsModel = 0;
       
   679     if ( model() ) {
       
   680         mDetailsModel = qVariantValue<LogsDetailsModel*>( model()->data( 
       
   681                 listIndex, LogsAbstractModel::RoleDetailsModel ) );    
       
   682     }
       
   683 }
       
   684 
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 // -----------------------------------------------------------------------------
       
   688 //
       
   689 void LogsBaseView::activateEmptyListIndicator(QAbstractItemModel* model)
       
   690 {
       
   691     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::activateEmptyListIndicator()" );
       
   692     if ( !mEmptyListLabel ){
       
   693         mEmptyListLabel = qobject_cast<HbLabel*>(
       
   694                             mRepository.findWidget( logsLabelEmptyListId ) );
       
   695     }
       
   696     if ( model ){
       
   697          // Listen for changes in model and update empty list label accordingly
       
   698          connect( model, SIGNAL(rowsInserted(const QModelIndex&,int,int)), 
       
   699              this, SLOT(updateEmptyListWidgetsVisibility()));
       
   700          connect( model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), 
       
   701              this, SLOT(updateEmptyListWidgetsVisibility()));
       
   702          connect( model, SIGNAL(modelReset()), 
       
   703              this, SLOT(updateEmptyListWidgetsVisibility()));
       
   704          // Update to reflect current situation
       
   705          updateEmptyListWidgetsVisibility();
       
   706     }
       
   707     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::activateEmptyListIndicator()" );
       
   708 }
       
   709 
       
   710 // -----------------------------------------------------------------------------
       
   711 //
       
   712 // -----------------------------------------------------------------------------
       
   713 //
       
   714 void LogsBaseView::deactivateEmptyListIndicator(QAbstractItemModel* model)
       
   715 {
       
   716     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::deactivateEmptyListIndicator()" );
       
   717     if ( model ){
       
   718          disconnect( model, SIGNAL(rowsInserted(const QModelIndex&,int,int)), 
       
   719              this, SLOT(updateEmptyListWidgetsVisibility()));
       
   720          disconnect( model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), 
       
   721              this, SLOT(updateEmptyListWidgetsVisibility()));
       
   722          disconnect( model, SIGNAL(modelReset()), 
       
   723              this, SLOT(updateEmptyListWidgetsVisibility()));
       
   724     }
       
   725     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::deactivateEmptyListIndicator()" );
       
   726 }
       
   727 
       
   728 // -----------------------------------------------------------------------------
       
   729 //
       
   730 // -----------------------------------------------------------------------------
       
   731 //
       
   732 void LogsBaseView::addViewSwitchingEffects()
       
   733 {
       
   734     // Add view switching effects, these are called when 
       
   735     // HbMainWindow::setCurrentView is called, may be removed once orbit
       
   736     // has some built-in effects for view switching.
       
   737     HbEffect::add(this, ":/view_show.fxml", "show");
       
   738     HbEffect::add(this, ":/view_hide.fxml", "hide");
       
   739 }
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 //
       
   743 // -----------------------------------------------------------------------------
       
   744 //
       
   745 void LogsBaseView::updateEmptyListWidgetsVisibility()
       
   746 {
       
   747     updateEmptyListLabelVisibility();
       
   748 }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 void LogsBaseView::updateEmptyListLabelVisibility()
       
   755 {
       
   756     if ( mEmptyListLabel && model() ){
       
   757         LOGS_QDEBUG( "logs [UI] <-> LogsBaseView::updateEmptyListLabelVisibility()" );   
       
   758         bool visible(model()->rowCount() == 0);
       
   759         mEmptyListLabel->setVisible(visible);
       
   760     }  
       
   761 }
       
   762 
       
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 void LogsBaseView::showCallDetails()
       
   768 {
       
   769     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::showCallDetails()" );
       
   770     
       
   771     if ( !mDetailsModel ){
       
   772         return;
       
   773     }
       
   774     
       
   775     QVariant arg = qVariantFromValue( mDetailsModel );
       
   776     if ( mViewManager.activateView(LogsDetailsViewId, false, arg) ){
       
   777         mDetailsModel = 0;
       
   778     }
       
   779    
       
   780     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::showCallDetails()" );
       
   781 }
       
   782 
       
   783 
       
   784 // -----------------------------------------------------------------------------
       
   785 //
       
   786 // -----------------------------------------------------------------------------
       
   787 //
       
   788 void LogsBaseView::deleteEvent()
       
   789 {
       
   790     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::deleteEvent()" );
       
   791     if ( mDetailsModel ) {
       
   792         if ( askConfirmation( hbTrId("txt_dialer_ui_title_delete_event"),
       
   793     			hbTrId("txt_dialer_info_call_event_will_be_removed_from"))){
       
   794             mDetailsModel->clearEvent();	  
       
   795         }
       
   796     }
       
   797     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::deleteEvent()" );
       
   798 }
       
   799 
       
   800 // -----------------------------------------------------------------------------
       
   801 //
       
   802 // -----------------------------------------------------------------------------
       
   803 //
       
   804 void LogsBaseView::updateWidgetsSizeAndLayout()
       
   805 {
       
   806 }
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // Sets appropriate list widget layout using listView.setLayoutName()
       
   810 // -----------------------------------------------------------------------------
       
   811 //
       
   812 void LogsBaseView::updateListLayoutName( HbListView& listView, bool ignoreDialpad )
       
   813 {
       
   814     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::updateListLayoutName()" );
       
   815     QString newLayout( logsListDefaultLayout  );
       
   816     Qt::Orientation orientation = mViewManager.mainWindow().orientation();    
       
   817     if (orientation == Qt::Horizontal) {
       
   818         if (mDialpad->isOpen()) {
       
   819             if (ignoreDialpad) {
       
   820                 newLayout = QString( logsListDefaultLayout );
       
   821             } else {
       
   822                 newLayout = QString( logsListLandscapeDialpadLayout );
       
   823             }
       
   824         } else {
       
   825             newLayout = QString( logsListLandscapeLayout );
       
   826         }
       
   827     } else {
       
   828         newLayout = QString( logsListDefaultLayout );
       
   829     }
       
   830     
       
   831     if (newLayout != listView.layoutName()) {
       
   832         LOGS_QDEBUG_2( "logs [UI]  setting new list layout name: ", newLayout );
       
   833         listView.setLayoutName( newLayout );
       
   834     }
       
   835     
       
   836     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::updateListLayoutName()" );
       
   837 }
       
   838 
       
   839 // -----------------------------------------------------------------------------
       
   840 // Loads appropriate section from *.docml to resize list widget
       
   841 // -----------------------------------------------------------------------------
       
   842 //
       
   843 void LogsBaseView::updateListSize()
       
   844 {
       
   845     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::updateListSize()" );
       
   846     QString newSection( logsViewDefaultSection );
       
   847     Qt::Orientation orientation = mViewManager.mainWindow().orientation();
       
   848 
       
   849     if (mDialpad->isOpen()) {
       
   850         if (orientation == Qt::Horizontal) {
       
   851             newSection = QString( logsViewLandscapeDialpadSection );
       
   852         } else {
       
   853             newSection = QString( logsViewPortraitDialpadSection );
       
   854         }
       
   855     } else {
       
   856         newSection = QString( logsViewDefaultSection );
       
   857     }
       
   858     
       
   859     if (newSection != mLayoutSectionName) {
       
   860         mLayoutSectionName = newSection;
       
   861         LOGS_QDEBUG_2( "logs [UI]  loading new section: ", newSection );
       
   862         mRepository.loadSection( viewId(), newSection );
       
   863     }
       
   864     
       
   865     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::updateListSize()" );
       
   866 }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 //
       
   870 // -----------------------------------------------------------------------------
       
   871 //
       
   872 void LogsBaseView::handleOrientationChanged()
       
   873 {
       
   874     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::handleOrientationChanged()!" );
       
   875     setDialpadPosition();
       
   876     updateWidgetsSizeAndLayout();    
       
   877     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::handleOrientationChanged()");
       
   878 }
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 //
       
   882 // -----------------------------------------------------------------------------
       
   883 //
       
   884 void LogsBaseView::toggleActionAvailability( HbAction* action, bool available )
       
   885 {
       
   886     if ( action ){
       
   887         action->setVisible( available );
       
   888     }
       
   889 }
       
   890 
       
   891 // -----------------------------------------------------------------------------
       
   892 // 
       
   893 // -----------------------------------------------------------------------------
       
   894 //
       
   895 bool LogsBaseView::askConfirmation( QString heading , QString text )
       
   896 {
       
   897    bool result(false);
       
   898    HbMessageBox *note = new HbMessageBox("", HbMessageBox::MessageTypeQuestion);
       
   899    note->setHeadingWidget(new HbLabel( heading ));
       
   900    note->setText( text );
       
   901    note->setPrimaryAction(new HbAction(hbTrId("txt_common_button_ok"), note));
       
   902    note->setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), note));
       
   903    HbAction *selected = note->exec();
       
   904    if (selected == note->primaryAction()){ 
       
   905        result = true;
       
   906    }
       
   907    delete note;
       
   908    return result;
       
   909 }