Merge branch 'master' of http://git.fredemmott.co.uk/repo/yanihp
[jkt-jerboa.git] / include / Util.h
blobb9a4ab6eb70888a617abf0ced1268db606c41208
1 /* LICENSE NOTICE
2 This file is part of Jerboa.
4 Jerboa is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option), version 3 of the license.
9 Jerboa 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 General Public License
15 along with Jerboa. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef _UTIL_H
18 #define _UTIL_H
20 #include <QByteArray>
21 #include <QIcon>
22 #include <QObject>
23 #include <QString>
24 #include <QUrl>
26 class QFileInfo;
28 /** Get the name of an enum value from a static meta object.
29 * @param so is a staticMetaObject.
30 * @param e is an enum.
31 * @param v is a value in this enum.
32 * @returns a const char* containing the key of an enum.
34 #define NAME_FROM_ENUM_HELPER(so,e,v) ( \
35 so.enumerator( \
36 so.indexOfEnumerator(#e) \
37 ).valueToKey(v) \
39 /** Get the value of an enum from it's key from a static meta object.
40 * @param so is a staticMetaObject.
41 * @param o is the object/class/namespace containing the enum declaration.
42 * @param e is the enum name.
43 * @param n is a QString containing the value key.
44 * @returns An o::e.
46 #define ENUM_FROM_NAME_HELPER(so,o,e,n) ( \
47 static_cast<o::e>( \
48 so.enumerator( \
49 so.indexOfEnumerator(#e) \
50 ).keyToValue(n.toLatin1()) \
51 ) \
53 /** Get the key of a Qt namespace enum value.
54 * @param e is the enum to get a value for, for example, ToolButtonStyle.
55 * @param v is the value that a key is wanted for, for example, Qt::ToolButtonTextUnderIcons
56 * @returns a const char* containing the key.
58 #define QT_NAME_FROM_ENUM(e,v) NAME_FROM_ENUM_HELPER(QObject::staticQtMetaObject,e,v)
59 /** Get the value of a Qt namespace enum value from it's int value.
60 * @param e is the enum to get a value for, for example, ToolButtonStyle.
61 * @param n is the name of an enum value, for example "ToolButtonTextUnderIcons"
62 * @returns A Qt::e value.
64 #define QT_ENUM_FROM_NAME(e,n) ENUM_FROM_NAME_HELPER(QObject::staticQtMetaObject,Qt,e,n)
65 /** Get the key of a QObject's enum value.
66 * @param o is a QObject
67 * @param e is the enum to get a value for, for example, ToolButtonStyle.
68 * @param v is the value that a key is wanted for, for example, Qt::ToolButtonTextUnderIcons
69 * @returns a const char* containing the key.
71 #define NAME_FROM_ENUM(o,e,v) NAME_FROM_ENUM_HELPER(o::staticMetaObject,e,v)
72 /** Get the value of a QObject enum value from it's int value.
73 * @param o is a QObject
74 * @param e is the enum to get a value for, for example, ToolButtonStyle.
75 * @param n is the name of an enum value, for example "ToolButtonTextUnderIcons"
76 * @returns A Qt::e value.
78 #define ENUM_FROM_NAME(o,e,n) ENUM_FROM_NAME_HELPER(o::staticMetaObject,o,e,n)
80 namespace Util
82 time_t timestamp();
83 unsigned int getArtistID(QString artist, QString artistSort);
84 QString artistName(unsigned int id);
85 QString simpleAlbum(QString album);
86 QString dataLocation();
87 QString musicLocation();
88 QIcon getIcon(QString name);
89 QList<QUrl> walkDirectories(const QFileInfo& fileinfo);
92 #endif