#ifndef _QUERY_MENU
#define _QUERY_MENU

#include <Locker.h>
#include <PopUpMenu.h>

class BLooper;
class BQuery;
class BVolume;
class QHandler;

class QueryMenu : public BPopUpMenu {
	friend QHandler;
	
	public:
		QueryMenu(const char *title, bool popUp=false,
			bool radioMode = false, bool autoRename = false);
		virtual ~QueryMenu(void);
		
		virtual BPoint ScreenLocation(void);
		virtual status_t SetTargetForItems(BHandler *handler);
		status_t SetPredicate(const char *expr, BVolume *vol = NULL);
	
	protected:
		virtual void EntryCreated(const entry_ref &ref, ino_t node);
		virtual void EntryRemoved(ino_t node);
		virtual void RemoveEntries(void);
		
		BHandler *fTargetHandler;
		static BLooper *fQueryLooper;
		
	private:
		virtual void DoQueryMessage(BMessage *msg);
		static int32 query_thread(void *data);
		int32 QueryThread(void);
	
		BLocker fQueryLock;
		BQuery *fQuery;
		QHandler *fQueryHandler;
		bool fCancelQuery;
		bool fPopUp;
		static int32 fMenuCount;
};

#endif // #ifndef _QUERY_MENU
