1 // Copyright (C) 2008, Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #ifndef RECENTLYPLAYEDGAMELIST_H
19 #define RECENTLYPLAYEDGAMELIST_H
24 #include <sigc++/trackable.h>
26 #include "xmlhelper.h"
29 class RecentlyPlayedGame;
31 //! A list of games that we've recently played.
33 * This is only used for network games at the moment.
34 * It is implemented as a singleton.
37 class RecentlyPlayedGameList: public std::list<RecentlyPlayedGame*>, public sigc::trackable
41 //! The xml tag of this object in a recently played game file.
42 static std::string d_tag;
44 static const int TWO_WEEKS_OLD = 1209600; /* seconds */
47 // Methods that operate on the class data and do not modify the class.
49 //! Save the recently played game list to the given file.
50 bool saveToFile(std::string filename) const;
52 //! Save the recently played game list to an opened file.
53 bool save(XML_Helper* helper) const;
56 // Methods that operate on the class data and modify the class.
58 //! Load the recently game list from the given file.
59 bool loadFromFile(std::string filename);
61 //! Add a game entry to the list of recently played games.
62 void addEntry(GameScenario *game_scenario, std::string filename);
64 //! Add a networked game entry to the list of recently played games.
65 void addNetworkedEntry(GameScenario *game_scenario, std::string host, guint32 port);
67 //! Touch the game in the recently played list.
68 void updateEntry(GameScenario *game_scenario);
70 //! Remove a game entry from the list, by it's scenario id.
71 bool removeEntry(std::string id);
73 //! Removes all networked games from the list.
74 void removeAllNetworkedGames();
76 //! Removes games from the list that are too old, or just too numerous.
82 //! return the singleton instance of this class.
83 static RecentlyPlayedGameList * getInstance();
85 //! Loads the singleton instance from an opened file.
86 static RecentlyPlayedGameList * getInstance(XML_Helper *helper);
88 //! Explicitly delete the singleton instance of this class.
89 static void deleteInstance();
92 //! Default Constructor.
93 RecentlyPlayedGameList();
95 //! Loading constructor
96 RecentlyPlayedGameList(XML_Helper *helper);
99 ~RecentlyPlayedGameList();
102 //! Callback for loading recentlyplayedgames into this list.
103 bool load(std::string tag, XML_Helper *helper);
105 //! Helper method to sort the list by it's last-played time.
106 static bool orderByTime(RecentlyPlayedGame*rhs, RecentlyPlayedGame *lhs);
108 //! Remove the old games from the list.
109 void pruneOldGames(int stale = TWO_WEEKS_OLD);
111 //! Remove extraneous games form the list.
112 void pruneTooManyGames(int too_many = 10);
116 //! A static pointer for the singleton instance.
117 static RecentlyPlayedGameList* s_instance;
120 #endif // RECENTLYPLAYEDGAMELIST_H