BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
iofactory.h
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #ifndef IOFACTORY_H
32 #define IOFACTORY_H
33 
34 #include <QString>
35 #include <QStringList>
36 
37 
38 /// \brief IO/files processing methods.
39 class IOFactory {
40  private:
41  explicit IOFactory();
42 
43  public:
44  /// \brief Plays selected file with default audio output.
45  /// \param file_path Path to file to play, it should be WAVE file.
46  static void playWaveFile(const QString &file_path);
47 
48  /// \brief Copies source file into destination path.
49  /// \param source Path to source file.
50  /// \param destination Path to destination path.
51  /// \return Returns true if copy operation was successfull.
52  /// \warning If destination exists, then it is overwritten.
53  static bool copyFile(const QString &source, const QString &destination);
54 
55  /// \brief Copies source directory into destination path.
56  /// \param source Path to source directory.
57  /// \param destination Path to destination directory.
58  /// \return Returns true if copy operation was successfull.
59  /// \note If destination exists, then it is overwritten.
60  static bool copyDirectory(QString source, QString destination);
61 
62  /// \brief Removes given directory and all its contents if not exceptions are given.
63  /// \param directory_name Path to directory.
64  /// \param exception_file_list List of file names which should be skipped.
65  /// \param exception_folder_list List of folder names which should be skipped.
66  /// \return Returns true if delete operation was successfull.
67  static bool removeDirectory(const QString & directory_name,
68  const QStringList &exception_file_list = QStringList(),
69  const QStringList &exception_folder_list = QStringList());
70 
71  /// \brief Takes input file and reads it into base64 byte array.
72  /// \param file_name Path to file.
73  /// \return Returns base64 byte array on success or empty array on failure.
74  static QByteArray fileToBase64(const QString &file_name);
75 
76  /// \brief Takes base64 byte array and saves it into file.
77  /// \param source_data Source base64 string.
78  /// \param target_file Path to target file.
79  /// \return Returns true if data was saved to file, false otherwise.
80  static bool base64ToFile(const QString &source_data, const QString &target_file);
81 };
82 
83 #endif // IOFACTORY_H
static bool base64ToFile(const QString &source_data, const QString &target_file)
Takes base64 byte array and saves it into file.
Definition: iofactory.cpp:125
static bool copyFile(const QString &source, const QString &destination)
Copies source file into destination path.
Definition: iofactory.cpp:69
static QByteArray fileToBase64(const QString &file_name)
Takes input file and reads it into base64 byte array.
Definition: iofactory.cpp:111
static void playWaveFile(const QString &file_path)
Plays selected file with default audio output.
Definition: iofactory.cpp:52
IO/files processing methods.
Definition: iofactory.h:39
static bool removeDirectory(const QString &directory_name, const QStringList &exception_file_list=QStringList(), const QStringList &exception_folder_list=QStringList())
Removes given directory and all its contents if not exceptions are given.
Definition: iofactory.cpp:85
static bool copyDirectory(QString source, QString destination)
Copies source directory into destination path.
Definition: iofactory.cpp:137