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 2 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
23
#include <sigc++/trackable.h>
25
#include "xmlhelper.h"
28
class RecentlyPlayedGame;
30
//! A list of games that we've recently played.
32
* This is only used for network games at the moment.
33
* It is implemented as a singleton.
36
class RecentlyPlayedGameList: public std::list<RecentlyPlayedGame*>, public sigc::trackable
40
//! The xml tag of this object in a recently played game file.
41
static std::string d_tag;
43
//! return the singleton instance of this class.
44
static RecentlyPlayedGameList * getInstance();
46
//! Loads the singleton instance from an opened file.
47
static RecentlyPlayedGameList * getInstance(XML_Helper *helper);
49
//! Explicitly delete the singleton instance of this class.
50
static void deleteInstance();
52
//! Load the recently game list from the given file.
53
bool loadFromFile(std::string filename);
55
//! Save the recently game list to the given file.
56
bool saveToFile(std::string filename);
58
//! Add a game entry to the list of recently played games
59
void addEntry(GameScenario *game_scenario, std::string filename);
60
void addNetworkedEntry(GameScenario *game_scenario, std::string host, Uint32 port);
61
void updateEntry(GameScenario *game_scenario);
63
//! Remove a game entry from the list, by it's scenario id.
64
bool removeEntry(std::string id);
66
bool save(XML_Helper* helper) const;
68
void removeAllNetworkedGames();
73
//! Default Constructor.
76
RecentlyPlayedGameList();
77
RecentlyPlayedGameList(XML_Helper *helper);
80
~RecentlyPlayedGameList();
83
//! Callback for loading recentlyplayedgames into this list.
84
bool load(std::string tag, XML_Helper *helper);
86
//! Helper method to sort the list by it's last-played time.
87
static bool orderByTime(RecentlyPlayedGame*rhs, RecentlyPlayedGame *lhs);
89
static const int TWO_WEEKS_OLD = 1209600; /* seconds */
90
void pruneOldGames(int stale = TWO_WEEKS_OLD);
91
void pruneTooManyGames(int too_many = 10);
93
//! A static pointer for the singleton instance.
94
static RecentlyPlayedGameList* s_instance;
97
#endif // RECENTLYPLAYEDGAMELIST_H