[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:22:36 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=93c573c

The following commit has been merged in the master branch:
commit 93c573cc75f400e7670f544f0c4bd68fb1ee6ede
Author: Dan Vrátil <dvratil at redhat.com>
Date:   Sun Sep 9 23:53:21 2012 +0200

    Add UI to clear entity/account logs
    
    REVIEW: 106229
---
 logviewer/entity-model-item.cpp |   5 ++
 logviewer/entity-model-item.h   |   1 +
 logviewer/entity-model.cpp      |  18 +++++++
 logviewer/entity-model.h        |   2 +
 logviewer/log-viewer.cpp        | 114 ++++++++++++++++++++++++++++++++++++++++
 logviewer/log-viewer.h          |   9 ++++
 6 files changed, 149 insertions(+)

diff --git a/logviewer/entity-model-item.cpp b/logviewer/entity-model-item.cpp
index c7f2249..a08ccc2 100644
--- a/logviewer/entity-model-item.cpp
+++ b/logviewer/entity-model-item.cpp
@@ -40,6 +40,11 @@ void EntityModelItem::addItem(EntityModelItem *item)
     m_items << item;
 }
 
+void EntityModelItem::removeItem(int index)
+{
+    delete m_items.takeAt(index);
+}
+
 EntityModelItem* EntityModelItem::item(int row) const
 {
     if (row < m_items.count()) {
diff --git a/logviewer/entity-model-item.h b/logviewer/entity-model-item.h
index e740d25..47d98cd 100644
--- a/logviewer/entity-model-item.h
+++ b/logviewer/entity-model-item.h
@@ -35,6 +35,7 @@ public:
     virtual ~EntityModelItem();
 
     void addItem(EntityModelItem *item);
+    void removeItem(int index);
 
     EntityModelItem* item(int row) const;
     EntityModelItem* item(const Tp::AccountPtr &account);
diff --git a/logviewer/entity-model.cpp b/logviewer/entity-model.cpp
index cbee00a..1c10c1d 100644
--- a/logviewer/entity-model.cpp
+++ b/logviewer/entity-model.cpp
@@ -137,6 +137,24 @@ Qt::ItemFlags EntityModel::flags(const QModelIndex &index) const
     return QAbstractItemModel::flags(index);
 }
 
+bool EntityModel::removeRows(int start, int count, const QModelIndex &parent)
+{
+    EntityModelItem *parentItem;
+
+    if (parent.isValid()) {
+        parentItem = m_rootItem->item(parent.row());
+    } else {
+        parentItem = m_rootItem;
+    }
+
+    beginRemoveRows(parent, start, start + count - 1);
+    for (int row = 0; row < count; ++row) {
+        parentItem->removeItem(start);
+    }
+    endRemoveRows();
+
+    return true;
+}
 
 void EntityModel::onEntitiesSearchFinished(Tpl::PendingOperation *operation)
 {
diff --git a/logviewer/entity-model.h b/logviewer/entity-model.h
index 205c132..5c9aa73 100644
--- a/logviewer/entity-model.h
+++ b/logviewer/entity-model.h
@@ -71,6 +71,8 @@ public:
     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
     QModelIndex parent(const QModelIndex &child) const;
 
+    bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex());
+
 private Q_SLOTS:
     void onEntitiesSearchFinished(Tpl::PendingOperation*);
     void onEntityContactRetrieved(Tp::PendingOperation*);
diff --git a/logviewer/log-viewer.cpp b/logviewer/log-viewer.cpp
index 1c72577..ce39775 100644
--- a/logviewer/log-viewer.cpp
+++ b/logviewer/log-viewer.cpp
@@ -32,14 +32,18 @@
 #include <TelepathyLoggerQt4/PendingSearch>
 
 #include <QSortFilterProxyModel>
+#include <QMenu>
 #include <QWebFrame>
 #include <KLineEdit>
 #include <KPixmapSequence>
+#include <KMessageBox>
 
 #include "entity-model.h"
 #include "entity-proxy-model.h"
 #include "entity-model-item.h"
 
+Q_DECLARE_METATYPE(QModelIndex)
+
 LogViewer::LogViewer(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::LogViewer)
@@ -76,6 +80,7 @@ LogViewer::LogViewer(QWidget *parent) :
     ui->entityList->setModel(m_filterModel);
     ui->entityList->setItemsExpandable(true);
     ui->entityList->setRootIsDecorated(true);
+    ui->entityList->setContextMenuPolicy(Qt::CustomContextMenu);
     ui->entityFilter->setProxy(m_filterModel);
     ui->entityFilter->lineEdit()->setClickMessage(i18nc("Placeholder text in line edit for filtering contacts", "Filter contacts..."));
 
@@ -85,6 +90,18 @@ LogViewer::LogViewer(QWidget *parent) :
     connect(ui->messageView, SIGNAL(conversationSwitchRequested(QDate)), SLOT(switchConversation(QDate)));
     connect(ui->globalSearch, SIGNAL(returnPressed(QString)), SLOT(startGlobalSearch(QString)));
     connect(ui->globalSearch, SIGNAL(clearButtonClicked()), SLOT(clearGlobalSearch()));
+    connect(ui->entityList, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showEntityListContextMenu(QPoint)));
+
+    /* Build the popup menu for entity list */
+    m_entityListContextMenu = new QMenu(ui->entityList);
+
+    m_clearAccountHistoryAction = new QAction(i18n("Clear account history"), m_entityListContextMenu);
+    connect(m_clearAccountHistoryAction, SIGNAL(triggered(bool)), SLOT(clearAccountHistory()));
+    m_entityListContextMenu->addAction(m_clearAccountHistoryAction);
+
+    m_clearContactHistoryAction = new QAction(i18n("Clear contact history"), m_entityListContextMenu);
+    connect(m_clearContactHistoryAction, SIGNAL(triggered(bool)), SLOT(clearContactHistory()));
+    m_entityListContextMenu->addAction(m_clearContactHistoryAction);
 }
 
 LogViewer::~LogViewer()
@@ -190,3 +207,100 @@ void LogViewer::clearGlobalSearch()
     ui->datePicker->clearSearchHits();
     ui->messageView->clearHighlightText();
 }
+
+void LogViewer::showEntityListContextMenu (const QPoint &coords)
+{
+    QModelIndex index = ui->entityList->indexAt(coords);
+    if (!index.isValid()) {
+        return;
+    }
+    index = m_filterModel->mapToSource(index);
+
+    /* Whether the node is an account or a contact */
+    if (index.parent() == QModelIndex()) {
+        m_clearContactHistoryAction->setVisible(false);
+        m_clearAccountHistoryAction->setVisible(true);
+    } else {
+        m_clearContactHistoryAction->setVisible(true);
+        m_clearAccountHistoryAction->setVisible(false);
+    }
+
+    m_entityListContextMenu->setProperty("index", QVariant::fromValue(index));
+    m_entityListContextMenu->popup(ui->entityList->mapToGlobal(coords));
+}
+
+void LogViewer::clearAccountHistory()
+{
+    QModelIndex index = m_entityListContextMenu->property("index").value<QModelIndex>();
+    if (!index.isValid()) {
+        return;
+    }
+
+    Tp::AccountPtr account = index.data(EntityModel::AccountRole).value<Tp::AccountPtr>();
+    if (account.isNull()) {
+	return;
+    }
+
+    if (KMessageBox::questionYesNo(
+            this, i18n("Are you sure you want to remove all logs from account %1?", account->displayName()),
+            i18n("Clear account history"), KStandardGuiItem::del(), KStandardGuiItem::cancel(),
+            QString(), KMessageBox::Dangerous) == KMessageBox::No) {
+        return;
+    }
+
+    Tpl::LogManagerPtr logManager = Tpl::LogManager::instance();
+    Tpl::PendingOperation *operation = logManager->clearAccountHistory(account);
+    connect(operation, SIGNAL(finished(Tpl::PendingOperation*)), SLOT(logClearingFinished(Tpl::PendingOperation*)));
+}
+
+void LogViewer::clearContactHistory()
+{
+    QModelIndex index = m_entityListContextMenu->property("index").value<QModelIndex>();
+    if (!index.isValid()) {
+        return;
+    }
+
+    Tp::AccountPtr account = index.data(EntityModel::AccountRole).value<Tp::AccountPtr>();
+    Tpl::EntityPtr entity = index.data(EntityModel::EntityRole).value<Tpl::EntityPtr>();
+    if (account.isNull() || entity.isNull()) {
+	return;
+    }
+
+    QString name = index.data(Qt::DisplayRole).toString();
+    if (KMessageBox::questionYesNo(
+            this, i18n("Are you sure you want to remove history of all conversations with %1?", name),
+            i18n("Clear contact history"), KStandardGuiItem::del(), KStandardGuiItem::cancel(),
+            QString(), KMessageBox::Dangerous) == KMessageBox::No) {
+        return;
+    }
+
+    Tpl::LogManagerPtr logManager = Tpl::LogManager::instance();
+    Tpl::PendingOperation *operation = logManager->clearEntityHistory(account, entity);
+    connect(operation, SIGNAL(finished(Tpl::PendingOperation*)), SLOT(logClearingFinished(Tpl::PendingOperation*)));
+}
+
+void LogViewer::logClearingFinished(Tpl::PendingOperation *operation)
+{
+    if (!operation->errorName().isEmpty() || !operation->errorMessage().isEmpty()) {
+	/* Make sure we display at least some message */
+	QString msg = (operation->errorMessage().isEmpty()) ? operation->errorName() : operation->errorMessage();
+	KMessageBox::sorry(this, msg, operation->errorName(), 0);
+	return;
+    }
+
+    QModelIndex index = m_entityListContextMenu->property("index").value<QModelIndex>();
+    if (!index.isValid()) {
+        m_entityListContextMenu->setProperty("index", QVariant());
+        return;
+    }
+
+    QModelIndex parent = index.parent();
+    m_entityModel->removeRow(index.row(), parent);
+
+    /* If last entity was removed then remove the account node as well */
+    if (parent.isValid() && !m_entityModel->hasChildren(parent)) {
+        m_entityModel->removeRow(parent.row(), parent.parent());
+    }
+
+    m_entityListContextMenu->setProperty("index", QVariant());
+}
diff --git a/logviewer/log-viewer.h b/logviewer/log-viewer.h
index 4a9e20b..b69753a 100644
--- a/logviewer/log-viewer.h
+++ b/logviewer/log-viewer.h
@@ -24,6 +24,7 @@
 #include <TelepathyQt/AccountManager>
 #include <TelepathyLoggerQt4/Types>
 
+class QMenu;
 namespace Ui {
     class LogViewer;
 }
@@ -54,12 +55,20 @@ private Q_SLOTS:
     void startGlobalSearch(const QString &term);
     void globalSearchFinished(Tpl::PendingOperation *);
     void clearGlobalSearch();
+    void showEntityListContextMenu(const QPoint &coords);
 
+    void clearAccountHistory();
+    void clearContactHistory();
+    void logClearingFinished(Tpl::PendingOperation *);
 private:
     Ui::LogViewer *ui;
     Tp::AccountManagerPtr m_accountManager;
     EntityModel *m_entityModel;
     EntityProxyModel *m_filterModel;
+
+    QMenu *m_entityListContextMenu;
+    QAction *m_clearAccountHistoryAction;
+    QAction *m_clearContactHistoryAction;
 };
 
 #endif // LOGVIEWER_H

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list