2
* Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
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
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
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.
20
#include "ApplicationProxyModelHelper.h"
21
#include <ApplicationModel/ApplicationModel.h>
22
#include "BackendsSingleton.h"
24
#include <LibQApt/Backend>
26
ApplicationProxyModelHelper::ApplicationProxyModelHelper(QObject* parent)
27
: ApplicationProxyModel(parent)
29
if(BackendsSingleton::self()->backend())
32
connect(BackendsSingleton::self(), SIGNAL(initialized()), SLOT(init()));
35
void ApplicationProxyModelHelper::init()
37
setBackend(BackendsSingleton::self()->backend());
38
setSourceModel(BackendsSingleton::self()->appsModel());
40
if(!m_sortRoleString.isEmpty())
41
setStringSortRole_hack(m_sortRoleString);
43
connect(BackendsSingleton::self()->appsModel(), SIGNAL(modelReset()),
48
void ApplicationProxyModelHelper::sortModel()
50
QSortFilterProxyModel::sort(sortColumn(), sortOrder());
53
void ApplicationProxyModelHelper::setStateFilter_hack(int state)
55
setStateFilter((QApt::Package::State) state);
56
emit stateFilterChanged();
59
Application* ApplicationProxyModelHelper::applicationAt(int row)
61
return ApplicationProxyModel::applicationAt(index(row, 0));
64
int ApplicationProxyModelHelper::stringToRole(const QByteArray& strRole) const
66
return roleNames().key(strRole);
69
QByteArray ApplicationProxyModelHelper::roleToString(int role) const
71
return roleNames().value(role);
74
void ApplicationProxyModelHelper::setSortRole_hack(int role)
77
emit sortRoleChanged();
80
void ApplicationProxyModelHelper::setSortOrder_hack(Qt::SortOrder order)
83
emit sortOrderChanged();
86
void ApplicationProxyModelHelper::setStringSortRole_hack(const QString& role)
88
setSortRole_hack(stringToRole(role.toUtf8()));
89
m_sortRoleString = role;
92
QString ApplicationProxyModelHelper::stringSortRole() const
94
return roleToString(sortRole());
97
void ApplicationProxyModelHelper::setOriginHostFilter(const QString& host)
99
QString origin = BackendsSingleton::self()->backend()->originForSite(QUrl(host).host());
100
setOriginFilter(origin);