camerauis/cameraxui/cxengine/src/cxegeotaggingtrailprivate.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 56 01e205c615b9
equal deleted inserted replaced
37:64817133cd1d 48:42ba2d16bf40
     1 /*
       
     2 * Copyright (c) 2009-2010 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 "cxutils.h"
       
    19 #include "cxestate.h"
       
    20 #include "cxesettings.h"
       
    21 #include "cxenamespace.h"
       
    22 #include "cxestillcapturecontrol.h"
       
    23 #include "cxevideocapturecontrol.h"
       
    24 #include "cxegeotaggingtrailprivate.h"
       
    25 
       
    26 #include <locationtrailpskeys.h>
       
    27 
       
    28 
       
    29 
       
    30 namespace
       
    31 {
       
    32     // in milliseconds
       
    33     const int STOP_TRAIL_INTERVAL = 10*1000;
       
    34 }
       
    35 
       
    36 
       
    37 /*!
       
    38 * Constructor
       
    39 */
       
    40 CxeGeoTaggingTrailPrivate::CxeGeoTaggingTrailPrivate(CxeStillCaptureControl &stillControl, 
       
    41                                                      CxeVideoCaptureControl &videoControl,
       
    42                                                      CxeSettings &settings)
       
    43     : CxeStateMachine("CxeGeoTaggingTrailPrivate"),
       
    44       mStillCaptureControl(stillControl),
       
    45       mVideoCaptureControl(videoControl),
       
    46       mSettings(settings),
       
    47       mStopLocationTrailTimer(),
       
    48       mPendingStopTrailSession(false)
       
    49 {
       
    50     CX_DEBUG_ENTER_FUNCTION();
       
    51 
       
    52     qRegisterMetaType<CxeGeoTaggingTrail::State>();
       
    53     initializeStates();
       
    54 
       
    55 #if defined(Q_OS_SYMBIAN)
       
    56 
       
    57     QVariant locationTrailState;
       
    58     // Get initial location trail state.
       
    59     mSettings.get(KPSUidLocationTrail.iUid, KLocationTrailState, 
       
    60                   Cxe::PublishAndSubscribe, locationTrailState);
       
    61 
       
    62     connect(&mSettings, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
       
    63             this, SLOT(handleGeoTaggingPropertyEvent(long int, unsigned long int, QVariant)));
       
    64 
       
    65 #endif
       
    66 
       
    67     connect(&mSettings, SIGNAL(settingValueChanged(const QString&,QVariant)),
       
    68             this, SLOT(handleSettingValueChanged(const QString&,QVariant)));
       
    69     
       
    70     connect(&mStopLocationTrailTimer, SIGNAL(timeout()),
       
    71             this, SLOT(timeout()), Qt::UniqueConnection);    
       
    72    
       
    73     CX_DEBUG_EXIT_FUNCTION();
       
    74 }
       
    75 
       
    76 /*!
       
    77 * Destructor
       
    78 */
       
    79 CxeGeoTaggingTrailPrivate::~CxeGeoTaggingTrailPrivate()
       
    80 {
       
    81     CX_DEBUG_ENTER_FUNCTION();
       
    82 
       
    83     // stop trail and close location utility session
       
    84     stop(true);
       
    85 
       
    86     CX_DEBUG_EXIT_FUNCTION();
       
    87 }
       
    88 
       
    89 
       
    90 /*!
       
    91 * Start location trail.
       
    92 */
       
    93 void CxeGeoTaggingTrailPrivate::start()
       
    94 {
       
    95     CX_DEBUG_ENTER_FUNCTION();
       
    96 
       
    97 #if defined(Q_OS_SYMBIAN)
       
    98 
       
    99     int err = KErrNone;
       
   100     int settingValue = Cxe::GeoTaggingOff;
       
   101     mSettings.get(CxeSettingIds::GEOTAGGING, settingValue);
       
   102     
       
   103     if (settingValue == Cxe::GeoTaggingOn) {
       
   104         // geotagging setting is ON, trying to start location trail
       
   105         if (state() == CxeGeoTaggingTrail::NotConnected) {
       
   106             err = mLocationTrail.Connect();
       
   107             if (!err) {
       
   108                 CX_DEBUG(("CxeGeoTaggingTrail <> location trail connected"));
       
   109                 setState(CxeGeoTaggingTrail::Connected);
       
   110             }
       
   111         }
       
   112     
       
   113         if (state() == CxeGeoTaggingTrail::Connected && !err) {
       
   114             err = mLocationTrail.StartLocationTrail(RLocationTrail::ECaptureAll);
       
   115             if (!err) {
       
   116                 CX_DEBUG(("CxeGeoTaggingTrail <> starting location trail"));
       
   117                 mStopLocationTrailTimer.stop(); // stop location timer.
       
   118                 setState(CxeGeoTaggingTrail::TrailStarted);
       
   119             }
       
   120         }
       
   121 
       
   122         if (err) {
       
   123             CX_DEBUG(("CxeGeoTaggingTrailPrivate::start <> FAILED: error = %d ", err));
       
   124             stop(true);
       
   125         }        
       
   126     } else {
       
   127         // geotagging setting off, do nothing.
       
   128         CX_DEBUG(("CxeGeoTaggingTrail <> start -- Geotagging setting OFF, do nothing.."));
       
   129     }
       
   130 
       
   131 #endif
       
   132 
       
   133     CX_DEBUG_EXIT_FUNCTION();
       
   134 }
       
   135 
       
   136 
       
   137 
       
   138 
       
   139 /*!
       
   140 * Stop location trail.
       
   141 * @ param closeSession, indicates if we are willing to close the location utility session.
       
   142 */
       
   143 void CxeGeoTaggingTrailPrivate::stop(bool closeSession)
       
   144 {
       
   145     CX_DEBUG_ENTER_FUNCTION();
       
   146 
       
   147 #if defined(Q_OS_SYMBIAN)
       
   148 
       
   149     bool ok2StopTrail = canStopTrail();
       
   150 
       
   151     if (ok2StopTrail) {
       
   152 
       
   153         if (state() == CxeGeoTaggingTrail::TrailStarted ||
       
   154             state() == CxeGeoTaggingTrail::DataAvailable) {
       
   155             CX_DEBUG(("CxeGeoTaggingTrailPrivate::StopLocationTrail"));
       
   156             // stop location trail timer.
       
   157             mStopLocationTrailTimer.stop();
       
   158             mLocationTrail.StopLocationTrail();
       
   159             setState(CxeGeoTaggingTrail::Connected);
       
   160         }
       
   161         
       
   162         if (closeSession && state() == CxeGeoTaggingTrail::Connected) {
       
   163             CX_DEBUG(("CxeGeoTaggingTrailPrivate <> disconnect location trail utility"));
       
   164             mLocationTrail.Close();
       
   165             setState(CxeGeoTaggingTrail::NotConnected);
       
   166         }
       
   167     } else {
       
   168         // not ready to stop the location trail, TrailStarted the timer.
       
   169         if (!mPendingStopTrailSession) {
       
   170             mPendingStopTrailSession = closeSession;
       
   171         }
       
   172         mStopLocationTrailTimer.start(STOP_TRAIL_INTERVAL);
       
   173     }
       
   174     
       
   175 #endif
       
   176     
       
   177     CX_DEBUG_EXIT_FUNCTION();
       
   178 }
       
   179 
       
   180 
       
   181 
       
   182 /*!
       
   183 * Checking possible stillcapturecontrol/videocapturecontrol states for stopping
       
   184 * location trail.
       
   185 */
       
   186 bool CxeGeoTaggingTrailPrivate::canStopTrail() const
       
   187 {
       
   188     // checking still capture control states
       
   189     bool ok = mStillCaptureControl.state() != CxeStillCaptureControl::Capturing;
       
   190     
       
   191     // Still side OK, checking video capture control states
       
   192     if (ok) {
       
   193         ok = (mVideoCaptureControl.state() != CxeVideoCaptureControl::Recording &&
       
   194               mVideoCaptureControl.state() != CxeVideoCaptureControl::Paused &&
       
   195               mVideoCaptureControl.state() != CxeVideoCaptureControl::Stopping);
       
   196     }
       
   197 
       
   198     return ok;
       
   199 }
       
   200 
       
   201 
       
   202 
       
   203 /*!
       
   204 * Slot that is called when timer timeout signal is triggered. We track this to do pending
       
   205 * stopping of location trail.
       
   206 */
       
   207 void CxeGeoTaggingTrailPrivate::timeout()
       
   208 {
       
   209     CX_DEBUG_ENTER_FUNCTION();
       
   210     
       
   211     // stop the pending location trail utility
       
   212     stop(mPendingStopTrailSession);
       
   213     
       
   214     CX_DEBUG_EXIT_FUNCTION();
       
   215 }
       
   216 
       
   217 
       
   218 
       
   219 
       
   220 /*!
       
   221 * Handle new setting value.
       
   222 * Check if the geotagging setting has changed.
       
   223 */
       
   224 void CxeGeoTaggingTrailPrivate::handleSettingValueChanged(const QString& settingId, QVariant newValue)
       
   225 {
       
   226     CX_DEBUG_ENTER_FUNCTION();
       
   227     
       
   228     if (settingId == CxeSettingIds::GEOTAGGING) {
       
   229         if (newValue.toInt() == Cxe::GeoTaggingOn) {
       
   230             // setting is turned ON, start location trail
       
   231             start();
       
   232         } else {
       
   233             // setting is turned OFF, stopping location trail
       
   234             stop();
       
   235         }
       
   236     } else if (settingId == CxeSettingIds::GEOTAGGING_DISCLAIMER) {
       
   237         if (newValue.toInt() == Cxe::GeoTaggingDisclaimerDisabled) {
       
   238             // geotagging disclaimer is diabled, we can start location trail.
       
   239             start();
       
   240         }
       
   241     }
       
   242     
       
   243     CX_DEBUG_EXIT_FUNCTION();
       
   244 }
       
   245 
       
   246 
       
   247 /*!
       
   248 * Handle new setting value.
       
   249 * Check if the geotagging setting has changed.
       
   250 */
       
   251 void CxeGeoTaggingTrailPrivate::handleGeoTaggingPropertyEvent(long int uid,
       
   252                                                               unsigned long int key,
       
   253                                                               QVariant value)
       
   254 {
       
   255     CX_DEBUG_ENTER_FUNCTION();
       
   256 
       
   257 #if defined(Q_OS_SYMBIAN)
       
   258 
       
   259     if (uid == KPSUidLocationTrail.iUid && key == KLocationTrailState) {
       
   260         CX_DEBUG(("Location trail: new state = %d ", value.toInt()));
       
   261 
       
   262         RLocationTrail::TTrailState newState = 
       
   263                 static_cast<RLocationTrail::TTrailState>(value.toInt());
       
   264 
       
   265         if (newState == RLocationTrail::ETrailStarted) {
       
   266             CX_DEBUG(("CxeGeoTaggingTrail <> location trail started, data available."));
       
   267             setState(CxeGeoTaggingTrail::DataAvailable);
       
   268         } else {
       
   269            // ignoring all other state changes.
       
   270         }
       
   271     }
       
   272 
       
   273 #endif
       
   274 
       
   275     CX_DEBUG_EXIT_FUNCTION();
       
   276 }
       
   277 
       
   278 
       
   279 
       
   280 /*!
       
   281 Returns current state of Location trail
       
   282 */
       
   283 CxeGeoTaggingTrail::State CxeGeoTaggingTrailPrivate::state() const
       
   284 {
       
   285     return static_cast<CxeGeoTaggingTrail::State> (stateId());
       
   286 }
       
   287 
       
   288 
       
   289 
       
   290 /*!
       
   291 * slot called when state is changed.
       
   292 */
       
   293 void CxeGeoTaggingTrailPrivate::handleStateChanged(int newStateId, CxeError::Id error)
       
   294 {
       
   295     emit stateChanged(static_cast<CxeGeoTaggingTrail::State> (newStateId), error);
       
   296     
       
   297 }
       
   298 
       
   299 
       
   300 /*!
       
   301 * Initialize states for geotaggingtrail
       
   302 */
       
   303 void CxeGeoTaggingTrailPrivate::initializeStates()
       
   304 {
       
   305     // addState( id, name, allowed next states )
       
   306     addState(new CxeState(CxeGeoTaggingTrail::NotConnected, "NotConnected", CxeGeoTaggingTrail::Connected));
       
   307     
       
   308     addState(new CxeState(CxeGeoTaggingTrail::Connected, "Connected", CxeGeoTaggingTrail::TrailStarted | 
       
   309                                                                       CxeGeoTaggingTrail::NotConnected));
       
   310     
       
   311     addState(new CxeState(CxeGeoTaggingTrail::TrailStarted, "TrailStarted", CxeGeoTaggingTrail::DataAvailable |
       
   312                                                                             CxeGeoTaggingTrail::Connected |
       
   313                                                                             CxeGeoTaggingTrail::NotConnected));
       
   314     
       
   315     addState(new CxeState(CxeGeoTaggingTrail::DataAvailable, "DataAvailable", CxeGeoTaggingTrail::Connected | 
       
   316                                                                               CxeGeoTaggingTrail::NotConnected));
       
   317     
       
   318 
       
   319     setInitialState(CxeGeoTaggingTrail::NotConnected);
       
   320 }
       
   321 
       
   322 // end of file