~ubuntu-branches/ubuntu/saucy/lordsawar/saucy

« back to all changes in this revision

Viewing changes to src/recently-played-game-list.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2008-12-20 13:52:12 UTC
  • mfrom: (1.1.6 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081220135212-noeb2w3y98ebo7o9
Tags: 0.1.4-1
[ Barry deFreese ]
* New upstream release.
* Move 0.0.8-2.1 changelog entry to correct point in changelog.
* Make lordsawar-data suggest lordsawar.
* Update my e-mail address.
* Add build-depends on intltool, uuid-dev, and libboost-dev.
* Don't install locales since there are no translations currently.
* Add simple man page for new lordsawar-pbm binary.
* Drop gcc4.3 patches as they have been fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Copyright (C) 2008, Ben Asselstine
 
2
//
 
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.
 
7
//
 
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.
 
12
//
 
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 
 
16
//  02110-1301, USA.
 
17
 
 
18
#ifndef RECENTLYPLAYEDGAMELIST_H
 
19
#define RECENTLYPLAYEDGAMELIST_H
 
20
 
 
21
#include <string>
 
22
#include <list>
 
23
#include <sigc++/trackable.h>
 
24
 
 
25
#include "xmlhelper.h"
 
26
 
 
27
class GameScenario;
 
28
class RecentlyPlayedGame;
 
29
 
 
30
//! A list of games that we've recently played.
 
31
/** 
 
32
 * This is only used for network games at the moment.
 
33
 * It is implemented as a singleton.
 
34
 *
 
35
 */
 
36
class RecentlyPlayedGameList: public std::list<RecentlyPlayedGame*>, public sigc::trackable
 
37
{
 
38
    public:
 
39
 
 
40
        //! The xml tag of this object in a recently played game file.
 
41
        static std::string d_tag; 
 
42
 
 
43
        //! return the singleton instance of this class.
 
44
        static RecentlyPlayedGameList * getInstance();
 
45
 
 
46
        //! Loads the singleton instance from an opened file.
 
47
        static RecentlyPlayedGameList * getInstance(XML_Helper *helper);
 
48
 
 
49
        //! Explicitly delete the singleton instance of this class.
 
50
        static void deleteInstance();
 
51
 
 
52
        //! Load the recently game list from the given file.
 
53
        bool loadFromFile(std::string filename);
 
54
 
 
55
        //! Save the recently game list to the given file.
 
56
        bool saveToFile(std::string filename);
 
57
 
 
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);
 
62
 
 
63
        //! Remove a game entry from the list, by it's scenario id.
 
64
        bool removeEntry(std::string id);
 
65
 
 
66
        bool save(XML_Helper* helper) const;
 
67
 
 
68
        void removeAllNetworkedGames();
 
69
 
 
70
        void pruneGames();
 
71
        
 
72
    protected:
 
73
        //! Default Constructor.
 
74
        /**
 
75
         */
 
76
        RecentlyPlayedGameList();
 
77
        RecentlyPlayedGameList(XML_Helper *helper);
 
78
        
 
79
        //! Destructor.
 
80
        ~RecentlyPlayedGameList();
 
81
 
 
82
    private:
 
83
        //! Callback for loading recentlyplayedgames into this list.
 
84
        bool load(std::string tag, XML_Helper *helper);
 
85
 
 
86
        //! Helper method to sort the list by it's last-played time.
 
87
        static bool orderByTime(RecentlyPlayedGame*rhs, RecentlyPlayedGame *lhs);
 
88
 
 
89
        static const int TWO_WEEKS_OLD = 1209600; /* seconds */
 
90
        void pruneOldGames(int stale = TWO_WEEKS_OLD);
 
91
        void pruneTooManyGames(int too_many = 10);
 
92
 
 
93
        //! A static pointer for the singleton instance.
 
94
        static RecentlyPlayedGameList* s_instance;
 
95
};
 
96
 
 
97
#endif // RECENTLYPLAYEDGAMELIST_H
 
98