Sayonara Player
Utils.h
1 /* Helper.h */
2 
3 /* Copyright (C) 2011-2019 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: 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 current_date_to_int();
52  uint64_t date_to_int(const QDateTime& date);
53  QDateTime int_to_date(uint64_t date);
54 
60  QString cvt_str_to_first_upper(const QString& str);
61 
67  QString cvt_str_to_very_first_upper(const QString& str);
68 
77  QString cvt_ms_to_string(MilliSeconds msec, bool empty_zero = false, bool colon=true, bool show_days=true);
78 
79  QString cvt_not_null(const QString& str);
80 
81 
86  QString sayonara_path();
87  QString sayonara_path(const QString& append_path);
88 
89 
94  QString share_path();
95  QString share_path(const QString& append_path);
96 
101  QString lib_path();
102  QString lib_path(const QString& append_path);
103 
111  QString create_link(const QString& name,
112  bool dark=true,
113  bool underline=true);
114 
115  QString create_link(const QString& name,
116  bool dark,
117  bool underline,
118  const QString& target);
119 
120 
125  QStringList soundfile_extensions(bool with_asterisk=true);
126 
131  QString soundfile_filter();
132 
137  QStringList playlist_extensions(bool with_asterisk=true);
138 
143  QStringList podcast_extensions(bool with_asterisk=true);
144 
145  QStringList image_extensions(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 get_file_filter(Extensions extensions, const QString& name);
165 
172  int random_number(int min, int max);
173 
174 
175  QString random_string(int max_chars);
176 
177 
184  QString easy_tag_finder(const QString& tag, const QString& xml_doc);
185 
191  QByteArray calc_hash(const QByteArray& data);
192 
193 
198  void sleep_ms(uint64_t ms);
199 
200 
205  QStringList ip_addresses();
206 
207 
208  QByteArray cvt_pixmap_to_bytearray(const QPixmap& pm);
209  QPixmap cvt_bytearray_to_pixmap(const QByteArray& arr);
210 
216  void set_environment(const QString& key, const QString& value);
217  void unset_environment(const QString& key);
218  QString get_environment(const char* key);
219 
220 }
221 
222 #endif
QString soundfile_filter()
get filter for file reader or file chooser
QStringList playlist_extensions(bool with_asterisk=true)
get all supported playlist file extensions
void set_environment(const QString &key, const QString &value)
set an environment variable. This function is platform independent
void sleep_ms(uint64_t ms)
sleep
QStringList soundfile_extensions(bool with_asterisk=true)
get all supported sound file extensions
QString lib_path()
get library path of sayonara
QString cvt_str_to_very_first_upper(const QString &str)
Transform only first letter to upper case.
QStringList ip_addresses()
get all ip addresses of the host
QByteArray calc_hash(const QByteArray &data)
calculate a md5 hashsum
QString get_file_filter(Extensions extensions, const QString &name)
get filter for file chooser dialog based on extensions
QString share_path()
get share path of sayonara
QString cvt_str_to_first_upper(const QString &str)
Transform all letters after a space to upper case.
QString sayonara_path()
get sayonara path in home directory
int random_number(int min, int max)
get a random val between min max
Helper functions.
Definition: GenreView.h:35
QString cvt_ms_to_string(MilliSeconds msec, bool empty_zero=false, bool colon=true, bool show_days=true)
Convert milliseconds to string.
QString easy_tag_finder(const QString &tag, const QString &xml_doc)
gets value out of tag
QStringList podcast_extensions(bool with_asterisk=true)
get all supported podcast file extensions
QString create_link(const QString &name, bool dark=true, bool underline=true)
create a link string