File indexing completed on 2023-12-03 08:28:33
0001 /* 0002 * Copyright (C) 2013 Daniel Vrátil <dvratil@redhat.com> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0017 * 0018 */ 0019 0020 #include "pending-logger-dates-impl.h" 0021 #include "abstract-logger-plugin.h" 0022 #include "debug.h" 0023 0024 PendingLoggerDatesImpl::PendingLoggerDatesImpl(const Tp::AccountPtr &account, 0025 const KTp::LogEntity &entity, 0026 QObject* parent): 0027 PendingLoggerDates(account, entity, parent) 0028 { 0029 if (plugins().isEmpty()) { 0030 emitFinished(); 0031 return; 0032 } 0033 0034 Q_FOREACH (KTp::AbstractLoggerPlugin *plugin, plugins()) { 0035 if (!plugin->handlesAccount(account)) { 0036 continue; 0037 } 0038 0039 PendingLoggerOperation *op = plugin->queryDates(account, entity); 0040 if (!op) { 0041 continue; 0042 } 0043 0044 connect(op, SIGNAL(finished(KTp::PendingLoggerOperation*)), 0045 this, SLOT(operationFinished(KTp::PendingLoggerOperation*))); 0046 mRunningOps << op; 0047 } 0048 } 0049 0050 PendingLoggerDatesImpl::~PendingLoggerDatesImpl() 0051 { 0052 } 0053 0054 void PendingLoggerDatesImpl::operationFinished(KTp::PendingLoggerOperation *op) 0055 { 0056 Q_ASSERT(mRunningOps.contains(op)); 0057 mRunningOps.removeAll(op); 0058 0059 KTp::PendingLoggerDates *operation = qobject_cast<KTp::PendingLoggerDates*>(op); 0060 Q_ASSERT(operation); 0061 0062 const QList<QDate> newDates = operation->dates(); 0063 QList<QDate> existingDates = dates(); 0064 qCDebug(KTP_LOGGER) << "Plugin" << op->parent() << "returned" << newDates.count() << "dates"; 0065 Q_FOREACH (const QDate &date, newDates) { 0066 if (!existingDates.contains(date)) { 0067 existingDates << date; 0068 } 0069 } 0070 0071 setDates(existingDates); 0072 0073 if (mRunningOps.isEmpty()) { 0074 QList<QDate> allDates = dates(); 0075 std::sort(allDates.begin(), allDates.end()); 0076 setDates(allDates); 0077 0078 emitFinished(); 0079 } 0080 }