xref: /haiku/src/apps/webpositive/BrowsingHistory.h (revision c14bca2958fb7b0c34d5464ccfdd87038f909a0c)
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 
13 class BFile;
14 class BString;
15 
16 
17 class BrowsingHistoryItem {
18 public:
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 
URL()42 			const BString&		URL() const { return fURL; }
DateTime()43 			const BDateTime&	DateTime() const { return fDateTime; }
InvokationCount()44 			uint32				InvokationCount() const {
45 									return fInvokationCount; }
46 			void				Invoked();
47 
48 private:
49 			BString				fURL;
50 			BDateTime			fDateTime;
51 			uint32				fInvokationCount;
52 };
53 
54 
55 class BrowsingHistory : public BLocker {
56 public:
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 
69 private:
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 
81 private:
82 			BList				fHistoryItems;
83 			int32				fMaxHistoryItemAge;
84 
85 	static	BrowsingHistory		sDefaultInstance;
86 			bool				fSettingsLoaded;
87 };
88 
89 
90 #endif // BROWSING_HISTORY_H
91 
92