Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

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

bool copyFile QString  oldName,
QString  newName
 

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().

00062 { 00063 //same file, no need to copy 00064 if(oldFilePath.compare(newFilePath) == 0) 00065 return true; 00066 00067 //load both files 00068 QFile oldFile(oldFilePath); 00069 QFile newFile(newFilePath); 00070 bool openOld = oldFile.open( IO_ReadOnly ); 00071 bool openNew = newFile.open( IO_WriteOnly ); 00072 00073 //if either file fails to open bail 00074 if(!openOld || !openNew) { return false; } 00075 00076 //copy contents 00077 uint BUFFER_SIZE = 16000; 00078 char* buffer = new char[BUFFER_SIZE]; 00079 while(!oldFile.atEnd()) 00080 { 00081 Q_ULONG len = oldFile.readBlock( buffer, BUFFER_SIZE ); 00082 newFile.writeBlock( buffer, len ); 00083 } 00084 00085 //deallocate buffer 00086 delete[] buffer; 00087 buffer = NULL; 00088 return true; 00089 }

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().

00138 { 00139 filename.replace( QChar(' '), "_" ); 00140 filename.replace( "<", "" ); 00141 filename.replace( ">", "" ); 00142 filename.replace( "&", "and" ); 00143 filename.replace( "\"", "" ); 00144 filename.replace( "\'", "" ); 00145 filename.replace( "?", "" ); 00146 return filename; 00147 }

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().

00041 { 00042 QDir rootDir; 00043 00044 //attempt to rename file 00045 if(!rootDir.rename( oldName, newName)) 00046 { 00047 //move failed, copy file and remove original 00048 00049 //copy failed! sound alert and do not remove original!!! 00050 if(!copyFile(oldName, newName)) 00051 return false; 00052 00053 //copy succeded, remove original and return 00054 rootDir.remove(oldName); 00055 } 00056 00057 //move succeeded either directly or via copying and removing original file 00058 return true; 00059 }


Generated on Sun Mar 4 19:42:59 2007 for AlbumShaper by doxygen 1.3.7