mmserv/tms/tmsserver/src/tmsrtcontainer.cpp
changeset 12 5a06f39ad45b
child 20 b67dd1fc57c5
equal deleted inserted replaced
0:71ca22bcf22a 12:5a06f39ad45b
       
     1 /*
       
     2  * Copyright (c) 2010 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:  Class representing ringing tone
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <apgcli.h>
       
    20 #include <DRMHelper.h>
       
    21 #include <bldvariant.hrh>
       
    22 //#include <pathinfo.h>
       
    23 #include "tmsrtcontainer.h"
       
    24 
       
    25 using namespace TMS;
       
    26 
       
    27 // CONSTANTS
       
    28 // Rich audio file MIME types
       
    29 _LIT(KAac, "audio/aac");
       
    30 _LIT(KMp3, "audio/mp3");
       
    31 _LIT(KMpeg, "audio/mpeg");
       
    32 _LIT(K3gpp, "audio/3gpp");
       
    33 _LIT(KMp4, "audio/mp4");
       
    34 _LIT(KAmrWb, "audio/amr-wb");
       
    35 _LIT(KWavX, "audio/x-wav");
       
    36 _LIT(KWav, "audio/wav");
       
    37 // Rich video file MIME types
       
    38 _LIT(KV3gpp, "video/3gpp");
       
    39 _LIT(KVMp4, "video/mp4");
       
    40 _LIT(KV3gpp2, "video/3gpp2");
       
    41 // Used in CPhoneRingingTone
       
    42 _LIT(KPhoneRingingToneDriveZ, "z:");
       
    43 #ifdef RD_VIDEO_AS_RINGING_TONE
       
    44 _LIT(KPhoneRingingToneVideoMime, "video/*");
       
    45 _LIT(KPhoneRingingToneRealVideoMime, "*realmedia");
       
    46 #endif
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // TMSRtContainer::TMSRtContainer
       
    50 // C++ default constructor
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 TMSRtContainer::TMSRtContainer(TBool aDrmInPlayback) :
       
    54     iDrmInPlayback(aDrmInPlayback)
       
    55     {
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // TMSRtContainer::ConstructL
       
    60 // Symbian 2nd phase constructor
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void TMSRtContainer::ConstructL(const TDesC& aFileName)
       
    64     {
       
    65     iFileName = aFileName.AllocL();
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // TMSRtContainer::NewL
       
    70 // Two-phased constructor.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 TMSRtContainer* TMSRtContainer::NewL(const TDesC& aFileName,
       
    74         TBool aDrmInPlayback)
       
    75     {
       
    76     TMSRtContainer* self = new (ELeave) TMSRtContainer(aDrmInPlayback);
       
    77     CleanupStack::PushL(self);
       
    78     self->ConstructL(aFileName);
       
    79     CleanupStack::Pop(self);
       
    80     return self;
       
    81     }
       
    82 
       
    83 // Destructor
       
    84 TMSRtContainer::~TMSRtContainer()
       
    85     {
       
    86     delete iFileName;
       
    87     delete iMimeType;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // TMSRtContainer::SetFileName
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void TMSRtContainer::SetFileName(const TDesC& aFileName)
       
    95     {
       
    96     delete iFileName;
       
    97     iFileName = aFileName.Alloc();
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // TMSRtContainer::FileName
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 const TDesC& TMSRtContainer::FileName() const
       
   105     {
       
   106     // iFileName is never NULL
       
   107     return *iFileName;
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // TMSRtContainer::MimeType
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 const TDesC& TMSRtContainer::MimeType() const
       
   115     {
       
   116     if (iMimeType)
       
   117         {
       
   118         return *iMimeType;
       
   119         }
       
   120     else
       
   121         {
       
   122         return KNullDesC;
       
   123         }
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // TMSRtContainer::IsVideoRingingTone
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 TBool TMSRtContainer::IsVideoRingingTone()
       
   131     {
       
   132 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   133     if (RefreshMime() != KErrNone)
       
   134         {
       
   135         // try to handle as audio
       
   136         return EFalse;
       
   137         }
       
   138 
       
   139     TBool isVideo(EFalse);
       
   140 
       
   141     if (iMimeType && iMimeType->MatchF(KPhoneRingingToneVideoMime)
       
   142             != KErrNotFound)
       
   143         {
       
   144         isVideo = ETrue;
       
   145         }
       
   146     else if (iMimeType && iMimeType->MatchF(KPhoneRingingToneRealVideoMime)
       
   147             != KErrNotFound)
       
   148         {
       
   149         isVideo = ETrue;
       
   150         }
       
   151 
       
   152     if (isVideo)
       
   153         {
       
   154         if (IsFileInRom() && !IsFileInVideoDirectory())
       
   155             {
       
   156             // For ROM files check also location, because
       
   157             // MIME check is not fully reliable.
       
   158             isVideo = EFalse;
       
   159             }
       
   160         }
       
   161 
       
   162     return isVideo;
       
   163 
       
   164 #else
       
   165     // if extended security -> refresh MIME
       
   166     if (iDrmInPlayback)
       
   167         {
       
   168         RefreshMime();
       
   169         }
       
   170 
       
   171     return EFalse;
       
   172 #endif
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // TMSRtContainer::IsFileDrmProtected
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 TBool TMSRtContainer::IsFileDrmProtected() const
       
   180     {
       
   181     const TDesC& type = MimeType();
       
   182 
       
   183     if (type == KAac || type == KMp3 || type == KMpeg || type == K3gpp ||
       
   184             type == KMp4 || type == KAmrWb || type == KWavX || type == KWav ||
       
   185             type == KV3gpp || type == KVMp4 || type == KV3gpp2)
       
   186         {
       
   187         ContentAccess::CContent* content = NULL;
       
   188         TRAPD(err, content = ContentAccess::CContent::NewL(*iFileName));
       
   189         if (err == KErrNone && content)
       
   190             {
       
   191             TInt drmProtected(0);
       
   192             content->GetAttribute(ContentAccess::EIsProtected, drmProtected);
       
   193             delete content;
       
   194             return drmProtected;
       
   195             }
       
   196         }
       
   197 
       
   198     return ETrue; // Other MIMEs can be played without DRM check.
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // TMSRtContainer::IsFileInRom
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 TBool TMSRtContainer::IsFileInRom() const
       
   206     {
       
   207     TParsePtrC parsedName(*iFileName);
       
   208 
       
   209     // Files on ROM don't need to be checked for DRM
       
   210     if (parsedName.Drive().CompareF(KPhoneRingingToneDriveZ) == 0)
       
   211         {
       
   212         return ETrue;
       
   213         }
       
   214     else
       
   215         {
       
   216         return EFalse;
       
   217         }
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // TMSRtContainer::IsFileInVideoDirectory
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 TBool TMSRtContainer::IsFileInVideoDirectory() const
       
   225     {/*
       
   226     TParsePtrC parsedName(*iFileName);
       
   227 
       
   228     if (PathInfo::PathType(parsedName.DriveAndPath()) == PathInfo::EVideosPath)
       
   229         {
       
   230         return ETrue;
       
   231         }
       
   232     else
       
   233         {*/
       
   234         return EFalse;
       
   235         //}
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // TMSRtContainer::RefreshMime
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 TInt TMSRtContainer::RefreshMime()
       
   243     {
       
   244     TRAPD(err, RefreshMimeL());
       
   245     return err;
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // TMSRtContainer::RefreshMimeL
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void TMSRtContainer::RefreshMimeL()
       
   253     {
       
   254     RApaLsSession apaLsSession;
       
   255     User::LeaveIfError(apaLsSession.Connect());
       
   256     CleanupClosePushL(apaLsSession);
       
   257     TUid dummyUid = {0};
       
   258     TDataType dataType(dummyUid);
       
   259     User::LeaveIfError(apaLsSession.AppForDocument(*iFileName, dummyUid,
       
   260             dataType));
       
   261     CleanupStack::PopAndDestroy(); // CleanupClosePushL
       
   262     delete iMimeType;
       
   263     iMimeType = NULL;
       
   264     iMimeType = dataType.Des().AllocL();
       
   265     }
       
   266 
       
   267 //  End of File