harvesterplugins/media/mediautils/src/cpixdocfetcher.cpp
changeset 5 3bc31ad99ee7
parent 2 208a4ba3894c
child 9 4a2987baf8f7
child 11 773be20e0a25
equal deleted inserted replaced
3:6832643895f7 5:3bc31ad99ee7
    25 #include <mdeobjectdef.h>
    25 #include <mdeobjectdef.h>
    26 #include "harvesterserverlogger.h"
    26 #include "harvesterserverlogger.h"
    27 
    27 
    28 #define CPIX_MIMETYPE_FIELD      L"_mimetype"
    28 #define CPIX_MIMETYPE_FIELD      L"_mimetype"
    29 #define LCPIX_MIMETYPE_FIELD     L"_mimetype"
    29 #define LCPIX_MIMETYPE_FIELD     L"_mimetype"
       
    30 const TInt KInitialExcerptLength = 5;
    30 const TInt KStartPosition = 2; //Start position of absolute path
    31 const TInt KStartPosition = 2; //Start position of absolute path
    31 const TInt KDrivePosition = 0; //Drive position in object Uri
    32 const TInt KDrivePosition = 0; //Drive position in object Uri
    32 const TInt KMaxMediaLength = 14;
    33 const TInt KMaxMediaLength = 14;
    33 const TInt KMaxExtLength = 5;
    34 const TInt KMaxExtLength = 5;
    34 //To unsigned decimal representation as UIds are out of range for signed decimal
    35 //To unsigned decimal representation as UIds are out of range for signed decimal
    35 _LIT(KFormat, "%u");
    36 _LIT(KFormat, "%u");
    36 _LIT(KNameField, "Name");
    37 _LIT(KNameField, "Name");
    37 _LIT(KMediaIdField, "MediaId");
    38 _LIT(KMediaIdField, "MediaId");
    38 _LIT(KExtensionField, "Extension");
    39 _LIT(KExtensionField, "Extension");
       
    40 _LIT(KExcerptDelimiter, " ");
    39 
    41 
    40 // -----------------------------------------------------------------------------
    42 // -----------------------------------------------------------------------------
    41 // CCPIXDocFetcher::NewL()
    43 // CCPIXDocFetcher::NewL()
    42 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    43 //
    45 //
    65 // -----------------------------------------------------------------------------
    67 // -----------------------------------------------------------------------------
    66 //
    68 //
    67 CCPIXDocFetcher::~CCPIXDocFetcher()
    69 CCPIXDocFetcher::~CCPIXDocFetcher()
    68     {
    70     {
    69     iFs.Close();
    71     iFs.Close();
       
    72     delete iExcerpt;
    70     }
    73     }
    71 
    74 
    72 // -----------------------------------------------------------------------------
    75 // -----------------------------------------------------------------------------
    73 // CCPIXDocFetcher::~ConstructL() 
    76 // CCPIXDocFetcher::~ConstructL() 
    74 // -----------------------------------------------------------------------------
    77 // -----------------------------------------------------------------------------
    75 //
    78 //
    76 void CCPIXDocFetcher::ConstructL()
    79 void CCPIXDocFetcher::ConstructL()
    77     {
    80     {
    78     //Heap variables if any
    81     //Heap variables if any
    79     User::LeaveIfError(iFs.Connect());
    82     User::LeaveIfError(iFs.Connect());
       
    83     iExcerpt = NULL;
    80     }
    84     }
    81 
    85 
    82 // -----------------------------------------------------------------------------
    86 // -----------------------------------------------------------------------------
    83 // CCPIXDocFetcher::CCPIXDocFetcher() 
    87 // CCPIXDocFetcher::CCPIXDocFetcher() 
    84 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
    85 //
    89 //
    86 CCPIXDocFetcher::CCPIXDocFetcher()
    90 CCPIXDocFetcher::CCPIXDocFetcher()
    87     {
    91     {
    88     
    92     
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CCPIXDocFetcher::ResetExcerpt() 
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CCPIXDocFetcher::ResetExcerpt()
       
   100     {
       
   101     if(iExcerpt)
       
   102         {
       
   103         delete iExcerpt;
       
   104         iExcerpt = NULL;
       
   105         }
    89     }
   106     }
    90 
   107 
    91 // -----------------------------------------------------------------------------
   108 // -----------------------------------------------------------------------------
    92 // CCPIXDocFetcher::GetCpixDocumentL() 
   109 // CCPIXDocFetcher::GetCpixDocumentL() 
    93 // -----------------------------------------------------------------------------
   110 // -----------------------------------------------------------------------------
   128         GetExtension(aObject.Uri(),extension);
   145         GetExtension(aObject.Uri(),extension);
   129         AddFiledtoDocumentL( *index_item, KExtensionField, extension );
   146         AddFiledtoDocumentL( *index_item, KExtensionField, extension );
   130         
   147         
   131         CMdEProperty* property(NULL);
   148         CMdEProperty* property(NULL);
   132         CMdEPropertyDef& titlePropDef = aObjectDef.GetPropertyDefL(MdeConstants::Object::KTitleProperty );
   149         CMdEPropertyDef& titlePropDef = aObjectDef.GetPropertyDefL(MdeConstants::Object::KTitleProperty );
       
   150         /*Requirement Excerpt should have all item specific field in priority order so has to be handled
       
   151          *at plugin specific document handler
       
   152          */
   133         if(aObject.Property( titlePropDef, property ) != KErrNotFound)
   153         if(aObject.Property( titlePropDef, property ) != KErrNotFound)
   134            {
   154            {
   135            //Add field to document
   155            //Add field to document
   136            CMdETextProperty* textProperty = ( CMdETextProperty* ) property;
   156            CMdETextProperty* textProperty = ( CMdETextProperty* ) property;
   137            if(textProperty->Value() != KNullDesC)
   157            if(textProperty->Value() != KNullDesC)
   138                {
   158                {
   139                AddFiledtoDocumentL(*index_item,
   159                AddFiledtoDocumentL(*index_item,
   140                                      MdeConstants::Object::KTitleProperty,
   160                                      MdeConstants::Object::KTitleProperty,
   141                                      textProperty->Value());
   161                                      textProperty->Value());
   142                index_item->AddExcerptL(textProperty->Value());
       
   143                }
   162                }
   144            else
       
   145                {
       
   146                index_item->AddExcerptL(aObject.Uri());
       
   147                }
       
   148            }
       
   149         else
       
   150            {
       
   151            //No property title
       
   152            index_item->AddExcerptL(aObject.Uri());
       
   153            }
   163            }
   154         //Item type as MIME type
   164         //Item type as MIME type
   155         CMdEPropertyDef& mimeTypePropDef = aObjectDef.GetPropertyDefL(MdeConstants::Object::KItemTypeProperty);
   165         CMdEPropertyDef& mimeTypePropDef = aObjectDef.GetPropertyDefL(MdeConstants::Object::KItemTypeProperty);
   156         if(aObject.Property( mimeTypePropDef, property )!= KErrNotFound)
   166         if(aObject.Property( mimeTypePropDef, property )!= KErrNotFound)
   157            {
   167            {
   212          aExtension.Copy(aUri.Mid(pos+1));
   222          aExtension.Copy(aUri.Mid(pos+1));
   213         }
   223         }
   214     }
   224     }
   215 
   225 
   216 // -----------------------------------------------------------------------------
   226 // -----------------------------------------------------------------------------
       
   227 // CCPIXDocFetcher::AddToFieldExcerptL() 
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CCPIXDocFetcher::AddToFieldExcerptL(const TDesC& aExcerptValue)
       
   231     {
       
   232     if(!iExcerpt)
       
   233         {
       
   234         iExcerpt = HBufC::NewL(KInitialExcerptLength);
       
   235         }
       
   236     if(aExcerptValue.Compare(KNullDesC) != 0)//value is not Null
       
   237         {
       
   238         TInt currentSize = iExcerpt->Size();
       
   239         TInt newSize = currentSize + aExcerptValue.Size() + 1;
       
   240         if(newSize > currentSize) //New size is bigger so we have to reallocate
       
   241             {
       
   242             iExcerpt = iExcerpt->ReAllocL(newSize);
       
   243             }
       
   244         TPtr ptr = iExcerpt->Des();
       
   245         ptr.Append(aExcerptValue);
       
   246         ptr.Append(KExcerptDelimiter);
       
   247         }
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
   217 // CCPIXDocFetcher::SetAbsoluteURI() 
   251 // CCPIXDocFetcher::SetAbsoluteURI() 
   218 // -----------------------------------------------------------------------------
   252 // -----------------------------------------------------------------------------
   219 //
   253 //
   220 void CCPIXDocFetcher::SetAbsoluteURI(const TDesC& aUri)
   254 void CCPIXDocFetcher::SetAbsoluteURI(const TDesC& aUri)
   221     {
   255     {