AlbumShaper  1.0a3
Public Member Functions | Private Attributes | List of all members
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]

Public Member Functions

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

Private Attributes

Subalbumsubalbum
 Subalbum photo is in. More...
 
Photoprev
 Pointer to prev photo. More...
 
Photonext
 Pointer to next photo. More...
 
int initialPhotoNumber
 
int initialSubalbumNumber
 
QString description
 Photo description. More...
 
QImage * thumbnailImage
 Thumbnail Image. More...
 
QString imageLocation
 Filenames. More...
 
QString slideshowLocation
 
QString thumbnailLocation
 
QString imageChecksum
 MD5 checksums, used to determine if image/thumbnail have been changed. More...
 
QString slideshowChecksum
 
QString thumbnailChecksum
 
bool needsSaving
 Unsaved modifications? More...
 
bool everSaved
 Has the photo ever been saved? More...
 
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. More...
 

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 44 of file photo.h.

Constructor & Destructor Documentation

§ Photo()

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

Sets default information.

Definition at line 32 of file photo.cpp.

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

33 {
34  //set subalbum pointer
35  this->subalbum = subalbum;
36 
37  //set prev pointer
38  this->prev = prev;
39 
40  //set next pointer to NULL, new photos are always
41  //inserted at the end of collections
42  next = NULL;
43 
44  //set initial photo and subalbum numbers
45  initialPhotoNumber = photoNumber;
47 
48  //set default to the empty string
49  description = QString::null;
50 
51  //set thumbnail image
52  thumbnailImage = NULL;
53 
54  //set filenames and checksums to null until the actual photo data has been set
55  imageLocation = QString::null;
56  imageChecksum = QString::null;
57 
58  slideshowLocation = QString::null;
59  slideshowChecksum = QString::null;
60 
61  thumbnailLocation = QString::null;
62  thumbnailChecksum = QString::null;
63 
64  //a default photo is not interesting. once the
65  //actual photo data or description files have
66  //been reset the photo will need to be saved.
67  needsSaving = false;
68 
69  //by default a photos are assumed to be saved.
70  //new photos are setup with a uniqueID and we'll set this bool false there
71  everSaved = true;
72 
73  //photo not recently reverted
74  recentlyReverted = false;
75 }
int initialSubalbumNumber
Definition: photo.h:202
QString slideshowLocation
Definition: photo.h:212
QString imageChecksum
MD5 checksums, used to determine if image/thumbnail have been changed.
Definition: photo.h:216
QString description
Photo description.
Definition: photo.h:205
bool everSaved
Has the photo ever been saved?
Definition: photo.h:224
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
bool recentlyReverted
Has the photo recently been reverted to it&#39;s original form? If so during the next save the orig file ...
Definition: photo.h:228
QString slideshowChecksum
Definition: photo.h:217
QString thumbnailChecksum
Definition: photo.h:218
bool needsSaving
Unsaved modifications?
Definition: photo.h:221
QString thumbnailLocation
Definition: photo.h:213
Photo * prev
Pointer to prev photo.
Definition: photo.h:193
Photo * next
Pointer to next photo.
Definition: photo.h:196
QString imageLocation
Filenames.
Definition: photo.h:211
QImage * thumbnailImage
Thumbnail Image.
Definition: photo.h:208
int getSubalbumNumber()
Returns subalbum number.
Definition: subalbum.cpp:103
int initialPhotoNumber
Definition: photo.h:199

§ ~Photo()

Photo::~Photo ( )

Definition at line 77 of file photo.cpp.

References thumbnailImage.

78 {
79  //free the thumbnail image
80  delete thumbnailImage;
81 }
QImage * thumbnailImage
Thumbnail Image.
Definition: photo.h:208

Member Function Documentation

§ applyTransformation()

void Photo::applyTransformation ( TRANSFORM_CODE  transformation)

Apply transformation.

Definition at line 476 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().

477 {
478  //backup old filename
479  QString oldName = imageLocation;
480 
481  //if the image did not previously need saving,
482  //reset filenames to point to temporary location and
483  //immediately perform transformation
484  if(!needsSaving)
485  {
486  imageLocation = subalbum->getAlbum()->getTmpDir() + QString("/%1_%2.jpg")
488  .arg(initialPhotoNumber);
489  slideshowLocation = subalbum->getAlbum()->getTmpDir() + QString("/%1_%2_slideshow.jpg")
491  .arg(initialPhotoNumber);
492  thumbnailLocation = subalbum->getAlbum()->getTmpDir() + QString("/%1_%2_thumb.jpg")
494  .arg(initialPhotoNumber);
495  transformImage( oldName, imageLocation, transformation );
496  }
497  else
498  {
499  //images that need saving already exist in the temporary directory
500  //this poses two problems:
501  //1.) fast jpeg transformations cannot be done in place, so we'll employ an
502  // intermediate image
503  QString intermediateName = QString("%1_intermdiate.jpg").arg(oldName);
504  transformImage( oldName, intermediateName, transformation );
505 
506  //2.) If the photo has never been saved and an orig file in the temporary
507  // directory does not exist then the current file is the original version. we
508  // must make sure that this original photo is maintained using an orig file so
509  // in the future users can revert the photo to it's original form.
510  QString origName = subalbum->getAlbum()->getTmpDir() + QString("/0_%1_orig.jpg")
511  .arg(initialPhotoNumber);
512  QDir tmpDir;
513  if( !getEverSaved() && !tmpDir.exists(origName) )
514  {
515  moveFile( oldName, origName );
516  moveFile( intermediateName, imageLocation );
517  }
518  else
519  {
520  moveFile( intermediateName, imageLocation );
521  }
522  }
523 
524  //image now modified from original form so orig file needs to be kept
525  recentlyReverted = false;
526 
527  //construct smaller iamges
529 }
int initialSubalbumNumber
Definition: photo.h:202
QString slideshowLocation
Definition: photo.h:212
bool moveFile(QString oldName, QString newName)
Definition: fileTools.cpp:40
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
Album * getAlbum()
returns the album pointer
Definition: subalbum.cpp:95
bool recentlyReverted
Has the photo recently been reverted to it&#39;s original form? If so during the next save the orig file ...
Definition: photo.h:228
bool transformImage(QString fileIn, QString fileOut, TRANSFORM_CODE transformation)
Apply image transformation on image.
Definition: imageTools.cpp:112
bool needsSaving
Unsaved modifications?
Definition: photo.h:221
QString thumbnailLocation
Definition: photo.h:213
bool getEverSaved()
Returns if the image has ever been saved to a permanant location.
Definition: photo.cpp:534
QString getTmpDir()
Returns the temporary directory for use when modifying and adding new images.
Definition: album.cpp:142
QString imageLocation
Filenames.
Definition: photo.h:211
bool constructSmallerImages()
Construct thumbnail and slideshow images, load up thumbnail image, and set photo has being modified...
Definition: photo.cpp:85
int initialPhotoNumber
Definition: photo.h:199

§ constructSmallerImages()

bool Photo::constructSmallerImages ( )

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

Definition at line 85 of file photo.cpp.

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

Referenced by applyTransformation(), and setImage().

86 {
87  //construct and save slideshow and thumbnail images
88  QImage TslideshowImage, TthumbnailImage;
89  constructImages( imageLocation, TslideshowImage, TthumbnailImage );
90  TslideshowImage.save( slideshowLocation, "JPEG", 95 );
91  TthumbnailImage.save( thumbnailLocation, "JPEG", 95 );
92 
93  //load up thumbnail image
94  delete thumbnailImage;
95  thumbnailImage = new QImage(thumbnailLocation);
96 
97  //image is being stored in temp location, needs saving!
98  needsSaving = true;
99 
100  //set the subalbum as being modified and return
102  return true;
103 }
QString slideshowLocation
Definition: photo.h:212
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
bool needsSaving
Unsaved modifications?
Definition: photo.h:221
QString thumbnailLocation
Definition: photo.h:213
void constructImages(QString imageName, QImage &slideshowImage, QImage &thumbnailImage)
Constructs slideshow and thumbnail images for a full sized image.
Definition: imageTools.cpp:69
QString imageLocation
Filenames.
Definition: photo.h:211
QImage * thumbnailImage
Thumbnail Image.
Definition: photo.h:208
void setModified()
Definition: subalbum.cpp:172

§ exportToXML()

void Photo::exportToXML ( Q3TextStream &  stream)

Exports photo to xml.

Definition at line 414 of file photo.cpp.

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

Referenced by Subalbum::exportToXML().

415 {
416  QFileInfo info;
417 
418  //write photo information
419  stream << " <photo>\n";
420  //-----
421  stream << " <description>" << fixXMLString(description) << "</description>\n";
422  //-----
423  //full image
424  info.setFile( getImageFilename() );
425  QDateTime modified = info.lastModified();
426  stream << " <image>\n";
427  stream << " <md5>" << fixXMLString(imageChecksum) << "</md5>\n";
428  stream << " <modified>";
429  stream << modified.date().year() << " ";
430  stream << modified.date().month() << " ";
431  stream << modified.date().day() << " ";
432  stream << modified.time().hour() << " ";
433  stream << modified.time().minute() << " ";
434  stream << modified.time().second() << " ";
435  stream << modified.time().msec() << "</modified>\n";
436  stream << " </image>\n";
437  //-----
438  //slidehow image
439  info.setFile( getSlideshowFilename() );
440  modified = info.lastModified();
441  stream << " <slideshow>\n";
442  stream << " <md5>" << fixXMLString(slideshowChecksum) << "</md5>\n";
443  stream << " <modified>";
444  stream << modified.date().year() << " ";
445  stream << modified.date().month() << " ";
446  stream << modified.date().day() << " ";
447  stream << modified.time().hour() << " ";
448  stream << modified.time().minute() << " ";
449  stream << modified.time().second() << " ";
450  stream << modified.time().msec() << "</modified>\n";
451  stream << " </slideshow>\n";
452  //-----
453  //thumbnail image
454  info.setFile( getThumbnailFilename() );
455  modified = info.lastModified();
456  stream << " <thumb>\n";
457  stream << " <md5>" << fixXMLString(thumbnailChecksum) << "</md5>\n";
458  stream << " <modified>";
459  stream << modified.date().year() << " ";
460  stream << modified.date().month() << " ";
461  stream << modified.date().day() << " ";
462  stream << modified.time().hour() << " ";
463  stream << modified.time().minute() << " ";
464  stream << modified.time().second() << " ";
465  stream << modified.time().msec() << "</modified>\n";
466  stream << " </thumb>\n";
467  //-----
468  stream << " </photo>\n";
469 }
QString getImageFilename()
Gets the image filename.
Definition: photo.cpp:192
QString imageChecksum
MD5 checksums, used to determine if image/thumbnail have been changed.
Definition: photo.h:216
QString description
Photo description.
Definition: photo.h:205
QString getThumbnailFilename()
Gets the thumbnail filename.
Definition: photo.cpp:194
QString slideshowChecksum
Definition: photo.h:217
QString thumbnailChecksum
Definition: photo.h:218
QString getSlideshowFilename()
Gets the slideshow filename.
Definition: photo.cpp:193
QString fixXMLString(QString text)
Fix strings before exporting to XML such that & becomes &, etc...
Definition: xmlTools.cpp:36

§ flipHorizontally()

void Photo::flipHorizontally ( )

Flips image about horizontal axis.

Definition at line 473 of file photo.cpp.

References applyTransformation(), and FLIP_H.

void applyTransformation(TRANSFORM_CODE transformation)
Apply transformation.
Definition: photo.cpp:476

§ flipVertically()

void Photo::flipVertically ( )

Flips image about vertical axis.

Definition at line 474 of file photo.cpp.

References applyTransformation(), and FLIP_V.

void applyTransformation(TRANSFORM_CODE transformation)
Apply transformation.
Definition: photo.cpp:476

§ getDescription()

QString Photo::getDescription ( )

Gets the description.

Definition at line 208 of file photo.cpp.

References description.

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

208 { return QString(description); }
QString description
Photo description.
Definition: photo.h:205

§ getEverSaved()

bool Photo::getEverSaved ( )

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

Definition at line 534 of file photo.cpp.

References everSaved.

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

534 { return everSaved; }
bool everSaved
Has the photo ever been saved?
Definition: photo.h:224

§ getImageChecksum()

QString Photo::getImageChecksum ( )

Get image checksum.

Definition at line 200 of file photo.cpp.

References imageChecksum.

Referenced by Subalbum::importFromDisk().

200 { return imageChecksum; }
QString imageChecksum
MD5 checksums, used to determine if image/thumbnail have been changed.
Definition: photo.h:216

§ getImageFilename()

QString Photo::getImageFilename ( )

§ getInitialPhotoNumber()

int Photo::getInitialPhotoNumber ( )

Returns initial photo number.

Definition at line 608 of file photo.cpp.

References initialPhotoNumber.

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

608 { return initialPhotoNumber; }
int initialPhotoNumber
Definition: photo.h:199

§ getInitialSubalbumNumber()

int Photo::getInitialSubalbumNumber ( )

Returns initial subalbum number.

Definition at line 611 of file photo.cpp.

References initialSubalbumNumber.

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

611 { return initialSubalbumNumber; }
int initialSubalbumNumber
Definition: photo.h:202

§ getNeedsSavingVal()

bool Photo::getNeedsSavingVal ( )

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

Definition at line 531 of file photo.cpp.

References needsSaving.

Referenced by Album::exportSubalbumImages().

531 { return needsSaving; }
bool needsSaving
Unsaved modifications?
Definition: photo.h:221

§ getNext()

Photo * Photo::getNext ( )

§ getPrev()

Photo * Photo::getPrev ( )

Returns the previous photo pointer.

Definition at line 224 of file photo.cpp.

References prev.

Referenced by SlideshowWidget::backupPhoto(), Subalbum::photoMoved(), Subalbum::removePhoto(), EditingInterface::setPhoto(), EditingInterface::showNextPrevFirstLastPhoto(), and EditingInterface::showPrevPhoto().

224 { return prev; }
Photo * prev
Pointer to prev photo.
Definition: photo.h:193

§ getRecentlyReverted()

bool Photo::getRecentlyReverted ( )

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

Definition at line 547 of file photo.cpp.

References recentlyReverted.

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

548 {
549  return recentlyReverted;
550 }
bool recentlyReverted
Has the photo recently been reverted to it&#39;s original form? If so during the next save the orig file ...
Definition: photo.h:228

§ getSlideshowChecksum()

QString Photo::getSlideshowChecksum ( )

Get thumbanil checksum.

Definition at line 202 of file photo.cpp.

References slideshowChecksum.

Referenced by Subalbum::importFromDisk().

202 { return slideshowChecksum; }
QString slideshowChecksum
Definition: photo.h:217

§ getSlideshowFilename()

QString Photo::getSlideshowFilename ( )

Gets the slideshow filename.

Definition at line 193 of file photo.cpp.

References slideshowLocation.

Referenced by AlbumStatistics::AlbumStatistics(), Album::exportCompressedWebAlbum(), Album::exportSubalbumImages(), exportToXML(), and PhotoDescEdit::PhotoDescEdit().

193 { return slideshowLocation; }
QString slideshowLocation
Definition: photo.h:212

§ getThumbnailChecksum()

QString Photo::getThumbnailChecksum ( )

Get thumbanil checksum.

Definition at line 201 of file photo.cpp.

References thumbnailChecksum.

Referenced by Subalbum::importFromDisk().

201 { return thumbnailChecksum; }
QString thumbnailChecksum
Definition: photo.h:218

§ getThumbnailFilename()

QString Photo::getThumbnailFilename ( )

§ getThumbnailImage()

QImage * Photo::getThumbnailImage ( )

Gets thumbnail image.

Definition at line 83 of file photo.cpp.

References thumbnailImage.

83 { return thumbnailImage; }
QImage * thumbnailImage
Thumbnail Image.
Definition: photo.h:208

§ importFromDisk()

QDateTime * Photo::importFromDisk ( QDomNode *  root)

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

Definition at line 239 of file photo.cpp.

References description, imageChecksum, slideshowChecksum, and thumbnailChecksum.

Referenced by Subalbum::importFromDisk().

240 {
241  //create modified date/time object for returning
242  QDateTime* modified = new QDateTime[3];
243 
244  QDomNode node = root->firstChild();
245  QDomText val;
246  while( !node.isNull() )
247  {
248  //------------------------------------------------------------
249  //photo description
250  if( node.isElement() && node.nodeName() == "description" )
251  {
252  val = node.firstChild().toText();
253  if(!val.isNull())
254  description = val.nodeValue();
255  description.replace("\\&quot;","\"");
256  }
257  //------------------------------------------------------------
258  //image information
259  else if( node.isElement() && node.nodeName() == "image" )
260  {
261  QDomNode childNode = node.firstChild();
262  while( !childNode.isNull() )
263  {
264  //------------------------------------------------------------
265  if( childNode.isElement() && childNode.nodeName() == "md5" )
266  {
267  val = childNode.firstChild().toText();
268  if(!val.isNull())
269  imageChecksum = val.nodeValue();
270  }
271  //------------------------------------------------------------
272  else if( childNode.isElement() && childNode.nodeName() == "modified" )
273  {
274  val = childNode.firstChild().toText();
275 
276  //split value based on spaces, should be 7 fields
277  QStringList vals = QStringList::split( QRegExp(" "), val.nodeValue() );
278  int i=0;
279  int intVals[7];
280  QStringList::Iterator it;
281  for ( it = vals.begin(); it != vals.end(); ++it )
282  {
283  //sanity check incase more fields are provided than there should be
284  if(i >6)
285  break;
286 
287  intVals[i] = QString(*it).toInt();
288  i++;
289  }
290  modified[0].setDate( QDate(intVals[0], intVals[1], intVals[2]) );
291  modified[0].setTime( QTime(intVals[3], intVals[4], intVals[5], intVals[6]) );
292  }
293  //------------------------------------------------------------
294  childNode = childNode.nextSibling();
295  }
296  }
297  //------------------------------------------------------------
298  //slideshow information
299  else if( node.isElement() && node.nodeName() == "slideshow" )
300  {
301  QDomNode childNode = node.firstChild();
302  while( !childNode.isNull() )
303  {
304  //------------------------------------------------------------
305  if( childNode.isElement() && childNode.nodeName() == "md5" )
306  {
307  val = childNode.firstChild().toText();
308  if(!val.isNull())
309  slideshowChecksum = val.nodeValue();
310  }
311  //------------------------------------------------------------
312  else if( childNode.isElement() && childNode.nodeName() == "modified" )
313  {
314  val = childNode.firstChild().toText();
315 
316  //split value based on spaces, should be 6 fields
317  QStringList vals = QStringList::split( QRegExp(" "), val.nodeValue() );
318  int i=0;
319  int intVals[7];
320  QStringList::Iterator it;
321  for ( it = vals.begin(); it != vals.end(); ++it )
322  {
323  //sanity check incase more fields are provided than there should be
324  if(i >6)
325  break;
326 
327  intVals[i] = QString(*it).toInt();
328  i++;
329  }
330  modified[1].setDate( QDate(intVals[0], intVals[1], intVals[2]) );
331  modified[1].setTime( QTime(intVals[3], intVals[4], intVals[5], intVals[6]) );
332  }
333  //------------------------------------------------------------
334  childNode = childNode.nextSibling();
335  }
336  }
337  //------------------------------------------------------------
338  //slideshow information
339  else if( node.isElement() && node.nodeName() == "thumb" )
340  {
341  QDomNode childNode = node.firstChild();
342  while( !childNode.isNull() )
343  {
344  //------------------------------------------------------------
345  if( childNode.isElement() && childNode.nodeName() == "md5" )
346  {
347  val = childNode.firstChild().toText();
348  if(!val.isNull())
349  thumbnailChecksum = val.nodeValue();
350  }
351  //------------------------------------------------------------
352  else if( childNode.isElement() && childNode.nodeName() == "modified" )
353  {
354  val = childNode.firstChild().toText();
355 
356  //split value based on spaces, should be 6 fields
357  QStringList vals = QStringList::split( QRegExp(" "), val.nodeValue() );
358  int i=0;
359  int intVals[7];
360  QStringList::Iterator it;
361  for ( it = vals.begin(); it != vals.end(); ++it )
362  {
363  //sanity check incase more fields are provided than there should be
364  if(i >6)
365  break;
366 
367  intVals[i] = QString(*it).toInt();
368  i++;
369  }
370  modified[2].setDate( QDate(intVals[0], intVals[1], intVals[2]) );
371  modified[2].setTime( QTime(intVals[3], intVals[4], intVals[5], intVals[6]) );
372  }
373  //------------------------------------------------------------
374  childNode = childNode.nextSibling();
375  }
376  }
377  //------------------------------------------------------------
378  //------------------------------------------------------------
379  //Handle md5 info as specified in 1.0a and 1.0a2 xml format
380  //image md5
381  else if( node.isElement() && node.nodeName() == "imageMD5" )
382  {
383  val = node.firstChild().toText();
384  if(!val.isNull())
385  imageChecksum = val.nodeValue();
386  }
387  //------------------------------------------------------------
388  //slideshow md5
389  else if( node.isElement() && node.nodeName() == "slideMD5" )
390  {
391  val = node.firstChild().toText();
392  if(!val.isNull())
393  slideshowChecksum = val.nodeValue();
394  }
395  //------------------------------------------------------------
396  //thumbnail md5
397  else if( node.isElement() && node.nodeName() == "thumbMD5" )
398  {
399  val = node.firstChild().toText();
400  if(!val.isNull())
401  thumbnailChecksum = val.nodeValue();
402  }
403  //------------------------------------------------------------
404  //------------------------------------------------------------
405  //advance to next node
406  node = node.nextSibling();
407  //------------------------------------------------------------
408  }
409 
410  //return modification dates read in
411  return modified;
412 }
QString imageChecksum
MD5 checksums, used to determine if image/thumbnail have been changed.
Definition: photo.h:216
QString description
Photo description.
Definition: photo.h:205
QString slideshowChecksum
Definition: photo.h:217
QString thumbnailChecksum
Definition: photo.h:218

§ originalImageFilename()

QString Photo::originalImageFilename ( )

orig filename

Definition at line 572 of file photo.cpp.

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

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

573 {
574  //determining the an images original filename is tricky
575  //if the photo has never been saved check for presence of an _orig file,
576  //otherwise use the current filename since the photo has not yet been modified
577  if( !getEverSaved() )
578  {
579  QString tempOrigLocation = imageLocation;
580  tempOrigLocation.truncate( imageLocation.length() - 4 );
581  tempOrigLocation = tempOrigLocation + "_orig.jpg";
582 
583  QDir tmpDir;
584  if(tmpDir.exists( tempOrigLocation ) )
585  return tempOrigLocation;
586  else
587  return imageLocation;
588  }
589  //if the photo was previously saved, it's original form could either be:
590  //1.) the permanant storage location + _orig
591  //2.) the permanant storage location
592  else
593  {
594  QString storedOrigLocation = subalbum->getAlbum()->getSaveLocation() +
595  QString("/img/%1/%2_orig.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
596 
597  QString lastSavedLocation = subalbum->getAlbum()->getSaveLocation() +
598  QString("/img/%1/%2.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
599 
600  QDir tmpDir;
601  if(tmpDir.exists( storedOrigLocation ) )
602  return storedOrigLocation;
603  else
604  return lastSavedLocation;
605  }
606 }
int initialSubalbumNumber
Definition: photo.h:202
QString getSaveLocation()
Returns the current save location of all images.
Definition: album.cpp:141
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
Album * getAlbum()
returns the album pointer
Definition: subalbum.cpp:95
bool getEverSaved()
Returns if the image has ever been saved to a permanant location.
Definition: photo.cpp:534
QString imageLocation
Filenames.
Definition: photo.h:211
int initialPhotoNumber
Definition: photo.h:199

§ revertPhoto()

void Photo::revertPhoto ( )

revert photo to original form

Definition at line 557 of file photo.cpp.

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

Referenced by EditingInterface::revertCurrentPhoto().

558 {
559  //ignore if revert is not possible
560  if(!revertPossible())
561  return;
562 
563  //set image to reverted form
564  QString origName = originalImageFilename();
565  setImage( origName );
566 
567  //recently reverted, orig file should be
568  //removed during next save since it's redundant
569  recentlyReverted = true;
570 }
QString originalImageFilename()
orig filename
Definition: photo.cpp:572
bool recentlyReverted
Has the photo recently been reverted to it&#39;s original form? If so during the next save the orig file ...
Definition: photo.h:228
bool setImage(QString imageName, QString slideshowName, QString thumbnailName)
Setup photo using preexisting full size, slideshow, and thumbnail images.
Definition: photo.cpp:105
bool revertPossible()
can photo be reverted to a differnt original form
Definition: photo.cpp:537

§ revertPossible()

bool Photo::revertPossible ( )

can photo be reverted to a differnt original form

Definition at line 537 of file photo.cpp.

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

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

538 {
539  //if photo not recently reverted and orig and current filenames differ
540  QString newName = getImageFilename();
541  QString origName = originalImageFilename();
542 
543  return ( !recentlyReverted &&
544  origName.compare( newName ) !=0 );
545 }
QString getImageFilename()
Gets the image filename.
Definition: photo.cpp:192
QString originalImageFilename()
orig filename
Definition: photo.cpp:572
bool recentlyReverted
Has the photo recently been reverted to it&#39;s original form? If so during the next save the orig file ...
Definition: photo.h:228

§ rotate270()

void Photo::rotate270 ( )

Rotates image clockwise 270 degrees.

Definition at line 472 of file photo.cpp.

References applyTransformation(), and ROTATE_270.

void applyTransformation(TRANSFORM_CODE transformation)
Apply transformation.
Definition: photo.cpp:476

§ rotate90()

void Photo::rotate90 ( )

Rotates image clockwise 90 degrees.

Definition at line 471 of file photo.cpp.

References applyTransformation(), and ROTATE_90.

void applyTransformation(TRANSFORM_CODE transformation)
Apply transformation.
Definition: photo.cpp:476

§ setDescription()

void Photo::setDescription ( QString  val)

Sets the description.

Definition at line 210 of file photo.cpp.

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

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

211 {
212  //set empty strings as null, takes up less space and necessary
213  //to check for string modification
214  if( val.isEmpty() )
215  val = QString::null;
216 
217  if(description.compare(val) != 0)
218  {
219  description = val;
221  }
222 }
QString description
Photo description.
Definition: photo.h:205
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
void setModified()
Definition: subalbum.cpp:172

§ setEverSaved()

void Photo::setEverSaved ( bool  val)

sets everSaved

Definition at line 535 of file photo.cpp.

References everSaved.

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

535 { everSaved = val; }
bool everSaved
Has the photo ever been saved?
Definition: photo.h:224

§ setImage() [1/3]

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 105 of file photo.cpp.

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

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

108 {
109  //set filenames, we'll lazily compute MD5 checksums for files when saving
110  imageLocation = imageName;
111  slideshowLocation = slideshowName;
112  thumbnailLocation = thumbnailName;
113 
114  //load thumbnail image
115  delete thumbnailImage;
116  thumbnailImage = new QImage(thumbnailName);
117  if(thumbnailImage->isNull()) return false;
118 
119  //image just loaded, no changes yet
120  needsSaving = false;
121  return true;
122 }
QString slideshowLocation
Definition: photo.h:212
bool needsSaving
Unsaved modifications?
Definition: photo.h:221
QString thumbnailLocation
Definition: photo.h:213
QString imageLocation
Filenames.
Definition: photo.h:211
QImage * thumbnailImage
Thumbnail Image.
Definition: photo.h:208

§ setImage() [2/3]

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 124 of file photo.cpp.

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

125 {
126  //this is a new photo, use a unique ID to construct temporary filenames
127  setEverSaved(false);
129  initialPhotoNumber = uniqueID;
130 
131  QString tmpDir = subalbum->getAlbum()->getTmpDir();
132  imageLocation = QString("%1/%2_%3.jpg") .arg(tmpDir).arg(initialSubalbumNumber).arg(initialPhotoNumber);
133  slideshowLocation = QString("%1/%2_%3_slideshow.jpg").arg(tmpDir).arg(initialSubalbumNumber).arg(initialPhotoNumber);
134  thumbnailLocation = QString("%1/%2_%3_thumb.jpg") .arg(tmpDir).arg(initialSubalbumNumber).arg(initialPhotoNumber);
135 
136  //if image in jpeg format simply copy file over
137  if( isJpeg(imageName) )
138  {
139  copyFile( imageName, imageLocation );
140  }
141  //otherwise we must load it up and save it out as jpeg
142  else
143  {
144  //if unable to open image at all using Qt then giveup
145  QImage tempImage(imageName);
146  if( tempImage.isNull() ) { return false; }
147 
148  //save out as jpeg
149  tempImage.save( imageLocation, "JPEG", 95 );
150  }
151 
152  //construct smaller iamges
153  return constructSmallerImages();
154 }
int initialSubalbumNumber
Definition: photo.h:202
QString slideshowLocation
Definition: photo.h:212
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
Album * getAlbum()
returns the album pointer
Definition: subalbum.cpp:95
bool copyFile(QString oldFilePath, QString newFilePath)
Copies a file from one location to another.
Definition: fileTools.cpp:61
void setEverSaved(bool val)
sets everSaved
Definition: photo.cpp:535
QString thumbnailLocation
Definition: photo.h:213
bool isJpeg(const char *filename)
Checks to see if an image is a valid jpg by seeing if the image dimensions can be read...
Definition: imageTools.cpp:33
QString getTmpDir()
Returns the temporary directory for use when modifying and adding new images.
Definition: album.cpp:142
QString imageLocation
Filenames.
Definition: photo.h:211
bool constructSmallerImages()
Construct thumbnail and slideshow images, load up thumbnail image, and set photo has being modified...
Definition: photo.cpp:85
int initialPhotoNumber
Definition: photo.h:199

§ setImage() [3/3]

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 156 of file photo.cpp.

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

157 {
158  //if the image has been saved then simply change the image,slideshow/thubnail
159  //filename handles to point to the temporary directory. We don't need to worry about backing up the
160  //image because the new version will be written to the temporary directory and the save location
161  if( getEverSaved() )
162  {
164  QString("/%1_%2.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
166  QString("/%1_%2_slideshow.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
168  QString("/%1_%2_thumb.jpg").arg(initialSubalbumNumber).arg(initialPhotoNumber);
169  }
170  //otherwise image has never been saved, make sure original form has been backed up!
171  else
172  {
173  QString tempOrigLocation = imageLocation;
174  tempOrigLocation.truncate( imageLocation.length() - 4 );
175  tempOrigLocation = tempOrigLocation + "_orig.jpg";
176 
177  QDir tmpDir;
178  if(!tmpDir.exists( tempOrigLocation ) )
179  { copyFile( imageLocation, tempOrigLocation ); }
180  }
181 
182  //copy over full size image
183  copyFile( editedImageFilename, imageLocation );
184 
185  //reset revert flag since image has not been modified
186  recentlyReverted = false;
187 
188  //construct smaller iamges
189  return constructSmallerImages();
190 }
int initialSubalbumNumber
Definition: photo.h:202
QString slideshowLocation
Definition: photo.h:212
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
Album * getAlbum()
returns the album pointer
Definition: subalbum.cpp:95
bool recentlyReverted
Has the photo recently been reverted to it&#39;s original form? If so during the next save the orig file ...
Definition: photo.h:228
bool copyFile(QString oldFilePath, QString newFilePath)
Copies a file from one location to another.
Definition: fileTools.cpp:61
QString thumbnailLocation
Definition: photo.h:213
bool getEverSaved()
Returns if the image has ever been saved to a permanant location.
Definition: photo.cpp:534
QString getTmpDir()
Returns the temporary directory for use when modifying and adding new images.
Definition: album.cpp:142
QString imageLocation
Filenames.
Definition: photo.h:211
bool constructSmallerImages()
Construct thumbnail and slideshow images, load up thumbnail image, and set photo has being modified...
Definition: photo.cpp:85
int initialPhotoNumber
Definition: photo.h:199

§ setImageChecksum()

void Photo::setImageChecksum ( QString  val)

Update image checksum.

Definition at line 204 of file photo.cpp.

References imageChecksum.

Referenced by Album::exportSubalbumImages().

204 { imageChecksum = val; }
QString imageChecksum
MD5 checksums, used to determine if image/thumbnail have been changed.
Definition: photo.h:216

§ setImageFilename()

void Photo::setImageFilename ( QString  val)

Sets the image filename.

Definition at line 196 of file photo.cpp.

References imageLocation.

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

196 { imageLocation = val; }
QString imageLocation
Filenames.
Definition: photo.h:211

§ setInitialPhotoNumber()

void Photo::setInitialPhotoNumber ( int  val)

Sets initial photo number.

Definition at line 609 of file photo.cpp.

References initialPhotoNumber.

Referenced by Album::reorderSubalbumImages().

609 { initialPhotoNumber = val; }
int initialPhotoNumber
Definition: photo.h:199

§ setInitialSubalbumNumber()

void Photo::setInitialSubalbumNumber ( int  val)

Sets initial subalbum number.

Definition at line 612 of file photo.cpp.

References initialSubalbumNumber.

Referenced by Album::reorderSubalbumImages().

612 { initialSubalbumNumber = val; }
int initialSubalbumNumber
Definition: photo.h:202

§ setNeedsSavingVal()

void Photo::setNeedsSavingVal ( bool  val)

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

Definition at line 532 of file photo.cpp.

References needsSaving.

Referenced by Album::exportSubalbumImages().

532 { needsSaving = val; }
bool needsSaving
Unsaved modifications?
Definition: photo.h:221

§ setNext()

void Photo::setNext ( Photo val)

Sets next photo pointer.

Definition at line 233 of file photo.cpp.

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

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

234 {
235  next = val;
237 }
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
Photo * next
Pointer to next photo.
Definition: photo.h:196
void setModified()
Definition: subalbum.cpp:172

§ setPrev()

void Photo::setPrev ( Photo val)

Sets prev photo pointer.

Definition at line 227 of file photo.cpp.

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

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

228 {
229  prev = val;
231 }
Subalbum * subalbum
Subalbum photo is in.
Definition: photo.h:190
Photo * prev
Pointer to prev photo.
Definition: photo.h:193
void setModified()
Definition: subalbum.cpp:172

§ setRecentlyReverted()

void Photo::setRecentlyReverted ( bool  val)

reset the recently reverted value to val

Definition at line 552 of file photo.cpp.

References recentlyReverted.

Referenced by Album::removeStagnantOrigFiles().

553 {
554  recentlyReverted = val;
555 }
bool recentlyReverted
Has the photo recently been reverted to it&#39;s original form? If so during the next save the orig file ...
Definition: photo.h:228

§ setSlideshowChecksum()

void Photo::setSlideshowChecksum ( QString  val)

Update slideshow checksum.

Definition at line 206 of file photo.cpp.

References slideshowChecksum.

Referenced by Album::exportSubalbumImages().

206 { slideshowChecksum = val; }
QString slideshowChecksum
Definition: photo.h:217

§ setSlideshowFilename()

void Photo::setSlideshowFilename ( QString  val)

Sets the slideshow filename.

Definition at line 197 of file photo.cpp.

References slideshowLocation.

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

197 { slideshowLocation = val; }
QString slideshowLocation
Definition: photo.h:212

§ setThumbnailChecksum()

void Photo::setThumbnailChecksum ( QString  val)

Update thumbnail checksum.

Definition at line 205 of file photo.cpp.

References thumbnailChecksum.

Referenced by Album::exportSubalbumImages().

205 { thumbnailChecksum = val; }
QString thumbnailChecksum
Definition: photo.h:218

§ setThumbnailFilename()

void Photo::setThumbnailFilename ( QString  val)

Sets the thumbnail filename.

Definition at line 198 of file photo.cpp.

References thumbnailLocation.

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

198 { thumbnailLocation = val; }
QString thumbnailLocation
Definition: photo.h:213

Member Data Documentation

§ description

QString Photo::description
private

Photo description.

Definition at line 205 of file photo.h.

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

§ everSaved

bool Photo::everSaved
private

Has the photo ever been saved?

Definition at line 224 of file photo.h.

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

§ imageChecksum

QString Photo::imageChecksum
private

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

Definition at line 216 of file photo.h.

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

§ imageLocation

QString Photo::imageLocation
private

§ initialPhotoNumber

int Photo::initialPhotoNumber
private

§ initialSubalbumNumber

int Photo::initialSubalbumNumber
private

§ needsSaving

bool Photo::needsSaving
private

Unsaved modifications?

Definition at line 221 of file photo.h.

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

§ next

Photo* Photo::next
private

Pointer to next photo.

Definition at line 196 of file photo.h.

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

§ prev

Photo* Photo::prev
private

Pointer to prev photo.

Definition at line 193 of file photo.h.

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

§ recentlyReverted

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 228 of file photo.h.

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

§ slideshowChecksum

QString Photo::slideshowChecksum
private

§ slideshowLocation

QString Photo::slideshowLocation
private

§ subalbum

Subalbum* Photo::subalbum
private

§ thumbnailChecksum

QString Photo::thumbnailChecksum
private

§ thumbnailImage

QImage* Photo::thumbnailImage
private

Thumbnail Image.

Definition at line 208 of file photo.h.

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

§ thumbnailLocation

QString Photo::thumbnailLocation
private

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