videocollection/videocollectionview/src/videooperatorservice.cpp
author hgs
Thu, 08 Jul 2010 13:05:19 +0300
changeset 44 518105d52e45
child 50 21fe8338c6bf
permissions -rw-r--r--
201027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:   VideoOperatorService class implementation.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
// Version : 
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
// INCLUDE FILES
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include <qdesktopservices.h>
hgs
parents:
diff changeset
    23
#include <qurl.h>
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
#include <e32base.h>
hgs
parents:
diff changeset
    26
#include <eikenv.h>
hgs
parents:
diff changeset
    27
#include <eikappui.h>
hgs
parents:
diff changeset
    28
#include <apgcli.h>
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
#include "videooperatorservice.h"
hgs
parents:
diff changeset
    31
#include "videocollectionviewutils.h"
hgs
parents:
diff changeset
    32
#include "videocollectioncenrepdefs.h"
hgs
parents:
diff changeset
    33
#include "videocollectiontrace.h"
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    36
// Constructor
hgs
parents:
diff changeset
    37
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    38
//
hgs
parents:
diff changeset
    39
VideoOperatorService::VideoOperatorService(QObject *parent) : 
hgs
parents:
diff changeset
    40
    QObject(parent)
hgs
parents:
diff changeset
    41
{
hgs
parents:
diff changeset
    42
    FUNC_LOG;
hgs
parents:
diff changeset
    43
}
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    46
// load
hgs
parents:
diff changeset
    47
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    48
//
hgs
parents:
diff changeset
    49
bool VideoOperatorService::load(int titleKey, int iconKey, int serviceUriKey, int appUidKey)
hgs
parents:
diff changeset
    50
{
hgs
parents:
diff changeset
    51
    FUNC_LOG;
hgs
parents:
diff changeset
    52
    VideoCollectionViewUtils& utils = VideoCollectionViewUtils::instance();
hgs
parents:
diff changeset
    53
    
hgs
parents:
diff changeset
    54
    mTitle = utils.getCenRepStringValue(titleKey);
hgs
parents:
diff changeset
    55
    mIconResource = utils.getCenRepStringValue(iconKey);
hgs
parents:
diff changeset
    56
    mServiceUri = utils.getCenRepStringValue(serviceUriKey);
hgs
parents:
diff changeset
    57
    mApplicationUid = utils.getCenRepIntValue(appUidKey);
hgs
parents:
diff changeset
    58
    
hgs
parents:
diff changeset
    59
    // Icon is required, either service uri or application uid is required.
hgs
parents:
diff changeset
    60
    if(mIconResource.isEmpty() && (mServiceUri.isEmpty() || mApplicationUid > 0))
hgs
parents:
diff changeset
    61
    {
hgs
parents:
diff changeset
    62
        return false;
hgs
parents:
diff changeset
    63
    }
hgs
parents:
diff changeset
    64
    
hgs
parents:
diff changeset
    65
    return true;
hgs
parents:
diff changeset
    66
}
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
// title
hgs
parents:
diff changeset
    70
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    71
//
hgs
parents:
diff changeset
    72
const QString VideoOperatorService::title() const
hgs
parents:
diff changeset
    73
{
hgs
parents:
diff changeset
    74
    return mTitle;
hgs
parents:
diff changeset
    75
}
hgs
parents:
diff changeset
    76
hgs
parents:
diff changeset
    77
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    78
// iconResource
hgs
parents:
diff changeset
    79
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    80
//
hgs
parents:
diff changeset
    81
const QString VideoOperatorService::iconResource() const
hgs
parents:
diff changeset
    82
{
hgs
parents:
diff changeset
    83
    return mIconResource;
hgs
parents:
diff changeset
    84
}
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    87
// launchService
hgs
parents:
diff changeset
    88
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    89
//
hgs
parents:
diff changeset
    90
void VideoOperatorService::launchService()
hgs
parents:
diff changeset
    91
{
hgs
parents:
diff changeset
    92
    FUNC_LOG;
hgs
parents:
diff changeset
    93
    
hgs
parents:
diff changeset
    94
    if(!mServiceUri.isEmpty())
hgs
parents:
diff changeset
    95
    {
hgs
parents:
diff changeset
    96
        INFO_1("VideoOperatorService::launchService() starting url: %S", mServiceUri);
hgs
parents:
diff changeset
    97
        QDesktopServices::openUrl(QUrl(mServiceUri));
hgs
parents:
diff changeset
    98
    }
hgs
parents:
diff changeset
    99
    else
hgs
parents:
diff changeset
   100
    {
hgs
parents:
diff changeset
   101
        INFO_1("VideoOperatorService::launchService() starting application 0x%x", mApplicationUid);
hgs
parents:
diff changeset
   102
        TRAP_IGNORE(launchApplicationL(TUid::Uid(mApplicationUid), 0));
hgs
parents:
diff changeset
   103
    }
hgs
parents:
diff changeset
   104
}
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   107
// launchApplicationL
hgs
parents:
diff changeset
   108
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   109
//
hgs
parents:
diff changeset
   110
void VideoOperatorService::launchApplicationL(const TUid uid, TInt viewId)
hgs
parents:
diff changeset
   111
{
hgs
parents:
diff changeset
   112
    CEikonEnv *eikEnv = CEikonEnv::Static();
hgs
parents:
diff changeset
   113
    
hgs
parents:
diff changeset
   114
    if (viewId > 0 && eikEnv) {
hgs
parents:
diff changeset
   115
        TVwsViewId view(uid, TUid::Uid(viewId));
hgs
parents:
diff changeset
   116
        eikEnv->EikAppUi()->ActivateViewL(view);
hgs
parents:
diff changeset
   117
    } else 
hgs
parents:
diff changeset
   118
    {
hgs
parents:
diff changeset
   119
        RWsSession wsSession;
hgs
parents:
diff changeset
   120
        User::LeaveIfError(wsSession.Connect());
hgs
parents:
diff changeset
   121
        CleanupClosePushL<RWsSession>(wsSession);
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
        // TApaAppInfo size is greater then 1024 bytes
hgs
parents:
diff changeset
   124
        // so its instances should not be created on the stack.
hgs
parents:
diff changeset
   125
        TApaAppInfo* appInfo = new (ELeave) TApaAppInfo;
hgs
parents:
diff changeset
   126
        CleanupStack::PushL(appInfo);
hgs
parents:
diff changeset
   127
        TApaAppCapabilityBuf capabilityBuf;
hgs
parents:
diff changeset
   128
        RApaLsSession appArcSession;
hgs
parents:
diff changeset
   129
        User::LeaveIfError(appArcSession.Connect());
hgs
parents:
diff changeset
   130
        CleanupClosePushL<RApaLsSession>(appArcSession);
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
        User::LeaveIfError(appArcSession.GetAppInfo(*appInfo, uid));
hgs
parents:
diff changeset
   133
        User::LeaveIfError(appArcSession.GetAppCapability(
hgs
parents:
diff changeset
   134
           capabilityBuf, uid));
hgs
parents:
diff changeset
   135
hgs
parents:
diff changeset
   136
        TApaAppCapability &caps = capabilityBuf();
hgs
parents:
diff changeset
   137
        CApaCommandLine *cmdLine = CApaCommandLine::NewLC();
hgs
parents:
diff changeset
   138
        cmdLine->SetExecutableNameL(appInfo->iFullName);
hgs
parents:
diff changeset
   139
hgs
parents:
diff changeset
   140
        if (caps.iLaunchInBackground) {
hgs
parents:
diff changeset
   141
            cmdLine->SetCommandL(EApaCommandBackground);
hgs
parents:
diff changeset
   142
        } else {
hgs
parents:
diff changeset
   143
            cmdLine->SetCommandL(EApaCommandRun);
hgs
parents:
diff changeset
   144
        }
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
        cmdLine->SetTailEndL(KNullDesC8);
hgs
parents:
diff changeset
   147
hgs
parents:
diff changeset
   148
        User::LeaveIfError(appArcSession.StartApp(*cmdLine));
hgs
parents:
diff changeset
   149
hgs
parents:
diff changeset
   150
        CleanupStack::PopAndDestroy(cmdLine);
hgs
parents:
diff changeset
   151
        CleanupStack::PopAndDestroy(&appArcSession);
hgs
parents:
diff changeset
   152
        CleanupStack::PopAndDestroy(appInfo);
hgs
parents:
diff changeset
   153
hgs
parents:
diff changeset
   154
        CleanupStack::PopAndDestroy(&wsSession);
hgs
parents:
diff changeset
   155
    }
hgs
parents:
diff changeset
   156
}
hgs
parents:
diff changeset
   157
hgs
parents:
diff changeset
   158
// End of file.