logsui/logsengine/tsrc/stubs/logscntfinder.h
changeset 27 de1630741fbe
parent 25 76a2435edfd4
child 28 3fad710701f2
child 31 2a11b5b00470
equal deleted inserted replaced
25:76a2435edfd4 27:de1630741fbe
     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 LOGSCNTFINDER_H
       
    19 #define LOGSCNTFINDER_H
       
    20 
       
    21 #include <QObject>
       
    22 #include <QList>
       
    23 #include <QString>
       
    24 #include <qtcontacts.h>
       
    25 
       
    26 QTM_USE_NAMESPACE
       
    27 
       
    28 class LogsCntEntry;
       
    29 typedef QObject LogsCntEntryHandle;
       
    30 
       
    31 
       
    32 class LogsCntText
       
    33 {
       
    34 public:
       
    35 
       
    36     inline LogsCntText() : mHighlights(0){}
       
    37     inline const QString& text() const {return mText;}
       
    38     inline int highlights() const {return mHighlights;}
       
    39     QString richText( QString startTag = QString("<b><u>"), 
       
    40                       QString endTag = QString("</u></b>")) const;
       
    41     
       
    42 private:
       
    43     
       
    44     QString mText;
       
    45     QString mTranslatedText;
       
    46     int mHighlights;
       
    47     
       
    48     friend class LogsCntEntry;
       
    49     friend class UT_LogsCntEntry;
       
    50     friend class UT_LogsCntFinder;
       
    51 };
       
    52 
       
    53 typedef QList<LogsCntText> LogsCntTextList;
       
    54 
       
    55 class LogsCntEntry
       
    56 {
       
    57 public:
       
    58 
       
    59     enum EntryType {
       
    60         EntryTypeHistory,
       
    61         EntryTypeContact
       
    62     };
       
    63     
       
    64     LogsCntEntry( LogsCntEntryHandle& handle, 
       
    65                                        quint32 cid );
       
    66     LogsCntEntry( quint32 cid );
       
    67     LogsCntEntry( const LogsCntEntry& entry );
       
    68     ~LogsCntEntry();
       
    69     EntryType type() const;
       
    70     const LogsCntTextList& firstName() const;
       
    71     const LogsCntTextList& lastName() const;
       
    72     const QString& avatarPath() const;
       
    73     quint32 contactId() const;
       
    74     LogsCntEntryHandle* handle() const;
       
    75     void setFirstName( const QString& name );
       
    76     void setLastName( const QString& name );
       
    77     const LogsCntText& phoneNumber() const;
       
    78     void setPhoneNumber( const QString& number );
       
    79     
       
    80     bool isCached() const;
       
    81     void setHighlights( const QString& pattern );
       
    82     bool match( const QString& pattern ) const;
       
    83 
       
    84 private:
       
    85     
       
    86     void doSetText( const QString& text, LogsCntTextList& textlist ); 
       
    87     bool doMatch( const QString& pattern, 
       
    88                   const LogsCntTextList& textlist ) const;
       
    89     
       
    90 private:
       
    91     
       
    92     EntryType mType;
       
    93     quint32 mCid;
       
    94     LogsCntTextList mFirstName;
       
    95     LogsCntTextList mLastName;
       
    96     bool mCached;
       
    97     LogsCntEntryHandle* mHandle;
       
    98     LogsCntText mPhoneNumber;
       
    99     QString mAvatarPath;
       
   100     
       
   101     friend class UT_LogsCntEntry;
       
   102     friend class UT_LogsCntFinder;
       
   103 };
       
   104 
       
   105 typedef QList<LogsCntEntry*> LogsCntEntryList;
       
   106     
       
   107 /**
       
   108  * Log events and contacts finder
       
   109  *
       
   110  */
       
   111 class LogsCntFinder : public QObject 
       
   112 {
       
   113 
       
   114     Q_OBJECT
       
   115     
       
   116 public: // The exported API
       
   117 
       
   118     LogsCntFinder();
       
   119     LogsCntFinder(QContactManager& contactManager);
       
   120     ~LogsCntFinder();
       
   121 
       
   122     /**
       
   123     * Starts/continues predictive query based on pattern. If
       
   124     * there is a previously executed query with same pattern, 
       
   125     * call is treated as continue query.
       
   126     * @param pattern the predictive pattern, containing digit(s)
       
   127     */
       
   128     void predictiveSearchQuery( const QString& pattern );
       
   129                                       
       
   130     /**
       
   131     * returns number of results
       
   132     * @return number of results
       
   133     */
       
   134     int resultsCount() const;
       
   135     
       
   136     /**
       
   137     * returns result at index
       
   138     * @param index the index
       
   139     */
       
   140     const LogsCntEntry& resultAt( int index );
       
   141     
       
   142     /**
       
   143     * Used for adding entiries to be part of a query
       
   144     * Ownership is transfered
       
   145     * @param entry the entry
       
   146     */
       
   147     void insertEntry( int index, LogsCntEntry* entry ); 
       
   148     
       
   149     /**
       
   150     * Used for updating entiries
       
   151     * @param handle the handle
       
   152     */
       
   153     LogsCntEntry* getEntry( const LogsCntEntryHandle& handle ) const; 
       
   154     
       
   155     /**
       
   156     * Used for updating entiries
       
   157     * @param entry the entry
       
   158     */
       
   159     void deleteEntry( const LogsCntEntryHandle& handle );
       
   160     
       
   161 signals:
       
   162 
       
   163     /**
       
   164     * emitted when query is ready
       
   165     */
       
   166     void queryReady();
       
   167     
       
   168 private:
       
   169 
       
   170     void doPredictiveHistoryQuery();
       
   171     void doPredictiveContactQuery();
       
   172     
       
   173     LogsCntEntry* doGetEntry( const LogsCntEntryList& list, 
       
   174                               const LogsCntEntryHandle& handle ) const;
       
   175     
       
   176     
       
   177 private:
       
   178     
       
   179     QString mCurrentPredictivePattern;
       
   180     LogsCntEntryList mResults;
       
   181     QContactManager* mContactManager;
       
   182     LogsCntEntryList mHistoryEvents;
       
   183     
       
   184     friend class UT_LogsMatchesModel;
       
   185     
       
   186 };
       
   187 
       
   188 #endif //LOGSCNTFINDER_H