xref: /haiku/src/kits/tracker/QueryPoseView.h (revision c90684742e7361651849be4116d0e5de3a817194)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 #ifndef	_QUERY_POSE_VIEW_H
36 #define _QUERY_POSE_VIEW_H
37 
38 class BQuery;
39 
40 #include "EntryIterator.h"
41 #include "PoseView.h"
42 
43 namespace BPrivate {
44 
45 class BQueryContainerWindow;
46 class QueryEntryListCollection;
47 
48 class BQueryPoseView : public BPoseView {
49 public:
50 	BQueryPoseView(Model *, BRect, uint32 resizeMask = B_FOLLOW_ALL);
51 	virtual ~BQueryPoseView();
52 
53 	virtual void MessageReceived(BMessage *message);
54 
55 	const char *SearchForType() const;
56 	BQueryContainerWindow *ContainerWindow() const;
57 	bool ActiveOnDevice(dev_t) const;
58 
59 	void Refresh();
60 		// makes queries that are static but need to appear dynamic
61 		// live - for instance for a query that contains a
62 		// date == today - RestartQuery gets called on midnight to update
63 		// the contents
64 
65 protected:
66 	virtual void AttachedToWindow();
67 	virtual void RestoreState(AttributeStreamNode *);
68 	virtual void RestoreState(const BMessage &);
69 	virtual void SavePoseLocations(BRect * = NULL);
70 	virtual void SetUpDefaultColumnsIfNeeded();
71 	virtual void SetViewMode(uint32);
72 	virtual void OpenParent();
73 	virtual void EditQueries();
74 	virtual EntryListBase *InitDirentIterator(const entry_ref *);
75 	virtual uint32 WatchNewNodeMask();
76 	virtual bool ShouldShowPose(const Model *, const PoseInfo *);
77 	virtual void AddPosesCompleted();
78 
79 private:
80 		// list of all the queries this PoseView represents
81 		// typically there will be one query per volume specified
82 		// QueryEntryListCollection provides the abstraction layer
83 		// defining the iterators for _add_poses_
84 	bool fShowResultsFromTrash;
85 	mutable BString fSearchForMimeType;
86 
87 	BObjectList<BQuery> *fQueryList;
88 	QueryEntryListCollection *fQueryListContainer;
89 
90 	bool fCreateOldPoseList;
91 
92 	typedef BPoseView _inherited;
93 };
94 
95 
96 class QueryEntryListCollection : public EntryListBase {
97 	// This will become a replacement for BDirectory and QueryList in a
98 	// PoseView, allowing PoseView to have an arbitrary collection of
99 	// elements that behave as an EntryList
100 	// For now just manage a list of BQueries
101 
102 
103 	class QueryListRep {
104 	public:
105 		QueryListRep(BObjectList<BQuery> *queryList)
106 			:	fQueryList(queryList),
107 				fRefCount(0),
108 				fShowResultsFromTrash(0),
109 				fOldPoseList(NULL)
110 			{}
111 
112 		~QueryListRep()
113 			{
114 				ASSERT(fRefCount <= 0);
115 				delete fQueryList;
116 				delete fOldPoseList;
117 			}
118 
119 		BObjectList<BQuery> *OpenQueryList()
120 			{
121 				fRefCount++;
122 				return fQueryList;
123 			}
124 
125 		bool CloseQueryList()
126 			{
127 				return atomic_add(&fRefCount, -1) == 0;
128 			}
129 
130 		BObjectList<BQuery> *fQueryList;
131 		int32 fRefCount;
132 		bool fShowResultsFromTrash;
133 		int32 fQueryListIndex;
134 		bool fDynamicDateQuery;
135 		bool fRefreshEveryHour;
136 		bool fRefreshEveryMinute;
137 
138 		PoseList *fOldPoseList;
139 			// when doing a Refresh, this list is used to detect poses that
140 			// are no longer a part of a fDynamicDateQuery and need to be removed
141 	};
142 
143 public:
144 
145 	QueryEntryListCollection(Model *, BHandler * = NULL, PoseList *oldPoseList = NULL);
146 	virtual ~QueryEntryListCollection();
147 
148 	QueryEntryListCollection *Clone();
149 
150 	BObjectList<BQuery> *QueryList() const
151 		{ return fQueryListRep->fQueryList; }
152 
153 	PoseList *OldPoseList() const
154 		{ return fQueryListRep->fOldPoseList; }
155 	void ClearOldPoseList();
156 
157 	virtual status_t GetNextEntry(BEntry *entry, bool traverse = false);
158 	virtual status_t GetNextRef(entry_ref *ref);
159 	virtual int32 GetNextDirents(struct dirent *buffer, size_t length,
160 		int32 count = INT_MAX);
161 
162 	virtual status_t Rewind();
163 	virtual int32 CountEntries();
164 
165 	bool ShowResultsFromTrash() const;
166 	bool DynamicDateQuery() const;
167 	bool DynamicDateRefreshEveryHour() const;
168 	bool DynamicDateRefreshEveryMinute() const;
169 
170 private:
171 	QueryEntryListCollection(const QueryEntryListCollection &);
172 		// only to be used by the Clone routine
173 	status_t FetchOneQuery(const BQuery *, BHandler *target,
174 		BObjectList<BQuery> *, BVolume *);
175 
176 	QueryListRep *fQueryListRep;
177 };
178 
179 } // namespace BPrivate
180 
181 using namespace BPrivate;
182 
183 #endif
184