mpxplugins/serviceplugins/collectionplugins/mpxsqlitepodcastdbplugin/src/mpxdbutil.cpp
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     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:  Utility functions for the podcast plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <bautils.h>
       
    21 #include <caf/data.h>
       
    22 #include <caf/virtualpathptr.h>
       
    23 #include <hash.h>
       
    24 #include <apgcli.h>
       
    25 #include <apmstd.h>
       
    26 
       
    27 #include <mpxmediageneraldefs.h>
       
    28 #include <mpxmediamusicdefs.h>
       
    29 #include <mpxmediaaudiodefs.h>
       
    30 #include <mpxmediadrmdefs.h>
       
    31 #include <mpxmediacollectiondetaildefs.h>
       
    32 #include <mpxmedia.h>
       
    33 #include <mpxmediaarray.h>
       
    34 #include <mpxlog.h>
       
    35 
       
    36 #include "mpxdbcommonstd.h"
       
    37 #include "mpxdbcommonutil.h"
       
    38 #include "mpxdbcommondef.h"
       
    39 
       
    40 #include "mpxdbutil.h"
       
    41 #include "mpxpodcastcollectiondbdef.h"
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ==============================
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // Append an item into the media array
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 void MPXDbUtil::AppendMediaL(
       
    50     CMPXMediaArray& aArray,
       
    51     const TDesC& aTitle,
       
    52     TMPXGeneralType aType,
       
    53     TMPXGeneralCategory aCat,
       
    54     TMPXPodcastType aPodcastType,
       
    55     TMPXPodcastCategory aPodcastCat,
       
    56     TMPXItemId aId,
       
    57     TInt aNonPermissibleActions)
       
    58     {
       
    59     MPX_FUNC("MPXDbUtil::AppendMediaL");
       
    60 
       
    61     RArray<TInt> supportedIds;
       
    62     CleanupClosePushL (supportedIds);
       
    63     supportedIds.AppendL (KMPXMediaIdGeneral);
       
    64     supportedIds.AppendL (KMPXMediaIdPodcast);
       
    65     CMPXMedia* entry = CMPXMedia::NewL(supportedIds.Array());
       
    66     CleanupStack::PushL (entry);
       
    67     entry->SetTextValueL (KMPXMediaGeneralTitle, aTitle);
       
    68     entry->SetTObjectValueL(KMPXMediaPodcastType, aPodcastType);
       
    69     entry->SetTObjectValueL(KMPXMediaPodcastCategoryGroup, aPodcastCat);
       
    70     entry->SetTObjectValueL(KMPXMediaGeneralId, aId);
       
    71     entry->SetTObjectValueL(KMPXMediaGeneralType, aType);
       
    72     entry->SetTObjectValueL(KMPXMediaGeneralCategory, aCat);
       
    73 
       
    74     // temp fix: Beryl BEGIN
       
    75     if ( aNonPermissibleActions != 0 )
       
    76         {
       
    77         // set non-permissible actions
       
    78         entry->SetTObjectValueL(KMPXMediaGeneralNonPermissibleActions,
       
    79             static_cast<TMPXGeneralNonPermissibleActions>(aNonPermissibleActions));
       
    80         }
       
    81     // temp fix: Beryl END
       
    82     aArray.AppendL (entry);
       
    83     CleanupStack::Pop (entry);
       
    84     CleanupStack::PopAndDestroy (&supportedIds);
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // MPXDbUtil::PodcastFieldNameForCategoryL
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 TPtrC MPXDbUtil::PodcastFieldNameForCategoryL(
       
    92     TMPXGeneralCategory aCategory)
       
    93     {
       
    94     MPX_FUNC("MPXDbUtil::PodcastFieldNameForCategoryL");
       
    95 
       
    96     TPtrC ptr;
       
    97     switch (aCategory)
       
    98         {
       
    99         case EMPXArtist:
       
   100             ptr.Set(KMCPodcastAuthor);
       
   101             break;
       
   102 
       
   103         case EMPXAlbum:
       
   104             ptr.Set(KMCPodcastTitle);
       
   105             break;
       
   106 
       
   107         case EMPXGenre:
       
   108             ptr.Set(KMCPodcastGenre);
       
   109             break;
       
   110 
       
   111         case EMPXComposer:
       
   112             ptr.Set(KMCPodcastComposer);
       
   113             break;
       
   114 
       
   115         default:
       
   116             User::Leave(KErrNotSupported);
       
   117         }
       
   118 
       
   119     return ptr;
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // MPXDbUtil::Today
       
   124 // ----------------------------------------------------------------------------
       
   125 //
       
   126 TTime MPXDbUtil::Today()
       
   127     {
       
   128     MPX_FUNC("MPXDbUtil::Today");
       
   129 
       
   130     TTime now;  // in microseconds
       
   131     now.HomeTime();
       
   132     TDateTime todayDate = now.DateTime();
       
   133 
       
   134     todayDate.SetHour(0);
       
   135     todayDate.SetMinute(0);
       
   136     todayDate.SetSecond(0);
       
   137     todayDate.SetMicroSecond(0);
       
   138 
       
   139     return TTime(todayDate);
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // MPXDbUtil::MonthStart
       
   144 // ----------------------------------------------------------------------------
       
   145 //
       
   146 TTime MPXDbUtil::MonthStart()
       
   147     {
       
   148     MPX_FUNC("MPXDbUtil::MonthStart");
       
   149 
       
   150     TTime now;  // in microseconds
       
   151     now.HomeTime();
       
   152     TDateTime lastMonthStartDate = now.DateTime();
       
   153 
       
   154     lastMonthStartDate.SetDay(0);  // Day range from 0 to 30
       
   155     lastMonthStartDate.SetHour(0);
       
   156     lastMonthStartDate.SetMinute(0);
       
   157     lastMonthStartDate.SetSecond(0);
       
   158     lastMonthStartDate.SetMicroSecond(0);
       
   159 
       
   160     return TTime(lastMonthStartDate);
       
   161     }
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 // MPXDbUtil::DayNoInWeek
       
   165 // ----------------------------------------------------------------------------
       
   166 //
       
   167 TInt MPXDbUtil::DayNoInWeek()
       
   168     {
       
   169     MPX_FUNC("MPXDbUtil::DayNoInWeek");
       
   170 
       
   171     TTime now;  // in microseconds
       
   172     now.HomeTime();
       
   173 
       
   174     // Calculate number of days in this week
       
   175     TDay dayNo = now.DayNoInWeek();
       
   176     TDay firstDay = TLocale().StartOfWeek();
       
   177     TInt numDay(0);
       
   178     if (firstDay == ESunday)
       
   179         {
       
   180         numDay = dayNo + 1;
       
   181         }
       
   182     else
       
   183         {
       
   184         numDay = dayNo - firstDay;
       
   185         }
       
   186 
       
   187     return numDay;
       
   188     }
       
   189 
       
   190 // ----------------------------------------------------------------------------
       
   191 // MPXDbUtil::TableNameForCategoryL
       
   192 // ----------------------------------------------------------------------------
       
   193 //
       
   194 TPtrC MPXDbUtil::TableNameForCategoryL(
       
   195     TMPXGeneralCategory aCategory)
       
   196     {
       
   197     MPX_FUNC("MPXDbUtil::TableNameForCategoryL");
       
   198 
       
   199     TPtrC ptr;
       
   200     switch (aCategory)
       
   201         {
       
   202         case EMPXArtist:
       
   203             ptr.Set(KMCAuthorTable);
       
   204             break;
       
   205         case EMPXAlbum:
       
   206             ptr.Set(KMCTitleTable);
       
   207             break;
       
   208         case EMPXGenre:
       
   209             ptr.Set(KMCCategoryTable);
       
   210             break;
       
   211         case EMPXComposer:
       
   212             ptr.Set(KMCComposerTable);
       
   213             break;
       
   214         default:
       
   215             User::Leave(KErrNotSupported);
       
   216         }
       
   217 
       
   218     return ptr;
       
   219     }
       
   220 
       
   221 // End of File