Sayonara Player
Utils.h
1 /* Helper.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 /*
22  * Helper.cpp
23  *
24  * Created on: Apr 4, 2011
25  * Author: Michael Lugmair (Lucio Carreras)
26  */
27 
28 #ifndef UTIL_HELPER_H
29 #define UTIL_HELPER_H
30 
31 class QString;
32 class QDateTime;
33 class QPixmap;
34 class QColor;
35 
36 #include "typedefs.h"
37 #include "Utils/Macros.h"
38 
39 #ifndef CAST_MACROS
40  #define scast(x, y) static_cast<x>(y)
41  #define dcast(x, y) dynamic_cast<x>(y)
42  #define rcast(x, y) reinterpret_cast<x>(y)
43  #define CAST_MACROS
44 #endif
45 
50 namespace Util
51 {
52  uint64_t currentDateToInt();
53  uint64_t dateToInt(const QDateTime& dateTime);
54  QDateTime intToDate(uint64_t date);
55 
61  QString stringToFirstUpper(const QString& str);
62 
68  QString stringToVeryFirstUpper(const QString& str);
69 
78  QString msToString(MilliSeconds msec, const QString& format);
79 
80  QString convertNotNull(const QString& str);
81 
82 
90  QString createLink(const QString& name,
91  bool dark=true,
92  bool underline=true);
93 
94  QString createLink(const QString& name,
95  bool dark,
96  bool underline,
97  const QString& target);
98 
99  QString createLink(const QString& name,
100  const QColor& color,
101  bool underline,
102  const QString& target);
103 
108  QStringList soundfileExtensions(bool withAsterisk=true);
109 
114  QString soundfileFilter();
115 
120  QStringList playlistExtensions(bool withAsterisk=true);
121 
126  QStringList podcastExtensions(bool withAsterisk=true);
127 
128  QStringList imageExtensions(bool withAsterisk=true);
129 
130 
131  enum Extension
132  {
133  Soundfile=1<<0,
134  Playlist=1<<1,
135  Podcast=1<<2,
136  Images=1<<3
137  };
138 
139  using Extensions=uint16_t;
140 
147  QString getFileFilter(Extensions extensions, const QString& name);
148 
155  int randomNumber(int min, int max);
156 
157 
158  QString randomString(int max_chars);
159 
160 
167  QString easyTagFinder(const QString& tag, const QString& xmlDocument);
168 
174  QByteArray calcHash(const QByteArray& data);
175 
176 
181  void sleepMs(uint64_t ms);
182 
183 
188  QStringList ipAddresses();
189 
190 
191  QByteArray convertPixmapToByteArray(const QPixmap& pm);
192  QByteArray convertPixmapToByteArray(const QPixmap& pm, const char* format);
193  QPixmap convertByteArrayToPixmap(const QByteArray& arr);
194 
200  void setEnvironment(const QString& key, const QString& value);
201  void unsetEnvironment(const QString& key);
202  QString getEnvironment(const char* key);
203 }
204 
205 #endif
Util::easyTagFinder
QString easyTagFinder(const QString &tag, const QString &xmlDocument)
gets value out of tag
Util::playlistExtensions
QStringList playlistExtensions(bool withAsterisk=true)
get all supported playlist file extensions
Util::stringToFirstUpper
QString stringToFirstUpper(const QString &str)
Transform all letters after a space to upper case.
Util::sleepMs
void sleepMs(uint64_t ms)
sleep
Util::getFileFilter
QString getFileFilter(Extensions extensions, const QString &name)
get filter for file chooser dialog based on extensions
Podcast
Definition: Station.h:43
Util::createLink
QString createLink(const QString &name, bool dark=true, bool underline=true)
create a link string
Util::calcHash
QByteArray calcHash(const QByteArray &data)
calculate a md5 hashsum
Util
Helper functions.
Definition: GenreView.h:36
Util::soundfileExtensions
QStringList soundfileExtensions(bool withAsterisk=true)
get all supported sound file extensions
Util::soundfileFilter
QString soundfileFilter()
get filter for file reader or file chooser
Util::msToString
QString msToString(MilliSeconds msec, const QString &format)
Convert milliseconds to string.
Util::ipAddresses
QStringList ipAddresses()
get all ip addresses of the host
Util::podcastExtensions
QStringList podcastExtensions(bool withAsterisk=true)
get all supported podcast file extensions
Util::stringToVeryFirstUpper
QString stringToVeryFirstUpper(const QString &str)
Transform only first letter to upper case.
Util::setEnvironment
void setEnvironment(const QString &key, const QString &value)
set an environment variable. This function is platform independent
Util::randomNumber
int randomNumber(int min, int max)
get a random val between min max