scrsaver/scrsaverplugins/SlideshowPlugin/inc/SlideshowPluginUtils.h
branchRCL_3
changeset 26 e8d784ac1a4b
parent 0 040fcad49f44
equal deleted inserted replaced
25:aaeeca1f15af 26:e8d784ac1a4b
       
     1 /*
       
     2 * Copyright (c) 2006 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:   SlideshowPlugin utilities collection
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_SLIDESHOWPLUGINUTILS_H
       
    21 #define C_SLIDESHOWPLUGINUTILS_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <cenrepnotifyhandler.h>
       
    26 #include <e32property.h>
       
    27 
       
    28 #include "SlideshowSlide.h"
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CDRMHelper;
       
    32 class CCoeEnv;
       
    33 class CRepository;
       
    34 
       
    35 // CLASS DECLARATION
       
    36 
       
    37 /**
       
    38 * Central Repository Change watcher
       
    39 * @since 3.2
       
    40 * @internal
       
    41 */    
       
    42 class CRepositoryWatcher : public CBase, public MCenRepNotifyHandlerCallback
       
    43     {
       
    44 public:
       
    45     static CRepositoryWatcher* NewL(
       
    46         const TUid aUid,
       
    47         const TUint32 aKey,
       
    48         CCenRepNotifyHandler::TCenRepKeyType aKeyType,
       
    49         TCallBack aCallBack,
       
    50         CRepository* aRepository);
       
    51 
       
    52     static CRepositoryWatcher* NewL(
       
    53         const TUid aUid,
       
    54         TCallBack aCallBack,
       
    55         CRepository* aRepository);
       
    56 
       
    57     ~CRepositoryWatcher();
       
    58 
       
    59     TUint32 ChangedKey();
       
    60 
       
    61 public: // from MCenRepNotifyHandlerCallback
       
    62     void HandleNotifyInt(TUint32 aKey, TInt aNewValue);
       
    63     void HandleNotifyString(TUint32 aKey, const TDesC16& aNewValue);
       
    64     void HandleNotifyGeneric(TUint32 aKey);
       
    65     void HandleNotifyError(
       
    66         TUint32 aKey, TInt aError, CCenRepNotifyHandler* aHandler);
       
    67 
       
    68 private:
       
    69     CRepositoryWatcher(
       
    70         const TUid aUid,
       
    71         const TUint32 aKey,
       
    72         TCallBack aCallBack,
       
    73         CRepository* aRepository);
       
    74 
       
    75     void ConstructL(CCenRepNotifyHandler::TCenRepKeyType aKeyType);
       
    76 
       
    77     void ConstructL();
       
    78 
       
    79 private:
       
    80     TUid iUid;
       
    81     TUint32 iKey;
       
    82     TUint32 iChangedKey;
       
    83     TCallBack iCallBack;
       
    84     CRepository* iRepository;
       
    85     CCenRepNotifyHandler* iNotifyHandler;
       
    86 };    
       
    87 
       
    88 
       
    89 /**
       
    90 * Publish & Subscribe change subscriber
       
    91 * @since 3.2
       
    92 * @internal
       
    93 */    
       
    94 class CPSSubscriber : public CActive
       
    95     {
       
    96 public:
       
    97     CPSSubscriber(TCallBack aCallBack, RProperty& aProperty);
       
    98     ~CPSSubscriber();
       
    99     
       
   100 public: // New functions
       
   101     void SubscribeL();
       
   102     void StopSubscribe();
       
   103 
       
   104 private: // from CActive
       
   105     void RunL();
       
   106     void DoCancel();
       
   107 
       
   108 private:
       
   109     TCallBack   iCallBack;
       
   110     RProperty&  iProperty;
       
   111 };
       
   112 
       
   113 
       
   114 // ========== UTILITIES CLASS =============================
       
   115 
       
   116 class SlideshowUtil
       
   117     {
       
   118 public:
       
   119     // Checks if memory card is present
       
   120     static TBool IsMCPresent();
       
   121 
       
   122     // Checks if the given file is on memory card
       
   123     static TBool IsOnMC(TFileName aFile);
       
   124 
       
   125     // Checks that the file has enough DRM rights to be displayed
       
   126     static TBool DRMCheck(CDRMHelper *aDRMHelper, TDesC& aFileName);
       
   127 
       
   128     // Checks that the slide has enough DRM rights to be displayed
       
   129     static TBool DRMCheck(CDRMHelper *aDRMHelper, CSlideshowSlide* aSlide);
       
   130 
       
   131     // Consumes the slide's DRM rights
       
   132     static void DRMConsume(CDRMHelper* aDRMHelper, CSlideshowSlide* aSlide);
       
   133     
       
   134 private:
       
   135     /**
       
   136      * Static class can not be instantiated.
       
   137      */
       
   138     SlideshowUtil();
       
   139     //lint -esym(1526, SlideshowUtil::SlideshowUtil) Intentionally undefined
       
   140 
       
   141     /**
       
   142      * Static class can not be instantiated.
       
   143      */
       
   144     ~SlideshowUtil();
       
   145     };
       
   146 
       
   147 
       
   148 // ========== LOGGING MACROS ===============================
       
   149 
       
   150 #ifdef USE_LOGGER
       
   151 
       
   152 #include <e32std.h>
       
   153 #include <e32def.h>
       
   154 #include <eikenv.h>
       
   155 #include <flogger.h>
       
   156 
       
   157 
       
   158 /* logging macros usage:
       
   159 
       
   160 // set logging on in mmp file...
       
   161 MACRO USE_LOGGER
       
   162 #ifdef WINS
       
   163 MACRO USE_RDEBUG
       
   164 #endif
       
   165 
       
   166 
       
   167 void CTestAppUi::ConstructL()
       
   168 {
       
   169 // creates log directory and log file on app startup.
       
   170 // prints starting banner...
       
   171 SCRLOGGER_CREATE;
       
   172 
       
   173 // entering to function...
       
   174 SCRLOGGER_ENTERFN("ConstructL()");
       
   175 
       
   176 TInt number = 42;
       
   177 TFileName file;
       
   178 file = "something" ....
       
   179 
       
   180 // print variable number of parameters...
       
   181 // Note: use _L macro for format string!
       
   182 SCRLOGGER_WRITEF(_L("SCR: number = %d, file = %S"), number, &file);
       
   183 
       
   184 // print just a string (no _L macro here!)
       
   185 SCRLOGGER_WRITE("Hello world!");
       
   186 
       
   187 // leave from function...
       
   188 SCRLOGGER_LEAVEFN("ConstructL()");
       
   189 }
       
   190 
       
   191 CTestAppUi::~CTestAppUi()
       
   192 {
       
   193 // print app exit banner when application exits.
       
   194 SCRLOGGER_DELETE;
       
   195 }
       
   196 
       
   197 */
       
   198 
       
   199 #ifdef USE_RDEBUG
       
   200 
       
   201 _LIT(KSSPLogBanner, "SlideshowPlugin log start");
       
   202 _LIT(KSSPLogEnterFn, "SSP: enter --> %S");
       
   203 _LIT(KSSPLogLeaveFn, "SSP: leave <-- %S");
       
   204 _LIT(KSSPLogWrite, "SSP: %S");
       
   205 _LIT(KSSPLogTag, "SSP: ");
       
   206 _LIT(KSSPLogExit, "SlideshowPlugin log end");
       
   207 _LIT(KSSPLogTimeFormatString, "%H:%T:%S:%*C2");
       
   208 
       
   209 #define SSPLOGGER_CREATE             {RDebug::Print(KSSPLogBanner);}
       
   210 #define SSPLOGGER_DELETE             {RDebug::Print(KSSPLogExit);}
       
   211 #define SSPLOGGER_ENTERFN(a)         {_LIT(temp, a); RDebug::Print(KSSPLogEnterFn, &temp);}
       
   212 #define SSPLOGGER_LEAVEFN(a)         {_LIT(temp, a); RDebug::Print(KSSPLogLeaveFn, &temp);}
       
   213 #define SSPLOGGER_WRITE(a)           {_LIT(temp, a); RDebug::Print(KSSPLogWrite, &temp);}
       
   214 #define SSPLOGGER_WRITE_TIMESTAMP(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL(buffer, KSSPLogTimeFormatString); buffer.Insert(0, temp); buffer.Insert(0, KSSPLogTag); RDebug::Print(buffer); }
       
   215 #define SSPLOGGER_WRITEF             RDebug::Print
       
   216 
       
   217 #else
       
   218 
       
   219 _LIT(KSSPLogDir, "SSP");
       
   220 _LIT(KSSPLogFile, "SSP.txt");
       
   221 _LIT8(KSSPLogBanner, "SlideshowPlugin log start");
       
   222 _LIT8(KSSPLogEnterFn, "SSP: -> %S");
       
   223 _LIT8(KSSPLogLeaveFn, "SSP: <- %S");
       
   224 _LIT8(KSSPLogExit, "SlideshowPlugin log end");
       
   225 _LIT(KSSPLogTimeFormatString, "%H:%T:%S:%*C2");
       
   226 
       
   227 #define SSPLOGGER_CREATE             {FCreate();}
       
   228 #define SSPLOGGER_DELETE             {RFileLogger::Write(KSSPLogDir, KSSPLogFile, EFileLoggingModeAppend, KSSPLogExit);}
       
   229 #define SSPLOGGER_ENTERFN(a)         {_LIT8(temp, a); RFileLogger::WriteFormat(KSSPLogDir, KSSPLogFile, EFileLoggingModeAppend, KSSPLogEnterFn, &temp);}
       
   230 #define SSPLOGGER_LEAVEFN(a)         {_LIT8(temp, a); RFileLogger::WriteFormat(KSSPLogDir, KSSPLogFile, EFileLoggingModeAppend, KSSPLogLeaveFn, &temp);}
       
   231 #define SSPLOGGER_WRITE(a)           {_LIT(temp, a); RFileLogger::Write(KSSPLogDir, KSSPLogFile, EFileLoggingModeAppend, temp);}
       
   232 #define SSPLOGGER_WRITE_TIMESTAMP(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL(buffer, KSSPLogTimeFormatString); buffer.Insert(0, temp); RFileLogger::Write(KSSPLogDir, KSSPLogFile, EFileLoggingModeAppend, buffer); }
       
   233 #define SSPLOGGER_WRITEF             FPrint
       
   234 
       
   235 inline void FPrint(const TRefByValue<const TDesC> aFmt, ...)
       
   236     {
       
   237     VA_LIST list;
       
   238     VA_START(list, aFmt);
       
   239     RFileLogger::WriteFormat(KSSPLogDir, KSSPLogFile, EFileLoggingModeAppend, aFmt, list);
       
   240     }
       
   241 
       
   242 inline void FPrint(const TDesC& aDes)
       
   243     {
       
   244     RFileLogger::WriteFormat(KSSPLogDir, KSSPLogFile, EFileLoggingModeAppend, aDes);
       
   245     }
       
   246 
       
   247 inline void FHex(const TUint8* aPtr, TInt aLen)
       
   248     {
       
   249     RFileLogger::HexDump(KSSPLogDir, KSSPLogFile, EFileLoggingModeAppend, 0, 0, aPtr, aLen);
       
   250     }
       
   251 
       
   252 inline void FHex(const TDesC8& aDes)
       
   253     {
       
   254     FHex(aDes.Ptr(), aDes.Length());
       
   255     }
       
   256 
       
   257 inline void FCreate()
       
   258     {
       
   259     TFileName path(_L("c:\\logs\\"));
       
   260     path.Append(KSSPLogDir);
       
   261     path.Append(_L("\\"));
       
   262     RFs& fs = CEikonEnv::Static()->FsSession();
       
   263     fs.MkDirAll(path);
       
   264     RFileLogger::WriteFormat(KSSPLogDir, KSSPLogFile, EFileLoggingModeOverwrite, KSSPLogBanner);
       
   265     }
       
   266 
       
   267 #endif // USE_RDEBUG
       
   268 
       
   269 #else // USE_LOGGER
       
   270 
       
   271 inline void FPrint(const TRefByValue<const TDesC> /*aFmt*/, ...) { };
       
   272 
       
   273 #define SSPLOGGER_CREATE
       
   274 #define SSPLOGGER_DELETE
       
   275 #define SSPLOGGER_ENTERFN(a)
       
   276 #define SSPLOGGER_LEAVEFN(a)
       
   277 #define SSPLOGGER_WRITE(a)
       
   278 #define SSPLOGGER_WRITEF 1 ? ((void)0) : FPrint
       
   279 #define SSPLOGGER_WRITE_TIMESTAMP(a)
       
   280 
       
   281 #endif // USE_LOGGER
       
   282 
       
   283 #endif // C_SLIDESHOWPLUGINUTILS_H