homesync/contentmanager/mediaservant/plugin/src/mediaservantplugin.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     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:  CMediaservantPlugin class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <w32std.h>
       
    21 #include <fbs.h>
       
    22 #include <StringLoader.h>
       
    23 #include <mediaservant.mbg>
       
    24 #include <mediaservant.rsg>
       
    25 #include <bautils.h>
       
    26 #include <eikenv.h>
       
    27 #include <apgcli.h>
       
    28 #include <AknsUtils.h>
       
    29 #include <AknUtils.h>
       
    30 #include <pathinfo.h>
       
    31 
       
    32 #include "msengine.h"
       
    33 #include "mediaservantplugin.h"
       
    34 #include "msconstants.h"
       
    35 #include "mediaservantuid.h"
       
    36 
       
    37 #include "msdebug.h"
       
    38 
       
    39 // CONSTANTS
       
    40 _LIT( KMediaservantRscFile, "\\resource\\apps\\mediaservant.rsc" );
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CMediaservantPlugin::NewL
       
    44 // Create instance of concrete ECOM interface implementation
       
    45 // ---------------------------------------------------------------------------
       
    46 CMediaservantPlugin* CMediaservantPlugin::NewL(
       
    47     MUPnPPluginObserver* aPluginObserver)
       
    48     {
       
    49     CMediaservantPlugin* self = CMediaservantPlugin::NewLC (aPluginObserver);
       
    50     CleanupStack::Pop( self );
       
    51     
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CMediaservantPlugin::NewLC
       
    57 // Create instance of concrete ECOM interface implementation
       
    58 // ---------------------------------------------------------------------------
       
    59 CMediaservantPlugin* CMediaservantPlugin::NewLC(
       
    60     MUPnPPluginObserver* aPluginObserver)
       
    61     {
       
    62     CMediaservantPlugin* self = new(ELeave)
       
    63                               CMediaservantPlugin(aPluginObserver);
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL( aPluginObserver );
       
    66 
       
    67     return self;
       
    68     }
       
    69     
       
    70 // ---------------------------------------------------------------------------
       
    71 // CMediaservantPlugin::ConstructL
       
    72 // Second phase constructor. Creates icon and sets title and secondary text
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CMediaservantPlugin::ConstructL(MUPnPPluginObserver*
       
    76                                                 aPluginObserver)
       
    77     {
       
    78     LOG(_L("[MediaServant]\t CMediaservantPlugin::ConstructL start"));
       
    79 
       
    80     // Set observer
       
    81     iPluginObserver = aPluginObserver;
       
    82 
       
    83     // set icon
       
    84     LOG(_L("[MediaServant]\t CMediaservantPlugin::ConstructL create icon"));
       
    85     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
    86 
       
    87     CFbsBitmap* bitmap = NULL;
       
    88     CFbsBitmap* mask = NULL;
       
    89 
       
    90     AknsUtils::CreateIconLC(skin, KAknsIIDDefault,
       
    91                             bitmap, mask, KMSMifFileName,
       
    92                             EMbmMediaservantQgn_mserv_app_menu_icon,
       
    93                             EMbmMediaservantQgn_mserv_app_menu_icon_mask);
       
    94 
       
    95     iIcon = CGulIcon::NewL(bitmap,mask);
       
    96     iIcon->SetBitmapsOwnedExternally(EFalse);
       
    97 
       
    98     CleanupStack::Pop( mask );
       
    99     CleanupStack::Pop( bitmap );
       
   100     bitmap = NULL;
       
   101     mask = NULL;
       
   102 
       
   103 
       
   104 
       
   105     // Load resource file
       
   106     LOG(_L("[MediaServant]\t CMediaservantPlugin::ConstructL load resource"));
       
   107     TFileName rscFileName( KMediaservantRscFile );
       
   108  
       
   109     iCoeEnv = CEikonEnv::Static();
       
   110     RFs& fileSession = iCoeEnv->FsSession();
       
   111 
       
   112     // Get the exact filename of the resource file
       
   113     BaflUtils::NearestLanguageFile( fileSession, rscFileName );
       
   114         
       
   115     // this works for c and z drives
       
   116     TInt err(KErrNone);
       
   117     TRAP( err, iResFileOffset = iCoeEnv->AddResourceFileL( rscFileName ))
       
   118     if ( err != KErrNone )
       
   119         {
       
   120         // not found? let's try mmc drive
       
   121         rscFileName.Copy( PathInfo::MemoryCardRootPath() );
       
   122         rscFileName.Delete(2, 2); // remove //
       
   123         rscFileName.Append( KMediaservantRscFile );
       
   124         iResFileOffset = iCoeEnv->AddResourceFileL( rscFileName );
       
   125         }
       
   126 
       
   127     LOG(_L("[MediaServant]\t CMediaServantPlugin::ConstructL \
       
   128     after resourceloader"));
       
   129 
       
   130     // Set item text
       
   131     iTitle = StringLoader::LoadL( R_MS_PLUGIN_LISTBOX_PRIMARY_TEXT );
       
   132 
       
   133     iMSEngine = CMSEngine::NewL();
       
   134 
       
   135     // load secondary text
       
   136     LoadPluginTextL();
       
   137 
       
   138     // Create property watcher for progress info
       
   139     iMSPropertyWatcher = CMSPropertyWatcher::NewL();
       
   140     // view will observe changes in property
       
   141     iMSPropertyWatcher->SetObserver(this);
       
   142     // start listening property
       
   143     iMSPropertyWatcher->StartL();
       
   144 
       
   145     LOG(_L("[MediaServant]\t CMediaservantPlugin::ConstructL end"));
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // Default constructor.
       
   150 // ---------------------------------------------------------------------------
       
   151 CMediaservantPlugin::CMediaservantPlugin(TAny* aEcomArguments)
       
   152    : CUPnPPluginInterface( aEcomArguments )
       
   153     {
       
   154     iRequiresUpnpConf = ETrue;
       
   155     iTitle = NULL;
       
   156     iSecondaryText = NULL;
       
   157     }
       
   158 
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CMediaservantPlugin::~CMediaservantPlugin
       
   162 // ---------------------------------------------------------------------------
       
   163 CMediaservantPlugin::~CMediaservantPlugin()
       
   164     {
       
   165     LOG(_L("[MediaServant]\t CMediaservantPlugin::~CMediaservantPlugin"));
       
   166 
       
   167     delete iMSEngine;
       
   168 
       
   169     // Un-Load resource file
       
   170     if ( iResFileOffset )
       
   171         {
       
   172         iCoeEnv->DeleteResourceFile( iResFileOffset );
       
   173         iResFileOffset = 0;
       
   174         }
       
   175 
       
   176     if ( iMSPropertyWatcher )
       
   177         {
       
   178         iMSPropertyWatcher->Stop();
       
   179         delete iMSPropertyWatcher;
       
   180         }
       
   181     delete iIcon;
       
   182     delete iTitle;
       
   183     delete iSecondaryText;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CMediaservantPlugin::GetIcon
       
   188 // Returns reference to the icon of the plugin
       
   189 // ---------------------------------------------------------------------------
       
   190 const CGulIcon& CMediaservantPlugin::GetIcon()
       
   191     {
       
   192     return *iIcon;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CMediaservantPlugin::GetTitle
       
   197 // Returns const reference to the icon of the plugin
       
   198 // ---------------------------------------------------------------------------
       
   199 const TDesC& CMediaservantPlugin::GetTitle()
       
   200     {
       
   201     return *iTitle;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CMediaservantPlugin::GetSecondaryText
       
   206 // Returns const reference to the scondary text of the plugin
       
   207 // ---------------------------------------------------------------------------
       
   208 const TDesC& CMediaservantPlugin::GetSecondaryText()
       
   209     {
       
   210     return *iSecondaryText;
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CMediaservantPlugin::ExecuteL
       
   215 // Executes the plugin
       
   216 // ---------------------------------------------------------------------------
       
   217 void CMediaservantPlugin::ExecuteL()
       
   218     {
       
   219     LOG(_L("[MediaServant]\t CMediaservantPlugin::ExecuteL"));
       
   220 
       
   221     RApaLsSession apaLsSession;
       
   222     User::LeaveIfError(apaLsSession.Connect());
       
   223     CleanupClosePushL(apaLsSession);
       
   224 
       
   225     TApaAppInfo applicationInfo;
       
   226     TInt error = apaLsSession.GetAppInfo(
       
   227                                     applicationInfo,
       
   228                                     TUid::Uid( KMediaServantUID3 ) );
       
   229 
       
   230     if(error == KErrNone)
       
   231         {
       
   232         CApaCommandLine* commandLine = CApaCommandLine::NewLC();
       
   233         commandLine->SetExecutableNameL( applicationInfo.iFullName );
       
   234         commandLine->SetCommandL( EApaCommandRun );
       
   235         apaLsSession.StartApp( *commandLine );
       
   236 
       
   237         CleanupStack::PopAndDestroy( commandLine );
       
   238         }
       
   239     else
       
   240         {
       
   241         LOG(_L("[MediaServant]\t CMediaservantPlugin::ExecuteL \
       
   242         application launch failed"));
       
   243         }
       
   244 
       
   245     CleanupStack::PopAndDestroy( &apaLsSession );
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CMediaservantPlugin::RequiresUpnpConfiguration
       
   250 // Checks if the plugin needs upnp configuration (set IAP)
       
   251 // ---------------------------------------------------------------------------
       
   252 TBool CMediaservantPlugin::RequiresUpnpConfiguration()
       
   253     {
       
   254     return iRequiresUpnpConf;
       
   255     }
       
   256 
       
   257 
       
   258 
       
   259 // --------------------------------------------------------------------------
       
   260 // CMediaservantPlugin::PropertyChangedL
       
   261 // --------------------------------------------------------------------------
       
   262 //
       
   263 void CMediaservantPlugin::PropertyChangedL( TCmService aService,
       
   264                                     TInt aTotalItems,
       
   265                                     TInt aProcessedItems,
       
   266                                     TInt /*aItemsToBeProcessed*/ )
       
   267     {
       
   268 
       
   269     LOG(_L("[MediaServant]\t CMediaservantPlugin::PropertyChangedL"));
       
   270 
       
   271     switch ( aService )
       
   272         {
       
   273         case ECmServiceHarvest:
       
   274             {
       
   275             delete iSecondaryText;
       
   276             iSecondaryText = NULL;
       
   277             iSecondaryText = StringLoader::LoadL( R_MS_PLUGIN_HARVESTING );
       
   278             iPluginObserver->ExtensionEvent(
       
   279                                 EExtensionSecondaryTextChanged );
       
   280             break;
       
   281             }
       
   282         case ECmServiceStore:
       
   283         // fall through
       
   284         case ECmServiceFill:
       
   285             {
       
   286                 {
       
   287                 TInt value( 0 );
       
   288                 // calculate procentual value
       
   289                 if ( aTotalItems > 0 && aProcessedItems >= 0 )
       
   290                     {
       
   291                 	value = (TReal(aProcessedItems)/TReal(aTotalItems))*100;
       
   292                     } 
       
   293                 delete iSecondaryText;
       
   294                 iSecondaryText = NULL;
       
   295                 iSecondaryText = StringLoader::LoadL(
       
   296                                    R_MS_PLUGIN_SYNCHRONIZING, value );
       
   297                 iPluginObserver->ExtensionEvent( 
       
   298                     EExtensionSecondaryTextChanged );
       
   299                 }
       
   300             break;
       
   301             }
       
   302         case ECmServiceNone:
       
   303             {
       
   304             LoadPluginTextL();
       
   305             iPluginObserver->ExtensionEvent(EExtensionSecondaryTextChanged);
       
   306             break;
       
   307             }
       
   308         default:
       
   309             {
       
   310             LOG(_L("[MediaServant]\t CMediaservantPlugin::PropertyChangedL \
       
   311             service not found"));
       
   312             }
       
   313 
       
   314         }
       
   315     }
       
   316 
       
   317 // --------------------------------------------------------------------------
       
   318 // CMediaservantPlugin::LoadPluginTextL
       
   319 // --------------------------------------------------------------------------
       
   320 //
       
   321 void CMediaservantPlugin::LoadPluginTextL()
       
   322     {
       
   323     // Need to check content manager service state
       
   324     //to determine secondary text
       
   325     LOG(_L("[MediaServant]\t CMediaservantPlugin:LoadPluginTextL \
       
   326     open msengine"));
       
   327 
       
   328     TCmServiceState state = iMSEngine->ServiceState(
       
   329                                         ECmServiceContentManager );
       
   330     if ( iSecondaryText )
       
   331         {
       
   332         delete iSecondaryText;
       
   333         iSecondaryText = NULL;
       
   334         }
       
   335 
       
   336     switch ( state )
       
   337         {
       
   338         case ECmServiceStateAutomatic:
       
   339             {
       
   340             iSecondaryText =  StringLoader::LoadL(
       
   341                                             R_MS_PLUGIN_TEXT_AUTO_SYNC );
       
   342             break;
       
   343             }
       
   344         case ECmServiceStateDisabled:
       
   345             {
       
   346             iSecondaryText =  StringLoader::LoadL(
       
   347                                             R_MS_PLUGIN_TEXT_MANUAL_SYNC );
       
   348             break;
       
   349             }
       
   350         default:
       
   351             {
       
   352             // don't show sync state
       
   353             LOG(_L("[MediaServant]\t CMediaservantPlugin:LoadPluginTextL \
       
   354             sync state not shown"));
       
   355             break;
       
   356             }
       
   357         }
       
   358     }
       
   359 // end of file