1/***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2013 by Vishesh Handa <me@vhanda.in> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21#ifndef KBALOO_ROLESPROVIDER_H
22#define KBALOO_ROLESPROVIDER_H
23
24#include <libdolphin_export.h>
25
26#include <QHash>
27#include <QSet>
28#include <QUrl>
29
30namespace Baloo {
31 class File;
32}
33
34/**
35 * @brief Allows accessing metadata of a file by providing KFileItemModel roles.
36 *
37 * Is a helper class for KFileItemModelRolesUpdater to retrieve roles that
38 * are only accessible with Baloo.
39 */
40class LIBDOLPHINPRIVATE_EXPORT KBalooRolesProvider
41{
42public:
43 static KBalooRolesProvider& instance();
44 virtual ~KBalooRolesProvider();
45
46 /**
47 * @return Roles that can be provided by KBalooRolesProvider.
48 */
49 QSet<QByteArray> roles() const;
50
51 /**
52 * @return Values for the roles \a roles that can be determined from the file
53 * with the URL \a url.
54 */
55 QHash<QByteArray, QVariant> roleValues(const Baloo::File& file,
56 const QSet<QByteArray>& roles) const;
57
58 QByteArray roleForProperty(const QString& property) const;
59
60protected:
61 KBalooRolesProvider();
62
63private:
64 /**
65 * @return User visible string for the given tag-values.
66 */
67 QString tagsFromValues(const QStringList& values) const;
68
69 /**
70 * @return User visible string for the EXIF-orientation property
71 * which can have the values 0 to 8.
72 * (see http://sylvana.net/jpegcrop/exif_orientation.html)
73 */
74 QString orientationFromValue(int value) const;
75
76 /**
77 * @return Duration in the format HH::MM::SS for the value given
78 * in seconds.
79 */
80 QString durationFromValue(int value) const;
81
82private:
83 QSet<QByteArray> m_roles;
84 QHash<QString, QByteArray> m_roleForProperty;
85
86 friend class KBalooRolesProviderSingleton;
87};
88
89#endif
90
91