upnpframework/upnputilities/inc/upnppathutility.h
branchIOP_Improvements
changeset 40 08b5eae9f9ff
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
       
     1 /*
       
     2 * Copyright (c) 2002-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 *
       
    15 * Description:  Utility class to get path related info for the media files
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #ifndef UPNPPATHUTILITY_H
       
    24 #define UPNPPATHUTILITY_H
       
    25 
       
    26 // INCLUDE FILES
       
    27 #include <e32base.h>    // CBase
       
    28 #include <f32file.h>    // TDriveNumber
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CUPnPSettingsEngine;
       
    32 class CUpnpObject;
       
    33 class CUpnpItem;
       
    34 class CUpnpElement;
       
    35 class CUpnpAttribute;
       
    36 class CUpnpDlnaProtocolInfo;
       
    37 
       
    38 // CLASS DECLARATION
       
    39 /**
       
    40  *  Path utility class to get path related info for the media files
       
    41  *  @lib upnputilities.lib
       
    42  */
       
    43 NONSHARABLE_CLASS ( CUPnPPathUtility ) : public CBase
       
    44     {
       
    45 public: // Constructors and destructor
       
    46 
       
    47     /**
       
    48      * Two-phased constructor.
       
    49      */
       
    50     IMPORT_C static CUPnPPathUtility* NewL();
       
    51 
       
    52     /**
       
    53      * Two-phased constructor.
       
    54      */
       
    55     IMPORT_C static CUPnPPathUtility* NewLC();
       
    56 
       
    57     /**
       
    58      * Destructor.
       
    59      */
       
    60     IMPORT_C virtual ~CUPnPPathUtility();
       
    61         
       
    62         
       
    63 public: // new functions
       
    64 
       
    65     /**
       
    66      * Gets the drive for the copy operation
       
    67      * @param aDrive, reference to copy path drive
       
    68      */
       
    69     IMPORT_C void GetCopyPathDriveL( TDriveNumber& aDrive ) const;
       
    70 
       
    71     /**
       
    72      * Gets the path of the upnp item's file to be copied
       
    73      * @param aItem, a upnp item
       
    74      * @param aResource, resource of the upnp item
       
    75      * @param aAppendTitleAndExt, If ETrue title and extensions gets 
       
    76      *                            appended to the path otherwise not.
       
    77      * @return HBufC*, copy path. Ownership is transferred to the caller
       
    78      *          Leaves in case of an error.    
       
    79      */
       
    80     IMPORT_C HBufC* GetCopyPathL(const CUpnpItem& aItem,
       
    81                                  const CUpnpElement& aResource,
       
    82                                  TBool aAppendTitleAndExt ) const;
       
    83 
       
    84     /**
       
    85      * Gets the path of the upnp item's file to be copied
       
    86      * @param aItem, a upnp item
       
    87      * @param aResource, resource of the upnp item
       
    88      * @param aAppendTitleAndExt, If ETrue title and extensions gets 
       
    89      *                            appended to the path otherwise not.
       
    90      * @param aDriveNumber, drive number to be used for the path calculation
       
    91      * @return HBufC*, copy path. Ownership is transferred to the caller
       
    92      *          Leaves in case of an error.    
       
    93      */
       
    94     IMPORT_C HBufC* GetCopyPathL(const CUpnpItem& aItem,
       
    95                                  const CUpnpElement& aResource,
       
    96                                  TBool aAppendTitleAndExt,
       
    97                                  TDriveNumber aDriveNumber ) const;
       
    98     
       
    99     /**
       
   100      * Gets and creates (if necessary) the path of the upnp item's 
       
   101      * file to be copied.
       
   102      * @param aItem, a upnp item
       
   103      * @param aResource, resource of the upnp item
       
   104      * @param aAppendTitleAndExt, If ETrue title and extensions gets 
       
   105      *                            appended to the path otherwise not.
       
   106      * @return HBufC*, copy path. Ownership is transferred to the caller
       
   107      *          Leaves in case of an error.    
       
   108      */
       
   109     IMPORT_C HBufC* CreateCopyPathL(const CUpnpItem& aItem,
       
   110                                  const CUpnpElement& aResource,
       
   111                                  TBool aAppendTitleAndExt ) const;
       
   112     
       
   113     /**
       
   114      * Gets and creates (if necessary) the path of the upnp item's 
       
   115      * file to be copied.
       
   116      * @param aItem, a upnp item
       
   117      * @param aResource, resource of the upnp item
       
   118      * @param aAppendTitleAndExt, If ETrue title and extensions gets 
       
   119      *                            appended to the path otherwise not.
       
   120      * @param aDriveNumber, drive number to be used for the path calculation
       
   121      * @return HBufC*, copy path. Ownership is transferred to the caller
       
   122      *          Leaves in case of an error.    
       
   123      */
       
   124     IMPORT_C HBufC* CreateCopyPathL(const CUpnpItem& aItem,
       
   125                                  const CUpnpElement& aResource,
       
   126                                  TBool aAppendTitleAndExt,
       
   127                                  TDriveNumber aDriveNumber ) const;
       
   128     
       
   129     /**
       
   130      * Removes empty folders from the copy path 
       
   131      * @param aCopyPath, the copy path to be analysed
       
   132      */
       
   133     IMPORT_C static void RemoveEmptyFoldersFromCopyPathL(
       
   134                             const TDesC& aCopyPath );
       
   135     
       
   136 private:
       
   137 
       
   138     /**
       
   139      * C++ default constructor.
       
   140      */
       
   141     CUPnPPathUtility();
       
   142 
       
   143     /**
       
   144      * By default Symbian 2nd phase constructor is private.
       
   145      */
       
   146     void ConstructL();
       
   147 
       
   148     /**
       
   149      * Gets and creates (if necessary) the path of the upnp item's 
       
   150      * file to be copied.
       
   151      * @param aItem, a upnp item
       
   152      * @param aResource, resource of the upnp item
       
   153      * @param aAppendTitleAndExt, If ETrue title and extensions gets 
       
   154      *                            appended to the path otherwise not.
       
   155      * @param aCreatePath, If ETrue path gets created otherwise not.
       
   156      * @param aDriveNumber, drive number to be used for the path calculation
       
   157      * @return HBufC*, copy path. Ownership is transferred to the caller
       
   158      *          Leaves in case of an error.    
       
   159      */
       
   160     HBufC* GetCreateCopyPathL(const CUpnpItem& aItem,
       
   161                               const CUpnpElement& aResource,
       
   162                               TBool aAppendTitleAndExt,
       
   163                               TBool aCreatePath,
       
   164                               TDriveNumber aDriveNumber ) const;
       
   165     /**
       
   166      * Appends title and extension to the path.
       
   167      * @param aPath, path of the upnp item
       
   168      * @param aProtocolInfo, protocol info. attribute of the resource elem.
       
   169      * @param aItem, a upnp item
       
   170      */    
       
   171     void AppendTitleAndExtL( TDes& aPath, 
       
   172                         CUpnpDlnaProtocolInfo& aProtocolInfo, 
       
   173                         const CUpnpItem& aItem ) const;
       
   174     /**
       
   175      * Appends year, month and day to the path.
       
   176      * @param aPath, path of the upnp item
       
   177      * @param aItem, a upnp item
       
   178      */        
       
   179     void AppendYearMonthDayL( 
       
   180             TDes& aPath, const CUpnpItem& aItem ) const;
       
   181     
       
   182     /**
       
   183      * Appends artist and album to the path.
       
   184      * @param aPath, path of the upnp item
       
   185      * @param aItem, a upnp item
       
   186      */        
       
   187     void AppendArtistAlbumL( 
       
   188             TDes& aPath, const CUpnpItem& aItem ) const;
       
   189     
       
   190     /**
       
   191      * Appends data to the path's buffer.
       
   192      * Leaves if data exceeds the maxlength of the buffer
       
   193      * 
       
   194      * @param aPath, path of the upnp item
       
   195      * @param aData, data which needs to be appended
       
   196      */    
       
   197     void AppendDataL( TDes& aPath, const TDesC& aData ) const;
       
   198     
       
   199     /**
       
   200      * Checks whether the data can be appended to buffer or not.
       
   201      * Leaves if data exceeds the maxlength of the buffer
       
   202      * 
       
   203      * @param aPath, path of the upnp item
       
   204      * @param aData, data which needs to be appended
       
   205      */    
       
   206     void CheckBufferSpaceL( const TDes& aPath, 
       
   207             const TDesC& aData ) const;
       
   208     
       
   209     /**
       
   210      * Checks whether the data of the specified length
       
   211      * can be appended to buffer or not.
       
   212      * Leaves if data exceeds the maxlength of the buffer
       
   213      * 
       
   214      * @param aPath, path of the upnp item
       
   215      * @param aLength, length of the data which needs to be appended
       
   216      */    
       
   217     void CheckBufferSpaceL( const TDes& aPath, 
       
   218             const TInt& aLength ) const;
       
   219     
       
   220     /**
       
   221      * Finds an element within an object.
       
   222      *
       
   223      * @param aObject the object where to look for elements
       
   224      * @param aName element name
       
   225      * @return a pointer to the element, or NULL if not found
       
   226      */
       
   227     const CUpnpElement* FindElementByName(
       
   228         const CUpnpObject& aObject, const TDesC8& aName ) const;
       
   229 
       
   230     /**
       
   231       * Finds an attribute within an upnp element
       
   232       *
       
   233       * @param aElement the element where to look for attributes
       
   234       * @param aName attribute name
       
   235       * @return a pointer to the attribute found
       
   236       */
       
   237     const CUpnpAttribute* FindAttributeByName(
       
   238          const CUpnpElement& aElement, const TDesC8& aName ) const;
       
   239     
       
   240     /**
       
   241      * Converts given upnp date string into TTime.
       
   242      *
       
   243      * @param aUpnpDate value from item's dc:date element
       
   244      * @param aTime out variable to receive corresponding TTime
       
   245      * @return KErrNone if conversion was succesful, otherwise < 0
       
   246      *         for error values see TTime::Parse()
       
   247      */
       
   248     void UPnPDateAsTTimeL( const TDesC8& aUpnpDate,
       
   249         TTime& aTime ) const;
       
   250 
       
   251     /**
       
   252      * Removes empty folders from the full path 
       
   253      * @param aBasePath, base path (e.g. till Images\ or Sounds\ )
       
   254      * @param aFullPath, complete path (without filename and extension) 
       
   255      */
       
   256     static void RemoveEmptyFoldersL( const TDesC& aBasePath, 
       
   257                             const TDesC& aFullPath );
       
   258         
       
   259 private:    // data
       
   260 
       
   261     // Settings Engine
       
   262     CUPnPSettingsEngine*         iSettingsEngine;
       
   263     
       
   264     };
       
   265 
       
   266 #endif  // UPNPPATHUTILITY_H
       
   267 
       
   268 // End of file