Main Page   Compound List   File List   Compound Members   File Members  

subalbum.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003 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 //  As a special exception, Will Stokes gives permission to 
00011 //  link this program with Qt non-commercial edition, and 
00012 //  distribute the resulting executable, without including the 
00013 //  source code for the Qt non-commercial edition in the 
00014 //  source distribution. 
00015 //==============================================
00016 
00017 //Systemwide includes
00018 #include <qimage.h>
00019 #include <qpixmap.h>
00020 #include <qstring.h>
00021 #include <qtextstream.h>
00022 #include <qdom.h>
00023 #include <fstream.h>
00024 #include <qdir.h>
00025 #include <qregexp.h>
00026 
00027 //Projectwide includes
00028 #include "album.h"
00029 #include "subalbum.h"
00030 #include "photo.h"
00031 #include "imageTools.h"
00032 #include "xmlTools.h"
00033 #include "md5.h"
00034 #include "../gui/photoWidget.h"
00035 #include "../gui/loadDialog.h"
00036 #include "../config.h"
00037 
00038 #include <iostream.h>
00039 
00040 //==============================================
00042 Subalbum::Subalbum(Album* albm, int number)
00043 {
00044   //set subalbum number
00045   this->number = number;
00046 
00047   //by default no photos in subalbum
00048   numPhotos = 0;
00049   loadedPhotos = 0;
00050   
00051   //set strings to default values
00052   name = "";
00053   description ="";
00054 
00055   //set default rep images
00056   smallRepresentativeImage = new QPixmap( QString(IMAGE_PATH)+"notSpecified.png" );
00057   mediumRepresentativeImage = new QPixmap( QString(IMAGE_PATH)+"subalbum.png" );
00058   largeRepresentativeImage = NULL;
00059 
00060   //no photos by default
00061   firstPhoto = NULL;
00062   lastPhoto = NULL;
00063   
00064   //next pointer null by default
00065   nextSubalbum = NULL;
00066   
00067   //set album pointer
00068   this->albm = albm;
00069 }
00070 //==============================================
00072 Subalbum::~Subalbum()
00073 {
00074   //delete representative images
00075   delete smallRepresentativeImage;
00076   delete mediumRepresentativeImage;
00077   delete largeRepresentativeImage;
00078   
00079   //delete all photos
00080   Photo* current = firstPhoto;
00081   Photo* temp;
00082   while(current != NULL)
00083   {
00084     temp = current->getNext();
00085     delete current;
00086     current = temp;
00087   }
00088 } 
00089 //==============================================
00091 void Subalbum::setName(QString val)
00092 {
00093   name = val;
00094 }
00095 //==============================================
00097 QString Subalbum::getName()
00098 {
00099   return QString(name);
00100 }
00101 //==============================================
00103 void Subalbum::setDescription(QString val)
00104 {
00105   description = val;
00106 }
00107 //==============================================
00109 QString Subalbum::getDescription()
00110 {
00111   return QString(description);
00112 }
00113 //==============================================
00114 //gets a sized representative image  
00115 QPixmap* Subalbum::getRepresentativeImage(int size)
00116 {
00117   if(size == SMALL)
00118     return smallRepresentativeImage;
00119   if(size == MEDIUM)
00120     return mediumRepresentativeImage;
00121   if(size == LARGE)
00122     return largeRepresentativeImage;
00123   else
00124     return NULL;
00125 }
00126 //==============================================
00127 //sets a sized representative iamge
00128 void Subalbum::setRepresentativeImages(QImage* rawThumbnail)
00129 {
00130   //---------------------------------------------------------    
00131   //delete old representative images
00132   delete smallRepresentativeImage;
00133   delete mediumRepresentativeImage;
00134   delete largeRepresentativeImage;
00135   //---------------------------------------------------------    
00136   //compute various representative image sizes
00137   int smallRepWidth = 0;
00138   int smallRepHeight = 0;
00139   int mediumRepWidth = 0;
00140   int mediumRepHeight = 0;  
00141   resizeImage( rawThumbnail->width(), rawThumbnail->height(),
00142                131, 98,
00143                mediumRepWidth, mediumRepHeight);
00144   resizeImage( rawThumbnail->width(), rawThumbnail->height(),
00145                107, 80,
00146                smallRepWidth, smallRepHeight);
00147   //---------------------------------------------------------    
00148   //create various representative images
00149   //---------------------------------------------------------    
00150   //copy and scale small version
00151   QImage thumbnailSmall = rawThumbnail->smoothScale( smallRepWidth, smallRepHeight );
00152   smallRepresentativeImage = new QPixmap( smallRepWidth, smallRepHeight );
00153   smallRepresentativeImage->convertFromImage( thumbnailSmall );  
00154   
00155   //copy and scale medium version
00156   QImage thumbnailMedium = rawThumbnail->smoothScale( mediumRepWidth, mediumRepHeight );
00157   QImage* centeredThumbnailMedium = new QImage(131, 98, thumbnailMedium.depth());
00158   centeredThumbnailMedium->setAlphaBuffer(true);
00159  
00160   int xDiff = 131 - mediumRepWidth;
00161   int yDiff = 98  - mediumRepHeight;
00162   
00163   //set all pixels to white
00164   int x, y;
00165   for(x=0; x< 131; x++)
00166   {
00167     for(y=0; y<98; y++)
00168     {
00169       centeredThumbnailMedium->setPixel(x, y, QColor(255, 255, 255).rgb()); 
00170     }
00171   }
00172   
00173   int x2 = 0;
00174   for(x= xDiff/2; x < (xDiff/2) + mediumRepWidth; x++)
00175   {
00176     int y2 = 0;
00177     for(y= yDiff/2; y < (yDiff/2) + mediumRepHeight; y++)
00178     {
00179       centeredThumbnailMedium->setPixel(x, y, thumbnailMedium.pixel(x2, y2));
00180       y2++;
00181     }
00182     x2++;
00183   }
00184   
00185   mediumRepresentativeImage = new QPixmap( centeredThumbnailMedium->width(), centeredThumbnailMedium->height() );
00186   mediumRepresentativeImage->convertFromImage( *centeredThumbnailMedium );
00187   delete centeredThumbnailMedium;
00188   //copy large version 
00189   largeRepresentativeImage = new QPixmap(*rawThumbnail);
00190   //---------------------------------------------------------    
00191 }
00192 //==============================================
00194 bool Subalbum::addPhoto(QString fileName, Photo* newPhoto)
00195 {
00196   numPhotos++;
00197   
00198   //create new photo if necessary
00199   if(newPhoto == NULL)
00200     newPhoto = new Photo(this, numPhotos);
00201     
00202   QString desc(fileName);  
00203   desc = desc.section( QRegExp("/"), -1);
00204   desc.truncate(desc.length() - 4);
00205   newPhoto->setDescription( desc );
00206   
00207   //attempt to set image
00208   if(!newPhoto->setImage(fileName))
00209   {
00210     cout << "Error! Unable to load " << fileName << endl;
00211     delete newPhoto;
00212     return false;
00213   }
00214   
00215   //if this is the only photo, set first and last 
00216   //pointers to this photo.
00217   if(firstPhoto == NULL)
00218   {
00219     firstPhoto = newPhoto;
00220     lastPhoto = newPhoto;
00221   }
00222   //else append to end of list
00223   else
00224   {
00225     lastPhoto->setNext(newPhoto);
00226     lastPhoto = newPhoto;
00227   }
00228   
00229   //copy image file over
00230   QString saveName = QDir::homeDirPath() + QString("/.albumShaper/tmp/%1_%2")
00231                                 .arg(number)
00232                                 .arg(numPhotos);
00233   
00234   newPhoto->getImage(IMAGE)->save( saveName + ".jpg", "JPEG", 100);
00235   newPhoto->getImage(SLIDESHOW)->save( saveName + "_slideshow.jpg", "JPEG", 100);
00236   
00237   newPhoto->setImageFilename(saveName + ".jpg");
00238   newPhoto->setSlideshowFilename(saveName + "_slideshow.jpg");
00239   
00240   //deallocate full image and slideshow versions to conserve memory
00241   newPhoto->deallocateLargeImages();
00242   
00243   return true;
00244 }
00245 //==============================================
00246 bool Subalbum::lazyAddPhoto(QString imageName, 
00247                                           QString slideshowName, 
00248                                           QString thumbnailName, 
00249                                           Photo* newPhoto)
00250 {
00251   numPhotos++;
00252   
00253   //attempt to set image
00254   if(!newPhoto->setImage(imageName, slideshowName, thumbnailName))
00255   {
00256     cout << "Error! Unable to load " << imageName << endl;
00257     delete newPhoto;
00258     return false;
00259   }
00260   
00261   //if this is the only photo, set first and last 
00262   //pointers to this photo.
00263   if(firstPhoto == NULL)
00264   {
00265     firstPhoto = newPhoto;
00266     lastPhoto = newPhoto;
00267   }
00268   //else append to end of list
00269   else
00270   {
00271     lastPhoto->setNext(newPhoto);
00272     lastPhoto = newPhoto;
00273   }
00274   
00275   return true;
00276 }
00277 //==============================================
00279 void Subalbum::removePhoto(Photo* val)
00280 { 
00281   //walk through list of photos and find specified photo
00282   Photo* current = firstPhoto;
00283   Photo* prev = NULL;
00284   while(current != val && current->getNext() != NULL)
00285   {
00286     prev = current;
00287     current = current->getNext();
00288   }
00289 
00290   if(current == val)
00291   {
00292     //update prev next pointer
00293     if(prev != NULL)
00294       prev->setNext(current->getNext());
00295     
00296     //update first and last pointers if necessary
00297     if(current == firstPhoto)
00298       firstPhoto = current->getNext();
00299     if(current == lastPhoto)
00300       lastPhoto = prev;
00301 
00302     //free Photo
00303     delete current;
00304     current = NULL;
00305     numPhotos--;
00306   }
00307 }
00308 //==============================================
00309 Subalbum* Subalbum::getNext()
00310 {
00311   return nextSubalbum;
00312 }
00313 //==============================================
00314 void Subalbum::setNext(Subalbum* val)
00315 {
00316   nextSubalbum = val;
00317 }
00318 //==============================================
00319 void Subalbum::exportToXML(QTextStream& stream)
00320 {
00321   //write subalbum information
00322   stream << "  <subalbum>\n";
00323   stream << "    <name>" << fixXMLString(name) << "</name>\n";
00324   stream << "    <description>" << fixXMLString(description) << "</description>\n";
00325   
00326   //write photos
00327   Photo* current = firstPhoto;
00328   while(current != NULL)
00329   {
00330     current->exportToXML(stream);
00331     current = current->getNext();
00332   }  
00333   
00334   //close subalbum
00335   stream << "  </subalbum>\n";
00336 
00337 }
00338 //==============================================
00339 void Subalbum::exportThumbnailHTML(QTextStream& stream, int subalbumNumber)
00340 {
00341   stream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";    
00342   stream << "<html>\n";
00343   stream << "  <head>\n";
00344   stream << "    <style type=\"text/html\">\n";
00345   stream << "      <!--\n";
00346   stream << "      A{text-decoration:none}\n";
00347   stream << "      -->\n";
00348   stream << "    </style>\n";
00349   stream << "    <style type=\"text/css\">\n";
00350   stream << "     <!--\n";
00351   stream << "     h3 {font-size: 12pt; font-weight: bold; text-align: center}\n";
00352   stream << "     h4 {font-size: 10pt; font-weight: normal; text-align: center}\n";
00353   stream << "     h4.ital {font-size: 10pt; font-weight: normal; text-align: center}\n";
00354   stream << "      -->\n";
00355   stream << "    </style>\n";    
00356   stream << "    <title>" << name << "</title>\n";
00357   stream << "    <meta name=\"generator\" ";
00358   stream << "content=\"Album Shaper (c.) Will Stokes\">\n";
00359   stream << "  </head>\n";
00360   stream << "  <body>\n";
00361   stream << "    <center>\n";
00362   stream << "      <table>\n";
00363   stream << "        <tr>\n";
00364   stream << "          <td width=\"450\">\n";
00365   stream << "            <h3>\n";
00366   stream << "              " << name << "\n";
00367   stream << "           </h3>\n";
00368   stream << "           <h4>\n";
00369   stream << "             " << description << "\n";
00370   stream << "           </h4>\n";
00371   stream << "          </td>\n";
00372   stream << "        </tr>\n";
00373   stream << "      </table>\n";
00374   stream << "    </center>\n";
00375   stream << "    <h4>\n";
00376   stream << "    <script type=\"text/javascript\" language=\"JavaScript\">\n";
00377   stream << "    <!-- HIDE FROM OLD BROWSERS\n";
00378   stream << "    document.write(\"<a href=\\\"subalbum_" << subalbumNumber << "_slideshow.html\\\">Begin Slide Show</a>\")\n";
00379   stream << "    document.write(\"&nbsp;-&nbsp;\")\n";
00380   stream << "    -->\n";
00381   stream << "    </script>\n";
00382   stream << "      <a href=\"Album.html\">\n";
00383   stream << "        Album Index\n";
00384   stream << "      </a>\n";
00385   stream << "    </h4>\n";
00386     
00387   int photoNumber = 0;
00388     
00389   //write photo thumbnails
00390   Photo* current = firstPhoto;
00391   if(current != NULL)
00392   {
00393     stream << "    <center>\n";
00394     stream << "      <table border=\"0\">\n";
00395     while(current != NULL)
00396     {
00397       Photo* backupCurrent = current;
00398       int backupNumber = photoNumber;
00399       //---------------------------------------
00400       //Print row of images
00401       //---------------------------------------
00402       int n = 3;
00403       stream << "        <tr>\n";
00404       while(current != NULL && n > 0)
00405       {
00406         n--;
00407         photoNumber++;
00408         stream << "          <td valign=\"bottom\" width=\"220\">\n";
00409         stream << "           <center>\n";
00410         stream << "            <a href=\"img/" << subalbumNumber << "/" << photoNumber << ".jpg\">\n";
00411         stream << "             <img alt=\"" << current->getDescription() << "\" src=\"img/" << subalbumNumber << "/" << photoNumber << "_thumb.jpg\">\n";
00412         stream << "            </a>\n";
00413         stream << "           </center>\n";
00414         stream << "          </td>\n";
00415         current = current->getNext();
00416       }
00417       
00418       while(n != 0 && photoNumber > 2)
00419       {
00420         stream << "          <td width=\"220\"></td>\n";
00421         n--;
00422       }
00423       stream << "        </tr>\n";
00424       //---------------------------------------
00425       //Print row of image descriptions
00426       //---------------------------------------
00427       current = backupCurrent;
00428       photoNumber = backupNumber;
00429       n = 3;
00430       stream << "        <tr>\n";
00431       while(current != NULL && n > 0)
00432       {
00433         n--;
00434         photoNumber++;
00435         stream << "          <td valign=\"top\" width=\"220\">\n";
00436         stream << "           <center>\n";
00437         stream << "             <a href=\"img/" << subalbumNumber << "/" << photoNumber << ".jpg\">\n";
00438         stream << "               " << current->getDescription() << "\n";
00439         stream << "            </a>\n";
00440         stream << "           </center>\n";
00441         stream << "          </td>\n";
00442         current = current->getNext();
00443       }
00444       
00445       while(n != 0 && photoNumber > 2)
00446       {
00447         stream << "          <td width=\"220\"></td>\n";
00448         n--;
00449       }
00450       stream << "        </tr>\n";
00451     }
00452       
00453     stream << "      </table>\n";
00454     stream << "    </center>\n";
00455   } //end if
00456   
00457   stream << "    <h4 class=\"ital\">\n";
00458   stream << "      (Generated by <a href=\"http://albumshaper.sourceforge.net\">Album Shaper</a>)\n";
00459   stream << "    </h4>\n";
00460   stream << "  </body>\n";
00461   stream << "</html>\n";
00462 }
00463 //==============================================
00464 void Subalbum::exportSlideshowHTML(QTextStream& stream, int subalbumNumber)
00465 {
00466   stream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";    
00467   stream << "<html>\n";
00468   stream << "  <head>\n";
00469   stream << "    <style type=\"text/html\">\n";
00470   stream << "      <!--\n";
00471   stream << "      A{text-decoration:none}\n";
00472   stream << "      -->\n";
00473   stream << "    </style>\n";
00474   stream << "    <style type=\"text/css\">\n";
00475   stream << "     <!--\n";
00476   stream << "     h3 {font-size: 12pt; font-weight: bold; text-align: center}\n";
00477   stream << "     h4 {font-size: 10pt; font-weight: normal; text-align: center}\n";
00478   stream << "     h4.ital {font-size: 10pt; font-weight: normal; text-align: center}\n";
00479   stream << "      -->\n";
00480   stream << "    </style>\n";    
00481   stream << "    <title>" << name << "</title>\n";
00482   stream << "    <meta name=\"generator\" content=\"Album Shaper (c.) Will Stokes\">\n";
00483   stream << "    <script type=\"text/javascript\" language=\"JavaScript\">\n"; 
00484   stream << "    <!-- HIDE FROM OLD BROWSERS\n";
00485   stream << "    var imageNumber=1\n\n"; 
00486   stream << "    var photoTitles = new Array(" << numPhotos << ");\n";
00487   
00488   Photo* current = firstPhoto;
00489   int n = 0;
00490   while(current != NULL)
00491   {
00492     stream << "    photoTitles[" << n << "] = \"" << current->getDescription() << "\";\n";
00493     n++;
00494     current = current->getNext();
00495   }
00496   
00497   stream << "    //###################################### \n";
00498   stream << "    //Define functions used to change images \n";
00499   stream << "    //###################################### \n";
00500   stream << "    function expandImage() \n";
00501   stream << "    { \n";
00502   stream << "      fileToOpen = \"img/" << subalbumNumber << "/\"+imageNumber+\".jpg\" \n";
00503   stream << "      new_window = window.open(fileToOpen,'albulmifyRules') \n";
00504   stream << "    } \n\n";
00505   stream << "    function reloadImage() \n";
00506   stream << "    { \n";
00507   stream << "      document.currentPhoto.src=\"img/" << subalbumNumber << "/\"+imageNumber+\"_slideshow.jpg\"\n";
00508   stream << "      document.currentPhoto.alt=photoTitles[imageNumber-1];\n";
00509   stream << "      document.photoInfo.whichPhoto.value=\"Photo \" + imageNumber + \" of " << numPhotos << "\"\n";
00510   stream << "      document.photoInfo.photoDesc.value=photoTitles[imageNumber-1];\n";
00511   stream << "    } \n\n";
00512   stream << "    function firstImage() \n";
00513   stream << "    { \n";
00514   stream << "      //set image number to first \n";
00515   stream << "      imageNumber = 1 \n\n";
00516   stream << "      //reset image src value based on variable \n";
00517   stream << "      reloadImage() \n";
00518   stream << "    } \n\n";
00519   stream << "    function lastImage() \n";
00520   stream << "    { \n";
00521   stream << "      //set image number to last \n";
00522   stream << "      imageNumber = " << numPhotos << "\n\n";
00523   stream << "      //reset image src value based on variable \n";
00524   stream << "      reloadImage() \n";
00525   stream << "    } \n\n";
00526   stream << "    function nextImage() \n";
00527   stream << "    { \n";
00528   stream << "      //increment image number \n";
00529   stream << "      imageNumber = imageNumber + 1 \n\n";
00530   stream << "      //wrap to begining if reached the end \n";
00531   stream << "      if (imageNumber==" << (numPhotos+1) << ") \n";
00532   stream << "      {imageNumber = 1} \n\n";
00533   stream << "      //reset image src value based on variable \n";
00534   stream << "      reloadImage() \n";
00535   stream << "    } \n\n";
00536   stream << "    function previousImage() \n";
00537   stream << "    { \n";
00538   stream << "      //decrement image number \n";
00539   stream << "      imageNumber = imageNumber - 1 \n";
00540   stream << "      //wrap to begining if reached the end \n";
00541   stream << "      if (imageNumber==(1 - 1)) \n";
00542   stream << "      {imageNumber = " << numPhotos << "} \n\n";
00543   stream << "      //reset image src value based on variable \n";
00544   stream << "      reloadImage() \n";
00545   stream << "    }\n\n";
00546   stream << "   -->\n";
00547   stream << "   </script> \n";
00548   stream << "  </head> \n";
00549   stream << "  <body> \n";
00550   stream << "    <center> \n";
00551   stream << "      <table>\n";
00552   stream << "        <tr>\n";
00553   stream << "          <td width=\"450\">\n";
00554   stream << "            <h3>\n";
00555   stream << "              " << name << "\n";
00556   stream << "           </h3>\n";
00557   stream << "           <h4>\n";
00558   stream << "             " << description << "\n";
00559   stream << "           </h4>\n";
00560   stream << "          </td>\n";
00561   stream << "        </tr>\n";
00562   stream << "      </table>\n";
00563   stream << "    </center> \n";
00564   stream << "    <h4>\n";
00565   stream << "      <a href=\"subalbum_" << subalbumNumber << "_thumbs.html\">\n";
00566   stream << "        Thumbnails\n";
00567   stream << "      </a>\n";
00568   stream << "      &nbsp;-&nbsp;\n";
00569   stream << "      <a href=\"Album.html\">\n";
00570   stream << "        Album Index\n";
00571   stream << "      </a>\n";
00572   stream << "    </h4>\n";
00573   stream << "    <center> \n";
00574   stream << "      <a href=\"JavaScript:expandImage()\"> \n";
00575   stream << "        <img alt=\"current photo\" src=\"img/" << subalbumNumber << "/1_slideshow.jpg\" name=\"currentPhoto\" border=\"0\"> \n";
00576   stream << "      </a> \n";
00577   stream << "    </center> \n";
00578   stream << "    <center> \n";
00579   stream << "      <form name=\"photoInfo\" action=\"\"> \n";
00580   stream << "        <table border=\"0\"> \n";
00581   stream << "          <tr> \n";
00582   stream << "            <td valign=\"middle\" align=\"center\" width=\"100\"> \n";
00583   stream << "              <a href=\"JavaScript:firstImage()\"> (First) </a> \n";
00584   stream << "            </td> \n";
00585   stream << "             <td valign=\"middle\" align=\"center\" width=\"100\"> \n";
00586   stream << "               <a href=\"JavaScript:previousImage()\"> Previous </a> \n";
00587   stream << "            </td> \n";
00588   stream << "            <td valign=\"middle\" align=\"center\">\n";
00589   stream << "              <input type=\"text\" maxlength=\"100\" name=\"whichPhoto\" readonly value=\"Photo 1 of " << numPhotos << "\">\n";
00590   stream << "            </td>\n";
00591   stream << "            <td valign=\"middle\" align=\"center\" width=\"100\"> \n";
00592   stream << "              <a href=\"JavaScript:nextImage()\"> Next </a> \n";
00593   stream << "            </td> \n";
00594   stream << "            <td valign=\"middle\" align=\"center\" width=\"100\"> \n";
00595   stream << "              <a href=\"JavaScript:lastImage()\"> (Last) </a> \n";
00596   stream << "            </td> \n";
00597   stream << "          </tr> \n";
00598   stream << "          <tr> \n";  
00599   stream << "            <td colspan=\"5\" valign=\"middle\" align=\"center\"> \n";
00600   stream << "              <textarea cols=\"40\" rows=\"2\" name=\"photoDesc\" readonly>\n";
00601   if( firstPhoto == NULL || firstPhoto->getDescription() == "" )
00602   {
00603     stream << "Photo 1 of " << numPhotos << "\n";
00604   }
00605   else
00606   {
00607     stream << firstPhoto->getDescription() << "\n";
00608   }
00609   stream << "              </textarea>\n";
00610   stream << "            </td> \n";
00611   stream << "          </tr> \n";
00612   stream << "        </table> \n";
00613   stream << "      </form> \n";
00614   stream << "    </center> \n";
00615   stream << "    <h4 class=\"ital\">\n";
00616   stream << "      (Generated by <a href=\"http://albumshaper.sourceforge.net\">Album Shaper</a>)\n";
00617   stream << "    </h4>\n";
00618   stream << "  </body> \n";
00619   stream << "</html> \n";
00620 }
00621 //==============================================
00622 Photo* Subalbum::getFirst()
00623 {
00624   return firstPhoto;
00625 }
00626 //==============================================
00627 Photo* Subalbum::getLast()
00628 {
00629   return lastPhoto;
00630 }
00631 //==============================================
00632 void Subalbum::importFromDisk(QDomNode* root, int subalbumNum, LoadDialog* dialog, QString dirName)
00633 {
00634   //if representative image exists load
00635   QString repName = QString(dirName + "/img/%1_thumb.jpg").arg(subalbumNum);
00636   QImage repImage(repName);
00637   if(!repImage.isNull())
00638   {
00639     setRepresentativeImages(&repImage);  
00640   }  
00641   
00642   QDomNode node = root->firstChild();
00643   QDomText val;  
00644   int photoNum = 0;
00645   while( !node.isNull() )
00646   {
00647     //------------------------------------------------------------
00648     //subalbum name
00649     if( node.isElement() && node.nodeName() == "name" )
00650     { 
00651       val = node.firstChild().toText();
00652       if(!val.isNull())
00653         name = val.nodeValue();
00654     }
00655     //------------------------------------------------------------
00656     //subalbum description
00657     else if( node.isElement() && node.nodeName() == "description" )
00658     { 
00659       val = node.firstChild().toText();
00660       if(!val.isNull())
00661         description = val.nodeValue();
00662     }
00663     //------------------------------------------------------------
00664     //photo
00665     else if( node.isElement() && node.nodeName() == "photo" )
00666     { 
00667       //increase counter
00668       photoNum++;
00669       
00670 
00671       dialog->printSubalbumPhoto(subalbumNum, photoNum);
00672       
00673       //create new photo object
00674       QString imageName = QString(dirName + "img/%1/%2.jpg").arg(subalbumNum).arg(photoNum);
00675       QString slideshowName = QString(dirName + "img/%1/%2_slideshow.jpg").arg(subalbumNum).arg(photoNum);
00676       QString thumbName = QString(dirName + "img/%1/%2_thumb.jpg").arg(subalbumNum).arg(photoNum);
00677       Photo* newPhoto = new Photo(this, photoNum);
00678 
00679       //load photo information from disk
00680       newPhoto->importFromDisk( &node );      
00681       
00682       //if no changes have occured do lazy load - don't 
00683       //bother scaling down thumbnail and slideshow images
00684       //from original image
00685       ifstream imageFile( imageName );      
00686       ifstream slideshowFile( slideshowName );      
00687       ifstream thumbnailFile( thumbName );
00688       
00689       if(
00690           imageFile.is_open() &&
00691           thumbnailFile.is_open() &&
00692           slideshowFile.is_open() &&
00693           getMD5(imageFile) == newPhoto->getImageChecksum() &&
00694           getMD5(slideshowFile) == newPhoto->getSlideshowChecksum() &&
00695           getMD5(thumbnailFile) == newPhoto->getThumbnailChecksum()
00696         )
00697       {
00698         //close ifstreams
00699         imageFile.close();
00700         slideshowFile.close();
00701         thumbnailFile.close();
00702         
00703         //populate image
00704         lazyAddPhoto(imageName, slideshowName, thumbName, newPhoto);
00705       }
00706       //else reload image and scale it since changes have occured.
00707       else
00708       {
00709         //close ifstreams if open
00710         if(imageFile.is_open())
00711           imageFile.close();
00712         if(thumbnailFile.is_open())
00713           thumbnailFile.close();
00714           
00715         //populate image
00716         addPhoto(imageName, newPhoto);
00717       }
00718 
00719       if(imageFile.is_open())
00720         imageFile.close();
00721       if(slideshowFile.is_open())
00722         slideshowFile.close();
00723       if(thumbnailFile.is_open())
00724         thumbnailFile.close();
00725     }
00726     //------------------------------------------------------------
00727     //advance to next node   
00728     node = node.nextSibling();
00729     //------------------------------------------------------------
00730   }
00731   //------------------------------------------------------------
00732   //set loaded number
00733   resetNumLoadedPhotos();
00734   //------------------------------------------------------------  
00735 }
00736 //==============================================
00737 void Subalbum::addPhoto(Photo* newPhoto)
00738 {
00739   //increase counter
00740   numPhotos++;
00741   
00742   //set it's next pointer to null
00743   newPhoto->setNext(NULL);
00744 
00745   //if this is the only photo, set first and last 
00746   //pointers to this photo.
00747   if(firstPhoto == NULL)
00748   {
00749     firstPhoto = newPhoto;
00750     lastPhoto = newPhoto;
00751   }
00752   //else append to end of list
00753   else
00754   {
00755     lastPhoto->setNext(newPhoto);
00756     lastPhoto = newPhoto;
00757   }
00758 }
00759 //==============================================
00760 void Subalbum::photoMoved(Photo* val)
00761 {
00762   //decrease counter
00763   numPhotos--;
00764  
00765  //walk through list of photos and find specified photo
00766   Photo* current = firstPhoto;
00767   Photo* prev = NULL;
00768   while(current != NULL &&
00769         current != val)
00770   {
00771     prev = current;
00772     current = current->getNext();
00773   }
00774 
00775   if(current == val)
00776   {
00777     //update prev next pointer
00778     if(prev != NULL)
00779       prev->setNext(current->getNext());
00780     
00781     //update first and last pointers if necessary
00782     if(current == firstPhoto)
00783       firstPhoto = current->getNext();
00784     if(current == lastPhoto)
00785       lastPhoto = prev;
00786   }
00787 }
00788 //==============================================
00789 void Subalbum::syncPhotoList(PhotoWidget* item)
00790 {
00791   //base case, no items
00792   if(item == NULL)
00793   {
00794     firstPhoto = NULL;
00795     lastPhoto = NULL;
00796     return;
00797   }
00798   
00799   //set first and last pointers
00800   firstPhoto = item->getPhoto();
00801   firstPhoto->setNext(NULL);
00802   lastPhoto = firstPhoto;
00803     
00804   //set all next pointers
00805   while(item->nextItem() != NULL)
00806   {
00807     item->getPhoto()->setNext( ((PhotoWidget*)item->nextItem())->getPhoto() );
00808     item = (PhotoWidget*)item->nextItem();
00809     lastPhoto = item->getPhoto();
00810     lastPhoto->setNext(NULL);
00811   }
00812 }
00813 //==============================================
00814 int Subalbum::getSubalbumNumber()
00815 {
00816   return number;
00817 }
00818 //==============================================
00819 int Subalbum::getNumPhotos()
00820 {
00821   return numPhotos;;
00822 }
00823 //==============================================
00824 int Subalbum::getNumLoadedPhotos()
00825 {
00826   return loadedPhotos;;
00827 }
00828 //==============================================
00829 void Subalbum::resetNumLoadedPhotos()
00830 {
00831   loadedPhotos = numPhotos;
00832 }
00833 //==============================================

Generated on Tue Jun 10 23:41:21 2003 for AlbumShaper by doxygen 1.3.1