videocollection/videocollectionview/src/videocollectionviewutils.cpp
changeset 30 4f111d64a341
child 34 bbb98528c666
equal deleted inserted replaced
2:dec420019252 30:4f111d64a341
       
     1 /*
       
     2 * Copyright (c) 2009 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: video collection view plugin's ui utils class
       
    15 * 
       
    16 */
       
    17 
       
    18 #include <hbdialog.h>
       
    19 #include <hbmessagebox.h>
       
    20 #include <centralrepository.h>
       
    21 
       
    22 #include "videocollectioncommon.h"
       
    23 #include "videocollectionviewutils.h"
       
    24 
       
    25 const int KVideoCollectionViewCenrepUid(0x2002BC63);
       
    26 const int KVideoCollectionViewCenrepServiceIconKey(0x2);
       
    27 const int KVideoCollectionViewCenrepServiceIconPressedKey(0x3);
       
    28 const int KVideoCollectionViewCenrepServiceUriKey(0x4);
       
    29 const int KVideoCollectionViewCenrepSortingRoleKey(0x5);
       
    30 const int KVideoCollectionViewCenrepSortingOrderKey(0x6);
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // instance
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 VideoCollectionViewUtils& VideoCollectionViewUtils::instance()
       
    37 {
       
    38      static VideoCollectionViewUtils _popupInstance;
       
    39      return _popupInstance;
       
    40 }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // VideoCollectionViewUtils
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 VideoCollectionViewUtils::VideoCollectionViewUtils()
       
    47 {
       
    48     
       
    49 }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // ~VideoCollectionViewUtils
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 VideoCollectionViewUtils::~VideoCollectionViewUtils()
       
    56 {
       
    57 
       
    58 }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // saveSortingValues
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 int VideoCollectionViewUtils::saveSortingValues(int role, Qt::SortOrder order)
       
    65 {
       
    66     int status = -1;
       
    67     CRepository *cenRep = 0;
       
    68     TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid)));
       
    69     if(cenRep)
       
    70     {
       
    71         status = cenRep->Set(KVideoCollectionViewCenrepSortingRoleKey, static_cast<TInt>(role));
       
    72         if(status == KErrNone)
       
    73         {
       
    74             status = cenRep->Set(KVideoCollectionViewCenrepSortingOrderKey, static_cast<TInt>(order));
       
    75         }
       
    76         delete cenRep;
       
    77     }
       
    78     return status;    
       
    79 }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // loadSortingValues
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 int VideoCollectionViewUtils::loadSortingValues(int& role, Qt::SortOrder& order)
       
    86 {
       
    87     int status = -1;
       
    88     CRepository *cenRep = 0;
       
    89     TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid)));
       
    90     if(cenRep)
       
    91     {
       
    92         TInt roleValue(KErrNotFound);
       
    93         TInt orderValue(KErrNotFound);
       
    94         status = cenRep->Get(KVideoCollectionViewCenrepSortingRoleKey, roleValue);
       
    95         if(status == KErrNone)
       
    96         {
       
    97             status = cenRep->Get(KVideoCollectionViewCenrepSortingOrderKey, orderValue);
       
    98             if(status == KErrNone)
       
    99             {
       
   100                 role = roleValue;
       
   101                 order = static_cast<Qt::SortOrder>(orderValue);
       
   102             }
       
   103         }
       
   104         delete cenRep;
       
   105     }
       
   106     return status;        
       
   107 }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // getServiceIconStrings
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 int VideoCollectionViewUtils::getServiceIconStrings(QString& icon, 
       
   114         QString& iconPressed)
       
   115 {
       
   116     int status = -1;
       
   117     CRepository *cenRep = 0;
       
   118     TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid)));
       
   119     if(cenRep)
       
   120     {
       
   121         TBuf<255> iconValue;
       
   122         TBuf<255> pressedValue;
       
   123         status = cenRep->Get(KVideoCollectionViewCenrepServiceIconKey, iconValue);
       
   124         if(status == KErrNone)
       
   125         {
       
   126             status = cenRep->Get(KVideoCollectionViewCenrepServiceIconPressedKey, pressedValue);
       
   127             if(status == KErrNone)
       
   128             {
       
   129                 QString iconTemp((QChar*)iconValue.Ptr(),iconValue.Length());
       
   130                 QString pressedTemp((QChar*)pressedValue.Ptr(),pressedValue.Length());
       
   131                 
       
   132                 icon = iconTemp;
       
   133                 iconPressed = pressedTemp;
       
   134             }
       
   135         }
       
   136         delete cenRep;
       
   137     }
       
   138     return status;        
       
   139 }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // getServiceUriString
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 QString VideoCollectionViewUtils::getServiceUriString()
       
   146 {
       
   147     QString uri;
       
   148     CRepository *cenRep = 0;
       
   149     TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid)));
       
   150     if(cenRep)
       
   151     {
       
   152         TBuf<255> uriValue;
       
   153         if(cenRep->Get(KVideoCollectionViewCenrepServiceIconKey, uriValue) == KErrNone)
       
   154         {
       
   155             QString uriTemp((QChar*)uriValue.Ptr(),uriValue.Length());
       
   156             uri = uriTemp;
       
   157         }
       
   158         delete cenRep;
       
   159     }
       
   160     return uri;        
       
   161 }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // showStatusMsgSlot
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void VideoCollectionViewUtils::showStatusMsgSlot(int statusCode, QVariant &additional)
       
   168 {
       
   169     QString msg("");
       
   170     bool error(true);
       
   171     if(statusCode == VideoCollectionCommon::statusSingleDeleteFail)
       
   172     {
       
   173         QString format = tr("Unable to delete item %1. It is currently open.");
       
   174         if(additional.isValid())
       
   175         {
       
   176            msg = format.arg(additional.toString());
       
   177         }
       
   178     }
       
   179     else if(statusCode == VideoCollectionCommon::statusMultipleDeleteFail)
       
   180     {
       
   181         msg = tr("Unable to delete some items which are currently open.");
       
   182     }
       
   183     else if(statusCode == VideoCollectionCommon::statusMultipleDeleteSucceed)
       
   184     {
       
   185         QString format = tr("%1 videos deleted");
       
   186         if(additional.isValid())
       
   187         {
       
   188             msg = format.arg(additional.toString());
       
   189         }
       
   190         error = false;
       
   191     }
       
   192         
       
   193     if(msg.count() > 0)
       
   194     {
       
   195         if(error)
       
   196         {
       
   197             HbMessageBox::warning(msg);
       
   198         }
       
   199         else
       
   200         {
       
   201             HbMessageBox::information(msg);
       
   202         }
       
   203      
       
   204     }  
       
   205 }
       
   206 
       
   207 
       
   208