AlbumShaper  1.0a3
recentAlbums.cpp
Go to the documentation of this file.
1 //==============================================
2 // copyright : (C) 2003-2005 by Will Stokes
3 //==============================================
4 // This program is free software; you can redistribute it
5 // and/or modify it under the terms of the GNU General
6 // Public License as published by the Free Software
7 // Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //==============================================
10 
11 //Systemwide includes
12 #include <qstring.h>
13 
14 //Projectwide includes
15 #include "recentAlbums.h"
16 
17 #define MAX_RECENT_ALBUMS 9
18 
19 //==============================================
21 {
23 }
24 //==============================================
26 {
27  albumNames.clear();
28  albumLocations.clear();
29  albumPhotoCounts.clear();
30 }
31 //==============================================
33 {
34  return albumNames.count();
35 }
36 //==============================================
38 {
39  return maxItems;
40 }
41 //==============================================
42 void RecentAlbums::getEntry ( int index, QString& name, QString& location, QString& photoCount )
43 {
44  name = *( albumNames.at (index) );
45  location = *( albumLocations.at (index) );
46  photoCount = *( albumPhotoCounts.at (index) );
47 }
48 //==============================================
49 void RecentAlbums::insertEntry ( QString name,
50  QString location,
51  QString photos,
52  bool insertAtBack )
53 {
54  //items are inserted at back during intialization of list when
55  //starting up the program. no duplicates should exist so no checking is performed
56  if(insertAtBack || albumNames.count() == 0)
57  {
58  albumNames.append ( name );
59  albumLocations.append ( location );
60  albumPhotoCounts.append( photos );
61  }
62  //items are inserted at the front of the list when either:
63  //1.) a new album is saved or
64  //2.) an album is opened.
65  //the list must then be checked for duplicates and any such duplicates should be removed
66  else
67  {
68  //prepend item
69  albumNames.prepend(name);
70  albumLocations.prepend(location);
71  albumPhotoCounts.prepend(photos);
72 
73  QStringList::Iterator namesIterator=albumNames.find(name);
74  QStringList::Iterator locationsIterator=albumLocations.find(location);
75  QStringList::Iterator photoCountsIterator=albumPhotoCounts.find(photos);
76 
77  //search list for dupes
78  while( true )
79  {
80  //move to next item.
81  namesIterator++;
82  locationsIterator++;
83  photoCountsIterator++;
84 
85  //if location matches remove item
86  if( location.compare(*locationsIterator) == 0 )
87  {
88  albumNames.remove ( namesIterator );
89  albumLocations.remove ( locationsIterator );
90  albumPhotoCounts.remove( photoCountsIterator );
91  break;
92  }
93 
94  //end of list? stop
95  if( namesIterator == albumNames.end() ) break;
96  }
97 
98  }//end else
99 
100  //truncate list as necessary
101  while(albumNames.count() > maxItems )
102  {
103  albumNames.remove( albumNames.last() );
104  albumLocations.remove( albumLocations.last() );
105  albumPhotoCounts.remove( albumPhotoCounts.last() );
106  }
107 }
108 //==============================================
#define MAX_RECENT_ALBUMS
void insertEntry(QString name, QString location, QString photos="-1", bool insertAtBack=true)
void getEntry(int index, QString &name, QString &location, QString &photoCount)
QStringList albumPhotoCounts
Definition: recentAlbums.h:57
void clearList()
QStringList albumNames
lists of album names and locations
Definition: recentAlbums.h:55
QStringList albumLocations
Definition: recentAlbums.h:56
uint maxItems
max allowable items in list
Definition: recentAlbums.h:60