File indexing completed on 2024-03-24 16:27:33
0001 /* 0002 * This file is part of TelepathyLoggerQt 0003 * 0004 * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/> 0005 * 0006 * This library is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU Lesser General Public License as published 0008 * by the Free Software Foundation; either version 2.1 of the License, or 0009 * (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "pending-clear.h" 0021 #include "entity.h" 0022 #include "_gen/cli-logger.h" 0023 0024 #include <TelepathyQt/Account> 0025 0026 #define TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME "org.freedesktop.Telepathy.Logger" 0027 #define TPL_DBUS_SRV_OBJECT_PATH "/org/freedesktop/Telepathy/Logger" 0028 0029 namespace Tpl { 0030 0031 PendingClear::PendingClear() 0032 : Tpl::PendingOperation() 0033 { 0034 mInterface = new Tpl::LoggerInterface(QDBusConnection::sessionBus(), 0035 TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME, 0036 TPL_DBUS_SRV_OBJECT_PATH); 0037 } 0038 0039 void PendingClear::setError(const QString &errorName, const QString &errorMessage) 0040 { 0041 Q_ASSERT(this->errorName.isEmpty()); 0042 Q_ASSERT(this->errorMessage.isEmpty()); 0043 0044 Q_ASSERT(!errorName.isEmpty()); 0045 0046 this->errorName = errorName; 0047 this->errorMessage = errorMessage; 0048 } 0049 0050 void PendingClear::finish() 0051 { 0052 if (errorName.isEmpty()) { 0053 setFinished(); 0054 } else { 0055 setFinishedWithError(errorName, errorMessage); 0056 } 0057 } 0058 0059 void PendingClear::clearLog() 0060 { 0061 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( 0062 mInterface->Clear()); 0063 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), 0064 this, 0065 SLOT(onLogCleared(QDBusPendingCallWatcher*))); 0066 } 0067 0068 void PendingClear::clearAccount(const Tp::AccountPtr &account) 0069 { 0070 QDBusObjectPath path = QDBusObjectPath(account->objectPath()); 0071 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( 0072 mInterface->ClearAccount(path)); 0073 0074 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), 0075 this, 0076 SLOT(onLogCleared(QDBusPendingCallWatcher*))); 0077 } 0078 0079 void PendingClear::clearContact(const Tp::AccountPtr &account, const QString &objectId) 0080 { 0081 QDBusObjectPath path = QDBusObjectPath(account->objectPath()); 0082 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( 0083 mInterface->ClearEntity(path, objectId, EntityTypeContact)); 0084 0085 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), 0086 this, 0087 SLOT(onLogCleared(QDBusPendingCallWatcher*))); 0088 } 0089 0090 void PendingClear::clearRoom(const Tp::AccountPtr &account, const QString &objectId) 0091 { 0092 QDBusObjectPath path = QDBusObjectPath(account->objectPath()); 0093 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( 0094 mInterface->ClearEntity(path, objectId, EntityTypeRoom)); 0095 0096 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), 0097 this, 0098 SLOT(onLogCleared(QDBusPendingCallWatcher*))); 0099 } 0100 0101 void PendingClear::onLogCleared(QDBusPendingCallWatcher *watcher) 0102 { 0103 QDBusPendingReply<> reply = *watcher; 0104 0105 if (!reply.isError()) { 0106 qDebug() << "PendingLogger:onLogCleared: Log has been cleared"; 0107 } else { 0108 qWarning().nospace() << "PendingLogger:onLogCleared: Clear log failed with " << 0109 reply.error().name() << ":" << reply.error().message(); 0110 } 0111 0112 if(!reply.isError()) { 0113 finish(); 0114 } else { 0115 setError(reply.error().name(), reply.error().message()); 0116 finish(); 0117 } 0118 0119 } 0120 0121 } 0122