1/*
2 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27#ifndef BROWSING_HISTORY_H
28#define BROWSING_HISTORY_H
29
30#include "DateTime.h"
31#include <List.h>
32#include <Locker.h>
33
34class BFile;
35class BString;
36
37
38class BrowsingHistoryItem {
39public:
40								BrowsingHistoryItem(const BString& url);
41								BrowsingHistoryItem(
42									const BrowsingHistoryItem& other);
43								BrowsingHistoryItem(const BMessage* archive);
44								~BrowsingHistoryItem();
45
46			status_t			Archive(BMessage* archive) const;
47
48			BrowsingHistoryItem& operator=(const BrowsingHistoryItem& other);
49
50			bool				operator==(
51									const BrowsingHistoryItem& other) const;
52			bool				operator!=(
53									const BrowsingHistoryItem& other) const;
54			bool				operator<(
55									const BrowsingHistoryItem& other) const;
56			bool				operator<=(
57									const BrowsingHistoryItem& other) const;
58			bool				operator>(
59									const BrowsingHistoryItem& other) const;
60			bool				operator>=(
61									const BrowsingHistoryItem& other) const;
62
63			const BString&		URL() const { return fURL; }
64			const BDateTime&	DateTime() const { return fDateTime; }
65			uint32				InvokationCount() const {
66									return fInvokationCount; }
67			void				Invoked();
68
69private:
70			BString				fURL;
71			BDateTime			fDateTime;
72			uint32				fInvokationCount;
73};
74
75
76class BrowsingHistory : public BLocker {
77public:
78	static	BrowsingHistory*	DefaultInstance();
79
80			bool				AddItem(const BrowsingHistoryItem& item);
81
82	// Should Lock() the object when using these in some loop or so:
83			int32				CountItems() const;
84			BrowsingHistoryItem	HistoryItemAt(int32 index) const;
85			void				Clear();
86
87			void				SetMaxHistoryItemAge(int32 days);
88			int32				MaxHistoryItemAge() const;
89
90private:
91								BrowsingHistory();
92	virtual						~BrowsingHistory();
93
94			void				_Clear();
95			bool				_AddItem(const BrowsingHistoryItem& item,
96									bool invoke);
97
98			void				_LoadSettings();
99			void				_SaveSettings();
100			bool				_OpenSettingsFile(BFile& file, uint32 mode);
101
102private:
103			BList				fHistoryItems;
104			int32				fMaxHistoryItemAge;
105
106	static	BrowsingHistory		sDefaultInstance;
107			bool				fSettingsLoaded;
108};
109
110
111#endif // BROWSING_HISTORY_H
112
113