File indexing completed on 2024-04-28 08:54:36
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 * 0007 * This library is free software; you can redistribute it and/or modify 0008 * it under the terms of the GNU Lesser General Public License as published 0009 * by the Free Software Foundation; either version 2.1 of the License, or 0010 * (at your option) any later version. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public License 0018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include "log-manager.h" 0022 #include "entity.h" 0023 #include "log-walker.h" 0024 #include "pending-dates.h" 0025 #include "pending-entities.h" 0026 #include "pending-events.h" 0027 #include "pending-search.h" 0028 #include "pending-clear.h" 0029 #include "utils.h" 0030 0031 #include <TelepathyQt/Account> 0032 #include <TelepathyQt/AccountManager> 0033 0034 #include <telepathy-logger/log-manager.h> 0035 #include <telepathy-logger/entity.h> 0036 #include <telepathy-glib/account.h> 0037 0038 #include "_gen/cli-logger.h" 0039 #include "_gen/cli-logger-body.hpp" 0040 0041 using namespace Tpl; 0042 0043 LogManagerPtr LogManager::instance() 0044 { 0045 TplLogManager *manager = tpl_log_manager_dup_singleton(); 0046 return TPLoggerQtWrapper::wrap2<TplLogManager, LogManager>(manager, false); 0047 } 0048 0049 Tp::AccountManagerPtr LogManager::accountManagerPtr() const 0050 { 0051 return Utils::instance()->accountManagerPtr(); 0052 } 0053 0054 void LogManager::setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager) 0055 { 0056 Utils::instance()->setAccountManagerPtr(accountManager); 0057 } 0058 0059 bool LogManager::exists(const Tp::AccountPtr & account, const EntityPtr & target, 0060 EventTypeMask type) const 0061 { 0062 TpAccount *tpAccount = Utils::instance()->tpAccount(account); 0063 return tpl_log_manager_exists(object<TplLogManager>(), tpAccount, 0064 TPLoggerQtWrapper::unwrap<TplEntity, Entity>(target), (gint) type); 0065 } 0066 0067 PendingDates *LogManager::queryDates(const Tp::AccountPtr & account, const EntityPtr & entity, 0068 EventTypeMask typeMask) 0069 { 0070 return new PendingDates(LogManagerPtr(this), account, entity, typeMask); 0071 } 0072 0073 PendingEvents *LogManager::queryEvents(const Tp::AccountPtr & account, const EntityPtr & entity, 0074 EventTypeMask typeMask, const QDate & date) 0075 { 0076 return new PendingEvents(LogManagerPtr(this), account, entity, typeMask, date); 0077 } 0078 0079 PendingEvents *LogManager::queryFilteredEvents(const Tp::AccountPtr & account, 0080 const EntityPtr & entity, EventTypeMask typeMask, uint numEvents, 0081 LogEventFilter filterFunction, void *filterFunctionUserData) 0082 { 0083 return new PendingEvents(LogManagerPtr(this), account, entity, typeMask, numEvents, 0084 filterFunction, filterFunctionUserData); 0085 } 0086 0087 PendingEntities *LogManager::queryEntities(const Tp::AccountPtr & account) 0088 { 0089 return new PendingEntities(LogManagerPtr(this), account); 0090 } 0091 0092 PendingSearch *LogManager::search(const QString &text, EventTypeMask typeMask) 0093 { 0094 return new PendingSearch(LogManagerPtr(this), text, typeMask); 0095 } 0096 0097 PendingOperation *LogManager::clearHistory() 0098 { 0099 PendingClear *operation = new PendingClear(); 0100 0101 operation->clearLog(); 0102 0103 return operation; 0104 } 0105 0106 PendingOperation *LogManager::clearAccountHistory(const Tp::AccountPtr &account) 0107 { 0108 PendingClear *operation = new PendingClear(); 0109 0110 operation->clearAccount(account); 0111 0112 return operation; 0113 } 0114 0115 PendingOperation *LogManager::clearEntityHistory(const Tp::AccountPtr &account, const EntityPtr &entity) 0116 { 0117 PendingClear *operation = new PendingClear(); 0118 0119 if (entity->entityType() == EntityTypeContact) { 0120 operation->clearContact(account, entity->identifier()); 0121 } else if (entity->entityType() == EntityTypeRoom) { 0122 operation->clearRoom(account, entity->identifier()); 0123 } else { 0124 return 0; 0125 } 0126 0127 return operation; 0128 } 0129 0130 LogWalkerPtr LogManager::queryWalkFilteredEvents(const Tp::AccountPtr& account, 0131 const EntityPtr& entity, EventTypeMask typeMask, LogEventFilter filterFunction, 0132 void* filterFunctionUserData) 0133 { 0134 TpAccount *tpAccount = Utils::instance()->tpAccount(account); 0135 if (!tpAccount) { 0136 qWarning() << "Invalid account"; 0137 return LogWalkerPtr(); 0138 } 0139 0140 TplLogWalker *tpWalker = tpl_log_manager_walk_filtered_events( 0141 object<TplLogManager>(), tpAccount, 0142 TPLoggerQtWrapper::unwrap<TplEntity, Entity>(entity), 0143 (gint) typeMask, (TplLogEventFilter) filterFunction, 0144 filterFunctionUserData); 0145 return TPLoggerQtWrapper::wrap<TplLogWalker, LogWalker>(tpWalker, false); 0146 } 0147 0148 #if TPLQT_TPL_IS_VERSION(0, 9, 0) 0149 bool LogManager::disableForEntity(const Tp::AccountPtr &account, const EntityPtr &entity) 0150 { 0151 TpAccount *tpAccount = Utils::instance()->tpAccount(account); 0152 if (!tpAccount) { 0153 qWarning() << "Invalid account"; 0154 return false; 0155 } 0156 tpl_log_manager_disable_for_entity(LogManagerPtr(this), tpAccount, entity); 0157 0158 return true; 0159 } 0160 0161 bool LogManager::enableForEntity(const Tp::AccountPtr &account, const EntityPtr &entity) 0162 { 0163 TpAccount *tpAccount = Utils::instance()->tpAccount(account); 0164 if (!tpAccount) { 0165 qWarning() << "Invalid account"; 0166 return false; 0167 } 0168 tpl_log_manager_enable_for_entity(LogManagerPtr(this), tpAccount, entity); 0169 0170 return true; 0171 } 0172 0173 bool LogManager::isDisabledForEntity(const Tp::AccountPtr &account, const EntityPtr &entity) 0174 { 0175 TpAccount *tpAccount = Utils::instance()->tpAccount(account); 0176 if (!tpAccount) { 0177 qWarning() << "Invalid account"; 0178 return false; 0179 } 0180 0181 return tpl_log_manager_is_disabled_for_entity(LogManagerPtr(this), tpAccount, entity); 0182 } 0183 #endif