svgtopt/SVGTPlugin/src/RepositoryVolumeListener.cpp
branchRCL_3
changeset 39 1902ade171ab
equal deleted inserted replaced
38:db5c883ad1c5 39:1902ade171ab
       
     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:  AO that completes on a change in the volume property.  Used for 
       
    15 *                the new Central Repository Server.  Used in EKA2 builds only
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //#include <SharedDataClient.h>
       
    21 
       
    22 
       
    23 #include "RepositoryVolumeListener.h"
       
    24 //#include <SharedDataKeys.h> //include this file when KSDUidMediaVolumeControl and KMediaVolume will be needed
       
    25 //#include "epocdebug.h"
       
    26 #include <browseruisdkcrkeys.h>
       
    27 #include "MRepositoryVolumeObserver.h"
       
    28 
       
    29 CRepositoryVolumeListener* CRepositoryVolumeListener::NewL(MRepositoryVolumeObserver* aObserver)
       
    30     {
       
    31     CRepositoryVolumeListener* self = new(ELeave) CRepositoryVolumeListener;
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL(aObserver);
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37 
       
    38 CRepositoryVolumeListener::CRepositoryVolumeListener() : CActive(CActive::EPriorityStandard)
       
    39     {
       
    40     iState = EUnableToConnect;
       
    41     CActiveScheduler::Add(this) ; // add to active scheduler
       
    42     }
       
    43 
       
    44 void CRepositoryVolumeListener::ConstructL(MRepositoryVolumeObserver* aObserver)
       
    45     {
       
    46     //
       
    47     // Open a connection to the Central Repository...
       
    48     iCenRepos = CRepository::NewL(KCRUidBrowser);
       
    49 
       
    50     if ( iCenRepos->NotifyRequest(KBrowserMediaVolumeControl, iStatus) == KErrNone )
       
    51         {
       
    52         iState = EConnected;	
       
    53         SetActive();
       
    54         }
       
    55     else
       
    56         {
       
    57         iState = EUnableToConnect;
       
    58         }
       
    59 
       
    60     iObserver = aObserver;
       
    61     }
       
    62 
       
    63 CRepositoryVolumeListener::~CRepositoryVolumeListener()
       
    64     {
       
    65 	Cancel();
       
    66 	delete iCenRepos;  // close the client session
       
    67     }
       
    68 
       
    69 //
       
    70 // Get the current volume
       
    71 TInt CRepositoryVolumeListener::GetCurrentVolume()
       
    72     {
       
    73     TInt currentVolume = 0;
       
    74 
       
    75     if ( iState == EUnableToConnect )
       
    76         {
       
    77     	//
       
    78     	// Connection to CenRepos not available so return the default volume
       
    79     	currentVolume = GetDefaultVolume();
       
    80         }
       
    81     else
       
    82         {
       
    83     	//
       
    84     	// Get the current volume
       
    85     	if ( iCenRepos->Get(KBrowserMediaVolumeControl, currentVolume) != KErrNone )
       
    86             {
       
    87             // Error retrieving value... return default value
       
    88             //PLAYEROUTPUT("*ERROR* CRepositoryVolumeListener::GetCurrentVolume() - Unable to retreive volume value");
       
    89             currentVolume = GetDefaultVolume();
       
    90             }
       
    91         }
       
    92     
       
    93     return currentVolume;
       
    94     }
       
    95 
       
    96 //
       
    97 // Return the default volume in this case 2/3 of the max support by the system
       
    98 TInt CRepositoryVolumeListener::GetDefaultVolume()
       
    99     {
       
   100     TInt defaultVol = 0;
       
   101 
       
   102     #if defined(__WINS__)
       
   103         defaultVol = WINS_DEFAULT_VOLUME;
       
   104     #else
       
   105         defaultVol = HW_DEFAULT_VOLUME;
       
   106     #endif
       
   107 
       
   108     return defaultVol;
       
   109     }
       
   110 
       
   111 void CRepositoryVolumeListener::DoCancel()
       
   112     {
       
   113     iCenRepos->NotifyCancel(KBrowserMediaVolumeControl);
       
   114     }
       
   115 
       
   116 //
       
   117 // Activated when the watched value updates.
       
   118 void CRepositoryVolumeListener::RunL()
       
   119     {
       
   120     TInt currentVolume = 0;
       
   121 
       
   122     if (EUnableToConnect == iState)
       
   123         {
       
   124         return;
       
   125         }
       
   126 
       
   127     //
       
   128     // Get the current volume
       
   129     if ( iCenRepos->Get(KBrowserMediaVolumeControl, currentVolume) == KErrNone )
       
   130         {
       
   131         //
       
   132         // Inform the observer
       
   133         iObserver->VolumeChanged(currentVolume);
       
   134         if ( iCenRepos->NotifyRequest(KBrowserMediaVolumeControl, iStatus) == KErrNone )
       
   135             {
       
   136             SetActive();
       
   137             }
       
   138         else
       
   139             {
       
   140             iState = EUnableToConnect;
       
   141             }
       
   142         }
       
   143     else
       
   144         {
       
   145         //
       
   146         // error
       
   147         iState = EUnableToConnect;		
       
   148         }
       
   149 
       
   150     }