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 35 #ifndef _FIND_PANEL_H 36 #define _FIND_PANEL_H 37 38 39 #include <ByteOrder.h> 40 #include <Window.h> 41 #include <View.h> 42 43 44 #include "DialogPane.h" 45 #include "ObjectList.h" 46 #include "MimeTypeList.h" 47 #include "Utilities.h" 48 #include "NodeWalker.h" 49 50 class BFilePanel; 51 class BQuery; 52 class BBox; 53 class BTextControl; 54 class BCheckBox; 55 class BMenuField; 56 class BFile; 57 58 namespace BPrivate { 59 60 class FindPanel; 61 class Model; 62 class DraggableIcon; 63 class TAttrView; 64 65 const uint32 kVolumeItem = 'Fvol'; 66 const uint32 kAttributeItemMain = 'Fatr'; 67 const uint32 kByNameItem = 'Fbyn'; 68 const uint32 kByAttributeItem = 'Fbya'; 69 const uint32 kByForumlaItem = 'Fbyq'; 70 const uint32 kAddItem = 'Fadd'; 71 const uint32 kRemoveItem = 'Frem'; 72 73 #if !B_BEOS_VERSION_DANO 74 _IMPEXP_TRACKER 75 #endif 76 BMenu *TrackerBuildRecentFindItemsMenu(const char *); 77 78 struct MoreOptionsStruct { 79 bool showMoreOptions; 80 bool searchTrash; 81 int32 reserved1; 82 bool temporary; 83 bool reserved9; 84 bool reserved10; 85 bool reserved11; 86 int32 reserved3; 87 int32 reserved4; 88 int32 reserved5; 89 int32 reserved6; 90 int32 reserved7; 91 int32 reserved8; 92 // reserve a bunch of fields so that we can add stuff later but not 93 // make old queries incompatible. Reserved fields are set to 0 when 94 // saved 95 96 MoreOptionsStruct() 97 : showMoreOptions(false), 98 searchTrash(false), 99 reserved1(0), 100 temporary(true), 101 reserved9(false), 102 reserved10(false), 103 reserved11(false), 104 reserved3(0), 105 reserved4(0), 106 reserved5(0), 107 reserved6(0), 108 reserved7(0), 109 reserved8(0) 110 {} 111 112 static void EndianSwap(void *castToThis); 113 114 static void SetQueryTemporary(BNode *, bool on); 115 static bool QueryTemporary(const BNode *); 116 }; 117 118 119 class FindWindow : public BWindow { 120 public: 121 FindWindow(const entry_ref * = NULL, bool editIfTemplateOnly = false); 122 virtual ~FindWindow(); 123 124 FindPanel *BackgroundView() const 125 { return fBackground; } 126 127 BNode *QueryNode() const 128 { return fFile; } 129 130 const char *QueryName() const; 131 // reads in the query name from either a saved name in a template or 132 // form a saved query name 133 134 static bool IsQueryTemplate(BNode *); 135 136 protected: 137 virtual void MessageReceived(BMessage *); 138 139 private: 140 static BFile *TryOpening(const entry_ref *); 141 static void GetDefaultQuery(BEntry &entry); 142 // when opening an empty panel, use the default query to set the panel up 143 void SaveQueryAttributes(BNode *, bool templateQuery); 144 145 void Find(); 146 // retrieve the results 147 void Save(); 148 // save the contents of the find window into the query file 149 150 void SwitchToTemplate(const entry_ref *); 151 bool FindSaveCommon(bool find); 152 153 status_t SaveQueryAsAttributes(BNode *, BEntry *, bool queryTemplate, 154 const BMessage *oldAttributes = 0, const BPoint *oldLocation = 0); 155 156 void GetDefaultName(BString &); 157 void GetPredicateString(BString &, bool &dynamicDate); 158 // dynamic date is a date such as 'today' 159 160 BFile *fFile; 161 entry_ref fRef; 162 bool fFromTemplate; 163 bool fEditTemplateOnly; 164 FindPanel *fBackground; 165 mutable BString fQueryNameFromTemplate; 166 BFilePanel *fSaveAsTemplatePanel; 167 168 typedef BWindow _inherited; 169 }; 170 171 172 class FindPanel : public BView { 173 public: 174 FindPanel(BRect, BFile *, FindWindow *parent, bool fromTemplate, 175 bool editTemplateOnly); 176 virtual ~FindPanel(); 177 178 virtual void AttachedToWindow(); 179 virtual void MessageReceived(BMessage*); 180 181 void BuildAttrQuery(BQuery *, bool &dynamicDate) const; 182 BPopUpMenu *MimeTypeMenu() const 183 { return fMimeTypeMenu; } 184 BMenuItem *CurrentMimeType(const char **type = NULL) const; 185 status_t SetCurrentMimeType(BMenuItem *item); 186 status_t SetCurrentMimeType(const char *label); 187 188 BPopUpMenu *VolMenu() const 189 { return fVolMenu; } 190 uint32 Mode() const 191 { return fMode; } 192 193 static BRect InitialViewSize(const BNode *); 194 // used when showing window, does not account for more options, 195 // those if used will force a resize later 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 const char *UserSpecifiedName() const; 209 // name filled out in the query name text field 210 211 static void AddRecentQueries(BMenu *, bool addSaveAsItem, 212 const BMessenger *target, uint32 what); 213 // populate the recent query menu with query templates and recent 214 // queries 215 216 private: 217 static float ViewHeightForMode(uint32 mode, bool moreOptions); 218 // accouts for moreOptions 219 // if in attributeView, only returns valid result if one attr only 220 static float BoxHeightForMode(uint32 mode, bool moreOptions); 221 222 void AddMimeTypesToMenu(); 223 // populates the type menu 224 static bool AddOneMimeTypeToMenu(const ShortMimeInfo *, void *); 225 226 void AddVolumes(BMenu *); 227 // populates the volume menu 228 void ShowVolumeMenuLabel(); 229 230 void AddAttrView(); 231 // add one more attribute item to the attr view 232 void RemoveAttrView(); 233 // remove the last attribute item 234 void AddFirstAttr(); 235 236 // panel building/restoring calls 237 void RestoreWindowState(const BNode *); 238 void RestoreMimeTypeMenuSelection(const BNode *); 239 void AddByAttributeItems(const BNode *); 240 void ResizeAttributeBox(const BNode *); 241 void RemoveByAttributeItems(); 242 void RemoveAttrViewItems(); 243 void ShowOrHideMimeTypeMenu(); 244 // MimeTypeWindow is only shown in kByNameItem and kByAttributeItem modes 245 246 void ShowOrHideMoreOptions(bool show); 247 // fMode gets set by this and the call relies on it being up-to-date 248 static int32 InitialAttrCount(const BNode *); 249 void FillCurrentQueryName(BTextControl *, FindWindow *); 250 void AddByNameOrFormulaItems(); 251 void AddOneAttributeItem(BBox *box, BRect); 252 void SetUpAddRemoveButtons(BBox *box); 253 254 void SwitchMode(uint32); 255 // go from search by name to search by attribute, etc. 256 257 void PushMimeType(BQuery *query) const; 258 259 void SaveAsQueryOrTemplate(const entry_ref *, const char *, bool queryTemplate); 260 261 uint32 fMode; 262 BObjectList<TAttrView> fAttrViewList; 263 BPopUpMenu *fMimeTypeMenu; 264 BMenuField *fMimeTypeField; 265 BPopUpMenu *fVolMenu; 266 BPopUpMenu *fSearchModeMenu; 267 BPopUpMenu *fRecentQueries; 268 DialogPane *fMoreOptionsPane; 269 BTextControl *fQueryName; 270 BString fInitialQueryName; 271 272 BCheckBox *fTemporaryCheck; 273 BCheckBox *fSearchTrashCheck; 274 275 PaneSwitch *fLatch; 276 DraggableIcon *fDraggableIcon; 277 278 typedef BView _inherited; 279 280 friend class RecentQueriesPopUp; 281 }; 282 283 class TAttrView : public BView { 284 // a single attribute item - the search by attribute view 285 // can add several of these 286 public: 287 TAttrView(BRect, int32 index); 288 ~TAttrView(); 289 290 virtual void AttachedToWindow(); 291 292 void RestoreState(const BMessage &, int32); 293 void SaveState(BMessage *, int32); 294 295 virtual void Draw(BRect); 296 virtual void MessageReceived(BMessage *); 297 298 void AddLogicMenu(bool selectAnd = true); 299 void RemoveLogicMenu(); 300 void AddMimeTypeAttrs(); 301 void MakeTextViewFocus(); 302 303 void GetDefaultName(BString &result) const; 304 305 private: 306 void AddMimeTypeAttrs(BMenu *); 307 308 BMenuField *fMenuField; 309 BTextControl *fTextControl; 310 311 typedef BView _inherited; 312 }; 313 314 315 class DeleteTransientQueriesTask { 316 // transient queries get deleted if they didn't get used in a while; 317 // this is the task that takes care of it 318 public: 319 static void StartUpTransientQueryCleaner(); 320 321 bool DoSomeWork(); 322 virtual ~DeleteTransientQueriesTask(); 323 324 protected: 325 DeleteTransientQueriesTask(); 326 // returns true when done 327 328 enum State { 329 kInitial, 330 kAllocatedWalker, 331 kTraversing, 332 kError 333 }; 334 335 State state; 336 337 void Initialize(); 338 bool GetSome(); 339 340 bool ProcessOneRef(Model *); 341 342 private: 343 WALKER_NS::TNodeWalker *fWalker; 344 }; 345 346 347 class RecentFindItemsMenu : public BMenu { 348 public: 349 RecentFindItemsMenu(const char *title, const BMessenger *target, uint32 what); 350 351 protected: 352 virtual void AttachedToWindow(); 353 354 private: 355 BMessenger fTarget; 356 uint32 fWhat; 357 }; 358 359 360 class DraggableQueryIcon : public DraggableIcon { 361 // query/query template drag&drop helper 362 public: 363 DraggableQueryIcon(BRect frame, const char *name, const BMessage *message, 364 BMessenger target, uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, 365 uint32 flags = B_WILL_DRAW); 366 367 protected: 368 virtual bool DragStarted(BMessage *); 369 }; 370 371 } // namespace BPrivate 372 373 using namespace BPrivate; 374 375 #endif 376