Sayonara Player
FileHelper.h
1 /* FileHelper.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 #ifndef FILEHELPER_H
22 #define FILEHELPER_H
23 
24 #include <QtGlobal>
25 
26 class QStringList;
27 class QString;
28 
29 namespace Helper
30 {
35  namespace File
36  {
42  QString clean_filename(const QString& filename);
43 
49  QString calc_file_extension(const QString& filename);
50 
56  void remove_files_in_directory(const QString& dir_name, const QStringList& filters);
57  void remove_files_in_directory(const QString& dir_name);
58 
63  void delete_files(const QStringList& files);
64 
70  QString get_parent_directory(const QString& path);
71 
77  QString get_filename_of_path(const QString& path);
78 
85  void split_filename(const QString& src, QString& dir, QString& filename);
86 
92  QString get_file_extension(const QString& filename);
93 
99  QStringList get_parent_directories(const QStringList& list);
100 
106  QString get_absolute_filename(const QString& filename);
107 
112  bool create_directories(const QString& path);
113 
114 
120  QString calc_filesize_str(quint64 filesize);
121 
122 
128  bool is_absolute(const QString& filename);
129 
130 
137  bool write_file(const QByteArray& raw_data, const QString& filename);
138 
145  bool read_file_into_str(const QString& filename, QString& content);
146 
153  bool read_file_into_byte_arr(const QString& filename, QByteArray& content);
154 
160  bool check_file(const QString& filepath);
161 
162  // Everything clear
163  bool is_url(const QString& str);
164  bool is_www(const QString& str);
165  bool is_file(const QString& filename);
166  bool is_dir(const QString& filename);
167  bool is_soundfile(const QString& filename);
168  bool is_playlistfile(const QString& filename);
169  }
170 }
171 
172 #endif // FILEHELPER_H
QStringList get_parent_directories(const QStringList &list)
extract parent folder of a file list (see also get_parent_directory(const QString& path) ...
QString get_parent_directory(const QString &path)
get parent directory of a filepath
QString get_filename_of_path(const QString &path)
extract pure filename from a complete file path
QString get_file_extension(const QString &filename)
get file extension
QString calc_file_extension(const QString &filename)
calc_file_extension
bool is_absolute(const QString &filename)
Tell whether filename is absolute.
void remove_files_in_directory(const QString &dir_name, const QStringList &filters)
Remove all files from directory.
void split_filename(const QString &src, QString &dir, QString &filename)
split filename into the dir and filename
bool write_file(const QByteArray &raw_data, const QString &filename)
Write raw data to file.
QString get_absolute_filename(const QString &filename)
get absolute filename of file
Helper functions.
Definition: FileHelper.h:29
bool create_directories(const QString &path)
create all directories necessary to access path
QString calc_filesize_str(quint64 filesize)
convert filesize to string
bool read_file_into_str(const QString &filename, QString &content)
read a complete file into a string
void delete_files(const QStringList &files)
Remove all given files (also directories can be specified)
QString clean_filename(const QString &filename)
formatter for filepaths. Removes double separators and replaces them with os specific separators...
bool read_file_into_byte_arr(const QString &filename, QByteArray &content)
read a complete file into a byte array
bool check_file(const QString &filepath)
Check, if file is valid. Web URLs are always valid.