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 #include <Message.h> 36 #include <PropertyInfo.h> 37 38 #include "Tracker.h" 39 #include "FSUtils.h" 40 41 #define kPropertyTrash "Trash" 42 #define kPropertyFolder "Folder" 43 44 #if 0 45 46 doo Tracker delete Trash 47 doo Tracker create Folder to '/boot/home/Desktop/hello' 48 49 ToDo: 50 Create file: on a "Tracker" "File" "B_CREATE_PROPERTY" "name" 51 Create query: on a "Tracker" "Query" "B_CREATE_PROPERTY" "name" 52 Open a folder: Tracker Execute "Folder" bla 53 Find a window for a path 54 55 #endif 56 57 58 #if _SUPPORTS_FEATURE_SCRIPTING 59 60 const property_info kTrackerPropertyList[] = { 61 { kPropertyTrash, 62 { B_DELETE_PROPERTY }, 63 { B_DIRECT_SPECIFIER }, 64 "delete Trash # Empties the Trash", 65 0, 66 {}, 67 {}, 68 {} 69 }, 70 { kPropertyFolder, 71 { B_CREATE_PROPERTY }, 72 { B_DIRECT_SPECIFIER }, 73 "create Folder to path # creates a new folder", 74 0, 75 { B_REF_TYPE }, 76 {}, 77 {} 78 }, 79 {NULL, 80 {}, 81 {}, 82 NULL, 0, 83 {}, 84 {}, 85 {} 86 } 87 }; 88 89 90 status_t 91 TTracker::GetSupportedSuites(BMessage *data) 92 { 93 data->AddString("suites", kTrackerSuites); 94 BPropertyInfo propertyInfo(const_cast<property_info *>(kTrackerPropertyList)); 95 data->AddFlat("messages", &propertyInfo); 96 97 return _inherited::GetSupportedSuites(data); 98 } 99 100 101 BHandler * 102 TTracker::ResolveSpecifier(BMessage *message, int32 index, 103 BMessage *specifier, int32 form, const char *property) 104 { 105 BPropertyInfo propertyInfo(const_cast<property_info *>(kTrackerPropertyList)); 106 107 int32 result = propertyInfo.FindMatch(message, index, specifier, form, property); 108 if (result < 0) { 109 //PRINT(("FindMatch result %d %s\n", result, strerror(result))); 110 return _inherited::ResolveSpecifier(message, index, specifier, 111 form, property); 112 } 113 114 return this; 115 } 116 117 118 bool 119 TTracker::HandleScriptingMessage(BMessage *message) 120 { 121 if (message->what != B_GET_PROPERTY 122 && message->what != B_SET_PROPERTY 123 && message->what != B_CREATE_PROPERTY 124 && message->what != B_COUNT_PROPERTIES 125 && message->what != B_DELETE_PROPERTY 126 && message->what != B_EXECUTE_PROPERTY) 127 return false; 128 129 // dispatch scripting messages 130 BMessage reply(B_REPLY); 131 const char *property = 0; 132 bool handled = false; 133 134 int32 index = 0; 135 int32 form = 0; 136 BMessage specifier; 137 138 status_t result = message->GetCurrentSpecifier(&index, &specifier, 139 &form, &property); 140 141 if (result != B_OK || index == -1) 142 return false; 143 144 ASSERT(property); 145 146 switch (message->what) { 147 case B_CREATE_PROPERTY: 148 handled = CreateProperty(message, &specifier, form, property, &reply); 149 break; 150 151 case B_GET_PROPERTY: 152 handled = GetProperty(&specifier, form, property, &reply); 153 break; 154 155 case B_SET_PROPERTY: 156 handled = SetProperty(message, &specifier, form, property, &reply); 157 break; 158 159 case B_COUNT_PROPERTIES: 160 handled = CountProperty(&specifier, form, property, &reply); 161 break; 162 163 case B_DELETE_PROPERTY: 164 handled = DeleteProperty(&specifier, form, property, &reply); 165 break; 166 167 case B_EXECUTE_PROPERTY: 168 handled = ExecuteProperty(&specifier, form, property, &reply); 169 break; 170 } 171 172 if (handled) 173 // done handling message, send a reply 174 message->SendReply(&reply); 175 176 return handled; 177 } 178 179 180 bool 181 TTracker::CreateProperty(BMessage *message, BMessage *, int32 form, 182 const char *property, BMessage *reply) 183 { 184 bool handled = false; 185 status_t error = B_OK; 186 if (strcmp(property, kPropertyFolder) == 0) { 187 if (form != B_DIRECT_SPECIFIER) 188 return false; 189 190 // create new empty folders 191 entry_ref ref; 192 for (int32 index = 0; 193 message->FindRef("data", index, &ref) == B_OK; index++) { 194 195 BEntry entry(&ref); 196 if (!entry.Exists()) 197 error = FSCreateNewFolder(&ref); 198 199 if (error != B_OK) 200 break; 201 } 202 203 handled = true; 204 } 205 206 if (error != B_OK) 207 reply->AddInt32("error", error); 208 209 return handled; 210 } 211 212 213 bool 214 TTracker::DeleteProperty(BMessage */*specifier*/, int32 form, 215 const char *property, BMessage */*reply*/) 216 { 217 if (strcmp(property, kPropertyTrash) == 0) { 218 // deleting on a selection is handled as removing a part of the selection 219 // not to be confused with deleting a selected item 220 221 if (form != B_DIRECT_SPECIFIER) 222 // only support direct specifier 223 return false; 224 225 // empty the trash 226 FSEmptyTrash(); 227 return true; 228 229 } 230 return false; 231 } 232 233 #else /* _SUPPORTS_FEATURE_SCRIPTING */ 234 235 status_t 236 TTracker::GetSupportedSuites(BMessage */*data*/) 237 { 238 return B_UNSUPPORTED; 239 } 240 241 242 BHandler * 243 TTracker::ResolveSpecifier(BMessage */*message*/, 244 int32 /*index*/, BMessage */*specifier*/, 245 int32 /*form*/, const char */*property*/) 246 { 247 return NULL; 248 } 249 250 251 bool 252 TTracker::HandleScriptingMessage(BMessage */*message*/) 253 { 254 return false; 255 } 256 257 258 bool 259 TTracker::CreateProperty(BMessage */*message*/, BMessage *, int32 /*form*/, 260 const char */*property*/, BMessage */*reply*/) 261 { 262 return false; 263 } 264 265 266 bool 267 TTracker::DeleteProperty(BMessage */*specifier*/, int32 /*form*/, 268 const char */*property*/, BMessage *) 269 { 270 return false; 271 } 272 273 #endif /* _SUPPORTS_FEATURE_SCRIPTING */ 274 275 276 bool 277 TTracker::ExecuteProperty(BMessage *, int32 , const char *, BMessage *) 278 { 279 return false; 280 } 281 282 283 bool 284 TTracker::CountProperty(BMessage *, int32, const char *, BMessage *) 285 { 286 return false; 287 } 288 289 290 bool 291 TTracker::GetProperty(BMessage *, int32, const char *, BMessage *) 292 { 293 return false; 294 } 295 296 297 bool 298 TTracker::SetProperty(BMessage *, BMessage *, int32, const char *, BMessage *) 299 { 300 return false; 301 } 302 303