Sayonara Player
Loading...
Searching...
No Matches
Utils.h
1/* Helper.h */
2
3/* Copyright (C) 2011-2024 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
31class QString;
32class QDateTime;
33class QPixmap;
34class 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
50namespace 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
89 QString createLink(const QString& name,
90 bool dark = true,
91 bool underline = true);
92
93 QString createLink(const QString& name,
94 bool dark,
95 bool underline,
96 const QString& target);
97
98 QString createLink(const QString& name,
99 const QColor& color,
100 bool underline,
101 const QString& target);
102
107 QStringList soundfileExtensions(bool withAsterisk = true);
108
114
119 QStringList playlistExtensions(bool withAsterisk = true);
120
125 QStringList podcastExtensions(bool withAsterisk = true);
126
127 QStringList imageExtensions(bool withAsterisk = true);
128
129 enum Extension
130 {
131 Soundfile = 1 << 0,
132 Playlist = 1 << 1,
133 Podcast = 1 << 2,
134 Images = 1 << 3
135 };
136
137 using Extensions = uint16_t;
138
145 QString getFileFilter(Extensions extensions, const QString& name);
146
153 int randomNumber(int min, int max);
154
155 QString randomString(int max_chars);
156
163 QString easyTagFinder(const QString& tag, const QString& xmlDocument);
164
170 QByteArray calcHash(const QByteArray& data);
171
176 void sleepMs(uint64_t ms);
177
182 QStringList ipAddresses();
183
184 QByteArray convertPixmapToByteArray(const QPixmap& pm);
185 QByteArray convertPixmapToByteArray(const QPixmap& pm, const char* format);
186 QPixmap convertByteArrayToPixmap(const QByteArray& arr);
187
193 void setEnvironment(const QString& key, const QString& value);
194 void unsetEnvironment(const QString& key);
195 QString getEnvironment(const char* key);
196
197 struct Version
198 {
199 int major {-1};
200 int minor {-1};
201 int patch {-1};
202 QString channel;
203 int channelIncrement {-1};
204
205 [[nodiscard]] bool operator<(const Version& other) const;
206 [[nodiscard]] bool isValid() const;
207 static Version fromString(const QString& str);
208 };
209}
210
211#endif
Definition: Station.h:73
Helper functions.
Definition: MetaTypeRegistry.h:25
QString stringToFirstUpper(const QString &str)
Transform all letters after a space to upper case.
QStringList playlistExtensions(bool withAsterisk=true)
get all supported playlist file extensions
QByteArray calcHash(const QByteArray &data)
calculate a md5 hashsum
QStringList soundfileExtensions(bool withAsterisk=true)
get all supported sound file extensions
QStringList ipAddresses()
get all ip addresses of the host
void sleepMs(uint64_t ms)
sleep
QString stringToVeryFirstUpper(const QString &str)
Transform only first letter to upper case.
int randomNumber(int min, int max)
get a random val between min max
QString getFileFilter(Extensions extensions, const QString &name)
get filter for file chooser dialog based on extensions
QString easyTagFinder(const QString &tag, const QString &xmlDocument)
gets value out of tag
QString msToString(MilliSeconds msec, const QString &format)
Convert milliseconds to string.
QString soundfileFilter()
get filter for file reader or file chooser
QStringList podcastExtensions(bool withAsterisk=true)
get all supported podcast file extensions
QString createLink(const QString &name, bool dark=true, bool underline=true)
create a link string
void setEnvironment(const QString &key, const QString &value)
set an environment variable. This function is platform independent
Definition: Utils.h:198