6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
38 #include <ByteOrder.h>
39 #include <ObjectList.h>
43 #include "DialogPane.h"
44 #include "MimeTypeList.h"
45 #include "Utilities.h"
46 #include "NodeWalker.h"
66 const uint32 kVolumeItem
= 'Fvol';
67 const uint32 kAttributeItemMain
= 'Fatr';
68 const uint32 kByNameItem
= 'Fbyn';
69 const uint32 kByAttributeItem
= 'Fbya';
70 const uint32 kByFormulaItem
= 'Fbyq';
71 const uint32 kAddItem
= 'Fadd';
72 const uint32 kRemoveItem
= 'Frem';
74 #ifdef _IMPEXP_TRACKER
77 BMenu
* TrackerBuildRecentFindItemsMenu(const char* title
);
79 struct MoreOptionsStruct
{
93 // reserve a bunch of fields so that we can add stuff later but not
94 // make old queries incompatible. Reserved fields are set to 0 when
99 showMoreOptions(false),
115 static void EndianSwap(void* castToThis
);
117 static void SetQueryTemporary(BNode
*, bool on
);
118 static bool QueryTemporary(const BNode
*);
122 class FindWindow
: public BWindow
{
124 FindWindow(const entry_ref
* ref
= NULL
,
125 bool editIfTemplateOnly
= false);
126 virtual ~FindWindow();
128 FindPanel
* BackgroundView() const
129 { return fBackground
; }
131 BNode
* QueryNode() const
134 const char* QueryName() const;
135 // reads in the query name from either a saved name in a template
136 // or form a saved query name
138 static bool IsQueryTemplate(BNode
* file
);
141 virtual void MessageReceived(BMessage
* message
);
144 static BFile
* TryOpening(const entry_ref
* ref
);
145 static void GetDefaultQuery(BEntry
&entry
);
146 // when opening an empty panel, use the default query to set the
148 void SaveQueryAttributes(BNode
* file
, bool templateQuery
);
151 // retrieve the results
153 // save the contents of the find window into the query file
155 void SwitchToTemplate(const entry_ref
*);
156 bool FindSaveCommon(bool find
);
158 status_t
SaveQueryAsAttributes(BNode
*, BEntry
*, bool queryTemplate
,
159 const BMessage
* oldAttributes
= 0, const BPoint
* oldLocation
= 0);
161 void GetDefaultName(BString
&);
162 void GetPredicateString(BString
&, bool &dynamicDate
);
163 // dynamic date is a date such as 'today'
168 bool fEditTemplateOnly
;
169 FindPanel
* fBackground
;
170 mutable BString fQueryNameFromTemplate
;
171 BFilePanel
* fSaveAsTemplatePanel
;
173 typedef BWindow _inherited
;
177 class FindPanel
: public BView
{
179 FindPanel(BFile
*, FindWindow
* parent
, bool fromTemplate
,
180 bool editTemplateOnly
);
181 virtual ~FindPanel();
183 virtual void AttachedToWindow();
184 virtual void Draw(BRect updateRect
);
185 virtual void MessageReceived(BMessage
*);
187 void BuildAttrQuery(BQuery
*, bool& dynamicDate
) const;
188 BPopUpMenu
* MimeTypeMenu() const
189 { return fMimeTypeMenu
; }
190 BMenuItem
* CurrentMimeType(const char** type
= NULL
) const;
191 status_t
SetCurrentMimeType(BMenuItem
* item
);
192 status_t
SetCurrentMimeType(const char* label
);
194 BPopUpMenu
* VolMenu() const
199 static uint32
InitialMode(const BNode
* entry
);
200 void SaveWindowState(BNode
*, bool editTemplate
);
202 void SwitchToTemplate(const BNode
*);
204 void GetByAttrPredicate(BQuery
*, bool &dynamicDate
) const;
205 // build up a query from by-attribute items
206 void GetByNamePredicate(BQuery
*) const;
207 // build up a simple query from the name we are searching for
209 void GetDefaultName(BString
&) const;
210 void GetDefaultAttrName(BString
&, int32
) const;
211 const char* UserSpecifiedName() const;
212 // name filled out in the query name text field
214 static void AddRecentQueries(BMenu
*, bool addSaveAsItem
,
215 const BMessenger
* target
, uint32 what
);
216 // populate the recent query menu with query templates and recent
220 void AddMimeTypesToMenu();
221 // populates the type menu
222 static bool AddOneMimeTypeToMenu(const ShortMimeInfo
*, void* castToMenu
);
224 void AddVolumes(BMenu
*);
225 // populates the volume menu
226 void ShowVolumeMenuLabel();
229 // add one more attribute item to the attr view
230 void RemoveAttrRow();
231 // remove the last attribute item
234 // panel building/restoring calls
235 void RestoreWindowState(const BNode
*);
236 void RestoreMimeTypeMenuSelection(const BNode
*);
237 void AddByAttributeItems(const BNode
*);
238 void RemoveByAttributeItems();
239 void RemoveAttrViewItems(bool removeGrid
= true);
240 void ShowOrHideMimeTypeMenu();
241 // MimeTypeWindow is only shown in kByNameItem and
242 // kByAttributeItem modes
244 void AddAttributeControls(int32
);
246 void ShowOrHideMoreOptions(bool show
);
247 // fMode gets set by this and the call relies on it being
249 static int32
InitialAttrCount(const BNode
*);
250 void FillCurrentQueryName(BTextControl
*, FindWindow
*);
251 void AddByNameOrFormulaItems();
252 void SetUpAddRemoveButtons();
254 void SwitchMode(uint32
);
255 // go from search by name to search by attribute, etc.
257 void PushMimeType(BQuery
* query
) const;
259 void SaveAsQueryOrTemplate(const entry_ref
*, const char*, bool queryTemplate
);
261 BView
* FindAttrView(const char*, int row
) const;
263 void AddAttributes(BMenu
* menu
, const BMimeType
&type
);
264 void AddMimeTypeAttrs(BMenu
* menu
);
265 void RestoreAttrState(const BMessage
&, int32
);
266 void SaveAttrState(BMessage
*, int32
);
267 void AddLogicMenu(int32
, bool selectAnd
= true);
268 void RemoveLogicMenu(int32
);
270 void ResizeMenuField(BMenuField
*);
273 BGridLayout
* fAttrGrid
;
274 BPopUpMenu
* fMimeTypeMenu
;
275 BMenuField
* fMimeTypeField
;
276 BPopUpMenu
* fVolMenu
;
277 BPopUpMenu
* fSearchModeMenu
;
278 BPopUpMenu
* fRecentQueries
;
280 BTextControl
* fQueryName
;
281 BString fInitialQueryName
;
283 BCheckBox
* fTemporaryCheck
;
284 BCheckBox
* fSearchTrashCheck
;
287 DraggableIcon
* fDraggableIcon
;
289 typedef BView _inherited
;
291 friend class RecentQueriesPopUp
;
295 class DeleteTransientQueriesTask
{
296 // transient queries get deleted if they didn't get used in a while;
297 // this is the task that takes care of it
299 static void StartUpTransientQueryCleaner();
302 virtual ~DeleteTransientQueriesTask();
305 DeleteTransientQueriesTask();
306 // returns true when done
320 bool ProcessOneRef(Model
*);
323 BTrackerPrivate::TNodeWalker
* fWalker
;
327 class RecentFindItemsMenu
: public BMenu
{
329 RecentFindItemsMenu(const char* title
, const BMessenger
* target
,
333 virtual void AttachedToWindow();
341 class DraggableQueryIcon
: public DraggableIcon
{
342 // query/query template drag&drop helper
344 DraggableQueryIcon(BRect frame
, const char* name
,
345 const BMessage
* message
, BMessenger target
,
346 uint32 resizeFlags
= B_FOLLOW_LEFT
| B_FOLLOW_TOP
,
347 uint32 flags
= B_WILL_DRAW
);
350 virtual bool DragStarted(BMessage
*);
353 } // namespace BPrivate
355 using namespace BPrivate
;
358 #endif // _FIND_PANEL_H