Sayonara Player
FileHelper.h
1 /* FileHelper.h */
2 
3 /* Copyright (C) 2011-2016 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 
23 #ifndef FILEHELPER_H
24 #define FILEHELPER_H
25 
26 #include <QString>
27 #include <QStringList>
28 #include <QDir>
29 #include <QFile>
30 
31 namespace Helper
32 {
33 
38  namespace File
39  {
45  QString calc_file_extension(const QString& filename);
46 
52  void remove_files_in_directory(const QString& dir_name, const QStringList& filters=QStringList());
53 
58  void delete_files(const QStringList& files);
59 
65  QString get_parent_directory(const QString& path);
66 
72  QString get_filename_of_path(const QString& path);
73 
80  void split_filename(const QString& src, QString& dir, QString& filename);
81 
87  QString get_file_extension(const QString& filename);
88 
94  QStringList get_parent_directories(const QStringList& list);
95 
101  QString get_absolute_filename(const QString& filename);
102 
107  bool create_directories(const QString& path);
108 
109 
115  QString calc_filesize_str(quint64 filesize);
116 
117 
123  bool is_absolute(const QString& filename);
124 
125 
132  bool write_file(const QByteArray& raw_data, const QString& filename);
133 
140  bool read_file_into_str(const QString& filename, QString& content);
141 
148  bool read_file_into_byte_arr(const QString& filename, QByteArray& content);
149 
155  bool check_file(const QString& filepath);
156 
157  // Everything clear
158  bool is_url(const QString& str);
159  bool is_www(const QString& str);
160  bool is_file(const QString& filename);
161  bool is_dir(const QString& filename);
162  bool is_soundfile(const QString& filename);
163  bool is_playlistfile(const QString& filename);
164  bool is_podcastfile(const QString& filename, const QByteArray& content);
165  }
166 }
167 
168 #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 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:31
bool create_directories(const QString &path)
create all directories necessary to access path
QString calc_filesize_str(quint64 filesize)
convert filesize to string
void remove_files_in_directory(const QString &dir_name, const QStringList &filters=QStringList())
Remove all files from directory.
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)
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.