controlpanelui/src/cpplugins/volumeplugin/src/cpvolumecontroller.cpp
changeset 12 624337f114fe
child 14 23411a3be0db
child 19 36aa4756ee82
equal deleted inserted replaced
11:10d0dd0e43f1 12:624337f114fe
       
     1 
       
     2 /*
       
     3  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4  * All rights reserved.
       
     5  * This component and the accompanying materials are made available
       
     6  * under the terms of "Eclipse Public License v1.0""
       
     7  * which accompanies this distribution, and is available
       
     8  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9  *
       
    10  * Initial Contributors:
       
    11  * Nokia Corporation - initial contribution.
       
    12  *
       
    13  * Contributors:
       
    14  *
       
    15  * Description:  
       
    16  *
       
    17  */
       
    18 
       
    19 #include "cpvolumecontroller.h"
       
    20 #include <cplogger.h>
       
    21 #include <cpitemdatahelper.h>
       
    22 #include <hbdataformmodelitem.h>
       
    23 #include "cpvolumegroupitemdata.h"
       
    24 #ifdef Q_OS_SYMBIAN
       
    25 	#include <cpprofilemodel.h>
       
    26 #endif
       
    27 //#include <hbslider.h>
       
    28 //#include <hbpushbutton.h>
       
    29 
       
    30 CpVolumeController::CpVolumeController(CpProfileModel *profileModel,
       
    31                                        const QList<HbDataFormModelItem *> &itemList,
       
    32                                        CpItemDataHelper &itemDataHelper): 
       
    33                                            mProfileModel(profileModel),
       
    34                                            mItemList(itemList)
       
    35 															 
       
    36 {
       
    37 	//itemDataHelper.addConnection(mMasterVolumeItem,SIGNAL(beepActivated()),this,SLOT(onBeepActivated()));
       
    38 	//itemDataHelper.addConnection(mMasterVolumeItem,SIGNAL(silentActivated()),this,SLOT(onSilentActivated()));
       
    39 	//itemDataHelper.addConnection(mMasterVolumeItem,SIGNAL(normalValueChanged(int)),this,SLOT(onNormalValueChanged(int)));
       
    40 	//updateMasterVolumeValue();
       
    41     itemDataHelper.addConnection(
       
    42                 mItemList.at(CpVolumeGroupItemData::EVolumeSilenceItem), SIGNAL(toggled(bool)),
       
    43                 this, SLOT(silenceModeChange(bool))
       
    44             );
       
    45     itemDataHelper.addConnection(
       
    46                 mItemList.at(CpVolumeGroupItemData::EVolumeMasterVolumeItem), SIGNAL(valueChanged(int)),
       
    47                 this, SLOT(masterVolumeChange(int))
       
    48             );
       
    49     itemDataHelper.addConnection(
       
    50                 mItemList.at(CpVolumeGroupItemData::EVolumeMasterVibraItem), SIGNAL(stateChanged(int)),
       
    51                 this, SLOT(masterVibraChange(int))
       
    52             );
       
    53     update();
       
    54 }
       
    55 
       
    56 CpVolumeController::~CpVolumeController()
       
    57 {
       
    58 
       
    59 }
       
    60 
       
    61 /*void CpMasterVolumeValueController::onBeepActivated()
       
    62 {
       
    63 #ifdef Q_OS_SYMBIAN
       
    64 	mProfileModel->activateBeep();
       
    65 #endif
       
    66 }*/
       
    67 
       
    68 void CpVolumeController::silenceModeChange(bool isSilence)
       
    69 {
       
    70 #ifdef Q_OS_SYMBIAN
       
    71 	mProfileModel->setSilenceMode(isSilence);
       
    72 	HbDataFormModelItem *masterVolume = mItemList.at(CpVolumeGroupItemData::EVolumeMasterVolumeItem);
       
    73     masterVolume->setEnabled(!isSilence);
       
    74 #endif
       
    75 }
       
    76 
       
    77 void CpVolumeController::masterVolumeChange(int value)
       
    78 {
       
    79 #ifdef Q_OS_SYMBIAN
       
    80 	mProfileModel->setMasterVolume( volumeLevelToInt( (CpVolumeController::VolumeLevel)value ) );
       
    81 	HbDataFormModelItem *masterVolume = mItemList.at(CpVolumeGroupItemData::EVolumeMasterVolumeItem);
       
    82 	masterVolume->setContentWidgetData("value",value);
       
    83 #endif
       
    84 }
       
    85 
       
    86 void CpVolumeController::masterVibraChange(int state)
       
    87 {
       
    88 #ifdef Q_OS_SYMBIAN
       
    89     mProfileModel->setMasterVibra(state);
       
    90 #endif
       
    91 }
       
    92 
       
    93 void CpVolumeController::update()
       
    94 {
       
    95 #ifdef Q_OS_SYMBIAN
       
    96 	bool isSilenceMode = mProfileModel->isSilenceMode();
       
    97 	HbDataFormModelItem *silenceIndicator = mItemList.at(CpVolumeGroupItemData::EVolumeSilenceItem);
       
    98 	silenceIndicator->setContentWidgetData("checked",isSilenceMode);
       
    99 	HbDataFormModelItem *masterVolume = mItemList.at(CpVolumeGroupItemData::EVolumeMasterVolumeItem);
       
   100 	if (masterVolume) {
       
   101 	    CPFW_LOG("::updateMasterVolumeValue(), Start using profile model.");
       
   102 	    QMap<QString, QVariant> iconMaps;
       
   103 	    if (isSilenceMode) {
       
   104 	        CPFW_LOG("::updateMasterVolumeValue(), Got silent state.");
       
   105 	        iconMaps.insert(QString("IconElement"), QVariant(":/icon/hb_vol_slider_muted.svg"));
       
   106 	    }
       
   107 	    else {
       
   108 	        iconMaps.insert(QString("IconElement"), QVariant(":/icon/hb_vol_slider_unmuted.svg"));
       
   109 	        CPFW_LOG("::updateMasterVolumeValue(), Got ring volume.");	        
       
   110 	    }
       
   111 	    masterVolume->setContentWidgetData("elementIcons", iconMaps);
       
   112 	    masterVolume->setEnabled(!isSilenceMode);
       
   113 	    //masterVolume->setContentWidgetData("enabled",!isSilenceMode);
       
   114 	    masterVolume->setContentWidgetData("value",intToVolumeLevel(mProfileModel->masterVolume()));
       
   115 	}
       
   116 	HbDataFormModelItem *masterVibra = mItemList.at(CpVolumeGroupItemData::EVolumeMasterVibraItem);
       
   117 	if (masterVibra) {
       
   118         masterVibra->setContentWidgetData("checkState",(mProfileModel->masterVibra()?2:0));
       
   119 	} 
       
   120 	
       
   121 #endif
       
   122 }
       
   123 
       
   124 int CpVolumeController::volumeLevelToInt( CpVolumeController::VolumeLevel volumeLevel )
       
   125 {
       
   126     switch( volumeLevel ){
       
   127         case VolumenLevelSoft:
       
   128             return 1;
       
   129         case VolumeLevelMed:
       
   130             return 5;
       
   131         case VolumeLevelLoud:
       
   132             return 10;
       
   133     }
       
   134 }
       
   135 CpVolumeController::VolumeLevel CpVolumeController::intToVolumeLevel( int value )
       
   136 {
       
   137     if( value < 4 ) {
       
   138         return VolumenLevelSoft;
       
   139     } else if( value < 8 )
       
   140         return VolumeLevelMed;
       
   141     else{
       
   142         return VolumeLevelLoud;
       
   143     }
       
   144 }