~ubuntu-branches/ubuntu/wily/unity-2d/wily

« back to all changes in this revision

Viewing changes to libunity-2d-private/src/filters.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-08-25 18:16:57 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20110825181657-opb29rqsxae3i98f
Tags: 4.2.0-0ubuntu1
* New upstream release:
  - [panel] application menus do not appear on first hover after dismissal
    (lp: #825262)
  - [dash] Lens icons badly scaled (lp: #825368)
  - [panel] indicators are shifted offscreen to the right (lp: #827673)
  - [panel] scrubbing from system indicators to menubar should be possible
    (lp: #706903)
  - [launcher] Closed applications don't get their launcher counts cleared
    (lp: #767367)
  - [dash] selected item should not be underlined but use the same 
    treatment as unity (lp: #817456)
  - [dash] categories should be collapsed by default (lp: #827214)
  - [dash] Ratings filter (lp: #831855)
  - [dash] Multirange filter (lp: #831856)
  - [dash] ToggleButton filter (lp: #831857)
  - [dash] Icon size must be bigger to match the mockups (lp: #831858)
  - [dash] "Refine search" right margin should be 15 pixels (lp: #832058)
  - [dash] "Refine search" should be "Filter results" (lp: #832060)
  - [dash] Font sizes should match new design (lp: #832114)
  - [panel] Glitch: application menu appearing when pressing the BFB 
    (lp: #825060)
  - [panel] Glitch: application menus are quickly opened after a drag gesture
    (lp: #825267)
  - [dash] File thumbnails aspect ratio is not respected (lp: #832204)
* debian/control: require current the current versions of nux and unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Florian Boucault <florian.boucault@canonical.com>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; version 3.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
// Self
 
21
#include "filters.h"
 
22
 
 
23
// Local
 
24
#include "filter.h"
 
25
 
 
26
// Qt
 
27
#include <QDebug>
 
28
 
 
29
// libunity-core
 
30
#include <UnityCore/Filters.h>
 
31
 
 
32
Filters::Filters(unity::dash::Filters::Ptr unityFilters, QObject *parent) :
 
33
    QAbstractListModel(parent), m_unityFilters(unityFilters)
 
34
{
 
35
    QHash<int, QByteArray> roles;
 
36
    roles[Filters::RoleFilter] = "filter";
 
37
    setRoleNames(roles);
 
38
 
 
39
    for (unsigned int i=0; i<m_unityFilters->count(); i++) {
 
40
        unity::dash::Filter::Ptr unityFilter = m_unityFilters->FilterAtIndex(i);
 
41
        addFilter(unityFilter, i);
 
42
    }
 
43
    m_unityFilters->filter_added.connect(sigc::mem_fun(this, &Filters::onFilterAdded));
 
44
    m_unityFilters->filter_changed.connect(sigc::mem_fun(this, &Filters::onFilterChanged));
 
45
    m_unityFilters->filter_removed.connect(sigc::mem_fun(this, &Filters::onFilterRemoved));
 
46
}
 
47
 
 
48
Filters::~Filters()
 
49
{
 
50
    while (!m_filters.isEmpty()) {
 
51
        delete m_filters.takeFirst();
 
52
    }
 
53
}
 
54
 
 
55
int Filters::rowCount(const QModelIndex& parent) const
 
56
{
 
57
    Q_UNUSED(parent)
 
58
 
 
59
    return m_unityFilters->count();
 
60
}
 
61
 
 
62
QVariant Filters::data(const QModelIndex& index, int role) const
 
63
{
 
64
    Q_UNUSED(role)
 
65
 
 
66
    if (!index.isValid()) {
 
67
        return QVariant();
 
68
    }
 
69
 
 
70
    Filter* filter = m_filters.at(index.row());
 
71
 
 
72
    if (role == Filters::RoleFilter) {
 
73
        return QVariant::fromValue(filter);
 
74
    } else {
 
75
        return QVariant();
 
76
    }
 
77
}
 
78
 
 
79
void Filters::onFilterAdded(unity::dash::Filter::Ptr unityFilter)
 
80
{
 
81
    if (unityFilter == NULL) {
 
82
        return;
 
83
    }
 
84
 
 
85
    /* FIXME: figure out actual index of unityFilter; for now filters are appended */
 
86
    int index = m_filters.count();
 
87
    addFilter(unityFilter, index);
 
88
}
 
89
 
 
90
void Filters::onFilterChanged(unity::dash::Filter::Ptr unityFilter)
 
91
{
 
92
    if (unityFilter == NULL) {
 
93
        return;
 
94
    }
 
95
 
 
96
    QModelIndex filterIndex = index(indexForFilter(unityFilter));
 
97
    Q_EMIT dataChanged(filterIndex, filterIndex);
 
98
}
 
99
 
 
100
void Filters::onFilterRemoved(unity::dash::Filter::Ptr unityFilter)
 
101
{
 
102
    removeFilter(indexForFilter(unityFilter));
 
103
}
 
104
 
 
105
void Filters::addFilter(unity::dash::Filter::Ptr unityFilter, int index)
 
106
{
 
107
    beginInsertRows(QModelIndex(), index, index);
 
108
    Filter* filter = Filter::newFromUnityFilter(unityFilter);
 
109
    m_filters.insert(index, filter);
 
110
    endInsertRows();
 
111
}
 
112
 
 
113
void Filters::removeFilter(int index)
 
114
{
 
115
    beginRemoveRows(QModelIndex(), index, index);
 
116
    Filter* filter = m_filters.takeAt(index);
 
117
    delete filter;
 
118
    endRemoveRows();
 
119
}
 
120
 
 
121
int Filters::indexForFilter(unity::dash::Filter::Ptr unityFilter)
 
122
{
 
123
    int index;
 
124
    for (index=0; index<m_filters.count(); index++) {
 
125
        if (m_filters[index]->hasUnityFilter(unityFilter)) {
 
126
            return index;
 
127
        }
 
128
    }
 
129
    qWarning() << "Filter" << QString::fromStdString(unityFilter->name()) << "not found in local cache.";
 
130
    return -1;
 
131
}
 
132
 
 
133
 
 
134
#include "filters.moc"