haiku/headers/private/interface/DecorInfo.h
Stephan Aßmus b46615c55a Applied patch by Joseph "looncraz" Groover from ticket #7445.
This changes how Decorators are managed and applied. The app_server
no longer scans and maintains the available ones himself, but is
simply asked to load a Decorator add-on from a provided path.
The Decorator scanning is moved into DecorInfo and DecorInfoUtil,
private classes in the InterfaceKit. The bin command 'setdecor'
uses those.
I cleaned up all the coding style violations that I could find,
removed chunks of code which didn't make sense (if you never put
a NULL pointer into a list, you don't need to check for this and
so on) and also cleaned up other passages for improved clarity
and simplicity.
I also tested the functionality and it works fine. Would even be
Ok to include in Alpha 3, IMHO. Thanks for the patch!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41581 a95241bf-73f2-0310-859d-f6bbb57e9c96
2011-05-19 15:25:54 +00:00

130 lines
2.9 KiB
C++

/*
* Public domain source code.
*
* Author:
* Joseph "looncraz" Groover <looncraz@satx.rr.com>
*/
#ifndef DECOR_INFO_H
#define DECOR_INFO_H
#include <Entry.h>
#include <Bitmap.h>
#include <String.h>
#include <Locker.h>
#include <ObjectList.h>
// NOTE: DecorInfo itself is not thread-safe
class DecorInfo {
public:
DecorInfo();
DecorInfo(const BString& path);
DecorInfo(const entry_ref& ref);
~DecorInfo();
status_t SetTo(const entry_ref& ref);
status_t SetTo(BString path);
status_t InitCheck() const;
void Unset();
bool IsDefault() const;
BString Path() const;
// Returns "Default" for the default decorator
const entry_ref* Ref() const;
// Returns NULL if virtual (default) or InitCheck() != B_OK
// The ref returned may NOT be the same as the one given to
// SetTo or the constructor - we may have traversed a Symlink!
BString Name() const;
BString ShortcutName() const;
BString Authors() const;
BString ShortDescription() const;
BString LongDescription() const;
BString LicenseURL() const;
BString LicenseName() const;
BString SupportURL() const;
float Version() const;
time_t ModificationTime() const;
bool CheckForChanges(bool &deleted);
private:
void _Init(bool is_update = false);
private:
entry_ref fRef;
BString fPath;
BString fName;
BString fAuthors;
BString fShortDescription;
BString fLongDescription;
BString fLicenseURL;
BString fLicenseName;
BString fSupportURL;
float fVersion;
time_t fModificationTime;
status_t fInitStatus;
};
class DecorInfoUtility{
public:
DecorInfoUtility(bool scanNow = true);
// NOTE: When scanNow is passed false,
// scanning will be performed lazily, such
// as in CountDecorators() and other
// methods.
~DecorInfoUtility();
status_t ScanDecorators();
// Can also be used to rescan for changes.
// Warning: potentially destructive as we
// will remove all DecorInfo objects which
// no longer have a file system cousin.
// TODO: Would a call-back mechanism be
// worthwhile here?
int32 CountDecorators();
DecorInfo* DecoratorAt(int32);
DecorInfo* FindDecorator(const BString& string);
// Checks for ref.name, path, fName, and
// "Default," an empty-string returns the
// current decorator NULL on match failure
DecorInfo* CurrentDecorator();
DecorInfo* DefaultDecorator();
bool IsCurrentDecorator(DecorInfo*);
status_t SetDecorator(DecorInfo*);
status_t SetDecorator(int32);
status_t Preview(DecorInfo* decor, BWindow* window);
private:
DecorInfo* _FindDecor(const BString& path);
private:
BObjectList<DecorInfo> fList;
BLocker fLock;
bool fHasScanned;
};
#endif