00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qimage.h>
00019 #include <qpixmap.h>
00020 #include <qstring.h>
00021 #include <time.h>
00022 #include <qfile.h>
00023 #include <qfileinfo.h>
00024 #include <qtextstream.h>
00025 #include <qdom.h>
00026 #include <qdir.h>
00027 #include <qapplication.h>
00028 #include <qregexp.h>
00029 #include <qdatetime.h>
00030
00031
00032 #include "album.h"
00033 #include "subalbum.h"
00034 #include "photo.h"
00035 #include "imageTools.h"
00036 #include "xmlTools.h"
00037 #include "md5.h"
00038 #include "../gui/subalbumPreviewWidget.h"
00039 #include "../gui/statusWidget.h"
00040 #include "../config.h"
00041
00042
00044 Album::Album()
00045 {
00046
00047 name = "";
00048 description ="";
00049 author = "";
00050
00051 theme = "Classic";
00052
00053
00054 smallRepresentativeImage = new QPixmap( QString(IMAGE_PATH)+"notSpecified.png" );
00055 largeRepresentativeImage = NULL;
00056
00057
00058 firstSubalbum = NULL;
00059 lastSubalbum = NULL;
00060
00061
00062 updateCreationDate();
00063
00064
00065 numSubalbums = 0;
00066 numLoadedSubalbums = 0;
00067
00068
00069 savedToDisk = false;
00070
00071
00072 modified = false;
00073
00074
00075 QDir rootDir( QDir::homeDirPath() );
00076 if(!rootDir.exists( ".albumShaper" ))
00077 {
00078 rootDir.mkdir( ".albumShaper" );
00079 }
00080 rootDir.cd( ".albumShaper" );
00081 if(!rootDir.exists( "tmp" ))
00082 {
00083 rootDir.mkdir( "tmp" );
00084 }
00085 saveLocation = QDir::homeDirPath() + "/.albumShaper/tmp";
00086 }
00087
00089 Album::~Album()
00090 {
00091
00092 delete smallRepresentativeImage;
00093 delete largeRepresentativeImage;
00094
00095
00096 Subalbum* current = firstSubalbum;
00097 Subalbum* temp;
00098 while(current != NULL)
00099 {
00100 temp = current->getNext();
00101 delete current;
00102 current = temp;
00103 }
00104 }
00105
00107 void Album::setName(QString val)
00108 {
00109 if(name != val)
00110 {
00111 name = val;
00112 modified = true;
00113 }
00114 }
00115
00117 QString Album::getName()
00118 {
00119 return QString(name);
00120 }
00121
00123 void Album::setDescription(QString val)
00124 {
00125 if(description != val)
00126 {
00127 description = val;
00128 modified = true;
00129 }
00130 }
00131
00133 QString Album::getDescription()
00134 {
00135 return QString(description);
00136 }
00137
00139 void Album::setAuthor(QString val)
00140 {
00141 if(author != val)
00142 {
00143 author = val;
00144 modified = true;
00145 }
00146 }
00147
00149 QString Album::getAuthor()
00150 {
00151 return QString(author);
00152 }
00153
00155 void Album::setRepresentativeImages(QImage* rawImage)
00156 {
00157
00158
00159 delete smallRepresentativeImage;
00160 delete largeRepresentativeImage;
00161
00162
00163 int smallRepWidth = 0;
00164 int smallRepHeight = 0;
00165 int largeRepWidth = 0;
00166 int largeRepHeight = 0;
00167 resizeImage( rawImage->width(), rawImage->height(),
00168 107, 80,
00169 smallRepWidth, smallRepHeight);
00170 resizeImage( rawImage->width(), rawImage->height(),
00171 500, 320,
00172 largeRepWidth, largeRepHeight);
00173
00174
00175
00176
00177 QImage thumbnailSmall = rawImage->smoothScale( smallRepWidth, smallRepHeight );
00178 thumbnailSmall.setAlphaBuffer(true);
00179 smallRepresentativeImage = new QPixmap( smallRepWidth, smallRepHeight );
00180 smallRepresentativeImage->convertFromImage( thumbnailSmall );
00181
00182
00183 QImage thumbnailLarge = rawImage->smoothScale( largeRepWidth, largeRepHeight );
00184 thumbnailLarge.setAlphaBuffer(true);
00185 largeRepresentativeImage = new QPixmap( largeRepWidth, largeRepHeight );
00186 largeRepresentativeImage->convertFromImage( thumbnailLarge );
00187
00188
00189 modified = true;
00190 }
00191
00193 QPixmap* Album::getRepresentativeImage(int size)
00194 {
00195 if(size == SMALL)
00196 return smallRepresentativeImage;
00197 else if(size == LARGE)
00198 return largeRepresentativeImage;
00199 else
00200 return NULL;
00201 }
00202
00204 Subalbum* Album::getFirstSubalbum()
00205 {
00206 return firstSubalbum;
00207 }
00208
00210 Subalbum* Album::getLastSubalbum()
00211 {
00212 return lastSubalbum;
00213 }
00214
00215 void Album::appendSubalbum(Subalbum* val)
00216 {
00217 numSubalbums++;
00218
00219
00220 if(firstSubalbum == NULL)
00221 {
00222 firstSubalbum = val;
00223 lastSubalbum = val;
00224 }
00225
00226 else
00227 {
00228 lastSubalbum->setNext( val );
00229 lastSubalbum = val;
00230 }
00231
00232
00233 modified = true;
00234 }
00235
00236 void Album::removeSubalbum(Subalbum* val)
00237 {
00238
00239 Subalbum* prev = NULL;
00240 Subalbum* current = firstSubalbum;
00241 while(current != NULL)
00242 {
00243
00244 if(current == val)
00245 {
00246
00247 if(firstSubalbum == val)
00248 firstSubalbum = val->getNext();
00249
00250
00251 if(lastSubalbum == val)
00252 lastSubalbum = prev;
00253
00254
00255 if(prev != NULL)
00256 prev->setNext( current->getNext() );
00257
00258
00259 delete val;
00260 val = NULL;
00261 numSubalbums--;
00262 return;
00263 }
00264
00265 prev = current;
00266 current = current->getNext();
00267 }
00268
00269
00270 modified = true;
00271 }
00272
00274 int Album::getModificationYear()
00275 {
00276 return modificationYear;
00277 }
00278
00280 int Album::getModificationMonth()
00281 {
00282 return modificationMonth;
00283 }
00284
00286 int Album::getModificationDay()
00287 {
00288 return modificationDay;
00289 }
00290
00292 void Album::updateCreationDate()
00293 {
00294
00295 QDate date = QDate::currentDate();
00296 creationYear = date.year();
00297 creationMonth = date.month();
00298 creationDay = date.day();
00299 }
00300
00302 void Album::updateModificationDate()
00303 {
00304
00305 QDate date = QDate::currentDate();
00306 modificationYear = date.year();
00307 modificationMonth = date.month();
00308 modificationDay = date.day();
00309 }
00310
00311 int Album::importFromDisk(StatusWidget* status, QString fileName)
00312 {
00313
00314 updateXML( QFileInfo(fileName).dirPath(TRUE) );
00315
00316
00317 QFile albumFile( fileName );
00318
00319
00320 if( !albumFile.open( IO_ReadOnly ) )
00321 return ALBUM_READ_ERROR;
00322
00323
00324 QDomDocument albumDom;
00325 if( !albumDom.setContent( &albumFile ) )
00326 return ALBUM_XML_ERROR;
00327
00328
00329 albumFile.close();
00330
00331
00332 QString rootDir = QFileInfo(albumFile).dirPath(TRUE);
00333 saveLocation = rootDir + "/img";
00334
00335
00336
00337 QImage repImage(rootDir + "/img/album.jpg");
00338 if(!repImage.isNull())
00339 {
00340 setRepresentativeImages(&repImage);
00341 }
00342
00343
00344 int numPhotos = 0;
00345 QDomElement root = albumDom.documentElement();
00346 QDomNode node = root.firstChild();
00347 while( !node.isNull() )
00348 {
00349 if( node.isElement() && node.nodeName() == "subalbum" )
00350 {
00351 QDomNode childNode = node.firstChild();
00352 while( !childNode.isNull() )
00353 {
00354 if( childNode.isElement() && childNode.nodeName() == "photo" )
00355 numPhotos++;
00356 childNode = childNode.nextSibling();
00357 }
00358 }
00359 node = node.nextSibling();
00360 }
00361
00362
00363 status->showProgressBar( "Loading:", numPhotos );
00364 qApp->processEvents();
00365
00366 int subalbumNum = 0;
00367
00368
00369 root = albumDom.documentElement();
00370 node = root.firstChild();
00371 QDomText val;
00372 while( !node.isNull() )
00373 {
00374
00375
00376 if( node.isElement() && node.nodeName() == "name" )
00377 {
00378 val = node.firstChild().toText();
00379 if(!val.isNull())
00380 name = val.nodeValue();
00381 }
00382
00383
00384 else if( node.isElement() && node.nodeName() == "description" )
00385 {
00386 val = node.firstChild().toText();
00387 if(!val.isNull())
00388 description = val.nodeValue();
00389 }
00390
00391
00392 else if( node.isElement() && node.nodeName() == "author" )
00393 {
00394 val = node.firstChild().toText();
00395 if(!val.isNull())
00396 author = val.nodeValue();
00397 }
00398
00399
00400 else if( node.isElement() && node.nodeName() == "theme" )
00401 {
00402 val = node.firstChild().toText();
00403 if(!val.isNull())
00404 theme = val.nodeValue();
00405 }
00406
00407
00408 else if( node.isElement() && node.nodeName() == "created" )
00409 {
00410 val = node.firstChild().toText();
00411
00412
00413 QStringList vals = QStringList::split( QRegExp(" "), val.nodeValue() );
00414 int i=0;
00415 int intVals[3];
00416 QStringList::Iterator it;
00417 for ( it = vals.begin(); it != vals.end(); ++it )
00418 {
00419 intVals[i] = QString(*it).toInt();
00420 i++;
00421
00422
00423 if(i > 2)
00424 break;
00425 }
00426 creationYear = intVals[0];
00427 creationMonth = intVals[1];
00428 creationDay = intVals[2];
00429 }
00430
00431
00432 else if( node.isElement() && node.nodeName() == "subalbum" )
00433 {
00434
00435 subalbumNum++;
00436
00437
00438 Subalbum* salbum = new Subalbum(this, numSubalbums+1);
00439
00440
00441 salbum->importFromDisk( &node, subalbumNum, status, (rootDir + "/") );
00442
00443
00444 appendSubalbum(salbum);
00445 }
00446
00447
00448 node = node.nextSibling();
00449
00450 }
00451
00452
00453 numLoadedSubalbums = numSubalbums;
00454
00455
00456 status->setStatus( "Album loaded." );
00457
00458
00459 saveLocation = rootDir;
00460 savedToDisk = true;
00461
00462 return ALBUM_LOADED;
00463 }
00464
00465 int Album::exportToDisk(StatusWidget* status,
00466 bool smallSave,
00467 QString dirName,
00468 QString themeName)
00469 {
00470
00471
00472 bool forceSave = true;
00473
00474 if(saveLocation == dirName)
00475 forceSave = false;
00476
00477 saveLocation = dirName;
00478 theme = themeName;
00479 return exportToDisk(status, smallSave, forceSave);
00480 }
00481
00482 int Album::exportToDisk(StatusWidget* status,
00483 bool smallSave,
00484 bool forceSave)
00485 {
00486
00487
00488 QDir localDir(saveLocation);
00489
00490 localDir.mkdir("img");
00491
00492 localDir.setPath(saveLocation + "/img");
00493 int i;
00494 for(i=1; i <= numSubalbums; i++)
00495 {
00496 QString dirName = QString("%1") .arg(i);
00497 localDir.mkdir(dirName);
00498 }
00499
00500
00501
00502
00503 int totalPhotos=0;
00504 Subalbum* current = firstSubalbum;
00505 while(current != NULL)
00506 {
00507 totalPhotos+=current->getNumPhotos();
00508 current = current->getNext();
00509 }
00510
00511
00512 status->showProgressBar( "Saving:", 3*totalPhotos );
00513 qApp->processEvents();
00514
00515
00516 exportThemeResources( theme );
00517
00518
00519 exportTopLevelImages();
00520
00521
00522 exportSubalbumImages(status, smallSave, forceSave);
00523
00524
00525 reorderSubalbumImages(status);
00526
00527
00528 removeStagnantImages();
00529
00530
00531 localDir.setPath(saveLocation);
00532 QStringList list = localDir.entryList( QDir::Files );
00533 QStringList::Iterator file;
00534 for ( file = list.begin(); file != list.end(); ++file )
00535 {
00536 if((*file).endsWith(".html"))
00537 localDir.remove( saveLocation + "/" + *file );
00538 }
00539
00540
00541 if(!smallSave)
00542 {
00543 int result = exportToXML();
00544 if(result != ALBUM_EXPORTED)
00545 return result;
00546 }
00547
00548
00549 transformXMLtoHTML( saveLocation, theme );
00550
00551
00552
00553 QDir tmpDir(QDir::homeDirPath() + "/.albumShaper/tmp" );
00554 QStringList strLst = tmpDir.entryList();
00555 QStringList::iterator it;
00556 for(it = strLst.begin(); it != strLst.end(); it++)
00557 {
00558 tmpDir.remove(*it);
00559 }
00560
00561 savedToDisk = true;
00562
00563
00564 modified = false;
00565
00566
00567 status->setStatus( "Album saved." );
00568
00569 return ALBUM_EXPORTED;
00570 }
00571
00572 int Album::exportToXML()
00573 {
00574
00575 updateModificationDate();
00576
00577
00578 QFile* xml = new QFile(saveLocation + "/Album.xml");
00579 if(xml->open(IO_WriteOnly))
00580 {
00581 QTextStream stream( xml );
00582
00583
00584 stream << "<?xml version=\"1.0\"?>\n";
00585 stream << "<album version=\"1.1\">\n";
00586 stream << " <name>" << fixXMLString(name) << "</name>\n";
00587 stream << " <description>" << fixXMLString(description) << "</description>\n";
00588 stream << " <author>" << fixXMLString(author) << "</author>\n";
00589 stream << " <created>" << creationYear << " " << creationMonth << " " << creationDay << "</created>\n";
00590 stream << " <modified>" << modificationYear << " " << modificationMonth << " " << modificationDay << "</modified>\n";
00591 stream << " <theme>" << theme << "</theme>\n";
00592 stream << " <thumbnailDimensions>" << THUMBNAIL_WIDTH << " " << THUMBNAIL_HEIGHT << "</thumbnailDimensions>\n";
00593 stream << " <slideshowDimensions>" << SLIDESHOW_WIDTH << " " << SLIDESHOW_HEIGHT << "</slideshowDimensions>\n";
00594
00595
00596 if(getRepresentativeImage(LARGE) != NULL )
00597 {
00598 stream << " <thumb path=\"img/album.jpg\"/>\n";
00599 }
00600
00601
00602 Subalbum* current = firstSubalbum;
00603 while(current != NULL)
00604 {
00605 current->exportToXML(stream);
00606 current = current->getNext();
00607 }
00608
00609
00610 stream << "</album>\n";
00611 xml->close();
00612
00613 return ALBUM_EXPORTED;
00614 }
00615 else
00616 {
00617 return ALBUM_ERROR_OPEN_FILE;
00618 }
00619 }
00620
00621 void Album::exportTopLevelImages()
00622 {
00623
00624 if(getRepresentativeImage(LARGE) != NULL)
00625 {
00626 getRepresentativeImage(LARGE)->save(saveLocation + "/img/album.jpg", "JPEG", 100);
00627 }
00628
00629 else
00630 {
00631 QDir rootDir(saveLocation + "/img/");
00632 rootDir.remove("album.jpg");
00633 }
00634
00635
00636 int n=0;
00637 Subalbum* current = firstSubalbum;
00638 while(current != NULL)
00639 {
00640 n++;
00641
00642 if(current->getRepresentativeImage(LARGE) != NULL )
00643 {
00644 QString fileName = QString(saveLocation + "/img/%1_thumb.jpg" ).arg(n);
00645 current->getRepresentativeImage(LARGE)->save(fileName, "JPEG", 100);
00646 }
00647
00648 else
00649 {
00650 QDir rootDir(saveLocation + "/img/");
00651 rootDir.remove( QString("%1_thumb.jpg").arg(n) );
00652 }
00653 current = current->getNext();
00654 }
00655 }
00656
00657 void Album::exportSubalbumImages(StatusWidget* status, bool smallSave, bool forceSave)
00658 {
00659
00660 int subalbumNumber=0;
00661 Subalbum* currentSubalbum = firstSubalbum;
00662 while(currentSubalbum != NULL)
00663 {
00664 subalbumNumber++;
00665
00666
00667 int photoNumber=0;
00668 Photo* currentPhoto = currentSubalbum->getFirst();
00669 while(currentPhoto != NULL)
00670 {
00671 photoNumber++;
00672
00673
00674 if( !forceSave && !currentPhoto->getNeedsSavingVal() )
00675 {
00676 currentPhoto = currentPhoto->getNext();
00677 status->incrementProgress();
00678 qApp->processEvents();
00679 continue;
00680 }
00681
00682
00683 QDir rootDir;
00684
00685
00686 int initPhotoNumber = currentPhoto->getInitialPhotoNumber();
00687 int initSubalbumNumber = currentPhoto->getInitialSubalbumNumber();
00688
00689
00690 QString fileName = QString(saveLocation + "/img/%1/%2_thumb.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00691 currentPhoto->getImage(THUMBNAIL)->save(fileName, "JPEG", 100);
00692
00693
00694 std::ifstream thumbnailFile(fileName.ascii());
00695 if(thumbnailFile.is_open())
00696 {
00697 currentPhoto->setThumbnailChecksum( getMD5(thumbnailFile) );
00698 thumbnailFile.close();
00699 }
00700
00701
00702 QString oldName = currentPhoto->getSlideshowFilename();
00703 QString newName = QString(saveLocation + "/img/%1/%2_slideshow.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00704
00705
00706 if( currentPhoto->getNeedsSavingVal() )
00707 {
00708
00709 if(!rootDir.rename( oldName, newName))
00710 {
00711 copyFile(oldName, newName);
00712 rootDir.remove(oldName);
00713 }
00714 }
00715
00716
00717 else
00718 {
00719 copyFile(oldName, newName);
00720 }
00721
00722
00723 std::ifstream file(newName.ascii());
00724 if(file.is_open())
00725 {
00726 currentPhoto->setSlideshowChecksum( getMD5(file) );
00727 file.close();
00728 }
00729
00730
00731 if(!smallSave)
00732 {
00733 oldName = currentPhoto->getImageFilename();
00734 newName = QString(saveLocation + "/img/%1/%2.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00735
00736
00737 if( currentPhoto->getNeedsSavingVal() )
00738 {
00739
00740 if(!rootDir.rename( oldName, newName))
00741 {
00742 copyFile(oldName, newName);
00743 rootDir.remove(oldName);
00744 }
00745 }
00746
00747
00748 else
00749 {
00750 copyFile(oldName, newName);
00751 }
00752
00753
00754 std::ifstream imageFile(newName.ascii());
00755 if(imageFile.is_open())
00756 {
00757 currentPhoto->setImageChecksum( getMD5(imageFile) );
00758 imageFile.close();
00759 }
00760 }
00761
00762
00763 if(!smallSave)
00764 {
00765 currentPhoto->setImageFilename( QString(saveLocation + "/img/%1/%2.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
00766 currentPhoto->setSlideshowFilename( QString(saveLocation + "/img/%1/%2_slideshow.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
00767 currentPhoto->setThumbnailFilename( QString(saveLocation + "/img/%1/%2_thumb.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
00768 }
00769
00770
00771 if(!smallSave)
00772 currentPhoto->setNeedsSavingVal(false);
00773
00774
00775 status->incrementProgress();
00776 qApp->processEvents();
00777
00778
00779 currentPhoto = currentPhoto->getNext();
00780
00781 }
00782
00783
00784 currentSubalbum = currentSubalbum->getNext();
00785 }
00786 }
00787
00788 void Album::reorderSubalbumImages(StatusWidget* status)
00789 {
00790
00791
00792
00793
00794
00795
00796
00797 int subalbumNumber=0;
00798 Subalbum* currentSubalbum = firstSubalbum;
00799 while(currentSubalbum != NULL)
00800 {
00801 subalbumNumber++;
00802
00803
00804 int photoNumber=0;
00805 Photo* currentPhoto = currentSubalbum->getFirst();
00806 while(currentPhoto != NULL)
00807 {
00808 photoNumber++;
00809
00810
00811 int initPhotoNumber = currentPhoto->getInitialPhotoNumber();
00812 int initSubalbumNumber = currentPhoto->getInitialSubalbumNumber();
00813
00814
00815 if( initPhotoNumber == photoNumber &&
00816 initSubalbumNumber == subalbumNumber)
00817 {
00818 currentPhoto = currentPhoto->getNext();
00819 status->incrementProgress();
00820 qApp->processEvents();
00821 continue;
00822 }
00823
00824
00825 QDir rootDir;
00826 QString oldName = QString(saveLocation + "/img/%1/%2.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00827 QString newName = QString(saveLocation + "/img/%1/%2_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00828 if(!rootDir.rename( oldName, newName))
00829 {
00830 copyFile(oldName, newName);
00831 rootDir.remove( oldName );
00832 }
00833
00834 oldName = QString(saveLocation + "/img/%1/%2_slideshow.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00835 newName = QString(saveLocation + "/img/%1/%2_slideshow_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00836 if(!rootDir.rename( oldName, newName))
00837 {
00838 copyFile(oldName, newName);
00839 rootDir.remove( oldName );
00840 }
00841
00842 oldName = QString(saveLocation + "/img/%1/%2_thumb.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00843 newName = QString(saveLocation + "/img/%1/%2_thumb_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00844 if(!rootDir.rename( oldName, newName))
00845 {
00846 copyFile(oldName, newName);
00847 rootDir.remove( oldName );
00848 }
00849
00850
00851 status->incrementProgress();
00852 qApp->processEvents();
00853
00854
00855 currentPhoto = currentPhoto->getNext();
00856
00857 }
00858
00859
00860 currentSubalbum = currentSubalbum->getNext();
00861 }
00862
00863
00864
00865
00866
00867
00868
00869
00870 subalbumNumber=0;
00871 currentSubalbum = firstSubalbum;
00872 while(currentSubalbum != NULL)
00873 {
00874 subalbumNumber++;
00875
00876
00877 int photoNumber=0;
00878 Photo* currentPhoto = currentSubalbum->getFirst();
00879 while(currentPhoto != NULL)
00880 {
00881 photoNumber++;
00882
00883
00884 int initPhotoNumber = currentPhoto->getInitialPhotoNumber();
00885 int initSubalbumNumber = currentPhoto->getInitialSubalbumNumber();
00886
00887
00888 if( initPhotoNumber == photoNumber &&
00889 initSubalbumNumber == subalbumNumber)
00890 {
00891 currentPhoto = currentPhoto->getNext();
00892 status->incrementProgress();
00893 qApp->processEvents();
00894 continue;
00895 }
00896
00897
00898 QDir rootDir;
00899 QString oldName = QString(saveLocation + "/img/%1/%2_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00900 QString newName = QString(saveLocation + "/img/%1/%2.jpg" ).arg(subalbumNumber).arg(photoNumber);
00901 if(!rootDir.rename( oldName, newName))
00902 {
00903 copyFile(oldName, newName);
00904 rootDir.remove( oldName );
00905 }
00906
00907 oldName = QString(saveLocation + "/img/%1/%2_slideshow_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00908 newName = QString(saveLocation + "/img/%1/%2_slideshow.jpg" ).arg(subalbumNumber).arg(photoNumber);
00909 if(!rootDir.rename( oldName, newName))
00910 {
00911 copyFile(oldName, newName);
00912 rootDir.remove( oldName );
00913 }
00914
00915 oldName = QString(saveLocation + "/img/%1/%2_thumb_moved.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);
00916 newName = QString(saveLocation + "/img/%1/%2_thumb.jpg" ).arg(subalbumNumber).arg(photoNumber);
00917 if(!rootDir.rename( oldName, newName))
00918 {
00919 copyFile(oldName, newName);
00920 rootDir.remove( oldName );
00921 }
00922
00923
00924 currentPhoto->setInitialPhotoNumber(photoNumber);
00925 currentPhoto->setInitialSubalbumNumber(subalbumNumber);
00926 currentPhoto->setImageFilename( QString(saveLocation + "/img/%1/%2.jpg").arg(subalbumNumber).arg(photoNumber) );
00927 currentPhoto->setSlideshowFilename( QString(saveLocation + "/img/%1/%2_slideshow.jpg").arg(subalbumNumber).arg(photoNumber) );
00928 currentPhoto->setThumbnailFilename( QString(saveLocation + "/img/%1/%2_thumb.jpg").arg(subalbumNumber).arg(photoNumber) );
00929
00930
00931 status->incrementProgress();
00932 qApp->processEvents();
00933
00934
00935 currentPhoto = currentPhoto->getNext();
00936
00937 }
00938
00939
00940 currentSubalbum = currentSubalbum->getNext();
00941 }
00942 }
00943
00944 void Album::removeStagnantImages()
00945 {
00946 QDir rootDir(saveLocation + "/img/");
00947
00948
00949 int subalbumNumber=0;
00950 Subalbum* currentSubalbum = firstSubalbum;
00951 while(currentSubalbum != NULL)
00952 {
00953 subalbumNumber++;
00954
00955 int i;
00956 for(i=currentSubalbum->getNumPhotos() + 1;
00957 i <= currentSubalbum->getNumLoadedPhotos();
00958 i++)
00959 {
00960 QString thumbString = QString(saveLocation + "/img/%1/%2_thumb.jpg" ).arg(subalbumNumber).arg(i);
00961 QString slideshowString = QString(saveLocation + "/img/%1/%2_slideshow.jpg" ).arg(subalbumNumber).arg(i);
00962 QString imageString = QString(saveLocation + "/img/%1/%2.jpg" ).arg(subalbumNumber).arg(i);
00963 rootDir.remove(thumbString);
00964 rootDir.remove(slideshowString);
00965 rootDir.remove(imageString);
00966 }
00967
00968
00969 currentSubalbum->resetNumLoadedPhotos();
00970
00971
00972 currentSubalbum = currentSubalbum->getNext();
00973 }
00974
00975
00976 int i;
00977 for(i=numSubalbums+1; i<=numLoadedSubalbums; i++)
00978 {
00979
00980 QDir imageDir( QString(saveLocation + "/img/%1/").arg(i) );
00981 QStringList list = imageDir.entryList( QDir::Files );
00982
00983
00984 QStringList::Iterator file;
00985 for ( file = list.begin(); file != list.end(); ++file )
00986 {
00987 rootDir.remove( QString(saveLocation + "/img/%1/" + *file).arg(i) );
00988 }
00989
00990
00991 rootDir.rmdir( QString("%1").arg(i) );
00992
00993
00994 rootDir.remove( QString(saveLocation + "/img/%1_thumb.jpg").arg(i) );
00995
00996
00997 rootDir.remove( QString(saveLocation + "/subalbum_%1_thumbs.html").arg(i) );
00998 rootDir.remove( QString(saveLocation + "/subalbum_%1_slideshow.html").arg(i) );
00999 }
01000
01001
01002 numLoadedSubalbums = numSubalbums;
01003
01004 }
01005
01006 void Album::exportThemeResources( QString theme )
01007 {
01008
01009 QDir localDir(saveLocation);
01010 localDir.mkdir("resources");
01011 localDir.setPath(saveLocation + "/resources");
01012
01013
01014 QStringList list = localDir.entryList( QDir::Files );
01015 QStringList::Iterator file;
01016 for ( file = list.begin(); file != list.end(); ++file )
01017 {
01018 localDir.remove( saveLocation + "/resources/" + *file );
01019 }
01020
01021
01022 localDir.setPath(THEMES_PATH + theme + "/resources");
01023 list = localDir.entryList( QDir::Files );
01024 for ( file = list.begin(); file != list.end(); ++file )
01025 {
01026 copyFile( THEMES_PATH + theme + "/resources/" + *file,
01027 saveLocation + "/resources/" + *file);
01028 }
01029 }
01030
01031 bool Album::prevSave()
01032 {
01033 return savedToDisk;
01034 }
01035
01036 bool Album::albumModified()
01037 {
01038 return modified;
01039 }
01040
01041 void Album::syncSubalbumList(SubalbumPreviewWidget* item)
01042 {
01043
01044 if(item == NULL)
01045 {
01046 firstSubalbum = NULL;
01047 lastSubalbum = NULL;
01048 return;
01049 }
01050
01051
01052 firstSubalbum = item->getSubalbum();
01053 firstSubalbum->setNext(NULL);
01054 lastSubalbum = firstSubalbum;
01055
01056
01057 while(item->nextItem() != NULL)
01058 {
01059 item->getSubalbum()->setNext( ((SubalbumPreviewWidget*)item->nextItem())->getSubalbum() );
01060 item = (SubalbumPreviewWidget*)item->nextItem();
01061 lastSubalbum = item->getSubalbum();
01062 lastSubalbum->setNext(NULL);
01063 }
01064 }
01065
01066 QString Album::getSaveLocation()
01067 {
01068 return saveLocation;
01069 }
01070
01071 int Album::getNumSubalbums()
01072 {
01073 return numSubalbums;
01074 }
01075
01076 QString Album::getTheme()
01077 {
01078 return QString(theme);
01079 }
01080
01081 void Album::setModified(bool val)
01082 {
01083 modified = val;
01084 }
01085