1/* 2Open Tracker License 3 4Terms and Conditions 5 6Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a copy of 9this software and associated documentation files (the "Software"), to deal in 10the Software without restriction, including without limitation the rights to 11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12of the Software, and to permit persons to whom the Software is furnished to do 13so, subject to the following conditions: 14 15The above copyright notice and this permission notice applies to all licensees 16and shall be included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of Be Incorporated shall not be 26used in advertising or otherwise to promote the sale, use or other dealings in 27this Software without prior written authorization from Be Incorporated. 28 29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30of Be Incorporated in the United States and other countries. Other brand product 31names are registered trademarks or trademarks of their respective holders. 32All rights reserved. 33*/ 34#ifndef _FIND_PANEL_H 35#define _FIND_PANEL_H 36 37 38#include <ByteOrder.h> 39#include <ObjectList.h> 40#include <Window.h> 41#include <View.h> 42 43#include "DialogPane.h" 44#include "MimeTypeList.h" 45#include "Utilities.h" 46#include "NodeWalker.h" 47 48 49class BFilePanel; 50class BQuery; 51class BBox; 52class BTextControl; 53class BCheckBox; 54class BMenuField; 55class BFile; 56class BPopUpMenu; 57class BGridLayout; 58 59namespace BPrivate { 60 61class FindPanel; 62class Model; 63class DraggableIcon; 64class TAttrView; 65 66const uint32 kVolumeItem = 'Fvol'; 67const uint32 kAttributeItemMain = 'Fatr'; 68const uint32 kByNameItem = 'Fbyn'; 69const uint32 kByAttributeItem = 'Fbya'; 70const uint32 kByFormulaItem = 'Fbyq'; 71const uint32 kAddItem = 'Fadd'; 72const uint32 kRemoveItem = 'Frem'; 73 74#ifdef _IMPEXP_TRACKER 75_IMPEXP_TRACKER 76#endif 77BMenu* TrackerBuildRecentFindItemsMenu(const char* title); 78 79struct MoreOptionsStruct { 80 // Some options used to be in a collapsable part of the window, but 81 // this was removed. Now the options are always visible. 82 bool showMoreOptions; 83 bool searchTrash; 84 // reserve a bunch of fields so that we can add stuff later but not 85 // make old queries incompatible. Reserved fields are set to 0 when 86 // saved 87 int32 reserved1; 88 bool temporary; 89 bool reserved9; 90 bool reserved10; 91 bool reserved11; 92 int32 reserved3; 93 int32 reserved4; 94 int32 reserved5; 95 int32 reserved6; 96 int32 reserved7; 97 int32 reserved8; 98 99 MoreOptionsStruct() 100 : 101 showMoreOptions(true), 102 searchTrash(false), 103 reserved1(0), 104 temporary(true), 105 reserved9(false), 106 reserved10(false), 107 reserved11(false), 108 reserved3(0), 109 reserved4(0), 110 reserved5(0), 111 reserved6(0), 112 reserved7(0), 113 reserved8(0) 114 {} 115 116 static void EndianSwap(void* castToThis); 117 118 static void SetQueryTemporary(BNode*, bool on); 119 static bool QueryTemporary(const BNode*); 120}; 121 122 123class FindWindow : public BWindow { 124public: 125 FindWindow(const entry_ref* ref = NULL, 126 bool editIfTemplateOnly = false); 127 virtual ~FindWindow(); 128 129 FindPanel* BackgroundView() const { return fBackground; } 130 131 BNode* QueryNode() const { return fFile; } 132 133 // reads in the query name from either a saved name in a template 134 // or form a saved query name 135 const char* QueryName() const; 136 137 static bool IsQueryTemplate(BNode* file); 138 139protected: 140 virtual void MessageReceived(BMessage* message); 141 142private: 143 static BFile* TryOpening(const entry_ref* ref); 144 // when opening an empty panel, use the default query to set the panel up 145 static void GetDefaultQuery(BEntry& entry); 146 void SaveQueryAttributes(BNode* file, bool templateQuery); 147 148 // retrieve the results 149 void Find(); 150 // save the contents of the find window into the query file 151 void Save(); 152 153 void SwitchToTemplate(const entry_ref*); 154 bool FindSaveCommon(bool find); 155 156 status_t SaveQueryAsAttributes(BNode*, BEntry*, bool queryTemplate, 157 const BMessage* oldAttributes = 0, 158 const BPoint* oldLocation = 0); 159 160 void GetDefaultName(BString&); 161 // dynamic date is a date such as 'today' 162 void GetPredicateString(BString&, bool& dynamicDate); 163 164private: 165 BFile* fFile; 166 entry_ref fRef; 167 bool fFromTemplate; 168 bool fEditTemplateOnly; 169 FindPanel* fBackground; 170 mutable BString fQueryNameFromTemplate; 171 BFilePanel* fSaveAsTemplatePanel; 172 173 typedef BWindow _inherited; 174}; 175 176 177class FindPanel : public BView { 178public: 179 FindPanel(BFile*, FindWindow* parent, bool fromTemplate, 180 bool editTemplateOnly); 181 virtual ~FindPanel(); 182 183 virtual void AttachedToWindow(); 184 virtual void Draw(BRect updateRect); 185 virtual void MessageReceived(BMessage*); 186 187 void BuildAttrQuery(BQuery*, bool& dynamicDate) const; 188 BPopUpMenu* MimeTypeMenu() const { return fMimeTypeMenu; } 189 BMenuItem* CurrentMimeType(const char** type = NULL) const; 190 status_t SetCurrentMimeType(BMenuItem* item); 191 status_t SetCurrentMimeType(const char* label); 192 193 BPopUpMenu* VolMenu() const { return fVolMenu; } 194 uint32 Mode() const { return fMode; } 195 196 static uint32 InitialMode(const BNode* entry); 197 void SaveWindowState(BNode*, bool editTemplate); 198 199 void SwitchToTemplate(const BNode*); 200 201 // build up a query from by-attribute items 202 void GetByAttrPredicate(BQuery*, bool& dynamicDate) const; 203 // build up a simple query from the name we are searching for 204 void GetByNamePredicate(BQuery*) const; 205 206 void GetDefaultName(BString&) const; 207 void GetDefaultAttrName(BString&, int32) const; 208 // name filled out in the query name text field 209 const char* UserSpecifiedName() const; 210 211 // populate the recent query menu with query templates and recent queries 212 static void AddRecentQueries(BMenu*, bool addSaveAsItem, 213 const BMessenger* target, uint32 what); 214 215private: 216 // populates the type menu 217 void AddMimeTypesToMenu(); 218 static bool AddOneMimeTypeToMenu(const ShortMimeInfo*, void* castToMenu); 219 220 // populates the volume menu 221 void AddVolumes(BMenu*); 222 223 void ShowVolumeMenuLabel(); 224 225 // add one more attribute item to the attr view 226 void AddAttrRow(); 227 // remove the last attribute item 228 void RemoveAttrRow(); 229 void AddFirstAttr(); 230 231 // panel building/restoring calls 232 void RestoreWindowState(const BNode*); 233 void RestoreMimeTypeMenuSelection(const BNode*); 234 void AddByAttributeItems(const BNode*); 235 void RemoveByAttributeItems(); 236 void RemoveAttrViewItems(bool removeGrid = true); 237 // MimeTypeWindow is only shown in kByNameItem and kByAttributeItem modes 238 void ShowOrHideMimeTypeMenu(); 239 240 void AddAttributeControls(int32); 241 242 // fMode gets set by this and the call relies on it being up-to-date 243 void ShowOrHideMoreOptions(bool show); 244 static int32 InitialAttrCount(const BNode*); 245 void FillCurrentQueryName(BTextControl*, FindWindow*); 246 void AddByNameOrFormulaItems(); 247 void SetupAddRemoveButtons(); 248 249 // go from search by name to search by attribute, etc. 250 void SwitchMode(uint32); 251 252 void PushMimeType(BQuery* query) const; 253 254 void SaveAsQueryOrTemplate(const entry_ref*, 255 const char*, bool queryTemplate); 256 257 BView* FindAttrView(const char*, int row) const; 258 259 void AddAttributes(BMenu* menu, const BMimeType& type); 260 void AddMimeTypeAttrs(BMenu* menu); 261 void RestoreAttrState(const BMessage&, int32); 262 void SaveAttrState(BMessage*, int32); 263 void AddLogicMenu(int32, bool selectAnd = true); 264 void RemoveLogicMenu(int32); 265 266 void ResizeMenuField(BMenuField*); 267 268private: 269 uint32 fMode; 270 BGridLayout* fAttrGrid; 271 BPopUpMenu* fMimeTypeMenu; 272 BMenuField* fMimeTypeField; 273 BPopUpMenu* fVolMenu; 274 BPopUpMenu* fSearchModeMenu; 275 BPopUpMenu* fRecentQueries; 276 BBox* fMoreOptions; 277 BTextControl* fQueryName; 278 BString fInitialQueryName; 279 280 BCheckBox* fTemporaryCheck; 281 BCheckBox* fSearchTrashCheck; 282 283 DraggableIcon* fDraggableIcon; 284 285 typedef BView _inherited; 286 287 friend class RecentQueriesPopUp; 288}; 289 290 291// transient queries get deleted if they didn't get used in a while; 292// this is the task that takes care of it 293class DeleteTransientQueriesTask { 294public: 295 virtual ~DeleteTransientQueriesTask(); 296 297 static void StartUpTransientQueryCleaner(); 298 299 // returns true when done 300 bool DoSomeWork(); 301 302protected: 303 DeleteTransientQueriesTask(); 304 305 void Initialize(); 306 bool GetSome(); 307 308 bool ProcessOneRef(Model*); 309 310protected: 311 enum State { 312 kInitial, 313 kAllocatedWalker, 314 kTraversing, 315 kError 316 }; 317 318protected: 319 State state; 320 321private: 322 BTrackerPrivate::TNodeWalker* fWalker; 323}; 324 325 326class RecentFindItemsMenu : public BMenu { 327public: 328 RecentFindItemsMenu(const char* title, 329 const BMessenger* target, uint32 what); 330 331protected: 332 virtual void AttachedToWindow(); 333 334private: 335 BMessenger fTarget; 336 uint32 fWhat; 337}; 338 339 340// query/query template drag&drop helper 341class DraggableQueryIcon : public DraggableIcon { 342public: 343 DraggableQueryIcon(BRect frame, const char* name, 344 const BMessage* message, BMessenger target, 345 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, 346 uint32 flags = B_WILL_DRAW); 347 348protected: 349 virtual bool DragStarted(BMessage*); 350}; 351 352} // namespace BPrivate 353 354using namespace BPrivate; 355 356#endif // _FIND_PANEL_H 357