|
AlbumShaper
1.0a3
|
#include <fstream>#include <qstring.h>#include <qfile.h>#include <qdir.h>#include <qlibrary.h>#include "fileTools.h"
Go to the source code of this file.
Functions | |
| bool | moveFile (QString oldName, QString newName) |
| bool | copyFile (QString oldFilePath, QString newFilePath) |
| Copies a file from one location to another. | |
| QString | fixFilename (QString filename) |
| Replaces invalid characters in filenames with valid ones. | |
| bool copyFile | ( | QString | oldFilePath, |
| QString | newFilePath | ||
| ) |
Copies a file from one location to another.
Definition at line 61 of file fileTools.cpp.
References buffer.
Referenced by Album::exportCompressedWebAlbum(), Album::exportLargeImages(), Album::exportSubalbumImages(), Album::exportThemeResources(), moveFile(), Photo::setImage(), and setWallpaper().
{
//same file, no need to copy
if(oldFilePath.compare(newFilePath) == 0)
return true;
//load both files
QFile oldFile(oldFilePath);
QFile newFile(newFilePath);
bool openOld = oldFile.open( IO_ReadOnly );
bool openNew = newFile.open( IO_WriteOnly );
//if either file fails to open bail
if(!openOld || !openNew) { return false; }
//copy contents
uint BUFFER_SIZE = 16000;
char* buffer = new char[BUFFER_SIZE];
while(!oldFile.atEnd())
{
Q_ULONG len = oldFile.readBlock( buffer, BUFFER_SIZE );
newFile.writeBlock( buffer, len );
}
//deallocate buffer
delete[] buffer;
buffer = NULL;
return true;
}
| QString fixFilename | ( | QString | filename | ) |
Replaces invalid characters in filenames with valid ones.
Definition at line 137 of file fileTools.cpp.
Referenced by TitleWidget::exportLargeImages(), and TitleWidget::exportSmallWebGallery().
{
filename.replace( QChar(' '), "_" );
filename.replace( "<", "" );
filename.replace( ">", "" );
filename.replace( "&", "and" );
filename.replace( "\"", "" );
filename.replace( "\'", "" );
filename.replace( "?", "" );
return filename;
}
| bool moveFile | ( | QString | oldName, |
| QString | newName | ||
| ) |
Definition at line 40 of file fileTools.cpp.
References copyFile().
Referenced by Photo::applyTransformation(), Album::exportSubalbumImages(), and Album::reorderSubalbumImages().
{
QDir rootDir;
//attempt to rename file
if(!rootDir.rename( oldName, newName))
{
//move failed, copy file and remove original
//copy failed! sound alert and do not remove original!!!
if(!copyFile(oldName, newName))
return false;
//copy succeded, remove original and return
rootDir.remove(oldName);
}
//move succeeded either directly or via copying and removing original file
return true;
}
1.7.5.1