IO/files processing methods.
More...
#include <iofactory.h>
|
static void | playWaveFile (const QString &file_path) |
| Plays selected file with default audio output. More...
|
|
static bool | copyFile (const QString &source, const QString &destination) |
| Copies source file into destination path. More...
|
|
static bool | copyDirectory (QString source, QString destination) |
| Copies source directory into destination path. More...
|
|
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. More...
|
|
static QByteArray | fileToBase64 (const QString &file_name) |
| Takes input file and reads it into base64 byte array. More...
|
|
static bool | base64ToFile (const QString &source_data, const QString &target_file) |
| Takes base64 byte array and saves it into file. More...
|
|
IO/files processing methods.
Definition at line 39 of file iofactory.h.
bool IOFactory::base64ToFile |
( |
const QString & |
source_data, |
|
|
const QString & |
target_file |
|
) |
| |
|
static |
Takes base64 byte array and saves it into file.
- Parameters
-
source_data | Source base64 string. |
target_file | Path to target file. |
- Returns
- Returns true if data was saved to file, false otherwise.
Definition at line 125 of file iofactory.cpp.
126 QFile target(target_file);
128 if (!target.open(QIODevice::Unbuffered | QIODevice::WriteOnly | QIODevice::Truncate)) {
132 target.write(QByteArray::fromBase64(source_data.toUtf8()));
bool IOFactory::copyDirectory |
( |
QString |
source, |
|
|
QString |
destination |
|
) |
| |
|
static |
Copies source directory into destination path.
- Parameters
-
source | Path to source directory. |
destination | Path to destination directory. |
- Returns
- Returns true if copy operation was successfull.
- Note
- If destination exists, then it is overwritten.
Definition at line 137 of file iofactory.cpp.
140 if (! dir.exists()) {
144 foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
145 QString dst_path = destination + QDir::separator() + d;
146 dir.mkpath(dst_path);
150 foreach (QString f, dir.entryList(QDir::Files)) {
151 QString original_file = source + QDir::separator() + f;
152 QString destination_file = destination + QDir::separator() + f;
154 if (!QFile::exists(destination_file) || QFile::remove(destination_file)) {
155 if (!QFile::copy(original_file, destination_file)) {
156 qDebug(
"Failed to copy file \'%s\'.", qPrintable(QDir::toNativeSeparators(original_file)));
160 qDebug(
"Failed to remove file \'%s\'.", qPrintable(QDir::toNativeSeparators(original_file)));
static bool copyDirectory(QString source, QString destination)
Copies source directory into destination path.
bool IOFactory::copyFile |
( |
const QString & |
source, |
|
|
const QString & |
destination |
|
) |
| |
|
static |
Copies source file into destination path.
- Parameters
-
source | Path to source file. |
destination | Path to destination path. |
- Returns
- Returns true if copy operation was successfull.
- Warning
- If destination exists, then it is overwritten.
Definition at line 69 of file iofactory.cpp.
70 if (!QFile::exists(source)) {
71 qDebug(
"Source file \'%s\' does not exist.", qPrintable(QDir::toNativeSeparators(source)));
75 if (QFile::exists(destination)) {
76 if (!QFile::remove(destination)) {
77 qDebug(
"Destination file \'%s\' could not be removed.", qPrintable(QDir::toNativeSeparators(destination)));
82 return QFile::copy(source, destination);
QByteArray IOFactory::fileToBase64 |
( |
const QString & |
file_name | ) |
|
|
static |
Takes input file and reads it into base64 byte array.
- Parameters
-
- Returns
- Returns base64 byte array on success or empty array on failure.
Definition at line 111 of file iofactory.cpp.
112 QFile file(file_name);
114 if (!file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) {
118 QByteArray file_contents = file.readAll();
121 return file_contents.toBase64();
void IOFactory::playWaveFile |
( |
const QString & |
file_path | ) |
|
|
static |
Plays selected file with default audio output.
- Parameters
-
file_path | Path to file to play, it should be WAVE file. |
Definition at line 52 of file iofactory.cpp.
53 #if QT_VERSION >= 0x050000
54 QSound::play(file_path);
55 #elif !defined(Q_OS_OS2)
56 Phonon::AudioOutput *out =
new Phonon::AudioOutput(Phonon::MusicCategory, qApp);
57 out->setVolume(100.0f);
60 Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(file_path));
62 Phonon::createPath(music, out);
64 QObject::connect(music, SIGNAL(finished()), music, SLOT(deleteLater()));
65 QObject::connect(music, SIGNAL(finished()), out, SLOT(deleteLater()));
bool IOFactory::removeDirectory |
( |
const QString & |
directory_name, |
|
|
const QStringList & |
exception_file_list = QStringList() , |
|
|
const QStringList & |
exception_folder_list = QStringList() |
|
) |
| |
|
static |
Removes given directory and all its contents if not exceptions are given.
- Parameters
-
directory_name | Path to directory. |
exception_file_list | List of file names which should be skipped. |
exception_folder_list | List of folder names which should be skipped. |
- Returns
- Returns true if delete operation was successfull.
Definition at line 85 of file iofactory.cpp.
89 QDir dir(directory_name);
91 if (dir.exists(directory_name)) {
92 foreach (QFileInfo info,
93 dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System |
94 QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
96 if (!exception_folder_list.contains(info.fileName())) {
97 result &=
removeDirectory(info.absoluteFilePath(), exception_file_list);
100 else if (!exception_file_list.contains(info.fileName())) {
101 result &= QFile::remove(info.absoluteFilePath());
105 result &= dir.rmdir(directory_name);
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.
The documentation for this class was generated from the following files: