Commit 2ab50b0d authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Port LogViewer and text-ui to KTp Logger

ktp-text-ui no longer depends on TelepathyLoggerQt now.

REVIEW: 112006
BUG: 323981
parent 2c8ff0f0
......@@ -15,11 +15,6 @@ set(KDE_MIN_VERSION "4.4.75")
find_package (KDE4 ${KDE_MIN_VERSION} REQUIRED)
find_package (TelepathyQt4 0.9.1 REQUIRED)
find_package (KTp REQUIRED)
find_package (TelepathyLoggerQt4 0.7.95 QUIET)
macro_log_feature(TELEPATHY_LOGGER_QT4_FOUND "TelepatyLoggerQt4" "Qt bindings for TelepathyLogger. This is needed to provide access to chat logs. HIGHLY recommended" "http://projects.kde.org/telepathy-logger-qt" FALSE "" "")
macro_display_feature_log()
# FUTURE: When we can depend on KDE 4.10, use emoticoncontexteditaction from here
# find_package(KdepimLibs 4.10 REQUIRED)
......@@ -42,15 +37,10 @@ add_definitions (${KDE4_DEFINITIONS}
configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if (TELEPATHY_LOGGER_QT4_FOUND)
add_definitions(${TELEPATHY_LOGGER_QT4_DEFINITIONS} -DHAVE_TPLOGGERQT)
include_directories(${TELEPATHY_LOGGER_QT4_INCLUDE_DIRS})
add_subdirectory(logviewer)
endif (TELEPATHY_LOGGER_QT4_FOUND)
add_subdirectory(lib)
add_subdirectory(app)
add_subdirectory(config)
add_subdirectory(data)
add_subdirectory(adiumxtra-protocol-handler)
add_subdirectory(filters)
add_subdirectory(logviewer)
......@@ -4,6 +4,7 @@
# KTP_LIBRARIES
# KTP_MODELS_LIBRARIES
# KTP_WIDGETS_LIBRARIES
# KTP_LOGGER_LIBRARIES
# Copyright (c) 2011, Dario Freddi <drf@kde.org>
#
......@@ -28,6 +29,7 @@ find_path(KTP_INCLUDE_DIR
find_library(KTP_LIBRARIES NAMES ktpcommoninternalsprivate )
find_library(KTP_MODELS_LIBRARIES NAMES ktpmodelsprivate )
find_library(KTP_WIDGETS_LIBRARIES NAMES ktpwidgetsprivate )
find_library(KTP_LOGGER_LIBRARIES NAMES ktploggerprivate )
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(KTp DEFAULT_MSG
......
......@@ -15,6 +15,7 @@ set(ktpchat_SRCS
chat-search-bar.cpp
notify-filter.cpp
text-chat-config.cpp
logmanager.cpp
)
set(ktpchat_HDRS
......@@ -47,18 +48,6 @@ set(ktpchat_UI
chat-widget.ui
)
if (TELEPATHY_LOGGER_QT4_FOUND)
set(ktpchat_SRCS
${ktpchat_SRCS}
logmanager.cpp
)
else (TELEPATHY_LOGGER_QT4_FOUND)
set(ktpchat_SRCS
${ktpchat_SRCS}
logmanager_dummy.cpp
)
endif (TELEPATHY_LOGGER_QT4_FOUND)
kde4_add_ui_files(ktpchat_SRCS ${ktpchat_UI})
kde4_add_library(ktpchat SHARED ${ktpchat_SRCS})
......@@ -71,7 +60,7 @@ target_link_libraries(ktpchat
${KDE4_KDEWEBKIT_LIBRARY}
${KDE4_KEMOTICONS_LIBS}
${KTP_LIBRARIES}
${TELEPATHY_LOGGER_QT4_LIBRARIES}
${KTP_LOGGER_LIBRARIES}
)
install(TARGETS ktpchat ${INSTALL_TARGETS_DEFAULT_ARGS})
......
/*
Copyright (C) 2011 Dominik Schmidt <kde@dominik-schmidt.de>
Copyright (C) 2013 Daniel Vrátil <dvratil@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -22,17 +23,13 @@
#include "adium-theme-content-info.h"
#include <KTp/message-processor.h>
#include <KTp/Logger/log-entity.h>
#include <KTp/Logger/log-manager.h>
#include <KTp/Logger/pending-logger-dates.h>
#include <KTp/Logger/pending-logger-logs.h>
#include <KDebug>
#include <TelepathyLoggerQt4/Init>
#include <TelepathyLoggerQt4/LogWalker>
#include <TelepathyLoggerQt4/Entity>
#include <TelepathyLoggerQt4/PendingEvents>
#include <TelepathyLoggerQt4/Event>
#include <TelepathyLoggerQt4/TextEvent>
#include <TelepathyLoggerQt4/LogManager>
#include <TelepathyQt/Types>
#include <TelepathyQt/AvatarData>
#include <TelepathyQt/TextChannel>
......@@ -47,8 +44,7 @@ class LogManager::Private
Tp::AccountPtr account;
Tp::TextChannelPtr textChannel;
Tpl::EntityPtr contactEntity;
Tpl::LogManagerPtr logManager;
KTp::LogEntity contactEntity;
int scrollbackLength;
};
......@@ -56,13 +52,6 @@ LogManager::LogManager(QObject *parent)
: QObject(parent),
d(new Private)
{
Tpl::init();
d->logManager = Tpl::LogManager::instance();
if (d->logManager.isNull()) {
qWarning() << "LogManager not found";
Q_ASSERT(false);
}
}
LogManager::~LogManager()
......@@ -76,24 +65,27 @@ bool LogManager::exists() const
return false;
}
Tpl::EntityPtr contactEntity;
if (d->textChannel->targetHandleType() == Tp::HandleTypeContact) {
contactEntity = Tpl::Entity::create(d->textChannel->targetContact()->id().toLatin1().data(),
Tpl::EntityTypeContact, NULL, NULL);
} else if (d->textChannel->targetHandleType() == Tp::HandleTypeRoom) {
contactEntity = Tpl::Entity::create(d->textChannel->targetId().toLatin1().data(),
Tpl::EntityTypeRoom, NULL, NULL);
} else {
return false;
}
return d->logManager->exists(d->account, contactEntity, Tpl::EventTypeMaskText);
return KTp::LogManager::instance()->logsExist(d->account, d->contactEntity);
}
void LogManager::setTextChannel(const Tp::AccountPtr &account, const Tp::TextChannelPtr &textChannel)
{
d->textChannel = textChannel;
d->account = account;
if (d->account.isNull() || d->textChannel.isNull()) {
return;
}
KTp::LogEntity contactEntity;
if (d->textChannel->targetHandleType() == Tp::HandleTypeContact) {
d->contactEntity = KTp::LogEntity(d->textChannel->targetHandleType(),
d->textChannel->targetContact()->id(),
d->textChannel->targetContact()->alias());
} else if (d->textChannel->targetHandleType() == Tp::HandleTypeRoom) {
d->contactEntity = KTp::LogEntity(d->textChannel->targetHandleType(),
d->textChannel->targetId());
}
}
void LogManager::setScrollbackLength(int n)
......@@ -114,21 +106,11 @@ void LogManager::fetchScrollback()
void LogManager::fetchHistory(int n)
{
if (n > 0 && !d->account.isNull() && !d->textChannel.isNull()) {
Tpl::EntityPtr contactEntity;
if (d->textChannel->targetHandleType() == Tp::HandleTypeContact) {
contactEntity = Tpl::Entity::create(d->textChannel->targetContact()->id().toLatin1().data(),
Tpl::EntityTypeContact, NULL, NULL);
} else if (d->textChannel->targetHandleType() == Tp::HandleTypeRoom) {
contactEntity = Tpl::Entity::create(d->textChannel->targetId().toLatin1().data(),
Tpl::EntityTypeRoom, NULL, NULL);
}
if (!contactEntity.isNull()) {
Tpl::LogWalkerPtr walker = d->logManager->queryWalkFilteredEvents(
d->account, contactEntity, Tpl::EventTypeMaskText, 0, 0);
Tpl::PendingEvents *events = walker->queryEvents(n);
connect(events, SIGNAL(finished(Tpl::PendingOperation*)),
this, SLOT(onEventsFinished(Tpl::PendingOperation*)));
if (d->contactEntity.isValid()) {
KTp::LogManager *manager = KTp::LogManager::instance();
KTp::PendingLoggerDates *dates = manager->queryDates(d->account, d->contactEntity);
connect(dates, SIGNAL(finished(KTp::PendingLoggerOperation*)),
this, SLOT(onDatesFinished(KTp::PendingLoggerOperation*)));
return;
}
}
......@@ -138,45 +120,44 @@ void LogManager::fetchHistory(int n)
Q_EMIT fetched(messages);
}
bool operator<(const Tpl::EventPtr &e1, const Tpl::EventPtr &e2)
{
return e1->timestamp() < e2->timestamp();
}
void LogManager::onEventsFinished(Tpl::PendingOperation *po)
void LogManager::onDatesFinished(KTp::PendingLoggerOperation* po)
{
Tpl::PendingEvents *pe = (Tpl::PendingEvents*) po;
if (pe->isError()) {
qWarning() << "error in PendingEvents" << pe->errorMessage();
KTp::PendingLoggerDates *datesOp = qobject_cast<KTp::PendingLoggerDates*>(po);
if (datesOp->hasError()) {
kWarning() << "Failed to fetch dates:" << datesOp->error();
Q_EMIT fetched(QList<KTp::Message>());
return;
}
QStringList queuedMessageTokens;
if (!d->textChannel.isNull()) {
Q_FOREACH(const Tp::ReceivedMessage &message, d->textChannel->messageQueue()) {
queuedMessageTokens.append(message.messageToken());
}
const QList<QDate> dates = datesOp->dates();
if (dates.isEmpty()) {
Q_EMIT fetched(QList<KTp::Message>());
return;
}
kDebug() << "queuedMessageTokens" << queuedMessageTokens;
// get last n (d->fetchLast) messages that are not queued
QList<Tpl::EventPtr> allEvents = pe->events();
KTp::LogManager *manager = KTp::LogManager::instance();
KTp::PendingLoggerLogs *logs = manager->queryLogs(datesOp->account(), datesOp->entity(),
dates.last());
connect(logs, SIGNAL(finished(KTp::PendingLoggerOperation*)),
this, SLOT(onEventsFinished(KTp::PendingLoggerOperation*)));
}
// See https://bugs.kde.org/show_bug.cgi?id=317866
// Uses the operator< overload above
qSort(allEvents);
void LogManager::onEventsFinished(KTp::PendingLoggerOperation *op)
{
KTp::PendingLoggerLogs *logsOp = qobject_cast<KTp::PendingLoggerLogs*>(op);
if (logsOp->hasError()) {
kWarning() << "Failed to fetch events:" << logsOp->error();
Q_EMIT fetched(QList<KTp::Message>());
return;
}
// get last n (d->fetchLast) messages that are not queued
const QList<KTp::LogMessage> allMessages = logsOp->logs();
QList<KTp::Message> messages;
Q_FOREACH (const Tpl::EventPtr &event, allEvents) {
const Tpl::TextEventPtr textEvent = event.dynamicCast<Tpl::TextEvent>();
if (!textEvent.isNull()) {
if (!queuedMessageTokens.contains(textEvent->messageToken())) {
const KTp::Message message = KTp::MessageProcessor::instance()->processIncomingMessage(textEvent, d->account, d->textChannel);
messages.append(message);
}
}
const KTp::MessageContext ctx(d->account, d->textChannel);
for (int i = 0; i < d->scrollbackLength && i < allMessages.count(); ++i) {
const KTp::LogMessage message = allMessages[i];
messages << KTp::MessageProcessor::instance()->processIncomingMessage(message, ctx);
}
kDebug() << "emit all messages" << messages.count();
......
/*
Copyright (C) 2011 Dominik Schmidt <kde@dominik-schmidt.de>
Copyright (C) 2013 Daniel Vrátil <dvratil@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -24,11 +25,10 @@
#include <KTp/message.h>
namespace Tpl {
class PendingOperation;
namespace KTp {
class PendingLoggerOperation;
}
class LogManager : public QObject
{
Q_OBJECT
......@@ -62,7 +62,8 @@ Q_SIGNALS:
void fetched(const QList<KTp::Message> &messages);
private Q_SLOTS:
void onEventsFinished(Tpl::PendingOperation *po);
void onDatesFinished(KTp::PendingLoggerOperation *po);
void onEventsFinished(KTp::PendingLoggerOperation *po);
private:
class Private;
......
/*
Copyright (C) 2013 Daniel Vrátil <dvratil@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "logmanager.h"
#include <TelepathyQt/Types>
class LogManager::Private
{
public:
Private(): scrollbackLength(10)
{
}
int scrollbackLength;
};
LogManager::LogManager(QObject *parent)
: QObject(parent),
d(new Private)
{
}
LogManager::~LogManager()
{
delete d;
}
bool LogManager::exists() const
{
return false;
}
void LogManager::setTextChannel(const Tp::AccountPtr &account, const Tp::TextChannelPtr &textChannel)
{
Q_UNUSED(account);
Q_UNUSED(textChannel);
}
void LogManager::setScrollbackLength(int n)
{
d->scrollbackLength = n;
}
int LogManager::scrollbackLength() const
{
return d->scrollbackLength;
}
void LogManager::fetchScrollback()
{
QMetaObject::invokeMethod(this, "fetched", Qt::QueuedConnection,
Q_ARG(QList<KTp::Message>, QList<KTp::Message>()));
}
void LogManager::fetchHistory(int n)
{
Q_UNUSED(n);
fetchScrollback();
}
void LogManager::onEventsFinished(Tpl::PendingOperation *po)
{
Q_UNUSED(po);
}
#include "moc_logmanager.cpp"
......@@ -23,9 +23,9 @@ target_link_libraries(ktp-log-viewer
${TELEPATHY_QT4_LIBRARIES}
${KDE4_KEMOTICONS_LIBS}
${KDE4_KCMUTILS_LIBS}
${TELEPATHY_LOGGER_QT4_LIBRARIES}
${KDE4_KDEWEBKIT_LIBRARY}
${KTP_LIBRARIES}
${KTP_LOGGER_LIBRARIES}
ktpchat)
install(TARGETS ktp-log-viewer DESTINATION ${BIN_INSTALL_DIR})
......
......@@ -19,11 +19,8 @@
#include "conversation-date-picker.h"
#include <TelepathyLoggerQt4/LogManager>
#include <TelepathyLoggerQt4/PendingDates>
#include <TelepathyLoggerQt4/PendingOperation>
#include <TelepathyLoggerQt4/Entity>
#include <TelepathyLoggerQt4/SearchHit>
#include <KTp/Logger/log-manager.h>
#include <KTp/Logger/pending-logger-dates.h>
#include <KDateTable>
#include <TelepathyQt/Account>
......@@ -33,7 +30,7 @@ ConversationDatePicker::ConversationDatePicker(QWidget *parent) :
{
}
void ConversationDatePicker::setEntity(const Tp::AccountPtr &account, const Tpl::EntityPtr &entity)
void ConversationDatePicker::setEntity(const Tp::AccountPtr &account, const KTp::LogEntity &entity)
{
clear();
......@@ -45,9 +42,9 @@ void ConversationDatePicker::setEntity(const Tp::AccountPtr &account, const Tpl:
updatePaintedDates();
Q_EMIT dateChanged(date());
} else {
Tpl::LogManagerPtr logManager = Tpl::LogManager::instance();
Tpl::PendingDates *pendingDates = logManager->queryDates(account, entity, Tpl::EventTypeMaskText);
connect(pendingDates, SIGNAL(finished(Tpl::PendingOperation*)), SLOT(onDatesFinished(Tpl::PendingOperation*)));
KTp::LogManager *logManager = KTp::LogManager::instance();
KTp::PendingLoggerDates* pendingDates = logManager->queryDates(account, entity);
connect(pendingDates, SIGNAL(finished(KTp::PendingLoggerOperation*)), SLOT(onDatesFinished(KTp::PendingLoggerOperation*)));
}
}
......@@ -62,7 +59,7 @@ void ConversationDatePicker::clear()
}
}
void ConversationDatePicker::setSearchHits(const Tpl::SearchHitList &searchHits)
void ConversationDatePicker::setSearchHits(const QList<KTp::LogSearchHit> &searchHits)
{
m_searchHits = searchHits;
......@@ -77,7 +74,6 @@ void ConversationDatePicker::clearSearchHits()
updatePaintedDates();
}
QDate ConversationDatePicker::nextDate() const
{
QList<QDate>::ConstIterator iter = qUpperBound(m_setDates, date());
......@@ -103,9 +99,9 @@ const QList<QDate>& ConversationDatePicker::validDates() const
return m_setDates;
}
void ConversationDatePicker::onDatesFinished(Tpl::PendingOperation *op)
void ConversationDatePicker::onDatesFinished(KTp::PendingLoggerOperation *op)
{
Tpl::PendingDates *pendingDates = qobject_cast<Tpl::PendingDates*>(op);
KTp::PendingLoggerDates *pendingDates = qobject_cast<KTp::PendingLoggerDates*>(op);
m_setDates = pendingDates->dates();
qSort(m_setDates);
......@@ -127,17 +123,17 @@ void ConversationDatePicker::setDatesFromSearchHits()
{
m_setDates.clear();
if (m_account.isNull() || m_entity.isNull()) {
if (m_account.isNull() || !m_entity.isValid()) {
return;
}
Q_FOREACH (const Tpl::SearchHit &searchHit, m_searchHits) {
if (searchHit.account().isNull() || searchHit.target().isNull()) {
Q_FOREACH (const KTp::LogSearchHit &searchHit, m_searchHits) {
if (searchHit.account().isNull() || !searchHit.entity().isValid()) {
continue;
}
if ((searchHit.account()->uniqueIdentifier() == m_account->uniqueIdentifier()) &&
(searchHit.target()->identifier() == m_entity->identifier())) {
(searchHit.entity().id() == m_entity.id())) {
m_setDates << searchHit.date();
}
}
......
/***************************************************************************
* Copyright (C) 2012 by David Edmundson <kde@davidedmundson.co.uk> *
* Copyright (C) 2013 by Daniel Vrátil <dvratil@redhat.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -22,12 +23,13 @@
#include <KDatePicker>
#include <TelepathyLoggerQt4/Entity>
#include <TelepathyLoggerQt4/SearchHit>
#include <KTp/Logger/log-entity.h>
#include <KTp/Logger/log-search-hit.h>
#include <TelepathyQt/Types>
namespace Tpl{
class PendingOperation;
namespace KTp {
class PendingLoggerOperation;
}
class ConversationDatePicker : public KDatePicker
......@@ -36,10 +38,10 @@ class ConversationDatePicker : public KDatePicker
public:
explicit ConversationDatePicker(QWidget *parent = 0);
void setEntity(const Tp::AccountPtr &accout, const Tpl::EntityPtr &entity);
void setEntity(const Tp::AccountPtr &accout, const KTp::LogEntity &entity);
void clear();
void setSearchHits(const Tpl::SearchHitList &searchHits);
void setSearchHits(const QList<KTp::LogSearchHit> &searchHits);
void clearSearchHits();
QDate previousDate() const;
......@@ -47,15 +49,15 @@ public:
const QList<QDate>& validDates() const;
private Q_SLOTS:
void onDatesFinished(Tpl::PendingOperation*);
void onDatesFinished(KTp::PendingLoggerOperation *op);
private:
void updatePaintedDates();
void setDatesFromSearchHits();
Tp::AccountPtr m_account;
Tpl::EntityPtr m_entity;
Tpl::SearchHitList m_searchHits;
KTp::LogEntity m_entity;
QList<KTp::LogSearchHit> m_searchHits;
QList< QDate > m_setDates;
};
......
......@@ -21,7 +21,6 @@
#include "entity-model.h"
#include <TelepathyQt/Contact>
#include <TelepathyLoggerQt4/Entity>
#include <QDebug>
......@@ -95,7 +94,7 @@ QVariant EntityModelItem::data(int role) const
{
switch (role) {
case Qt::DisplayRole:
return m_contact ? m_contact->alias() : (m_entity ? m_entity->alias() : m_account->displayName());
return m_contact ? m_contact->alias() : (m_entity.isValid() ? m_entity.alias() : m_account->displayName());
case EntityModel::AccountRole:
return QVariant::fromValue(m_account);
case EntityModel::ContactRole:
......@@ -103,7 +102,7 @@ QVariant EntityModelItem::data(int role) const
case EntityModel::EntityRole:
return QVariant::fromValue(m_entity);
case EntityModel::IdRole:
return m_entity->identifier();
return m_entity.id();
}
return QVariant();
......@@ -119,7 +118,7 @@ void EntityModelItem::setData(const QVariant &data, int role)
m_contact = data.value< KTp::ContactPtr >();
break;
case EntityModel::EntityRole:
m_entity = data.value< Tpl::EntityPtr >();
m_entity = data.value< KTp::LogEntity >();
break;
}
}
......@@ -25,9 +25,9 @@
#include <QList>
#include <TelepathyQt/Types>
#include <TelepathyLoggerQt4/Entity>
#include <KTp/contact.h>
#include <KTp/Logger/log-entity.h>
class EntityModelItem
{
......@@ -54,7 +54,7 @@ private:
EntityModelItem *m_parent;
Tp::AccountPtr m_account;
Tpl::EntityPtr m_entity;
KTp::LogEntity m_entity;
KTp::ContactPtr m_contact;
};
......
......@@ -21,10 +21,9 @@
#include "entity-model.h"
#include "entity-model-item.h"
#include <TelepathyLoggerQt4/LogManager>
#include <TelepathyLoggerQt4/PendingEntities>
#include <TelepathyLoggerQt4/PendingOperation>
#include <TelepathyLoggerQt4/Entity>
#include <KTp/Logger/log-manager.h>
#include <KTp/Logger/log-entity.h>
#include <KTp/Logger/pending-logger-entities.h>
#include <TelepathyQt/AccountManager>
#include <TelepathyQt/Account>
......@@ -49,11 +48,11 @@ EntityModel::~EntityModel()
void EntityModel::setAccountManager(const Tp::AccountManagerPtr &accountManager)
{
Tpl::LogManagerPtr logManager = Tpl::LogManager::instance();
KTp::LogManager *logManager = KTp::LogManager::instance();
Q_FOREACH(const Tp::AccountPtr &account, accountManager->allAccounts()) {
connect(logManager->queryEntities(account),
SIGNAL(finished(Tpl::PendingOperation*)),
SLOT(onEntitiesSearchFinished(Tpl::PendingOperation*)));
SIGNAL(finished(KTp::PendingLoggerOperation*)),