102be5353SAxel Dörfler/*
202be5353SAxel DörflerOpen Tracker License
302be5353SAxel Dörfler
402be5353SAxel DörflerTerms and Conditions
502be5353SAxel Dörfler
602be5353SAxel DörflerCopyright (c) 1991-2000, Be Incorporated. All rights reserved.
702be5353SAxel Dörfler
802be5353SAxel DörflerPermission is hereby granted, free of charge, to any person obtaining a copy of
902be5353SAxel Dörflerthis software and associated documentation files (the "Software"), to deal in
1002be5353SAxel Dörflerthe Software without restriction, including without limitation the rights to
1102be5353SAxel Dörfleruse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1202be5353SAxel Dörflerof the Software, and to permit persons to whom the Software is furnished to do
1302be5353SAxel Dörflerso, subject to the following conditions:
1402be5353SAxel Dörfler
1502be5353SAxel DörflerThe above copyright notice and this permission notice applies to all licensees
1602be5353SAxel Dörflerand shall be included in all copies or substantial portions of the Software.
1702be5353SAxel Dörfler
1802be5353SAxel DörflerTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1902be5353SAxel DörflerIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
2002be5353SAxel DörflerFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2102be5353SAxel DörflerBE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2202be5353SAxel DörflerAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
2302be5353SAxel DörflerWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2402be5353SAxel Dörfler
2502be5353SAxel DörflerExcept as contained in this notice, the name of Be Incorporated shall not be
2602be5353SAxel Dörflerused in advertising or otherwise to promote the sale, use or other dealings in
2702be5353SAxel Dörflerthis Software without prior written authorization from Be Incorporated.
2802be5353SAxel Dörfler
2902be5353SAxel DörflerTracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
3002be5353SAxel Dörflerof Be Incorporated in the United States and other countries. Other brand product
3102be5353SAxel Dörflernames are registered trademarks or trademarks of their respective holders.
3202be5353SAxel DörflerAll rights reserved.
3302be5353SAxel Dörfler*/
3458203edfSJohn Scipione#ifndef _FIND_PANEL_H
3502be5353SAxel Dörfler#define _FIND_PANEL_H
3602be5353SAxel Dörfler
3702be5353SAxel Dörfler
3802be5353SAxel Dörfler#include <ByteOrder.h>
3958203edfSJohn Scipione#include <ObjectList.h>
4002be5353SAxel Dörfler#include <Window.h>
4102be5353SAxel Dörfler#include <View.h>
4202be5353SAxel Dörfler
4302be5353SAxel Dörfler#include "DialogPane.h"
4402be5353SAxel Dörfler#include "MimeTypeList.h"
4502be5353SAxel Dörfler#include "Utilities.h"
4602be5353SAxel Dörfler#include "NodeWalker.h"
4702be5353SAxel Dörfler
48b05aa8b5SJohn Scipione
4902be5353SAxel Dörflerclass BFilePanel;
5002be5353SAxel Dörflerclass BQuery;
5102be5353SAxel Dörflerclass BBox;
5202be5353SAxel Dörflerclass BTextControl;
5302be5353SAxel Dörflerclass BCheckBox;
5402be5353SAxel Dörflerclass BMenuField;
5502be5353SAxel Dörflerclass BFile;
56f2e230caSJérôme Duvalclass BPopUpMenu;
5721fd5809SJessica Hamiltonclass BGridLayout;
5802be5353SAxel Dörfler
5902be5353SAxel Dörflernamespace BPrivate {
6002be5353SAxel Dörfler
6102be5353SAxel Dörflerclass FindPanel;
6202be5353SAxel Dörflerclass Model;
6302be5353SAxel Dörflerclass DraggableIcon;
6402be5353SAxel Dörflerclass TAttrView;
6502be5353SAxel Dörfler
6602be5353SAxel Dörflerconst uint32 kVolumeItem = 'Fvol';
6702be5353SAxel Dörflerconst uint32 kAttributeItemMain = 'Fatr';
6802be5353SAxel Dörflerconst uint32 kByNameItem = 'Fbyn';
6902be5353SAxel Dörflerconst uint32 kByAttributeItem = 'Fbya';
70b9224a25SAxel Dörflerconst uint32 kByFormulaItem = 'Fbyq';
7102be5353SAxel Dörflerconst uint32 kAddItem = 'Fadd';
7202be5353SAxel Dörflerconst uint32 kRemoveItem = 'Frem';
7302be5353SAxel Dörfler
74f6e4cbb9SAxel Dörfler#ifdef _IMPEXP_TRACKER
7502be5353SAxel Dörfler_IMPEXP_TRACKER
7602be5353SAxel Dörfler#endif
77b05aa8b5SJohn ScipioneBMenu* TrackerBuildRecentFindItemsMenu(const char* title);
7802be5353SAxel Dörfler
7902be5353SAxel Dörflerstruct MoreOptionsStruct {
8002be5353SAxel Dörfler	bool showMoreOptions;
8102be5353SAxel Dörfler	bool searchTrash;
8202be5353SAxel Dörfler	int32 reserved1;
8302be5353SAxel Dörfler	bool temporary;
8402be5353SAxel Dörfler	bool reserved9;
8502be5353SAxel Dörfler	bool reserved10;
8602be5353SAxel Dörfler	bool reserved11;
8702be5353SAxel Dörfler	int32 reserved3;
8802be5353SAxel Dörfler	int32 reserved4;
8902be5353SAxel Dörfler	int32 reserved5;
9002be5353SAxel Dörfler	int32 reserved6;
9102be5353SAxel Dörfler	int32 reserved7;
9202be5353SAxel Dörfler	int32 reserved8;
9302be5353SAxel Dörfler	// reserve a bunch of fields so that we can add stuff later but not
9402be5353SAxel Dörfler	// make old queries incompatible. Reserved fields are set to 0 when
9502be5353SAxel Dörfler	// saved
96b9224a25SAxel Dörfler
9702be5353SAxel Dörfler	MoreOptionsStruct()
9814948881SJohn Scipione		:
9914948881SJohn Scipione		showMoreOptions(false),
10014948881SJohn Scipione		searchTrash(false),
10114948881SJohn Scipione		reserved1(0),
10214948881SJohn Scipione		temporary(true),
10314948881SJohn Scipione		reserved9(false),
10414948881SJohn Scipione		reserved10(false),
10514948881SJohn Scipione		reserved11(false),
10614948881SJohn Scipione		reserved3(0),
10714948881SJohn Scipione		reserved4(0),
10814948881SJohn Scipione		reserved5(0),
10914948881SJohn Scipione		reserved6(0),
11014948881SJohn Scipione		reserved7(0),
11114948881SJohn Scipione		reserved8(0)
11214948881SJohn Scipione	{
11314948881SJohn Scipione	}
114b9224a25SAxel Dörfler
115b05aa8b5SJohn Scipione	static void EndianSwap(void* castToThis);
116b9224a25SAxel Dörfler
117b05aa8b5SJohn Scipione	static void SetQueryTemporary(BNode*, bool on);
118b05aa8b5SJohn Scipione	static bool QueryTemporary(const BNode*);
11902be5353SAxel Dörfler};
12002be5353SAxel Dörfler
12102be5353SAxel Dörfler
12202be5353SAxel Dörflerclass FindWindow : public BWindow {
12314948881SJohn Scipionepublic:
12414948881SJohn Scipione	FindWindow(const entry_ref* ref = NULL,
12514948881SJohn Scipione		bool editIfTemplateOnly = false);
12614948881SJohn Scipione	virtual ~FindWindow();
12702be5353SAxel Dörfler
12814948881SJohn Scipione	FindPanel* BackgroundView() const
12914948881SJohn Scipione		{ return fBackground; }
13002be5353SAxel Dörfler
13114948881SJohn Scipione	BNode* QueryNode() const
13214948881SJohn Scipione		{ return fFile; }
13302be5353SAxel Dörfler
13414948881SJohn Scipione	const char* QueryName() const;
13514948881SJohn Scipione		// reads in the query name from either a saved name in a template
13614948881SJohn Scipione		// or form a saved query name
13702be5353SAxel Dörfler
13814948881SJohn Scipione	static bool IsQueryTemplate(BNode* file);
13902be5353SAxel Dörfler
14014948881SJohn Scipioneprotected:
14114948881SJohn Scipione	virtual	void MessageReceived(BMessage* message);
14202be5353SAxel Dörfler
14314948881SJohn Scipioneprivate:
14414948881SJohn Scipione	static BFile* TryOpening(const entry_ref* ref);
14514948881SJohn Scipione	static void GetDefaultQuery(BEntry &entry);
14614948881SJohn Scipione		// when opening an empty panel, use the default query to set the
14714948881SJohn Scipione		// panel up
14814948881SJohn Scipione	void SaveQueryAttributes(BNode* file, bool templateQuery);
14902be5353SAxel Dörfler
15014948881SJohn Scipione	void Find();
15114948881SJohn Scipione		// retrieve the results
15214948881SJohn Scipione	void Save();
15314948881SJohn Scipione		// save the contents of the find window into the query file
15402be5353SAxel Dörfler
15514948881SJohn Scipione	void SwitchToTemplate(const entry_ref*);
15614948881SJohn Scipione	bool FindSaveCommon(bool find);
15702be5353SAxel Dörfler
15814948881SJohn Scipione	status_t SaveQueryAsAttributes(BNode*, BEntry*, bool queryTemplate,
15914948881SJohn Scipione		const BMessage* oldAttributes = 0, const BPoint* oldLocation = 0);
16002be5353SAxel Dörfler
16114948881SJohn Scipione	void GetDefaultName(BString &);
16214948881SJohn Scipione	void GetPredicateString(BString &, bool &dynamicDate);
16314948881SJohn Scipione		// dynamic date is a date such as 'today'
16402be5353SAxel Dörfler
16514948881SJohn Scipione	BFile* fFile;
16614948881SJohn Scipione	entry_ref fRef;
16714948881SJohn Scipione	bool fFromTemplate;
16814948881SJohn Scipione	bool fEditTemplateOnly;
16914948881SJohn Scipione	FindPanel* fBackground;
17014948881SJohn Scipione	mutable BString fQueryNameFromTemplate;
17114948881SJohn Scipione	BFilePanel* fSaveAsTemplatePanel;
17202be5353SAxel Dörfler
17314948881SJohn Scipione	typedef BWindow _inherited;
17402be5353SAxel Dörfler};
17502be5353SAxel Dörfler
17602be5353SAxel Dörfler
17702be5353SAxel Dörflerclass FindPanel : public BView {
17814948881SJohn Scipionepublic:
17914948881SJohn Scipione	FindPanel(BFile*, FindWindow* parent, bool fromTemplate,
18014948881SJohn Scipione		bool editTemplateOnly);
18114948881SJohn Scipione	virtual ~FindPanel();
18214948881SJohn Scipione
18314948881SJohn Scipione	virtual	void AttachedToWindow();
18414948881SJohn Scipione	virtual	void Draw(BRect updateRect);
18514948881SJohn Scipione	virtual	void MessageReceived(BMessage*);
18614948881SJohn Scipione
18714948881SJohn Scipione	void BuildAttrQuery(BQuery*, bool& dynamicDate) const;
18814948881SJohn Scipione	BPopUpMenu* MimeTypeMenu() const
18914948881SJohn Scipione		{ return fMimeTypeMenu; }
19014948881SJohn Scipione	BMenuItem* CurrentMimeType(const char** type = NULL) const;
19114948881SJohn Scipione	status_t SetCurrentMimeType(BMenuItem* item);
19214948881SJohn Scipione	status_t SetCurrentMimeType(const char* label);
19314948881SJohn Scipione
19414948881SJohn Scipione	BPopUpMenu* VolMenu() const
19514948881SJohn Scipione		{ return fVolMenu; }
19614948881SJohn Scipione	uint32 Mode() const
19714948881SJohn Scipione		{ return fMode; }
19814948881SJohn Scipione
19914948881SJohn Scipione	static uint32 InitialMode(const BNode* entry);
20014948881SJohn Scipione	void SaveWindowState(BNode*, bool editTemplate);
20114948881SJohn Scipione
20214948881SJohn Scipione	void SwitchToTemplate(const BNode*);
20314948881SJohn Scipione
20414948881SJohn Scipione	void GetByAttrPredicate(BQuery*, bool &dynamicDate) const;
20514948881SJohn Scipione		// build up a query from by-attribute items
20614948881SJohn Scipione	void GetByNamePredicate(BQuery*) const;
20714948881SJohn Scipione		// build up a simple query from the name we are searching for
20814948881SJohn Scipione
20914948881SJohn Scipione	void GetDefaultName(BString&) const;
21014948881SJohn Scipione	void GetDefaultAttrName(BString&, int32) const;
21114948881SJohn Scipione	const char* UserSpecifiedName() const;
21214948881SJohn Scipione		// name filled out in the query name text field
21314948881SJohn Scipione
21414948881SJohn Scipione	static void AddRecentQueries(BMenu*, bool addSaveAsItem,
21514948881SJohn Scipione		const BMessenger* target, uint32 what);
21614948881SJohn Scipione		// populate the recent query menu with query templates and recent
21714948881SJohn Scipione		// queries
21814948881SJohn Scipione
21914948881SJohn Scipioneprivate:
22014948881SJohn Scipione	void AddMimeTypesToMenu();
22114948881SJohn Scipione		// populates the type menu
22214948881SJohn Scipione	static bool AddOneMimeTypeToMenu(const ShortMimeInfo*, void* castToMenu);
22314948881SJohn Scipione
22414948881SJohn Scipione	void AddVolumes(BMenu*);
22514948881SJohn Scipione		// populates the volume menu
22614948881SJohn Scipione	void ShowVolumeMenuLabel();
22714948881SJohn Scipione
22814948881SJohn Scipione	void AddAttrRow();
22914948881SJohn Scipione		// add one more attribute item to the attr view
23014948881SJohn Scipione	void RemoveAttrRow();
23114948881SJohn Scipione		// remove the last attribute item
23214948881SJohn Scipione	void AddFirstAttr();
23314948881SJohn Scipione
23414948881SJohn Scipione	// panel building/restoring calls
23514948881SJohn Scipione	void RestoreWindowState(const BNode*);
23614948881SJohn Scipione	void RestoreMimeTypeMenuSelection(const BNode*);
23714948881SJohn Scipione	void AddByAttributeItems(const BNode*);
23814948881SJohn Scipione	void RemoveByAttributeItems();
23914948881SJohn Scipione	void RemoveAttrViewItems(bool removeGrid = true);
24014948881SJohn Scipione	void ShowOrHideMimeTypeMenu();
24114948881SJohn Scipione		// MimeTypeWindow is only shown in kByNameItem and
24214948881SJohn Scipione		// kByAttributeItem modes
24314948881SJohn Scipione
24414948881SJohn Scipione	void AddAttributeControls(int32);
24514948881SJohn Scipione
24614948881SJohn Scipione	void ShowOrHideMoreOptions(bool show);
24714948881SJohn Scipione		// fMode gets set by this and the call relies on it being
24814948881SJohn Scipione		// up-to-date
24914948881SJohn Scipione	static int32 InitialAttrCount(const BNode*);
25014948881SJohn Scipione	void FillCurrentQueryName(BTextControl*, FindWindow*);
25114948881SJohn Scipione	void AddByNameOrFormulaItems();
252a2b0a3c0SJohn Scipione	void SetUpAddRemoveButtons();
25314948881SJohn Scipione
25414948881SJohn Scipione	void SwitchMode(uint32);
25514948881SJohn Scipione		// go from search by name to search by attribute, etc.
25614948881SJohn Scipione
25714948881SJohn Scipione	void PushMimeType(BQuery* query) const;
25814948881SJohn Scipione
25914948881SJohn Scipione	void SaveAsQueryOrTemplate(const entry_ref*, const char*, bool queryTemplate);
26014948881SJohn Scipione
26114948881SJohn Scipione	BView* FindAttrView(const char*, int row) const;
26214948881SJohn Scipione
26314948881SJohn Scipione	void AddAttributes(BMenu* menu, const BMimeType &type);
26414948881SJohn Scipione	void AddMimeTypeAttrs(BMenu* menu);
26514948881SJohn Scipione	void RestoreAttrState(const BMessage &, int32);
26614948881SJohn Scipione	void SaveAttrState(BMessage*, int32);
26714948881SJohn Scipione	void AddLogicMenu(int32, bool selectAnd = true);
26814948881SJohn Scipione	void RemoveLogicMenu(int32);
26914948881SJohn Scipione
27014948881SJohn Scipione	void ResizeMenuField(BMenuField*);
27114948881SJohn Scipione
27214948881SJohn Scipione	uint32 fMode;
27314948881SJohn Scipione	BGridLayout* fAttrGrid;
27414948881SJohn Scipione	BPopUpMenu* fMimeTypeMenu;
27514948881SJohn Scipione	BMenuField* fMimeTypeField;
27614948881SJohn Scipione	BPopUpMenu* fVolMenu;
27714948881SJohn Scipione	BPopUpMenu* fSearchModeMenu;
27814948881SJohn Scipione	BPopUpMenu* fRecentQueries;
27914948881SJohn Scipione	BBox* fMoreOptions;
28014948881SJohn Scipione	BTextControl* fQueryName;
28114948881SJohn Scipione	BString fInitialQueryName;
28214948881SJohn Scipione
28314948881SJohn Scipione	BCheckBox* fTemporaryCheck;
28414948881SJohn Scipione	BCheckBox* fSearchTrashCheck;
28514948881SJohn Scipione
28614948881SJohn Scipione	PaneSwitch* fLatch;
28714948881SJohn Scipione	DraggableIcon* fDraggableIcon;
28814948881SJohn Scipione
28914948881SJohn Scipione	typedef BView _inherited;
29014948881SJohn Scipione
29114948881SJohn Scipione	friend class RecentQueriesPopUp;
29202be5353SAxel Dörfler};
29302be5353SAxel Dörfler
29402be5353SAxel Dörfler
29502be5353SAxel Dörflerclass DeleteTransientQueriesTask {
29602be5353SAxel Dörfler	// transient queries get deleted if they didn't get used in a while;
29702be5353SAxel Dörfler	// this is the task that takes care of it
29814948881SJohn Scipionepublic:
29914948881SJohn Scipione	static void StartUpTransientQueryCleaner();
30002be5353SAxel Dörfler
30114948881SJohn Scipione	bool DoSomeWork();
30214948881SJohn Scipione	virtual ~DeleteTransientQueriesTask();
30302be5353SAxel Dörfler
30414948881SJohn Scipioneprotected:
30514948881SJohn Scipione	DeleteTransientQueriesTask();
30614948881SJohn Scipione		// returns true when done
30702be5353SAxel Dörfler
30814948881SJohn Scipione	enum State {
30914948881SJohn Scipione		kInitial,
31014948881SJohn Scipione		kAllocatedWalker,
31114948881SJohn Scipione		kTraversing,
31214948881SJohn Scipione		kError
31314948881SJohn Scipione	};
31402be5353SAxel Dörfler
31514948881SJohn Scipione	State state;
31602be5353SAxel Dörfler
31714948881SJohn Scipione	void Initialize();
31814948881SJohn Scipione	bool GetSome();
31902be5353SAxel Dörfler
32014948881SJohn Scipione	bool ProcessOneRef(Model*);
32102be5353SAxel Dörfler
32214948881SJohn Scipioneprivate:
32314948881SJohn Scipione	BTrackerPrivate::TNodeWalker* fWalker;
32402be5353SAxel Dörfler};
32502be5353SAxel Dörfler
32602be5353SAxel Dörfler
32702be5353SAxel Dörflerclass RecentFindItemsMenu : public BMenu {
32814948881SJohn Scipionepublic:
32914948881SJohn Scipione	RecentFindItemsMenu(const char* title, const BMessenger* target,
33014948881SJohn Scipione		uint32 what);
33102be5353SAxel Dörfler
33214948881SJohn Scipioneprotected:
33314948881SJohn Scipione	virtual void AttachedToWindow();
33402be5353SAxel Dörfler
33514948881SJohn Scipioneprivate:
33614948881SJohn Scipione	BMessenger fTarget;
33714948881SJohn Scipione	uint32 fWhat;
33802be5353SAxel Dörfler};
33902be5353SAxel Dörfler
34002be5353SAxel Dörfler
34102be5353SAxel Dörflerclass DraggableQueryIcon : public DraggableIcon {
34202be5353SAxel Dörfler	// query/query template drag&drop helper
34314948881SJohn Scipionepublic:
34414948881SJohn Scipione	DraggableQueryIcon(BRect frame, const char* name,
34514948881SJohn Scipione		const BMessage* message, BMessenger target,
34614948881SJohn Scipione		uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP,
34714948881SJohn Scipione		uint32 flags = B_WILL_DRAW);
34814948881SJohn Scipione
34914948881SJohn Scipioneprotected:
35014948881SJohn Scipione	virtual bool DragStarted(BMessage*);
35102be5353SAxel Dörfler};
35202be5353SAxel Dörfler
35302be5353SAxel Dörfler} // namespace BPrivate
35402be5353SAxel Dörfler
35502be5353SAxel Dörflerusing namespace BPrivate;
35602be5353SAxel Dörfler
35758203edfSJohn Scipione
35858203edfSJohn Scipione#endif	// _FIND_PANEL_H
359