recents_plat/logs_engine_api/inc/logsmodel.h
changeset 0 4a5361db8937
child 2 7119b73b84d6
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 LOGSMODEL_H
       
    19 #define LOGSMODEL_H
       
    20 
       
    21 #include <logsexport.h>
       
    22 #include <logsabstractmodel.h>
       
    23 
       
    24 class LogsEvent;
       
    25 class LogsDbConnector;
       
    26 class LogsMatchesModel;
       
    27 
       
    28 /**
       
    29  * Model for log events.
       
    30  *
       
    31  */
       
    32 class LogsModel : public LogsAbstractModel
       
    33 {
       
    34     Q_OBJECT
       
    35     
       
    36 public:
       
    37     
       
    38     enum ClearType {
       
    39         TypeLogsClearAll = 0,
       
    40         TypeLogsClearReceived,
       
    41         TypeLogsClearCalled,
       
    42         TypeLogsClearMissed
       
    43     };
       
    44     
       
    45     enum LogsModelType {
       
    46         LogsRecentModel, // Model handles recent events
       
    47         LogsFullModel    // Model handles all events
       
    48     };
       
    49 public: // The exported API
       
    50 
       
    51     /**
       
    52      * Constructor
       
    53      * @param modelType
       
    54      * @param resourceControl, true will start model in compressed data mode
       
    55      *  where memory usage is minimized and refreshData call is required
       
    56      *  to get all available data
       
    57      */
       
    58     LOGSENGINE_EXPORT explicit LogsModel(
       
    59         LogsModelType modelType = LogsRecentModel, bool resourceControl = false);
       
    60     
       
    61     /**
       
    62      * Destructor
       
    63      */
       
    64     LOGSENGINE_EXPORT ~LogsModel();
       
    65 
       
    66     /**
       
    67      * Clear events. Clearing is async operation and completion is indicated
       
    68      * by clearingCompleted signal.
       
    69      * @param cleartype, type of events to be cleared
       
    70      * @return true if async clearing started
       
    71      */
       
    72     LOGSENGINE_EXPORT bool clearList(LogsModel::ClearType cleartype);
       
    73         
       
    74     /**
       
    75      * Get matches model.
       
    76      * @return matches model
       
    77      */
       
    78     LOGSENGINE_EXPORT LogsMatchesModel* logsMatchesModel();
       
    79     
       
    80     /**
       
    81      * Mark events as seen. Operation is asycn and completion is indicated
       
    82      * by markingCompleted signal.
       
    83      * @param cleartype, type of events to be marked as seen
       
    84      * @return true if async marking started, false if marking did not start
       
    85      */
       
    86     LOGSENGINE_EXPORT bool markEventsSeen(LogsModel::ClearType cleartype);
       
    87     
       
    88     /**
       
    89      * Clear missed calls counter
       
    90      * @return 0 if clearing was success
       
    91      */    
       
    92     LOGSENGINE_EXPORT int clearMissedCallsCounter();
       
    93     
       
    94     /**
       
    95      * Refresh data if it was compressed, can be used only if resourceControl
       
    96      * is enabled.
       
    97      * @return 0 if refreshed
       
    98      */
       
    99     LOGSENGINE_EXPORT int refreshData();
       
   100     
       
   101     /**
       
   102      * Compress data, minimizes memory usage, can be used only if resourceControl
       
   103      * is enabled.
       
   104      * @return 0 if compressed
       
   105      */
       
   106     LOGSENGINE_EXPORT int compressData();
       
   107     
       
   108     /**
       
   109      * Returns cenrep key status of predictive search feature. 
       
   110      * @return 0 - feature is permanently off and can't be turned on,
       
   111      *         1 - feature is on
       
   112      *         2 - feature is temporarily off and can be turned on 
       
   113      *         negative value indicates some error in fetching the key
       
   114      */
       
   115     LOGSENGINE_EXPORT int predictiveSearchStatus();
       
   116     
       
   117     /**
       
   118      * Allows to modify cenrep key value of predictive search features. 
       
   119      * However, this function can't be used if feature is set permanently off 
       
   120      * (see predictiveSearchStatus())
       
   121      * @param enabled, specify whether cenrep key will be set to 1 or 2
       
   122      * @ return 0 if cenrep key value modified succesfully,
       
   123      *          -1 in case of some error
       
   124      */
       
   125     LOGSENGINE_EXPORT int setPredictiveSearch(bool enabled);    
       
   126 
       
   127 public: // From QAbstractItemModel
       
   128     
       
   129     /**
       
   130      * Get number of events currently in the model.
       
   131      * @return number of events
       
   132      */
       
   133     virtual int rowCount(const QModelIndex &parent) const;
       
   134     
       
   135     /**
       
   136      * Get various data from the model. Fetched data type is defined
       
   137      * by role input parameter. Besides standard Qt::DisplayRole and
       
   138      * Qt::DecorationRole, LogsAbstractModel::LogsModelRole defines
       
   139      * additional data types.
       
   140      */
       
   141     virtual QVariant data(const QModelIndex &index, int role) const;
       
   142 
       
   143 signals:
       
   144     
       
   145     /**
       
   146      * Signaled once clearing has completed.
       
   147      * @param err, 0 if clearing was success
       
   148      */
       
   149     void clearingCompleted(int err);
       
   150     
       
   151     /**
       
   152      * Signaled once marking has completed.
       
   153      * @param err, 0 if marking was success
       
   154      */
       
   155     void markingCompleted(int err);
       
   156     
       
   157        
       
   158 public slots:
       
   159 
       
   160     void dataAdded(QList<int> addedIndexes);   
       
   161     void dataUpdated(QList<int> updatedIndexes);
       
   162     void dataRemoved(QList<int> removedIndexes);
       
   163 
       
   164 private:
       
   165     
       
   166     /**
       
   167      * Find sequential indexes and place each sequence to own list.
       
   168      * @param indexes, index list
       
   169      * @return list of index sequence lists
       
   170      */
       
   171     QList< QList<int> > findSequentialIndexes(const QList<int>& indexes); 
       
   172     QString getCallerId(const LogsEvent& event) const;
       
   173     void initIcons();
       
   174     bool matchEventWithClearType(const LogsEvent& event, LogsModel::ClearType clearType);
       
   175     
       
   176 private: //data 
       
   177     
       
   178     LogsModelType mModelType;
       
   179     QList<LogsEvent*> mEvents;
       
   180     
       
   181 private:  // Testing related friend definitions
       
   182     
       
   183     friend class UT_LogsModel;
       
   184     friend class UT_LogsFilter;
       
   185     friend class UT_LogsCustomFilter;
       
   186     friend class UT_LogsMatchesModel;
       
   187     
       
   188 };
       
   189 
       
   190 #endif //LOGSMODEL_H