phonebookengines/cntimageutility/src/cntorientationhelper.cpp
changeset 81 640d30f4fb64
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cntorientationhelper.h"
       
    19 #include <restricted/hbcorepskeys_r.h>
       
    20 
       
    21 CntOrientationHelper::CntOrientationHelper( QObject* parent ) : 
       
    22 QObject( parent ),
       
    23 mSettings( NULL ),
       
    24 mOrientationKey( NULL )
       
    25 {
       
    26     mSettings = new XQSettingsManager();
       
    27     
       
    28     mOrientationKey = new XQSettingsKey( XQSettingsKey::TargetPublishAndSubscribe, 
       
    29         KHbPsForegroundAppOrientationCategoryUid.iUid, 
       
    30         KHbPsForegroundAppOrientationKey);
       
    31     
       
    32     connect( mSettings, SIGNAL(valueChanged(const XQSettingsKey&, const QVariant&)),
       
    33              this, SLOT(emitOrientationChanged(const XQSettingsKey&, const QVariant&)) );
       
    34 
       
    35     int orientation = mSettings->readItemValue(*mOrientationKey, XQSettingsManager::TypeInt).toInt(); 
       
    36     mOrientation = Qt::Orientation(orientation & 0x7F);
       
    37 
       
    38     mSettings->startMonitoring( *mOrientationKey, XQSettingsManager::TypeInt );
       
    39 }
       
    40 
       
    41 CntOrientationHelper::~CntOrientationHelper()
       
    42 {
       
    43     mSettings->stopMonitoring( *mOrientationKey );
       
    44     
       
    45     delete mSettings;
       
    46     delete mOrientationKey;
       
    47 }
       
    48 
       
    49 Qt::Orientation& CntOrientationHelper::orientation()
       
    50 {
       
    51     return mOrientation;
       
    52 }
       
    53 
       
    54 void CntOrientationHelper::emitOrientationChanged( const XQSettingsKey& key, const QVariant& value )
       
    55 {
       
    56     if ( key.uid() == mOrientationKey->uid() && key.key() == mOrientationKey->key() ) 
       
    57     {
       
    58         bool ok;
       
    59         int orientation = value.toInt( &ok );
       
    60         if ( ok ) {
       
    61             // Bits 0-7 contain the Qt::Orientation value.
       
    62             // If bit 8 is set then the orientation is a fixed (forced) one.
       
    63             // If bit 8 is not set then the orientation is managed automatically by the framework.
       
    64             mOrientation = Qt::Orientation( orientation & 0x7F ); 
       
    65             emit orientationChanged( mOrientation );   
       
    66         }
       
    67     }
       
    68 }