videocollection/videocollectionview/src/videooperatorservice_p.cpp
changeset 55 4bfa887905cf
child 67 72c709219fcd
equal deleted inserted replaced
50:21fe8338c6bf 55:4bfa887905cf
       
     1 /*
       
     2 * Copyright (c) 2008 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:   VideoOperatorServicePrivate class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "videooperatorservice_p.h"
       
    22 #include "videocollectionviewutils.h"
       
    23 #include "videocollectioncenrepdefs.h"
       
    24 #include "videocollectiontrace.h"
       
    25 
       
    26 #include <qdesktopservices.h>
       
    27 #include <qurl.h>
       
    28 #include <e32base.h>
       
    29 #include <coemain.h>
       
    30 #include <apgcli.h>
       
    31 #include <apaid.h>
       
    32 #include <apgtask.h>
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Constructor
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 VideoOperatorServicePrivate::VideoOperatorServicePrivate() :
       
    39     mProcess(0)
       
    40 {
       
    41     
       
    42 }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Destructor
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 VideoOperatorServicePrivate::~VideoOperatorServicePrivate()
       
    49 {   
       
    50     if(mProcess)
       
    51     {
       
    52         disconnect(mProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
       
    53                 this, SLOT(processFinished(int, QProcess::ExitStatus)));
       
    54         
       
    55         disconnect(mProcess, SIGNAL(error(QProcess::ProcessError)), 
       
    56                 this, SLOT(processError(QProcess::ProcessError)));        
       
    57         mProcess->close();
       
    58     }
       
    59     delete mProcess;
       
    60 }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // load
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 bool VideoOperatorServicePrivate::load(int titleKey, int iconKey, int serviceUriKey, int appUidKey)
       
    67 {
       
    68     FUNC_LOG;
       
    69     VideoCollectionViewUtils& utils = VideoCollectionViewUtils::instance();
       
    70     
       
    71     mTitle = utils.getCenRepStringValue(titleKey);
       
    72     mIconResource = utils.getCenRepStringValue(iconKey);
       
    73     mServiceUri = utils.getCenRepStringValue(serviceUriKey);
       
    74     mApplicationUid = utils.getCenRepIntValue(appUidKey);
       
    75     
       
    76     // Icon is required, either service uri or application uid is required.
       
    77     if(mIconResource.isEmpty() || (mServiceUri.isEmpty() && mApplicationUid <= 0))
       
    78     {
       
    79         return false;
       
    80     }
       
    81     
       
    82     return true;
       
    83 }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // title
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 const QString VideoOperatorServicePrivate::title() const
       
    90 {
       
    91     return mTitle;
       
    92 }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // iconResource
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 const QString VideoOperatorServicePrivate::iconResource() const
       
    99 {
       
   100     return mIconResource;
       
   101 }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // launchService
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void VideoOperatorServicePrivate::launchService()
       
   108 {
       
   109     FUNC_LOG;
       
   110     
       
   111     if(!mServiceUri.isEmpty())
       
   112     {
       
   113         INFOQSTR_1("VideoOperatorServicePrivate::launchService() starting url: %S", mServiceUri);
       
   114         QDesktopServices::openUrl(QUrl(mServiceUri));
       
   115     }
       
   116     else
       
   117     {
       
   118         INFO_1("VideoOperatorServicePrivate::launchService() starting application 0x%x", mApplicationUid);
       
   119         TRAPD(err, startApplicationL(TUid::Uid(mApplicationUid)));
       
   120         if(err)
       
   121         {
       
   122             INFO_1("VideoOperatorServicePrivate::launchService() failed to start, error: %d", err);
       
   123         }
       
   124     }
       
   125 }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // getApplicationFilenameL
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 QString VideoOperatorServicePrivate::getApplicationFilenameL(const TUid uid)
       
   132 {
       
   133     FUNC_LOG;
       
   134 
       
   135     // TApaAppInfo size is greater then 1024 bytes
       
   136     // so its instances should not be created on the stack.
       
   137     TApaAppInfo* appInfo = new (ELeave) TApaAppInfo;
       
   138     CleanupStack::PushL(appInfo);
       
   139     RApaLsSession appArcSession;
       
   140     User::LeaveIfError(appArcSession.Connect());
       
   141     CleanupClosePushL<RApaLsSession>(appArcSession);
       
   142 
       
   143     User::LeaveIfError(appArcSession.GetAppInfo(*appInfo, uid));
       
   144 
       
   145     QString fullName((QChar*)appInfo->iFullName.Ptr(), appInfo->iFullName.Length()); 
       
   146     
       
   147     CleanupStack::PopAndDestroy(&appArcSession);
       
   148     CleanupStack::PopAndDestroy(appInfo);
       
   149     
       
   150     return fullName;
       
   151 }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // bringApplicationToForeground
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 bool VideoOperatorServicePrivate::bringApplicationToForeground(const TUid uid)
       
   158 {
       
   159     FUNC_LOG;
       
   160     
       
   161     CCoeEnv* coe = CCoeEnv::Static();
       
   162     bool ret = false;
       
   163     if(coe)
       
   164     {
       
   165         TApaTaskList taskList(coe->WsSession());
       
   166         TApaTask task(taskList.FindApp(uid));
       
   167         
       
   168         if(task.Exists())
       
   169         {
       
   170             INFO("VideoOperatorServicePrivate::processFinished() task found.");
       
   171             task.BringToForeground();
       
   172             ret = true;
       
   173         }
       
   174     }
       
   175     return ret;
       
   176 }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // startApplicationL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void VideoOperatorServicePrivate::startApplicationL(const TUid uid)
       
   183 {
       
   184     FUNC_LOG;
       
   185     
       
   186     // Process handle already exists, try to bring app to foreground.
       
   187     if(mProcess)
       
   188     {
       
   189         if(bringApplicationToForeground(uid))
       
   190         {
       
   191             // App brought to foreground, all done.
       
   192             return;
       
   193         }
       
   194         // Application is not running, cleanup previous process.
       
   195         disconnect(mProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
       
   196                 this, SLOT(processFinished(int, QProcess::ExitStatus)));
       
   197         
       
   198         disconnect(mProcess, SIGNAL(error(QProcess::ProcessError)), 
       
   199                 this, SLOT(processError(QProcess::ProcessError)));
       
   200 
       
   201         delete mProcess;
       
   202         mProcess = 0;
       
   203     }
       
   204     
       
   205     // Create new process and start it.
       
   206     mProcess = new QProcess();
       
   207 
       
   208     if(!connect(mProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
       
   209             this, SLOT(processFinished(int, QProcess::ExitStatus)), Qt::UniqueConnection) ||
       
   210        !connect(mProcess, SIGNAL(error(QProcess::ProcessError)), 
       
   211             this, SLOT(processError(QProcess::ProcessError)), Qt::UniqueConnection))
       
   212     {
       
   213         INFO("VideoOperatorServicePrivate::startApplicationL() failed to connect signals");
       
   214         User::Leave(KErrGeneral);
       
   215     }
       
   216 
       
   217     QString appName = getApplicationFilenameL(uid);
       
   218     if(!appName.isEmpty())
       
   219     {
       
   220         mProcess->start(appName);
       
   221     }
       
   222 }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // processFinished
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void VideoOperatorServicePrivate::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
       
   229 {
       
   230     Q_UNUSED(exitCode);
       
   231     Q_UNUSED(exitStatus);
       
   232     INFO_2("VideoOperatorServicePrivate::processFinished() code: %d, status: %d", exitCode, exitStatus);
       
   233 }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // processError
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void VideoOperatorServicePrivate::processError(QProcess::ProcessError error)
       
   240 {
       
   241     Q_UNUSED(error);
       
   242     INFO_1("VideoOperatorServicePrivate::processError() error: %d", error);
       
   243 }
       
   244 
       
   245 // End of file.