[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:08:17 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=3ca0945

The following commit has been merged in the master branch:
commit 3ca0945a5b9dbde44eb74f3a1d878e8c50c4f994
Author: Nilesh Suthar <nil.15111993 at gmail.com>
Date:   Wed Aug 6 19:33:18 2014 +0530

    Added KPeople Chat Plugin
---
 kpeople/CMakeLists.txt                             |   2 +-
 kpeople/uiplugins/CMakeLists.txt                   |   2 +
 kpeople/uiplugins/chatplugin/CMakeLists.txt        |  17 +++
 .../uiplugins/chatplugin/chatlistviewdelegate.cpp  |  60 ++++++++
 .../chatplugin/chatlistviewdelegate.h}             |  33 ++--
 .../uiplugins/chatplugin/kpeople_chat_plugin.cpp   | 166 +++++++++++++++++++++
 .../chatplugin/kpeople_chat_plugin.desktop         |  11 ++
 .../kpeople_chat_plugin.h}                         |  36 +++--
 8 files changed, 297 insertions(+), 30 deletions(-)

diff --git a/kpeople/CMakeLists.txt b/kpeople/CMakeLists.txt
index c5f1019..7e09453 100644
--- a/kpeople/CMakeLists.txt
+++ b/kpeople/CMakeLists.txt
@@ -1,3 +1,3 @@
 add_subdirectory(actionsplugin)
 add_subdirectory(datasourceplugin)
-add_subdirectory(uiplugins)
+add_subdirectory(uiplugins)
\ No newline at end of file
diff --git a/kpeople/uiplugins/CMakeLists.txt b/kpeople/uiplugins/CMakeLists.txt
index 2fa6b8b..42f9acc 100644
--- a/kpeople/uiplugins/CMakeLists.txt
+++ b/kpeople/uiplugins/CMakeLists.txt
@@ -14,3 +14,5 @@ target_link_libraries(imdetailswidgetplugin ${QT_QTCORE_LIBRARY}
 
 install(TARGETS imdetailswidgetplugin DESTINATION ${PLUGIN_INSTALL_DIR})
 install(FILES imdetailswidgetplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+
+add_subdirectory(chatplugin)
\ No newline at end of file
diff --git a/kpeople/uiplugins/chatplugin/CMakeLists.txt b/kpeople/uiplugins/chatplugin/CMakeLists.txt
new file mode 100644
index 0000000..14bffc9
--- /dev/null
+++ b/kpeople/uiplugins/chatplugin/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories(${KPEOPLE_INCLUDES})
+
+kde4_add_plugin(kpeople_chat_plugin chatlistviewdelegate.cpp kpeople_chat_plugin.cpp)
+target_link_libraries(kpeople_chat_plugin ${QT_QTCORE_LIBRARY}
+    ${QT_QTGUI_LIBRARY}
+    ${TELEPATHY_QT4_LIBRARIES}
+    ${KDE4_KDECORE_LIBRARY}
+    ${KDE4_KDEUI_LIBRARY}
+    ${KPEOPLE_LIBS}
+    ${KDEPIMLIBS_KABC_LIBS}
+    kpeoplewidgets
+    ktploggerprivate
+    ktpcommoninternalsprivate
+)
+
+install(TARGETS kpeople_chat_plugin DESTINATION ${PLUGIN_INSTALL_DIR})
+install(FILES kpeople_chat_plugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
diff --git a/kpeople/uiplugins/chatplugin/chatlistviewdelegate.cpp b/kpeople/uiplugins/chatplugin/chatlistviewdelegate.cpp
new file mode 100644
index 0000000..4d116bf
--- /dev/null
+++ b/kpeople/uiplugins/chatplugin/chatlistviewdelegate.cpp
@@ -0,0 +1,60 @@
+/*
+    Copyright 2014  Nilesh Suthar <nileshsuthar at live.in>
+
+    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 "chatlistviewdelegate.h"
+#include <QPainter>
+#include <QApplication>
+
+void ChatListviewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+                                 const QModelIndex &index) const
+{
+    QStyledItemDelegate::paint(painter, option, index);
+
+    painter->save();
+
+    QFont font = QApplication::font();
+    QFont timeFont = QApplication::font();
+    QFont messagefont = QApplication::font();
+    timeFont.setItalic(true);
+    font.setBold(true);
+    QFontMetrics fm(font);
+
+    QString senderAlias = index.data(senderAliasRole).toString() + QLatin1String(":");
+    QString message = index.data(messageRole).toString();
+    QString time = index.data(messageTimeRole).toString();
+
+    QRect aliasRect = option.rect;
+    QRect messageRect = option.rect;
+    QRect timeRect = option.rect;
+
+    messageRect.setLeft(fm.width(senderAlias));
+
+    painter->setFont(font);
+    painter->drawText(aliasRect, senderAlias);
+
+    painter->setFont(messagefont);
+    painter->drawText(messageRect, message);
+
+    painter->setFont(timeFont);
+    painter->drawText(timeRect, Qt::AlignRight, time);
+
+    painter->restore();
+
+}
+
+#include "chatlistviewdelegate.moc"
diff --git a/kpeople/datasourceplugin/im-persons-data-source.h b/kpeople/uiplugins/chatplugin/chatlistviewdelegate.h
similarity index 57%
copy from kpeople/datasourceplugin/im-persons-data-source.h
copy to kpeople/uiplugins/chatplugin/chatlistviewdelegate.h
index c90b026..26e10ec 100644
--- a/kpeople/datasourceplugin/im-persons-data-source.h
+++ b/kpeople/uiplugins/chatplugin/chatlistviewdelegate.h
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013  Martin Klapetek <mklapetek at kde.org>
+    Copyright 2014  Nilesh Suthar <nileshsuthar at live.in>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -14,26 +14,27 @@
     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
-*/
+ */
 
+#ifndef CHATLISTVIEWDELEGATE_H
+#define CHATLISTVIEWDELEGATE_H
 
-#ifndef IM_PERSONS_DATA_SOURCE_H
-#define IM_PERSONS_DATA_SOURCE_H
+#include <QStyledItemDelegate>
 
-#include <KPeople/BasePersonsDataSource>
+class QPainter;
 
-#include <TelepathyQt/Types>
-
-#include "KTp/ktp-export.h"
-
-class KTP_EXPORT IMPersonsDataSource : public KPeople::BasePersonsDataSource
+class ChatListviewDelegate : public QStyledItemDelegate
 {
 public:
-    IMPersonsDataSource(QObject *parent, const QVariantList &data);
-    virtual ~IMPersonsDataSource();
-    virtual QString sourcePluginId() const;
+    ChatListviewDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
 
-    virtual KPeople::AllContactsMonitor* createAllContactsMonitor();
-};
+    enum dataRole {
+        senderAliasRole = Qt::UserRole + 100,
+        messageRole, messageTimeRole
+    };
 
-#endif // IM_PERSONS_DATA_SOURCE_H
+    void paint(QPainter *painter, const QStyleOptionViewItem &option,
+               const QModelIndex &index) const;
+
+};
+#endif // CHATLISTVIEWDELEGATE_H
diff --git a/kpeople/uiplugins/chatplugin/kpeople_chat_plugin.cpp b/kpeople/uiplugins/chatplugin/kpeople_chat_plugin.cpp
new file mode 100644
index 0000000..f87253d
--- /dev/null
+++ b/kpeople/uiplugins/chatplugin/kpeople_chat_plugin.cpp
@@ -0,0 +1,166 @@
+/*
+    Copyright 2014  Nilesh Suthar <nileshsuthar at live.in>
+
+    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 "kpeople_chat_plugin.h"
+#include "chatlistviewdelegate.h"
+
+#include <QLabel>
+#include <QDebug>
+#include <QListView>
+#include <QStandardItemModel>
+#include <QVBoxLayout>
+#include <QScrollArea>
+#include <KLocalizedString>
+#include <KGlobal>
+#include <KABC/Addressee>
+#include <KPluginFactory>
+#include <KLocale>
+
+#include <KTp/core.h>
+#include <KTp/Logger/log-manager.h>
+#include <KTp/Logger/log-entity.h>
+#include <KTp/Logger/pending-logger-dates.h>
+#include <KTp/Logger/pending-logger-logs.h>
+#include <KTp/message.h>
+#include <TelepathyQt/Account>
+#include <TelepathyQt/AccountManager>
+
+#define TP_ACCOUNT_OBJECT_PATH_BASE "/org/freedesktop/Telepathy/Account/"
+
+K_PLUGIN_FACTORY(KpeopleChatFactory, registerPlugin<ChatWidgetFactory>();)
+K_EXPORT_PLUGIN(KpeopleChatFactory("kpeople_chat_plugin", "ktp-common-internals"))
+
+ChatWidgetFactory::ChatWidgetFactory(QObject *parent, const QVariantList &args): AbstractFieldWidgetFactory(parent)
+{
+    Q_UNUSED(parent);
+    Q_UNUSED(args);
+    m_model = new QStandardItemModel();
+}
+
+QWidget *ChatWidgetFactory::createDetailsWidget(const KABC::Addressee &person, const KABC::AddresseeList &contacts, QWidget *parent) const
+{
+    Q_UNUSED(contacts);
+    QWidget *widget = new QWidget(parent);
+
+    QScrollArea *scrollArea = new QScrollArea();
+    scrollArea->setWidget(widget);
+    scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+    scrollArea->setWidgetResizable(true);
+    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+    scrollArea->setFixedHeight(widget->height());
+
+    QVBoxLayout *layout = new QVBoxLayout(widget);
+    QListView *chatlistView = new QListView();
+    ChatListviewDelegate *chatListViewDelegate = new ChatListviewDelegate(chatlistView);
+    chatlistView->setItemDelegate(chatListViewDelegate);
+    chatlistView->setModel(m_model);
+    layout->setContentsMargins(0, 0, 0, 0);
+
+    if (person.custom(QLatin1String("telepathy"), QLatin1String("accountPath")).isEmpty()) {
+        layout->addWidget(new QLabel(QLatin1String("Chat for current contact is not supported")));
+    } else {
+        KTp::LogManager *logManager = KTp::LogManager::instance();
+        logManager->setAccountManager(KTp::accountManager());
+        KTp::LogEntity logEntity(Tp::HandleTypeContact, person.custom(QLatin1String("telepathy"), QLatin1String("contactId")));
+
+        Tp::AccountPtr account;
+
+        if (person.custom(QLatin1String("telepathy"), QLatin1String("accountPath")).contains(QLatin1String(TP_ACCOUNT_OBJECT_PATH_BASE))) {
+            account = KTp::accountManager().data()->accountForObjectPath(person.custom(QLatin1String("telepathy"), QLatin1String("accountPath")));
+        } else {
+            account = KTp::accountManager().data()->accountForObjectPath(QLatin1String(TP_ACCOUNT_OBJECT_PATH_BASE) + person.custom(QLatin1String("telepathy"), QLatin1String("accountPath")));
+        }
+
+        if (account.isNull()) {
+            qDebug() << "Error Occoured Account is not supposed to be null";
+        } else {
+            if (logManager->logsExist(account, logEntity)) {
+                connect(logManager->queryDates(account, logEntity), SIGNAL(finished(KTp::PendingLoggerOperation*)), SLOT(onPendingDates(KTp::PendingLoggerOperation*)));
+            } else {
+                layout->addWidget(new QLabel(QLatin1String("Chat for current contact is not available")));
+            }
+        }
+    }
+
+    layout->addWidget(chatlistView);
+    widget->setLayout(layout);
+
+    return scrollArea;
+}
+void ChatWidgetFactory::onPendingDates(KTp::PendingLoggerOperation *pendingOperation)
+{
+
+    KTp::PendingLoggerDates *pd = qobject_cast<KTp::PendingLoggerDates *>(pendingOperation);
+    QList<QDate> dates = pd->dates();
+    if (dates.isEmpty()) {
+        qDebug() << "No messages";
+        return;
+    }
+    //Return atmost 5 logs previous logs
+    int numberOfLogs = 5;
+    if (dates.count() <= numberOfLogs) {
+        Q_FOREACH (QDate date , dates) {
+            KTp::PendingLoggerLogs *log = KTp::LogManager::instance()->queryLogs(pd->account(), pd->entity(), date);
+            connect(log, SIGNAL(finished(KTp::PendingLoggerOperation*)), this, SLOT(onEventsFinished(KTp::PendingLoggerOperation*)));
+        }
+    } else {
+        for (int i = numberOfLogs; i > 0; i--) {
+            KTp::PendingLoggerLogs *log = KTp::LogManager::instance()->queryLogs(pd->account(), pd->entity(), dates[dates.count() - i]);
+            connect(log, SIGNAL(finished(KTp::PendingLoggerOperation*)), this, SLOT(onEventsFinished(KTp::PendingLoggerOperation*)));
+        }
+    }
+}
+
+void ChatWidgetFactory::onEventsFinished(KTp::PendingLoggerOperation *pendingOperation)
+{
+    KTp::PendingLoggerLogs *logs = qobject_cast<KTp::PendingLoggerLogs *>(pendingOperation);
+    if (logs->hasError()) {
+        qDebug() << "Failed to fetch error:" << logs->error();
+        return;
+    }
+    QStringList queuedMessageTokens;
+    QList<KTp::LogMessage> messageList = logs->logs();
+
+    Q_FOREACH (KTp::LogMessage message, messageList) {
+        if (message.direction() == KTp::Message::RemoteToLocal) {
+            QStandardItem *messageRow = new QStandardItem();
+            messageRow->setData(message.senderAlias(), ChatListviewDelegate::senderAliasRole);
+            messageRow->setData(message.mainMessagePart(), ChatListviewDelegate::messageRole);
+            messageRow->setData(KGlobal::locale()->formatDateTime(message.time(), KLocale::FancyShortDate), ChatListviewDelegate::messageTimeRole);
+            m_model->appendRow(messageRow);
+        } else {
+            QStandardItem *messageRow = new QStandardItem();
+            messageRow->setData(QLatin1String("Me"), ChatListviewDelegate::senderAliasRole);
+            messageRow->setData(message.mainMessagePart(), ChatListviewDelegate::messageRole);
+            messageRow->setData(KGlobal::locale()->formatDateTime(message.time(), KLocale::FancyShortDate), ChatListviewDelegate::messageTimeRole);
+            m_model->appendRow(messageRow);
+        }
+    }
+}
+
+QString ChatWidgetFactory::label() const
+{
+    return i18n("Chat");
+}
+
+int ChatWidgetFactory::sortWeight() const
+{
+    return 0;
+}
+
+#include "kpeople_chat_plugin.moc"
diff --git a/kpeople/uiplugins/chatplugin/kpeople_chat_plugin.desktop b/kpeople/uiplugins/chatplugin/kpeople_chat_plugin.desktop
new file mode 100644
index 0000000..4d7392d
--- /dev/null
+++ b/kpeople/uiplugins/chatplugin/kpeople_chat_plugin.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Type=Service
+ServiceTypes=KPeople/Plugin
+X-KDE-Library=kpeople_chat_plugin
+X-KDE-PluginInfo-Author=Nilesh Suthar
+X-KDE-PluginInfo-Email=nileshsuthar at live.in
+X-KDE-PluginInfo-Name=kpeople
+X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-License=LGPL
+X-KDE-PluginInfo-EnabledByDefault=true
\ No newline at end of file
diff --git a/kpeople/uiplugins/imdetailswidget.h b/kpeople/uiplugins/chatplugin/kpeople_chat_plugin.h
similarity index 52%
copy from kpeople/uiplugins/imdetailswidget.h
copy to kpeople/uiplugins/chatplugin/kpeople_chat_plugin.h
index f361e03..9cdb9dc 100644
--- a/kpeople/uiplugins/imdetailswidget.h
+++ b/kpeople/uiplugins/chatplugin/kpeople_chat_plugin.h
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013  David Edmundson <davidedmundson at kde.org>
+    Copyright 2014  Nilesh Suthar <nileshsuthar at live.in>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -14,24 +14,34 @@
     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
-*/
+ */
 
-
-
-#ifndef IM_DETAILS_WIDGET_H
-#define IM_DETAILS_WIDGET_H
+#ifndef CHATDATASOURCE_H
+#define CHATDATASOURCE_H
 
 #include <kpeople/widgets/abstractfieldwidgetfactory.h>
 
-#include <QVariant>
-#include <QGridLayout>
+namespace KTp
+{
+class PendingLoggerOperation;
+}
+class QStandardItemModel;
 
-class ImDetailsWidget : public KPeople::AbstractFieldWidgetFactory
+class ChatWidgetFactory : public KPeople::AbstractFieldWidgetFactory
 {
+    Q_OBJECT
 public:
-    explicit ImDetailsWidget(QObject *parent, const QVariantList &args);
-    QString label() const;
-    virtual QWidget* createDetailsWidget(const KABC::Addressee& person, const KABC::AddresseeList &contacts, QWidget* parent) const;
+    explicit ChatWidgetFactory(QObject *parent, const QVariantList &args);
+    virtual QString label() const;
+    virtual int sortWeight() const;
+    virtual QWidget *createDetailsWidget(const KABC::Addressee &person, const KABC::AddresseeList &contacts, QWidget *parent) const;
+
+private Q_SLOTS:
+    void onPendingDates(KTp::PendingLoggerOperation *);
+    void onEventsFinished(KTp::PendingLoggerOperation *);
+
+private:
+    QStandardItemModel *m_model;
 };
 
-#endif // IM_DETAILS_WIDGET_H
+#endif // CHATDATASOURCE_H

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list