Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/lib/qutim/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ namespace qutim_sdk_0_3
return AsyncResult<MessageList>::create(MessageList());
}

void showHistory(const ChatUnit *) override
{
}

AsyncResult<QVector<AccountInfo>> accounts() override
{
return AsyncResult<QVector<AccountInfo>>::create(QVector<AccountInfo>());
Expand All @@ -63,12 +59,12 @@ namespace qutim_sdk_0_3
return AsyncResult<QVector<ContactInfo>>::create(QVector<ContactInfo>());
}

AsyncResult<QList<QDate>> months(const ContactInfo &, const QRegularExpression &) override
AsyncResult<QList<QDate>> months(const ContactInfo &, const QString &) override
{
return AsyncResult<QList<QDate>>::create(QList<QDate>());
}

AsyncResult<QList<QDate>> dates(const ContactInfo &, const QDate &, const QRegularExpression &) override
AsyncResult<QList<QDate>> dates(const ContactInfo &, const QDate &, const QString &) override
{
return AsyncResult<QList<QDate>>::create(QList<QDate>());
}
Expand Down
23 changes: 18 additions & 5 deletions src/lib/qutim/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace qutim_sdk_0_3
{
class ChatUnit;

/**
* @brief The History class is base class to implement history storage plugins
*/
class LIBQUTIM_EXPORT History : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -61,11 +64,24 @@ namespace qutim_sdk_0_3
};

virtual void store(const Message &message) = 0;
/**
* Read messages from history.
* \warning \a from or/and \a to parameter can be invalid, which means that
* you should ignore that parameter
*/
virtual AsyncResult<MessageList> read(const ContactInfo &contact, const QDateTime &from, const QDateTime &to, int max_num) = 0;
virtual AsyncResult<QVector<AccountInfo>> accounts() = 0;
virtual AsyncResult<QVector<ContactInfo>> contacts(const AccountInfo &account) = 0;
virtual AsyncResult<QList<QDate>> months(const ContactInfo &contact, const QRegularExpression &regex) = 0;
virtual AsyncResult<QList<QDate>> dates(const ContactInfo &contact, const QDate &month, const QRegularExpression &regex) = 0;
/**
* Returns list of date(year, month). If search string is presented, you may return list of months where
* at least message contains search string.
*/
virtual AsyncResult<QList<QDate>> months(const ContactInfo &contact, const QString &needle) = 0;
/**
* Returns list of days in month of certain year. If search string is not empty, you should return list of days
* where at least one message with search string is presented
*/
virtual AsyncResult<QList<QDate>> dates(const ContactInfo &contact, const QDate &month, const QString &needle) = 0;

AsyncResult<MessageList> read(const ChatUnit *unit, const QDateTime &to, int max_num);
AsyncResult<MessageList> read(const ChatUnit *unit, int max_num);
Expand All @@ -75,9 +91,6 @@ namespace qutim_sdk_0_3

static ContactInfo info(const ChatUnit *unit);

public slots:
virtual void showHistory(const ChatUnit *unit) = 0;

protected:
History();

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/generic/generic.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Project {
"formula/formula.qbs",
"highlighter/highlighter.qbs",
"histman/histman.qbs",
"histview/histview.qbs",
"hunspeller/hunspeller.qbs",
"idledetector/idledetector.qbs",
"idlestatuschanger/idlestatuschanger.qbs",
Expand Down Expand Up @@ -75,6 +76,7 @@ Project {
"simplecontactlist/simplecontactlist.qbs",
"simplerosterstorage/simplerosterstorage.qbs",
"soundthemeselector/soundthemeselector.qbs",
"sqlitehistory/sqlitehistory.qbs",
"trayicon/trayicon.qbs",
"unreadmessageskeeper/unreadmessageskeeper.qbs",
"updater/updater.qbs",
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/generic/histview/histview.plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"pluginIcon": "",
"pluginName": "History View",
"pluginDescription": "Simple separate window plugin for viewing history",
"extensionHeader": "src/histview.h",
"extensionClass": "Core::HistView"
}
5 changes: 5 additions & 0 deletions src/plugins/generic/histview/histview.qbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "../GenericPlugin.qbs" as GenericPlugin

GenericPlugin {

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ HistoryWindow::HistoryWindow(const ChatUnit *unit)
ui.setupUi(this);

ui.historyLog->setHtml("<p align='center'><span style='font-size:36pt;'>"
+ tr("No History") + "</span></p>");
+ tr("No History") + "</span></p>");
ui.label_in->setText( tr( "In: %L1").arg( 0 ) );
ui.label_out->setText( tr( "Out: %L1").arg( 0 ) );
ui.label_all->setText( tr( "All: %L1").arg( 0 ) );
Expand All @@ -92,6 +92,8 @@ HistoryWindow::HistoryWindow(const ChatUnit *unit)

connect(ui.dateTreeWidget, &QTreeWidget::itemExpanded, this, &HistoryWindow::fillMonth);

connect(ui.dateTreeWidget, &QTreeWidget::itemCollapsed, this, &HistoryWindow::clearMonth);

fillAccountComboBox();

setParent(QApplication::activeWindow());
Expand Down Expand Up @@ -126,7 +128,21 @@ void HistoryWindow::setUnit(const ChatUnit *unit)
void HistoryWindow::setIcons()
{
// setWindowIcon(Icon("history"));
// ui.searchButton->setIcon(Icon("search"));
// ui.searchButton->setIcon(Icon("search"));
}

QTreeWidgetItem *HistoryWindow::findChild(QTreeWidgetItem *parent, const QVariant &value)
{
if (!parent)
return nullptr;

for (int i = 0; i < parent->childCount(); ++i) {
QTreeWidgetItem *child = parent->child(i);
if (child->data(0, Qt::UserRole) == value)
return child;
}

return nullptr;
}

void HistoryWindow::fillAccountComboBox()
Expand All @@ -146,10 +162,14 @@ void HistoryWindow::fillAccountComboBox()
connect(ui.accountComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &HistoryWindow::fillContactComboBox);
int accountIndex = ui.accountComboBox->findData(QVariant::fromValue<History::AccountInfo>(m_unitInfo));

if (accountIndex < 0)
fillContactComboBox(0);
else
else {
ui.accountComboBox->setCurrentIndex(accountIndex);
fillContactComboBox(accountIndex);
}

});
}

Expand Down Expand Up @@ -201,7 +221,7 @@ void HistoryWindow::fillDateTreeWidget(int index)

setWindowTitle(QStringLiteral("%1 (%2)").arg(ui.fromComboBox->currentText(), ui.accountComboBox->currentText()));

history()->months(contactInfo, m_search).connect(this, [this, contactInfo] (const QList<QDate> &months) {
history()->months(contactInfo, m_search_word).connect(this, [this, contactInfo] (const QList<QDate> &months) {
int index = ui.fromComboBox->currentIndex();
auto currentContactInfo = ui.fromComboBox->itemData(index).value<History::ContactInfo>();
if (!(currentContactInfo == contactInfo))
Expand Down Expand Up @@ -244,25 +264,12 @@ void HistoryWindow::fillMonth(QTreeWidgetItem *monthItem)
auto contactInfo = ui.fromComboBox->itemData(contactIndex).value<History::ContactInfo>();
auto month = monthItem->data(0, Qt::UserRole).toDate();

history()->dates(contactInfo, month, m_search).connect(this, [this, contactInfo, month] (const QList<QDate> &dates) {
history()->dates(contactInfo, month, m_search_word).connect(this, [this, contactInfo, month] (const QList<QDate> &dates) {
int contactIndex = ui.fromComboBox->currentIndex();
auto currentContactInfo = ui.fromComboBox->itemData(contactIndex).value<History::ContactInfo>();
if (!(currentContactInfo == contactInfo))
return;

auto findChild = [] (QTreeWidgetItem *parent, const QVariant &value) -> QTreeWidgetItem * {
if (!parent)
return nullptr;

for (int i = 0; i < parent->childCount(); ++i) {
QTreeWidgetItem *child = parent->child(i);
if (child->data(0, Qt::UserRole) == value)
return child;
}

return nullptr;
};

auto monthItem = findChild(findChild(ui.dateTreeWidget->invisibleRootItem(), month.year()), month);
if (!monthItem)
return;
Expand All @@ -276,6 +283,18 @@ void HistoryWindow::fillMonth(QTreeWidgetItem *monthItem)
});
}

void HistoryWindow::clearMonth(QTreeWidgetItem *monthItem) {
auto month = monthItem->data(0, Qt::UserRole).toDate();

auto item = findChild(findChild(ui.dateTreeWidget->invisibleRootItem(), month.year()), month);

if(item) {
auto items = item->takeChildren();
qDeleteAll(items);
}
}


void HistoryWindow::on_dateTreeWidget_currentItemChanged(QTreeWidgetItem *dayItem, QTreeWidgetItem *)
{
QTreeWidgetItem *monthItem = dayItem ? dayItem->parent() : nullptr;
Expand Down Expand Up @@ -351,7 +370,11 @@ void HistoryWindow::on_dateTreeWidget_currentItemChanged(QTreeWidgetItem *dayIte
cursor.insertHtml(historyMessage);
cursor.insertText(QStringLiteral("\n"));
} else {
cursor.insertHtml(historyMessage.replace(m_search, resultString));
QRegularExpression expr;
expr.setPattern(QLatin1Char('(') + QRegularExpression::escape(m_search_word) + QLatin1Char(')'));
expr.setPatternOptions(QRegularExpression::MultilineOption | QRegularExpression::CaseInsensitiveOption);

cursor.insertHtml(historyMessage.replace(expr, resultString));
cursor.insertText(QStringLiteral("\n"));
}
}
Expand Down Expand Up @@ -382,8 +405,6 @@ void HistoryWindow::on_searchButton_clicked()
}
} else {
m_search_word = searchWord;
m_search.setPattern(QLatin1Char('(') + QRegularExpression::escape(searchWord) + QLatin1Char(')'));
m_search.setPatternOptions(QRegularExpression::MultilineOption | QRegularExpression::CaseInsensitiveOption);
fillDateTreeWidget(ui.fromComboBox->currentIndex());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ using namespace qutim_sdk_0_3;

namespace Core
{
class JsonEngine;

class HistoryWindow : public QWidget
{
Expand All @@ -52,6 +51,7 @@ private slots:
void fillContactComboBox(int index);
void fillDateTreeWidget(int index);
void fillMonth(QTreeWidgetItem *month);
void clearMonth(QTreeWidgetItem *month);
void on_dateTreeWidget_currentItemChanged( QTreeWidgetItem* current, QTreeWidgetItem* previous );
void on_searchButton_clicked();
void findPrevious();
Expand All @@ -62,8 +62,8 @@ private slots:
Ui::HistoryWindowClass ui;
QMetaObject::Connection m_contactConnection;
History::ContactInfo m_unitInfo;
QRegularExpression m_search;
QString m_search_word;
QTreeWidgetItem* findChild(QTreeWidgetItem *parent, const QVariant &value);
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@
<string>HistoryWindow</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item row="0" column="0">
Expand All @@ -40,10 +49,18 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QComboBox" name="accountComboBox"/>
<widget class="QComboBox" name="accountComboBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="fromComboBox"/>
<widget class="QComboBox" name="fromComboBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
</layout>
</item>
Expand Down
81 changes: 81 additions & 0 deletions src/plugins/generic/histview/src/histview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/****************************************************************************
**
** qutIM - instant messenger
**
** Copyright © 2015 Nicolay Izoderov <[email protected]>
**
*****************************************************************************
**
** $QUTIM_BEGIN_LICENSE$
** 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
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see http://www.gnu.org/licenses/.
** $QUTIM_END_LICENSE$
**
****************************************************************************/

#include "histview.h"
#include <QPoint>
#include <QApplication>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QDir>
#include <qutim/icon.h>
#include <qutim/protocol.h>
#include <qutim/accountmanager.h>
#include <qutim/chatunit.h>
#include <QScrollBar>
#include <QStringBuilder>
#include <QDebug>
#include <qutim/systemintegration.h>
#include <qutim/shortcut.h>

namespace Core
{

HistView::HistView()
{
m_historyAction = new ActionGenerator(Icon("view-history"),
QT_TRANSLATE_NOOP("Chat", "View History"),
this,
SLOT(onHistoryActionTriggered(QObject*)));
m_historyAction->setType(ActionTypeChatButton|ActionTypeContactList);
m_historyAction->setPriority(512);
MenuController::addAction<ChatUnit>(m_historyAction);
}

HistView::~HistView()
{
delete m_historyAction;
}

void HistView::onHistoryActionTriggered(QObject* object)
{
ChatUnit *unit = qobject_cast<ChatUnit*>(object);
Q_ASSERT(unit);

showHistory(unit);
}

void HistView::showHistory(const ChatUnit *unit)
{
unit = unit->getHistoryUnit();
if (m_historyWindow) {
m_historyWindow.data()->setUnit(unit);
m_historyWindow.data()->raise();
} else {
m_historyWindow = new HistoryWindow(unit);
m_historyWindow.data()->show();
}
}

}
Loading