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 <Window.h> 40 #include <View.h> 41 42 #include "DialogPane.h" 43 #include "ObjectList.h" 44 #include "MimeTypeList.h" 45 #include "Utilities.h" 46 #include "NodeWalker.h" 47 48 49 class BFilePanel; 50 class BQuery; 51 class BBox; 52 class BTextControl; 53 class BCheckBox; 54 class BMenuField; 55 class BFile; 56 class BPopUpMenu; 57 class BGridLayout; 58 59 namespace BPrivate { 60 61 class FindPanel; 62 class Model; 63 class DraggableIcon; 64 class TAttrView; 65 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'; 73 74 #ifdef _IMPEXP_TRACKER 75 _IMPEXP_TRACKER 76 #endif 77 BMenu* TrackerBuildRecentFindItemsMenu(const char* title); 78 79 struct MoreOptionsStruct { 80 bool showMoreOptions; 81 bool searchTrash; 82 int32 reserved1; 83 bool temporary; 84 bool reserved9; 85 bool reserved10; 86 bool reserved11; 87 int32 reserved3; 88 int32 reserved4; 89 int32 reserved5; 90 int32 reserved6; 91 int32 reserved7; 92 int32 reserved8; 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 95 // saved 96 97 MoreOptionsStruct() 98 : showMoreOptions(false), 99 searchTrash(false), 100 reserved1(0), 101 temporary(true), 102 reserved9(false), 103 reserved10(false), 104 reserved11(false), 105 reserved3(0), 106 reserved4(0), 107 reserved5(0), 108 reserved6(0), 109 reserved7(0), 110 reserved8(0) 111 {} 112 113 static void EndianSwap(void* castToThis); 114 115 static void SetQueryTemporary(BNode*, bool on); 116 static bool QueryTemporary(const BNode*); 117 }; 118 119 120 class FindWindow : public BWindow { 121 public: 122 FindWindow(const entry_ref* ref = NULL, 123 bool editIfTemplateOnly = false); 124 virtual ~FindWindow(); 125 126 FindPanel* BackgroundView() const 127 { return fBackground; } 128 129 BNode* QueryNode() const 130 { return fFile; } 131 132 const char* QueryName() const; 133 // reads in the query name from either a saved name in a template 134 // or form a saved query name 135 136 static bool IsQueryTemplate(BNode* file); 137 138 protected: 139 virtual void MessageReceived(BMessage* message); 140 141 private: 142 static BFile* TryOpening(const entry_ref* ref); 143 static void GetDefaultQuery(BEntry &entry); 144 // when opening an empty panel, use the default query to set the 145 // panel up 146 void SaveQueryAttributes(BNode* file, bool templateQuery); 147 148 void Find(); 149 // retrieve the results 150 void Save(); 151 // save the contents of the find window into the query file 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, const BPoint* oldLocation = 0); 158 159 void GetDefaultName(BString &); 160 void GetPredicateString(BString &, bool &dynamicDate); 161 // dynamic date is a date such as 'today' 162 163 BFile* fFile; 164 entry_ref fRef; 165 bool fFromTemplate; 166 bool fEditTemplateOnly; 167 FindPanel* fBackground; 168 mutable BString fQueryNameFromTemplate; 169 BFilePanel* fSaveAsTemplatePanel; 170 171 typedef BWindow _inherited; 172 }; 173 174 175 class FindPanel : public BView { 176 public: 177 FindPanel(BFile*, FindWindow* parent, bool fromTemplate, 178 bool editTemplateOnly); 179 virtual ~FindPanel(); 180 181 virtual void AttachedToWindow(); 182 virtual void Draw(BRect updateRect); 183 virtual void MessageReceived(BMessage*); 184 185 void BuildAttrQuery(BQuery*, bool &dynamicDate) const; 186 BPopUpMenu* MimeTypeMenu() const 187 { return fMimeTypeMenu; } 188 BMenuItem* CurrentMimeType(const char** type = NULL) const; 189 status_t SetCurrentMimeType(BMenuItem* item); 190 status_t SetCurrentMimeType(const char* label); 191 192 BPopUpMenu* VolMenu() const 193 { return fVolMenu; } 194 uint32 Mode() const 195 { return fMode; } 196 197 static uint32 InitialMode(const BNode* entry); 198 void SaveWindowState(BNode*, bool editTemplate); 199 200 void SwitchToTemplate(const BNode*); 201 202 void GetByAttrPredicate(BQuery*, bool &dynamicDate) const; 203 // build up a query from by-attribute items 204 void GetByNamePredicate(BQuery *) const; 205 // build up a simple query from the name we are searching for 206 207 void GetDefaultName(BString &) const; 208 void GetDefaultAttrName(BString &, int32) const; 209 const char* UserSpecifiedName() const; 210 // name filled out in the query name text field 211 212 static void AddRecentQueries(BMenu*, bool addSaveAsItem, 213 const BMessenger* target, uint32 what); 214 // populate the recent query menu with query templates and recent 215 // queries 216 217 private: 218 void AddMimeTypesToMenu(); 219 // populates the type menu 220 static bool AddOneMimeTypeToMenu(const ShortMimeInfo*, void* castToMenu); 221 222 void AddVolumes(BMenu*); 223 // populates the volume menu 224 void ShowVolumeMenuLabel(); 225 226 void AddAttrRow(); 227 // add one more attribute item to the attr view 228 void RemoveAttrRow(); 229 // remove the last attribute item 230 void AddFirstAttr(); 231 232 // panel building/restoring calls 233 void RestoreWindowState(const BNode*); 234 void RestoreMimeTypeMenuSelection(const BNode*); 235 void AddByAttributeItems(const BNode*); 236 void RemoveByAttributeItems(); 237 void RemoveAttrViewItems(bool removeGrid = true); 238 void ShowOrHideMimeTypeMenu(); 239 // MimeTypeWindow is only shown in kByNameItem and 240 // kByAttributeItem modes 241 242 void AddAttributeControls(int32); 243 244 void ShowOrHideMoreOptions(bool show); 245 // fMode gets set by this and the call relies on it being 246 // up-to-date 247 static int32 InitialAttrCount(const BNode*); 248 void FillCurrentQueryName(BTextControl*, FindWindow*); 249 void AddByNameOrFormulaItems(); 250 void SetUpAddRemoveButtons(BBox* box); 251 252 void SwitchMode(uint32); 253 // go from search by name to search by attribute, etc. 254 255 void PushMimeType(BQuery* query) const; 256 257 void SaveAsQueryOrTemplate(const entry_ref*, const char*, bool queryTemplate); 258 259 BView* FindAttrView(const char*, int row) const; 260 261 void AddAttributes(BMenu* menu, const BMimeType &type); 262 void AddMimeTypeAttrs(BMenu* menu); 263 void RestoreAttrState(const BMessage &, int32); 264 void SaveAttrState(BMessage*, int32); 265 void AddLogicMenu(int32, bool selectAnd = true); 266 void RemoveLogicMenu(int32); 267 268 void ResizeMenuField(BMenuField*); 269 270 uint32 fMode; 271 BGridLayout* fAttrGrid; 272 BPopUpMenu* fMimeTypeMenu; 273 BMenuField* fMimeTypeField; 274 BPopUpMenu* fVolMenu; 275 BPopUpMenu* fSearchModeMenu; 276 BPopUpMenu* fRecentQueries; 277 BBox* fMoreOptions; 278 BTextControl* fQueryName; 279 BString fInitialQueryName; 280 281 BCheckBox* fTemporaryCheck; 282 BCheckBox* fSearchTrashCheck; 283 284 PaneSwitch* fLatch; 285 DraggableIcon* fDraggableIcon; 286 287 typedef BView _inherited; 288 289 friend class RecentQueriesPopUp; 290 }; 291 292 293 class DeleteTransientQueriesTask { 294 // transient queries get deleted if they didn't get used in a while; 295 // this is the task that takes care of it 296 public: 297 static void StartUpTransientQueryCleaner(); 298 299 bool DoSomeWork(); 300 virtual ~DeleteTransientQueriesTask(); 301 302 protected: 303 DeleteTransientQueriesTask(); 304 // returns true when done 305 306 enum State { 307 kInitial, 308 kAllocatedWalker, 309 kTraversing, 310 kError 311 }; 312 313 State state; 314 315 void Initialize(); 316 bool GetSome(); 317 318 bool ProcessOneRef(Model*); 319 320 private: 321 BTrackerPrivate::TNodeWalker* fWalker; 322 }; 323 324 325 class RecentFindItemsMenu : public BMenu { 326 public: 327 RecentFindItemsMenu(const char* title, const BMessenger* target, 328 uint32 what); 329 330 protected: 331 virtual void AttachedToWindow(); 332 333 private: 334 BMessenger fTarget; 335 uint32 fWhat; 336 }; 337 338 339 class DraggableQueryIcon : public DraggableIcon { 340 // query/query template drag&drop helper 341 public: 342 DraggableQueryIcon(BRect frame, const char* name, 343 const BMessage* message, BMessenger target, 344 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, 345 uint32 flags = B_WILL_DRAW); 346 347 protected: 348 virtual bool DragStarted(BMessage*); 349 }; 350 351 } // namespace BPrivate 352 353 using namespace BPrivate; 354 355 #endif 356