Ticket #7445: cleanups.diff
File cleanups.diff, 43.8 KB (added by , 13 years ago) |
---|
-
src/preferences/appearance/APRView.
old new 39 39 #define DECORATOR_CHANGED 'dcch' 40 40 41 41 42 APRView::APRView(const char *name, uint32 flags)43 42 APRView::APRView(const char* name, uint32 flags) 43 : 44 44 BView(name, flags), 45 45 fDefaultSet(ColorSet::DefaultColorSet()), 46 46 fDecorMenu(NULL), … … 64 64 BMenuField* field = new BMenuField("Window Style", fDecorMenu); 65 65 // TODO: use this menu field. 66 66 } 67 BMenuItem *marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator());67 BMenuItem* marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator()); 68 68 if (marked) 69 69 marked->SetMarked(true); 70 70 else { -
src/preferences/appearance/APRView.
old new 39 39 #define DECORATOR_CHANGED 'dcch' 40 40 41 41 42 APRView::APRView(const char *name, uint32 flags)43 42 APRView::APRView(const char* name, uint32 flags) 43 : 44 44 BView(name, flags), 45 45 fDefaultSet(ColorSet::DefaultColorSet()), 46 46 fDecorMenu(NULL), … … 64 64 BMenuField* field = new BMenuField("Window Style", fDecorMenu); 65 65 // TODO: use this menu field. 66 66 } 67 BMenuItem *marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator());67 BMenuItem* marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator()); 68 68 if (marked) 69 69 marked->SetMarked(true); 70 70 else { -
src/add-ons/decorators/WinDecorator/resources.
old new 1 2 resource("be:decor:info") message('deco') 3 4 { 5 "name" = "Windows 95", 6 "authors" = "", 7 "short_descr" = "Windows 95", 1 resource("be:decor:info") message('deco') { 2 "name" = "Windows 95", 3 "authors" = "", 4 "short_descr" = "Windows 95", 8 5 "long_descr" = "", 9 6 "lic_url" = "", 10 "lic_name" = "MIT",7 "lic_name" = "MIT", 11 8 "support_url" = "http://www.haiku-os.org/", 12 float "version"= 1.09 float "version" = 1.0 13 10 }; 14 -
src/add-ons/decorators/MacDecorator/resources.
old new 1 2 resource("be:decor:info") message('deco') 3 4 { 5 "name" = "MacOS 9", 1 resource("be:decor:info") message('deco') { 2 "name" = "MacOS 9", 6 3 "authors" = "", 7 4 "short_descr" = "MacOS 9", 8 "long_descr" 9 "lic_url" 5 "long_descr" = "", 6 "lic_url" = "", 10 7 "lic_name" = "MIT", 11 "support_url" 12 float "version"= 1.08 "support_url" = "http://www.haiku-os.org/", 9 float "version" = 1.0 13 10 }; 14 -
src/add-ons/decorators/BeDecorator/resources.
old new 1 2 resource("be:decor:info") message('deco') 3 4 { 5 "name" = "Classic BeOS", 1 resource("be:decor:info") message('deco') { 2 "name" = "Classic BeOS", 6 3 "authors" = "DarkWyrm, Stephan Aßmus, Clemens Zeidler", 7 4 "short_descr" = "Basic appearance of the classic BeOS.", 8 "long_descr" 9 "lic_url" 5 "long_descr" = "", 6 "lic_url" = "", 10 7 "lic_name" = "MIT", 11 "support_url" 12 float "version"= 1.08 "support_url" = "http://www.haiku-os.org/", 9 float "version" = 1.0 13 10 }; 14 -
src/add-ons/decorators/SATDecorator/resources.
old new 1 2 resource("be:decor:info") message('deco') 3 4 { 5 "name" = "Stack and Tile", 1 resource("be:decor:info") message('deco') { 2 "name" = "Stack and Tile", 6 3 "authors" = "Clemens Zeidler, Ingo Weinhold", 7 4 "short_descr" = "Default look with ability to stack & tile windows.", 8 "long_descr" 5 "long_descr" = "Group windows together and take advantage of those" 9 6 " tabs!\n\nTODO: instructions", 10 "lic_url" 7 "lic_url" = "", 11 8 "lic_name" = "MIT", 12 "support_url" 13 float "version"= 1.09 "support_url" = "http://www.haiku-os.org/", 10 float "version" = 1.0 14 11 }; 15 -
src/bin/setdecor.
old new 2 2 * Copyright 2011, Joseph "looncraz" Groover, looncraz@satx.rr.com 3 3 * Copyright 2007, François Revol, revol@free.fr. 4 4 * Distributed under the terms of the MIT license. 5 *6 5 */ 7 6 8 7 … … 18 17 #include <private/interface/DecorInfo.h> 19 18 20 19 21 void print_decor_info_header() 20 void 21 print_decor_info_header() 22 22 { 23 23 printf(" Name License\t Description\n"); 24 24 printf("----------------------------------------------------\n"); 25 25 } 26 26 27 27 28 void print_decor_summary(DecorInfo* decor, bool is_current) 28 void 29 print_decor_summary(DecorInfo* decor, bool isCurrent) 29 30 { 30 if ( is_current)31 if (isCurrent) 31 32 printf("*"); 32 33 33 printf("%-12s\t%-8s %-30s\n", decor->Name().String(), 34 decor->LicenseName().String(), 35 decor->ShortDescription().String()); 34 printf("%-12s\t%-8s %-30s\n", decor->Name().String(), 35 decor->LicenseName().String(), decor->ShortDescription().String()); 36 36 } 37 37 38 38 39 void print_decor_shortcut(DecorInfo* decor, bool is_current) 39 void 40 print_decor_shortcut(DecorInfo* decor, bool isCurrent) 40 41 { 41 if ( is_current)42 if (isCurrent) 42 43 printf("*"); 43 44 44 printf("%-12s\t%-12s\n", 45 45 printf("%-12s\t%-12s\n", decor->ShortcutName().String(), 46 decor->Name().String()); 46 47 } 47 48 48 49 49 void print_decor_info_verbose(DecorInfo* decor, bool is_current) 50 void 51 print_decor_info_verbose(DecorInfo* decor, bool isCurrent) 50 52 { 51 53 printf("Name:\t\t%s\n", decor->Name().String()); 52 54 printf("Version:\t%f\n", decor->Version()); 53 55 printf("Author(s):\t%s\n", decor->Authors().String()); 54 56 printf("Description:\t%s\n", decor->ShortDescription().String()); 55 57 printf("License:\t%s (%s)\n", decor->LicenseName().String(), 56 58 decor->LicenseURL().String()); 57 59 printf("Support URL:\t%s\n", decor->SupportURL().String()); 58 printf("%s\n", is _current ? "Currently in use." : "Currently not in use.");60 printf("%s\n", isCurrent ? "Currently in use." : "Currently not in use."); 59 61 } 60 62 61 63 62 int main(int argc, char **argv) 64 int 65 main(int argc, char** argv) 63 66 { 64 67 if (argc < 2) { 65 68 printf("usage: %s [-l|-c|decorname]\n", argv[0]); … … 71 74 return 1; 72 75 } 73 76 74 77 // combine remaining args into one string: 75 78 BString decoratorName; 76 79 for (int i = 2; i < argc; ++i) 77 80 decoratorName << argv[i] << " "; … … 83 86 DecorInfo* decor = NULL; 84 87 85 88 if (util == NULL) { 86 fprintf(stderr, "error instantiating DecoratorInfoUtility ( 87 " memory?)\n");89 fprintf(stderr, "error instantiating DecoratorInfoUtility (out of" 90 " memory?)\n"); 88 91 return 1; 89 92 } 90 93 91 94 // we want the list 92 95 if (!strcmp(argv[1], "-l")) { 93 96 // Print default decorator: 94 95 97 print_decor_info_header(); 96 98 int32 count = util->CountDecorators(); 97 99 for (int32 i = 0; i < count; ++i) { 98 100 decor = util->DecoratorAt(i); 99 101 if (decor == NULL) { 100 102 fprintf(stderr, "error NULL entry @ %li / %li - BUG BUG BUG\n", 101 i, count); 102 return 2; // return 2 to track DecorInfoUtility errors 103 i, count); 104 // return 2 to track DecorInfoUtility errors 105 return 2; 103 106 } 104 107 print_decor_summary(decor, util->IsCurrentDecorator(decor)); 105 108 } … … 113 116 114 117 if (decor == NULL) { 115 118 fprintf(stderr, "Unable to determine current decorator, sorry! - " 116 119 "BUG BUG BUG\n"); 117 120 return 2; 118 121 } 119 122 … … 133 136 decor = util->DecoratorAt(i); 134 137 if (decor == NULL) { 135 138 fprintf(stderr, "error NULL entry @ %li / %li - BUG BUG BUG\n", 136 i, count); 137 return 2; // return 2 to track DecorInfoUtility errors 139 i, count); 140 // return 2 to track DecorInfoUtility errors 141 return 2; 138 142 } 139 143 print_decor_shortcut(decor, util->IsCurrentDecorator(decor)); 140 144 } 141 145 142 146 return 0; 143 144 147 } 145 148 146 149 // we want detailed information for a specific decorator ( by name or path ) … … 153 156 decor = util->FindDecorator(decoratorName.String()); 154 157 155 158 if (decor == NULL) { 156 157 158 159 159 fprintf(stderr, "Can't find decor named \"%s\", try again\n", 160 decoratorName.String()); 161 return 1; 162 } 160 163 161 164 print_decor_info_verbose(decor, util->IsCurrentDecorator(decor)); 162 165 return 0; … … 169 172 return 1; 170 173 } 171 174 172 173 175 decor = util->FindDecorator(decoratorName.String()); 174 176 175 177 if (decor == NULL) { 176 177 178 179 178 fprintf(stderr, "Can't find decor named \"%s\", try again\n", 179 decoratorName.String()); 180 return 1; 181 } 180 182 181 183 printf("Preparing preview...\n"); 182 184 185 BWindow* previewWindow = new BWindow(BRect(150, 150, 390, 490), 186 decor->Name().String(), B_TITLED_WINDOW, B_NOT_ZOOMABLE 187 | B_QUIT_ON_WINDOW_CLOSE | B_NOT_RESIZABLE ); 188 189 previewWindow->AddChild(new BView(previewWindow->Bounds(), "", 190 B_FOLLOW_ALL, 0)); 191 192 if (util->Preview(decor, previewWindow) != B_OK) { 193 fprintf(stderr, "Unable to preview decorator, sorry!\n"); 194 // TODO: more detailed error... 195 return 1; 196 } 183 197 184 BWindow* win = new BWindow(BRect(50,50,290,390), 185 decor->Name().String(), 186 B_TITLED_WINDOW, 187 B_NOT_ZOOMABLE 188 | B_QUIT_ON_WINDOW_CLOSE 189 | B_NOT_RESIZABLE ); 190 191 win->MoveBy(100,100); 192 BView* v = new BView(win->Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW); 193 win->AddChild(v); 194 195 if (util->Preview(decor, win) != B_OK) { 196 fprintf(stderr, "Unable to preview decorator, sorry!\n"); 197 return 1; // todo more detailed error... 198 } 199 200 win->Show(); 198 previewWindow->Show(); 201 199 202 be_app->Run();200 app.Run(); 203 201 return 0; 204 202 } 205 203 206 207 204 // we want to change it 208 205 decoratorName = ""; 209 206 for (int i = 1; i < argc; ++i) … … 219 216 220 217 if (util->IsCurrentDecorator(decor)) { 221 218 printf("\"%s\" is already the current decorator\n", 222 219 decor->Name().String()); 223 220 return 0; 224 221 } 225 222 -
src/servers/app/DecorManager.
old new 1 1 /* 2 * Copyright (c) 2001-201 0, Haiku, Inc.2 * Copyright (c) 2001-2011, Haiku, Inc. 3 3 * Distributed under the terms of the MIT license. 4 4 * 5 5 * Author: … … 120 120 } 121 121 122 122 123 Decorator 124 DecorManager::AllocateDecorator(Window *window)123 Decorator* 124 DecorManager::AllocateDecorator(Window* window) 125 125 { 126 126 // Create a new instance of the current decorator. 127 127 // Ownership is that of the caller 128 128 129 if (!fCurrentDecor) { 129 130 // We should *never* be here. If we do, it's a bug. 130 131 debugger("DecorManager::AllocateDecorator has a NULL decorator"); … … 132 133 } 133 134 134 135 // Are we previewing a specific decorator? 135 if ( window == fPreviewWindow) {136 if (window == fPreviewWindow) { 136 137 if (fPreviewDecor != NULL) { 137 138 return fPreviewDecor->AllocateDecorator(window->Desktop(), 138 window->GetDrawingEngine(), window->Frame(),139 window->Title(),window->Look(), window->Flags());139 window->GetDrawingEngine(), window->Frame(), window->Title(), 140 window->Look(), window->Flags()); 140 141 } else { 141 142 fPreviewWindow = NULL; 142 143 } 143 144 } 144 145 145 146 return fCurrentDecor->AllocateDecorator(window->Desktop(), 146 window->GetDrawingEngine(), window->Frame(),147 window->Title(),window->Look(), window->Flags());147 window->GetDrawingEngine(), window->Frame(), window->Title(), 148 window->Look(), window->Flags()); 148 149 } 149 150 150 151 … … 162 163 163 164 164 165 void 165 DecorManager::CleanupForWindow(Window *window) 166 { // given window is being deleted, do any cleanup needed 166 DecorManager::CleanupForWindow(Window* window) 167 { 168 // Given window is being deleted, do any cleanup needed 167 169 if (fPreviewWindow == window && window != NULL){ 168 170 fPreviewWindow = NULL; 169 171 … … 176 178 177 179 178 180 status_t 179 DecorManager::PreviewDecorator(BString path, Window *window)181 DecorManager::PreviewDecorator(BString path, Window* window) 180 182 { 181 183 if (fPreviewWindow != NULL && fPreviewWindow != window){ 182 // reset other window to current decorator - only one can preview183 Window * old_preview_window = fPreviewWindow;184 // Reset other window to current decorator - only one can preview 185 Window* oldPreviewWindow = fPreviewWindow; 184 186 fPreviewWindow = NULL; 185 old _preview_window->ReloadDecor();187 oldPreviewWindow->ReloadDecor(); 186 188 } 187 189 188 190 if (window == NULL) 189 191 return B_BAD_VALUE; 190 192 191 status_t error = B_OK;192 193 // We have to jump some hoops because the window must be able to 193 194 // delete its decorator before we unload the add-on 194 DecorAddOn* decorPtr = _LoadDecor(path, error), 195 * oldDecor = fPreviewDecor; 196 195 status_t error = B_OK; 196 DecorAddOn* decorPtr = _LoadDecor(path, error); 197 197 if (decorPtr == NULL) 198 198 return error == B_OK ? B_ERROR : error; 199 199 200 BRegion border , newBorder;200 BRegion border; 201 201 window->GetBorderRegion(&border); 202 202 203 203 DecorAddOn* oldDecor = fPreviewDecor; 204 204 fPreviewDecor = decorPtr; 205 205 fPreviewWindow = window; 206 fPreviewWindow->ReloadDecor(); // window deletes its decorator here 206 // After this call, the window has deleted its decorator. 207 fPreviewWindow->ReloadDecor(); 207 208 209 BRegion newBorder; 208 210 window->GetBorderRegion(&newBorder); 211 209 212 border.Include(&newBorder); 210 213 window->Desktop()->RebuildAndRedrawAfterWindowChange(window, border); 211 214 212 215 if (oldDecor != NULL) 213 216 unload_add_on(oldDecor->ImageID()); 214 217 215 216 218 return B_OK; 217 219 } 218 220 … … 235 237 DecorManager::SetDecorator(BString path, Desktop* desktop) 236 238 { 237 239 status_t error = B_OK; 240 DecorAddOn* newDecor = _LoadDecor(path, error); 241 if (newDecor == NULL) 242 return error == B_OK ? B_ERROR : error; 238 243 239 DecorAddOn *newDecor = _LoadDecor(path, error); 240 241 if (!newDecor) 242 return B_ERROR; 243 244 DecorAddOn *oldDecor = fCurrentDecor; 244 DecorAddOn* oldDecor = fCurrentDecor; 245 245 BString oldPath = fCurrentDecorPath; 246 246 image_id oldImage = fCurrentDecor->ImageID(); 247 247 … … 250 250 251 251 if (desktop->ReloadDecor()) { 252 252 // now safe to unload all old decorator data 253 unload_add_on(oldImage); // saves us from deleting oldDecor... 253 // saves us from deleting oldDecor... 254 unload_add_on(oldImage); 254 255 _SaveSettingsToDisk(); 255 256 return B_OK; 256 257 } 258 257 259 // TODO: unloading the newDecor and its image 258 // problem is we don't know how many windows failed... 259 // or why they failed... 260 // problem is we don't know how many windows failed... or why they failed... 260 261 syslog(LOG_WARNING, 261 262 262 "app_server:DecorManager:SetDecorator:\"%s\" *partly* failed\n", 263 fCurrentDecorPath.String()); 263 264 264 265 fCurrentDecor = oldDecor; 265 266 fCurrentDecorPath = oldPath; … … 267 268 } 268 269 269 270 270 271 271 DecorAddOn* 272 DecorManager::_LoadDecor(BString _path, status_t &error )272 DecorManager::_LoadDecor(BString _path, status_t& error ) 273 273 { 274 274 if (_path == "Default") { 275 275 error = B_OK; 276 276 return &fDefaultDecor; 277 277 } 278 278 279 image_id image = -1;280 DecorAddOn* newDecor = NULL;281 entry_ref ref;282 283 279 BEntry entry(_path.String(), true); 284 285 280 if (!entry.Exists()) { 286 entry.Unset();287 281 error = B_ENTRY_NOT_FOUND; 288 282 return NULL; 289 283 } 290 284 291 285 BPath path(&entry); 292 entry.GetRef(&ref); 293 entry.Unset(); 294 295 image = load_add_on(path.Path()); 296 297 path.Unset(); 298 286 image_id image = load_add_on(path.Path()); 299 287 if (image < 0) { 300 288 error = B_BAD_IMAGE_ID; 301 289 return NULL; 302 290 } 303 291 304 292 create_decor_addon* createFunc; 305 306 if (get_image_symbol(image, 307 "instantiate_decor_addon", 308 B_SYMBOL_TYPE_TEXT, 309 (void**)&createFunc) != B_OK) { 293 if (get_image_symbol(image, "instantiate_decor_addon", B_SYMBOL_TYPE_TEXT, 294 (void**)&createFunc) != B_OK) { 310 295 unload_add_on(image); 311 296 error = B_MISSING_SYMBOL; 312 297 return NULL; 313 298 } 314 299 315 newDecor = createFunc(image, ref.name); 316 300 char name[B_FILE_NAME_LENGTH]; 301 entry.GetName(name); 302 DecorAddOn* newDecor = createFunc(image, name); 317 303 if (newDecor == NULL || newDecor->InitCheck() != B_OK) { 318 304 unload_add_on(image); 319 305 error = B_ERROR; … … 324 310 } 325 311 326 312 327 328 329 313 static const char* kSettingsDir = "system/app_server"; 330 314 static const char* kSettingsFile = "decorator_settings"; 331 315 … … 351 335 if (settings.FindString("decorator", &itemPath) == B_OK) { 352 336 status_t error = B_OK; 353 337 DecorAddOn* decor = _LoadDecor(itemPath, error); 354 if (decor ) {338 if (decor != NULL) { 355 339 fCurrentDecor = decor; 356 340 return true; 357 341 } else { -
src/servers/app/ServerApp.
old new 648 648 case AS_SET_DECORATOR: 649 649 { 650 650 // Attached Data: 651 // entry_ref to decorator651 // path to decorator add-on 652 652 653 653 BString path; 654 654 link.ReadString(path); -
src/servers/app/Window.
old new 1108 1108 bool 1109 1109 Window::SetDecoratorSettings(const BMessage& settings, BRegion& dirty) 1110 1110 { 1111 if (settings.what == 'prVu') { // 'prVu' == preview a decorator! 1111 if (settings.what == 'prVu') { 1112 // 'prVu' == preview a decorator! 1112 1113 BString path; 1113 if (settings.FindString("preview", &path) == B_OK) {1114 if (settings.FindString("preview", &path) == B_OK) 1114 1115 return gDecorManager.PreviewDecorator(path, this) == B_OK; 1115 }1116 1116 return false; 1117 1117 } 1118 1118 -
src/servers/app/Desktop.
old new 2059 2059 2060 2060 for (Window* window = fAllWindows.FirstWindow(); window != NULL; 2061 2061 window = window->NextWindow(kAllWindowList)) { 2062 2063 2062 BRegion oldBorder; 2063 window->GetBorderRegion(&oldBorder); 2064 2064 2065 if (!window->ReloadDecor()) 2066 returnValue = false; // prevent unloading previous add-on 2065 if (!window->ReloadDecor()) { 2066 // prevent unloading previous add-on 2067 returnValue = false; 2068 } 2067 2069 2068 2069 2070 BRegion border; 2071 window->GetBorderRegion(&border); 2070 2072 2071 2072 2073 border.Include(&oldBorder); 2074 RebuildAndRedrawAfterWindowChange(window, border); 2073 2075 } 2074 2076 2075 2077 // register new listeners -
src/servers/app/DecorManager.
old new 39 39 40 40 virtual status_t InitCheck() const; 41 41 42 image_idImageID() const { return fImageID; }42 image_id ImageID() const { return fImageID; } 43 43 44 Decorator*AllocateDecorator(Desktop* desktop,44 Decorator* AllocateDecorator(Desktop* desktop, 45 45 DrawingEngine* engine, BRect rect, 46 46 const char* title, window_look look, 47 47 uint32 flags); 48 48 49 virtual 49 virtual WindowBehaviour* AllocateWindowBehaviour(Window* window); 50 50 51 virtual const DesktopListenerList& 51 virtual const DesktopListenerList& GetDesktopListeners(); 52 52 53 53 protected: 54 54 virtual Decorator* _AllocateDecorator(DesktopSettings& settings, 55 55 BRect rect, window_look look, uint32 flags); 56 56 57 DesktopListenerListfDesktopListeners;57 DesktopListenerList fDesktopListeners; 58 58 59 59 private: 60 image_idfImageID;61 BStringfName;60 image_id fImageID; 61 BString fName; 62 62 }; 63 63 64 64 65 class DecorManager 66 { 65 class DecorManager { 67 66 public: 68 DecorManager();69 ~DecorManager();67 DecorManager(); 68 ~DecorManager(); 70 69 71 Decorator* AllocateDecorator(Window *window);72 WindowBehaviour* AllocateWindowBehaviour(Window *window);73 void CleanupForWindow(Window *window);70 Decorator* AllocateDecorator(Window *window); 71 WindowBehaviour* AllocateWindowBehaviour(Window *window); 72 void CleanupForWindow(Window *window); 74 73 75 status_t PreviewDecorator(BString path, Window *window);74 status_t PreviewDecorator(BString path, Window *window); 76 75 77 const DesktopListenerList&GetDesktopListeners();76 const DesktopListenerList& GetDesktopListeners(); 78 77 79 BString GetCurrentDecorator() const;80 status_t SetDecorator(BString path, Desktop *desktop);78 BString GetCurrentDecorator() const; 79 status_t SetDecorator(BString path, Desktop *desktop); 81 80 82 81 private: 83 DecorAddOn* _LoadDecor(BString path, status_t &error); 84 bool _LoadSettingsFromDisk(); 85 bool _SaveSettingsToDisk(); 86 87 DecorAddOn fDefaultDecor, 88 *fCurrentDecor, 89 *fPreviewDecor; 82 DecorAddOn* _LoadDecor(BString path, status_t &error); 83 bool _LoadSettingsFromDisk(); 84 bool _SaveSettingsToDisk(); 90 85 91 Window *fPreviewWindow; 92 BString fCurrentDecorPath; 86 private: 87 DecorAddOn fDefaultDecor; 88 DecorAddOn* fCurrentDecor; 89 DecorAddOn* fPreviewDecor; 90 91 Window* fPreviewWindow; 92 BString fCurrentDecorPath; 93 93 }; 94 94 95 95 extern DecorManager gDecorManager; -
src/kits/interface/DecorInfo.
old new 6 6 */ 7 7 8 8 9 #include <stdio.h>10 9 #include <DecorInfo.h> 11 #include <Path.h>12 #include <Resources.h>13 10 11 #include <new> 12 #include <stdio.h> 13 14 #include <Autolock.h> 14 15 #include <Directory.h> 15 16 #include <FindDirectory.h> 17 #include <Path.h> 18 #include <Resources.h> 16 19 17 20 18 21 DecorInfo::DecorInfo() … … 23 26 { 24 27 } 25 28 26 DecorInfo::DecorInfo(BString path) 29 30 DecorInfo::DecorInfo(const BString& path) 27 31 : 28 fPath(path .String()),32 fPath(path), 29 33 fVersion(0), 30 34 fModificationTime(0), 31 35 fInitStatus(B_NO_INIT) 32 36 { 33 37 BEntry entry(path.String(), true); 34 38 entry.GetRef(&fRef); 35 entry.Unset();36 39 37 40 _Init(); 38 41 } 39 42 43 40 44 DecorInfo::DecorInfo(const entry_ref& ref) 41 45 : 42 46 fRef(ref), … … 46 50 { 47 51 BPath path(&ref); 48 52 fPath = path.Path(); 49 path.Unset();50 53 51 54 _Init(); 52 55 } 53 56 57 54 58 DecorInfo::~DecorInfo() 55 59 { 56 60 } 57 61 62 58 63 status_t 59 64 DecorInfo::SetTo(const entry_ref& ref) 60 65 { … … 70 75 return InitCheck(); 71 76 } 72 77 78 73 79 status_t 74 80 DecorInfo::SetTo(BString path) 75 81 { … … 80 86 return SetTo(ref); 81 87 } 82 88 89 83 90 status_t 84 91 DecorInfo::InitCheck() const 85 92 { 86 93 return fInitStatus; 87 94 } 88 95 96 89 97 void 90 98 DecorInfo::Unset() 91 99 { … … 106 114 bool 107 115 DecorInfo::IsDefault() const 108 116 { 109 return (fInitStatus == B_OK && Path() == "default");117 return fInitStatus == B_OK && fPath == "Default"; 110 118 } 111 119 112 120 … … 116 124 return fPath.String(); 117 125 } 118 126 127 119 128 const entry_ref* 120 129 DecorInfo::Ref() const 121 130 { 122 if (InitCheck() != B_OK 123 || IsDefault()) 131 if (InitCheck() != B_OK || IsDefault()) 124 132 return NULL; 125 133 return &fRef; 126 134 } … … 145 153 BString 146 154 DecorInfo::Authors() const 147 155 { 148 156 return fAuthors; 149 157 } 150 158 159 151 160 BString 152 161 DecorInfo::ShortDescription() const 153 162 { 154 163 return fShortDescription; 155 164 } 156 165 166 157 167 BString 158 168 DecorInfo::LongDescription() const 159 169 { 160 170 return fLongDescription; 161 171 } 162 172 173 163 174 BString 164 175 DecorInfo::LicenseURL() const 165 176 { 166 177 return fLicenseURL; 167 178 } 168 179 180 169 181 BString 170 182 DecorInfo::LicenseName() const 171 183 { 172 184 return fLicenseName; 173 185 } 174 186 187 175 188 BString 176 189 DecorInfo::SupportURL() const 177 190 { 178 191 return fSupportURL; 179 192 } 180 193 194 181 195 float 182 196 DecorInfo::Version() const 183 197 { 184 198 return fVersion; 185 199 } 186 200 201 187 202 time_t 188 203 DecorInfo::ModificationTime() const 189 204 { 190 205 return fModificationTime; 191 206 } 192 207 208 193 209 bool 194 DecorInfo::CheckForChanges(bool &deleted)210 DecorInfo::CheckForChanges(bool& deleted) 195 211 { 196 212 if (InitCheck() != B_OK) 197 213 return false; 198 214 199 215 BEntry entry(&fRef); 200 216 201 if (entry.InitCheck() != B_OK) { 202 entry.Unset(); 217 if (entry.InitCheck() != B_OK) 203 218 return false; 204 }205 219 206 220 if (!entry.Exists()) { 207 entry.Unset();208 221 deleted = true; 209 222 return true; 210 223 } 211 224 212 225 time_t modtime = 0; 213 214 226 if (entry.GetModificationTime(&modtime) != B_OK) { 215 entry.Unset();216 227 fprintf(stderr, "DecorInfo::CheckForChanges()\tERROR: " 217 228 "BEntry:GetModificationTime() failed\n"); 218 229 return false; 219 230 } 220 231 … … 225 236 226 237 return false; 227 238 } 228 // checks for changes (by modification time), and updates data 229 // accordingly 239 230 240 231 241 void 232 DecorInfo::_Init(bool is _update)242 DecorInfo::_Init(bool isUpdate) 233 243 { 234 if (!is _update && InitCheck() != B_NO_INIT)235 {// TODO: remove after validation236 237 238 244 if (!isUpdate && InitCheck() != B_NO_INIT) { 245 // TODO: remove after validation 246 fprintf(stderr, "DecorInfo::_Init()\tImproper init state\n"); 247 return; 248 } 239 249 240 250 BEntry entry; 241 251 242 if (fPath == "Default") 243 {244 if (is_update){252 if (fPath == "Default") { 253 if (isUpdate){ 254 // should never happen 245 255 fprintf(stderr, "DecorInfo::_Init(true)\tBUG BUG updating default" 246 247 return; // should never happen256 "decorator!?!?!\n"); 257 return; 248 258 } 249 259 250 260 fName = "Default"; 251 fAuthors = "DarkWyrm, Stephan Aßmus, Clemens Zeidler, "; 252 fAuthors << "Ingo Weinhold"; 261 fAuthors = "DarkWyrm, Stephan Aßmus, Clemens Zeidler, Ingo Weinhold"; 253 262 fShortDescription = "Default Haiku window decorator."; 254 263 fLongDescription = fShortDescription; 255 264 fLicenseURL = "http://"; … … 258 267 fVersion = 0.5; 259 268 fInitStatus = B_OK; 260 269 261 // the following is to get the modification time of the app_server 262 // and, thusly, the Default decorator... 263 // if you can make it more simple, please do! 264 270 // The following is to get the modification time of the app_server 271 // and, thusly, the Default decorator... 272 // If you can make it more simple, please do! 265 273 BPath path; 266 find_directory(B_BEOS_SERVERS_DIRECTORY, &path ); 267 path.Append("app_server"); 268 entry.SetTo(path.Path(), true); 269 path.Unset(); 270 274 find_directory(B_BEOS_SERVERS_DIRECTORY, &path); 275 path.Append("app_server"); 276 entry.SetTo(path.Path(), true); 271 277 if (!entry.Exists()) { 272 fprintf(stderr, "server MIA" 273 "the world has become its slave!" 274 "call the CIA\n"); 275 276 entry.Unset(); 278 fprintf(stderr, "Server MIA the world has become its slave! " 279 "Call the CIA!\n"); 277 280 return; 278 281 } 279 282 … … 284 287 285 288 // Is a file system object... 286 289 287 entry.SetTo(&fRef, true); // follow links 288 290 entry.SetTo(&fRef, true); // follow link 289 291 if (entry.InitCheck() != B_OK) { 290 292 fInitStatus = entry.InitCheck(); 291 entry.Unset();292 293 return; 293 294 } 294 295 295 296 if (!entry.Exists()) { 296 entry.Unset(); 297 if (is_update) { 297 if (isUpdate) { 298 298 fprintf(stderr, "DecorInfo::_Init()\tERROR: decorator deleted" 299 299 " after CheckForChanges() found it!\n"); 300 300 fprintf(stderr, "DecorInfo::_Init()\tERROR: DecorInfo will " … … 303 303 } 304 304 return; 305 305 } 306 // update fRef to match file system object307 306 307 // update fRef to match file system object 308 308 entry.GetRef(&fRef); 309 entry.GetModificationTime(&fModificationTime); 310 entry.Unset(); 309 entry.GetModificationTime(&fModificationTime); 311 310 312 BResources rsrc(&fRef); 313 314 if (rsrc.InitCheck() != B_OK) { 315 fprintf(stderr, "DecorInfo::_Init()\t BResource InitCheck() " 316 "failure\n"); 317 rsrc.Unset(); 311 BResources resources(&fRef); 312 if (resources.InitCheck() != B_OK) { 313 fprintf(stderr, "DecorInfo::_Init()\t BResource InitCheck() failure\n"); 318 314 return; 319 315 } 320 316 321 size_t sz= 0;322 323 const void* ptr = rsrc.LoadResource(B_MESSAGE_TYPE, "be:decor:info", &sz);324 BMessage * msg = new BMessage();317 size_t infoSize = 0; 318 const void* infoData = resources.LoadResource(B_MESSAGE_TYPE, 319 "be:decor:info", &infoSize); 320 BMessage infoMessage; 325 321 326 if (!ptr || !msg || sz <= 0) { 322 if (infoData == NULL || infoSize == 0 323 || infoMessage.Unflatten((const char*)infoData) != B_OK) { 327 324 fprintf(stderr, "DecorInfo::_init()\tNo extended information found for" 328 " \"%s\"\n", fRef.name); 329 }else{ 330 msg->Unflatten((const char*)ptr); 331 msg->FindString("name", &fName); 332 msg->FindString("authors", &fAuthors); 333 msg->FindString("short_descr", &fShortDescription); 334 msg->FindString("long_descr", &fLongDescription); 335 msg->FindString("lic_url", &fLicenseURL); 336 msg->FindString("lic_name", &fLicenseName); 337 msg->FindString("support_url", &fSupportURL); 338 msg->FindFloat ("version", &fVersion); 325 " \"%s\"\n", fRef.name); 326 } else { 327 infoMessage.FindString("name", &fName); 328 infoMessage.FindString("authors", &fAuthors); 329 infoMessage.FindString("short_descr", &fShortDescription); 330 infoMessage.FindString("long_descr", &fLongDescription); 331 infoMessage.FindString("lic_url", &fLicenseURL); 332 infoMessage.FindString("lic_name", &fLicenseName); 333 infoMessage.FindString("support_url", &fSupportURL); 334 infoMessage.FindFloat ("version", &fVersion); 339 335 } 340 336 341 r src.Unset();337 resources.Unset(); 342 338 fInitStatus = B_OK; 343 344 if (fName == "") 345 fName = fRef.name; 339 fName = fRef.name; 346 340 } 347 341 348 342 349 / *343 // #pragma mark - DecorInfoUtility 350 344 351 DecorInfoUtility below this point352 353 */354 355 356 namespace BPrivate{ // kits/interface/InterfaceDefs.cpp357 bool get_decorator(BString*);358 status_t set_decorator(BString);359 status_t preview_decorator(BString, BWindow*);360 345 346 namespace BPrivate { 347 // kits/interface/InterfaceDefs.cpp 348 bool get_decorator(BString&); 349 status_t set_decorator(const BString&); 350 status_t preview_decorator(const BString&, BWindow*); 361 351 }; 362 352 363 353 using namespace BPrivate; 364 354 365 355 366 DecorInfoUtility::DecorInfoUtility(bool scan _now)356 DecorInfoUtility::DecorInfoUtility(bool scanNow) 367 357 : 368 358 fHasScanned(false) 369 359 { 370 360 // get default decorator from app_server 371 372 DecorInfo* info = new DecorInfo("Default"); 373 374 if (info->InitCheck() != B_OK) { 361 DecorInfo* info = new(std::nothrow) DecorInfo("Default"); 362 if (info == NULL || info->InitCheck() != B_OK) { 363 delete info; 375 364 fprintf(stderr, "DecorInfoUtility::constructor\tdefault decorator's " 376 365 "DecorInfo failed InitCheck()\n"); 377 366 return; … … 379 368 380 369 fList.AddItem(info); 381 370 382 if (scan _now)371 if (scanNow) 383 372 ScanDecorators(); 384 373 } 385 374 386 375 387 376 DecorInfoUtility::~DecorInfoUtility() 388 377 { 389 fLock.Lock(); 390 391 DecorInfo* decor = NULL; 392 393 for (int i = fList.CountItems() - 1; i >= 0; --i) { 394 decor = fList.ItemAt(i); 395 if (!decor) { 396 fprintf(stderr, "DecorInfoUtility::destructor\tNULL DecorInfo " 397 "in list!\n"); 398 continue; 399 } 400 delete decor; 401 fList.RemoveItemAt(i); 402 } 378 BAutolock _(fLock); 379 for (int i = fList.CountItems() - 1; i >= 0; --i) 380 delete fList.ItemAt(i); 403 381 } 404 382 405 383 … … 407 385 DecorInfoUtility::ScanDecorators() 408 386 { 409 387 BPath decorPath; 410 411 find_directory(B_USER_ADDONS_DIRECTORY, &decorPath); 412 413 decorPath.Append("decorators"); 388 status_t ret = find_directory(B_USER_ADDONS_DIRECTORY, &decorPath); 389 if (ret != B_OK) 390 return ret; 391 ret = decorPath.Append("decorators"); 392 if (ret != B_OK) 393 return ret; 414 394 415 395 BDirectory dir(decorPath.Path()); 416 417 if (dir.InitCheck() != B_OK) { 418 fprintf(stderr, "DecorInfoUtility::ScanDecorators:\tERROR: " 419 "DECORATORS_DIR not found!\n"); 420 dir.Unset(); 421 return B_ENTRY_NOT_FOUND; 422 } 423 424 425 BString* tstr = new BString(); 426 427 if (!get_decorator(tstr)) { 428 fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tERROR: no can " 429 "speak to app_server!\n"); 430 return B_ERROR; 396 ret = dir.InitCheck(); 397 if (ret != B_OK) { 398 fprintf(stderr, "DecorInfoUtility::ScanDecorators:\tERROR: " 399 "DECORATORS_DIR not found!\n"); 400 return ret; 431 401 } 432 402 433 BString cur_decor = tstr->String(); 434 435 DecorInfo* decor_ptr = NULL; 436 437 fLock.Lock(); 403 BAutolock _(fLock); 438 404 // First, run through our list and DecorInfos CheckForChanges() 439 405 440 406 if (fHasScanned) { 441 for (int i = fList.CountItems() - 1; i >= 0; --i) { 442 decor_ptr = fList.ItemAt(i); 407 for (int i = fList.CountItems() - 1; i > 0; --i) { 408 DecorInfo* decorInfo = fList.ItemAt(i); 409 410 bool deleted = false; 411 decorInfo->CheckForChanges(deleted); 443 412 444 if (decor_ptr) { 445 if (decor_ptr->IsDefault()) 446 continue; 447 448 bool deleted = false; 449 decor_ptr->CheckForChanges(deleted); 450 451 if (deleted) { 452 fList.RemoveItem(decor_ptr); 453 delete decor_ptr; 454 } 413 if (deleted) { 414 fList.RemoveItem(decorInfo); 415 delete decorInfo; 455 416 } 456 else457 fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tFound "458 "NULL entry in list @ %i _ BUG BUG BUG\n", i);459 417 } 460 418 } 461 419 462 decor_ptr = NULL;463 464 DecorInfo* decor = NULL;465 420 BPath path; 466 421 entry_ref ref; 467 // Now, look at file system: 422 // Now, look at file system, skip the entries for which we already have 423 // a DecorInfo in the list. 468 424 while (dir.GetNextRef(&ref) == B_OK) { 469 path.Unset();470 425 path.SetTo(decorPath.Path()); 471 426 path.Append(ref.name); 472 473 decor_ptr = _find_decor(path.Path()); 474 475 if (decor_ptr) 427 if (_FindDecor(path.Path()) != NULL) 476 428 continue; 477 429 478 decor = new DecorInfo(ref); 479 480 if (decor->InitCheck() != B_OK) { 430 DecorInfo* decorInfo = new(std::nothrow) DecorInfo(ref); 431 if (decorInfo == NULL || decorInfo->InitCheck() != B_OK) { 481 432 fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tInitCheck() " 482 "failure on decorator, skipping\n"); 483 delete decor; 484 decor = NULL; 433 "failure on decorator, skipping\n"); 434 delete decorInfo; 485 435 continue; 486 436 } 487 437 488 fList.AddItem(decor );438 fList.AddItem(decorInfo); 489 439 } 490 440 491 441 fHasScanned = true; 492 fLock.Unlock(); 493 path.Unset(); 494 decorPath.Unset(); 442 495 443 return B_OK; 496 444 } 497 445 … … 499 447 int32 500 448 DecorInfoUtility::CountDecorators() 501 449 { 450 BAutolock _(fLock); 502 451 if (!fHasScanned) 503 452 ScanDecorators(); 504 453 … … 507 456 508 457 509 458 DecorInfo* 510 DecorInfoUtility::DecoratorAt(int32 ind x)459 DecorInfoUtility::DecoratorAt(int32 index) 511 460 { 512 return fList.ItemAt(indx); 461 BAutolock _(fLock); 462 return fList.ItemAt(index); 513 463 } 514 464 515 465 516 466 DecorInfo* 517 DecorInfoUtility::FindDecorator( BString str)467 DecorInfoUtility::FindDecorator(const BString& string) 518 468 { 519 if ( !fHasScanned)520 ScanDecorators();469 if (string.Length() == 0) 470 return CurrentDecorator(); 521 471 522 BString tmp = str.String(); 523 if (tmp.ToLower() == "default") 472 if (string.ICompare("default") == 0) 524 473 return DefaultDecorator(); 525 474 526 if (str == "") 527 return CurrentDecorator(); 528 529 fLock.Lock(); 475 BAutolock _(fLock); 476 if (!fHasScanned) 477 ScanDecorators(); 530 478 531 479 // search by path 532 DecorInfo* ptr = _find_decor(str); 533 534 if (ptr) { 535 fLock.Unlock(); 536 return ptr; 537 } 538 539 // scan through Name() 540 str.ToLower(); 541 542 BString lc_comp, lc_comp2; 480 DecorInfo* decor = _FindDecor(string); 481 if (decor != NULL) 482 return decor; 543 483 484 // search by cached name 544 485 for (int i = 1; i < fList.CountItems(); ++i) { 545 ptr = fList.ItemAt(i); 546 547 if (ptr == NULL) { 548 fprintf(stderr, "DecorInfoUtility::FindDecorator()\tFound NULL " 549 "entry @ %i BUG BUG\n", i); 550 continue; 551 } 552 // last, but not least, we compare lower-case 553 554 lc_comp = ptr->Name(); 555 lc_comp.ToLower(); 556 lc_comp2 = ""; 557 558 if (ptr->Ref()) 559 lc_comp2 = ptr->Ref()->name; 560 561 lc_comp2.ToLower(); 562 563 // if "fancy" name or the file's name match, we are golden! 564 if (lc_comp == str 565 || str == lc_comp2) { 566 fLock.Unlock(); 567 return ptr; 568 } 486 decor = fList.ItemAt(i); 487 if (string.ICompare(decor->Name()) == 0) 488 return decor; 569 489 } 570 490 571 fLock.Unlock();572 491 return NULL; 573 492 } 574 493 … … 576 495 DecorInfo* 577 496 DecorInfoUtility::CurrentDecorator() 578 497 { 498 BAutolock _(fLock); 579 499 if (!fHasScanned) 580 500 ScanDecorators(); 581 501 582 BString str;583 get_decorator( &str);584 return FindDecorator( str);502 BString name; 503 get_decorator(name); 504 return FindDecorator(name); 585 505 } 586 506 587 507 588 508 DecorInfo* 589 509 DecorInfoUtility::DefaultDecorator() 590 510 { 511 BAutolock _(fLock); 591 512 return fList.ItemAt(0); 592 513 } 593 514 … … 595 516 bool 596 517 DecorInfoUtility::IsCurrentDecorator(DecorInfo* decor) 597 518 { 519 BAutolock _(fLock); 598 520 if (decor == NULL) 599 521 return false; 600 return decor->Path() == CurrentDecorator()->Path() .String();522 return decor->Path() == CurrentDecorator()->Path(); 601 523 } 602 524 603 525 … … 607 529 if (decor == NULL) 608 530 return B_BAD_VALUE; 609 531 532 BAutolock _(fLock); 610 533 if (decor->IsDefault()) 611 534 return set_decorator("Default"); 612 535 … … 615 538 616 539 617 540 status_t 618 DecorInfoUtility::SetDecorator(int32 ind x)541 DecorInfoUtility::SetDecorator(int32 index) 619 542 { 543 BAutolock _(fLock); 620 544 if (!fHasScanned) 621 545 return B_ERROR; 622 546 623 DecorInfo* decor = DecoratorAt(indx);; 624 625 if (!decor) 547 DecorInfo* decor = DecoratorAt(index); 548 if (decor == NULL) 626 549 return B_BAD_INDEX; 627 550 628 551 return SetDecorator(decor); … … 639 562 } 640 563 641 564 642 // P R I V A T E643 // ENFORCE LOCKING! 565 // #pargma mark - private 566 644 567 645 568 DecorInfo* 646 DecorInfoUtility::_find_decor(BString _path) 647 { // find decor by path and path alone! 569 DecorInfoUtility::_FindDecor(const BString& pathString) 570 { 571 // find decor by path and path alone! 648 572 if (!fLock.IsLocked()) { 649 573 fprintf(stderr, "DecorInfoUtility::_find_decor()\tfailure to lock! - " 650 574 "BUG BUG BUG\n"); 651 575 return NULL; 652 576 } 653 577 654 BString tmp = _path; 655 if (tmp.ToLower() == "default") 578 if (pathString == "Default") 656 579 return fList.ItemAt(0); 657 580 658 DecorInfo* decor = NULL; 659 660 BPath path; 661 662 for ( int i = 1; i < fList.CountItems(); ++i ) { 663 decor = fList.ItemAt(i); 664 if (decor == NULL) { 665 fprintf(stderr, "DecorInfoUtility::_find_decor()\tfound NULL @ %i!" 666 " - BUG BUG BUG\n", i); 667 continue; 668 } 669 670 path.SetTo(decor->Ref()); 671 672 if (path.Path() == _path 673 ||decor->Path() == _path) { 674 path.Unset(); 675 return decor; 676 } 677 678 path.Unset(); 581 for (int i = 1; i < fList.CountItems(); ++i) { 582 DecorInfo* decor = fList.ItemAt(i); 583 // Find the DecoratorInfo either by its true current location or by 584 // what we still think the location is (before we had a chance to 585 // update). NOTE: This will only catch the case when the user moved the 586 // folder in which the add-on file lives. It will not work when the user 587 // moves the add-on file itself or renames it. 588 BPath path(decor->Ref()); 589 if (path.Path() == pathString || decor->Path() == pathString) 590 return decor; 679 591 } 680 592 681 593 return NULL; -
src/kits/interface/InterfaceDefs.
old new 1196 1196 \return boolean true/false 1197 1197 */ 1198 1198 bool 1199 get_decorator(BString *path)1199 get_decorator(BString& path) 1200 1200 { 1201 if ( ! path )1202 return false;1203 1204 1201 BPrivate::AppServerLink link; 1205 1202 link.StartMessage(AS_GET_DECORATOR); 1206 1203 … … 1208 1205 if (link.FlushWithReply(code) != B_OK || code != B_OK) 1209 1206 return false; 1210 1207 1211 return ( link.ReadString(*path) == B_OK );1208 return link.ReadString(path) == B_OK; 1212 1209 } 1213 1210 1214 1211 … … 1218 1215 Will return detailed error status via status_t 1219 1216 */ 1220 1217 status_t 1221 set_decorator( BStringpath)1218 set_decorator(const BString& path) 1222 1219 { 1223 1220 BPrivate::AppServerLink link; 1224 1221 … … 1233 1230 return error; 1234 1231 } 1235 1232 1233 1236 1234 /*! \brief sets a window to preview a given decorator 1237 1235 \param path path to any given decorator add-on 1238 1236 \param window pointer to BWindow which will show decorator … … 1240 1238 Piggy-backs on BWindow::SetDecoratorSettings(...) 1241 1239 */ 1242 1240 status_t 1243 preview_decorator( BString path, BWindow* window)1241 preview_decorator(const BString& path, BWindow* window) 1244 1242 { 1245 1243 if (window == NULL) 1246 1244 return B_ERROR; -
headers/private/interface/DecorInfo.
old new 17 17 #include <ObjectList.h> 18 18 19 19 20 // NOTE: DecorInfo itself is not thread-safe 20 21 class DecorInfo { 21 public: // DecorInfo is not thread-safe 22 DecorInfo(); 23 DecorInfo(BString path); 24 DecorInfo(const entry_ref& ref); 25 ~DecorInfo(); 26 27 status_t SetTo(const entry_ref& ref); 28 status_t SetTo(BString path); 29 status_t InitCheck() const; 30 void Unset(); 31 32 bool IsDefault() const; 33 34 BString Path() const; 35 // "Default" is a possible result 36 37 const entry_ref* Ref() const; 38 // returns NULL if virtual ( default ) or InitCheck() != B_OK 39 // the ref returned may NOT be the same as the one given to SetTo 40 // or the constructor - we may have traversed a Symlink! 41 42 BString Name() const; 43 BString ShortcutName() const; 44 45 BString Authors() const; 46 BString ShortDescription() const; 47 BString LongDescription() const; 48 BString LicenseURL() const; 49 BString LicenseName() const; 50 BString SupportURL() const; 51 52 float Version() const; 53 time_t ModificationTime() const; 54 55 bool CheckForChanges(bool &deleted); 56 private: 57 void _Init(bool is_update = false); 58 entry_ref fRef; 59 60 BString fPath, 61 fName, 62 fAuthors, 63 fShortDescription, 64 fLongDescription, 65 fLicenseURL, 66 fLicenseName, 67 fSupportURL; 22 public: 23 DecorInfo(); 24 DecorInfo(const BString& path); 25 DecorInfo(const entry_ref& ref); 26 ~DecorInfo(); 27 28 status_t SetTo(const entry_ref& ref); 29 status_t SetTo(BString path); 30 status_t InitCheck() const; 31 void Unset(); 32 33 bool IsDefault() const; 34 35 BString Path() const; 36 // Returns "Default" for the default decorator 37 38 const entry_ref* Ref() const; 39 // Returns NULL if virtual (default) or InitCheck() != B_OK 40 // The ref returned may NOT be the same as the one given to 41 // SetTo or the constructor - we may have traversed a Symlink! 42 43 BString Name() const; 44 BString ShortcutName() const; 45 46 BString Authors() const; 47 BString ShortDescription() const; 48 BString LongDescription() const; 49 BString LicenseURL() const; 50 BString LicenseName() const; 51 BString SupportURL() const; 52 53 float Version() const; 54 time_t ModificationTime() const; 55 56 bool CheckForChanges(bool &deleted); 57 58 private: 59 void _Init(bool is_update = false); 60 61 private: 62 entry_ref fRef; 63 64 BString fPath; 65 BString fName; 66 BString fAuthors; 67 BString fShortDescription; 68 BString fLongDescription; 69 BString fLicenseURL; 70 BString fLicenseName; 71 BString fSupportURL; 68 72 69 float fVersion;73 float fVersion; 70 74 71 time_t fModificationTime;75 time_t fModificationTime; 72 76 73 status_t fInitStatus;77 status_t fInitStatus; 74 78 }; 75 79 76 80 77 81 class DecorInfoUtility{ 78 public: 79 DecorInfoUtility(bool scan_now = true); 80 // scan now or as neeeded? 82 public: 83 DecorInfoUtility(bool scanNow = true); 84 // NOTE: When scanNow is passed false, 85 // scanning will be performed lazily, such 86 // as in CountDecorators() and other 87 // methods. 81 88 82 ~DecorInfoUtility();89 ~DecorInfoUtility(); 83 90 84 status_t ScanDecorators(); 85 // can also be used to rescan for changes. 86 // warning: potentially destructive as we will remove 87 // all DecorInfo objects which no longer have a file 88 // system cousin. 89 // TODO: would a call-back mechanism worthwhile here? 91 status_t ScanDecorators(); 92 // Can also be used to rescan for changes. 93 // Warning: potentially destructive as we 94 // will remove all DecorInfo objects which 95 // no longer have a file system cousin. 96 // TODO: Would a call-back mechanism be 97 // worthwhile here? 90 98 91 int32 CountDecorators();99 int32 CountDecorators(); 92 100 93 DecorInfo* DecoratorAt(int32);101 DecorInfo* DecoratorAt(int32); 94 102 95 DecorInfo* FindDecorator(BString);96 // checks for ref.name, path, fName, and "Default,"97 // an empty-string returns the current decorator98 //NULL on match failure103 DecorInfo* FindDecorator(const BString& string); 104 // Checks for ref.name, path, fName, and 105 // "Default," an empty-string returns the 106 // current decorator NULL on match failure 99 107 100 DecorInfo* CurrentDecorator();101 DecorInfo* DefaultDecorator();108 DecorInfo* CurrentDecorator(); 109 DecorInfo* DefaultDecorator(); 102 110 103 bool IsCurrentDecorator(DecorInfo*);111 bool IsCurrentDecorator(DecorInfo*); 104 112 105 status_t SetDecorator(DecorInfo*);106 status_t SetDecorator(int32);113 status_t SetDecorator(DecorInfo*); 114 status_t SetDecorator(int32); 107 115 108 status_t Preview(DecorInfo* decor, BWindow* window);116 status_t Preview(DecorInfo* decor, BWindow* window); 109 117 110 111 DecorInfo* _find_decor(BStringpath);118 private: 119 DecorInfo* _FindDecor(const BString& path); 112 120 121 private: 113 122 BObjectList<DecorInfo> fList; 114 123 BLocker fLock; 115 124 bool fHasScanned;