AlbumShaper 1.0a3
fileTools.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool moveFile (QString oldName, QString newName)
 
bool copyFile (QString oldName, QString newName)
 Copies a file from one location to another.
 
QString fixFilename (QString filename)
 Replaces invalid characters in filenames with valid ones.
 

Function Documentation

◆ copyFile()

bool copyFile ( QString oldName,
QString newName )

Copies a file from one location to another.

Definition at line 61 of file fileTools.cpp.

62{
63 //same file, no need to copy
64 if(oldFilePath.compare(newFilePath) == 0)
65 return true;
66
67 //load both files
68 QFile oldFile(oldFilePath);
69 QFile newFile(newFilePath);
70 bool openOld = oldFile.open( QIODevice::ReadOnly );
71 bool openNew = newFile.open( QIODevice::WriteOnly );
72
73 //if either file fails to open bail
74 if(!openOld || !openNew) { return false; }
75
76 //copy contents
77 uint BUFFER_SIZE = 16000;
78 char* buffer = new char[BUFFER_SIZE];
79 while(!oldFile.atEnd())
80 {
81 Q_ULONG len = oldFile.readBlock( buffer, BUFFER_SIZE );
82 newFile.writeBlock( buffer, len );
83 }
84
85 //deallocate buffer
86 delete[] buffer;
87 buffer = NULL;
88 return true;
89}
float * buffer
Definition blur.cpp:80

References buffer.

Referenced by Album::exportCompressedWebAlbum(), Album::exportLargeImages(), Album::exportSubalbumImages(), Album::exportThemeResources(), moveFile(), Photo::setImage(), Photo::setImage(), and setWallpaper().

◆ fixFilename()

QString fixFilename ( QString filename)

Replaces invalid characters in filenames with valid ones.

Definition at line 137 of file fileTools.cpp.

138{
139 filename.replace( QChar(' '), "_" );
140 filename.replace( "<", "" );
141 filename.replace( ">", "" );
142 filename.replace( "&", "and" );
143 filename.replace( "\"", "" );
144 filename.replace( "\'", "" );
145 filename.replace( "?", "" );
146 return filename;
147}

Referenced by TitleWidget::exportLargeImages(), and TitleWidget::exportSmallWebGallery().

◆ moveFile()

bool moveFile ( QString oldName,
QString newName )

Definition at line 40 of file fileTools.cpp.

41{
42 QDir rootDir;
43
44 //attempt to rename file
45 if(!rootDir.rename( oldName, newName))
46 {
47 //move failed, copy file and remove original
48
49 //copy failed! sound alert and do not remove original!!!
50 if(!copyFile(oldName, newName))
51 return false;
52
53 //copy succeded, remove original and return
54 rootDir.remove(oldName);
55 }
56
57 //move succeeded either directly or via copying and removing original file
58 return true;
59}
bool copyFile(QString oldFilePath, QString newFilePath)
Copies a file from one location to another.
Definition fileTools.cpp:61

References copyFile().

Referenced by Photo::applyTransformation(), Album::exportSubalbumImages(), and Album::reorderSubalbumImages().