Logo Search packages:      
Sourcecode: albumshaper version File versions  Download package

void Album::exportSubalbumImages ( StatusWidget *  status,
bool  forceSave 
) [private]

Exports subalbum images.

Before we move the file we must be sure to preserve the photos original format. if the photo was not recently reverted (if it was then we're saving out the original form so no need to backup) and the file has previously been saved and an orig file does not exist, we better backup the previously saved version quick

If a photo has never been saved before, make sure to also move over any orig file if one exists. The presence of such a file indicates a photo was modified before it was ever saved, but the original form has been preseved and should be backed up at this time to allow a user to revert to the photos original form in the future.

ok, now it's safe to move over currrent version of the photo

----

----

Definition at line 889 of file album.cpp.

References firstSubalbum, Photo::getEverSaved(), Subalbum::getFirst(), Photo::getImageFilename(), Photo::getInitialPhotoNumber(), Photo::getInitialSubalbumNumber(), Photo::getNeedsSavingVal(), Subalbum::getNext(), Photo::getNext(), Photo::getRecentlyReverted(), Photo::getSlideshowFilename(), Photo::getThumbnailFilename(), getTmpDir(), saveLocation, Photo::setEverSaved(), Photo::setImageChecksum(), Photo::setImageFilename(), Photo::setNeedsSavingVal(), Photo::setSlideshowChecksum(), Photo::setSlideshowFilename(), Photo::setThumbnailChecksum(), Photo::setThumbnailFilename(), and tmpDir.

Referenced by exportToDisk().

{
  //iterate over all subalbums
  int subalbumNumber=0;
  Subalbum* currentSubalbum = firstSubalbum;
  while(currentSubalbum != NULL)
  {
    subalbumNumber++;

    //iterate over all photos in this subalbum
    int photoNumber=0;
    Photo* currentPhoto = currentSubalbum->getFirst();
    while(currentPhoto != NULL)
    {
      photoNumber++;
      //---------------------------------------
      //if the current photo does not need to be saved then move on
      if( !forceSave && !currentPhoto->getNeedsSavingVal() )
      {
        currentPhoto = currentPhoto->getNext();
        status->incrementProgress();
        qApp->processEvents();
        continue;
      }
      //---------------------------------------
      //get initial photo # and subalbum #, used for saving
      int initPhotoNumber = currentPhoto->getInitialPhotoNumber();
      int initSubalbumNumber = currentPhoto->getInitialSubalbumNumber();
      //---------------------------------------
      //export thumbnail image
      QString oldName = currentPhoto->getThumbnailFilename();
      QString newName = QString(saveLocation + "/img/%1/%2_thumb.jpg" )
                        .arg(initSubalbumNumber).arg(initPhotoNumber);
      
      //if file has been modified move from current location to final location
      if( currentPhoto->getNeedsSavingVal() ) { moveFile( oldName, newName ); }
      //If file has not been modified we must be doing a save-as and saving has been forced. In this case
      //COPY file from current location to final location, DON'T delete previous copy!!!
      else { copyFile(oldName, newName); }

      //compute and store md5 for slideshow image
      std::ifstream thumbnailFile( QFile::encodeName(newName) );
      if(thumbnailFile.is_open())
      {
        currentPhoto->setThumbnailChecksum( getMD5(thumbnailFile) );
        thumbnailFile.close();
      }
      //---------------------------------------
      //export slideshow image
      oldName = currentPhoto->getSlideshowFilename();
      newName = QString(saveLocation + "/img/%1/%2_slideshow.jpg" )
                        .arg(initSubalbumNumber).arg(initPhotoNumber);

      //if file has been modified move from current location to final location
      if( currentPhoto->getNeedsSavingVal() ) { moveFile( oldName, newName ); }
      //If file has not been modified we must be doing a save-as and saving has been forced. In this case
      //COPY file from current location to final location, DON'T delete previous copy!!!
      else { copyFile(oldName, newName); }

      //compute and store md5 for slideshow image
      std::ifstream slideshowFile( QFile::encodeName(newName) );
      if(slideshowFile.is_open())
      {
        currentPhoto->setSlideshowChecksum( getMD5(slideshowFile) );
        slideshowFile.close();
      }
      //---------------------------------------
      //export full size image
      oldName = currentPhoto->getImageFilename();
      newName = QString(saveLocation + "/img/%1/%2.jpg" ).arg(initSubalbumNumber).arg(initPhotoNumber);

      //if file has been modified move from current location to final location
      if( currentPhoto->getNeedsSavingVal() ) 
      {
        QString tempOrigName = getTmpDir() + QString("/%1_%2_orig.jpg")
        .arg(initSubalbumNumber).arg(initPhotoNumber);
                     
        QString finalOrigName = QString(saveLocation + "/img/%1/%2_orig.jpg" )
          .arg(initSubalbumNumber).arg(initPhotoNumber);

        ///Before we move the file we must be sure to preserve the photos original format.
        ///if the photo was not recently reverted (if it was then we're saving out
        ///the original form so no need to backup) and the file has previously been saved and
        ///an orig file does not exist, we better backup the previously saved version quick
        QDir tmpDir;
        if( !currentPhoto->getRecentlyReverted() &&
            tmpDir.exists(newName) &&
            !tmpDir.exists(finalOrigName) )
        {
          moveFile( newName, finalOrigName );
        }      
        //if photo previously saved, there is no orig file, but the photo 
        //is modified and we're doing a force save than make sure to copy 
        //over the original as well even though it's not an orig file
        else if ( currentPhoto->getEverSaved() &&
                  currentPhoto->getNeedsSavingVal() &&
                  forceSave &&
                  saveLocation.compare( oldSaveLocation ) != 0 )
        {
          QString storedOrigLocation = oldSaveLocation +         
                                       QString("/img/%1/%2_orig.jpg").arg(currentPhoto->getInitialSubalbumNumber())
                                                                     .arg(currentPhoto->getInitialPhotoNumber());
          QString storedLocation = oldSaveLocation +         
                                   QString("/img/%1/%2.jpg").arg(currentPhoto->getInitialSubalbumNumber())
                                                            .arg(currentPhoto->getInitialPhotoNumber());
          
          if( tmpDir.exists(storedOrigLocation) )
            copyFile( storedOrigLocation, finalOrigName );
          else if( tmpDir.exists(storedLocation) )
            copyFile( storedLocation, finalOrigName );
        }
        ///If a photo has never been saved before, make sure to also move over any orig file if
        ///one exists. The presence of such a file indicates a photo was modified before it
        ///was ever saved, but the original form has been preseved and should be backed up at this
        ///time to allow a user to revert to the photos original form in the future.
        else if( !currentPhoto->getRecentlyReverted() &&
                 !tmpDir.exists(newName) &&
                 tmpDir.exists(tempOrigName) )
        {
          moveFile( tempOrigName, finalOrigName );
        }

        ///ok, now it's safe to move over currrent version of the photo
        moveFile( oldName, newName );
      }
      //If file does not need to be saved a force save is taking place. This occurs when a user chooses
      //save as and copies an entire album to a different location so all files must be copied. Make
      //sure to copy over the original form of the photo as well if this file exists
      else
      {
        //copy current image
        copyFile( oldName, newName );
        
        ///----
        //if orig file exists copy it too
        QDir tmpDir;
         
        QString tempOrigName = getTmpDir() + QString("/%1_%2_orig.jpg")
           .arg(initSubalbumNumber).arg(initPhotoNumber);

        QString curOrigName = currentPhoto->getImageFilename();
        curOrigName.truncate( curOrigName.length() - 4 );
        curOrigName = curOrigName + "_orig.jpg";

        QString finalOrigName = QString(saveLocation + "/img/%1/%2_orig.jpg" )
           .arg(initSubalbumNumber).arg(initPhotoNumber);

        //if the photo was recently reverted ignore the presence of orig files
        if( !currentPhoto->getRecentlyReverted() )
        {
          //if the photo was never previously saved and an orig file
          //exists in the tmp directory make sure to copy it over
          if( !currentPhoto->getEverSaved() &&
              tmpDir.exists( tempOrigName ) )
          {
            copyFile( tempOrigName, finalOrigName );
          }        
          //if the photo was previously saved and an orig file exists
          //in the previous save location make sure to copy it over
          else if( currentPhoto->getEverSaved() &&
                   tmpDir.exists( curOrigName ) )
          {
            copyFile( curOrigName, finalOrigName );
          }        
        }
        ///----
      }
      //---------------------------------------
      //compute and store md5 for image
      std::ifstream imageFile( QFile::encodeName(newName) );
      if(imageFile.is_open())
      {
        currentPhoto->setImageChecksum( getMD5(imageFile) );
        imageFile.close();
      }
      //---------------------------------------
      //set new storage locations of files
      currentPhoto->setImageFilename
        ( QString(saveLocation + "/img/%1/%2.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
      
      currentPhoto->setSlideshowFilename
        ( QString(saveLocation + "/img/%1/%2_slideshow.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
      
      currentPhoto->setThumbnailFilename
        ( QString(saveLocation + "/img/%1/%2_thumb.jpg").arg(initSubalbumNumber).arg(initPhotoNumber) );
      //---------------------------------------
      //set image as not needing saving and as being saved
      currentPhoto->setNeedsSavingVal(false);
      currentPhoto->setEverSaved(true);
      //---------------------------------------
      //update progress bar
      status->incrementProgress();
      qApp->processEvents();
      //---------------------------------------
      //move on to next photo in subalbum
      currentPhoto = currentPhoto->getNext();
      //---------------------------------------
    }
    //---------------------------------------
    //move on to next subalbum
    currentSubalbum = currentSubalbum->getNext();
  }
}


Generated by  Doxygen 1.6.0   Back to index