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

album.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003-2005 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it
00005 //  and/or modify it under the terms of the GNU General
00006 //  Public License as published by the Free Software
00007 //  Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //==============================================
00010 
00011 //Systemwide includes
00012 #include <qimage.h>
00013 #include <qpixmap.h>
00014 #include <qstring.h>
00015 #include <time.h>
00016 #include <qfile.h>
00017 #include <qfileinfo.h>
00018 #include <qtextstream.h>
00019 #include <qdom.h>
00020 #include <qdir.h>
00021 #include <qapplication.h>
00022 #include <qregexp.h>
00023 #include <qdatetime.h>
00024 #include <math.h>
00025 
00026 //Projectwide includes
00027 #include "album.h"
00028 #include "subalbum.h"
00029 #include "photo.h"
00030 #include "tools/imageTools.h"
00031 #include "tools/fileTools.h"
00032 #include "tools/md5.h"
00033 #include "tools/xmlTools.h"
00034 #include "../config.h"
00035 #include "../gui/subalbumPreviewWidget.h"
00036 #include "../gui/statusWidget.h"
00037 
00038 //==============================================
00040 Album::Album( QString tmpDir, bool createSubalbum )
00041 {
00042   //set strings to default values
00043   name = "";
00044   description ="";
00045   author = ""; 
00046   theme = "Slick";
00047   this->tmpDir = tmpDir;
00048 
00049   //by default no representative image
00050   smallRepresentativeImage = NULL;
00051   largeRepresentativeImage = NULL;
00052 
00053   //no Subalbums by default
00054   firstSubalbum = NULL;
00055   lastSubalbum = NULL;
00056 
00057   //set the creation/modification date to today
00058   updateCreationDate();
00059   updateModificationDate();
00060 
00061   //no subalbums
00062   numSubalbums = 0;
00063   numLoadedSubalbums = 0;
00064 
00065   //not previously saved by default
00066   savedToDisk = false;
00067 
00068   //set default save location (where images are placed before saving) to the tmp directory
00069   saveLocation = getTmpDir();
00070 
00071   if(createSubalbum)
00072   {
00073     Subalbum* s = new Subalbum( this, 1 );
00074     appendSubalbum( s );
00075   }
00076   
00077   //no interesting modifications yet
00078   modified = false;
00079 
00080   nextUniqueID = 0;
00081 }
00082 //==============================================
00083 Album::~Album()
00084 {
00085   //delete representative image
00086   delete smallRepresentativeImage;
00087   delete largeRepresentativeImage;
00088 
00089   //delete subalbums
00090   Subalbum* current = firstSubalbum;
00091   Subalbum* temp;
00092   while(current != NULL)
00093   {
00094     temp = current->getNext();
00095     delete current;
00096     current = temp;
00097   }
00098 
00099   //remove all old tmp dir contents and directory itself
00100   if(!tmpDir.isNull())
00101   {
00102     QDir oldTmpDir(tmpDir);
00103     QString tmpDirName = oldTmpDir.dirName();
00104     QStringList strLst = oldTmpDir.entryList();
00105     QStringList::iterator it;
00106     for(it = strLst.begin(); it != strLst.end(); it++)
00107     {
00108       oldTmpDir.remove(tmpDir + "/" + *it);
00109     }
00110     oldTmpDir.cdUp();
00111     oldTmpDir.rmdir( tmpDirName );
00112   }
00113 }
00114 //==============================================
00115 int Album::getModificationYear()  { return modificationYear;     }
00116 int Album::getModificationMonth() { return modificationMonth;    }
00117 int Album::getModificationDay()   { return modificationDay;      }
00118 
00119 int Album::getCreationYear()      { return creationYear;         }
00120 int Album::getCreationMonth()     { return creationMonth;        }
00121 int Album::getCreationDay()       { return creationDay;          }
00122 
00123 QString Album::getName()          { return QString(name);        }
00124 QString Album::getDescription()   { return QString(description); }
00125 QString Album::getAuthor()        { return QString(author);      }
00126 //==============================================
00127 QPixmap* Album::getRepresentativeImage(int size)
00128 {
00129   if(size == SMALL)      return smallRepresentativeImage;
00130   else if(size == LARGE) return largeRepresentativeImage;
00131   else                   return NULL;
00132 }
00133 //==============================================
00134 Subalbum* Album::getFirstSubalbum() { return firstSubalbum; }
00135 Subalbum* Album::getLastSubalbum()  { return lastSubalbum;  }
00136 //==============================================
00137 bool Album::prevSave()      { return savedToDisk; }
00138 bool Album::albumModified() { return modified;    }
00139 //==============================================
00140 QString Album::getSaveLocation() { return saveLocation; }
00141 QString Album::getTmpDir()       { return tmpDir;       }
00142 QString Album::getTheme()        { return theme;        }
00143 int Album::getNumSubalbums()     { return numSubalbums; }
00144 //==============================================
00145 int Album::getNumPhotos()
00146 {
00147   //compute number of photos and size on disk
00148   int numPhotos = 0;
00149   Subalbum* curr = firstSubalbum;
00150   while(curr != NULL)
00151   {
00152     numPhotos+= curr->getNumPhotos();
00153     curr = curr->getNext();
00154   }
00155   return numPhotos; 
00156 }
00157 //==============================================
00158 void Album::setName(QString val)
00159 {
00160   if(name != val)
00161   {
00162     name = val;
00163     modified = true;
00164   }
00165 }
00166 //==============================================
00167 void Album::setDescription(QString val)
00168 {
00169   if(description != val)
00170   {
00171     description = val;
00172     modified = true;
00173   }
00174 }
00175 //==============================================
00176 void Album::setAuthor(QString val)
00177 {
00178   if(author != val)
00179   {
00180     author = val;
00181     modified = true;
00182   }
00183 }
00184 //==============================================
00185 void Album::setRepresentativeImages(QString imageFilename)
00186 {
00187   //delete representative images
00188   delete smallRepresentativeImage;
00189   delete largeRepresentativeImage;
00190 
00191   //if being set to null, set back to defaults
00192   if(imageFilename.isNull())
00193   {
00194     smallRepresentativeImage = NULL;
00195     largeRepresentativeImage = NULL;
00196   }
00197   else
00198   {
00199     //compute representative image sizes
00200     int imageWidth, imageHeight;
00201     getImageSize( imageFilename, imageWidth, imageHeight );
00202     
00203     int smallRepWidth = 0;
00204     int smallRepHeight = 0;
00205     int largeRepWidth = 0;
00206     int largeRepHeight = 0;
00207     calcScaledImageDimensions( imageWidth, imageHeight,
00208                                107, REP_IMAGE_HEIGHT,
00209                                smallRepWidth, smallRepHeight);
00210     calcScaledImageDimensions( imageWidth, imageHeight,
00211                                500, 320,
00212                                largeRepWidth, largeRepHeight);
00213 
00214     //create various representative images
00215 
00216     //copy and scale small version
00217     QImage thumbnailSmall;
00218     scaleImage( imageFilename, thumbnailSmall, smallRepWidth, smallRepHeight );
00219     smallRepresentativeImage = new QPixmap( thumbnailSmall.width(), thumbnailSmall.height() );
00220     smallRepresentativeImage->convertFromImage( thumbnailSmall );
00221 
00222     //copy and scale large version
00223     QImage thumbnailLarge;
00224     scaleImage( imageFilename, thumbnailLarge, largeRepWidth, largeRepHeight );
00225     largeRepresentativeImage = new QPixmap( thumbnailLarge.width(), thumbnailLarge.height() );
00226     largeRepresentativeImage->convertFromImage( thumbnailLarge );
00227   }
00228 
00229   //set modified
00230   modified = true;
00231 }
00232 //==============================================
00233 void Album::appendSubalbum(Subalbum* val)
00234 {
00235   //if passed a null pointer bail!
00236   if( val == NULL) return;
00237 
00238   //empty list - stick on front
00239   if(firstSubalbum == NULL)
00240   {
00241     firstSubalbum = val;
00242     lastSubalbum = val;
00243   }
00244   //else - append to end
00245   else
00246   {
00247     lastSubalbum->setNext( val );
00248     val->setPrev( lastSubalbum );
00249     lastSubalbum = val;
00250   }
00251 
00252   numSubalbums++;
00253   modified = true;
00254 }
00255 //==============================================
00256 void Album::removeSubalbum(Subalbum* val)
00257 {
00258   //if passed a null pointer bail!
00259   if( val == NULL) return;
00260   
00261   //reset head and tail pointers if necessary
00262   if( val == firstSubalbum ) firstSubalbum = val->getNext();
00263   if( val == lastSubalbum )  lastSubalbum  = val->getPrev();
00264   
00265   //split out
00266   if( val->getPrev() != NULL ) val->getPrev()->setNext( val->getNext() );
00267   if( val->getNext() != NULL ) val->getNext()->setPrev( val->getPrev() );
00268   
00269   //delete object
00270   delete val;
00271   val = NULL;
00272   numSubalbums--;
00273   modified = true;
00274 }
00275 //==============================================
00276 void Album::updateCreationDate()
00277 {
00278   //set creation date to today
00279   QDate date    = QDate::currentDate();
00280   creationYear  = date.year();
00281   creationMonth = date.month();
00282   creationDay   = date.day();
00283 }
00284 //==============================================
00285 void Album::updateModificationDate()
00286 {
00287   //set last modification date to today
00288   QDate date        = QDate::currentDate();
00289   modificationYear  = date.year();
00290   modificationMonth = date.month();
00291   modificationDay   = date.day();
00292 }
00293 //==============================================
00294 int Album::importFromDisk(StatusWidget* status, QString fileName, bool disableCheckPhotoMods)
00295 {
00296   //update file
00297   updateXML( QFileInfo(fileName).dirPath(TRUE) );
00298 
00299   //open file
00300   QFile albumFile( fileName );
00301 
00302   //unable to open xml file? alert user
00303   if( !albumFile.open( IO_ReadOnly ) )
00304     return ALBUM_READ_ERROR;
00305 
00306   //parse dom
00307   QDomDocument albumDom;
00308   if( !albumDom.setContent( &albumFile ) )
00309     return ALBUM_XML_ERROR;
00310 
00311   //close file
00312   albumFile.close();
00313 
00314   //get main directory all other files and subdirectories are in
00315   QString rootDir = QFileInfo(albumFile).dirPath(TRUE);
00316   saveLocation = rootDir + "/img";
00317 
00318   //if representative image exists load
00319   QImage repImage(rootDir + "/img/album.jpg");
00320   if(!repImage.isNull())
00321   {
00322     setRepresentativeImages( rootDir + "/img/album.jpg");
00323   }
00324 
00325   //count number of photos in album, needed for showing loading progress
00326   int numPhotos = 0;
00327   QDomElement root = albumDom.documentElement();
00328   QDomNode node = root.firstChild();
00329   while( !node.isNull() )
00330   {
00331     if( node.isElement() && node.nodeName() == "subalbum" )
00332     {
00333       QDomNode childNode = node.firstChild();
00334       while( !childNode.isNull() )
00335       {
00336         if( childNode.isElement() && childNode.nodeName() == "photo" )
00337           numPhotos++;
00338         childNode = childNode.nextSibling();
00339       }
00340     }
00341     node = node.nextSibling();
00342   }
00343 
00344   //setup progress bar
00345   status->showProgressBar( StatusWidget::tr("Loading:"), numPhotos );
00346   qApp->processEvents();
00347 
00348   int subalbumNum = 0;
00349 
00350   //get root node and start parsing DOM
00351   root = albumDom.documentElement();
00352   node = root.firstChild();
00353   QDomText val;
00354   while( !node.isNull() )
00355   {
00356     //------------------------------------------------------------
00357     //album name
00358     if( node.isElement() && node.nodeName() == "name" )
00359     {
00360       val = node.firstChild().toText();
00361       if(!val.isNull())
00362         name = val.nodeValue();
00363      name.replace("\\&quot;","\"");
00364     }
00365     //------------------------------------------------------------
00366     //album description
00367     else if( node.isElement() && node.nodeName() == "description" )
00368     {
00369       val = node.firstChild().toText();
00370       if(!val.isNull())
00371         description = val.nodeValue();
00372      description.replace("\\&quot;","\"");
00373     }
00374     //------------------------------------------------------------
00375     //album author
00376     else if( node.isElement() && node.nodeName() == "author" )
00377     {
00378       val = node.firstChild().toText();
00379       if(!val.isNull())
00380         author = val.nodeValue();
00381      author.replace("\\&quot;","\"");
00382     }
00383     //------------------------------------------------------------
00384     //album theme
00385     else if( node.isElement() && node.nodeName() == "theme" )
00386     {
00387       val = node.firstChild().toText();
00388       if(!val.isNull())
00389         theme = val.nodeValue();
00390      theme.replace("\\&quot;","\"");
00391     }
00392     //------------------------------------------------------------
00393     //album creation date
00394     else if( node.isElement() && node.nodeName() == "created" )
00395     {
00396       val = node.firstChild().toText();
00397 
00398       //split value based on spaces, should be 7 fields
00399       QStringList vals = QStringList::split( QRegExp(" "), val.nodeValue() );
00400       int i=0;
00401       int intVals[3];
00402       QStringList::Iterator it;
00403       for ( it = vals.begin(); it != vals.end(); ++it )
00404       {
00405         intVals[i] = QString(*it).toInt();
00406         i++;
00407         //only read first 3 entires, year/month/day, don't overwrite
00408         //buffer on addition entries if xml messed up
00409         if(i > 2)
00410           break;
00411       }
00412       creationYear = intVals[0];
00413       creationMonth = intVals[1];
00414       creationDay = intVals[2];
00415     }
00416     //------------------------------------------------------------
00417     //subalbum
00418     else if( node.isElement() && node.nodeName() == "subalbum" )
00419     {
00420       //increase counter
00421       subalbumNum++;
00422 
00423       //create new subalbum
00424       Subalbum* salbum = new Subalbum(this, numSubalbums+1);
00425 
00426       //populate it
00427       salbum->importFromDisk( &node, subalbumNum, status, (rootDir + "/"), disableCheckPhotoMods );
00428 
00429       //append it to list of subalbums
00430       appendSubalbum(salbum);
00431     }
00432     //------------------------------------------------------------
00433     //advance to next node
00434     node = node.nextSibling();
00435     //------------------------------------------------------------
00436   }
00437 
00438   //reset number of loaded subalbums
00439   numLoadedSubalbums = numSubalbums;
00440 
00441   //hide progress bar
00442   status->setStatus( "Album loaded." );
00443 
00444   //save load directory name and loaded/saved bit
00445   saveLocation = rootDir;
00446   savedToDisk = true;
00447 
00448   return ALBUM_LOADED;
00449 }
00450 //==============================================
00451 int Album::exportToDisk(StatusWidget* status, QString dirName, QString themeName)
00452 {
00453   //check to see if save location has actually changed, if not don't force save images
00454   //this occurs when user blindly selects the same old spot, or is just changing the theme used by default
00455   bool forceSave = true;
00456 
00457   if(saveLocation == dirName)
00458     forceSave = false;
00459 
00460   //backup theme and save location, if save fails revert to previous values
00461   QString oldSaveLocation = saveLocation;
00462   QString oldTheme = theme;
00463 
00464   //attempt to save album
00465   saveLocation = dirName;
00466   theme = themeName;
00467   int result = exportToDisk(status, forceSave);
00468 
00469   //if album saving failed revert save location and theme
00470   if(result != ALBUM_EXPORTED)
00471   {
00472     saveLocation = oldSaveLocation;
00473     theme = oldTheme;
00474   }
00475   //else update tmp save dir
00476   else
00477   {
00478     //remove all old tmp dir contents and directory itself
00479     QDir oldTmpDir(tmpDir);
00480     QString tmpDirName = oldTmpDir.dirName();
00481     QStringList strLst = oldTmpDir.entryList();
00482     QStringList::iterator it;
00483     for(it = strLst.begin(); it != strLst.end(); it++)
00484     {
00485       oldTmpDir.remove( tmpDir + "/" + *it);
00486     }
00487 
00488     oldTmpDir.cdUp();
00489     oldTmpDir.rmdir( tmpDirName );
00490 
00491     //create and set new temp dir location
00492     QDir saveDir( saveLocation );
00493     if(!saveDir.exists( "tmp" ))
00494       saveDir.mkdir( "tmp" );
00495     tmpDir = saveLocation + "/tmp";
00496     
00497     //reset unique id counter
00498     nextUniqueID = 0;
00499   }
00500 
00501   //return result
00502   return result;
00503 }
00504 //==============================================
00505 int Album::exportToDisk(StatusWidget* status, bool forceSave)
00506 {
00507   //------------------------------------------
00508   //create subdirs
00509   QDir localDir(saveLocation);
00510   //img dirs
00511   localDir.mkdir("img");
00512   //subalbum dirs
00513   localDir.setPath(saveLocation + "/img");
00514 
00515   //make a temporary 0 directory for copying new images, they'll be moved to their final
00516   //location during the reordering step
00517   localDir.mkdir( "0" );
00518   
00519   //iterate over each subalbum and create its image directory
00520   Subalbum* current = firstSubalbum;  
00521   int collectionNum = 0;
00522   while(current != NULL)
00523   {
00524     collectionNum++;
00525     QString dirName = QString("%1") .arg( collectionNum );
00526     localDir.mkdir(dirName);
00527     current = current->getNext();
00528   }
00529   //------------------------------------------
00530   //checks worked, go ahead with export
00531 
00532   //count number of photos
00533   int totalPhotos=0;
00534   current = firstSubalbum;
00535   while(current != NULL)
00536   {
00537     totalPhotos+=current->getNumPhotos();
00538     current = current->getNext();
00539   }
00540 
00541   //setup progress bar
00542   status->showProgressBar( StatusWidget::tr("Saving:"), 4*totalPhotos );
00543   qApp->processEvents();
00544 
00545   //copy over theme resources
00546   exportThemeResources( theme );
00547 
00548   //export album cover image, subalbum thumbnails
00549   exportTopLevelImages();
00550 
00551   //export subalbum images (thumbnail, slideshow, and full versions of all images)
00552   exportSubalbumImages(status, forceSave);
00553 
00554   //remove any _orig images for photos which have been reverted to their original form
00555   removeStagnantOrigFiles(status);
00556   
00557   //apply reordering to all images
00558   reorderSubalbumImages(status);
00559 
00560   //reset subalbum numbers to current ordering
00561   current = firstSubalbum;
00562   int n=0;
00563   while(current !=NULL)
00564   {
00565     n++;
00566     current->setSubalbumNumber(n);
00567     current = current->getNext();
00568   }
00569 
00570   //remove collection 0 directory
00571   QDir rootDir(saveLocation + "/img/");
00572   rootDir.rmdir( "0" );
00573   
00574   //remove old images that nolonger belong
00575   removeStagnantImages();
00576 
00577   //remove previous html/htm files
00578   localDir.setPath(saveLocation);
00579   QStringList list = localDir.entryList( QDir::Files );
00580   QStringList::Iterator file;
00581   for ( file = list.begin(); file != list.end(); ++file )
00582   {
00583     if( (*file).endsWith(".html") || (*file).endsWith(".htm") )
00584       localDir.remove( saveLocation + "/" + *file );
00585   }
00586 
00587   //export xml structure of album
00588   int result = exportToXML(status, saveLocation);
00589   if(result != ALBUM_EXPORTED) { return result; }
00590 
00591   //export various html pages using selected theme
00592   transformXMLtoHTML( saveLocation, theme, false );
00593 
00594   //------------------------------------------
00595   //remove files from temp folder
00596   QDir tmpDirHandle( getTmpDir() );
00597   QStringList strLst = tmpDirHandle.entryList();
00598   QStringList::iterator it;
00599   for(it = strLst.begin(); it != strLst.end(); it++)
00600   {
00601     tmpDirHandle.remove( getTmpDir() + "/" + *it);
00602   }
00603   //------------------------------------------
00604   savedToDisk = true;
00605 
00606   //just saved so no modifications since last save
00607   modified = false;
00608 
00609   //hide progress bar
00610   status->setStatus( "Album saved." );
00611   //------------------------------------------
00612   return ALBUM_EXPORTED;
00613 }
00614 //==============================================
00615 int Album::exportCompressedWebAlbum(StatusWidget* status, 
00616                                     QString exportLocation, 
00617                                     QString exportMessage)
00618 {
00619   //------------------------------------------
00620   //copy all images
00621   QDir localDir(exportLocation);
00622   localDir.mkdir("img");
00623   localDir.setPath(exportLocation + "/img");
00624   
00625   //copy album image
00626   if(getRepresentativeImage(LARGE) != NULL)
00627   { getRepresentativeImage(LARGE)->save(exportLocation + "/img/album.jpg", "JPEG", 95); }
00628   else
00629   { localDir.remove(exportLocation + "/img/album.jpg"); }
00630     
00631   int numPhotos = getNumPhotos();  
00632   int photosLeft = numPhotos;  
00633   int updateInverval = numPhotos / 50;
00634   int updateCount = 0;
00635   
00636   //iterate over each collection
00637   Subalbum* curCollection = firstSubalbum;
00638   int collectionNum=1;
00639   while(curCollection != NULL)
00640   {
00641     QString collectionDir = QString("%1").arg( collectionNum );
00642     localDir.mkdir( collectionDir );
00643 
00644     //copy collection image
00645     QString collectionThumbFilename = QString(exportLocation + "/img/%1_thumb.jpg" ).arg(collectionNum);
00646     if(curCollection->getRepresentativeImage(LARGE) != NULL )
00647     { curCollection->getRepresentativeImage(LARGE)->save( collectionThumbFilename, "JPEG", 95); }
00648     else
00649     { localDir.remove( collectionThumbFilename ); }
00650     
00651     //copy each photo
00652     Photo* curPhoto = curCollection->getFirst();
00653     int photoNum = 1;
00654     while(curPhoto != NULL)
00655     {
00656       //update status message
00657       status->updateProgress( numPhotos - photosLeft, exportMessage.arg( photosLeft ) );
00658       
00659       //make sure events are processed every 2% of the photos that are processes
00660       updateCount++;
00661       if(updateCount > updateInverval)
00662       {
00663         updateCount = 0;
00664         qApp->processEvents();        
00665       }      
00666       
00667       //copy files
00668       QString newFilePath = QDir::convertSeparators( exportLocation + "/img/" + 
00669                                                      collectionDir + "/" + 
00670                                                      QString("%1").arg(photoNum) );
00671 
00672       copyFile( curPhoto->getSlideshowFilename(), newFilePath + "_slideshow.jpg" );
00673       copyFile( curPhoto->getThumbnailFilename(), newFilePath + "_thumb.jpg" );
00674       
00675       curPhoto = curPhoto->getNext();
00676       photoNum++;
00677       photosLeft--;
00678     }
00679     
00680     curCollection = curCollection->getNext();
00681     collectionNum++;
00682   }
00683   //------------------------------------------
00684   //copy theme resources
00685   QStringList fileList;
00686   QStringList::Iterator file;
00687   
00688   //create HTML and misc resources directories
00689   localDir.setPath(exportLocation);
00690   localDir.mkdir("resources");
00691   
00692   //remove all files in these directories from previous saves with other themes
00693   localDir.setPath(exportLocation + "/resources");
00694   fileList = localDir.entryList( QDir::Files );
00695   for ( file = fileList.begin(); file != fileList.end(); ++file )
00696   { localDir.remove( exportLocation + "/resources/" + *file ); }
00697   
00698   //copy files over from theme's directory
00699   localDir.setPath(THEMES_PATH + theme + "/resources");
00700   fileList = localDir.entryList( QDir::Files );
00701   for ( file = fileList.begin(); file != fileList.end(); ++file )
00702   { copyFile( THEMES_PATH + theme + "/resources/" + *file, exportLocation + "/resources/" + *file); }
00703   //------------------------------------------
00704   //export xml file
00705   exportToXML(status, exportLocation);
00706   //------------------------------------------  
00707   //remove previous html/htm files
00708   localDir.setPath(exportLocation);
00709   fileList = localDir.entryList( QDir::Files );
00710   for ( file = fileList.begin(); file != fileList.end(); ++file )
00711   {
00712     if( (*file).endsWith(".html") || (*file).endsWith(".htm") )
00713       localDir.remove( exportLocation + "/" + *file );
00714   }
00715   //------------------------------------------
00716   //construct html files
00717   transformXMLtoHTML( exportLocation, theme, true );
00718   //------------------------------------------
00719   //remove xml file
00720   localDir.remove( exportLocation + "/Album.xml" );  
00721   //------------------------------------------
00722   return ALBUM_EXPORTED;
00723 }
00724 //==============================================
00725 int Album::exportLargeImages(StatusWidget* status, QString exportPath, QString exportMessage)
00726 {
00727   //determine number of digits collecion # requires
00728   uint collectionDigits = (uint) (1 + log( (double) getNumSubalbums() ) / log( 10.0 ) );
00729   
00730   //determine number of digits photo # requires, this
00731   //involves walking through the album and finding the collection with the most phots first
00732   int mostPhotos = 0;  
00733   Subalbum* curCollection = getFirstSubalbum();
00734   while(curCollection != NULL )
00735   {
00736     mostPhotos = QMAX( mostPhotos, curCollection->getNumPhotos() );
00737     curCollection = curCollection->getNext(); 
00738   }
00739   uint photoDigits = (uint) ( 1 + log( (double) mostPhotos ) / log( 10.0 ) );   
00740   //------------
00741   //copy files  
00742   int numPhotos = getNumPhotos();  
00743   int photosLeft = numPhotos;  
00744   
00745   int collectionNum = 1;
00746   curCollection = getFirstSubalbum();
00747   
00748   int updateInverval = numPhotos / 50;
00749   int updateCount = 0;
00750   
00751   while(curCollection != NULL )
00752   {
00753     //construct collection string
00754     QString collectionString = QString("%1").arg(collectionNum);
00755     while(collectionString.length() < collectionDigits)
00756     { collectionString = "0" + collectionString; }  
00757     
00758     //copy all photos in collection
00759     int photoNum = 1;
00760     Photo* curPhoto = curCollection->getFirst();
00761     while(curPhoto != NULL)
00762     {
00763       //update status message
00764       status->updateProgress( numPhotos - photosLeft, exportMessage.arg( photosLeft ) );
00765       
00766       //make sure events are processed every 2% of the photos that are processes
00767       updateCount++;
00768       if(updateCount > updateInverval)
00769       {
00770         updateCount = 0;
00771         qApp->processEvents();        
00772       }
00773 
00774       //construct photo string
00775       QString photoString = QString("%1").arg(photoNum);
00776       while(photoString.length() < photoDigits)
00777       { photoString = "0" + photoString; }  
00778       
00779       //construct new photo path
00780       QString newFilePath = QDir::convertSeparators( exportPath + "/" + collectionString + 
00781                                                      "_" + photoString + ".jpg" );
00782       //copy file
00783       copyFile( curPhoto->getImageFilename(), newFilePath );
00784       
00785       //move on to next file
00786       photosLeft--;
00787       curPhoto = curPhoto->getNext();
00788       photoNum++;
00789       
00790     } //while photo
00791     
00792     //move on to next collection
00793     curCollection = curCollection->getNext();
00794     collectionNum++;    
00795   }// while collection
00796    //------------
00797   return ALBUM_EXPORTED;
00798 }
00799 //==============================================
00800 int Album::exportToXML(StatusWidget* status, QString exportPath)
00801 {
00802   //update modification date
00803   updateModificationDate();
00804 
00805   //create/open xml file
00806   QFile file( exportPath + "/Album.xml" );
00807   if(file.open(IO_WriteOnly))
00808   {
00809     //-----
00810     QTextStream stream;
00811     stream.setDevice( &file );
00812     stream.setEncoding( QTextStream::UnicodeUTF8 );
00813     
00814     //write album information
00815     stream << "<?xml version=\"1.0\"?>\n";
00816     stream << "<album version=\"1.1\">\n";
00817     stream << "  <name>" << fixXMLString(name) << "</name>\n";
00818     stream << "  <description>" << fixXMLString(description) << "</description>\n";
00819     stream << "  <author>" << fixXMLString(author) << "</author>\n";
00820     stream << "  <created>" << creationYear << " " << creationMonth << " " << creationDay << "</created>\n";
00821     stream << "  <modified>" << modificationYear << " " << modificationMonth << " " << modificationDay << "</modified>\n";
00822     stream << "  <theme>" << theme << "</theme>\n";
00823     stream << "  <thumbnailDimensions>" << THUMBNAIL_WIDTH << " " << THUMBNAIL_HEIGHT << "</thumbnailDimensions>\n";
00824     stream << "  <slideshowDimensions>" << SLIDESHOW_WIDTH << " " << SLIDESHOW_HEIGHT << "</slideshowDimensions>\n";
00825 
00826     //if album has a represenatative image save it's path
00827     if(getRepresentativeImage(LARGE) != NULL )
00828     {
00829       stream << "  <thumb path=\"img/album.jpg\"/>\n";
00830     }
00831 
00832     //write subalbums
00833     Subalbum* current = firstSubalbum;
00834     while(current != NULL)
00835     {
00836       current->exportToXML(status, stream);
00837       current = current->getNext();
00838     }
00839 
00840     //end album
00841     stream << "</album>\n";
00842     file.close();
00843 
00844     return ALBUM_EXPORTED;
00845   }
00846   else
00847   {
00848     return ALBUM_ERROR_OPEN_FILE;
00849   }
00850 }
00851 //==============================================
00852 void Album::exportTopLevelImages()
00853 {
00854   //if image set export it
00855   if(getRepresentativeImage(LARGE) != NULL)
00856   {
00857     getRepresentativeImage(LARGE)->save(saveLocation + "/img/album.jpg", "JPEG", 95);
00858   }
00859   //else make sure any previously set images are removed
00860   else
00861   {
00862     QDir rootDir(saveLocation + "/img/");
00863     rootDir.remove(saveLocation + "/img/album.jpg");
00864   }
00865 
00866   //export subalbum thumbs
00867   int n=0;
00868   Subalbum* current = firstSubalbum;
00869   while(current != NULL)
00870   {
00871     n++;
00872     //if subalbum has representative image export it
00873     if(current->getRepresentativeImage(LARGE) != NULL )
00874     {
00875       QString fileName = QString(saveLocation + "/img/%1_thumb.jpg" ).arg(n);
00876       current->getRepresentativeImage(LARGE)->save(fileName, "JPEG", 95);
00877     }
00878     //otherwise make sure anyprevious set images are removed
00879     else
00880     {
00881       QDir rootDir(saveLocation + "/img/");
00882       rootDir.remove( saveLocation + QString("/img/%1_thumb.jpg").arg(n) );
00883     }
00884     current = current->getNext();
00885   }
00886 }
00887 //==============================================
00888 void Album::exportSubalbumImages(StatusWidget* status, bool forceSave)
00889 {
00890   //iterate over all subalbums
00891   int subalbumNumber=0;
00892   Subalbum* currentSubalbum = firstSubalbum;
00893   while(currentSubalbum != NULL)
00894   {
00895     subalbumNumber++;
00896 
00897     //iterate over all photos in this subalbum
00898     int photoNumber=0;
00899     Photo* currentPhoto = currentSubalbum->getFirst();
00900     while(currentPhoto != NULL)
00901     {
00902       photoNumber++;
00903       //---------------------------------------
00904       //if the current photo does not need to be saved then move on
00905       if( !forceSave && !currentPhoto->getNeedsSavingVal() )
00906       {
00907         currentPhoto = currentPhoto->getNext();
00908         status->incrementProgress();
00909         qApp->processEvents();
00910         continue;
00911       }
00912       //---------------------------------------
00913       //get initial photo # and subalbum #, used for saving
00914       int initPhotoNumber = currentPhoto->getInitialPhotoNumber();
00915       int initSubalbumNumber = currentPhoto->getInitialSubalbumNumber();
00916       //---------------------------------------
00917       //export thumbnail image
00918       QString oldName = currentPhoto->getThumbnailFilename();
00919       QString newName = QString(saveLocation + "/img/%1/%2_thumb.jpg" )
00920                         .arg(initSubalbumNumber).arg(initPhotoNumber);
00921       
00922       //if file has been modified move from current location to final location
00923       if( currentPhoto->getNeedsSavingVal() ) { moveFile( oldName, newName ); }
00924       //If file has not been modified we must be doing a save-as and saving has been forced. In this case
00925       //COPY file from current location to final location, DON'T delete previous copy!!!
00926       else { copyFile(oldName, newName); }
00927 
00928       //compute and store md5 for slideshow image
00929       std::ifstream thumbnailFile( QFile::encodeName(newName) );
00930       if(thumbnailFile.is_open())
00931       {
00932         currentPhoto->setThumbnailChecksum( getMD5(thumbnailFile) );
00933         thumbnailFile.close();
00934       }
00935       //---------------------------------------
00936       //export slideshow image
00937       oldName = currentPhoto->getSlideshowFilename();
00938       newName = QString(saveLocation + "/img/%1/%2_slideshow.jpg" )
00939                         .arg(initSubalbumNumber).arg(initPhotoNumber);
00940 
00941       //if file has been modified move from current location to final location
00942       if( currentPhoto->getNeedsSavingVal() ) { moveFile( oldName, newName ); }
00943       //If file has not been modified we must be doing a save-as and saving has been forced. In this case
00944       //COPY file from current location to final location, DON'T delete previous copy!!!
00945       else { copyFile(oldName, newName); }
00946 
00947       //compute and store md5 for slideshow image
00948       std::ifstream slideshowFile( QFile::encodeName(newName) );
00949       if(slideshowFile.is_open())
00950       {
00951         currentPhoto->setSlideshowChecksum( getMD5(slideshowFile) );
00952         slideshowFile.close();
00953       }
00954       //---------------------------------------
00955       //export full size image
00956       oldName = currentPhoto->getImageFilename();
00957       newName = QString(saveLocation + "/img/%1/%2.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00958 
00959       //if file has been modified move from current location to final location
00960       if( currentPhoto->getNeedsSavingVal() ) 
00961       {
00962         QString tempOrigName = getTmpDir() + QString("/%1_%2_orig.jpg")
00963         .arg(initSubalbumNumber).arg(initPhotoNumber);
00964                      
00965         QString finalOrigName = QString(saveLocation + "/img/%1/%2_orig.jpg" )
00966           .arg(initSubalbumNumber).arg(initPhotoNumber);
00967 
00973         QDir tmpDir;
00974         if( !currentPhoto->getRecentlyReverted() &&
00975             tmpDir.exists(newName) &&
00976             !tmpDir.exists(finalOrigName) )
00977         {
00978           moveFile( newName, finalOrigName );
00979         }      
00984         else if( !currentPhoto->getRecentlyReverted() &&
00985                  !tmpDir.exists(newName) &&
00986                  tmpDir.exists(tempOrigName) )
00987         {
00988           moveFile( tempOrigName, finalOrigName );
00989         }
00990 
00992         moveFile( oldName, newName );
00993       }
00994       //If file does not need to be saved a force save is taking place. This occurs when a user chooses
00995       //save as and copies an entire album to a different location so all files must be copied. Make
00996       //sure to copy over the original form of the photo as well if this file exists
00997       else
00998       {
00999         //copy current image
01000         copyFile( oldName, newName );
01001         
01003         //if orig file exists copy it too
01004         QDir tmpDir;
01005          
01006         QString tempOrigName = getTmpDir() + QString("/%1_%2_orig.jpg")
01007            .arg(initSubalbumNumber).arg(initPhotoNumber);
01008 
01009         QString curOrigName = currentPhoto->getImageFilename();
01010         curOrigName.truncate( curOrigName.length() - 4 );
01011         curOrigName = curOrigName + "_orig.jpg";
01012 
01013         QString finalOrigName = QString(saveLocation + "/img/%1/%2_orig.jpg" )
01014            .arg(initSubalbumNumber).arg(initPhotoNumber);
01015 
01016         //if the photo was recently reverted ignore the presence of orig files
01017         if( !currentPhoto->getRecentlyReverted() )
01018         {
01019           //if the photo was never previously saved and an orig file
01020           //exists in the tmp directory make sure to copy it over
01021           if( !currentPhoto->getEverSaved() &&
01022               tmpDir.exists( tempOrigName ) )
01023           {
01024             copyFile( tempOrigName, finalOrigName );
01025           }        
01026           //if the photo was previously saved and an orig file exists
01027           //in the previous save location make sure to copy it over
01028           else if( currentPhoto->getEverSaved() &&
01029                    tmpDir.exists( curOrigName ) )
01030           {
01031             copyFile( curOrigName, finalOrigName );
01032           }        
01033         }
01035       }
01036       //---------------------------------------
01037       //compute and store md5 for image
01038       std::ifstream imageFile( QFile::encodeName(newName) );
01039       if(imageFile.is_open())
01040       {
01041         currentPhoto->setImageChecksum( getMD5(imageFile) );
01042         imageFile.close();
01043       }
01044       //---------------------------------------
01045       //set new storage locations of files
01046       currentPhoto->setImageFilename
01047         ( QString(saveLocation + "/img/%1/%2.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
01048       
01049       currentPhoto->setSlideshowFilename
01050         ( QString(saveLocation + "/img/%1/%2_slideshow.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
01051       
01052       currentPhoto->setThumbnailFilename
01053         ( QString(saveLocation + "/img/%1/%2_thumb.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
01054       //---------------------------------------
01055       //set image as not needing saving and as being saved
01056       currentPhoto->setNeedsSavingVal(false);
01057       currentPhoto->setEverSaved(true);
01058       //---------------------------------------
01059       //update progress bar
01060       status->incrementProgress();
01061       qApp->processEvents();
01062       //---------------------------------------
01063       //move on to next photo in subalbum
01064       currentPhoto = currentPhoto->getNext();
01065       //---------------------------------------
01066     }
01067     //---------------------------------------
01068     //move on to next subalbum
01069     currentSubalbum = currentSubalbum->getNext();
01070   }
01071 }
01072 //==============================================
01073 void Album::removeStagnantOrigFiles(StatusWidget* status)
01074 {
01075   QDir tmpDir;
01076   
01077   //iterate over all collections
01078   Subalbum* currentSubalbum = firstSubalbum;
01079   while(currentSubalbum != NULL)
01080   {
01081     //iterate over all photos in this subalbum
01082     Photo* currentPhoto = currentSubalbum->getFirst();
01083     while(currentPhoto != NULL)
01084     {
01085       //if photo recently reverted, if so remove orig file
01086       if(currentPhoto->getRecentlyReverted() )
01087       {
01088         tmpDir.remove( currentPhoto->originalImageFilename() );
01089         currentPhoto->setRecentlyReverted( false );
01090       }
01091       
01092       //move on to next photo
01093       currentPhoto = currentPhoto->getNext();
01094       status->incrementProgress();
01095       qApp->processEvents();
01096     }
01097     
01098     //move on to next subalbum
01099     currentSubalbum  = currentSubalbum->getNext();
01100   }      
01101 }
01102 //==============================================
01103 void Album::reorderSubalbumImages(StatusWidget* status)
01104 {
01105   //--------------------------------------------------------
01106   //--------------------------------------------------------
01107   //first pass over all photos, those whose initial and current numbers don't match up
01108   //rename slightly so we don't overwrte them the second time around
01109   //--------------------------------------------------------
01110   //--------------------------------------------------------
01111   //iterate over all subalbums
01112   QDir tmpDir;
01113   int subalbumNumber=0;
01114   Subalbum* currentSubalbum = firstSubalbum;
01115   while(currentSubalbum != NULL)
01116   {
01117     subalbumNumber++;
01118 
01119     //iterate over all photos in this subalbum
01120     int photoNumber=0;
01121     Photo* currentPhoto = currentSubalbum->getFirst();
01122     while(currentPhoto != NULL)
01123     {
01124       photoNumber++;
01125       int initPhotoNumber    = currentPhoto->getInitialPhotoNumber();
01126       int initSubalbumNumber = currentPhoto->getInitialSubalbumNumber();
01127 
01128       //if photo has moved rename full image, orig image (if it exists), slideshow image, and thumbnail images
01129       if( initPhotoNumber != photoNumber || initSubalbumNumber != subalbumNumber)
01130       {
01131         QString oldName = QString(saveLocation + "/img/%1/%2.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01132         QString newName = QString(saveLocation + "/img/%1/%2_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01133         moveFile( oldName, newName );
01134         //-----      
01135         oldName = QString(saveLocation + "/img/%1/%2_orig.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01136         newName = QString(saveLocation + "/img/%1/%2_orig_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01137         if(tmpDir.exists(oldName) ) { moveFile( oldName, newName ); }
01138         //-----
01139         oldName = QString(saveLocation + "/img/%1/%2_slideshow.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01140         newName = QString(saveLocation + "/img/%1/%2_slideshow_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01141         moveFile( oldName, newName );
01142         //-----
01143         oldName = QString(saveLocation + "/img/%1/%2_thumb.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01144         newName = QString(saveLocation + "/img/%1/%2_thumb_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01145         moveFile( oldName, newName );
01146       }
01147       
01148       //move on to next photo
01149       currentPhoto = currentPhoto->getNext();
01150       status->incrementProgress();
01151       qApp->processEvents();
01152     }
01153 
01154     //move on to next subalbum
01155     currentSubalbum = currentSubalbum->getNext();
01156   }
01157 
01158   //--------------------------------------------------------
01159   //--------------------------------------------------------
01160   //second pass over all photos, those whose initial and current numbers don't match up
01161   //rename to their final names and reset initial photo and subalbum numbers
01162   //--------------------------------------------------------
01163   //--------------------------------------------------------
01164   //iterate over all subalbums
01165   subalbumNumber=0;
01166   currentSubalbum = firstSubalbum;
01167   while(currentSubalbum != NULL)
01168   {
01169     subalbumNumber++;
01170 
01171     //iterate over all photos in this subalbum
01172     int photoNumber=0;
01173     Photo* currentPhoto = currentSubalbum->getFirst();
01174     while(currentPhoto != NULL)
01175     {
01176       photoNumber++;
01177       int initPhotoNumber    = currentPhoto->getInitialPhotoNumber();
01178       int initSubalbumNumber = currentPhoto->getInitialSubalbumNumber();
01179       
01180       //if the current photo has moved rename full image, slideshow image, and thumbnail image to their final names
01181       if( initPhotoNumber != photoNumber || initSubalbumNumber != subalbumNumber)
01182       { 
01183         QString oldName = QString(saveLocation + "/img/%1/%2_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01184         QString newName = QString(saveLocation + "/img/%1/%2.jpg" ).arg(subalbumNumber).arg(photoNumber);
01185         moveFile( oldName, newName );
01186         //-----
01187         oldName = QString(saveLocation + "/img/%1/%2_orig_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01188         newName = QString(saveLocation + "/img/%1/%2_orig.jpg" ).arg(subalbumNumber).arg(photoNumber);
01189         if(tmpDir.exists(oldName) ) { moveFile( oldName, newName ); }
01190         //-----
01191         oldName = QString(saveLocation + "/img/%1/%2_slideshow_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01192         newName = QString(saveLocation + "/img/%1/%2_slideshow.jpg" ).arg(subalbumNumber).arg(photoNumber);
01193         moveFile( oldName, newName );
01194         //-----
01195         oldName = QString(saveLocation + "/img/%1/%2_thumb_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
01196         newName = QString(saveLocation + "/img/%1/%2_thumb.jpg" ).arg(subalbumNumber).arg(photoNumber);
01197         moveFile( oldName, newName );
01198         //---------------------------------------
01199         //reset initial photo and subalbum numbers, and filenames
01200         currentPhoto->setInitialPhotoNumber(photoNumber);
01201         currentPhoto->setInitialSubalbumNumber(subalbumNumber);
01202         currentPhoto->setImageFilename( QString(saveLocation + "/img/%1/%2.jpg").
01203                                         arg(subalbumNumber).arg(photoNumber) );
01204         currentPhoto->setSlideshowFilename( QString(saveLocation + "/img/%1/%2_slideshow.jpg").
01205                                             arg(subalbumNumber).arg(photoNumber) );
01206         currentPhoto->setThumbnailFilename( QString(saveLocation + "/img/%1/%2_thumb.jpg").
01207                                             arg(subalbumNumber).arg(photoNumber) );
01208       }
01209       
01210       //move on to next photo
01211       currentPhoto = currentPhoto->getNext();
01212       status->incrementProgress();
01213       qApp->processEvents();
01214     }
01215 
01216     //move on to next subalbum
01217     currentSubalbum = currentSubalbum->getNext();
01218   }
01219 }
01220 //==============================================
01221 void Album::removeStagnantImages()
01222 {
01223   QDir rootDir(saveLocation + "/img/");
01224 
01225   //iterate over each collection
01226   int subalbumNumber=0;
01227   Subalbum* currentSubalbum = firstSubalbum;
01228   while(currentSubalbum != NULL)
01229   {
01230     subalbumNumber++;
01231 
01232     //remove all photos who are numbered greater
01233     //than the number of photos in the subalbum
01234     int photoNum = currentSubalbum->getNumPhotos()+1;
01235     while(true)
01236     {
01237       QString imageString     = QString(saveLocation + "/img/%1/%2.jpg").arg(subalbumNumber).arg(photoNum);
01238       QString origString      = QString(saveLocation + "/img/%1/%2_orig.jpg").arg(subalbumNumber).arg(photoNum);
01239       QString slideshowString = QString(saveLocation + "/img/%1/%2_slideshow.jpg").arg(subalbumNumber).arg(photoNum);
01240       QString thumbString     = QString(saveLocation + "/img/%1/%2_thumb.jpg").arg(subalbumNumber).arg(photoNum);
01241       
01242       //if none of the possible images exist then assume 
01243       //no more stagnant images exist in this collection
01244       //
01245       if( !rootDir.exists(imageString)     && !rootDir.exists(origString) &&
01246           !rootDir.exists(slideshowString) && !rootDir.exists(thumbString) )
01247         break;
01248       //else delete photos and move on
01249       else
01250       {
01251         rootDir.remove( imageString );
01252         rootDir.remove( origString );
01253         rootDir.remove( slideshowString );
01254         rootDir.remove( thumbString );
01255         photoNum++;
01256       }
01257     }
01258 
01259     //reset number of loaded photos since old photos removed now
01260     currentSubalbum->resetNumLoadedPhotos();
01261 
01262     //move on to next collection
01263     currentSubalbum = currentSubalbum->getNext();
01264   }
01265   //---------------------------------
01266   //remove stagnant collections and all their contents
01267   subalbumNumber = numSubalbums+1;
01268   while(true)
01269   {    
01270     //check to see if the directory exists, if not we are done
01271     QString imageDirString = QString(saveLocation + "/img/%1/").arg(subalbumNumber);
01272     if( !rootDir.exists(imageDirString) )
01273       break;
01274 
01275     //get filelist for directory
01276     QDir imageDir(  imageDirString );
01277     QStringList list = imageDir.entryList( QDir::Files );
01278 
01279     //remove each file in directory
01280     QStringList::Iterator file;
01281     for ( file = list.begin(); file != list.end(); ++file )
01282     { rootDir.remove( QString(saveLocation + "/img/%1/" + *file).arg(subalbumNumber) ); }
01283 
01284     //remove directory
01285     rootDir.rmdir( QString("%1").arg(subalbumNumber) );
01286 
01287     //remove thumbnail image
01288     rootDir.remove( QString(saveLocation + "/img/%1_thumb.jpg").arg(subalbumNumber) );
01289 
01290     //move on to next subalbum
01291     subalbumNumber++;
01292   }
01293 
01294   //reset number of loaded subalbums since stagnant directories removed now
01295   numLoadedSubalbums = numSubalbums;
01296   //---------------------------------
01297 }
01298 //==============================================
01299 void Album::exportThemeResources( QString theme )
01300 {
01301   QStringList fileList;
01302   QStringList::Iterator file;
01303   QDir localDir;
01304   
01305   //remove any "resources" directories created by 1.0* versions of Album Shaper
01306   localDir.setPath( saveLocation + "/resources" );
01307   fileList = localDir.entryList();
01308   for(file = fileList.begin(); file != fileList.end(); file++)
01309   {
01310     localDir.remove(saveLocation + "/resources/" + *file);
01311   }
01312   localDir.cdUp();
01313   localDir.rmdir( "resources" );
01314   
01315   //create HTML and misc resources directories
01316   localDir.setPath(saveLocation);
01317   localDir.mkdir("resources");
01318 //  localDir.mkdir("misc_resources");
01319 
01320   //remove all files in these directories from previous saves with other themes
01321   localDir.setPath(saveLocation + "/resources");
01322   fileList = localDir.entryList( QDir::Files );
01323   for ( file = fileList.begin(); file != fileList.end(); ++file )
01324   { localDir.remove( saveLocation + "/resources/" + *file ); }
01325   //--
01326 /*
01327  localDir.setPath(saveLocation + "/misc_resources");
01328   fileList = localDir.entryList( QDir::Files );
01329   for ( file = fileList.begin(); file != fileList.end(); ++file )
01330   { localDir.remove( saveLocation + "/misc_resources/" + *file ); }
01331 */    
01332   //copy files over from theme's directory
01333   localDir.setPath(THEMES_PATH + theme + "/resources");
01334   fileList = localDir.entryList( QDir::Files );
01335   for ( file = fileList.begin(); file != fileList.end(); ++file )
01336   { copyFile( THEMES_PATH + theme + "/resources/" + *file, saveLocation + "/resources/" + *file); }
01337   //--
01338 /*
01339  localDir.setPath(THEMES_PATH + theme + "/misc_resources");
01340   fileList = localDir.entryList( QDir::Files );
01341   for ( file = fileList.begin(); file != fileList.end(); ++file )
01342   { copyFile( THEMES_PATH + theme + "/misc_resources/" + *file, saveLocation + "/misc_resources/" + *file); }  
01343 */
01344 }
01345 //==============================================
01346 void Album::syncSubalbumList(SubalbumPreviewWidget* item)
01347 {
01348   //check to see if any changes actually took place
01349   bool change = false;
01350   Subalbum* tmp = firstSubalbum;
01351   SubalbumPreviewWidget* tmp2 = item;
01352   while( tmp2 != NULL)
01353   {
01354     //pointers do not match up
01355     if(tmp != tmp2->getSubalbum() )
01356     {
01357       change = true;
01358       break;
01359     }
01360 
01361     tmp = tmp->getNext();
01362     tmp2 = (SubalbumPreviewWidget*)tmp2->nextItem();
01363   }
01364 
01365   //if no change then quit
01366   if(!change)
01367     return;
01368 
01369   //base case, no items
01370   if(item == NULL)
01371   {
01372     firstSubalbum = NULL;
01373     lastSubalbum = NULL;
01374     return;
01375   }
01376 
01377   //set first and last pointers
01378   firstSubalbum = item->getSubalbum();
01379   firstSubalbum->setNext(NULL);
01380   firstSubalbum->setPrev(NULL);
01381   lastSubalbum = firstSubalbum;
01382 
01383   //set all next pointers
01384   while(item->nextItem() != NULL)
01385   {
01386     item->getSubalbum()->setNext( ((SubalbumPreviewWidget*)item->nextItem())->getSubalbum() );
01387     item->getSubalbum()->getNext()->setPrev( item->getSubalbum() );
01388     item = (SubalbumPreviewWidget*)item->nextItem();
01389     lastSubalbum = item->getSubalbum();
01390     lastSubalbum->setNext(NULL);
01391   }
01392   
01393 }
01394 //==============================================
01395 void Album::setModified(bool val) { modified = val; }
01396 //==============================================
01397 int Album::getNextUniquePhotoID()
01398 {
01399   nextUniqueID++;
01400   return nextUniqueID;
01401 }
01402 //==============================================

Generated on Sat Apr 2 05:44:04 2005 for AlbumShaper by  doxygen 1.3.9.1