logsui/logsengine/logssymbianos/inc/logsdbconnector.h
changeset 0 4a5361db8937
child 6 41c0a814d878
equal deleted inserted replaced
-1:000000000000 0:4a5361db8937
       
     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 #ifndef LOGSDBCONNECTOR_H
       
    19 #define LOGSDBCONNECTOR_H
       
    20 
       
    21 //  INCLUDES
       
    22 #include <QObject>
       
    23 #include "logsengdefs.h"
       
    24 #include "logsreaderobserver.h"
       
    25 #include "logsremoveobserver.h"
       
    26 #include "logsmodel.h"
       
    27 // MACROS
       
    28 
       
    29 // DATA TYPES
       
    30 
       
    31 // FUNCTION PROTOTYPES
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class CLogClient;
       
    35 class LogsReader;
       
    36 class LogsEvent;
       
    37 class LogsRemove;
       
    38 class RFs;
       
    39 class CRepository;
       
    40 
       
    41 // CLASS DECLARATIONS
       
    42 
       
    43 
       
    44 /**
       
    45  * LogsDbConnector is used to initialize database access
       
    46  */
       
    47 class LogsDbConnector :  
       
    48     public QObject, public LogsReaderObserver, public LogsRemoveObserver
       
    49     {
       
    50     Q_OBJECT
       
    51     
       
    52     public:
       
    53 
       
    54         /**
       
    55          * Constructor
       
    56          * @param events, connector fills the array with events
       
    57          *  read from database. Ownership of events is not transferred.
       
    58          * @param checkAllEvents, true if interested in all events of the database,
       
    59          *  false if interested only in recent events
       
    60          */
       
    61         LogsDbConnector( QList<LogsEvent*>& events, bool checkAllEvents = false, bool resourceControl = false );
       
    62         ~LogsDbConnector();
       
    63         
       
    64     signals:
       
    65     
       
    66         /**
       
    67          * Signaled once some new data has been read from database.
       
    68          * Added data is placed to event array already when this signal
       
    69          * is emitted.
       
    70          * @param addedIndexes, indexes for new events
       
    71          */
       
    72         void dataAdded(QList<int> addedIndexes);   
       
    73         
       
    74         /**
       
    75          * Signaled once some data has been updated.
       
    76          * Corresponding events have been already updated at event array
       
    77          * when this signal is emitted.
       
    78          * @param updatedIndexes, indexes for updated events
       
    79          */
       
    80         void dataUpdated(QList<int> updatedIndexes);
       
    81         
       
    82         /**
       
    83          * Signaled once some data has been removed.
       
    84          * Corresponding events have been already removed from event array
       
    85          * when this signal is emitted.
       
    86          * @param removedIndexes, indexes for removed events
       
    87          */
       
    88         void dataRemoved(QList<int> removedIndexes);
       
    89         
       
    90         /**
       
    91          * Signaled once asycn event clearing has completed.
       
    92          * @param err, 0 if marking completed succesfully
       
    93          */
       
    94         void clearingCompleted(int err);
       
    95         
       
    96         /**
       
    97          * Signaled once asycn event marking has completed.
       
    98          * @param err, 0 if marking completed succesfully
       
    99          */
       
   100         void markingCompleted(int err);
       
   101         
       
   102         /**
       
   103          * Signaled once duplicate reading has completed.
       
   104          */
       
   105         void duplicatesRead();
       
   106 
       
   107     public:
       
   108         
       
   109         /**
       
   110          * Initialize database access
       
   111          * @return 0 if initialized succesfully
       
   112          */
       
   113 		int init();
       
   114 		
       
   115 		/**
       
   116          * Start reading data from database
       
   117          * @return 0 if reading started succesfully
       
   118          */
       
   119 		int start();
       
   120 		
       
   121         /**
       
   122 		 * Synchronously updates details (rematches from phonebook) for 
       
   123          * already read events
       
   124          * @param clearCached if true, cached matches will be cleaned before
       
   125          * rematching
       
   126          */
       
   127         int updateDetails(bool clearCached);
       
   128 		
       
   129         /**
       
   130          * Clear events of defined type. Clearing is async and completion is
       
   131          * indicated by clearingCompleted signal.
       
   132          * @return true if async clearing started 
       
   133          */
       
   134 		bool clearList(LogsModel::ClearType cleartype);
       
   135 		
       
   136         /**
       
   137          * Starts removing events and all their duplicates. Clearing
       
   138          * can be sync or async. In case of async, completion is
       
   139          * indicated by clearingCompleted signal.
       
   140          * @param eventIds, ids of the events to be removed
       
   141          * @return true if async clearing started
       
   142          */
       
   143         bool clearEvents(const QList<int>& eventIds);
       
   144         
       
   145         /**
       
   146          * Mark events as seen. Completion is indicated by
       
   147          * markingCompleted signal.
       
   148          * @param eventIds, ids of the events to be marked
       
   149          * @return true if marking started
       
   150          */
       
   151         bool markEventsSeen(const QList<int>& eventIds);
       
   152         
       
   153         /**
       
   154          * Clear missed calls counter.
       
   155          * @return 0 if clearing was success
       
   156          */
       
   157         int clearMissedCallsCounter();
       
   158         
       
   159         /**
       
   160          * Read duplicates for specified event
       
   161          * @param eventId
       
   162          * @return 0 if reading started succesfully
       
   163          */
       
   164         int readDuplicates(int eventId);
       
   165         
       
   166         /**
       
   167          * Take current duplicates.
       
   168          * @return list of duplicate events, ownership is transferred
       
   169          */
       
   170         QList<LogsEvent*> takeDuplicates();
       
   171         
       
   172         int refreshData();
       
   173         int compressData();
       
   174 		
       
   175         
       
   176         /**
       
   177          * Returns cenrep key status of predictive search feature. 
       
   178          * @return 0 - feature is permanently off and can't be turned on,
       
   179          *         1 - feature is on
       
   180          *         2 - feature is temporarily off and can be turned on 
       
   181          *         negative value indicates some error in fetching the key
       
   182          */
       
   183         int predictiveSearchStatus();
       
   184         
       
   185         /**
       
   186          * Allows to modify cenrep key value of predictive search features. 
       
   187          * However, this function can't be used if feature is set permanently off 
       
   188          * (see predictiveSearchStatus())
       
   189          * @param enabled, specify whether cenrep key will be set to 1 or 2
       
   190          * @ return 0 if cenrep key value modified succesfully,
       
   191          *          -1 in case of some error
       
   192          */
       
   193         int setPredictiveSearch(bool enabled);
       
   194         
       
   195         
       
   196     protected: // From LogsReaderObserver
       
   197         
       
   198         virtual void readCompleted(int readCount);
       
   199         virtual void errorOccurred(int err);
       
   200 		virtual void temporaryErrorOccurred(int err);
       
   201 		virtual void eventModifyingCompleted();
       
   202 		virtual void duplicatesReadingCompleted(QList<LogsEvent*> duplicates);
       
   203 		
       
   204 	protected: // From LogsRemoveObserver
       
   205 		virtual void removeCompleted();
       
   206 		virtual void logsRemoveErrorOccured(int err);
       
   207         
       
   208     private:
       
   209 		void initL();
       
   210 		void handleTemporaryError(int& error);
       
   211 		void deleteRemoved(int newEventCount);
       
   212 		int doMarkEventSeen();
       
   213 		bool handleModifyingCompletion(int err=0);
       
   214 
       
   215     private: // data
       
   216 
       
   217         QList<LogsEvent*>& mModelEvents;
       
   218         bool mCheckAllEvents;
       
   219         bool mResourceControl;
       
   220         CLogClient* mLogClient;
       
   221         LogsEventStrings mLogEventStrings;
       
   222         RFs* mFsSession;
       
   223         LogsReader* mReader;
       
   224         LogsRemove* mLogsRemove;
       
   225         CRepository* mRepository;
       
   226         bool mCompressionEnabled;
       
   227         
       
   228         QList<LogsEvent*> mEvents;
       
   229         QList<LogsEvent*> mDuplicatedEvents;
       
   230         QList<int> mRemovedEventIndexes;
       
   231         QList<int> mUpdatedEventIndexes;
       
   232         QList<int> mAddedEventIndexes;
       
   233         QList<int> mEventsSeen;
       
   234         
       
   235     private: // Testing related friend definitions
       
   236         
       
   237         friend class UT_LogsDbConnector;
       
   238         friend class UT_LogsRemove;
       
   239         friend class UT_LogsModel;
       
   240         friend class UT_LogsDetailsModel;
       
   241     
       
   242     };
       
   243 
       
   244             
       
   245 #endif
       
   246 
       
   247 // End of File  LOGSDBCONNECTOR_H