1/*
2 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
3 *
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6#ifndef BROWSING_HISTORY_H
7#define BROWSING_HISTORY_H
8
9#include "DateTime.h"
10#include <List.h>
11#include <Locker.h>
12
13class BFile;
14class BString;
15
16
17class BrowsingHistoryItem {
18public:
19								BrowsingHistoryItem(const BString& url);
20								BrowsingHistoryItem(
21									const BrowsingHistoryItem& other);
22								BrowsingHistoryItem(const BMessage* archive);
23								~BrowsingHistoryItem();
24
25			status_t			Archive(BMessage* archive) const;
26
27			BrowsingHistoryItem& operator=(const BrowsingHistoryItem& other);
28
29			bool				operator==(
30									const BrowsingHistoryItem& other) const;
31			bool				operator!=(
32									const BrowsingHistoryItem& other) const;
33			bool				operator<(
34									const BrowsingHistoryItem& other) const;
35			bool				operator<=(
36									const BrowsingHistoryItem& other) const;
37			bool				operator>(
38									const BrowsingHistoryItem& other) const;
39			bool				operator>=(
40									const BrowsingHistoryItem& other) const;
41
42			const BString&		URL() const { return fURL; }
43			const BDateTime&	DateTime() const { return fDateTime; }
44			uint32				InvokationCount() const {
45									return fInvokationCount; }
46			void				Invoked();
47
48private:
49			BString				fURL;
50			BDateTime			fDateTime;
51			uint32				fInvokationCount;
52};
53
54
55class BrowsingHistory : public BLocker {
56public:
57	static	BrowsingHistory*	DefaultInstance();
58
59			bool				AddItem(const BrowsingHistoryItem& item);
60
61	// Should Lock() the object when using these in some loop or so:
62			int32				CountItems() const;
63			BrowsingHistoryItem	HistoryItemAt(int32 index) const;
64			void				Clear();
65
66			void				SetMaxHistoryItemAge(int32 days);
67			int32				MaxHistoryItemAge() const;
68
69private:
70								BrowsingHistory();
71	virtual						~BrowsingHistory();
72
73			void				_Clear();
74			bool				_AddItem(const BrowsingHistoryItem& item,
75									bool invoke);
76
77			void				_LoadSettings();
78			void				_SaveSettings();
79			bool				_OpenSettingsFile(BFile& file, uint32 mode);
80
81private:
82			BList				fHistoryItems;
83			int32				fMaxHistoryItemAge;
84
85	static	BrowsingHistory		sDefaultInstance;
86			bool				fSettingsLoaded;
87};
88
89
90#endif // BROWSING_HISTORY_H
91
92