~jamesh/mediascanner/qml-plugin

« back to all changes in this revision

Viewing changes to src/mediascanner/MediaFileBuilder.cc

  • Committer: Tarmac
  • Author(s): Jussi Pakkanen
  • Date: 2013-12-02 16:20:17 UTC
  • mfrom: (186.2.12 mediascanner)
  • Revision ID: tarmac-20131202162017-tjcflnrvqvx489qp
Made MediaFile immutable.

Approved by James Henstridge, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *    Jussi Pakkanen <jussi.pakkanen@canonical.com>
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or modify it under
 
8
 * the terms of version 3 of the GNU General Public License as published
 
9
 * by the Free Software Foundation.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 
14
 * 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
#include"MediaFileBuilder.hh"
 
21
#include"MediaFile.hh"
 
22
#include<stdexcept>
 
23
 
 
24
MediaFileBuilder::MediaFileBuilder(const std::string &fname) {
 
25
    filename = fname;
 
26
}
 
27
 
 
28
MediaFileBuilder::MediaFileBuilder(const MediaFile &mf) :
 
29
    type(mf.getType()),
 
30
    filename(mf.getFileName()),
 
31
    content_type(mf.getContentType()),
 
32
    etag(mf.getETag()),
 
33
    title(mf.getTitle()),
 
34
    date(mf.getDate()),
 
35
    author(mf.getAuthor()),
 
36
    album(mf.getAlbum()),
 
37
    album_artist(mf.getAlbumArtist()),
 
38
    track_number(mf.getTrackNumber()),
 
39
    duration(mf.getDuration()) {
 
40
}
 
41
 
 
42
MediaFile MediaFileBuilder::build() const {
 
43
    return MediaFile(filename, content_type, etag, title, date, author,
 
44
            album, album_artist, track_number, duration, type);
 
45
}
 
46
 
 
47
void MediaFileBuilder::setType(MediaType t) {
 
48
    if(type_set)
 
49
        throw std::invalid_argument("Tried to set type when it was already set.");
 
50
    type = t;
 
51
    type_set = true;
 
52
}
 
53
 
 
54
void MediaFileBuilder::setETag(const std::string &e) {
 
55
    if(etag_set)
 
56
        throw std::invalid_argument("Tried to set filename when it was already set.");
 
57
    etag = e;
 
58
    etag_set = true;
 
59
 
 
60
}
 
61
void MediaFileBuilder::setContentType(const std::string &c) {
 
62
    if(content_type_set)
 
63
        throw std::invalid_argument("Tried to set filename when it was already set.");
 
64
    content_type = c;
 
65
    content_type_set = true;
 
66
 
 
67
}
 
68
 
 
69
void MediaFileBuilder::setTitle(const std::string &t) {
 
70
    if(title_set)
 
71
        throw std::invalid_argument("Tried to set title when it was already set.");
 
72
    title = t;
 
73
    title_set = true;
 
74
}
 
75
 
 
76
void MediaFileBuilder::setDate(const std::string &d) {
 
77
    if(date_set)
 
78
        throw std::invalid_argument("Tried to set date when it was already set.");
 
79
    date = d;
 
80
    date_set = true;
 
81
}
 
82
 
 
83
void MediaFileBuilder::setAuthor(const std::string &a) {
 
84
    if(author_set)
 
85
        throw std::invalid_argument("Tried to set author when it was already set.");
 
86
    author = a;
 
87
    author_set = true;
 
88
}
 
89
 
 
90
void MediaFileBuilder::setAlbum(const std::string &a) {
 
91
    if(album_set)
 
92
        throw std::invalid_argument("Tried to set album when it was already set.");
 
93
    album = a;
 
94
    album_set = true;
 
95
}
 
96
 
 
97
void MediaFileBuilder::setAlbumArtist(const std::string &a) {
 
98
    if(album_artist_set)
 
99
        throw std::invalid_argument("Tried to set album artist when it was already set.");
 
100
    album_artist = a;
 
101
    album_artist_set = true;
 
102
}
 
103
 
 
104
void MediaFileBuilder::setTrackNumber(int n) {
 
105
    if(track_number_set)
 
106
        throw std::invalid_argument("Tried to set track number when it was already set.");
 
107
    track_number = n;
 
108
    track_number_set = true;
 
109
}
 
110
 
 
111
void MediaFileBuilder::setDuration(int n) {
 
112
    if(duration_set)
 
113
        throw std::invalid_argument("Tried to set duration when it was already set.");
 
114
    duration = n;
 
115
    duration_set = true;
 
116
}