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 
35 #include "typedefs.h"
36 #include "Utils/Macros.h"
37 
38 #ifndef CAST_MACROS
39  #define scast(x, y) static_cast<x>(y)
40  #define dcast(x, y) dynamic_cast<x>(y)
41  #define rcast(x, y) reinterpret_cast<x>(y)
42  #define CAST_MACROS
43 #endif
44 
49 namespace Util
50 {
51  uint64_t currentDateToInt();
52  uint64_t dateToInt(const QDateTime& date);
53  QDateTime intToDate(uint64_t date);
54 
60  QString stringToFirstUpper(const QString& str);
61 
67  QString stringToVeryFirstUpper(const QString& str);
68 
77  QString msToString(MilliSeconds msec, const QString& format);
78 
79  QString convertNotNull(const QString& str);
80 
81 
86  QString sayonaraPath();
87  QString sayonaraPath(const QString& append_path);
88 
89 
94  QString sharePath();
95  QString sharePath(const QString& append_path);
96 
101  QString tempPath();
102  QString tempPath(const QString& append_path);
103 
111  QString createLink(const QString& name,
112  bool dark=true,
113  bool underline=true);
114 
115  QString createLink(const QString& name,
116  bool dark,
117  bool underline,
118  const QString& target);
119 
120 
125  QStringList soundfileExtensions(bool with_asterisk=true);
126 
131  QString soundfileFilter();
132 
137  QStringList playlistExtensions(bool with_asterisk=true);
138 
143  QStringList podcastExtensions(bool with_asterisk=true);
144 
145  QStringList imageExtensions(bool with_asterisk=true);
146 
147 
148  enum Extension
149  {
150  Soundfile=1<<0,
151  Playlist=1<<1,
152  Podcast=1<<2,
153  Haltdeimaul=1<<3
154  };
155 
156  using Extensions=uint16_t;
157 
164  QString getFileFilter(Extensions extensions, const QString& name);
165 
172  int randomNumber(int min, int max);
173 
174 
175  QString randomString(int max_chars);
176 
177 
184  QString easyTagFinder(const QString& tag, const QString& xml_doc);
185 
191  QByteArray calcHash(const QByteArray& data);
192 
193 
198  void sleepMs(uint64_t ms);
199 
200 
205  QStringList ipAddresses();
206 
207 
208  QByteArray convertPixmapToByteArray(const QPixmap& pm);
209  QByteArray convertPixmapToByteArray(const QPixmap& pm, const char* format);
210  QPixmap convertByteArrayToPixmap(const QByteArray& arr);
211 
217  void setEnvironment(const QString& key, const QString& value);
218  void unsetEnvironment(const QString& key);
219  QString getEnvironment(const char* key);
220 }
221 
222 #endif
QString soundfileFilter()
get filter for file reader or file chooser
QString sayonaraPath()
get sayonara path in home directory
QString getFileFilter(Extensions extensions, const QString &name)
get filter for file chooser dialog based on extensions
QStringList ipAddresses()
get all ip addresses of the host
QString msToString(MilliSeconds msec, const QString &format)
Convert milliseconds to string.
QString tempPath()
get a temporary directory. usually /tmp/sayonara
QString easyTagFinder(const QString &tag, const QString &xml_doc)
gets value out of tag
QString stringToFirstUpper(const QString &str)
Transform all letters after a space to upper case.
void sleepMs(uint64_t ms)
sleep
QStringList playlistExtensions(bool with_asterisk=true)
get all supported playlist file extensions
int randomNumber(int min, int max)
get a random val between min max
QString stringToVeryFirstUpper(const QString &str)
Transform only first letter to upper case.
Helper functions.
Definition: GenreView.h:35
QString createLink(const QString &name, bool dark=true, bool underline=true)
create a link string
QStringList soundfileExtensions(bool with_asterisk=true)
get all supported sound file extensions
QString sharePath()
get share path of sayonara
QStringList podcastExtensions(bool with_asterisk=true)
get all supported podcast file extensions
void setEnvironment(const QString &key, const QString &value)
set an environment variable. This function is platform independent
Definition: Station.h:41
QByteArray calcHash(const QByteArray &data)
calculate a md5 hashsum