camerauis/cameraxui/cxengine/src/cxeharvestercontrolsymbian.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24: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 #include <QString>
       
    18 #include "cxeerrormappingsymbian.h"
       
    19 #include "cxutils.h"
       
    20 #include "cxeharvestercontrolsymbian.h"
       
    21 
       
    22 
       
    23 
       
    24 /*!
       
    25 * CxeHarvesterControlSymbian::CxeHarvesterControlSymbian
       
    26 */
       
    27 CxeHarvesterControlSymbian::CxeHarvesterControlSymbian()
       
    28 : mHarvesterClientConnected(false),
       
    29   mRegisteredForHarvesterEvents(false)
       
    30 {
       
    31     CX_DEBUG_IN_FUNCTION();
       
    32 }
       
    33 
       
    34 
       
    35 /*!
       
    36 * CxeHarvesterControlSymbian::~CxeHarvesterControlSymbian
       
    37 */
       
    38 CxeHarvesterControlSymbian::~CxeHarvesterControlSymbian()
       
    39 {
       
    40     CX_DEBUG_ENTER_FUNCTION();
       
    41 
       
    42     deRegisterHarverterClientEvents();
       
    43 
       
    44     if (mHarvesterClientConnected) {
       
    45         mHarvesterClient.Close();
       
    46     }
       
    47 
       
    48     CX_DEBUG_EXIT_FUNCTION();
       
    49 }
       
    50 
       
    51 
       
    52 
       
    53 /*!
       
    54 * Calls MDS (Meta data system) harvester client to "harvest" files to
       
    55 * specific album and also to default "captured" album in photos.
       
    56 */
       
    57 CxeError::Id CxeHarvesterControlSymbian::harvestFile(const QString& filename,
       
    58                                                      bool addLocation,
       
    59                                                      quint32 albumId)
       
    60 {
       
    61     CX_DEBUG_ENTER_FUNCTION();
       
    62 
       
    63     TInt err = KErrNone;
       
    64     RArray<TUint32> harvestAlbumIds;
       
    65 
       
    66     if (albumId > 0) {
       
    67        err = harvestAlbumIds.Append(albumId);
       
    68     }
       
    69 
       
    70     if (!mHarvesterClientConnected) {
       
    71         err = mHarvesterClient.Connect();
       
    72         if (!err) {
       
    73             mHarvesterClientConnected = true;
       
    74         }
       
    75 
       
    76     }
       
    77 
       
    78     if (KErrNone == err) {
       
    79         registerForHarvesterEvents();
       
    80         TPtrC16 harvestFilename(reinterpret_cast<const TUint16*>(filename.utf16()));
       
    81         mHarvesterClient.HarvestFile(harvestFilename,
       
    82                                      harvestAlbumIds,
       
    83                                      addLocation);
       
    84     }
       
    85 
       
    86     harvestAlbumIds.Close();
       
    87 
       
    88     CX_DEBUG_EXIT_FUNCTION();
       
    89     return CxeErrorHandlingSymbian::map(err);
       
    90 }
       
    91 
       
    92 
       
    93 
       
    94 /*!
       
    95 * Call back method, which informs client about harvest complete events from MDS
       
    96 * harvester client
       
    97 */
       
    98 void CxeHarvesterControlSymbian::HarvestingComplete(TDesC& aURI ,TInt aError)
       
    99 {
       
   100     CX_DEBUG_ENTER_FUNCTION();
       
   101 
       
   102     QString uri = QString::fromUtf16(aURI.Ptr(),aURI.Length());
       
   103     CX_DEBUG(("Harvesting completed! error = %d, filename = %s", aError,
       
   104                                                                  uri.toAscii().constData()));
       
   105     // update the clients about the harvest complete event
       
   106     emit fileHarvested(CxeErrorHandlingSymbian::map(aError), uri);
       
   107 
       
   108     CX_DEBUG_EXIT_FUNCTION();
       
   109 }
       
   110 
       
   111 
       
   112 /*!
       
   113 * Helper method to de-register for harvester events
       
   114 */
       
   115 void CxeHarvesterControlSymbian::deRegisterHarverterClientEvents()
       
   116 {
       
   117     if (mRegisteredForHarvesterEvents && mHarvesterClientConnected) {
       
   118         mHarvesterClient.RemoveObserver(this);
       
   119         mRegisteredForHarvesterEvents = false;
       
   120     }
       
   121 }
       
   122 
       
   123 
       
   124 /*!
       
   125 * Helper method to register for harvester events
       
   126 */
       
   127 void CxeHarvesterControlSymbian::registerForHarvesterEvents()
       
   128 {
       
   129     if ( !mRegisteredForHarvesterEvents && mHarvesterClientConnected) {
       
   130         mHarvesterClient.SetObserver(this);
       
   131         mRegisteredForHarvesterEvents = true;
       
   132     }
       
   133 }