videocollection/videocollectionview/src/videooperatorservice.cpp
changeset 55 4bfa887905cf
parent 50 21fe8338c6bf
equal deleted inserted replaced
50:21fe8338c6bf 55:4bfa887905cf
    17 
    17 
    18 // Version : 
    18 // Version : 
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 
    21 
    22 #include <qdesktopservices.h>
       
    23 #include <qurl.h>
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <eikenv.h>
       
    27 #include <eikappui.h>
       
    28 #include <apgcli.h>
       
    29 
       
    30 #include "videooperatorservice.h"
    22 #include "videooperatorservice.h"
    31 #include "videocollectionviewutils.h"
    23 #include "videooperatorservice_p.h"
    32 #include "videocollectioncenrepdefs.h"
       
    33 #include "videocollectiontrace.h"
    24 #include "videocollectiontrace.h"
    34 
    25 
    35 // ---------------------------------------------------------------------------
    26 // ---------------------------------------------------------------------------
    36 // Constructor
    27 // Constructor
    37 // ---------------------------------------------------------------------------
    28 // ---------------------------------------------------------------------------
    38 //
    29 //
    39 VideoOperatorService::VideoOperatorService(QObject *parent) : 
    30 VideoOperatorService::VideoOperatorService(QObject *parent) : 
    40     QObject(parent)
    31     QObject(parent), d_ptr( new VideoOperatorServicePrivate() )
    41 {
    32 {
    42     FUNC_LOG;
    33     FUNC_LOG;
       
    34 }
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // Destructor
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 VideoOperatorService::~VideoOperatorService()
       
    42 {
       
    43     FUNC_LOG;
       
    44     delete d_ptr;
    43 }
    45 }
    44 
    46 
    45 // ---------------------------------------------------------------------------
    47 // ---------------------------------------------------------------------------
    46 // load
    48 // load
    47 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    48 //
    50 //
    49 bool VideoOperatorService::load(int titleKey, int iconKey, int serviceUriKey, int appUidKey)
    51 bool VideoOperatorService::load(int titleKey, int iconKey, int serviceUriKey, int appUidKey)
    50 {
    52 {
    51     FUNC_LOG;
    53     FUNC_LOG;
    52     VideoCollectionViewUtils& utils = VideoCollectionViewUtils::instance();
    54     return d_ptr->load(titleKey, iconKey, serviceUriKey, appUidKey);
    53     
       
    54     mTitle = utils.getCenRepStringValue(titleKey);
       
    55     mIconResource = utils.getCenRepStringValue(iconKey);
       
    56     mServiceUri = utils.getCenRepStringValue(serviceUriKey);
       
    57     mApplicationUid = utils.getCenRepIntValue(appUidKey);
       
    58     
       
    59     // Icon is required, either service uri or application uid is required.
       
    60     if(mIconResource.isEmpty() || (mServiceUri.isEmpty() && mApplicationUid <= 0))
       
    61     {
       
    62         return false;
       
    63     }
       
    64     
       
    65     return true;
       
    66 }
    55 }
    67 
    56 
    68 // ---------------------------------------------------------------------------
    57 // ---------------------------------------------------------------------------
    69 // title
    58 // title
    70 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    71 //
    60 //
    72 const QString VideoOperatorService::title() const
    61 const QString VideoOperatorService::title() const
    73 {
    62 {
    74     return mTitle;
    63     return d_ptr->title();
    75 }
    64 }
    76 
    65 
    77 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    78 // iconResource
    67 // iconResource
    79 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    80 //
    69 //
    81 const QString VideoOperatorService::iconResource() const
    70 const QString VideoOperatorService::iconResource() const
    82 {
    71 {
    83     return mIconResource;
    72     return d_ptr->iconResource();
    84 }
    73 }
    85 
    74 
    86 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    87 // launchService
    76 // launchService
    88 // ---------------------------------------------------------------------------
    77 // ---------------------------------------------------------------------------
    89 //
    78 //
    90 void VideoOperatorService::launchService()
    79 void VideoOperatorService::launchService()
    91 {
    80 {
    92     FUNC_LOG;
    81     FUNC_LOG;
    93     
    82     d_ptr->launchService();
    94     if(!mServiceUri.isEmpty())
       
    95     {
       
    96         INFOQSTR_1("VideoOperatorService::launchService() starting url: %S", mServiceUri);
       
    97         QDesktopServices::openUrl(QUrl(mServiceUri));
       
    98     }
       
    99     else
       
   100     {
       
   101         INFO_1("VideoOperatorService::launchService() starting application 0x%x", mApplicationUid);
       
   102         TRAP_IGNORE(launchApplicationL(TUid::Uid(mApplicationUid), 0));
       
   103     }
       
   104 }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // launchApplicationL
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void VideoOperatorService::launchApplicationL(const TUid uid, TInt viewId)
       
   111 {
       
   112     CEikonEnv *eikEnv = CEikonEnv::Static();
       
   113     
       
   114     if (viewId > 0 && eikEnv) {
       
   115         TVwsViewId view(uid, TUid::Uid(viewId));
       
   116         eikEnv->EikAppUi()->ActivateViewL(view);
       
   117     } else 
       
   118     {
       
   119         RWsSession wsSession;
       
   120         User::LeaveIfError(wsSession.Connect());
       
   121         CleanupClosePushL<RWsSession>(wsSession);
       
   122 
       
   123         // TApaAppInfo size is greater then 1024 bytes
       
   124         // so its instances should not be created on the stack.
       
   125         TApaAppInfo* appInfo = new (ELeave) TApaAppInfo;
       
   126         CleanupStack::PushL(appInfo);
       
   127         TApaAppCapabilityBuf capabilityBuf;
       
   128         RApaLsSession appArcSession;
       
   129         User::LeaveIfError(appArcSession.Connect());
       
   130         CleanupClosePushL<RApaLsSession>(appArcSession);
       
   131 
       
   132         User::LeaveIfError(appArcSession.GetAppInfo(*appInfo, uid));
       
   133         User::LeaveIfError(appArcSession.GetAppCapability(
       
   134            capabilityBuf, uid));
       
   135 
       
   136         TApaAppCapability &caps = capabilityBuf();
       
   137         CApaCommandLine *cmdLine = CApaCommandLine::NewLC();
       
   138         cmdLine->SetExecutableNameL(appInfo->iFullName);
       
   139 
       
   140         if (caps.iLaunchInBackground) {
       
   141             cmdLine->SetCommandL(EApaCommandBackground);
       
   142         } else {
       
   143             cmdLine->SetCommandL(EApaCommandRun);
       
   144         }
       
   145 
       
   146         cmdLine->SetTailEndL(KNullDesC8);
       
   147 
       
   148         User::LeaveIfError(appArcSession.StartApp(*cmdLine));
       
   149 
       
   150         CleanupStack::PopAndDestroy(cmdLine);
       
   151         CleanupStack::PopAndDestroy(&appArcSession);
       
   152         CleanupStack::PopAndDestroy(appInfo);
       
   153 
       
   154         CleanupStack::PopAndDestroy(&wsSession);
       
   155     }
       
   156 }
    83 }
   157 
    84 
   158 // End of file.
    85 // End of file.