qtinternetradio/ui/src/ircontrolservice.cpp
changeset 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
11:f683e24efca3 12:608f67c22514
       
     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 
       
    18 // System includes
       
    19 #include <xqserviceutil.h>
       
    20 
       
    21 // User includes
       
    22 #include "ircontrolservice.h"
       
    23 #include "irapplication.h"
       
    24 #include "irplaycontroller.h"
       
    25 #include "irqlogger.h"
       
    26 
       
    27 // Contants
       
    28 static const QString IR_CONTROL_SERVICE_NAME = "internet_radio_10_1.com.nokia.symbian.IInternetRadioControl";
       
    29 
       
    30 // Constructor
       
    31 IrControlService::IrControlService(IRApplication *aIrApp, QObject *aParent) :
       
    32     XQServiceProvider(IR_CONTROL_SERVICE_NAME, aParent),
       
    33     mIrApp(aIrApp)
       
    34 {
       
    35     publishAll();
       
    36 }
       
    37 
       
    38 // Destructor
       
    39 IrControlService::~IrControlService()
       
    40 {
       
    41 }
       
    42 
       
    43 // service interface, called via Qt Highway
       
    44 int IrControlService::handleCmd(int aCmdId)
       
    45 {
       
    46     LOG_FORMAT( "IrControlService::handleCmd, the command is %d",  aCmdId);
       
    47     IrServiceResult::Type result = IrServiceResult::Fail;
       
    48         
       
    49     switch (aCmdId)
       
    50     {
       
    51         case IrServiceCmd::LaunchNormally:
       
    52             result = handleLaunchNormallyCmd();
       
    53             break;
       
    54                     
       
    55         case IrServiceCmd::LaunchNowPlayingView:
       
    56             result = handleLaunchNowPlayingViewCmd();
       
    57             break;
       
    58 
       
    59         case IrServiceCmd::Play:
       
    60             result = handlePlayCmd();
       
    61             break;
       
    62 
       
    63         case IrServiceCmd::Stop:
       
    64             result = handleStopCmd();
       
    65             break;
       
    66 
       
    67         case IrServiceCmd::Cancel:
       
    68             result = handleCancelCmd();
       
    69             break;
       
    70 
       
    71         case IrServiceCmd::Foreground:
       
    72             XQServiceUtil::toBackground(false);
       
    73             result = IrServiceResult::Success;
       
    74             break;
       
    75 
       
    76         default:
       
    77             break;
       
    78     }
       
    79     
       
    80     if (!requestInfo().isSynchronous())
       
    81     {
       
    82         // NOTE ! we consider the Async to be success as long as the request can be sent here
       
    83         completeRequest(setCurrentRequestAsync(), (int)result);
       
    84     }
       
    85     
       
    86     return (int)result;
       
    87 }
       
    88 
       
    89 IrServiceResult::Type IrControlService::handleLaunchNowPlayingViewCmd()
       
    90 {
       
    91     if (!mIrApp->isAppFullyStarted())
       
    92     {
       
    93         mIrApp->launchStartingView(EIRView_PlayingView);
       
    94     }
       
    95     return IrServiceResult::Success;
       
    96 }
       
    97 
       
    98 IrServiceResult::Type IrControlService::handleLaunchNormallyCmd()
       
    99 {
       
   100     if (!mIrApp->isAppFullyStarted())
       
   101     {
       
   102         mIrApp->setLaunchView();
       
   103     }
       
   104     return IrServiceResult::Success;
       
   105 }
       
   106 
       
   107 IrServiceResult::Type IrControlService::handlePlayCmd()
       
   108 {           
       
   109 #ifdef HS_WIDGET_ENABLED    
       
   110     LOG( "IrControlService::handlePlayCmd");
       
   111     bool ret = mIrApp->startPlaying();
       
   112     LOG_FORMAT( "IrControlService::handlePlayCmd, the ret is:%d",(int)ret);
       
   113     return ret?IrServiceResult::Success : IrServiceResult::Fail;    
       
   114 #else
       
   115     return IrServiceResult::Fail;
       
   116 #endif       
       
   117     
       
   118 }
       
   119 
       
   120 IrServiceResult::Type IrControlService::handleStopCmd()
       
   121 {
       
   122     if (mIrApp->getPlayController()->isPlaying())
       
   123     {
       
   124         mIrApp->getPlayController()->stop(EIRQUserTerminated);
       
   125     }
       
   126     return IrServiceResult::Success; 
       
   127 }
       
   128 
       
   129 IrServiceResult::Type IrControlService::handleCancelCmd()
       
   130 {
       
   131 #ifdef HS_WIDGET_ENABLED       
       
   132     mIrApp->cancelPlayerLoading();
       
   133 #endif     
       
   134     return IrServiceResult::Success;
       
   135 }
       
   136