File indexing completed on 2024-04-28 05:02:08

0001 /*
0002  * This file is part of TelepathyLoggerQt
0003  *
0004  * Copyright (C) 2011 Stefano Sanfilippo <stefano.k.sanfilippo@gmail.com>
0005  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
0006  * Copyright (C) 2013 Dan Vrátil <dvratil@redhat.com>
0007  *
0008  * This library is free software; you can redistribute it and/or modify
0009  * it under the terms of the GNU Lesser General Public License as published
0010  * by the Free Software Foundation; either version 2.1 of the License, or
0011  * (at your option) any later version.
0012  *
0013  * This program is distributed in the hope that it will be useful,
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016  * GNU General Public License for more details.
0017  *
0018  * You should have received a copy of the GNU Lesser General Public License
0019  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0020  */
0021 #ifndef _TelepathyLoggerQt_log_manager_h_HEADER_GUARD_
0022 #define _TelepathyLoggerQt_log_manager_h_HEADER_GUARD_
0023 
0024 #include <TelepathyLoggerQt_export.h>
0025 #include <TelepathyLogger_version.h>
0026 
0027 // Check TelepathyLogger version
0028 #ifndef TPLQT_TPL_IS_VERSION
0029 #define TPLQT_TPL_IS_VERSION(maj, min, patch) \
0030    (TelepathyLogger_VERSION_MAJOR > maj) \
0031 || (TelepathyLogger_VERSION_MAJOR == maj && TelepathyLogger_VERSION_MINOR > min) \
0032 || (TelepathyLogger_VERSION_MAJOR == maj && TelepathyLogger_VERSION_MINOR == min && TelepathyLogger_VERSION_PATCH >= patch)
0033 #endif
0034 
0035 #include "types.h"
0036 #include "object.h"
0037 
0038 namespace Tpl
0039 {
0040 
0041 /*!
0042  * \headerfile log-manager.h <TelepathyLoggerQt/LogManager>
0043  * \brief The LogManager object allows user to fetch logs and make searches.
0044  */
0045 class TELEPATHY_LOGGER_QT_EXPORT LogManager : public Tpl::Object
0046 {
0047 public:
0048     /*!
0049      * \brief Returns reference to a LogManager singleton
0050      */
0051     static LogManagerPtr instance();
0052 
0053     /*!
0054      * \brief Returns Tp::AccountManager assigned to the LogManager.
0055      */
0056     Tp::AccountManagerPtr accountManagerPtr() const;
0057 
0058     /*!
0059      * \brief Sets a new Tp::AccountManager to be used by the LogManager.
0060      *
0061      * The \p accountManager is expected to be in ready state.
0062      *
0063      * \param accountManager An Tp::AccountManager in the ready state.
0064      */
0065     void setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager);
0066 
0067     /*!
0068      * \brief Checks if logs exist for \p target.
0069      *
0070      * It applies for any registered readable log store.
0071      *
0072      * \param account An account to which the events should be associated
0073      * \param target Target to query
0074      * \param type Type of the events to query
0075      * \returns true when logs exist for \p target, otherwise false.
0076      */
0077     bool exists(const Tp::AccountPtr & account, const EntityPtr & target, EventTypeMask type) const;
0078 
0079     /*!
0080      * \brief Retrieves a list of dates corresponding to each day where
0081      * at least one event exist for \p target.
0082      *
0083      * \param account An account associated with the events
0084      * \param entity An entity to query
0085      * \param typeMask Type of events to query
0086      * \return Returns a PendingOperation that will emit finished() when
0087      * events were retrieved or an error occurs.
0088      */
0089     PendingDates *queryDates(const Tp::AccountPtr & account, const EntityPtr & entity,
0090         EventTypeMask typeMask);
0091 
0092     /*!
0093      * \brief Retrieves a list of events on given \p date for \p target.
0094      *
0095      * \param account An account associated with the events
0096      * \param entity An entity to query
0097      * \param typeMask Type of events to query
0098      * \param date A date for which to retrieve events
0099      * \return Returns a PendingOperation that will emit finished() when
0100      * events were retrieved or an error occurs.
0101      */
0102     PendingEvents *queryEvents(const Tp::AccountPtr & account, const EntityPtr & entity,
0103         EventTypeMask typeMask, const QDate & date);
0104 
0105     /*!
0106      * \brief Retrieves a list of events matching given filter.
0107      *
0108      * \param account An account associated with the events
0109      * \param entity An entity to query
0110      * \param typeMask Type of events to query
0111      * \param numEvents Maximum amount of events to fetch
0112      * \param filterFunction A filter function that will be called for every event to
0113      * check whether it matches the filter or not.
0114      * \param filterFunctionUserData An arbitrary user data to be passed to the \p filterFunction
0115      * with every call.
0116      * \return Returns a PendingOperation that will emit finished() when
0117      * events were retrieved has been rewound or an error occurs.
0118      */
0119     PendingEvents *queryFilteredEvents(const Tp::AccountPtr & account, const EntityPtr & entity,
0120         EventTypeMask typeMask, uint numEvents, LogEventFilter filterFunction,
0121         void *filterFunctionUserData = 0);
0122 
0123     /**
0124      * \brief Retrieves a list of entities associated with given \p account.
0125      *
0126      * \param account
0127      * \return Returns a PendingOperation that will emit finished() when
0128      * entities were retrieved or an error occurs.
0129      */
0130     PendingEntities *queryEntities(const Tp::AccountPtr & account);
0131 
0132     /**
0133      * \brief Retrieves a list of events matching given full-text filter
0134      *
0135      * \param text A pattern to search
0136      * \param typeMask Type of events to match
0137      * \return Returns a PendingOperation that will emit finished() when
0138      * entities were retrieved or an error occurs.
0139      */
0140     PendingSearch *search(const QString &text, EventTypeMask typeMask);
0141 
0142     /**
0143      * \brief Irreversibly deletes all logs.
0144      *
0145      * \return Returns a PendingOperation that will emit finished() when
0146      * all logs were deleted or an error occurs.
0147      */
0148     PendingOperation *clearHistory();
0149 
0150     /**
0151      * \brief Irreversibly deletes all logs associated with given \p account
0152      *
0153      * \param account
0154      * \return Returns a PendingOperation that will emit finished() when
0155      * logs were deleted or an error occurs.
0156      */
0157     PendingOperation *clearAccountHistory(const Tp::AccountPtr &account);
0158 
0159     /**
0160      * \brief Irreversibly delets all logs associated with given \p account and
0161      * \p entity.
0162      *
0163      * \param account
0164      * \param entity
0165      * \return Returns a PendingOperation that will emit finished() when
0166      * logs were deleted or an error occurs.
0167      */
0168     PendingOperation *clearEntityHistory(const Tp::AccountPtr &account, const Tpl::EntityPtr &entity);
0169 
0170     /**
0171      * \brief Creates a LogWalker to traverse all the events exchanged with \p target
0172      *
0173      * \param account An account associated with the events
0174      * \param entity An entity associated with the events
0175      * \param typeMask Type of events to query
0176      * \param filterFunction A filter function that will be called for every event to
0177      * check whether it matches the filter or not.
0178      * \param filterFunctionUserData An arbitrary user data to be passed to the
0179      * \p filterFunction with every call.
0180      * \return A new LogWalker.
0181      * \since 0.8.0
0182      */
0183     Tpl::LogWalkerPtr queryWalkFilteredEvents(const Tp::AccountPtr &account,
0184         const Tpl::EntityPtr &entity, EventTypeMask typeMask, LogEventFilter filterFunction,
0185         void *filterFunctionUserData = 0);
0186 
0187 #if TPLQT_TPL_IS_VERSION(0, 9, 0)
0188     /**
0189      * \brief Disables logging for given \p account and \p entity
0190      *
0191      * \param account
0192      * \param entity
0193      *
0194      * \return true if operation succeeds
0195      */
0196     bool disableForEntity(const Tp::AccountPtr &account, const EntityPtr &entity);
0197 
0198     /**
0199      * \brief Enables logging for given \p account and \p entity
0200      *
0201      * \param account
0202      * \param entity
0203      *
0204      * \return true if operation succeeds
0205      */
0206     bool enableForEntity(const Tp::AccountPtr &account, const EntityPtr &entity);
0207 
0208     /**
0209      * \brief Checks if logging is disabled for given \p account and \p entity
0210      *
0211      * \param account
0212      * \param entity
0213      *
0214      * \return true if logging is disabled for given \p account and \p entity
0215      */
0216     bool isDisabledForEntity(const Tp::AccountPtr &account, const EntityPtr &entity);
0217 #endif
0218 
0219 private:
0220     QTELEPATHYLOGGERQT_WRAPPER(LogManager)
0221 };
0222 
0223 } //namespace
0224 
0225 #endif