Skip to content

Commit

Permalink
Add a search/filter toolbar for views (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Mar 25, 2014
1 parent 93c89f6 commit 90f1ef1
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 3 deletions.
96 changes: 96 additions & 0 deletions artwork/filter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions harbour-communi.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
<file>ui/images/arrow-down.png</file>
<file>ui/images/complete.png</file>
<file>ui/images/cover.png</file>
<file>ui/images/filter.png</file>
<file>ui/images/warning.png</file>
<file>ui/settings/settings.qml</file>
<file>ui/view/BufferDelegate.qml</file>
<file>ui/view/BufferListPanel.qml</file>
<file>ui/view/BufferPage.qml</file>
<file>ui/view/BufferToolBar.qml</file>
<file>ui/view/NetworkDelegate.qml</file>
<file>ui/view/PageStackScheduler.qml</file>
<file>ui/view/Panel.qml</file>
Expand Down
88 changes: 88 additions & 0 deletions src/bufferfiltermodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright (C) 2013-2014 The Communi Project
You may use this file under the terms of BSD license as follows:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Communi Project nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "bufferfiltermodel.h"
#include "messagestorage.h"
#include "messagemodel.h"
#include <IrcBuffer>

BufferFilterModel::BufferFilterModel(QObject* parent) : QSortFilterProxyModel(parent), m_status(0)
{
setDynamicSortFilter(true);
}

int BufferFilterModel::filterStatus() const
{
return m_status;
}

void BufferFilterModel::setFilterStatus(int status)
{
if (m_status != status) {
m_status = status;
emit filterStatusChanged();
invalidate();
}
}

QString BufferFilterModel::filterString() const
{
return m_filter;
}

void BufferFilterModel::setFilterString(const QString& filter)
{
if (m_filter != filter) {
m_filter = filter;
emit filterStringChanged();
invalidate();
}
}

bool BufferFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
if (m_status == 0 && m_filter.isEmpty())
return true;

QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
IrcBuffer* buffer = index.data(Irc::BufferRole).value<IrcBuffer*>();
if (buffer && !buffer->isSticky()) {
if (!m_filter.isEmpty() && !buffer->title().contains(m_filter, Qt::CaseInsensitive))
return false;
if (m_status > 0) {
MessageModel* model = MessageStorage::instance()->model(buffer);
if (model) {
if (m_status == 1 && model->badge() <= 0)
return false;
if (m_status == 2 && model->activeHighlights() <= 0)
return false;
}
}
}
return true;
}
61 changes: 61 additions & 0 deletions src/bufferfiltermodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright (C) 2013-2014 The Communi Project
You may use this file under the terms of BSD license as follows:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Communi Project nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef BUFFERFILTERMODEL_H
#define BUFFERFILTERMODEL_H

#include <QSortFilterProxyModel>

class BufferFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(int filterStatus READ filterStatus WRITE setFilterStatus NOTIFY filterStatusChanged)
Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)

public:
BufferFilterModel(QObject* parent = 0);

int filterStatus() const;
void setFilterStatus(int status);

QString filterString() const;
void setFilterString(const QString& filter);

signals:
void filterStatusChanged();
void filterStringChanged();

protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;

private:
int m_status;
QString m_filter;
};

#endif // BUFFERFILTERMODEL_H
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sailfishapp.h>

#include "activitymodel.h"
#include "bufferfiltermodel.h"
#include "bufferproxymodel.h"
#include "networksession.h"
#include "messagestorage.h"
Expand Down Expand Up @@ -97,6 +98,10 @@ Q_DECL_EXPORT int main(int argc, char* argv[])
BufferProxyModel* model = new BufferProxyModel(app.data());
viewer->rootContext()->setContextProperty("BufferModel", model);

BufferFilterModel* filter = new BufferFilterModel(app.data());
filter->setSourceModel(model);
viewer->rootContext()->setContextProperty("FilterModel", filter);

ActivityModel* activity = new ActivityModel(app.data());
viewer->rootContext()->setContextProperty("ActivityModel", activity);
QObject::connect(MessageStorage::instance(), SIGNAL(added(MessageModel*)), activity, SLOT(add(MessageModel*)));
Expand Down
5 changes: 5 additions & 0 deletions src/messagestorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ MessageStorage* MessageStorage::instance()
return &storage;
}

MessageModel* MessageStorage::model(IrcBuffer* buffer) const
{
return m_models.value(buffer);
}

QObject* MessageStorage::get(IrcBuffer* buffer) const
{
return m_models.value(buffer);
Expand Down
1 change: 1 addition & 0 deletions src/messagestorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MessageStorage : public QObject
public:
static MessageStorage* instance();

MessageModel* model(IrcBuffer* buffer) const;
Q_INVOKABLE QObject* get(IrcBuffer* buffer) const;

IrcBuffer* currentBuffer() const;
Expand Down
2 changes: 2 additions & 0 deletions src/src.pri
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DEPENDPATH += $$PWD $$PWD/3rdparty
INCLUDEPATH += $$PWD $$PWD/3rdparty

HEADERS += $$PWD/activitymodel.h
HEADERS += $$PWD/bufferfiltermodel.h
HEADERS += $$PWD/bufferproxymodel.h
HEADERS += $$PWD/messagefilter.h
HEADERS += $$PWD/messagemodel.h
Expand All @@ -12,6 +13,7 @@ HEADERS += $$PWD/3rdparty/RowsJoinerProxy.h
HEADERS += $$PWD/3rdparty/simplecrypt.h

SOURCES += $$PWD/activitymodel.cpp
SOURCES += $$PWD/bufferfiltermodel.cpp
SOURCES += $$PWD/bufferproxymodel.cpp
SOURCES += $$PWD/messagefilter.cpp
SOURCES += $$PWD/messagemodel.cpp
Expand Down
Binary file added ui/images/filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 21 additions & 2 deletions ui/view/BufferListPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ Panel {
SilicaListView {
pressDelay: 0
anchors.fill: parent
anchors.bottomMargin: toolbar.height - 2

model: BufferModel
model: FilterModel

section.property: "section"
section.labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
Expand All @@ -50,7 +51,7 @@ Panel {
}

delegate: BufferDelegate {
buffer: model.buffer
buffer: model.buffer || null
onClicked: panel.clicked(model.buffer)
}

Expand All @@ -59,4 +60,22 @@ Panel {
anchors.right: undefined
}
}

Binding {
target: FilterModel
property: "filterStatus"
value: toolbar.checked
}

Binding {
target: FilterModel
property: "filterString"
value: toolbar.filter
}

BufferToolBar {
id: toolbar
width: parent.width
anchors.bottom: parent.bottom
}
}
2 changes: 1 addition & 1 deletion ui/view/BufferPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Page {
width: parent.width

backgroundVisible: !positioner.running && !pushUpMenu.active && !view.atYEnd
opacity: pullDownMenu.active || pushUpMenu.active ? 0.0 : 1.0
opacity: !viewer.closed || pullDownMenu.active || pushUpMenu.active ? 0.0 : 1.0
Behavior on opacity { FadeAnimation { } }
}
}
Expand Down
Loading

0 comments on commit 90f1ef1

Please sign in to comment.