[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:13 UTC 2016


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

The following commit has been merged in the master branch:
commit a2834770a29cb8378ec0e6741c52612f96a0190e
Author: Dan Vrátil <dan at progdan.cz>
Date:   Fri Jul 27 11:02:00 2012 +0200

    Global search in LogViewer
    
    REVIEW: 105586
    BUG: 294652
---
 logviewer/conversation-date-picker.cpp | 67 +++++++++++++++++++++++++++++++---
 logviewer/conversation-date-picker.h   | 15 ++++++--
 logviewer/entity-proxy-model.cpp       | 40 ++++++++++++++++++--
 logviewer/entity-proxy-model.h         |  8 ++++
 logviewer/log-viewer.cpp               | 63 +++++++++++++++++++++++++++++++-
 logviewer/log-viewer.h                 | 13 ++++++-
 logviewer/log-viewer.ui                | 35 +++++++++++++++++-
 logviewer/message-view.cpp             | 20 ++++++++++
 logviewer/message-view.h               |  6 +++
 9 files changed, 249 insertions(+), 18 deletions(-)

diff --git a/logviewer/conversation-date-picker.cpp b/logviewer/conversation-date-picker.cpp
index 3817083..c6bbf2e 100644
--- a/logviewer/conversation-date-picker.cpp
+++ b/logviewer/conversation-date-picker.cpp
@@ -23,8 +23,10 @@
 #include <TelepathyLoggerQt4/PendingDates>
 #include <TelepathyLoggerQt4/PendingOperation>
 #include <TelepathyLoggerQt4/Entity>
+#include <TelepathyLoggerQt4/SearchHit>
 
 #include <KDateTable>
+#include <TelepathyQt/Account>
 
 ConversationDatePicker::ConversationDatePicker(QWidget *parent) :
     KDatePicker(parent)
@@ -34,9 +36,18 @@ ConversationDatePicker::ConversationDatePicker(QWidget *parent) :
 void ConversationDatePicker::setEntity(const Tp::AccountPtr &account, const Tpl::EntityPtr &entity)
 {
     clear();
-    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*)));
+
+    m_account = account;
+    m_entity = entity;
+
+    if (!m_searchHits.isEmpty()) {
+        setDatesFromSearchHits();
+        updatePaintedDates();
+    } 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*)));
+    }
 }
 
 void ConversationDatePicker::clear()
@@ -48,9 +59,24 @@ void ConversationDatePicker::clear()
     Q_FOREACH(const QDate &date, m_setDates) {
         dateTable()->unsetCustomDatePainting(date);
     }
-    m_setDates.clear();
 }
 
+void ConversationDatePicker::setSearchHits(const Tpl::SearchHitList &searchHits)
+{
+    m_searchHits = searchHits;
+
+    setDatesFromSearchHits();
+    updatePaintedDates();
+}
+
+
+void ConversationDatePicker::clearSearchHits()
+{
+    m_searchHits.clear();
+    updatePaintedDates();
+}
+
+
 QDate ConversationDatePicker::nextDate() const
 {
     int i = m_setDates.indexOf(date());
@@ -71,11 +97,40 @@ QDate ConversationDatePicker::previousDate() const
     return QDate();
 }
 
+const QList<QDate>& ConversationDatePicker::validDates() const
+{
+    return m_setDates;
+}
+
 void ConversationDatePicker::onDatesFinished(Tpl::PendingOperation *op)
 {
     Tpl::PendingDates *pendingDates = qobject_cast<Tpl::PendingDates*>(op);
-    Q_FOREACH(const QDate &date, pendingDates->dates()) {
+    m_setDates = pendingDates->dates();
+
+    updatePaintedDates();
+}
+
+void ConversationDatePicker::updatePaintedDates()
+{
+    clear();
+
+    Q_FOREACH(const QDate &date, m_setDates) {
         dateTable()->setCustomDatePainting(date, Qt::blue);
     }
-    m_setDates.append(pendingDates->dates());
+}
+
+void ConversationDatePicker::setDatesFromSearchHits()
+{
+    m_setDates.clear();
+
+    if (m_account.isNull() || m_entity.isNull()) {
+        return;
+    }
+
+    Q_FOREACH (const Tpl::SearchHit &searchHit, m_searchHits) {
+        if ((searchHit.account()->uniqueIdentifier() == m_account->uniqueIdentifier()) &&
+            (searchHit.target()->identifier() == m_entity->identifier())) {
+                m_setDates << searchHit.date();
+        }
+    }
 }
diff --git a/logviewer/conversation-date-picker.h b/logviewer/conversation-date-picker.h
index 868eb43..d39e68d 100644
--- a/logviewer/conversation-date-picker.h
+++ b/logviewer/conversation-date-picker.h
@@ -23,6 +23,7 @@
 #include <KDatePicker>
 
 #include <TelepathyLoggerQt4/Entity>
+#include <TelepathyLoggerQt4/SearchHit>
 #include <TelepathyQt/Types>
 
 namespace Tpl{
@@ -38,17 +39,25 @@ public:
     void setEntity(const Tp::AccountPtr &accout, const Tpl::EntityPtr &entity);
     void clear();
 
+    void setSearchHits(const Tpl::SearchHitList &searchHits);
+    void clearSearchHits();
+
     QDate previousDate() const;
     QDate nextDate() const;
-
-Q_SIGNALS:
+    const QList<QDate>& validDates() const;
 
 private Q_SLOTS:
     void onDatesFinished(Tpl::PendingOperation*);
 
 private:
-    QList<QDate> m_setDates;
+    void updatePaintedDates();
+    void setDatesFromSearchHits();
+
+    Tp::AccountPtr m_account;
+    Tpl::EntityPtr m_entity;
+    Tpl::SearchHitList m_searchHits;
 
+    QList< QDate > m_setDates;
 };
 
 #endif // CONVERSATIONDATEPICKER_H
diff --git a/logviewer/entity-proxy-model.cpp b/logviewer/entity-proxy-model.cpp
index ac1bbf5..5365783 100644
--- a/logviewer/entity-proxy-model.cpp
+++ b/logviewer/entity-proxy-model.cpp
@@ -22,6 +22,7 @@
 #include "entity-model.h"
 
 #include <TelepathyQt/Types>
+#include <TelepathyLoggerQt4/SearchHit>
 
 EntityProxyModel::EntityProxyModel(QObject *parent):
     QSortFilterProxyModel(parent)
@@ -40,22 +41,55 @@ bool EntityProxyModel::filterAcceptsRow(int source_row, const QModelIndex &sourc
     }
 
     QModelIndex index = source_parent.child(source_row, 0);
+    Tp::AccountPtr account = source_parent.data(EntityModel::AccountRole).value< Tp::AccountPtr >();
+    Tpl::EntityPtr entity = index.data(EntityModel::EntityRole).value< Tpl::EntityPtr >();
+
+    bool matches_filter = false;
+
+    if (!m_searchHits.isEmpty() && !account.isNull() && !entity.isNull()) {
+        Q_FOREACH(const Tpl::SearchHit &searchHit, m_searchHits) {
+            if ((searchHit.account()->uniqueIdentifier() == account->uniqueIdentifier()) &&
+                (searchHit.target()->identifier() == entity->identifier())) {
+                matches_filter = true;
+            }
+        }
+    } else {
+        matches_filter = true;
+    }
+
     QString term = filterRegExp().pattern();
+    if (term.isEmpty()) {
+        return matches_filter;
+    }
 
     Tp::ContactPtr contact = index.data(EntityModel::ContactRole).value< Tp::ContactPtr >();
-    Tpl::EntityPtr entity = index.data(EntityModel::EntityRole).value< Tpl::EntityPtr >();
 
     /* Check if contact's account name matches */
-    if (entity->alias().contains(term, Qt::CaseInsensitive)) {
+    if (entity->alias().contains(term, Qt::CaseInsensitive) && matches_filter) {
         return true;
     }
 
     /* If there's information about contact's real name try to match it too */
     if (!contact.isNull()) {
-        if (contact->alias().contains(term, Qt::CaseInsensitive)) {
+        if (contact->alias().contains(term, Qt::CaseInsensitive) && matches_filter) {
             return true;
         }
     }
 
     return false;
 }
+
+void EntityProxyModel::setSearchHits(const Tpl::SearchHitList &searchHits)
+{
+    m_searchHits = searchHits;
+
+    invalidate();
+}
+
+
+void EntityProxyModel::clearSearchHits()
+{
+    m_searchHits.clear();
+
+    invalidate();
+}
diff --git a/logviewer/entity-proxy-model.h b/logviewer/entity-proxy-model.h
index 0548081..78dd071 100644
--- a/logviewer/entity-proxy-model.h
+++ b/logviewer/entity-proxy-model.h
@@ -22,7 +22,9 @@
 #define ENTITY_PROXY_MODEL_H
 
 #include <QSortFilterProxyModel>
+#include <TelepathyLoggerQt4/Types>
 
+typedef QPair< Tp::AccountPtr, Tpl::EntityPtr > AccountEntityPair;
 
 class EntityProxyModel : public QSortFilterProxyModel
 {
@@ -32,9 +34,15 @@ public:
     explicit EntityProxyModel(QObject *parent = 0);
     virtual ~EntityProxyModel();
 
+    void setSearchHits(const Tpl::SearchHitList &searchHits);
+    void clearSearchHits();
+
 protected:
     bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
 
+private:
+    Tpl::SearchHitList m_searchHits;
+
 };
 
 #endif // ENTITY_PROXY_MODEL_H
diff --git a/logviewer/log-viewer.cpp b/logviewer/log-viewer.cpp
index 04fba29..5866cdb 100644
--- a/logviewer/log-viewer.cpp
+++ b/logviewer/log-viewer.cpp
@@ -28,12 +28,17 @@
 #include <TelepathyLoggerQt4/Init>
 #include <TelepathyLoggerQt4/Entity>
 #include <TelepathyLoggerQt4/LogManager>
+#include <TelepathyLoggerQt4/SearchHit>
+#include <TelepathyLoggerQt4/PendingSearch>
 
 #include <QSortFilterProxyModel>
 #include <QWebFrame>
+#include <KLineEdit>
+#include <KPixmapSequence>
 
 #include "entity-model.h"
 #include "entity-proxy-model.h"
+#include "entity-model-item.h"
 
 LogViewer::LogViewer(QWidget *parent) :
     QWidget(parent),
@@ -72,6 +77,7 @@ LogViewer::LogViewer(QWidget *parent) :
     ui->entityList->setItemsExpandable(true);
     ui->entityList->setRootIsDecorated(true);
     ui->entityFilter->setProxy(m_filterModel);
+    ui->entityFilter->lineEdit()->setClickMessage(i18nc("Placeholder text in line edit for filtering contacts", "Filter contacts..."));
 
     //TODO parse command line args and update all views as appropriate
 
@@ -79,6 +85,8 @@ LogViewer::LogViewer(QWidget *parent) :
     connect(ui->entityList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(onEntitySelected(QModelIndex,QModelIndex)));
     connect(ui->datePicker, SIGNAL(dateChanged(QDate)), SLOT(onDateSelected()));
     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()));
 }
 
 LogViewer::~LogViewer()
@@ -123,14 +131,65 @@ void LogViewer::updateMainView()
         return;
     }
 
-    QPair< QDate, QDate > nearestDates(ui->datePicker->previousDate(), ui->datePicker->nextDate());
+    QPair< QDate, QDate > nearestDates;
+
+    /* If the selected date is not within valid (highlighted) dates then display empty
+     * conversation (even if there is a chat log for that particular date) */
+    QDate date = ui->datePicker->date();
+    if (!ui->datePicker->validDates().contains(date)) {
+        date = QDate();
+    } else {
+        nearestDates.first = ui->datePicker->previousDate();
+        nearestDates.second = ui->datePicker->nextDate();
+    }
 
     Tpl::EntityPtr entity = currentIndex.data(EntityModel::EntityRole).value<Tpl::EntityPtr>();
     Tp::AccountPtr account = currentIndex.data(EntityModel::AccountRole).value<Tp::AccountPtr>();
-    ui->messageView->loadLog(account, entity, ui->datePicker->date(), nearestDates);
+    ui->messageView->loadLog(account, entity, date, nearestDates);
 }
 
 void LogViewer::switchConversation(const QDate &date)
 {
     ui->datePicker->setDate(date);
 }
+
+void LogViewer::startGlobalSearch(const QString &term)
+{
+    if (term.isEmpty()) {
+        ui->messageView->clearHighlightText();
+        m_filterModel->clearSearchHits();
+        ui->datePicker->clearSearchHits();
+        return;
+    }
+
+    ui->busyAnimation->setSequence(KPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium));
+    ui->busyAnimation->setVisible(true);
+    ui->globalSearch->setDisabled(true);
+
+    ui->messageView->setHighlightText(term);
+
+    Tpl::LogManagerPtr manager = Tpl::LogManager::instance();
+    Tpl::PendingSearch *search = manager->search(term, Tpl::EventTypeMaskAny);
+    connect (search, SIGNAL(finished(Tpl::PendingOperation*)),
+             this, SLOT(globalSearchFinished(Tpl::PendingOperation*)));
+}
+
+void LogViewer::globalSearchFinished(Tpl::PendingOperation *operation)
+{
+    Tpl::PendingSearch *search = qobject_cast< Tpl::PendingSearch* >(operation);
+    Q_ASSERT(search);
+
+    m_filterModel->setSearchHits(search->hits());
+    ui->datePicker->setSearchHits(search->hits());
+
+    ui->globalSearch->setEnabled(true);
+    ui->busyAnimation->setSequence(KPixmapSequence());
+    ui->busyAnimation->setVisible(false);
+}
+
+void LogViewer::clearGlobalSearch()
+{
+    m_filterModel->clearSearchHits();
+    ui->datePicker->clearSearchHits();
+    ui->messageView->clearHighlightText();
+}
diff --git a/logviewer/log-viewer.h b/logviewer/log-viewer.h
index 2b13bc1..4a9e20b 100644
--- a/logviewer/log-viewer.h
+++ b/logviewer/log-viewer.h
@@ -22,13 +22,18 @@
 
 #include <QWidget>
 #include <TelepathyQt/AccountManager>
+#include <TelepathyLoggerQt4/Types>
 
 namespace Ui {
     class LogViewer;
 }
 
+namespace Tpl {
+    class PendingOperation;
+}
+
 class EntityModel;
-class QSortFilterProxyModel;
+class EntityProxyModel;
 
 class LogViewer : public QWidget
 {
@@ -46,11 +51,15 @@ private Q_SLOTS:
     void updateMainView();
     void switchConversation(const QDate &date);
 
+    void startGlobalSearch(const QString &term);
+    void globalSearchFinished(Tpl::PendingOperation *);
+    void clearGlobalSearch();
+
 private:
     Ui::LogViewer *ui;
     Tp::AccountManagerPtr m_accountManager;
     EntityModel *m_entityModel;
-    QSortFilterProxyModel *m_filterModel;
+    EntityProxyModel *m_filterModel;
 };
 
 #endif // LOGVIEWER_H
diff --git a/logviewer/log-viewer.ui b/logviewer/log-viewer.ui
index 7e4097f..a76b34a 100644
--- a/logviewer/log-viewer.ui
+++ b/logviewer/log-viewer.ui
@@ -14,12 +14,29 @@
    <string>LogViewer</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0">
+   <item row="1" column="0">
+    <widget class="KLineEdit" name="globalSearch">
+     <property name="clickMessage">
+      <string>Search all logs...</string>
+     </property>
+     <property name="showClearButton" stdset="0">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <widget class="KPixmapSequenceWidget" name="busyAnimation">
+     <property name="visible">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="0" colspan="2">
     <widget class="QSplitter" name="splitter">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
-     <widget class="QWidget" name="">
+     <widget class="QWidget" name="layoutWidget">
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
         <widget class="EntityView" name="entityList"/>
@@ -52,6 +69,16 @@
    <header>kfilterproxysearchline.h</header>
   </customwidget>
   <customwidget>
+   <class>KLineEdit</class>
+   <extends>QLineEdit</extends>
+   <header>klineedit.h</header>
+  </customwidget>
+  <customwidget>
+   <class>KPixmapSequenceWidget</class>
+   <extends>QWidget</extends>
+   <header>kpixmapsequencewidget.h</header>
+  </customwidget>
+  <customwidget>
    <class>MessageView</class>
    <extends>QWidget</extends>
    <header>message-view.h</header>
@@ -69,6 +96,10 @@
    <header>entity-view.h</header>
   </customwidget>
  </customwidgets>
+ <tabstops>
+  <tabstop>entityList</tabstop>
+  <tabstop>globalSearch</tabstop>
+ </tabstops>
  <resources/>
  <connections/>
 </ui>
diff --git a/logviewer/message-view.cpp b/logviewer/message-view.cpp
index 1f51a83..021287a 100644
--- a/logviewer/message-view.cpp
+++ b/logviewer/message-view.cpp
@@ -57,6 +57,16 @@ void MessageView::loadLog(const Tp::AccountPtr &account, const Tpl::EntityPtr &e
     initialise(headerInfo);
 }
 
+void MessageView::setHighlightText(const QString &text)
+{
+    m_highlightedText = text;
+}
+
+void MessageView::clearHighlightText()
+{
+    setHighlightText(QString());
+}
+
 void MessageView::onLoadFinished()
 {
     //load stuff here.
@@ -118,6 +128,10 @@ void MessageView::onEventsLoaded(Tpl::PendingOperation *po)
 
         addStatusMessage(message);
     }
+
+    /* Can't highlight the text directly, we need to wait for the JavaScript in
+     * AdiumThemeView to include the log messages into DOM. */
+    QTimer::singleShot(100, this, SLOT(doHighlightText()));
 }
 
 void MessageView::onLinkClicked(const QUrl &link)
@@ -134,3 +148,9 @@ void MessageView::onLinkClicked(const QUrl &link)
 
     AdiumThemeView::onLinkClicked(link);
 }
+
+void MessageView::doHighlightText()
+{
+    findText(QString());
+    findText(m_highlightedText, QWebPage::HighlightAllOccurrences | QWebPage::FindWrapsAroundDocument);
+}
diff --git a/logviewer/message-view.h b/logviewer/message-view.h
index 9e01260..40c281b 100644
--- a/logviewer/message-view.h
+++ b/logviewer/message-view.h
@@ -37,12 +37,16 @@ public:
     void loadLog(const Tp::AccountPtr &account, const Tpl::EntityPtr &entity,
                  const QDate &date, const QPair< QDate, QDate > &nearestDates);
 
+    void setHighlightText(const QString &text);
+    void clearHighlightText();
+
 public Q_SLOTS:
     void onLinkClicked(const QUrl &link);
 
 private Q_SLOTS:
    void onLoadFinished();
    void onEventsLoaded(Tpl::PendingOperation* po);
+   void doHighlightText();
 
 Q_SIGNALS:
     void conversationSwitchRequested(const QDate &date);
@@ -54,6 +58,8 @@ private:
     QDate m_prev;
     QDate m_next;
 
+    QString m_highlightedText;
+
 };
 
 #endif // MESSAGEVIEW_H

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list