15#include <qstringlist.h>
19#include <q3textstream.h>
22#include <qapplication.h>
93 while(current != NULL)
104 QString tmpDirName = oldTmpDir.dirName();
105 QStringList strLst = oldTmpDir.entryList();
106 QStringList::iterator it;
107 for(it = strLst.begin(); it != strLst.end(); it++)
109 oldTmpDir.remove(
tmpDir +
"/" + *it);
112 oldTmpDir.rmdir( tmpDirName );
193 if(imageFilename.isNull())
201 int imageWidth, imageHeight;
204 int smallRepWidth = 0;
205 int smallRepHeight = 0;
206 int largeRepWidth = 0;
207 int largeRepHeight = 0;
210 smallRepWidth, smallRepHeight);
213 largeRepWidth, largeRepHeight);
218 QImage thumbnailSmall;
219 scaleImage( imageFilename, thumbnailSmall, smallRepWidth, smallRepHeight );
224 QImage thumbnailLarge;
225 scaleImage( imageFilename, thumbnailLarge, largeRepWidth, largeRepHeight );
237 if( val == NULL)
return;
260 if( val == NULL)
return;
280 QDate date = QDate::currentDate();
289 QDate date = QDate::currentDate();
298 updateXML( QFileInfo(fileName).dirPath(TRUE) );
301 QFile albumFile( fileName );
304 if( !albumFile.open( QIODevice::ReadOnly ) )
308 QDomDocument albumDom;
309 if( !albumDom.setContent( &albumFile ) )
316 QString rootDir = QFileInfo(albumFile).dirPath(TRUE);
320 QImage repImage(rootDir +
"/img/album.jpg");
321 if(!repImage.isNull())
328 QDomElement root = albumDom.documentElement();
329 QDomNode node = root.firstChild();
330 while( !node.isNull() )
332 if( node.isElement() && node.nodeName() ==
"subalbum" )
334 QDomNode childNode = node.firstChild();
335 while( !childNode.isNull() )
337 if( childNode.isElement() && childNode.nodeName() ==
"photo" )
339 childNode = childNode.nextSibling();
342 node = node.nextSibling();
347 qApp->processEvents();
352 root = albumDom.documentElement();
353 node = root.firstChild();
355 while( !node.isNull() )
359 if( node.isElement() && node.nodeName() ==
"name" )
361 val = node.firstChild().toText();
363 name = val.nodeValue();
364 name.replace(
"\\"",
"\"");
368 else if( node.isElement() && node.nodeName() ==
"description" )
370 val = node.firstChild().toText();
377 else if( node.isElement() && node.nodeName() ==
"author" )
379 val = node.firstChild().toText();
382 author.replace(
"\\"",
"\"");
386 else if( node.isElement() && node.nodeName() ==
"theme" )
388 val = node.firstChild().toText();
390 theme = val.nodeValue();
391 theme.replace(
"\\"",
"\"");
395 else if( node.isElement() && node.nodeName() ==
"created" )
397 val = node.firstChild().toText();
400 QStringList vals = QStringList::split( QRegExp(
" "), val.nodeValue() );
403 QStringList::Iterator it;
404 for ( it = vals.begin(); it != vals.end(); ++it )
406 intVals[i] = QString(*it).toInt();
419 else if( node.isElement() && node.nodeName() ==
"subalbum" )
435 node = node.nextSibling();
456 bool forceSave =
true;
463 QString oldTheme =
theme;
481 QString tmpDirName = oldTmpDir.dirName();
482 QStringList strLst = oldTmpDir.entryList();
483 QStringList::iterator it;
484 for(it = strLst.begin(); it != strLst.end(); it++)
486 oldTmpDir.remove(
tmpDir +
"/" + *it);
490 oldTmpDir.rmdir( tmpDirName );
494 if(!saveDir.exists(
"tmp" ))
495 saveDir.mkdir(
"tmp" );
512 localDir.mkdir(
"img");
518 localDir.mkdir(
"0" );
522 int collectionNum = 0;
523 while(current != NULL)
526 QString dirName = QString(
"%1") .arg( collectionNum );
527 localDir.mkdir(dirName);
536 while(current != NULL)
544 qApp->processEvents();
564 while(current !=NULL)
573 rootDir.rmdir(
"0" );
580 QStringList list = localDir.entryList( QDir::Files );
581 QStringList::Iterator file;
582 for ( file = list.begin(); file != list.end(); ++file )
584 if( (*file).endsWith(
".html") || (*file).endsWith(
".htm") )
598 QStringList strLst = tmpDirHandle.entryList();
599 QStringList::iterator it;
600 for(it = strLst.begin(); it != strLst.end(); it++)
602 tmpDirHandle.remove(
getTmpDir() +
"/" + *it);
617 QString exportLocation,
618 QString exportMessage)
622 QDir localDir(exportLocation);
623 localDir.mkdir(
"img");
624 localDir.setPath(exportLocation +
"/img");
630 { localDir.remove(exportLocation +
"/img/album.jpg"); }
633 int photosLeft = numPhotos;
634 int updateInverval = numPhotos / 50;
640 while(curCollection != NULL)
642 QString collectionDir = QString(
"%1").arg( collectionNum );
643 localDir.mkdir( collectionDir );
646 QString collectionThumbFilename = QString(exportLocation +
"/img/%1_thumb.jpg" ).arg(collectionNum);
650 { localDir.remove( collectionThumbFilename ); }
655 while(curPhoto != NULL)
662 if(updateCount > updateInverval)
665 qApp->processEvents();
669 QString newFilePath = QDir::convertSeparators( exportLocation +
"/img/" +
670 collectionDir +
"/" +
671 QString(
"%1").arg(photoNum) );
676 curPhoto = curPhoto->
getNext();
681 curCollection = curCollection->
getNext();
686 QStringList fileList;
687 QStringList::Iterator file;
690 localDir.setPath(exportLocation);
691 localDir.mkdir(
"resources");
694 localDir.setPath(exportLocation +
"/resources");
695 fileList = localDir.entryList( QDir::Files );
696 for ( file = fileList.begin(); file != fileList.end(); ++file )
697 { localDir.remove( exportLocation +
"/resources/" + *file ); }
701 fileList = localDir.entryList( QDir::Files );
702 for ( file = fileList.begin(); file != fileList.end(); ++file )
709 localDir.setPath(exportLocation);
710 fileList = localDir.entryList( QDir::Files );
711 for ( file = fileList.begin(); file != fileList.end(); ++file )
713 if( (*file).endsWith(
".html") || (*file).endsWith(
".htm") )
714 localDir.remove( exportLocation +
"/" + *file );
721 localDir.remove( exportLocation +
"/Album.xml" );
729 uint collectionDigits = (uint) (1 + log( (
double)
getNumSubalbums() ) / log( 10.0 ) );
735 while(curCollection != NULL )
737 mostPhotos = QMAX( mostPhotos, curCollection->
getNumPhotos() );
738 curCollection = curCollection->
getNext();
740 uint photoDigits = (uint) ( 1 + log( (
double) mostPhotos ) / log( 10.0 ) );
744 int photosLeft = numPhotos;
746 int collectionNum = 1;
749 int updateInverval = numPhotos / 50;
752 while(curCollection != NULL )
755 QString collectionString = QString(
"%1").arg(collectionNum);
756 while(collectionString.length() < collectionDigits)
757 { collectionString =
"0" + collectionString; }
762 while(curPhoto != NULL)
769 if(updateCount > updateInverval)
772 qApp->processEvents();
776 QString photoString = QString(
"%1").arg(photoNum);
777 while(photoString.length() < photoDigits)
778 { photoString =
"0" + photoString; }
781 QString newFilePath = QDir::convertSeparators( exportPath +
"/" + collectionString +
782 "_" + photoString +
".jpg" );
788 curPhoto = curPhoto->
getNext();
794 curCollection = curCollection->
getNext();
807 QFile file( exportPath +
"/Album.xml" );
808 if(file.open(QIODevice::WriteOnly))
812 stream.setDevice( &file );
813 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
816 stream <<
"<?xml version=\"1.0\"?>\n";
817 stream <<
"<album version=\"1.1\">\n";
823 stream <<
" <theme>" <<
theme <<
"</theme>\n";
830 stream <<
" <thumb path=\"img/album.jpg\"/>\n";
835 while(current != NULL)
842 stream <<
"</album>\n";
870 while(current != NULL)
876 QString fileName = QString(
saveLocation +
"/img/%1_thumb.jpg" ).arg(n);
883 rootDir.remove(
saveLocation + QString(
"/img/%1_thumb.jpg").arg(n) );
892 int subalbumNumber=0;
894 while(currentSubalbum != NULL)
901 while(currentPhoto != NULL)
908 currentPhoto = currentPhoto->
getNext();
910 qApp->processEvents();
920 QString newName = QString(
saveLocation +
"/img/%1/%2_thumb.jpg" )
921 .arg(initSubalbumNumber).arg(initPhotoNumber);
927 else {
copyFile(oldName, newName); }
930 std::ifstream thumbnailFile( QFile::encodeName(newName) );
931 if(thumbnailFile.is_open())
934 thumbnailFile.close();
939 newName = QString(
saveLocation +
"/img/%1/%2_slideshow.jpg" )
940 .arg(initSubalbumNumber).arg(initPhotoNumber);
946 else {
copyFile(oldName, newName); }
949 std::ifstream slideshowFile( QFile::encodeName(newName) );
950 if(slideshowFile.is_open())
953 slideshowFile.close();
958 newName = QString(
saveLocation +
"/img/%1/%2.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
963 QString tempOrigName =
getTmpDir() + QString(
"/%1_%2_orig.jpg")
964 .arg(initSubalbumNumber).arg(initPhotoNumber);
966 QString finalOrigName = QString(
saveLocation +
"/img/%1/%2_orig.jpg" )
967 .arg(initSubalbumNumber).arg(initPhotoNumber);
976 !
tmpDir.exists(finalOrigName) )
995 if(
tmpDir.exists(storedOrigLocation) )
996 copyFile( storedOrigLocation, finalOrigName );
997 else if(
tmpDir.exists(storedLocation) )
998 copyFile( storedLocation, finalOrigName );
1005 !
tmpDir.exists(newName) &&
1006 tmpDir.exists(tempOrigName) )
1008 moveFile( tempOrigName, finalOrigName );
1026 QString tempOrigName =
getTmpDir() + QString(
"/%1_%2_orig.jpg")
1027 .arg(initSubalbumNumber).arg(initPhotoNumber);
1030 curOrigName.truncate( curOrigName.length() - 4 );
1031 curOrigName = curOrigName +
"_orig.jpg";
1033 QString finalOrigName = QString(
saveLocation +
"/img/%1/%2_orig.jpg" )
1034 .arg(initSubalbumNumber).arg(initPhotoNumber);
1042 tmpDir.exists( tempOrigName ) )
1044 copyFile( tempOrigName, finalOrigName );
1049 tmpDir.exists( curOrigName ) )
1051 copyFile( curOrigName, finalOrigName );
1058 std::ifstream imageFile( QFile::encodeName(newName) );
1059 if(imageFile.is_open())
1067 ( QString(
saveLocation +
"/img/%1/%2.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
1070 ( QString(
saveLocation +
"/img/%1/%2_slideshow.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
1073 ( QString(
saveLocation +
"/img/%1/%2_thumb.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
1081 qApp->processEvents();
1084 currentPhoto = currentPhoto->
getNext();
1089 currentSubalbum = currentSubalbum->
getNext();
1099 while(currentSubalbum != NULL)
1103 while(currentPhoto != NULL)
1116 currentPhoto = currentPhoto->
getNext();
1118 qApp->processEvents();
1122 currentSubalbum = currentSubalbum->
getNext();
1136 int subalbumNumber=0;
1138 while(currentSubalbum != NULL)
1145 while(currentPhoto != NULL)
1152 if( initPhotoNumber != photoNumber || initSubalbumNumber != subalbumNumber)
1154 QString oldName = QString(
saveLocation +
"/img/%1/%2.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1155 QString newName = QString(
saveLocation +
"/img/%1/%2_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1158 oldName = QString(
saveLocation +
"/img/%1/%2_orig.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1159 newName = QString(
saveLocation +
"/img/%1/%2_orig_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1162 oldName = QString(
saveLocation +
"/img/%1/%2_slideshow.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1163 newName = QString(
saveLocation +
"/img/%1/%2_slideshow_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1166 oldName = QString(
saveLocation +
"/img/%1/%2_thumb.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1167 newName = QString(
saveLocation +
"/img/%1/%2_thumb_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1172 currentPhoto = currentPhoto->
getNext();
1174 qApp->processEvents();
1178 currentSubalbum = currentSubalbum->
getNext();
1190 while(currentSubalbum != NULL)
1197 while(currentPhoto != NULL)
1204 if( initPhotoNumber != photoNumber || initSubalbumNumber != subalbumNumber)
1206 QString oldName = QString(
saveLocation +
"/img/%1/%2_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1207 QString newName = QString(
saveLocation +
"/img/%1/%2.jpg" ).arg(subalbumNumber).arg(photoNumber);
1210 oldName = QString(
saveLocation +
"/img/%1/%2_orig_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1211 newName = QString(
saveLocation +
"/img/%1/%2_orig.jpg" ).arg(subalbumNumber).arg(photoNumber);
1214 oldName = QString(
saveLocation +
"/img/%1/%2_slideshow_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1215 newName = QString(
saveLocation +
"/img/%1/%2_slideshow.jpg" ).arg(subalbumNumber).arg(photoNumber);
1218 oldName = QString(
saveLocation +
"/img/%1/%2_thumb_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
1219 newName = QString(
saveLocation +
"/img/%1/%2_thumb.jpg" ).arg(subalbumNumber).arg(photoNumber);
1226 arg(subalbumNumber).arg(photoNumber) );
1228 arg(subalbumNumber).arg(photoNumber) );
1230 arg(subalbumNumber).arg(photoNumber) );
1234 currentPhoto = currentPhoto->
getNext();
1236 qApp->processEvents();
1240 currentSubalbum = currentSubalbum->
getNext();
1249 int subalbumNumber=0;
1251 while(currentSubalbum != NULL)
1260 QString imageString = QString(
saveLocation +
"/img/%1/%2.jpg").arg(subalbumNumber).arg(photoNum);
1261 QString origString = QString(
saveLocation +
"/img/%1/%2_orig.jpg").arg(subalbumNumber).arg(photoNum);
1262 QString slideshowString = QString(
saveLocation +
"/img/%1/%2_slideshow.jpg").arg(subalbumNumber).arg(photoNum);
1263 QString thumbString = QString(
saveLocation +
"/img/%1/%2_thumb.jpg").arg(subalbumNumber).arg(photoNum);
1268 if( !rootDir.exists(imageString) && !rootDir.exists(origString) &&
1269 !rootDir.exists(slideshowString) && !rootDir.exists(thumbString) )
1274 rootDir.remove( imageString );
1275 rootDir.remove( origString );
1276 rootDir.remove( slideshowString );
1277 rootDir.remove( thumbString );
1286 currentSubalbum = currentSubalbum->
getNext();
1294 QString imageDirString = QString(
saveLocation +
"/img/%1/").arg(subalbumNumber);
1295 if( !rootDir.exists(imageDirString) )
1299 QDir imageDir( imageDirString );
1300 QStringList list = imageDir.entryList( QDir::Files );
1303 QStringList::Iterator file;
1304 for ( file = list.begin(); file != list.end(); ++file )
1305 { rootDir.remove( QString(
saveLocation +
"/img/%1/" + *file).arg(subalbumNumber) ); }
1308 rootDir.rmdir( QString(
"%1").arg(subalbumNumber) );
1311 rootDir.remove( QString(
saveLocation +
"/img/%1_thumb.jpg").arg(subalbumNumber) );
1324 QStringList fileList;
1325 QStringList::Iterator file;
1330 fileList = localDir.entryList();
1331 for(file = fileList.begin(); file != fileList.end(); file++)
1336 localDir.rmdir(
"resources" );
1340 localDir.mkdir(
"resources");
1345 fileList = localDir.entryList( QDir::Files );
1346 for ( file = fileList.begin(); file != fileList.end(); ++file )
1347 { localDir.remove(
saveLocation +
"/resources/" + *file ); }
1357 fileList = localDir.entryList( QDir::Files );
1358 for ( file = fileList.begin(); file != fileList.end(); ++file )
1372 bool change =
false;
1375 while( tmp2 != NULL)
1407 while(item->nextItem() != NULL)
1429 QStringList thumbnailList;
1431 while(currCollection != NULL)
1435 while( currPhoto != NULL )
1438 currPhoto = currPhoto->
getNext();
1441 currCollection = currCollection->
getNext();
1444 return thumbnailList;
#define ALBUM_ERROR_OPEN_FILE
bool modified
Modification status of the album.
int getModificationDay()
Returns the last modified day.
QPixmap * largeRepresentativeImage
void exportSubalbumImages(StatusWidget *status, bool forceSave)
Exports subalbum images.
QString author
Album Creator.
Subalbum * getFirstSubalbum()
Returns a pointer to the first Subalbum.
void updateModificationDate()
Updates the modification date to today's date.
void setRepresentativeImages(QString imageFilename)
Sets the representative image.
int creationDay
Creation day.
QString description
Longer description of album.
int nextUniqueID
Next Unique ID for new photos.
void appendSubalbum(Subalbum *val)
Appends subalbum to end of linked list.
void setAuthor(QString val)
Sets the album author.
int getCreationDay()
Returnst he creation day.
QString theme
Theme to save album with.
int getModificationYear()
Returns the last modified year.
void removeStagnantOrigFiles(StatusWidget *status)
Removes any _orig images for photos which have been recently reverted to their original form (and hen...
int importFromDisk(StatusWidget *status, QString fileName, bool disableCheckPhotoMods)
Imports album from XML format, returning int indicates success or not.
QString getDescription()
Gets the album description.
Album(QString tmpDir, bool createSubalbum=true)
Sets default information and create temporary directory as necessary.
int getNextUniquePhotoID()
Returns the next unique photo id.
void reorderSubalbumImages(StatusWidget *status)
Checks if images need to be moved and does so if necessary.
QString saveLocation
Directory album saved to.
int getNumSubalbums()
Returns number of subalbums.
int exportLargeImages(StatusWidget *status, QString exportPath, QString exportMessage)
Export fullsize images (excludes slideshow and thumbnail images, album and collection iamges,...
void exportTopLevelImages()
Exports top level images.
void removeSubalbum(Subalbum *val)
Removes a subalbum.
int exportToDisk(StatusWidget *status, QString dirName, QString themeName)
Exports album in XML and HTML format, along with resized images.
int creationMonth
Creation month.
QString name
Short name for album.
void setName(QString val)
Sets the album name.
int numLoadedSubalbums
Number of loaded subalbums.
int exportCompressedWebAlbum(StatusWidget *status, QString exportLocation, QString exportMessage)
Export a compressed web album (excludes full size images and xml data)
int exportToXML(StatusWidget *status, QString exportPath)
Exports album to XML.
QPixmap * smallRepresentativeImage
Representative images.
void setModified(bool val=true)
Sets the album as modified.
int getModificationMonth()
Returns the last modified month.
QString getTmpDir()
Returns the temporary directory for use when modifying and adding new images.
int getCreationMonth()
Returns the creation month.
bool savedToDisk
Set if album was loaded/has been saved to disk.
Subalbum * lastSubalbum
Pointer to last Subalbum.
int modificationMonth
Last modification month.
void syncSubalbumList(SubalbumPreviewWidget *item)
Syncs subalbum ordering with front end gui ordering.
int getNumPhotos()
Returns the number of photos.
QString getTheme()
Returns currently selected theme.
void exportThemeResources(QString theme)
Removes previously saved resources, copies over new resources.
QString getAuthor()
Gets the album author.
int modificationDay
Last modification day.
void setDescription(QString val)
Sets the album description.
void removeStagnantImages()
Removes old stagnant images caused when photos are removed from album or moved from one subalbum to a...
QString getSaveLocation()
Returns the current save location of all images.
Subalbum * getLastSubalbum()
Returns a pointer to the last Subalbum.
bool prevSave()
Returns true if album previously saved to disk.
int numSubalbums
Number of subalbums.
int getCreationYear()
Returns the creation year.
int modificationYear
Last modification year.
QStringList getThumbnailFilenames()
Returns a list of the most up to date thumbnail filesnames.
bool albumModified()
Returns true if album has been modified since the last save operation.
int creationYear
Creation year.
Subalbum * firstSubalbum
Pointer to first Subalbum.
QString tmpDir
Temporary directory for placing modified or new images before saving takes place.
QString getName()
Gets the album name.
void updateCreationDate()
Updates the creation date to today's date.
QPixmap * getRepresentativeImage(int size)
Returns the representative image.
A photo consists of a full size image, a smaller slide show image, a very small thumbnail image,...
bool getRecentlyReverted()
was the photo recently reverted? if so ignore the presence of orig files on disk
void setSlideshowChecksum(QString val)
Update slideshow checksum.
void setThumbnailChecksum(QString val)
Update thumbnail checksum.
bool getNeedsSavingVal()
Returns if the image needs to be saved to its permament location.
void setRecentlyReverted(bool val)
reset the recently reverted value to val
Photo * getNext()
Returns next photo pointer.
void setInitialSubalbumNumber(int val)
Sets initial subalbum number.
QString getImageFilename()
Gets the image filename.
void setEverSaved(bool val)
sets everSaved
bool getEverSaved()
Returns if the image has ever been saved to a permanant location.
QString originalImageFilename()
orig filename
void setNeedsSavingVal(bool val)
Sets if the image needs to be saved to its permanent location.
int getInitialSubalbumNumber()
Returns initial subalbum number.
void setThumbnailFilename(QString val)
Sets the thumbnail filename.
void setInitialPhotoNumber(int val)
Sets initial photo number.
QString getThumbnailFilename()
Gets the thumbnail filename.
int getInitialPhotoNumber()
Returns initial photo number.
void setSlideshowFilename(QString val)
Sets the slideshow filename.
void setImageFilename(QString val)
Sets the image filename.
QString getSlideshowFilename()
Gets the slideshow filename.
void setImageChecksum(QString val)
Update image checksum.
A subalbum contains photos.
Subalbum * getPrev()
Returns pointer to prev subalbum.
int getNumPhotos()
Returns the number of photos in the subalbum.
void setSubalbumNumber(int newVal)
Sets the subalbum number to newVal.
Subalbum * getNext()
Returns pointer to next subalbum.
void setPrev(Subalbum *val)
Sets pointer of prev subalbum.
QPixmap * getRepresentativeImage(int size)
gets a sized representative image
Photo * getFirst()
Returns first photo in subalbum.
void resetNumLoadedPhotos()
void setNext(Subalbum *val)
Sets pointer of next subalbum.
void importFromDisk(QDomNode *root, int subalbumNum, StatusWidget *status, QString dirName, bool disableCheckPhotoMods)
Builds subalbum from XML DOM node.
void exportToXML(StatusWidget *status, Q3TextStream &stream)
Exports subalbum to xml.
QString getMD5(std::ifstream &stream)