~ps-jenkins/mediascanner2/trusty-proposed

« back to all changes in this revision

Viewing changes to src/qml/Ubuntu/MediaScanner/ArtistsModel.cc

  • Committer: CI bot
  • Author(s): James Henstridge
  • Date: 2014-03-07 17:40:02 UTC
  • mfrom: (211.1.7 megamerge)
  • Revision ID: ps-jenkins@lists.canonical.com-20140307174002-udfe610ez85ixbik
Merge  lp:~jamesh/mediascanner2/qml-plugin,  lp:~jamesh/mediascanner2/short-searches,  lp:~jpakkane/mediascanner2/errmsg, lp:~jpakkane/mediascanner2/cleanshutdown,  lp:~jpakkane/mediascanner2/threadness and lp:~jamesh/mediascanner2/glib-main-loop 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *    James Henstridge <james.henstridge@canonical.com>
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU Lesser General Public License version 3 as
 
9
 * published by the Free Software Foundation.
 
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 Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "ArtistsModel.hh"
 
21
 
 
22
using namespace mediascanner::qml;
 
23
 
 
24
ArtistsModel::ArtistsModel(QObject *parent)
 
25
    : QAbstractListModel(parent),
 
26
      store(nullptr),
 
27
      album_artists(false),
 
28
      limit(-1) {
 
29
    roles[Roles::RoleArtist] = "artist";
 
30
}
 
31
 
 
32
int ArtistsModel::rowCount(const QModelIndex &) const {
 
33
    return results.size();
 
34
}
 
35
 
 
36
QVariant ArtistsModel::data(const QModelIndex &index, int role) const {
 
37
    if (index.row() < 0 || index.row() >= (ptrdiff_t)results.size()) {
 
38
        return QVariant();
 
39
    }
 
40
    switch (role) {
 
41
    case RoleArtist:
 
42
        return QString::fromStdString(results[index.row()]);
 
43
    default:
 
44
        return QVariant();
 
45
    }
 
46
}
 
47
 
 
48
QHash<int, QByteArray> ArtistsModel::roleNames() const {
 
49
    return roles;
 
50
}
 
51
 
 
52
MediaStoreWrapper *ArtistsModel::getStore() {
 
53
    return store;
 
54
}
 
55
 
 
56
void ArtistsModel::setStore(MediaStoreWrapper *store) {
 
57
    if (this->store != store) {
 
58
        this->store = store;
 
59
        update();
 
60
    }
 
61
}
 
62
 
 
63
bool ArtistsModel::getAlbumArtists() {
 
64
    return album_artists;
 
65
}
 
66
 
 
67
void ArtistsModel::setAlbumArtists(bool album_artists) {
 
68
    if (this->album_artists != album_artists) {
 
69
        this->album_artists = album_artists;
 
70
        update();
 
71
    }
 
72
}
 
73
 
 
74
int ArtistsModel::getLimit() {
 
75
    return limit;
 
76
}
 
77
 
 
78
void ArtistsModel::setLimit(int limit) {
 
79
    if (this->limit != limit) {
 
80
        this->limit = limit;
 
81
        update();
 
82
    }
 
83
}
 
84
 
 
85
void ArtistsModel::update() {
 
86
    beginResetModel();
 
87
    if (store == nullptr) {
 
88
        this->results.clear();
 
89
    } else {
 
90
        this->results = store->store.listArtists(album_artists, limit);
 
91
    }
 
92
    this->results = results;
 
93
    endResetModel();
 
94
}