Sayonara Player
Utils.h
1 /* Helper.h */
2 
3 /* Copyright (C) 2011-2017 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 _HELPER_H
29 #define _HELPER_H
30 
31 #include <QObject>
32 #include <algorithm>
33 
34 class QDateTime;
39 namespace Util
40 {
41  uint64_t current_date_to_int();
42  uint64_t date_to_int(const QDateTime& date);
43 
49  QString cvt_str_to_first_upper(const QString& str);
50 
56  QString cvt_str_to_very_first_upper(const QString& str);
57 
66  QString cvt_ms_to_string(uint64_t msec, bool empty_zero = false, bool colon=true, bool show_days=true);
67 
68 
73  QString sayonara_path(const QString& append_path=QString());
74 
79  QString share_path(const QString& append_path=QString());
80 
85  QString lib_path(const QString& append_path=QString());
86 
94  QString create_link(const QString& name,
95  bool dark=true,
96  const QString& target="",
97  bool underline=true);
98 
99 
104  QStringList soundfile_extensions(bool with_asterisk=true);
105 
110  QStringList playlist_extensions(bool with_asterisk=true);
111 
116  QStringList podcast_extensions(bool with_asterisk=true);
117 
118  QStringList image_extensions(bool with_asterisk=true);
119 
120 
127  int random_number(int min, int max);
128 
129 
130  QString random_string(int max_chars);
131 
132 
139  QString easy_tag_finder(const QString& tag, const QString& xml_doc);
140 
146  QByteArray calc_hash(const QByteArray& data);
147 
148 
153  void sleep_ms(uint64_t ms);
154 
159  QStringList ip_addresses();
160 
161 
167  void set_environment(const QString& key, const QString& value);
168  void unset_environment(const QString& key);
169 
170  template<typename T, typename FN>
171  bool contains(const T& container, FN fn)
172  {
173  return std::any_of(container.begin(), container.end(), fn);
174  }
175 
176  template<typename T, typename FN>
177  void sort(T& container, FN fn)
178  {
179  std::sort(container.begin(), container.end(), fn);
180  }
181 }
182 
183 #endif
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 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 share_path(const QString &append_path=QString())
get share path of sayonara
QString cvt_str_to_first_upper(const QString &str)
Transform all letters after a space to upper case.
QString lib_path(const QString &append_path=QString())
get library path of sayonara
int random_number(int min, int max)
get a random val between min max
Helper functions.
Definition: FileUtils.h:30
QString sayonara_path(const QString &append_path=QString())
get sayonara path in home directory
QString create_link(const QString &name, bool dark=true, const QString &target="", bool underline=true)
create a link string
QString cvt_ms_to_string(uint64_t 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