recentAlbums.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003-2005 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it
00005 //  and/or modify it under the terms of the GNU General
00006 //  Public License as published by the Free Software
00007 //  Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //==============================================
00010 
00011 //Systemwide includes
00012 #include <qstring.h>
00013 
00014 //Projectwide includes
00015 #include "recentAlbums.h"
00016 
00017 #define MAX_RECENT_ALBUMS 9
00018 
00019 //==============================================
00020 RecentAlbums::RecentAlbums()
00021 {
00022   maxItems = MAX_RECENT_ALBUMS;
00023 }
00024 //==============================================
00025 void RecentAlbums::clearList()
00026 {
00027   albumNames.clear();
00028   albumLocations.clear();
00029   albumPhotoCounts.clear();
00030 }
00031 //==============================================
00032 int RecentAlbums::numEntries()
00033 {
00034   return albumNames.count();
00035 }
00036 //==============================================
00037 int RecentAlbums::getMaxItems()
00038 {
00039   return maxItems;
00040 }
00041 //==============================================
00042 void RecentAlbums::getEntry ( int index, QString& name, QString& location, QString& photoCount )
00043 {
00044   name       = *( albumNames.at       (index) );
00045   location   = *( albumLocations.at   (index) );
00046   photoCount = *( albumPhotoCounts.at (index) );  
00047 }
00048 //==============================================
00049 void RecentAlbums::insertEntry ( QString name, 
00050                                  QString location, 
00051                                  QString photos, 
00052                                  bool insertAtBack )
00053 {
00054   //items are inserted at back during intialization of list when
00055   //starting up the program. no duplicates should exist so no checking is performed
00056   if(insertAtBack || albumNames.count() == 0)
00057   {
00058     albumNames.append      ( name     );
00059     albumLocations.append  ( location );
00060     albumPhotoCounts.append( photos   ); 
00061   }
00062   //items are inserted at the front of the list when either:
00063   //1.) a new album is saved or
00064   //2.) an album is opened.
00065   //the list must then be checked for duplicates and any such duplicates should be removed
00066   else
00067   {
00068     //prepend item
00069     QStringList::Iterator namesIterator       = ++albumNames.prepend       ( name     );
00070     QStringList::Iterator locationsIterator   = ++albumLocations.prepend   ( location );
00071     QStringList::Iterator photoCountsIterator = ++albumPhotoCounts.prepend ( photos   );
00072 
00073     //search list for dupes
00074     while( true )
00075     {
00076       //if location matches remove item
00077       if( location.compare(*locationsIterator) == 0 )
00078       {
00079         albumNames.remove      ( namesIterator       );
00080         albumLocations.remove  ( locationsIterator   );
00081         albumPhotoCounts.remove( photoCountsIterator );
00082         break;
00083       }
00084 
00085       //end of list? stop
00086       if( namesIterator == albumNames.end() ) break;
00087       
00088       //move to next item.
00089       namesIterator++;
00090       locationsIterator++;
00091       photoCountsIterator++; 
00092     }
00093 
00094   }//end else
00095 
00096   //truncate list as necessary
00097   while(albumNames.count() > maxItems )
00098   {
00099     albumNames.remove( albumNames.last() );
00100     albumLocations.remove( albumLocations.last() );
00101     albumPhotoCounts.remove( albumPhotoCounts.last() );
00102   }  
00103 }
00104 //==============================================

Generated on Wed Jan 24 05:38:05 2007 for AlbumShaper by  doxygen 1.5.1