camerauis/cameraxui/cxengine/src/cxediskmonitorprivate.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 53 61bc0f252b2b
child 57 2c87b2808fd7
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
     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 <QObject> // Compiler flags, keep first
       
    19 #ifdef Q_OS_SYMBIAN
       
    20 #include <coemain.h>
       
    21 #endif // Q_OS_SYMBIAN
       
    22 #include "cxutils.h"
       
    23 #include "cxesysutil.h"
       
    24 #include "cxesettings.h"
       
    25 #include "cxediskmonitor.h"
       
    26 #include "cxediskmonitorprivate.h"
       
    27 
       
    28 
       
    29 namespace
       
    30 {
       
    31     const int MONITORING_INTERVAL = 2*1000; // in milliseconds
       
    32     const int UNKNOWN = -1;
       
    33 }
       
    34 
       
    35 
       
    36 /*!
       
    37 * Constructor.
       
    38 */
       
    39 CxeDiskMonitorPrivate::CxeDiskMonitorPrivate(CxeSettings &settings)
       
    40     : mSettings(settings),
       
    41       mTimer(),
       
    42 #ifdef Q_OS_SYMBIAN
       
    43       mFs(CCoeEnv::Static()->FsSession()),
       
    44       mCameraDrive(CxeSysUtil::getCameraDrive(mFs)),
       
    45 #endif // Q_OS_SYMBIAN
       
    46       mTriggerLevelBytes(UNKNOWN),
       
    47       mLatestFreeBytes(UNKNOWN)
       
    48 {
       
    49     CX_DEBUG_ENTER_FUNCTION();
       
    50     CX_DEBUG_EXIT_FUNCTION();
       
    51 }
       
    52 
       
    53 /*!
       
    54 * Destructor.
       
    55 */
       
    56 CxeDiskMonitorPrivate::~CxeDiskMonitorPrivate()
       
    57 {
       
    58     CX_DEBUG_ENTER_FUNCTION();
       
    59     stop();
       
    60     CX_DEBUG_EXIT_FUNCTION();
       
    61 }
       
    62 
       
    63 /*!
       
    64 * Slot for checking if the available disk space is below warning trigger level.
       
    65 */
       
    66 void CxeDiskMonitorPrivate::checkSpace()
       
    67 {
       
    68     CX_DEBUG_ENTER_FUNCTION();
       
    69 
       
    70     qint64 previousFree(mLatestFreeBytes);
       
    71 
       
    72     // Get the current free space.
       
    73     mLatestFreeBytes = free(false);
       
    74 
       
    75     // If space has changed during monitoring, signal it now.
       
    76     if (previousFree != mLatestFreeBytes && isMonitoring()) {
       
    77         CX_DEBUG(("CxeDiskMonitorPrivate - Disk space changed %d -> %d bytes", previousFree, mLatestFreeBytes));
       
    78         emit diskSpaceChanged();
       
    79     }
       
    80 
       
    81     // Only emit warning if trigger level is set to some positive value.
       
    82     // Otherwise updating cached free space value is enough.
       
    83     if (mTriggerLevelBytes != UNKNOWN && mLatestFreeBytes < mTriggerLevelBytes) {
       
    84         CX_DEBUG(("[WARNING] CxeDiskMonitorPrivate - Disk space low!"));
       
    85         emit diskSpaceLow();
       
    86     }
       
    87 
       
    88     CX_DEBUG_EXIT_FUNCTION();
       
    89 }
       
    90 
       
    91 /*!
       
    92 * Set the warning level of free disk space.
       
    93 * When free disk space falls below this limit, diskSpaceLow() signal is emitted.
       
    94 * @param bytes Limit in bytes.
       
    95 */
       
    96 void CxeDiskMonitorPrivate::setLowWarningLevel(qint64 bytes)
       
    97 {
       
    98     mTriggerLevelBytes = bytes;
       
    99 }
       
   100 
       
   101 /*!
       
   102 * Start monitoring disk space.
       
   103 */
       
   104 void CxeDiskMonitorPrivate::start()
       
   105 {
       
   106     if (!mTimer.isActive()) {
       
   107         connect(&mTimer, SIGNAL(timeout()), this, SLOT(checkSpace()), Qt::UniqueConnection);
       
   108         mTimer.start(MONITORING_INTERVAL);
       
   109     }
       
   110 }
       
   111 
       
   112 /*!
       
   113 * Stop monitoring disk space.
       
   114 */
       
   115 void CxeDiskMonitorPrivate::stop()
       
   116 {
       
   117     mTimer.stop();
       
   118     mLatestFreeBytes = UNKNOWN;
       
   119 }
       
   120 
       
   121 /*!
       
   122 * Is monitoring ongoing at the moment.
       
   123 */
       
   124 bool CxeDiskMonitorPrivate::isMonitoring() const
       
   125 {
       
   126     return mTimer.isActive();
       
   127 }
       
   128 
       
   129 /*!
       
   130 * Get free disk space for Camera use in bytes.
       
   131 * @param cached Can cached value be used.
       
   132 * If true (default value), value of last constant-interval-check is used (if it exists).
       
   133 * If false (or there's no cached value), forced reading of free space is done now.
       
   134 * This may cause significant delay compared to returning cached value.
       
   135 */
       
   136 qint64 CxeDiskMonitorPrivate::free(bool cached) const
       
   137 {
       
   138     qint64 value(0);
       
   139     if (cached && mLatestFreeBytes != UNKNOWN) {
       
   140         value = mLatestFreeBytes;
       
   141     } else {
       
   142         value = CxeSysUtil::spaceAvailable(mFs, mCameraDrive, mSettings);
       
   143     }
       
   144     return value;
       
   145 }
       
   146 
       
   147 // end of file