skins/AknSkins/wppsrc/aknswallpaperplugin.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Project definition file for project aknswallpaperplugin
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eikmenup.h>
       
    19 #include <f32file.h>
       
    20 #include <AknsWallpaperUtils.h>
       
    21 #include <AiwMenu.h>
       
    22 #include <AiwCommon.h>
       
    23 #include <AiwCommon.hrh>
       
    24 #include <barsread.h>
       
    25 #include <eikenv.h>
       
    26 #include <ecom/implementationproxy.h>
       
    27 #include <StringLoader.h>
       
    28 #include <aknnotewrappers.h>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 #include <aknswallpaperplugin.rsg>
       
    31 #include "aknswallpaperplugin.h"
       
    32 #include "aknswallpaperplugin.rh"
       
    33 
       
    34 _LIT(KResourceFileName, "AknsWallpaperPlugin.rsc");
       
    35 _LIT(KDriveZ, "z:");
       
    36 
       
    37 _LIT(KAknsWallpaperPluginMimeTypeImage, "IMAGE");
       
    38 _LIT(KAknsWallpaperPluginMimeTypeOTABitmap, "IMAGE/X-OTA-BITMAP");
       
    39 _LIT(KAknsWallpaperPluginSeparator, "/");
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 CAknsWallpaperPlugin* CAknsWallpaperPlugin::NewL()
       
    44     {
       
    45     CAknsWallpaperPlugin* self = new( ELeave ) CAknsWallpaperPlugin;
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop(self);
       
    49     return self;
       
    50     }
       
    51 
       
    52 CAknsWallpaperPlugin::CAknsWallpaperPlugin():
       
    53     iConeResLoader(*CCoeEnv::Static())
       
    54     {
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CAknsWallpaperPlugin::ConstructL
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CAknsWallpaperPlugin::ConstructL()
       
    63     {
       
    64     TParse parse;
       
    65     parse.Set(KResourceFileName, &KDC_RESOURCE_FILES_DIR, &KDriveZ);
       
    66     TFileName resourceFileName;
       
    67     resourceFileName.Append(parse.FullName());
       
    68     iConeResLoader.OpenL(resourceFileName);
       
    69     }
       
    70 
       
    71 CAknsWallpaperPlugin::~CAknsWallpaperPlugin()
       
    72     {
       
    73     iConeResLoader.Close();
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // From class CAiwServiceIfMenu.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CAknsWallpaperPlugin::InitialiseL(MAiwNotifyCallback& /*aFrameworkCallback*/,
       
    81     const RCriteriaArray& /*aInterest*/)
       
    82     {
       
    83     // Not needed.
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // From class CAiwServiceIfMenu.
       
    88 //
       
    89 // Implements setting the main wallpaper for the device using
       
    90 // AknsWallpaperUtils.
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CAknsWallpaperPlugin::HandleServiceCmdL(const TInt& aCmdId,
       
    94     const CAiwGenericParamList& aInParamList,
       
    95     CAiwGenericParamList& /*aOutParamList*/,
       
    96     TUint /*aCmdOptions*/,
       
    97     const MAiwNotifyCallback* aCallback)
       
    98     {
       
    99      // Handle only assign command.
       
   100     if ( aCmdId == KAiwCmdAssign )
       
   101         {
       
   102         // Retrieve filename and file MIME type from AIW param list
       
   103         TPtrC fileName = GetAiwParamAsDescriptor(aInParamList, EGenericParamFile);
       
   104 
       
   105         TPtrC mimeTypeString = GetAiwParamAsDescriptor(aInParamList, EGenericParamMIMEType);
       
   106 
       
   107         // Leave, if there were not given all the required parameters
       
   108         if ((fileName == KNullDesC) ||
       
   109             (mimeTypeString == KNullDesC) || !IsMimeTypeSupportedL(mimeTypeString) )
       
   110             {
       
   111             User::Leave(KErrArgument);
       
   112             }
       
   113         TInt err = AknsWallpaperUtils::SetIdleWallpaper(
       
   114                                         fileName,
       
   115                                         CCoeEnv::Static(),
       
   116                                         R_AKNS_WALLPAPER_TEXT_LOADING_IMAGE,
       
   117                                         R_AKNS_WALLPAPER_GENERAL_WAIT_NOTE );
       
   118 
       
   119         if (err == KAknsWpuErrorPreviewOnly)
       
   120             {
       
   121             DisplayInfoNoteL(R_AKNS_WALLPAPER_TEXT_DRM_PREVIEW);
       
   122             }
       
   123         else if ( err == KErrNoMemory || err == KErrDiskFull || err == KErrTooBig )
       
   124             {
       
   125             DisplayInfoNoteL( R_AKNS_WALLPAPER_TEXT_IMAGE_TOO_LARGE );
       
   126             }
       
   127         else if (err == KErrCancel || err == KErrCouldNotConnect )
       
   128             {
       
   129             // Skip, this is not a real error or the error is not propagated
       
   130             // to upper level.
       
   131             }
       
   132         else if ( err == KLeaveExit )
       
   133             {
       
   134             // Exit leaves should always allowed to leave.
       
   135             User::Leave( KLeaveExit );
       
   136             }
       
   137         else if ( err != KErrNone )
       
   138             {
       
   139             DisplayInfoNoteL( R_AKNS_WALLPAPER_TEXT_IMAGE_CORRUPTED );
       
   140             }
       
   141 
       
   142         // If aCallback defined inform consumers that we have done with
       
   143         // the operation.
       
   144         if (aCallback)
       
   145             {
       
   146             // Cope with the design problems of AIW framework
       
   147             MAiwNotifyCallback* nonConstCallback =
       
   148             const_cast<MAiwNotifyCallback*> (aCallback);
       
   149             CAiwGenericParamList* eventParamList = CAiwGenericParamList::NewL();
       
   150             CleanupStack::PushL(eventParamList);
       
   151             nonConstCallback->HandleNotifyL(
       
   152                 KAiwCmdAssign,
       
   153                 KAiwEventCompleted,
       
   154                 *eventParamList,
       
   155                 aInParamList);
       
   156             CleanupStack::PopAndDestroy(eventParamList);
       
   157             }
       
   158         }
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // From class CAiwServiceIfMenu.
       
   163 //
       
   164 // Inserts plugin's menu items to aMenuPane.
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CAknsWallpaperPlugin::InitializeMenuPaneL(CAiwMenuPane& aMenuPane,
       
   168     TInt aIndex,
       
   169     TInt /*aCascadeId*/,
       
   170     const CAiwGenericParamList& aInParamList)
       
   171     {
       
   172     TPtrC mimeTypeString = GetAiwParamAsDescriptor(aInParamList, EGenericParamMIMEType);
       
   173 
       
   174     // Insert menu only if supported MIME type is given
       
   175     if ((mimeTypeString != KNullDesC) && IsMimeTypeSupportedL(mimeTypeString) )
       
   176         {
       
   177         TResourceReader reader;
       
   178         CCoeEnv::Static()->CreateResourceReaderLC(reader, R_AKNS_WALLPAPER_PLUGIN_MENU);
       
   179         aMenuPane.AddMenuItemsL(reader, KAiwCmdAssign, aIndex);
       
   180         CleanupStack::PopAndDestroy(); // reader
       
   181         }
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // From class CAiwServiceIfMenu.
       
   186 //
       
   187 // Implements menu command handling for EAknsWallpaperPluginCmdSetWallPaper.
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CAknsWallpaperPlugin::HandleMenuCmdL(
       
   191     TInt aMenuCmdId,
       
   192     const CAiwGenericParamList& aInParamList,
       
   193     CAiwGenericParamList& aOutParamList,
       
   194     TUint aCmdOptions,
       
   195     const MAiwNotifyCallback* aCallback)
       
   196     {
       
   197     if (aMenuCmdId == EAknsWallpaperPluginCmdSetWallPaper)
       
   198         {
       
   199         // Menu commands are handled as service commands.
       
   200         HandleServiceCmdL(
       
   201             KAiwCmdAssign,
       
   202             aInParamList,
       
   203             aOutParamList,
       
   204             aCmdOptions,
       
   205             aCallback );
       
   206         }
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // Implements showing information note
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CAknsWallpaperPlugin::DisplayInfoNoteL(TInt aTextResourceId)
       
   214     {
       
   215     HBufC* text = StringLoader::LoadLC(aTextResourceId);
       
   216     CAknInformationNote* dlg = new (ELeave) CAknInformationNote(EFalse);
       
   217     dlg->ExecuteLD(*text);
       
   218     CleanupStack::PopAndDestroy(text);
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // Implements checking if a given MIME type is supported or not
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 TBool CAknsWallpaperPlugin::IsMimeTypeSupportedL(const TDesC& aMimeTypeString)
       
   226     {
       
   227     // Check for a type separator in the string
       
   228     TInt pos = aMimeTypeString.Find(KAknsWallpaperPluginSeparator);
       
   229 
       
   230     // Leave if no separator was found.. the MIME
       
   231     // standard requires it
       
   232     if (pos == KErrNotFound)
       
   233         {
       
   234         User::Leave(KErrArgument);
       
   235         }
       
   236 
       
   237     // Copy the full Mime type string (needed for uppercase)
       
   238     HBufC* fullBuf = aMimeTypeString.AllocLC();
       
   239     TPtr fullString = fullBuf->Des();
       
   240     fullString.UpperCase();
       
   241 
       
   242     // Construct the compare string
       
   243     TPtrC compareString(aMimeTypeString.Left(pos));
       
   244 
       
   245     // Perform the comparison
       
   246     TBool ret = EFalse;
       
   247 
       
   248     // Mime type case:  IMAGE/* except IMAGE/X-OTA-BITMAP
       
   249     if (compareString.CompareF(KAknsWallpaperPluginMimeTypeImage) == 0 &&
       
   250         !(fullString.CompareF(KAknsWallpaperPluginMimeTypeOTABitmap) == 0))
       
   251         {
       
   252         ret = ETrue;
       
   253         }
       
   254     CleanupStack::PopAndDestroy(fullBuf);
       
   255 
       
   256     return ret;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // Implements getting a AIW parameter as descriptor
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 TPtrC CAknsWallpaperPlugin::GetAiwParamAsDescriptor(
       
   264         const CAiwGenericParamList& aParamList,
       
   265         TGenericParamId aParamType)
       
   266     {
       
   267     TInt index = 0;
       
   268     const TAiwGenericParam* genericParam = NULL;
       
   269     genericParam = aParamList.FindFirst(
       
   270         index,
       
   271         aParamType,
       
   272         EVariantTypeDesC);
       
   273 
       
   274     if (index >= 0 && genericParam)
       
   275         {
       
   276         // Get the data
       
   277         return genericParam->Value().AsDes();
       
   278         }
       
   279     else
       
   280         {
       
   281         return KNullDesC();
       
   282         }
       
   283     }
       
   284 
       
   285 // ======== ECOM INITIALIZATION ========
       
   286 
       
   287 // Map the interface UIDs to implementation factory functions
       
   288 const TImplementationProxy ImplementationTable[] =
       
   289     {
       
   290     IMPLEMENTATION_PROXY_ENTRY(KAknsWallpaperPluginImplementationUid, CAknsWallpaperPlugin::NewL)
       
   291     };
       
   292 
       
   293 // ---------------------------------------------------------
       
   294 // Exported proxy for instantiation method resolution
       
   295 // ---------------------------------------------------------
       
   296 //
       
   297 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   298     {
       
   299     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   300     return ImplementationTable;
       
   301     }