satui/satapp/src/satappmainhandler.cpp
branchRCL_3
changeset 19 7d48bed6ce0c
equal deleted inserted replaced
18:594d59766373 19:7d48bed6ce0c
       
     1 /*
       
     2 * Copyright (c) 2010 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 */
       
    18 //Qt
       
    19 #include <HbApplication>
       
    20 #include <HbActivityManager>
       
    21 #include <hbapplication.h>
       
    22 #include <hbmessagebox.h>
       
    23 
       
    24 // symbian
       
    25 #include <centralrepository.h>
       
    26 #include <coreapplicationuissdkcrkeys.h>
       
    27 
       
    28 #include "satappmainhandler.h"
       
    29 #include "satappserverdispatcher.h"
       
    30 #include "satappmenuprovider.h"
       
    31 #include "satappinputprovider.h"
       
    32 #include "satapptoneprovider.h"
       
    33 #include "satapppopupprovider.h"
       
    34 #include "satappconstant.h"
       
    35 #include "satappconfirmprovider.h"
       
    36 
       
    37 // Activity ID for Sat Application
       
    38 const char *SATAPP_ACTIVITY_ID = "SIMServicesList";
       
    39 
       
    40 // ======== MEMBER FUNCTIONS ==================================================
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // SatAppMainHandler::SatAppMainHandler
       
    44 // (Construtor).
       
    45 // ----------------------------------------------------------------------------
       
    46 //
       
    47 SatAppMainHandler::SatAppMainHandler(HbMainWindow &window, 
       
    48     QObject */*parent*/):
       
    49 mOfflineWarningDlg(NULL)
       
    50 {
       
    51     qDebug("SATAPP: SatAppMainHandler::SatAppMainHandler >");
       
    52 
       
    53     if(!isOffline()){
       
    54         mServer = new SatAppServerDispatcher(this);
       
    55         mMenu = new SatAppMenuProvider(&window, this);
       
    56         mInput = new SatAppInputProvider(this);
       
    57         mTone = new SatAppToneProvider(this);
       
    58         mPopup = new SatAppPopupProvider(this);
       
    59         mConfirm = new SatAppConfirmProvider(this);
       
    60         initConnections();
       
    61     }
       
    62     else{
       
    63         showOfflineWarning();
       
    64     }
       
    65     removeActivity();
       
    66     
       
    67     qDebug("SATAPP: SatAppMainHandler::SatAppMainHandler <");
       
    68 }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // SatAppMainHandler::~SatAppMainHandler
       
    72 // (Destructor).
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 SatAppMainHandler::~SatAppMainHandler()
       
    76 {
       
    77     qDebug("SATAPP: SatAppMainHandler::~SatAppMainHandler >");
       
    78     delete mOfflineWarningDlg;
       
    79     qDebug("SATAPP: SatAppMainHandler::~SatAppMainHandler <");
       
    80 }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // Local override for connect-function
       
    84 // this method ENSURES that the connection is succesful.
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 void doConnect(
       
    88     const QObject *sender,
       
    89     const char *signal,
       
    90     const QObject *receiver,
       
    91     const char *member)
       
    92 {
       
    93     bool ret = QObject::connect(sender, signal,
       
    94                 receiver, member, Qt::DirectConnection);
       
    95     Q_ASSERT_X(ret, "doConnect: connection failed for: ", signal);
       
    96 }
       
    97 
       
    98 // ----------------------------------------------------------------------------
       
    99 // SatAppMainHandler::initConnections
       
   100 // 
       
   101 // ----------------------------------------------------------------------------
       
   102 //
       
   103 void SatAppMainHandler::initConnections()
       
   104 {
       
   105     qDebug("SATAPP: SatAppMainHandler::initConnections >");
       
   106 
       
   107     // --------------------------------------
       
   108     // MenuProvider
       
   109     // --------------------------------------
       
   110 
       
   111     // SetupMenu command from server
       
   112     doConnect(
       
   113         mServer, SIGNAL( setUpMenu( SatAppAction &) ),
       
   114         mMenu, SLOT( setUpMenu( SatAppAction &) ) );
       
   115     
       
   116     // SelectItem command from server
       
   117     doConnect(
       
   118         mServer, SIGNAL( selectItem( SatAppAction &) ),
       
   119         mMenu, SLOT( selectItem( SatAppAction &) ) );
       
   120 
       
   121     // --------------------------------------
       
   122     // InputProvider
       
   123     // --------------------------------------
       
   124 
       
   125     // GetInkey command    
       
   126     doConnect(
       
   127         mServer, SIGNAL( getInkey( SatAppAction &) ),
       
   128         mInput, SLOT( getInkey( SatAppAction &) ) );
       
   129     // GetInput command
       
   130     doConnect(
       
   131         mServer, SIGNAL( getInput( SatAppAction &) ),
       
   132         mInput, SLOT( getInput( SatAppAction &) ) );
       
   133 
       
   134     // clearScreen in InputProvider
       
   135     doConnect(
       
   136         mServer, SIGNAL( clearScreen() ),
       
   137         mInput, SLOT( resetState() ));
       
   138  
       
   139     // --------------------------------------
       
   140     // Play tone
       
   141     // --------------------------------------
       
   142     // Play tone 
       
   143     doConnect(
       
   144         mServer, SIGNAL( playTone( SatAppAction &) ),
       
   145         mTone, SLOT( playTone( SatAppAction &) ) );
       
   146 
       
   147     // clearScreen in tone provider
       
   148     doConnect(
       
   149         mServer, SIGNAL( clearScreen() ),
       
   150         mTone, SLOT( clearScreen() ) );
       
   151 
       
   152     // --------------------------------------
       
   153     // Show Popups
       
   154     // --------------------------------------
       
   155 
       
   156     // display text
       
   157     doConnect(
       
   158         mServer, SIGNAL(displayText( SatAppAction & )),
       
   159         mPopup, SLOT(displayText( SatAppAction & )));
       
   160 
       
   161     // show notification
       
   162     doConnect(
       
   163         mServer, SIGNAL( notification( SatAppAction & ) ),
       
   164         mPopup, SLOT( notification( SatAppAction & ) ) );
       
   165 
       
   166     // hide wait note
       
   167     doConnect(
       
   168         mServer, SIGNAL( stopShowWaitNote() ),
       
   169         mPopup, SLOT( stopShowWaitNote() ) );
       
   170 
       
   171     // clearScreen in popup note provider
       
   172     doConnect(
       
   173         mServer, SIGNAL(clearScreen()),
       
   174         mPopup, SLOT(clearScreen()));
       
   175     
       
   176     // clearScreen in popup note provider
       
   177     doConnect(
       
   178         mServer, SIGNAL(showSsErrorNote()),
       
   179         mPopup, SLOT(showSsErrorNote()));    
       
   180 
       
   181     // --------------------------------------
       
   182     // Show Confirm
       
   183     // --------------------------------------
       
   184 
       
   185     // show confirmCommand
       
   186     doConnect(
       
   187         mServer, SIGNAL( confirmCommand( SatAppAction & ) ),
       
   188         mConfirm, SLOT( confirmCommand( SatAppAction & ) ) );
       
   189 
       
   190     // clearScreen
       
   191     doConnect(
       
   192         mServer, SIGNAL( clearScreen() ),
       
   193         mConfirm, SLOT( clearScreen() ) );
       
   194 
       
   195     // Task switcher
       
   196     doConnect(
       
   197         mServer, SIGNAL( setUpMenu( SatAppAction & ) ),
       
   198         this, SLOT( updateActivity() ) );
       
   199 
       
   200     doConnect(
       
   201         qApp, SIGNAL( aboutToQuit() ),
       
   202         this, SLOT( saveActivity() ) );
       
   203 
       
   204     qDebug("SATAPP: SatAppMainHandler::initConnections <");
       
   205 }
       
   206 
       
   207 // ----------------------------------------------------------------------------
       
   208 // SatAppMainHandler::updateActivity
       
   209 // ----------------------------------------------------------------------------
       
   210 //
       
   211 void SatAppMainHandler::updateActivity()
       
   212 {
       
   213     qDebug("SATAPP: SatAppMainHandler::updateActivity >");
       
   214     mActivity.insert("screenshot", mMenu->takeScreenShot());
       
   215     qDebug("SATAPP: SatAppMainHandler::updateActivity <");
       
   216 }
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 // SatAppMainHandler::saveActivity
       
   220 // ----------------------------------------------------------------------------
       
   221 //
       
   222 void SatAppMainHandler::saveActivity()
       
   223 {
       
   224     qDebug("SATAPP: SatAppMainHandler::saveActivity >");
       
   225 
       
   226     // Add the activity to the activity manager
       
   227     const bool ok = qobject_cast<HbApplication*>(qApp)->activityManager()->
       
   228         addActivity(SATAPP_ACTIVITY_ID, QVariant(), mActivity);
       
   229     
       
   230     qDebug("SATAPP: SatAppMainHandler::saveActivity < %d", ok);
       
   231 }
       
   232 
       
   233 // ----------------------------------------------------------------------------
       
   234 // SatAppMainHandler::removeActivity
       
   235 // ----------------------------------------------------------------------------
       
   236 //
       
   237 void SatAppMainHandler::removeActivity()
       
   238 {
       
   239     qDebug("SATAPP: SatAppMainHandler::removeActivity >");
       
   240         
       
   241     QList<QVariantHash> activityList = 
       
   242         qobject_cast<HbApplication*>(qApp)->activityManager()->activities();
       
   243     qDebug("SATAPP: SatAppMenuProvider::removeActivity count=%d",
       
   244         activityList.count());
       
   245     foreach (QVariantHash activity, activityList){
       
   246         if (activity.keys().contains(SATAPP_ACTIVITY_ID)){
       
   247             mActivity = activity;
       
   248             qDebug("SATAPP: SatAppMenuProvider::removeActivity store");
       
   249             break;
       
   250         }
       
   251     }    
       
   252 
       
   253     const bool ok = qobject_cast<HbApplication*>(qApp)->activityManager()->
       
   254         removeActivity(SATAPP_ACTIVITY_ID);
       
   255     
       
   256     qDebug("SATAPP: SatAppMainHandler::removeActivity < %d", ok);
       
   257 }
       
   258 
       
   259 // ----------------------------------------------------------------------------
       
   260 // SatAppMainHandler::isOffline
       
   261 // ----------------------------------------------------------------------------
       
   262 //
       
   263 bool SatAppMainHandler::isOffline()
       
   264 {
       
   265     //If current active profile is offline, show a warning and quit
       
   266     qDebug("SATAPP: SatAppMainHandler::isOffline >");
       
   267     TInt profileId(0);
       
   268     CRepository* cr (NULL);
       
   269     TRAPD(err, cr = CRepository::NewL(KCRUidCoreApplicationUIs));
       
   270     if ( KErrNone == err )
       
   271     {
       
   272         // Get the ID of the currently active profile:
       
   273         const TInt error = 
       
   274             cr->Get(KCoreAppUIsNetworkConnectionAllowed, profileId);
       
   275         qDebug("SATAPP: SatAppMainHandler::isOffline get active \
       
   276                 profile error=%d",error);
       
   277         delete cr;
       
   278     }
       
   279     qDebug("SATAPP: SatAppMainHandler::isOffline< profileId = %d",profileId);
       
   280     return ( ECoreAppUIsNetworkConnectionNotAllowed == profileId );
       
   281 }
       
   282 
       
   283 // ----------------------------------------------------------------------------
       
   284 // SatAppMainHandler::showOfflineWarning
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 void SatAppMainHandler::showOfflineWarning()
       
   288 {
       
   289     qDebug("SATAPP: SatAppMainHandler::showOfflineWarning >");
       
   290     mOfflineWarningDlg = 
       
   291         new HbMessageBox(HbMessageBox::MessageTypeWarning);
       
   292     mOfflineWarningDlg->setText(
       
   293         hbTrId("txt_simatk_dpopinfo_sim_services_not_available"));
       
   294     mOfflineWarningDlg->clearActions();
       
   295     mOfflineWarningDlg->setDismissPolicy(HbDialog::TapOutside);
       
   296     mOfflineWarningDlg->setTimeout(KDisplayTxtUserClearTimeout);
       
   297     SAT_ASSERT(connect(mOfflineWarningDlg, SIGNAL(aboutToClose()),
       
   298                 qApp, SLOT(quit())));
       
   299     mOfflineWarningDlg->open();
       
   300     qDebug("SATAPP: SatAppMainHandler::showOfflineWarning <");
       
   301 }
       
   302 
       
   303 //End of file