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 class BPopUpMenu; 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 or 134 // 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 panel up 145 void SaveQueryAttributes(BNode *file, bool templateQuery); 146 147 void Find(); 148 // retrieve the results 149 void Save(); 150 // save the contents of the find window into the query file 151 152 void SwitchToTemplate(const entry_ref *); 153 bool FindSaveCommon(bool find); 154 155 status_t SaveQueryAsAttributes(BNode *, BEntry *, bool queryTemplate, 156 const BMessage *oldAttributes = 0, const BPoint *oldLocation = 0); 157 158 void GetDefaultName(BString &); 159 void GetPredicateString(BString &, bool &dynamicDate); 160 // dynamic date is a date such as 'today' 161 162 BFile *fFile; 163 entry_ref fRef; 164 bool fFromTemplate; 165 bool fEditTemplateOnly; 166 FindPanel *fBackground; 167 mutable BString fQueryNameFromTemplate; 168 BFilePanel *fSaveAsTemplatePanel; 169 170 typedef BWindow _inherited; 171 }; 172 173 174 class FindPanel : public BView { 175 public: 176 FindPanel(BRect, BFile *, FindWindow *parent, bool fromTemplate, 177 bool editTemplateOnly); 178 virtual ~FindPanel(); 179 180 virtual void AttachedToWindow(); 181 virtual void MessageReceived(BMessage*); 182 183 void BuildAttrQuery(BQuery *, bool &dynamicDate) const; 184 BPopUpMenu *MimeTypeMenu() const 185 { return fMimeTypeMenu; } 186 BMenuItem *CurrentMimeType(const char **type = NULL) const; 187 status_t SetCurrentMimeType(BMenuItem *item); 188 status_t SetCurrentMimeType(const char *label); 189 190 BPopUpMenu *VolMenu() const 191 { return fVolMenu; } 192 uint32 Mode() const 193 { return fMode; } 194 195 static BRect InitialViewSize(const BNode *); 196 // used when showing window, does not account for more options, 197 // those if used will force a resize later 198 199 static uint32 InitialMode(const BNode *entry); 200 void SaveWindowState(BNode *, bool editTemplate); 201 202 void SwitchToTemplate(const BNode *); 203 204 void GetByAttrPredicate(BQuery *, bool &dynamicDate) const; 205 // build up a query from by-attribute items 206 void GetByNamePredicate(BQuery *) const; 207 // build up a simple query from the name we are searching for 208 209 void GetDefaultName(BString &) const; 210 const char *UserSpecifiedName() const; 211 // name filled out in the query name text field 212 213 static void AddRecentQueries(BMenu *, bool addSaveAsItem, 214 const BMessenger *target, uint32 what); 215 // populate the recent query menu with query templates and recent 216 // queries 217 218 private: 219 static float ViewHeightForMode(uint32 mode, bool moreOptions); 220 // accouts for moreOptions 221 // if in attributeView, only returns valid result if one attr only 222 static float BoxHeightForMode(uint32 mode, bool moreOptions); 223 224 void AddMimeTypesToMenu(); 225 // populates the type menu 226 static bool AddOneMimeTypeToMenu(const ShortMimeInfo *, void *); 227 228 void AddVolumes(BMenu *); 229 // populates the volume menu 230 void ShowVolumeMenuLabel(); 231 232 void AddAttrView(); 233 // add one more attribute item to the attr view 234 void RemoveAttrView(); 235 // remove the last attribute item 236 void AddFirstAttr(); 237 238 // panel building/restoring calls 239 void RestoreWindowState(const BNode *); 240 void RestoreMimeTypeMenuSelection(const BNode *); 241 void AddByAttributeItems(const BNode *); 242 void ResizeAttributeBox(const BNode *); 243 void RemoveByAttributeItems(); 244 void RemoveAttrViewItems(); 245 void ShowOrHideMimeTypeMenu(); 246 // MimeTypeWindow is only shown in kByNameItem and kByAttributeItem modes 247 248 void ShowOrHideMoreOptions(bool show); 249 // fMode gets set by this and the call relies on it being up-to-date 250 static int32 InitialAttrCount(const BNode *); 251 void FillCurrentQueryName(BTextControl *, FindWindow *); 252 void AddByNameOrFormulaItems(); 253 void AddOneAttributeItem(BBox *box, BRect); 254 void SetUpAddRemoveButtons(BBox *box); 255 256 void SwitchMode(uint32); 257 // go from search by name to search by attribute, etc. 258 259 void PushMimeType(BQuery *query) const; 260 261 void SaveAsQueryOrTemplate(const entry_ref *, const char *, bool queryTemplate); 262 263 uint32 fMode; 264 BObjectList<TAttrView> fAttrViewList; 265 BPopUpMenu *fMimeTypeMenu; 266 BMenuField *fMimeTypeField; 267 BPopUpMenu *fVolMenu; 268 BPopUpMenu *fSearchModeMenu; 269 BPopUpMenu *fRecentQueries; 270 DialogPane *fMoreOptionsPane; 271 BTextControl *fQueryName; 272 BString fInitialQueryName; 273 274 BCheckBox *fTemporaryCheck; 275 BCheckBox *fSearchTrashCheck; 276 277 PaneSwitch *fLatch; 278 DraggableIcon *fDraggableIcon; 279 280 typedef BView _inherited; 281 282 friend class RecentQueriesPopUp; 283 }; 284 285 class TAttrView : public BView { 286 // a single attribute item - the search by attribute view 287 // can add several of these 288 public: 289 TAttrView(BRect frame, int32 index); 290 ~TAttrView(); 291 292 virtual void AttachedToWindow(); 293 294 void RestoreState(const BMessage &settings, int32 index); 295 void SaveState(BMessage *settings, int32 index); 296 297 virtual void Draw(BRect updateRect); 298 virtual void MessageReceived(BMessage *message); 299 300 void AddLogicMenu(bool selectAnd = true); 301 void RemoveLogicMenu(); 302 void AddMimeTypeAttrs(); 303 void MakeTextViewFocus(); 304 305 void GetDefaultName(BString &result) const; 306 307 private: 308 void AddAttributes(BMenu *menu, const BMimeType &type); 309 void AddMimeTypeAttrs(BMenu *menu); 310 311 BMenuField *fMenuField; 312 BTextControl *fTextControl; 313 314 typedef BView _inherited; 315 }; 316 317 318 class DeleteTransientQueriesTask { 319 // transient queries get deleted if they didn't get used in a while; 320 // this is the task that takes care of it 321 public: 322 static void StartUpTransientQueryCleaner(); 323 324 bool DoSomeWork(); 325 virtual ~DeleteTransientQueriesTask(); 326 327 protected: 328 DeleteTransientQueriesTask(); 329 // returns true when done 330 331 enum State { 332 kInitial, 333 kAllocatedWalker, 334 kTraversing, 335 kError 336 }; 337 338 State state; 339 340 void Initialize(); 341 bool GetSome(); 342 343 bool ProcessOneRef(Model *); 344 345 private: 346 BTrackerPrivate::TNodeWalker *fWalker; 347 }; 348 349 350 class RecentFindItemsMenu : public BMenu { 351 public: 352 RecentFindItemsMenu(const char *title, const BMessenger *target, uint32 what); 353 354 protected: 355 virtual void AttachedToWindow(); 356 357 private: 358 BMessenger fTarget; 359 uint32 fWhat; 360 }; 361 362 363 class DraggableQueryIcon : public DraggableIcon { 364 // query/query template drag&drop helper 365 public: 366 DraggableQueryIcon(BRect frame, const char *name, const BMessage *message, 367 BMessenger target, uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, 368 uint32 flags = B_WILL_DRAW); 369 370 protected: 371 virtual bool DragStarted(BMessage *); 372 }; 373 374 } // namespace BPrivate 375 376 using namespace BPrivate; 377 378 #endif 379