~ubuntu-branches/ubuntu/trusty/mediascanner/trusty-proposed

« back to all changes in this revision

Viewing changes to src/mediascanner/mediautils.h

  • Committer: Package Import Robot
  • Author(s): Łukasz 'sil2100' Zemczak
  • Date: 2013-08-13 18:47:34 UTC
  • Revision ID: package-import@ubuntu.com-20130813184734-u3lyvu2u1hgybryc
Tags: upstream-0.3.93
Import upstream version 0.3.93

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the Ubuntu TV Media Scanner
 
3
 * Copyright (C) 2012-2013 Canonical Ltd.
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU Lesser General Public License version 3 as
 
7
 * published by the 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 Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public License
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Contact: Jim Hodapp <jim.hodapp@canonical.com>
 
18
 * Authored by: Mathias Hasselmann <mathias@openismus.com>
 
19
 */
 
20
#ifndef MEDIASCANNER_MEDIAUTILS_H
 
21
#define MEDIASCANNER_MEDIAUTILS_H
 
22
 
 
23
// C++ Standard Library
 
24
#include <string>
 
25
#include <vector>
 
26
 
 
27
// Media Scanner Library
 
28
#include "mediascanner/property.h"
 
29
 
 
30
typedef struct _GList GList;
 
31
typedef struct _GrlMedia GrlMedia;
 
32
 
 
33
namespace mediascanner {
 
34
 
 
35
class MimeType {
 
36
public:
 
37
    static const MimeType kApplicationOgg;
 
38
    static const MimeType kAudioPrefix;
 
39
    static const MimeType kImagePrefix;
 
40
    static const MimeType kVideoPrefix;
 
41
 
 
42
    explicit MimeType(const std::string &str)
 
43
        : str_(str.begin(), str.end()) {
 
44
    }
 
45
 
 
46
    explicit MimeType(const std::wstring &str)
 
47
        : str_(str) {
 
48
    }
 
49
 
 
50
    const std::wstring& str() const {
 
51
        return str_;
 
52
    }
 
53
 
 
54
    bool is_audio() const;
 
55
    bool is_image() const;
 
56
    bool is_video() const;
 
57
 
 
58
    GrlMedia* make_media() const;
 
59
 
 
60
private:
 
61
    std::wstring str_;
 
62
};
 
63
 
 
64
class MediaInfo {
 
65
private:
 
66
    typedef std::vector<Property::ValueMap> PropertyVector;
 
67
 
 
68
public:
 
69
    typedef PropertyVector::const_iterator const_iterator;
 
70
    typedef PropertyVector::value_type value_type;
 
71
 
 
72
    MediaInfo();
 
73
 
 
74
    void add_related(const Property::ValueMap &properties);
 
75
    void add_single(const Property::BoundValue &value);
 
76
 
 
77
    Property::Value first(Property key) const;
 
78
    size_t count(Property key) const;
 
79
 
 
80
    template<typename PropertyType, typename ValueType>
 
81
    ValueType first(const GenericProperty<PropertyType, ValueType> &key) const;
 
82
 
 
83
    std::wstring first(StringProperty key) const {
 
84
        return first<StringProperty, std::wstring>(key);
 
85
    }
 
86
 
 
87
    std::wstring first(TextProperty key) const {
 
88
        return first<TextProperty, std::wstring>(key);
 
89
    }
 
90
 
 
91
 
 
92
    GrlMedia* make_media(GList *const requested_keys) const;
 
93
    GrlMedia* make_media(GList *const requested_keys,
 
94
                         const std::string &url) const;
 
95
 
 
96
    void copy_to_media(GList *const requested_keys,
 
97
                       GrlMedia *const media) const;
 
98
    bool fill_from_media(GrlMedia *media, const GList *const requested_keys,
 
99
                         GList **failed_keys, std::string *error_message);
 
100
 
 
101
    const_iterator begin() const {
 
102
        return related_properties_.begin();
 
103
    }
 
104
 
 
105
    const_iterator end() const {
 
106
        return related_properties_.end();
 
107
    }
 
108
 
 
109
    bool empty() const;
 
110
 
 
111
    bool operator==(const MediaInfo &other) const {
 
112
        return related_properties_ == other.related_properties_;
 
113
    }
 
114
 
 
115
    bool operator!=(const MediaInfo &other) const {
 
116
        return not operator==(other);
 
117
    }
 
118
 
 
119
private:
 
120
    std::vector<Property::ValueMap> related_properties_;
 
121
};
 
122
 
 
123
template<typename P, typename V>
 
124
inline V MediaInfo::first(const GenericProperty<P, V> &key) const {
 
125
    const Property::Value value = first(static_cast<Property>(key));
 
126
    return value.which() ? boost::get<V>(value) : V();
 
127
}
 
128
 
 
129
} // namespace mediascanner
 
130
 
 
131
#endif // MEDIASCANNER_MEDIAUTILS_H