AlbumShaper  1.0a3
Public Member Functions | Private Attributes
Photo Class Reference

A photo consists of a full size image, a smaller slide show image, a very small thumbnail image, and a desription. More...

#include <photo.h>

Collaboration diagram for Photo:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Photo (Subalbum *subalbum, Photo *prev, int photoNumber)
 Sets default information.
 ~Photo ()
QImage * getThumbnailImage ()
 Gets thumbnail image.
bool constructSmallerImages ()
 Construct thumbnail and slideshow images, load up thumbnail image, and set photo has being modified.
bool setImage (QString imageName, QString slideshowName, QString thumbnailName)
 Setup photo using preexisting full size, slideshow, and thumbnail images.
bool setImage (QString imageName, int uniqueID)
 Setup photo using a new image. We'll need to create slideshow and thumbnail images.
bool setImage (QString editedImageFilename)
 Reset photo data after photo editing has taken place.
QString getImageFilename ()
 Gets the image filename.
QString getSlideshowFilename ()
 Gets the slideshow filename.
QString getThumbnailFilename ()
 Gets the thumbnail filename.
void setImageFilename (QString val)
 Sets the image filename.
void setSlideshowFilename (QString val)
 Sets the slideshow filename.
void setThumbnailFilename (QString val)
 Sets the thumbnail filename.
QString getImageChecksum ()
 Get image checksum.
QString getThumbnailChecksum ()
 Get thumbanil checksum.
QString getSlideshowChecksum ()
 Get thumbanil checksum.
void setImageChecksum (QString val)
 Update image checksum.
void setThumbnailChecksum (QString val)
 Update thumbnail checksum.
void setSlideshowChecksum (QString val)
 Update slideshow checksum.
QString getDescription ()
 Gets the description.
void setDescription (QString val)
 Sets the description.
PhotogetPrev ()
 Returns the previous photo pointer.
PhotogetNext ()
 Returns next photo pointer.
void setPrev (Photo *val)
 Sets prev photo pointer.
void setNext (Photo *val)
 Sets next photo pointer.
QDateTime * importFromDisk (QDomNode *root)
 Builds photo from XML DOM node, returns date modified info from xml.
void exportToXML (QTextStream &stream)
 Exports photo to xml.
void rotate90 ()
 Rotates image clockwise 90 degrees.
void rotate270 ()
 Rotates image clockwise 270 degrees.
void flipHorizontally ()
 Flips image about horizontal axis.
void flipVertically ()
 Flips image about vertical axis.
void applyTransformation (TRANSFORM_CODE transformation)
 Apply transformation.
bool getNeedsSavingVal ()
 Returns if the image needs to be saved to its permament location.
void setNeedsSavingVal (bool val)
 Sets if the image needs to be saved to its permanent location.
bool getEverSaved ()
 Returns if the image has ever been saved to a permanant location.
void setEverSaved (bool val)
 sets everSaved
void revertPhoto ()
 revert photo to original form
bool revertPossible ()
 can photo be reverted to a differnt original form
bool getRecentlyReverted ()
 was the photo recently reverted? if so ignore the presence of orig files on disk
void setRecentlyReverted (bool val)
 reset the recently reverted value to val
QString originalImageFilename ()
 orig filename
int getInitialPhotoNumber ()
 Returns initial photo number.
void setInitialPhotoNumber (int val)
 Sets initial photo number.
int getInitialSubalbumNumber ()
 Returns initial subalbum number.
void setInitialSubalbumNumber (int val)
 Sets initial subalbum number.

Private Attributes

Subalbumsubalbum
 Subalbum photo is in.
Photoprev
 Pointer to prev photo.
Photonext
 Pointer to next photo.
int initialPhotoNumber
int initialSubalbumNumber
QString description
 Photo description.
QImage * thumbnailImage
 Thumbnail Image.
QString imageLocation
 Filenames.
QString slideshowLocation
QString thumbnailLocation
QString imageChecksum
 MD5 checksums, used to determine if image/thumbnail have been changed.
QString slideshowChecksum
QString thumbnailChecksum
bool needsSaving
 Unsaved modifications?
bool everSaved
 Has the photo ever been saved?
bool recentlyReverted
 Has the photo recently been reverted to it's original form? If so during the next save the orig file can safely be remove.

Detailed Description

A photo consists of a full size image, a smaller slide show image, a very small thumbnail image, and a desription.

Definition at line 41 of file photo.h.


Constructor & Destructor Documentation

Photo::Photo ( Subalbum subalbum,
Photo prev,
int  photoNumber 
)

Sets default information.

Definition at line 31 of file photo.cpp.

References description, everSaved, Subalbum::getSubalbumNumber(), imageChecksum, imageLocation, initialPhotoNumber, initialSubalbumNumber, needsSaving, next, prev, recentlyReverted, slideshowChecksum, slideshowLocation, subalbum, thumbnailChecksum, thumbnailImage, and thumbnailLocation.

{
  //set subalbum pointer
  this->subalbum = subalbum;

  //set prev pointer
  this->prev = prev;
  
  //set next pointer to NULL, new photos are always
  //inserted at the end of collections
  next = NULL;
  
  //set initial photo and subalbum numbers
  initialPhotoNumber = photoNumber;
  initialSubalbumNumber = subalbum->getSubalbumNumber();

  //set default to the empty string
  description = QString::null;

  //set thumbnail image
  thumbnailImage = NULL;

  //set filenames and checksums to null until the actual photo data has been set
  imageLocation     = QString::null;
  imageChecksum     = QString::null;
  
  slideshowLocation = QString::null;
  slideshowChecksum = QString::null;
  
  thumbnailLocation = QString::null;
  thumbnailChecksum = QString::null;

  //a default photo is not interesting. once the 
  //actual photo data or description files have
  //been reset the photo will need to be saved.
  needsSaving = false;
  
  //by default a photos are assumed to be saved. 
  //new photos are setup with a uniqueID and we'll set this bool false there
  everSaved = true;
  
  //photo not recently reverted
  recentlyReverted = false;
}
Photo::~Photo ( )

Definition at line 76 of file photo.cpp.

References thumbnailImage.

{
  //free the thumbnail image
  delete thumbnailImage;
}

Member Function Documentation

void Photo::applyTransformation ( TRANSFORM_CODE  transformation)

Apply transformation.

Definition at line 475 of file photo.cpp.

References constructSmallerImages(), Subalbum::getAlbum(), getEverSaved(), Album::getTmpDir(), imageLocation, initialPhotoNumber, initialSubalbumNumber, moveFile(), needsSaving, recentlyReverted, slideshowLocation, subalbum, thumbnailLocation, and transformImage().

Referenced by flipHorizontally(), flipVertically(), rotate270(), and rotate90().

{  
  //backup old filename
  QString oldName = imageLocation;
   
  //if the image did not previously need saving, 
  //reset filenames to point to temporary location and
  //immediately perform transformation
  if(!needsSaving)
  {
    imageLocation = subalbum->getAlbum()->getTmpDir() + QString("/%1_%2.jpg")
                                                                .arg(initialSubalbumNumber)
                                                                .arg(initialPhotoNumber);
    slideshowLocation = subalbum->getAlbum()->getTmpDir() + QString("/%1_%2_slideshow.jpg")
                                                                .arg(initialSubalbumNumber)
                                                                .arg(initialPhotoNumber);
    thumbnailLocation = subalbum->getAlbum()->getTmpDir() + QString("/%1_%2_thumb.jpg")
                                                                .arg(initialSubalbumNumber)
                                                                .arg(initialPhotoNumber);
    transformImage( oldName, imageLocation, transformation );
  }
  else
  {
    //images that need saving already exist in the temporary directory
    //this poses two problems:
    //1.) fast jpeg transformations cannot be done in place, so we'll employ an
    //    intermediate image
    QString intermediateName = QString("%1_intermdiate.jpg").arg(oldName);
    transformImage( oldName, intermediateName, transformation );    
    
    //2.) If the photo has never been saved and an orig file in the temporary
    //    directory does not exist then the current file is the original version. we
    //    must make sure that this original photo is maintained using an orig file so
    //    in the future users can revert the photo to it's original form.
    QString origName = subalbum->getAlbum()->getTmpDir() + QString("/0_%1_orig.jpg")
      .arg(initialPhotoNumber);      
    QDir tmpDir;
    if( !getEverSaved() && !tmpDir.exists(origName) )
    {
      moveFile( oldName, origName );
      moveFile( intermediateName, imageLocation );
    }
    else
    {
      moveFile( intermediateName, imageLocation );
    }
  }
  
  //image now modified from original form so orig file needs to be kept
  recentlyReverted = false;
  
  //construct smaller iamges
  constructSmallerImages();
}
bool Photo::constructSmallerImages ( )

Construct thumbnail and slideshow images, load up thumbnail image, and set photo has being modified.

Definition at line 84 of file photo.cpp.

References constructImages(), imageLocation, needsSaving, Subalbum::setModified(), slideshowLocation, subalbum, thumbnailImage, and thumbnailLocation.

Referenced by applyTransformation(), and setImage().

{
  //construct and save slideshow and thumbnail images
  QImage TslideshowImage, TthumbnailImage;
  constructImages( imageLocation, TslideshowImage, TthumbnailImage );  
  TslideshowImage.save( slideshowLocation, "JPEG", 95 );
  TthumbnailImage.save( thumbnailLocation, "JPEG", 95 );

  //load up thumbnail image
  delete thumbnailImage;
  thumbnailImage = new QImage(thumbnailLocation);

  //image is being stored in temp location, needs saving!
  needsSaving = true;

  //set the subalbum as being modified and return
  subalbum->setModified();
  return true;
}
void Photo::exportToXML ( QTextStream &  stream)

Exports photo to xml.

Definition at line 413 of file photo.cpp.

References description, fixXMLString(), getImageFilename(), getSlideshowFilename(), getThumbnailFilename(), imageChecksum, slideshowChecksum, and thumbnailChecksum.

Referenced by Subalbum::exportToXML().

{
  QFileInfo info;

  //write photo information
  stream << "    <photo>\n";
  //-----
  stream << "      <description>" << fixXMLString(description) << "</description>\n";
  //-----
  //full image
  info.setFile( getImageFilename() );
  QDateTime modified = info.lastModified();
  stream << "      <image>\n";
  stream << "        <md5>" << fixXMLString(imageChecksum) << "</md5>\n";
  stream << "        <modified>";
  stream << modified.date().year() << " ";
  stream << modified.date().month() << " ";
  stream << modified.date().day() << " ";
  stream << modified.time().hour() << " ";
  stream << modified.time().minute() << " ";
  stream << modified.time().second() << " ";
  stream << modified.time().msec() << "</modified>\n";
  stream << "      </image>\n";
  //-----
  //slidehow image
  info.setFile( getSlideshowFilename() );
  modified = info.lastModified();
  stream << "      <slideshow>\n";
  stream << "        <md5>" << fixXMLString(slideshowChecksum) << "</md5>\n";
  stream << "        <modified>";
  stream << modified.date().year() << " ";
  stream << modified.date().month() << " ";
  stream << modified.date().day() << " ";
  stream << modified.time().hour() << " ";
  stream << modified.time().minute() << " ";
  stream << modified.time().second() << " ";
  stream << modified.time().msec() << "</modified>\n";
  stream << "      </slideshow>\n";
  //-----
  //thumbnail image
  info.setFile( getThumbnailFilename() );
  modified = info.lastModified();
  stream << "      <thumb>\n";
  stream << "        <md5>" << fixXMLString(thumbnailChecksum) << "</md5>\n";
  stream << "        <modified>";
  stream << modified.date().year() << " ";
  stream << modified.date().month() << " ";
  stream << modified.date().day() << " ";
  stream << modified.time().hour() << " ";
  stream << modified.time().minute() << " ";
  stream << modified.time().second() << " ";
  stream << modified.time().msec() << "</modified>\n";
  stream << "      </thumb>\n";
  //-----
  stream << "    </photo>\n";
}
void Photo::flipHorizontally ( )

Flips image about horizontal axis.

Definition at line 472 of file photo.cpp.

References applyTransformation(), and FLIP_H.

void Photo::flipVertically ( )

Flips image about vertical axis.

Definition at line 473 of file photo.cpp.

References applyTransformation(), and FLIP_V.

QString Photo::getDescription ( )

Gets the description.

Definition at line 207 of file photo.cpp.

References description.

Referenced by PhotoDescEdit::PhotoDescEdit(), PhotoPreviewWidget::PhotoPreviewWidget(), SlideshowWidget::showPhoto(), and PhotoPreviewWidget::updateDescription().

{ return QString(description); }
bool Photo::getEverSaved ( )

Returns if the image has ever been saved to a permanant location.

Definition at line 533 of file photo.cpp.

References everSaved.

Referenced by applyTransformation(), Album::exportSubalbumImages(), originalImageFilename(), and setImage().

{ return everSaved; }
QString Photo::getImageChecksum ( )

Get image checksum.

Definition at line 199 of file photo.cpp.

References imageChecksum.

Referenced by Subalbum::importFromDisk().

{ return imageChecksum; }
QString Photo::getImageFilename ( )
int Photo::getInitialPhotoNumber ( )

Returns initial photo number.

Definition at line 607 of file photo.cpp.

References initialPhotoNumber.

Referenced by Album::exportSubalbumImages(), and Album::reorderSubalbumImages().

{ return initialPhotoNumber; }
int Photo::getInitialSubalbumNumber ( )

Returns initial subalbum number.

Definition at line 610 of file photo.cpp.

References initialSubalbumNumber.

Referenced by Album::exportSubalbumImages(), and Album::reorderSubalbumImages().

bool Photo::getNeedsSavingVal ( )

Returns if the image needs to be saved to its permament location.

Definition at line 530 of file photo.cpp.

References needsSaving.

Referenced by Album::exportSubalbumImages().

{ return needsSaving; }
Photo * Photo::getNext ( )
Photo * Photo::getPrev ( )
bool Photo::getRecentlyReverted ( )

was the photo recently reverted? if so ignore the presence of orig files on disk

Definition at line 546 of file photo.cpp.

References recentlyReverted.

Referenced by Album::exportSubalbumImages(), and Album::removeStagnantOrigFiles().

{
  return recentlyReverted;
}
QString Photo::getSlideshowChecksum ( )

Get thumbanil checksum.

Definition at line 201 of file photo.cpp.

References slideshowChecksum.

Referenced by Subalbum::importFromDisk().

{ return slideshowChecksum; }
QString Photo::getSlideshowFilename ( )
QString Photo::getThumbnailChecksum ( )

Get thumbanil checksum.

Definition at line 200 of file photo.cpp.

References thumbnailChecksum.

Referenced by Subalbum::importFromDisk().

{ return thumbnailChecksum; }
QString Photo::getThumbnailFilename ( )
QImage * Photo::getThumbnailImage ( )

Gets thumbnail image.

Definition at line 82 of file photo.cpp.

References thumbnailImage.

{ return thumbnailImage; }
QDateTime * Photo::importFromDisk ( QDomNode *  root)

Builds photo from XML DOM node, returns date modified info from xml.

Definition at line 238 of file photo.cpp.

References description, imageChecksum, slideshowChecksum, and thumbnailChecksum.

Referenced by Subalbum::importFromDisk().

{
  //create modified date/time object for returning
  QDateTime* modified = new QDateTime[3];

  QDomNode node = root->firstChild();
  QDomText val;
  while( !node.isNull() )
  {
    //------------------------------------------------------------
    //photo description
    if( node.isElement() && node.nodeName() == "description" )
    {
      val = node.firstChild().toText();
      if(!val.isNull())
        description = val.nodeValue();
     description.replace("\\&quot;","\"");
    }
    //------------------------------------------------------------
    //image information
    else if( node.isElement() && node.nodeName() == "image" )
    {
      QDomNode childNode = node.firstChild();
      while( !childNode.isNull() )
      {
        //------------------------------------------------------------
        if( childNode.isElement() && childNode.nodeName() == "md5" )
        {
          val = childNode.firstChild().toText();
          if(!val.isNull())
            imageChecksum = val.nodeValue();
        }
        //------------------------------------------------------------
        else if( childNode.isElement() && childNode.nodeName() == "modified" )
        {
          val = childNode.firstChild().toText();

          //split value based on spaces, should be 7 fields
          QStringList vals = QStringList::split( QRegExp(" "), val.nodeValue() );
          int i=0;
          int intVals[7];
          QStringList::Iterator it;
          for ( it = vals.begin(); it != vals.end(); ++it )
          {
            //sanity check incase more fields are provided than there should be
            if(i >6)
              break;

            intVals[i] = QString(*it).toInt();
            i++;
          }
          modified[0].setDate( QDate(intVals[0], intVals[1], intVals[2]) );
          modified[0].setTime( QTime(intVals[3], intVals[4], intVals[5], intVals[6]) );
        }
        //------------------------------------------------------------
        childNode = childNode.nextSibling();
      }
    }
    //------------------------------------------------------------
    //slideshow information
    else if( node.isElement() && node.nodeName() == "slideshow" )
    {
      QDomNode childNode = node.firstChild();
      while( !childNode.isNull() )
      {
        //------------------------------------------------------------
        if( childNode.isElement() && childNode.nodeName() == "md5" )
        {
          val = childNode.firstChild().toText();
          if(!val.isNull())
            slideshowChecksum = val.nodeValue();
        }
        //------------------------------------------------------------
        else if( childNode.isElement() && childNode.nodeName() == "modified" )
        {
          val = childNode.firstChild().toText();

          //split value based on spaces, should be 6 fields
          QStringList vals = QStringList::split( QRegExp(" "), val.nodeValue() );
          int i=0;
          int intVals[7];
          QStringList::Iterator it;
          for ( it = vals.begin(); it != vals.end(); ++it )
          {
            //sanity check incase more fields are provided than there should be
            if(i >6)
              break;

            intVals[i] = QString(*it).toInt();
            i++;
          }
          modified[1].setDate( QDate(intVals[0], intVals[1], intVals[2]) );
          modified[1].setTime( QTime(intVals[3], intVals[4], intVals[5], intVals[6]) );
        }
        //------------------------------------------------------------
        childNode = childNode.nextSibling();
      }
    }
    //------------------------------------------------------------
    //slideshow information
    else if( node.isElement() && node.nodeName() == "thumb" )
    {
      QDomNode childNode = node.firstChild();
      while( !childNode.isNull() )
      {
        //------------------------------------------------------------
        if( childNode.isElement() && childNode.nodeName() == "md5" )
        {
          val = childNode.firstChild().toText();
          if(!val.isNull())
            thumbnailChecksum = val.nodeValue();
        }
        //------------------------------------------------------------
        else if( childNode.isElement() && childNode.nodeName() == "modified" )
        {
          val = childNode.firstChild().toText();

          //split value based on spaces, should be 6 fields
          QStringList vals = QStringList::split( QRegExp(" "), val.nodeValue() );
          int i=0;
          int intVals[7];
          QStringList::Iterator it;
          for ( it = vals.begin(); it != vals.end(); ++it )
          {
            //sanity check incase more fields are provided than there should be
            if(i >6)
              break;

            intVals[i] = QString(*it).toInt();
            i++;
          }
          modified[2].setDate( QDate(intVals[0], intVals[1], intVals[2]) );
          modified[2].setTime( QTime(intVals[3], intVals[4], intVals[5], intVals[6]) );
        }
        //------------------------------------------------------------
        childNode = childNode.nextSibling();
      }
    }
    //------------------------------------------------------------
    //------------------------------------------------------------
    //Handle md5 info as specified in 1.0a and 1.0a2 xml format
    //image md5
    else if( node.isElement() && node.nodeName() == "imageMD5" )
    {
      val = node.firstChild().toText();
      if(!val.isNull())
        imageChecksum = val.nodeValue();
    }
    //------------------------------------------------------------
    //slideshow md5
    else if( node.isElement() && node.nodeName() == "slideMD5" )
    {
      val = node.firstChild().toText();
      if(!val.isNull())
        slideshowChecksum = val.nodeValue();
    }
    //------------------------------------------------------------
    //thumbnail md5
    else if( node.isElement() && node.nodeName() == "thumbMD5" )
    {
      val = node.firstChild().toText();
      if(!val.isNull())
        thumbnailChecksum = val.nodeValue();
    }
    //------------------------------------------------------------
    //------------------------------------------------------------
    //advance to next node
    node = node.nextSibling();
    //------------------------------------------------------------
  }

  //return modification dates read in
  return modified;
}
QString Photo::originalImageFilename ( )

orig filename

Definition at line 571 of file photo.cpp.

References Subalbum::getAlbum(), getEverSaved(), Album::getSaveLocation(), imageLocation, initialPhotoNumber, initialSubalbumNumber, and subalbum.

Referenced by Album::removeStagnantOrigFiles(), EditingInterface::revertCurrentPhoto(), revertPhoto(), and revertPossible().

{
  //determining the an images original filename is tricky
  //if the photo has never been saved check for presence of an _orig file,
  //otherwise use the current filename since the photo has not yet been modified
  if( !getEverSaved() )
  {
    QString tempOrigLocation = imageLocation;
    tempOrigLocation.truncate( imageLocation.length() - 4 );
    tempOrigLocation = tempOrigLocation + "_orig.jpg";
    
    QDir tmpDir;
    if(tmpDir.exists( tempOrigLocation ) )
      return tempOrigLocation;
    else
      return imageLocation;
  }
  //if the photo was previously saved, it's original form could either be:
  //1.) the permanant storage location + _orig
  //2.) the permanant storage location
  else
  {
    QString storedOrigLocation = subalbum->getAlbum()->getSaveLocation() +  
      QString("/img/%1/%2_orig.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
   
    QString lastSavedLocation = subalbum->getAlbum()->getSaveLocation() +  
      QString("/img/%1/%2.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);    
    
    QDir tmpDir;
    if(tmpDir.exists( storedOrigLocation ) )
      return storedOrigLocation;
    else
      return lastSavedLocation;
  }
}
void Photo::revertPhoto ( )

revert photo to original form

Definition at line 556 of file photo.cpp.

References originalImageFilename(), recentlyReverted, revertPossible(), and setImage().

Referenced by EditingInterface::revertCurrentPhoto().

{
  //ignore if revert is not possible
  if(!revertPossible())
    return;
  
  //set image to reverted form
  QString origName = originalImageFilename();
  setImage( origName );
  
  //recently reverted, orig file should be
  //removed during next save since it's redundant
  recentlyReverted = true;
}
bool Photo::revertPossible ( )

can photo be reverted to a differnt original form

Definition at line 536 of file photo.cpp.

References getImageFilename(), originalImageFilename(), and recentlyReverted.

Referenced by EditingInterface::currentPhotoRevertable(), and revertPhoto().

{
  //if photo not recently reverted and orig and current filenames differ
  QString newName = getImageFilename();
  QString origName = originalImageFilename();
  
  return ( !recentlyReverted &&
           origName.compare( newName ) !=0 );
}
void Photo::rotate270 ( )

Rotates image clockwise 270 degrees.

Definition at line 471 of file photo.cpp.

References applyTransformation(), and ROTATE_270.

void Photo::rotate90 ( )

Rotates image clockwise 90 degrees.

Definition at line 470 of file photo.cpp.

References applyTransformation(), and ROTATE_90.

void Photo::setDescription ( QString  val)

Sets the description.

Definition at line 209 of file photo.cpp.

References description, Subalbum::setModified(), and subalbum.

Referenced by Subalbum::addPhoto(), and PhotoDescEdit::disappear().

{
  //set empty strings as null, takes up less space and necessary
  //to check for string modification
  if( val.isEmpty() )
    val = QString::null;

  if(description.compare(val) != 0)
  {
    description = val;
    subalbum->setModified();
  }
}
void Photo::setEverSaved ( bool  val)

sets everSaved

Definition at line 534 of file photo.cpp.

References everSaved.

Referenced by Album::exportSubalbumImages(), and setImage().

{ everSaved = val; }
bool Photo::setImage ( QString  imageName,
QString  slideshowName,
QString  thumbnailName 
)

Setup photo using preexisting full size, slideshow, and thumbnail images.

We call this method when loading photos from disk and resizing is not necessary.

Definition at line 104 of file photo.cpp.

References imageLocation, needsSaving, slideshowLocation, thumbnailImage, and thumbnailLocation.

Referenced by Subalbum::addPhoto(), EditingInterface::applyImageUpdate(), Subalbum::lazyAddPhoto(), revertPhoto(), and EditingInterface::rotateFlip().

{  
  //set filenames, we'll lazily compute MD5 checksums for files when saving
  imageLocation     = imageName;
  slideshowLocation = slideshowName;
  thumbnailLocation = thumbnailName;
  
  //load thumbnail image
  delete thumbnailImage;
  thumbnailImage = new QImage(thumbnailName);
  if(thumbnailImage->isNull()) return false;
  
  //image just loaded, no changes yet
  needsSaving = false;
  return true;
}
bool Photo::setImage ( QString  imageName,
int  uniqueID 
)

Setup photo using a new image. We'll need to create slideshow and thumbnail images.

Definition at line 123 of file photo.cpp.

References constructSmallerImages(), copyFile(), Subalbum::getAlbum(), Album::getTmpDir(), imageLocation, initialPhotoNumber, initialSubalbumNumber, isJpeg(), setEverSaved(), slideshowLocation, subalbum, and thumbnailLocation.

{ 
  //this is a new photo, use a unique ID to construct temporary filenames
  setEverSaved(false);
  initialSubalbumNumber = 0;
  initialPhotoNumber = uniqueID;

  QString tmpDir = subalbum->getAlbum()->getTmpDir();
  imageLocation     = QString("%1/%2_%3.jpg")          .arg(tmpDir).arg(initialSubalbumNumber).arg(initialPhotoNumber);
  slideshowLocation = QString("%1/%2_%3_slideshow.jpg").arg(tmpDir).arg(initialSubalbumNumber).arg(initialPhotoNumber);
  thumbnailLocation = QString("%1/%2_%3_thumb.jpg")    .arg(tmpDir).arg(initialSubalbumNumber).arg(initialPhotoNumber);
  
  //if image in jpeg format simply copy file over
  if( isJpeg(imageName) )
  {
    copyFile( imageName, imageLocation );
  }
  //otherwise we must load it up and save it out as jpeg
  else
  {
    //if unable to open image at all using Qt then giveup
    QImage tempImage(imageName);
    if( tempImage.isNull() ) { return false; }
    
    //save out as jpeg
    tempImage.save( imageLocation, "JPEG", 95 );
  }  
  
  //construct smaller iamges
  return constructSmallerImages();
}
bool Photo::setImage ( QString  editedImageFilename)

Reset photo data after photo editing has taken place.

Slideshow and thumbnail images need to be regenerated.

Definition at line 155 of file photo.cpp.

References constructSmallerImages(), copyFile(), Subalbum::getAlbum(), getEverSaved(), Album::getTmpDir(), imageLocation, initialPhotoNumber, initialSubalbumNumber, recentlyReverted, slideshowLocation, subalbum, and thumbnailLocation.

{
  //if the image has been saved then simply change the image,slideshow/thubnail 
  //filename handles to point to the temporary directory. We don't need to worry about backing up the
  //image because the new version will be written to the temporary directory and the save location
  if( getEverSaved() )
  {
    imageLocation = subalbum->getAlbum()->getTmpDir() + 
                    QString("/%1_%2.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
    slideshowLocation = subalbum->getAlbum()->getTmpDir() + 
                        QString("/%1_%2_slideshow.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
    thumbnailLocation = subalbum->getAlbum()->getTmpDir() + 
                        QString("/%1_%2_thumb.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
  }
  //otherwise image has never been saved, make sure original form has been backed up!
  else
  {
    QString tempOrigLocation = imageLocation;
    tempOrigLocation.truncate( imageLocation.length() - 4 );
    tempOrigLocation = tempOrigLocation + "_orig.jpg";
       
    QDir tmpDir;
    if(!tmpDir.exists( tempOrigLocation ) )
    { copyFile( imageLocation, tempOrigLocation ); }    
  }
  
  //copy over full size image
  copyFile( editedImageFilename, imageLocation );
  
  //reset revert flag since image has not been modified
  recentlyReverted = false;
  
  //construct smaller iamges
  return constructSmallerImages();
}
void Photo::setImageChecksum ( QString  val)

Update image checksum.

Definition at line 203 of file photo.cpp.

References imageChecksum.

Referenced by Album::exportSubalbumImages().

{ imageChecksum = val; }
void Photo::setImageFilename ( QString  val)

Sets the image filename.

Definition at line 195 of file photo.cpp.

References imageLocation.

Referenced by Album::exportSubalbumImages(), and Album::reorderSubalbumImages().

{ imageLocation = val;     }
void Photo::setInitialPhotoNumber ( int  val)

Sets initial photo number.

Definition at line 608 of file photo.cpp.

References initialPhotoNumber.

Referenced by Album::reorderSubalbumImages().

{ initialPhotoNumber = val; }
void Photo::setInitialSubalbumNumber ( int  val)

Sets initial subalbum number.

Definition at line 611 of file photo.cpp.

References initialSubalbumNumber.

Referenced by Album::reorderSubalbumImages().

void Photo::setNeedsSavingVal ( bool  val)

Sets if the image needs to be saved to its permanent location.

Definition at line 531 of file photo.cpp.

References needsSaving.

Referenced by Album::exportSubalbumImages().

{ needsSaving = val; }
void Photo::setNext ( Photo val)

Sets next photo pointer.

Definition at line 232 of file photo.cpp.

References next, Subalbum::setModified(), and subalbum.

Referenced by Subalbum::addPhoto(), Subalbum::lazyAddPhoto(), Subalbum::photoMoved(), Subalbum::removePhoto(), and Subalbum::syncPhotoList().

{ 
  next = val;
  subalbum->setModified();
}
void Photo::setPrev ( Photo val)

Sets prev photo pointer.

Definition at line 226 of file photo.cpp.

References prev, Subalbum::setModified(), and subalbum.

Referenced by Subalbum::addPhoto(), Subalbum::lazyAddPhoto(), Subalbum::photoMoved(), Subalbum::removePhoto(), and Subalbum::syncPhotoList().

{ 
  prev = val;
  subalbum->setModified();
}
void Photo::setRecentlyReverted ( bool  val)

reset the recently reverted value to val

Definition at line 551 of file photo.cpp.

References recentlyReverted.

Referenced by Album::removeStagnantOrigFiles().

{
  recentlyReverted = val;
}
void Photo::setSlideshowChecksum ( QString  val)

Update slideshow checksum.

Definition at line 205 of file photo.cpp.

References slideshowChecksum.

Referenced by Album::exportSubalbumImages().

{ slideshowChecksum = val; }
void Photo::setSlideshowFilename ( QString  val)

Sets the slideshow filename.

Definition at line 196 of file photo.cpp.

References slideshowLocation.

Referenced by Album::exportSubalbumImages(), and Album::reorderSubalbumImages().

{ slideshowLocation = val; }
void Photo::setThumbnailChecksum ( QString  val)

Update thumbnail checksum.

Definition at line 204 of file photo.cpp.

References thumbnailChecksum.

Referenced by Album::exportSubalbumImages().

{ thumbnailChecksum = val; }
void Photo::setThumbnailFilename ( QString  val)

Sets the thumbnail filename.

Definition at line 197 of file photo.cpp.

References thumbnailLocation.

Referenced by Album::exportSubalbumImages(), and Album::reorderSubalbumImages().

{ thumbnailLocation = val; }

Member Data Documentation

QString Photo::description [private]

Photo description.

Definition at line 202 of file photo.h.

Referenced by exportToXML(), getDescription(), importFromDisk(), Photo(), and setDescription().

bool Photo::everSaved [private]

Has the photo ever been saved?

Definition at line 221 of file photo.h.

Referenced by getEverSaved(), Photo(), and setEverSaved().

QString Photo::imageChecksum [private]

MD5 checksums, used to determine if image/thumbnail have been changed.

Definition at line 213 of file photo.h.

Referenced by exportToXML(), getImageChecksum(), importFromDisk(), Photo(), and setImageChecksum().

QString Photo::imageLocation [private]
bool Photo::needsSaving [private]

Unsaved modifications?

Definition at line 218 of file photo.h.

Referenced by applyTransformation(), constructSmallerImages(), getNeedsSavingVal(), Photo(), setImage(), and setNeedsSavingVal().

Photo* Photo::next [private]

Pointer to next photo.

Definition at line 193 of file photo.h.

Referenced by getNext(), Photo(), and setNext().

Photo* Photo::prev [private]

Pointer to prev photo.

Definition at line 190 of file photo.h.

Referenced by getPrev(), Photo(), and setPrev().

bool Photo::recentlyReverted [private]

Has the photo recently been reverted to it's original form? If so during the next save the orig file can safely be remove.

Definition at line 225 of file photo.h.

Referenced by applyTransformation(), getRecentlyReverted(), Photo(), revertPhoto(), revertPossible(), setImage(), and setRecentlyReverted().

QString Photo::slideshowChecksum [private]
QString Photo::slideshowLocation [private]
QString Photo::thumbnailChecksum [private]
QImage* Photo::thumbnailImage [private]

Thumbnail Image.

Definition at line 205 of file photo.h.

Referenced by constructSmallerImages(), getThumbnailImage(), Photo(), setImage(), and ~Photo().

QString Photo::thumbnailLocation [private]

The documentation for this class was generated from the following files: