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 #ifndef _FIND_PANEL_H 35 #define _FIND_PANEL_H 36 37 38 #include <ByteOrder.h> 39 #include <FilePanel.h> 40 #include <ObjectList.h> 41 #include <View.h> 42 #include <Window.h> 43 44 #include "DialogPane.h" 45 #include "MimeTypeList.h" 46 #include "Utilities.h" 47 #include "NodeWalker.h" 48 49 50 class BFilePanel; 51 class BQuery; 52 class BBox; 53 class BTextControl; 54 class BCheckBox; 55 class BMenuBar; 56 class BMenuField; 57 class BFile; 58 class BPopUpMenu; 59 class BGroupView; 60 class BGridLayout; 61 62 namespace BPrivate { 63 64 class FindPanel; 65 class Model; 66 class DraggableIcon; 67 class TAttrView; 68 69 const uint32 kVolumeItem = 'Fvol'; 70 const uint32 kAttributeItemMain = 'Fatr'; 71 const uint32 kByNameItem = 'Fbyn'; 72 const uint32 kByAttributeItem = 'Fbya'; 73 const uint32 kByFormulaItem = 'Fbyq'; 74 const uint32 kAddItem = 'Fadd'; 75 const uint32 kRemoveItem = 'Frem'; 76 77 const uint32 kSaveQueryOrTemplate = 'FSaQ'; 78 const uint32 kOpenSaveAsPanel = 'Fosv'; 79 const uint32 kOpenLoadQueryPanel = 'Folo'; 80 const uint32 kTemporaryOptionClicked = 'FTCl'; 81 const uint32 kSearchInTrashOptionClicked = 'FSCl'; 82 83 const uint32 kSelectDirectoryFilter = 'FSeD'; 84 const uint32 kAddDirectoryFilters = 'FAdF'; 85 const uint32 kRemoveDirectoryFilter = 'FRmD'; 86 87 #ifdef _IMPEXP_TRACKER 88 _IMPEXP_TRACKER 89 #endif 90 BMenu* TrackerBuildRecentFindItemsMenu(const char* title); 91 92 struct MoreOptionsStruct { 93 // Some options used to be in a collapsable part of the window, but 94 // this was removed. Now the options are always visible. 95 bool showMoreOptions; 96 bool searchTrash; 97 // reserve a bunch of fields so that we can add stuff later but not 98 // make old queries incompatible. Reserved fields are set to 0 when 99 // saved 100 int32 reserved1; 101 bool temporary; 102 bool reserved9; 103 bool reserved10; 104 bool reserved11; 105 int32 reserved3; 106 int32 reserved4; 107 int32 reserved5; 108 int32 reserved6; 109 int32 reserved7; 110 int32 reserved8; 111 MoreOptionsStructMoreOptionsStruct112 MoreOptionsStruct() 113 : 114 showMoreOptions(true), 115 searchTrash(false), 116 reserved1(0), 117 temporary(true), 118 reserved9(false), 119 reserved10(false), 120 reserved11(false), 121 reserved3(0), 122 reserved4(0), 123 reserved5(0), 124 reserved6(0), 125 reserved7(0), 126 reserved8(0) 127 {} 128 129 static void EndianSwap(void* castToThis); 130 131 static void SetQueryTemporary(BNode*, bool on); 132 static bool QueryTemporary(const BNode*); 133 }; 134 135 136 class FindWindow : public BWindow { 137 public: 138 FindWindow(const entry_ref* ref = NULL, 139 bool editIfTemplateOnly = false); 140 virtual ~FindWindow(); 141 BackgroundView()142 FindPanel* BackgroundView() const { return fBackground; } 143 QueryNode()144 BNode* QueryNode() const { return fFile; } 145 146 // reads in the query name from either a saved name in a template 147 // or form a saved query name 148 const char* QueryName() const; 149 150 static bool IsQueryTemplate(BNode* file); 151 void SetOptions(bool searchInTrash); 152 void AddIconToMenuBar(BView*); 153 154 protected: 155 virtual void MessageReceived(BMessage* message); 156 157 private: 158 static BFile* TryOpening(const entry_ref* ref); 159 static BPath GetQueriesDirectory(); 160 void SaveQueryAttributes(BNode* file, bool templateQuery); 161 162 // retrieve the results 163 void Find(); 164 // save the contents of the find window into the query file 165 void Save(); 166 167 void SwitchToTemplate(const entry_ref*); 168 bool FindSaveCommon(bool find); 169 170 status_t SaveQueryAsAttributes(BNode*, BEntry*, bool queryTemplate, 171 const BMessage* oldAttributes = 0, 172 const BPoint* oldLocation = 0, bool temporary = true); 173 174 void GetDefaultName(BString&); 175 // dynamic date is a date such as 'today' 176 void GetPredicateString(BString&, bool& dynamicDate); 177 178 void BuildMenuBar(); 179 void PopulateTemplatesMenu(); 180 void UpdateFileReferences(const entry_ref*); 181 void ClearHistoryOrTemplates(bool clearTemplates, bool temporaryOnly); 182 status_t DeleteQueryOrTemplate(BEntry*); 183 184 private: 185 BFile* fFile; 186 entry_ref fRef; 187 bool fFromTemplate; 188 bool fEditTemplateOnly; 189 FindPanel* fBackground; 190 mutable BString fQueryNameFromTemplate; 191 BFilePanel* fSaveAsPanel; 192 BFilePanel* fOpenQueryPanel; 193 194 // Menu Bar For New Panel 195 BGroupView* fMenuBarContainer; 196 BMenuBar* fMenuBar; 197 BMenu* fQueryMenu; 198 BMenuItem* fSaveQueryOrTemplateItem; 199 BMenu* fOptionsMenu; 200 BMenu* fTemplatesMenu; 201 BMenu* fHistoryMenu; 202 BMenu* fSaveAsMenu; 203 BMenuItem* fSearchInTrash; 204 205 typedef BWindow _inherited; 206 }; 207 208 209 class FindPanel : public BView { 210 public: 211 FindPanel(BFile*, FindWindow* parent, bool fromTemplate, 212 bool editTemplateOnly); 213 virtual ~FindPanel(); 214 215 virtual void AttachedToWindow(); 216 virtual void Draw(BRect updateRect); 217 virtual void MessageReceived(BMessage*); 218 219 void BuildAttrQuery(BQuery*, bool& dynamicDate) const; MimeTypeMenu()220 BPopUpMenu* MimeTypeMenu() const { return fMimeTypeMenu; } 221 BMenuItem* CurrentMimeType(const char** type = NULL) const; 222 status_t SetCurrentMimeType(BMenuItem* item); 223 status_t SetCurrentMimeType(const char* label); 224 225 BPopUpMenu* VolMenu(int32* firstVolumeItem = NULL, 226 int32* volumeItemsCount = NULL) const; Mode()227 uint32 Mode() const { return fMode; } 228 229 static uint32 InitialMode(const BNode* entry); 230 void SaveWindowState(BNode*, bool editTemplate); 231 232 void SwitchToTemplate(const BNode*); 233 234 // build up a query from by-attribute items 235 void GetByAttrPredicate(BQuery*, bool& dynamicDate) const; 236 // build up a simple query from the name we are searching for 237 void GetByNamePredicate(BQuery*) const; 238 239 void GetDefaultName(BString&) const; 240 void GetDefaultAttrName(BString&, int32) const; 241 // name filled out in the query name text field 242 const char* UserSpecifiedName() const; 243 244 // populate the recent query menu with query templates and recent queries 245 static void AddRecentQueries(BMenu*, bool addSaveAsItem, 246 const BMessenger* target, uint32 what, 247 bool includeTemplates = true); 248 249 status_t SaveDirectoryFiltersToFile(BNode*); 250 void LoadDirectoryFiltersFromFile(const BNode*); 251 252 private: 253 void AddMimeTypesToMenu(); 254 static bool AddOneMimeTypeToMenu(const ShortMimeInfo*, void* castToMenu); 255 256 void AddVolumes(); 257 258 void ShowVolumeMenuLabel(); 259 260 // add one more attribute item to the attr view 261 void AddAttrRow(); 262 // remove the last attribute item 263 void RemoveAttrRow(); 264 void AddFirstAttr(); 265 266 // panel building/restoring calls 267 void RestoreWindowState(const BNode*); 268 void RestoreMimeTypeMenuSelection(const BNode*); 269 void AddByAttributeItems(const BNode*); 270 void RemoveByAttributeItems(); 271 void RemoveAttrViewItems(bool removeGrid = true); 272 // MimeTypeWindow is only shown in kByNameItem and kByAttributeItem modes 273 void ShowOrHideMimeTypeMenu(); 274 275 void AddAttributeControls(int32); 276 277 // fMode gets set by this and the call relies on it being up-to-date 278 void ShowOrHideMoreOptions(bool show); 279 static int32 InitialAttrCount(const BNode*); 280 void FillCurrentQueryName(BTextControl*, FindWindow*); 281 void AddByNameOrFormulaItems(); 282 void SetupAddRemoveButtons(); 283 284 // go from search by name to search by attribute, etc. 285 void SwitchMode(uint32); 286 287 void PushMimeType(BQuery* query) const; 288 289 void SaveAsQueryOrTemplate(const entry_ref*, 290 const char*, bool queryTemplate); 291 292 BView* FindAttrView(const char*, int row) const; 293 294 void AddAttributes(BMenu* menu, const BMimeType& type); 295 void AddMimeTypeAttrs(BMenu* menu); 296 void RestoreAttrState(const BMessage&, int32); 297 void SaveAttrState(BMessage*, int32); 298 void AddLogicMenu(int32, bool selectAnd = true); 299 void RemoveLogicMenu(int32); 300 301 void ResizeMenuField(BMenuField*); 302 303 status_t AddDirectoryFiltersToMenu(BMenu*, BHandler* target); 304 status_t AddDirectoryFilter(const entry_ref* ref, bool addToMenu = true); 305 void RemoveDirectoryFilter(const entry_ref* ref); 306 static status_t AddDirectoryFilterItemToMenu(BMenu*, const entry_ref* ref, 307 BHandler* target, int32 index = -1); 308 void UnmarkDisks(); 309 void MarkDiskAccordingToDirectoryFilter(entry_ref*); 310 311 public: 312 BObjectList<entry_ref> fDirectoryFilters; 313 314 private: 315 uint32 fMode; 316 BGridLayout* fAttrGrid; 317 BPopUpMenu* fMimeTypeMenu; 318 BMenuField* fMimeTypeField; 319 BPopUpMenu* fSearchModeMenu; 320 BMenuField* fSearchModeField; 321 BPopUpMenu* fVolMenu; 322 int32 fFirstVolumeItem, fVolumeItemsCount; 323 BMenuField* fVolumeField; 324 BPopUpMenu* fRecentQueries; 325 BBox* fMoreOptions; 326 BTextControl* fQueryName; 327 BString fInitialQueryName; 328 329 DraggableIcon* fDraggableIcon; 330 331 BFilePanel* fDirectorySelectPanel; 332 333 bool fAddSeparatorItemState; 334 335 typedef BView _inherited; 336 337 friend class RecentQueriesPopUp; 338 }; 339 340 341 // transient queries get deleted if they didn't get used in a while; 342 // this is the task that takes care of it 343 class DeleteTransientQueriesTask { 344 public: 345 virtual ~DeleteTransientQueriesTask(); 346 347 static void StartUpTransientQueryCleaner(); 348 349 // returns true when done 350 bool DoSomeWork(); 351 352 protected: 353 DeleteTransientQueriesTask(); 354 355 void Initialize(); 356 bool GetSome(); 357 358 bool ProcessOneRef(Model*); 359 360 protected: 361 enum State { 362 kInitial, 363 kAllocatedWalker, 364 kTraversing, 365 kError 366 }; 367 368 static bool QueryOldEnough(Model* model); 369 370 protected: 371 State state; 372 373 private: 374 static const int32 kBatchCount = 100; 375 static const int32 kDaysToExpire = 7; 376 377 BTrackerPrivate::TNodeWalker* fWalker; 378 }; 379 380 381 class RecentFindItemsMenu : public BMenu { 382 public: 383 RecentFindItemsMenu(const char* title, 384 const BMessenger* target, uint32 what); 385 386 protected: 387 virtual void AttachedToWindow(); 388 389 private: 390 BMessenger fTarget; 391 uint32 fWhat; 392 }; 393 394 395 // query/query template drag&drop helper 396 class DraggableQueryIcon : public DraggableIcon { 397 public: 398 DraggableQueryIcon(BRect frame, const char* name, 399 const BMessage* message, BMessenger target, 400 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, 401 uint32 flags = B_WILL_DRAW); 402 403 protected: 404 virtual bool DragStarted(BMessage*); 405 }; 406 407 408 class FolderFilter : public BRefFilter { 409 public: 410 virtual bool Filter(const entry_ref*, BNode*, struct stat_beos*, const char*); 411 }; 412 413 } // namespace BPrivate 414 415 using namespace BPrivate; 416 417 #endif // _FIND_PANEL_H 418