Ticket #7445: cleanups.diff

File cleanups.diff, 43.8 KB (added by stippi, 13 years ago)

Diff of the patch before and after coding style cleanups and other improvements.

  • src/preferences/appearance/APRView.

    old new  
    3939#define DECORATOR_CHANGED 'dcch'
    4040
    4141
    42 APRView::APRView(const char *name, uint32 flags)
    43  :
     42APRView::APRView(const char* name, uint32 flags)
     43    :
    4444    BView(name, flags),
    4545    fDefaultSet(ColorSet::DefaultColorSet()),
    4646    fDecorMenu(NULL),
     
    6464        BMenuField* field = new BMenuField("Window Style", fDecorMenu);
    6565        // TODO: use this menu field.
    6666    }
    67     BMenuItem *marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator());
     67    BMenuItem* marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator());
    6868    if (marked)
    6969        marked->SetMarked(true);
    7070    else {
  • src/preferences/appearance/APRView.

    old new  
    3939#define DECORATOR_CHANGED 'dcch'
    4040
    4141
    42 APRView::APRView(const char *name, uint32 flags)
    43  :
     42APRView::APRView(const char* name, uint32 flags)
     43    :
    4444    BView(name, flags),
    4545    fDefaultSet(ColorSet::DefaultColorSet()),
    4646    fDecorMenu(NULL),
     
    6464        BMenuField* field = new BMenuField("Window Style", fDecorMenu);
    6565        // TODO: use this menu field.
    6666    }
    67     BMenuItem *marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator());
     67    BMenuItem* marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator());
    6868    if (marked)
    6969        marked->SetMarked(true);
    7070    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",
     1resource("be:decor:info") message('deco') {
     2    "name"              = "Windows 95",
     3    "authors"           = "",
     4    "short_descr"       = "Windows 95",
    85    "long_descr"        = "",
    96    "lic_url"           = "",
    10     "lic_name"      = "MIT",
     7    "lic_name"          = "MIT",
    118    "support_url"       = "http://www.haiku-os.org/",
    12     float   "version" = 1.0
     9    float "version"     = 1.0
    1310};
    14 
  • src/add-ons/decorators/MacDecorator/resources.

    old new  
    1 
    2 resource("be:decor:info") message('deco')
    3 
    4 {
    5     "name"          = "MacOS 9",
     1resource("be:decor:info") message('deco') {
     2    "name"          = "MacOS 9",
    63    "authors"       = "",
    74    "short_descr"   = "MacOS 9",
    8     "long_descr"        = "",
    9     "lic_url"           = "",
     5    "long_descr"    = "",
     6    "lic_url"       = "",
    107    "lic_name"      = "MIT",
    11     "support_url"       = "http://www.haiku-os.org/",
    12     float   "version" = 1.0
     8    "support_url"   = "http://www.haiku-os.org/",
     9    float "version" = 1.0
    1310};
    14 
  • src/add-ons/decorators/BeDecorator/resources.

    old new  
    1 
    2 resource("be:decor:info") message('deco')
    3 
    4 {
    5     "name"          = "Classic BeOS",
     1resource("be:decor:info") message('deco') {
     2    "name"          = "Classic BeOS",
    63    "authors"       = "DarkWyrm, Stephan Aßmus, Clemens Zeidler",
    74    "short_descr"   = "Basic appearance of the classic BeOS.",
    8     "long_descr"        = "",
    9     "lic_url"           = "",
     5    "long_descr"    = "",
     6    "lic_url"       = "",
    107    "lic_name"      = "MIT",
    11     "support_url"       = "http://www.haiku-os.org/",
    12     float   "version" = 1.0
     8    "support_url"   = "http://www.haiku-os.org/",
     9    float "version" = 1.0
    1310};
    14 
  • src/add-ons/decorators/SATDecorator/resources.

    old new  
    1 
    2 resource("be:decor:info") message('deco')
    3 
    4 {
    5     "name"          = "Stack and Tile",
     1resource("be:decor:info") message('deco') {
     2    "name"          = "Stack and Tile",
    63    "authors"       = "Clemens Zeidler, Ingo Weinhold",
    74    "short_descr"   = "Default look with ability to stack & tile windows.",
    8     "long_descr"        = "Group windows together and take advantage of those"
     5    "long_descr"    = "Group windows together and take advantage of those"
    96                        " tabs!\n\nTODO: instructions",
    10     "lic_url"           = "",
     7    "lic_url"       = "",
    118    "lic_name"      = "MIT",
    12     "support_url"       = "http://www.haiku-os.org/",
    13     float   "version" = 1.0
     9    "support_url"   = "http://www.haiku-os.org/",
     10    float "version" = 1.0
    1411};
    15 
  • src/bin/setdecor.

    old new  
    22 * Copyright 2011, Joseph "looncraz" Groover, looncraz@satx.rr.com
    33 * Copyright 2007, François Revol, revol@free.fr.
    44 * Distributed under the terms of the MIT license.
    5  *
    65 */
    76
    87
     
    1817#include <private/interface/DecorInfo.h>
    1918
    2019
    21 void    print_decor_info_header()
     20void
     21print_decor_info_header()
    2222{
    2323    printf("    Name      License\t    Description\n");
    2424    printf("----------------------------------------------------\n");
    2525}
    2626
    2727
    28 void    print_decor_summary(DecorInfo* decor, bool is_current)
     28void
     29print_decor_summary(DecorInfo* decor, bool isCurrent)
    2930{
    30     if ( is_current )
     31    if (isCurrent)
    3132        printf("*");
    3233
    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());
    3636}
    3737
    3838
    39 void    print_decor_shortcut(DecorInfo* decor, bool is_current)
     39void
     40print_decor_shortcut(DecorInfo* decor, bool isCurrent)
    4041{
    41     if ( is_current )
     42    if (isCurrent)
    4243        printf("*");
    4344
    44     printf("%-12s\t%-12s\n",    decor->ShortcutName().String(),
    45                             decor->Name().String());
     45    printf("%-12s\t%-12s\n", decor->ShortcutName().String(),
     46        decor->Name().String());
    4647}
    4748
    4849
    49 void    print_decor_info_verbose(DecorInfo* decor, bool is_current)
     50void
     51print_decor_info_verbose(DecorInfo* decor, bool isCurrent)
    5052{
    5153    printf("Name:\t\t%s\n", decor->Name().String());
    5254    printf("Version:\t%f\n", decor->Version());
    5355    printf("Author(s):\t%s\n", decor->Authors().String());
    5456    printf("Description:\t%s\n", decor->ShortDescription().String());
    5557    printf("License:\t%s (%s)\n", decor->LicenseName().String(),
    56             decor->LicenseURL().String());
     58        decor->LicenseURL().String());
    5759    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.");
    5961}
    6062
    6163
    62 int main(int argc, char **argv)
     64int
     65main(int argc, char** argv)
    6366{
    6467    if (argc < 2) {
    6568        printf("usage: %s [-l|-c|decorname]\n", argv[0]);
     
    7174        return 1;
    7275    }
    7376
    74         // combine remaining args into one string:
     77    // combine remaining args into one string:
    7578    BString decoratorName;
    7679    for (int i = 2; i < argc; ++i)
    7780        decoratorName << argv[i] << " ";
     
    8386    DecorInfo* decor = NULL;
    8487
    8588    if (util == NULL) {
    86         fprintf(stderr, "error instantiating DecoratorInfoUtility ( out of"
    87                 " memory? )\n");
     89        fprintf(stderr, "error instantiating DecoratorInfoUtility (out of"
     90            " memory?)\n");
    8891        return 1;
    8992    }
    9093
    9194    // we want the list
    9295    if (!strcmp(argv[1], "-l")) {
    9396        // Print default decorator:
    94 
    9597        print_decor_info_header();
    9698        int32 count = util->CountDecorators();
    9799        for (int32 i = 0; i < count; ++i) {
    98100            decor = util->DecoratorAt(i);
    99101            if (decor == NULL) {
    100102                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;
    103106            }
    104107            print_decor_summary(decor, util->IsCurrentDecorator(decor));
    105108        }
     
    113116
    114117        if (decor == NULL) {
    115118            fprintf(stderr, "Unable to determine current decorator, sorry! - "
    116                     "BUG BUG BUG\n");
     119                "BUG BUG BUG\n");
    117120            return 2;
    118121        }
    119122
     
    133136            decor = util->DecoratorAt(i);
    134137            if (decor == NULL) {
    135138                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;
    138142            }
    139143            print_decor_shortcut(decor, util->IsCurrentDecorator(decor));
    140144        }
    141145
    142146        return 0;
    143 
    144147    }
    145148
    146149    // we want detailed information for a specific decorator ( by name or path )
     
    153156        decor = util->FindDecorator(decoratorName.String());
    154157
    155158        if (decor == NULL) {
    156                 fprintf(stderr, "Can't find decor named \"%s\", try again\n",
    157                         decoratorName.String());
    158                 return 1;
    159             }
     159            fprintf(stderr, "Can't find decor named \"%s\", try again\n",
     160                decoratorName.String());
     161            return 1;
     162        }
    160163
    161164        print_decor_info_verbose(decor, util->IsCurrentDecorator(decor));
    162165        return 0;
     
    169172            return 1;
    170173        }
    171174
    172 
    173175        decor = util->FindDecorator(decoratorName.String());
    174176
    175177        if (decor == NULL) {
    176                 fprintf(stderr, "Can't find decor named \"%s\", try again\n",
    177                         decoratorName.String());
    178                 return 1;
    179             }
     178            fprintf(stderr, "Can't find decor named \"%s\", try again\n",
     179                decoratorName.String());
     180            return 1;
     181        }
    180182
    181183        printf("Preparing preview...\n");
    182184
     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        }
    183197
    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();
    201199
    202         be_app->Run();
     200        app.Run();
    203201        return 0;
    204202    }
    205203
    206 
    207204    // we want to change it
    208205    decoratorName = "";
    209206    for (int i = 1; i < argc; ++i)
     
    219216
    220217    if (util->IsCurrentDecorator(decor)) {
    221218        printf("\"%s\" is already the current decorator\n",
    222                 decor->Name().String());
     219            decor->Name().String());
    223220        return 0;
    224221    }
    225222
  • src/servers/app/DecorManager.

    old new  
    11/*
    2  * Copyright (c) 2001-2010, Haiku, Inc.
     2 * Copyright (c) 2001-2011, Haiku, Inc.
    33 * Distributed under the terms of the MIT license.
    44 *
    55 * Author:
     
    120120}
    121121
    122122
    123 Decorator *
    124 DecorManager::AllocateDecorator(Window *window)
     123Decorator*
     124DecorManager::AllocateDecorator(Window* window)
    125125{
    126126    // Create a new instance of the current decorator.
    127127    // Ownership is that of the caller
     128
    128129    if (!fCurrentDecor) {
    129130        // We should *never* be here. If we do, it's a bug.
    130131        debugger("DecorManager::AllocateDecorator has a NULL decorator");
     
    132133    }
    133134
    134135    // Are we previewing a specific decorator?
    135     if ( window == fPreviewWindow ) {
     136    if (window == fPreviewWindow) {
    136137        if (fPreviewDecor != NULL) {
    137138            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());
    140141        } else {
    141142            fPreviewWindow = NULL;
    142143        }
    143144    }
    144145
    145146    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());
    148149}
    149150
    150151
     
    162163
    163164
    164165void
    165 DecorManager::CleanupForWindow(Window *window)
    166 {   // given window is being deleted, do any cleanup needed
     166DecorManager::CleanupForWindow(Window* window)
     167{
     168    // Given window is being deleted, do any cleanup needed
    167169    if (fPreviewWindow == window && window != NULL){
    168170        fPreviewWindow = NULL;
    169171
     
    176178
    177179
    178180status_t
    179 DecorManager::PreviewDecorator(BString path, Window *window)
     181DecorManager::PreviewDecorator(BString path, Window* window)
    180182{
    181183    if (fPreviewWindow != NULL && fPreviewWindow != window){
    182     // reset other window to current decorator - only one can preview
    183         Window * old_preview_window = fPreviewWindow;
     184        // Reset other window to current decorator - only one can preview
     185        Window* oldPreviewWindow = fPreviewWindow;
    184186        fPreviewWindow = NULL;
    185         old_preview_window->ReloadDecor();
     187        oldPreviewWindow->ReloadDecor();
    186188    }
    187189
    188190    if (window == NULL)
    189191        return B_BAD_VALUE;
    190192
    191     status_t error = B_OK;
    192193    // We have to jump some hoops because the window must be able to
    193194    // 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);
    197197    if (decorPtr == NULL)
    198198        return error == B_OK ? B_ERROR : error;
    199199
    200     BRegion border, newBorder;
     200    BRegion border;
    201201    window->GetBorderRegion(&border);
    202202
    203 
     203    DecorAddOn* oldDecor = fPreviewDecor;
    204204    fPreviewDecor = decorPtr;
    205205    fPreviewWindow = window;
    206     fPreviewWindow->ReloadDecor(); // window deletes its decorator here
     206    // After this call, the window has deleted its decorator.
     207    fPreviewWindow->ReloadDecor();
    207208
     209    BRegion newBorder;
    208210    window->GetBorderRegion(&newBorder);
     211
    209212    border.Include(&newBorder);
    210213    window->Desktop()->RebuildAndRedrawAfterWindowChange(window, border);
    211214
    212215    if (oldDecor != NULL)
    213216        unload_add_on(oldDecor->ImageID());
    214217
    215 
    216218    return B_OK;
    217219}
    218220
     
    235237DecorManager::SetDecorator(BString path, Desktop* desktop)
    236238{
    237239    status_t error = B_OK;
     240    DecorAddOn* newDecor = _LoadDecor(path, error);
     241    if (newDecor == NULL)
     242        return error == B_OK ? B_ERROR : error;
    238243
    239     DecorAddOn *newDecor = _LoadDecor(path, error);
    240 
    241     if (!newDecor)
    242         return B_ERROR;
    243 
    244     DecorAddOn *oldDecor = fCurrentDecor;
     244    DecorAddOn* oldDecor = fCurrentDecor;
    245245    BString oldPath = fCurrentDecorPath;
    246246    image_id oldImage = fCurrentDecor->ImageID();
    247247
     
    250250
    251251    if (desktop->ReloadDecor()) {
    252252        // 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);
    254255        _SaveSettingsToDisk();
    255256        return B_OK;
    256257    }
     258
    257259    // 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...
    260261    syslog(LOG_WARNING,
    261             "app_server:DecorManager:SetDecorator:\"%s\" *partly* failed\n",
    262             fCurrentDecorPath.String());
     262        "app_server:DecorManager:SetDecorator:\"%s\" *partly* failed\n",
     263        fCurrentDecorPath.String());
    263264
    264265    fCurrentDecor = oldDecor;
    265266    fCurrentDecorPath = oldPath;
     
    267268}
    268269
    269270
    270 
    271271DecorAddOn*
    272 DecorManager::_LoadDecor(BString _path, status_t &error )
     272DecorManager::_LoadDecor(BString _path, status_t& error )
    273273{
    274274    if (_path == "Default") {
    275275        error = B_OK;
    276276        return &fDefaultDecor;
    277277    }
    278278
    279     image_id image = -1;
    280     DecorAddOn* newDecor = NULL;
    281     entry_ref ref;
    282 
    283279    BEntry entry(_path.String(), true);
    284 
    285280    if (!entry.Exists()) {
    286         entry.Unset();
    287281        error = B_ENTRY_NOT_FOUND;
    288282        return NULL;
    289283    }
    290284
    291285    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());
    299287    if (image < 0) {
    300288        error = B_BAD_IMAGE_ID;
    301289        return NULL;
    302290    }
    303291
    304292    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) {
    310295        unload_add_on(image);
    311296        error = B_MISSING_SYMBOL;
    312297        return NULL;
    313298    }
    314299
    315     newDecor = createFunc(image, ref.name);
    316 
     300    char name[B_FILE_NAME_LENGTH];
     301    entry.GetName(name);
     302    DecorAddOn* newDecor = createFunc(image, name);
    317303    if (newDecor == NULL || newDecor->InitCheck() != B_OK) {
    318304        unload_add_on(image);
    319305        error = B_ERROR;
     
    324310}
    325311
    326312
    327 
    328 
    329313static const char* kSettingsDir = "system/app_server";
    330314static const char* kSettingsFile = "decorator_settings";
    331315
     
    351335        if (settings.FindString("decorator", &itemPath) == B_OK) {
    352336            status_t error = B_OK;
    353337            DecorAddOn* decor = _LoadDecor(itemPath, error);
    354             if (decor) {
     338            if (decor != NULL) {
    355339                fCurrentDecor = decor;
    356340                return true;
    357341            } else {
  • src/servers/app/ServerApp.

    old new  
    648648        case AS_SET_DECORATOR:
    649649        {
    650650            // Attached Data:
    651             // entry_ref to decorator
     651            // path to decorator add-on
    652652
    653653            BString path;
    654654            link.ReadString(path);
  • src/servers/app/Window.

    old new  
    11081108bool
    11091109Window::SetDecoratorSettings(const BMessage& settings, BRegion& dirty)
    11101110{
    1111     if (settings.what == 'prVu') { // 'prVu' == preview a decorator!
     1111    if (settings.what == 'prVu') {
     1112        // 'prVu' == preview a decorator!
    11121113        BString path;
    1113         if (settings.FindString("preview", &path) == B_OK){
     1114        if (settings.FindString("preview", &path) == B_OK)
    11141115            return gDecorManager.PreviewDecorator(path, this) == B_OK;
    1115         }
    11161116        return false;
    11171117    }
    11181118
  • src/servers/app/Desktop.

    old new  
    20592059
    20602060    for (Window* window = fAllWindows.FirstWindow(); window != NULL;
    20612061            window = window->NextWindow(kAllWindowList)) {
    2062             BRegion oldBorder;
    2063             window->GetBorderRegion(&oldBorder);
     2062        BRegion oldBorder;
     2063        window->GetBorderRegion(&oldBorder);
    20642064
    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        }
    20672069
    2068             BRegion border;
    2069             window->GetBorderRegion(&border);
     2070        BRegion border;
     2071        window->GetBorderRegion(&border);
    20702072
    2071             border.Include(&oldBorder);
    2072             RebuildAndRedrawAfterWindowChange(window, border);
     2073        border.Include(&oldBorder);
     2074        RebuildAndRedrawAfterWindowChange(window, border);
    20732075    }
    20742076
    20752077    // register new listeners
  • src/servers/app/DecorManager.

    old new  
    3939
    4040    virtual status_t            InitCheck() const;
    4141
    42         image_id                ImageID() const { return fImageID; }
     42            image_id            ImageID() const { return fImageID; }
    4343
    44         Decorator*              AllocateDecorator(Desktop* desktop,
     44            Decorator*          AllocateDecorator(Desktop* desktop,
    4545                                    DrawingEngine* engine, BRect rect,
    4646                                    const char* title, window_look look,
    4747                                    uint32 flags);
    4848
    49     virtual WindowBehaviour*    AllocateWindowBehaviour(Window* window);
     49    virtual WindowBehaviour*    AllocateWindowBehaviour(Window* window);
    5050
    51     virtual const DesktopListenerList&  GetDesktopListeners();
     51    virtual const DesktopListenerList& GetDesktopListeners();
    5252
    5353protected:
    5454    virtual Decorator*          _AllocateDecorator(DesktopSettings& settings,
    5555                                    BRect rect, window_look look, uint32 flags);
    5656
    57         DesktopListenerList     fDesktopListeners;
     57            DesktopListenerList fDesktopListeners;
    5858
    5959private:
    60         image_id                fImageID;
    61         BString                 fName;
     60            image_id            fImageID;
     61            BString             fName;
    6262};
    6363
    6464
    65 class DecorManager
    66 {
     65class DecorManager {
    6766public:
    68                             DecorManager();
    69                             ~DecorManager();
     67                                DecorManager();
     68                                ~DecorManager();
    7069
    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);
    7473
    75         status_t            PreviewDecorator(BString path, Window *window);
     74            status_t            PreviewDecorator(BString path, Window *window);
    7675
    77     const DesktopListenerList&  GetDesktopListeners();
     76            const DesktopListenerList& GetDesktopListeners();
    7877
    79         BString             GetCurrentDecorator() const;
    80         status_t            SetDecorator(BString path, Desktop *desktop);
     78            BString             GetCurrentDecorator() const;
     79            status_t            SetDecorator(BString path, Desktop *desktop);
    8180
    8281private:
    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();
    9085
    91         Window              *fPreviewWindow;
    92         BString             fCurrentDecorPath;
     86private:
     87            DecorAddOn          fDefaultDecor;
     88            DecorAddOn*         fCurrentDecor;
     89            DecorAddOn*         fPreviewDecor;
     90
     91            Window*             fPreviewWindow;
     92            BString             fCurrentDecorPath;
    9393};
    9494
    9595extern DecorManager gDecorManager;
  • src/kits/interface/DecorInfo.

    old new  
    66 */
    77
    88
    9 #include <stdio.h>
    109#include <DecorInfo.h>
    11 #include <Path.h>
    12 #include <Resources.h>
    1310
     11#include <new>
     12#include <stdio.h>
     13
     14#include <Autolock.h>
    1415#include <Directory.h>
    1516#include <FindDirectory.h>
     17#include <Path.h>
     18#include <Resources.h>
    1619
    1720
    1821DecorInfo::DecorInfo()
     
    2326{
    2427}
    2528
    26 DecorInfo::DecorInfo(BString path)
     29
     30DecorInfo::DecorInfo(const BString& path)
    2731    :
    28     fPath(path.String()),
     32    fPath(path),
    2933    fVersion(0),
    3034    fModificationTime(0),
    3135    fInitStatus(B_NO_INIT)
    3236{
    3337    BEntry entry(path.String(), true);
    3438    entry.GetRef(&fRef);
    35     entry.Unset();
    3639
    3740    _Init();
    3841}
    3942
     43
    4044DecorInfo::DecorInfo(const entry_ref& ref)
    4145    :
    4246    fRef(ref),
     
    4650{
    4751    BPath path(&ref);
    4852    fPath = path.Path();
    49     path.Unset();
    5053
    5154    _Init();
    5255}
    5356
     57
    5458DecorInfo::~DecorInfo()
    5559{
    5660}
    5761
     62
    5863status_t
    5964DecorInfo::SetTo(const entry_ref& ref)
    6065{
     
    7075    return InitCheck();
    7176}
    7277
     78
    7379status_t
    7480DecorInfo::SetTo(BString path)
    7581{
     
    8086    return SetTo(ref);
    8187}
    8288
     89
    8390status_t
    8491DecorInfo::InitCheck()  const
    8592{
    86         return fInitStatus;
     93    return fInitStatus;
    8794}
    8895
     96
    8997void
    9098DecorInfo::Unset()
    9199{
     
    106114bool
    107115DecorInfo::IsDefault() const
    108116{
    109     return (fInitStatus == B_OK && Path() == "default");
     117    return fInitStatus == B_OK && fPath == "Default";
    110118}
    111119
    112120
     
    116124    return fPath.String();
    117125}
    118126
     127
    119128const entry_ref*
    120129DecorInfo::Ref() const
    121130{
    122     if (InitCheck() != B_OK
    123         ||  IsDefault())
     131    if (InitCheck() != B_OK || IsDefault())
    124132        return NULL;
    125133    return &fRef;
    126134}
     
    145153BString
    146154DecorInfo::Authors() const
    147155{
    148         return fAuthors;
     156    return fAuthors;
    149157}
    150158
     159
    151160BString
    152161DecorInfo::ShortDescription() const
    153162{
    154         return fShortDescription;
     163    return fShortDescription;
    155164}
    156165
     166
    157167BString
    158168DecorInfo::LongDescription() const
    159169{
    160         return fLongDescription;
     170    return fLongDescription;
    161171}
    162172
     173
    163174BString
    164175DecorInfo::LicenseURL() const
    165176{
    166         return fLicenseURL;
     177    return fLicenseURL;
    167178}
    168179
     180
    169181BString
    170182DecorInfo::LicenseName() const
    171183{
    172         return fLicenseName;
     184    return fLicenseName;
    173185}
    174186
     187
    175188BString
    176189DecorInfo::SupportURL() const
    177190{
    178         return fSupportURL;
     191    return fSupportURL;
    179192}
    180193
     194
    181195float
    182196DecorInfo::Version() const
    183197{
    184198    return fVersion;
    185199}
    186200
     201
    187202time_t
    188203DecorInfo::ModificationTime() const
    189204{
    190205    return fModificationTime;
    191206}
    192207
     208
    193209bool
    194 DecorInfo::CheckForChanges(bool &deleted)
     210DecorInfo::CheckForChanges(bool& deleted)
    195211{
    196212    if (InitCheck() != B_OK)
    197213        return false;
    198214
    199215    BEntry entry(&fRef);
    200216
    201     if (entry.InitCheck() != B_OK) {
    202         entry.Unset();
     217    if (entry.InitCheck() != B_OK)
    203218        return false;
    204     }
    205219
    206220    if (!entry.Exists()) {
    207         entry.Unset();
    208221        deleted = true;
    209222        return true;
    210223    }
    211224
    212225    time_t modtime = 0;
    213 
    214226    if (entry.GetModificationTime(&modtime) != B_OK) {
    215         entry.Unset();
    216227        fprintf(stderr, "DecorInfo::CheckForChanges()\tERROR: "
    217                 "BEntry:GetModificationTime() failed\n");
     228            "BEntry:GetModificationTime() failed\n");
    218229        return false;
    219230    }
    220231
     
    225236
    226237    return false;
    227238}
    228             // checks for changes (by modification time), and updates data
    229             // accordingly
     239
    230240
    231241void
    232 DecorInfo::_Init(bool is_update)
     242DecorInfo::_Init(bool isUpdate)
    233243{
    234     if (!is_update && InitCheck() != B_NO_INIT)
    235         { // TODO: remove after validation
    236                 fprintf(stderr, "DecorInfo::_Init()\tImproper init state\n");
    237                 return;
    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    }
    239249
    240250    BEntry entry;
    241251
    242     if (fPath == "Default")
    243     {
    244         if (is_update){
     252    if (fPath == "Default") {
     253        if (isUpdate){
     254            // should never happen
    245255            fprintf(stderr, "DecorInfo::_Init(true)\tBUG BUG updating default"
    246                     "decorator!?!?!\n");
    247             return; // should never happen
     256                "decorator!?!?!\n");
     257            return;
    248258        }
    249259
    250260        fName = "Default";
    251         fAuthors = "DarkWyrm, Stephan Aßmus, Clemens Zeidler, ";
    252             fAuthors << "Ingo Weinhold";
     261        fAuthors = "DarkWyrm, Stephan Aßmus, Clemens Zeidler, Ingo Weinhold";
    253262        fShortDescription = "Default Haiku window decorator.";
    254263        fLongDescription = fShortDescription;
    255264        fLicenseURL = "http://";
     
    258267        fVersion = 0.5;
    259268        fInitStatus = B_OK;
    260269
    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!
    265273        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);
    271277        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");
    277280            return;
    278281        }
    279282
     
    284287
    285288    // Is a file system object...
    286289
    287     entry.SetTo(&fRef, true);   // follow links
    288 
     290    entry.SetTo(&fRef, true);   // follow link
    289291    if (entry.InitCheck() != B_OK) {
    290292        fInitStatus = entry.InitCheck();
    291         entry.Unset();
    292293        return;
    293294    }
    294295
    295296    if (!entry.Exists()) {
    296         entry.Unset();
    297         if (is_update) {
     297        if (isUpdate) {
    298298            fprintf(stderr, "DecorInfo::_Init()\tERROR: decorator deleted"
    299299                    " after CheckForChanges() found it!\n");
    300300            fprintf(stderr, "DecorInfo::_Init()\tERROR: DecorInfo will "
     
    303303        }
    304304        return;
    305305    }
    306     // update fRef to match file system object
    307306
     307    // update fRef to match file system object
    308308    entry.GetRef(&fRef);
    309         entry.GetModificationTime(&fModificationTime);
    310     entry.Unset();
     309    entry.GetModificationTime(&fModificationTime);
    311310
    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");
    318314        return;
    319315    }
    320316
    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;
    325321
    326     if (!ptr || !msg || sz <= 0) {
     322    if (infoData == NULL || infoSize == 0
     323        || infoMessage.Unflatten((const char*)infoData) != B_OK) {
    327324        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);
    339335    }
    340336
    341     rsrc.Unset();
     337    resources.Unset();
    342338    fInitStatus = B_OK;
    343 
    344     if (fName == "")
    345         fName = fRef.name;
     339    fName = fRef.name;
    346340}
    347341
    348342
    349 /*
     343// #pragma mark - DecorInfoUtility
    350344
    351     DecorInfoUtility below this point
    352 
    353 */
    354 
    355 
    356 namespace BPrivate{ // kits/interface/InterfaceDefs.cpp
    357     bool        get_decorator(BString*);
    358     status_t    set_decorator(BString);
    359     status_t    preview_decorator(BString, BWindow*);
    360345
     346namespace 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*);
    361351};
    362352
    363353using namespace BPrivate;
    364354
    365355
    366 DecorInfoUtility::DecorInfoUtility(bool scan_now)
     356DecorInfoUtility::DecorInfoUtility(bool scanNow)
    367357    :
    368358    fHasScanned(false)
    369359{
    370360    // 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;
    375364        fprintf(stderr, "DecorInfoUtility::constructor\tdefault decorator's "
    376365                "DecorInfo failed InitCheck()\n");
    377366        return;
     
    379368
    380369    fList.AddItem(info);
    381370
    382     if (scan_now)
     371    if (scanNow)
    383372        ScanDecorators();
    384373}
    385374
    386375
    387376DecorInfoUtility::~DecorInfoUtility()
    388377{
    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);
    403381}
    404382
    405383
     
    407385DecorInfoUtility::ScanDecorators()
    408386{
    409387    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;
    414394
    415395    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;
    431401    }
    432402
    433     BString cur_decor = tstr->String();
    434 
    435     DecorInfo* decor_ptr = NULL;
    436 
    437     fLock.Lock();
     403    BAutolock _(fLock);
    438404    // First, run through our list and DecorInfos CheckForChanges()
    439405
    440406    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);
    443412
    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;
    455416            }
    456             else
    457                 fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tFound "
    458                         "NULL entry in list @ %i _ BUG BUG BUG\n", i);
    459417        }
    460418    }
    461419
    462     decor_ptr = NULL;
    463 
    464     DecorInfo* decor = NULL;
    465420    BPath path;
    466421    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.
    468424    while (dir.GetNextRef(&ref) == B_OK) {
    469         path.Unset();
    470425        path.SetTo(decorPath.Path());
    471426        path.Append(ref.name);
    472 
    473         decor_ptr = _find_decor(path.Path());
    474 
    475         if (decor_ptr)
     427        if (_FindDecor(path.Path()) != NULL)
    476428            continue;
    477429
    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) {
    481432            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;
    485435            continue;
    486436        }
    487437
    488         fList.AddItem(decor);
     438        fList.AddItem(decorInfo);
    489439    }
    490440
    491441    fHasScanned = true;
    492     fLock.Unlock();
    493     path.Unset();
    494     decorPath.Unset();
     442
    495443    return B_OK;
    496444}
    497445
     
    499447int32
    500448DecorInfoUtility::CountDecorators()
    501449{
     450    BAutolock _(fLock);
    502451    if (!fHasScanned)
    503452        ScanDecorators();
    504453
     
    507456
    508457
    509458DecorInfo*
    510 DecorInfoUtility::DecoratorAt(int32 indx)
     459DecorInfoUtility::DecoratorAt(int32 index)
    511460{
    512     return fList.ItemAt(indx);
     461    BAutolock _(fLock);
     462    return fList.ItemAt(index);
    513463}
    514464
    515465
    516466DecorInfo*
    517 DecorInfoUtility::FindDecorator(BString str)
     467DecorInfoUtility::FindDecorator(const BString& string)
    518468{
    519     if (!fHasScanned)
    520         ScanDecorators();
     469    if (string.Length() == 0)
     470        return CurrentDecorator();
    521471
    522     BString tmp = str.String();
    523     if (tmp.ToLower() == "default")
     472    if (string.ICompare("default") == 0)
    524473        return DefaultDecorator();
    525474
    526     if (str == "")
    527         return CurrentDecorator();
    528 
    529     fLock.Lock();
     475    BAutolock _(fLock);
     476    if (!fHasScanned)
     477        ScanDecorators();
    530478
    531479    // 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;
    543483
     484    // search by cached name
    544485    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;
    569489    }
    570490
    571     fLock.Unlock();
    572491    return NULL;
    573492}
    574493
     
    576495DecorInfo*
    577496DecorInfoUtility::CurrentDecorator()
    578497{
     498    BAutolock _(fLock);
    579499    if (!fHasScanned)
    580500        ScanDecorators();
    581501
    582     BString str;
    583     get_decorator(&str);
    584     return FindDecorator(str);
     502    BString name;
     503    get_decorator(name);
     504    return FindDecorator(name);
    585505}
    586506
    587507
    588508DecorInfo*
    589509DecorInfoUtility::DefaultDecorator()
    590510{
     511    BAutolock _(fLock);
    591512    return fList.ItemAt(0);
    592513}
    593514
     
    595516bool
    596517DecorInfoUtility::IsCurrentDecorator(DecorInfo* decor)
    597518{
     519    BAutolock _(fLock);
    598520    if (decor == NULL)
    599521         return false;
    600     return decor->Path() == CurrentDecorator()->Path().String();
     522    return decor->Path() == CurrentDecorator()->Path();
    601523}
    602524
    603525
     
    607529    if (decor == NULL)
    608530        return B_BAD_VALUE;
    609531
     532    BAutolock _(fLock);
    610533    if (decor->IsDefault())
    611534        return set_decorator("Default");
    612535
     
    615538
    616539
    617540status_t
    618 DecorInfoUtility::SetDecorator(int32 indx)
     541DecorInfoUtility::SetDecorator(int32 index)
    619542{
     543    BAutolock _(fLock);
    620544    if (!fHasScanned)
    621545        return B_ERROR;
    622546
    623     DecorInfo* decor = DecoratorAt(indx);;
    624 
    625     if (!decor)
     547    DecorInfo* decor = DecoratorAt(index);
     548    if (decor == NULL)
    626549        return B_BAD_INDEX;
    627550
    628551    return SetDecorator(decor);
     
    639562}
    640563
    641564
    642 // P R I V A T E
    643     // ENFORCE LOCKING!
     565// #pargma mark - private
     566
    644567
    645568DecorInfo*
    646 DecorInfoUtility::_find_decor(BString _path)
    647 {       // find decor by path and path alone!
     569DecorInfoUtility::_FindDecor(const BString& pathString)
     570{
     571    // find decor by path and path alone!
    648572    if (!fLock.IsLocked()) {
    649573        fprintf(stderr, "DecorInfoUtility::_find_decor()\tfailure to lock! - "
    650                 "BUG BUG BUG\n");
     574            "BUG BUG BUG\n");
    651575        return NULL;
    652576    }
    653577
    654     BString tmp = _path;
    655     if (tmp.ToLower() == "default")
     578    if (pathString == "Default")
    656579        return fList.ItemAt(0);
    657580
    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;
    679591    }
    680592
    681593    return NULL;
  • src/kits/interface/InterfaceDefs.

    old new  
    11961196    \return boolean true/false
    11971197*/
    11981198bool
    1199 get_decorator(BString * path)
     1199get_decorator(BString& path)
    12001200{
    1201     if ( ! path )
    1202         return false;
    1203 
    12041201    BPrivate::AppServerLink link;
    12051202    link.StartMessage(AS_GET_DECORATOR);
    12061203
     
    12081205    if (link.FlushWithReply(code) != B_OK || code != B_OK)
    12091206        return false;
    12101207
    1211     return ( link.ReadString(*path) == B_OK );
     1208    return link.ReadString(path) == B_OK;
    12121209}
    12131210
    12141211
     
    12181215    Will return detailed error status via status_t
    12191216*/
    12201217status_t
    1221 set_decorator(BString path)
     1218set_decorator(const BString& path)
    12221219{
    12231220    BPrivate::AppServerLink link;
    12241221
     
    12331230    return error;
    12341231}
    12351232
     1233
    12361234/*! \brief sets a window to preview a given decorator
    12371235    \param path path to any given decorator add-on
    12381236    \param window pointer to BWindow which will show decorator
     
    12401238    Piggy-backs on BWindow::SetDecoratorSettings(...)
    12411239*/
    12421240status_t
    1243 preview_decorator(BString path, BWindow * window)
     1241preview_decorator(const BString& path, BWindow* window)
    12441242{
    12451243    if (window == NULL)
    12461244        return B_ERROR;
  • headers/private/interface/DecorInfo.

    old new  
    1717#include <ObjectList.h>
    1818
    1919
     20// NOTE: DecorInfo itself is not thread-safe
    2021class 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;
     22public:
     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
     58private:
     59            void                _Init(bool is_update = false);
     60
     61private:
     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;
    6872
    69             float       fVersion;
     73            float               fVersion;
    7074
    71             time_t      fModificationTime;
     75            time_t              fModificationTime;
    7276
    73             status_t    fInitStatus;
     77            status_t            fInitStatus;
    7478};
    7579
    7680
    7781class DecorInfoUtility{
    78     public:
    79                         DecorInfoUtility(bool scan_now = true);
    80                                     // scan now or as neeeded?
     82public:
     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.
    8188
    82                         ~DecorInfoUtility();
     89                                ~DecorInfoUtility();
    8390
    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?
    9098
    91             int32       CountDecorators();
     99            int32               CountDecorators();
    92100
    93             DecorInfo*  DecoratorAt(int32);
     101            DecorInfo*          DecoratorAt(int32);
    94102
    95             DecorInfo*  FindDecorator(BString);
    96                 // checks for ref.name, path, fName, and "Default,"
    97                 // an empty-string returns the current decorator
    98                 // NULL on match failure
     103            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
    99107
    100             DecorInfo*  CurrentDecorator();
    101             DecorInfo*  DefaultDecorator();
     108            DecorInfo*          CurrentDecorator();
     109            DecorInfo*          DefaultDecorator();
    102110
    103             bool        IsCurrentDecorator(DecorInfo*);
     111            bool                IsCurrentDecorator(DecorInfo*);
    104112
    105             status_t    SetDecorator(DecorInfo*);
    106             status_t    SetDecorator(int32);
     113            status_t            SetDecorator(DecorInfo*);
     114            status_t            SetDecorator(int32);
    107115
    108             status_t    Preview(DecorInfo* decor, BWindow* window);
     116            status_t            Preview(DecorInfo* decor, BWindow* window);
    109117
    110     private:
    111             DecorInfo*  _find_decor(BString path);
     118private:
     119            DecorInfo*          _FindDecor(const BString& path);
    112120
     121private:
    113122            BObjectList<DecorInfo>  fList;
    114123            BLocker                 fLock;
    115124            bool                    fHasScanned;