~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to discover/ApplicationProxyModelHelper.cpp

Tags: upstream-1.3.65
ImportĀ upstreamĀ versionĀ 1.3.65

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library/Lesser General Public License
 
6
 *   version 2, or (at your option) any later version, as published by the
 
7
 *   Free Software Foundation
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library/Lesser General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "ApplicationProxyModelHelper.h"
 
21
#include <ApplicationModel/ApplicationModel.h>
 
22
#include "BackendsSingleton.h"
 
23
#include <QDebug>
 
24
#include <LibQApt/Backend>
 
25
 
 
26
ApplicationProxyModelHelper::ApplicationProxyModelHelper(QObject* parent)
 
27
    : ApplicationProxyModel(parent)
 
28
{
 
29
    if(BackendsSingleton::self()->backend())
 
30
        init();
 
31
    else
 
32
        connect(BackendsSingleton::self(), SIGNAL(initialized()), SLOT(init()));
 
33
}
 
34
 
 
35
void ApplicationProxyModelHelper::init()
 
36
{
 
37
    setBackend(BackendsSingleton::self()->backend());
 
38
    setSourceModel(BackendsSingleton::self()->appsModel());
 
39
    
 
40
    if(!m_sortRoleString.isEmpty())
 
41
        setStringSortRole_hack(m_sortRoleString);
 
42
    
 
43
    connect(BackendsSingleton::self()->appsModel(), SIGNAL(modelReset()),
 
44
            SLOT(sortModel()));
 
45
    sortModel();
 
46
}
 
47
 
 
48
void ApplicationProxyModelHelper::sortModel()
 
49
{
 
50
    QSortFilterProxyModel::sort(sortColumn(), sortOrder());
 
51
}
 
52
 
 
53
void ApplicationProxyModelHelper::setStateFilter_hack(int state)
 
54
{
 
55
    setStateFilter((QApt::Package::State) state);
 
56
    emit stateFilterChanged();
 
57
}
 
58
 
 
59
Application* ApplicationProxyModelHelper::applicationAt(int row)
 
60
{
 
61
    return ApplicationProxyModel::applicationAt(index(row, 0));
 
62
}
 
63
 
 
64
int ApplicationProxyModelHelper::stringToRole(const QByteArray& strRole) const
 
65
{
 
66
    return roleNames().key(strRole);
 
67
}
 
68
 
 
69
QByteArray ApplicationProxyModelHelper::roleToString(int role) const
 
70
{
 
71
    return roleNames().value(role);
 
72
}
 
73
 
 
74
void ApplicationProxyModelHelper::setSortRole_hack(int role)
 
75
{
 
76
    setSortRole(role);
 
77
    emit sortRoleChanged();
 
78
}
 
79
 
 
80
void ApplicationProxyModelHelper::setSortOrder_hack(Qt::SortOrder order)
 
81
{
 
82
    sort(0, order);
 
83
    emit sortOrderChanged();
 
84
}
 
85
 
 
86
void ApplicationProxyModelHelper::setStringSortRole_hack(const QString& role)
 
87
{
 
88
    setSortRole_hack(stringToRole(role.toUtf8()));
 
89
    m_sortRoleString = role;
 
90
}
 
91
 
 
92
QString ApplicationProxyModelHelper::stringSortRole() const
 
93
{
 
94
    return roleToString(sortRole());
 
95
}
 
96
 
 
97
void ApplicationProxyModelHelper::setOriginHostFilter(const QString& host)
 
98
{
 
99
    QString origin = BackendsSingleton::self()->backend()->originForSite(QUrl(host).host());
 
100
    setOriginFilter(origin);
 
101
}