From d0815ca03b474657ea161f5d3783b458c899a947 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 8 May 2013 04:39:56 +0200 Subject: [PATCH] Add private MIME DB classes to libbe_build * This pulls in some more stuff, like libicon and agg which are also included in libbe_build, now. * Update a few libbe_build classes and headers needed to get things building. * This likely breaks the mimeset build on Haiku. --- headers/build/os/interface/Gradient.h | 1 + headers/build/os/interface/IconUtils.h | 1 + headers/build/os/storage/AppFileInfo.h | 129 +---- headers/build/os/storage/Entry.h | 2 + headers/build/private/interface/Palette.h | 1 + .../build/private/storage/MergedDirectory.h | 72 +++ .../private/storage/mime/AppMetaMimeCreator.h | 1 + .../private/storage/mime/AssociatedTypes.h | 1 + headers/build/private/storage/mime/Database.h | 1 + .../private/storage/mime/DatabaseDirectory.h | 1 + .../private/storage/mime/DatabaseLocation.h | 1 + .../private/storage/mime/InstalledTypes.h | 1 + .../build/private/storage/mime/MimeSniffer.h | 1 + .../build/private/storage/mime/SnifferRules.h | 1 + .../build/private/storage/mime/Supertype.h | 1 + .../private/storage/mime/SupportingApps.h | 1 + .../private/storage/mime/database_access.h | 46 -- .../private/storage/mime/database_support.h | 98 +--- .../private/storage/sniffer/CharStream.h | 1 + .../build/private/storage/sniffer/DisjList.h | 1 + headers/build/private/storage/sniffer/Err.h | 1 + .../build/private/storage/sniffer/Parser.h | 1 + .../build/private/storage/sniffer/Pattern.h | 1 + .../private/storage/sniffer/PatternList.h | 1 + .../build/private/storage/sniffer/RPattern.h | 1 + .../private/storage/sniffer/RPatternList.h | 1 + headers/build/private/storage/sniffer/Range.h | 1 + headers/build/private/storage/sniffer/Rule.h | 1 + src/build/Jamfile | 1 + src/build/libbe/Jamfile | 2 + src/build/libbe/icon/Jamfile | 92 ++++ src/build/libbe/interface/Jamfile | 2 + src/build/libbe/interface/SystemPalette.cpp | 126 +++++ src/build/libbe/storage/AppFileInfo.cpp | 509 ++++++++++++++---- src/build/libbe/storage/Entry.cpp | 10 + src/build/libbe/storage/Jamfile | 26 + src/build/libbe/storage/MergedDirectory.cpp | 240 +++++++++ src/build/libbe/storage/Mime.cpp | 3 +- .../libbe/storage/mime/database_support.cpp | 378 ------------- src/build/libicon/Jamfile | 63 +++ src/tools/Jamfile | 7 +- 41 files changed, 1058 insertions(+), 771 deletions(-) create mode 100644 headers/build/os/interface/Gradient.h create mode 100644 headers/build/os/interface/IconUtils.h create mode 100644 headers/build/private/interface/Palette.h create mode 100644 headers/build/private/storage/MergedDirectory.h create mode 100644 headers/build/private/storage/mime/AppMetaMimeCreator.h create mode 100644 headers/build/private/storage/mime/AssociatedTypes.h create mode 100644 headers/build/private/storage/mime/Database.h create mode 100644 headers/build/private/storage/mime/DatabaseDirectory.h create mode 100644 headers/build/private/storage/mime/DatabaseLocation.h create mode 100644 headers/build/private/storage/mime/InstalledTypes.h create mode 100644 headers/build/private/storage/mime/MimeSniffer.h create mode 100644 headers/build/private/storage/mime/SnifferRules.h create mode 100644 headers/build/private/storage/mime/Supertype.h create mode 100644 headers/build/private/storage/mime/SupportingApps.h delete mode 100644 headers/build/private/storage/mime/database_access.h create mode 100644 headers/build/private/storage/sniffer/CharStream.h create mode 100644 headers/build/private/storage/sniffer/DisjList.h create mode 100644 headers/build/private/storage/sniffer/Err.h create mode 100644 headers/build/private/storage/sniffer/Parser.h create mode 100644 headers/build/private/storage/sniffer/Pattern.h create mode 100644 headers/build/private/storage/sniffer/PatternList.h create mode 100644 headers/build/private/storage/sniffer/RPattern.h create mode 100644 headers/build/private/storage/sniffer/RPatternList.h create mode 100644 headers/build/private/storage/sniffer/Range.h create mode 100644 headers/build/private/storage/sniffer/Rule.h create mode 100644 src/build/libbe/icon/Jamfile create mode 100644 src/build/libbe/interface/SystemPalette.cpp create mode 100644 src/build/libbe/storage/MergedDirectory.cpp delete mode 100644 src/build/libbe/storage/mime/database_support.cpp create mode 100644 src/build/libicon/Jamfile diff --git a/headers/build/os/interface/Gradient.h b/headers/build/os/interface/Gradient.h new file mode 100644 index 0000000000..8a46fa6020 --- /dev/null +++ b/headers/build/os/interface/Gradient.h @@ -0,0 +1 @@ +#include <../os/interface/Gradient.h> diff --git a/headers/build/os/interface/IconUtils.h b/headers/build/os/interface/IconUtils.h new file mode 100644 index 0000000000..99f3c7459f --- /dev/null +++ b/headers/build/os/interface/IconUtils.h @@ -0,0 +1 @@ +#include <../os/interface/IconUtils.h> diff --git a/headers/build/os/storage/AppFileInfo.h b/headers/build/os/storage/AppFileInfo.h index 235be9bb1b..9ed7e9deae 100644 --- a/headers/build/os/storage/AppFileInfo.h +++ b/headers/build/os/storage/AppFileInfo.h @@ -1,128 +1 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- -/*! - \file AppFileInfo.h - BAppFileInfo and related structures' interface declarations. -*/ -#ifndef _APP_FILE_INFO_H -#define _APP_FILE_INFO_H - -#include - -class BBitmap; -class BFile; -class BMessage; -class BResources; - -struct version_info { - uint32 major; - uint32 middle; - uint32 minor; - uint32 variety; - uint32 internal; - char short_info[64]; - char long_info[256]; -}; - -enum info_location { - B_USE_ATTRIBUTES = 0x1, - B_USE_RESOURCES = 0x2, - B_USE_BOTH_LOCATIONS = 0x3 // == B_USE_ATTRIBUTES | B_USE_RESOURCES -}; - -enum version_kind { - B_APP_VERSION_KIND, - B_SYSTEM_VERSION_KIND -}; - -/*! \brief Executable meta information handling. - The BAppFileInfo class provides access to meta data that can be associated - with executables, libraries and add-ons. - - \author Ingo Weinhold - \version 0.0.0 -*/ -class BAppFileInfo: public BNodeInfo { -public: - BAppFileInfo(); - BAppFileInfo(BFile *file); - virtual ~BAppFileInfo(); - - status_t SetTo(BFile *file); - - virtual status_t GetType(char *type) const; - virtual status_t SetType(const char *type); - - status_t GetSignature(char *signature) const; - status_t SetSignature(const char *signature); - - status_t GetCatalogEntry(char *catalogEntry) const; - status_t SetCatalogEntry(const char *catalogEntry); - - status_t GetAppFlags(uint32 *flags) const; - status_t SetAppFlags(uint32 flags); - - status_t GetSupportedTypes(BMessage *types) const; - status_t SetSupportedTypes(const BMessage *types, bool syncAll); - status_t SetSupportedTypes(const BMessage *types); - bool IsSupportedType(const char *type) const; - bool Supports(BMimeType *type) const; - - virtual status_t GetIcon(BBitmap *icon, icon_size which) const; - virtual status_t SetIcon(const BBitmap *icon, icon_size which); - - status_t GetVersionInfo(version_info *info, version_kind kind) const; - status_t SetVersionInfo(const version_info *info, version_kind kind); - - status_t GetIconForType(const char *type, BBitmap *icon, - icon_size which) const; - status_t SetIconForType(const char *type, const BBitmap *icon, - icon_size which); - - void SetInfoLocation(info_location location); - bool IsUsingAttributes() const; - bool IsUsingResources() const; - -private: -// uncomment when needed -// friend status_t _update_mime_info_(const char *, int32); -// friend status_t _real_update_app_(BAppFileInfo *, const char *, bool); -// friend status_t _query_for_app_(BMimeType *, const char *, entry_ref *, -// version_info *); -// friend class BRoster; - - virtual void _ReservedAppFileInfo1(); - virtual void _ReservedAppFileInfo2(); - virtual void _ReservedAppFileInfo3(); - -// uncomment when needed -// static status_t SetSupTypesForAll(BMimeType *, const BMessage *); - - BAppFileInfo &operator=(const BAppFileInfo &); - BAppFileInfo(const BAppFileInfo &); - -// uncomment when needed -// status_t _SetSupportedTypes(const BMessage *types); -// status_t UpdateFromRsrc(); -// status_t RealUpdateRsrcToAttr(); -// status_t UpdateMetaMime(const char *path, bool force, -// uint32 *changesMask) const; -// bool IsApp(); - status_t GetMetaMime(BMimeType *meta) const; - - status_t _ReadData(const char *name, int32 id, type_code type, - void *buffer, size_t bufferSize, - size_t &bytesRead, void **allocatedBuffer = NULL) const; - status_t _WriteData(const char *name, int32 id, type_code type, - const void *buffer, size_t bufferSize, - bool findID = false); - status_t _RemoveData(const char *name, type_code type); - - BResources *fResources; - info_location fWhere; - uint32 _reserved[2]; -}; - -#endif // _APP_FILE_INFO_H +#include <../os/storage/AppFileInfo.h> diff --git a/headers/build/os/storage/Entry.h b/headers/build/os/storage/Entry.h index 58a1208ad0..46775c54b4 100644 --- a/headers/build/os/storage/Entry.h +++ b/headers/build/os/storage/Entry.h @@ -51,6 +51,8 @@ public: status_t InitCheck() const; bool Exists() const; + const char* Name() const; + virtual status_t GetStat(struct stat *st) const; status_t SetTo(const BDirectory *dir, const char *path, diff --git a/headers/build/private/interface/Palette.h b/headers/build/private/interface/Palette.h new file mode 100644 index 0000000000..630ee6a6b3 --- /dev/null +++ b/headers/build/private/interface/Palette.h @@ -0,0 +1 @@ +#include <../private/interface/Palette.h> diff --git a/headers/build/private/storage/MergedDirectory.h b/headers/build/private/storage/MergedDirectory.h new file mode 100644 index 0000000000..667902ed14 --- /dev/null +++ b/headers/build/private/storage/MergedDirectory.h @@ -0,0 +1,72 @@ +/* + * Copyright 2013, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ingo Weinhold + */ +#ifndef _MERGED_DIRECTORY_H +#define _MERGED_DIRECTORY_H + + +#include +#include + + +class BDirectory; + + +class BMergedDirectory : public BEntryList { +public: + // policy how to handle equally named entries in different + // directories + enum BPolicy { + B_ALLOW_DUPLICATES, + B_ALWAYS_FIRST, + B_COMPARE + }; + +public: + BMergedDirectory( + BPolicy policy = B_ALWAYS_FIRST); + virtual ~BMergedDirectory(); + + status_t Init(); + + BPolicy Policy() const; + void SetPolicy(BPolicy policy); + + status_t AddDirectory(BDirectory* directory); + status_t AddDirectory(const char* path); + + virtual status_t GetNextEntry(BEntry* entry, + bool traverse = false); + virtual status_t GetNextRef(entry_ref* ref); + virtual int32 GetNextDirents(struct dirent* direntBuffer, + size_t bufferSize, + int32 maxEntries = INT_MAX); + virtual status_t Rewind(); + virtual int32 CountEntries(); + +protected: + virtual bool ShallPreferFirstEntry(const entry_ref& entry1, + int32 index1, const entry_ref& entry2, + int32 index2); + // always invoked with index1 < index2 + +private: + typedef BObjectList DirectoryList; + struct EntryNameSet; + +private: + bool _IsBestEntry(const char* name); + +private: + DirectoryList fDirectories; + BPolicy fPolicy; + int32 fDirectoryIndex; + EntryNameSet* fVisitedEntries; +}; + + +#endif // _MERGED_DIRECTORY_H diff --git a/headers/build/private/storage/mime/AppMetaMimeCreator.h b/headers/build/private/storage/mime/AppMetaMimeCreator.h new file mode 100644 index 0000000000..f420c6a9c8 --- /dev/null +++ b/headers/build/private/storage/mime/AppMetaMimeCreator.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/AppMetaMimeCreator.h> diff --git a/headers/build/private/storage/mime/AssociatedTypes.h b/headers/build/private/storage/mime/AssociatedTypes.h new file mode 100644 index 0000000000..da79b982e9 --- /dev/null +++ b/headers/build/private/storage/mime/AssociatedTypes.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/AssociatedTypes.h> diff --git a/headers/build/private/storage/mime/Database.h b/headers/build/private/storage/mime/Database.h new file mode 100644 index 0000000000..683cad90ac --- /dev/null +++ b/headers/build/private/storage/mime/Database.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/Database.h> diff --git a/headers/build/private/storage/mime/DatabaseDirectory.h b/headers/build/private/storage/mime/DatabaseDirectory.h new file mode 100644 index 0000000000..c16303c0e8 --- /dev/null +++ b/headers/build/private/storage/mime/DatabaseDirectory.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/DatabaseDirectory.h> diff --git a/headers/build/private/storage/mime/DatabaseLocation.h b/headers/build/private/storage/mime/DatabaseLocation.h new file mode 100644 index 0000000000..858317f37e --- /dev/null +++ b/headers/build/private/storage/mime/DatabaseLocation.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/DatabaseLocation.h> diff --git a/headers/build/private/storage/mime/InstalledTypes.h b/headers/build/private/storage/mime/InstalledTypes.h new file mode 100644 index 0000000000..95412e1925 --- /dev/null +++ b/headers/build/private/storage/mime/InstalledTypes.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/InstalledTypes.h> diff --git a/headers/build/private/storage/mime/MimeSniffer.h b/headers/build/private/storage/mime/MimeSniffer.h new file mode 100644 index 0000000000..34329cdd38 --- /dev/null +++ b/headers/build/private/storage/mime/MimeSniffer.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/MimeSniffer.h> diff --git a/headers/build/private/storage/mime/SnifferRules.h b/headers/build/private/storage/mime/SnifferRules.h new file mode 100644 index 0000000000..aa242bc616 --- /dev/null +++ b/headers/build/private/storage/mime/SnifferRules.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/SnifferRules.h> diff --git a/headers/build/private/storage/mime/Supertype.h b/headers/build/private/storage/mime/Supertype.h new file mode 100644 index 0000000000..87f2bfd92f --- /dev/null +++ b/headers/build/private/storage/mime/Supertype.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/Supertype.h> diff --git a/headers/build/private/storage/mime/SupportingApps.h b/headers/build/private/storage/mime/SupportingApps.h new file mode 100644 index 0000000000..494a0efe62 --- /dev/null +++ b/headers/build/private/storage/mime/SupportingApps.h @@ -0,0 +1 @@ +#include <../../../private/storage/mime/SupportingApps.h> diff --git a/headers/build/private/storage/mime/database_access.h b/headers/build/private/storage/mime/database_access.h deleted file mode 100644 index 5e6a8026f2..0000000000 --- a/headers/build/private/storage/mime/database_access.h +++ /dev/null @@ -1,46 +0,0 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- -/*! - \file database_access.h - Mime database atomic read functions and miscellany declarations -*/ - -#ifndef _MIME_DATABASE_ACCESS_H -#define _MIME_DATABASE_ACCESS_H - -#include - -class BNode; -class BBitmap; -class BMessage; - -namespace BPrivate { -namespace Storage { -namespace Mime { - -// Get() functions -status_t get_app_hint(const char *type, entry_ref *ref); -status_t get_attr_info(const char *type, BMessage *info); -status_t get_short_description(const char *type, char *description); -status_t get_long_description(const char *type, char *description); -status_t get_file_extensions(const char *type, BMessage *extensions); -status_t get_icon(const char *type, BBitmap *icon, icon_size size); -status_t get_icon_for_type(const char *type, const char *fileType, BBitmap *icon, - icon_size which); -status_t get_preferred_app(const char *type, char *signature, app_verb verb); -status_t get_sniffer_rule(const char *type, BString *result); -status_t get_supported_types(const char *type, BMessage *types); - -bool is_installed(const char *type); - -// Called by BMimeType to get properly formatted icon data ready -// to be shipped off to SetIcon*() and written to the database -status_t get_icon_data(const BBitmap *icon, icon_size size, void **data, int32 *dataSize); - -} // namespace Mime -} // namespace Storage -} // namespace BPrivate - -#endif // _MIME_DATABASE_H diff --git a/headers/build/private/storage/mime/database_support.h b/headers/build/private/storage/mime/database_support.h index 557b8ab15a..a207876afe 100644 --- a/headers/build/private/storage/mime/database_support.h +++ b/headers/build/private/storage/mime/database_support.h @@ -1,97 +1 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- -/*! - \file database_support.h - Private mime database function and constant declarations -*/ - -#ifndef _MIME_DATABASE_SUPPORT_H -#define _MIME_DATABASE_SUPPORT_H - -#include - -#include - -class BNode; -class BMessage; - -namespace BPrivate { -namespace Storage { -namespace Mime { - -// Database directory -extern const std::string kDatabaseDir; -extern const std::string kApplicationDatabaseDir; - -// Attribute Prefixes -extern const char *kMiniIconAttrPrefix; -extern const char *kLargeIconAttrPrefix; - -// Attribute names -extern const char *kFileTypeAttr; -extern const char *kTypeAttr; -extern const char *kAttrInfoAttr; -extern const char *kAppHintAttr; -extern const char *kShortDescriptionAttr; -extern const char *kLongDescriptionAttr; -extern const char *kFileExtensionsAttr; -extern const char *kMiniIconAttr; -extern const char *kLargeIconAttr; -extern const char *kPreferredAppAttr; -extern const char *kSnifferRuleAttr; -extern const char *kSupportedTypesAttr; - -// Attribute Datatypes -extern const int32 kFileTypeType; -extern const int32 kTypeType; -extern const int32 kAppHintType; -extern const int32 kAttrInfoType; -extern const int32 kShortDescriptionType; -extern const int32 kLongDescriptionType; -extern const int32 kFileExtensionsType; -extern const int32 kMiniIconType; -extern const int32 kLargeIconType; -extern const int32 kPreferredAppType; -extern const int32 kSnifferRuleType; -extern const int32 kSupportedTypesType; - -// Message fields -extern const char *kApplicationsField; -extern const char *kExtensionsField; -extern const char *kSupertypesField; -extern const char *kSupportingAppsSubCountField; -extern const char *kSupportingAppsSuperCountField; -extern const char *kTypesField; - -// Mime types -extern const char *kGenericFileType; -extern const char *kDirectoryType; -extern const char *kSymlinkType; -extern const char *kMetaMimeType; - -// Error codes (to be used only by BPrivate::Storage::Mime members) -extern const status_t kMimeGuessFailureError; - -std::string type_to_filename(const char *type); - -status_t open_type(const char *type, BNode *result); -status_t open_or_create_type(const char *type, BNode *result, bool *didCreate); - -ssize_t read_mime_attr(const char *type, const char *attr, void *data, - size_t len, type_code datatype); -status_t read_mime_attr_message(const char *type, const char *attr, BMessage *msg); -status_t read_mime_attr_string(const char *type, const char *attr, BString *str); -status_t write_mime_attr(const char *type, const char *attr, const void *data, - size_t len, type_code datatype, bool *didCreate); -status_t write_mime_attr_message(const char *type, const char *attr, - const BMessage *msg, bool *didCreate); - -status_t delete_attribute(const char *type, const char *attr); - -} // namespace Mime -} // namespace Storage -} // namespace BPrivate - -#endif // _MIME_DATABASE_SUPPORT_H +#include <../../../private/storage/mime/database_support.h> diff --git a/headers/build/private/storage/sniffer/CharStream.h b/headers/build/private/storage/sniffer/CharStream.h new file mode 100644 index 0000000000..88909236a5 --- /dev/null +++ b/headers/build/private/storage/sniffer/CharStream.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/CharStream.h> diff --git a/headers/build/private/storage/sniffer/DisjList.h b/headers/build/private/storage/sniffer/DisjList.h new file mode 100644 index 0000000000..695dea1593 --- /dev/null +++ b/headers/build/private/storage/sniffer/DisjList.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/DisjList.h> diff --git a/headers/build/private/storage/sniffer/Err.h b/headers/build/private/storage/sniffer/Err.h new file mode 100644 index 0000000000..9b0c0965a4 --- /dev/null +++ b/headers/build/private/storage/sniffer/Err.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/Err.h> diff --git a/headers/build/private/storage/sniffer/Parser.h b/headers/build/private/storage/sniffer/Parser.h new file mode 100644 index 0000000000..acda7de966 --- /dev/null +++ b/headers/build/private/storage/sniffer/Parser.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/Parser.h> diff --git a/headers/build/private/storage/sniffer/Pattern.h b/headers/build/private/storage/sniffer/Pattern.h new file mode 100644 index 0000000000..798d6eb68f --- /dev/null +++ b/headers/build/private/storage/sniffer/Pattern.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/Pattern.h> diff --git a/headers/build/private/storage/sniffer/PatternList.h b/headers/build/private/storage/sniffer/PatternList.h new file mode 100644 index 0000000000..67ff2e55cf --- /dev/null +++ b/headers/build/private/storage/sniffer/PatternList.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/PatternList.h> diff --git a/headers/build/private/storage/sniffer/RPattern.h b/headers/build/private/storage/sniffer/RPattern.h new file mode 100644 index 0000000000..1547c8f931 --- /dev/null +++ b/headers/build/private/storage/sniffer/RPattern.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/RPattern.h> diff --git a/headers/build/private/storage/sniffer/RPatternList.h b/headers/build/private/storage/sniffer/RPatternList.h new file mode 100644 index 0000000000..b2a6b6ff46 --- /dev/null +++ b/headers/build/private/storage/sniffer/RPatternList.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/RPatternList.h> diff --git a/headers/build/private/storage/sniffer/Range.h b/headers/build/private/storage/sniffer/Range.h new file mode 100644 index 0000000000..3d05e0b2d8 --- /dev/null +++ b/headers/build/private/storage/sniffer/Range.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/Range.h> diff --git a/headers/build/private/storage/sniffer/Rule.h b/headers/build/private/storage/sniffer/Rule.h new file mode 100644 index 0000000000..7635c40a9f --- /dev/null +++ b/headers/build/private/storage/sniffer/Rule.h @@ -0,0 +1 @@ +#include <../../../private/storage/sniffer/Rule.h> diff --git a/src/build/Jamfile b/src/build/Jamfile index 17634b03de..55b852805e 100644 --- a/src/build/Jamfile +++ b/src/build/Jamfile @@ -2,6 +2,7 @@ SubDir HAIKU_TOP src build ; SubInclude HAIKU_TOP src build libbe ; SubInclude HAIKU_TOP src build libhaikucompat ; +SubInclude HAIKU_TOP src build libicon ; SubInclude HAIKU_TOP src build libpackage ; SubInclude HAIKU_TOP src build libroot ; SubInclude HAIKU_TOP src build libshared ; diff --git a/src/build/libbe/Jamfile b/src/build/libbe/Jamfile index 68d2afb16d..80c84ea93b 100644 --- a/src/build/libbe/Jamfile +++ b/src/build/libbe/Jamfile @@ -9,6 +9,7 @@ BuildPlatformSharedLibrary libbe_build.so : # no sources here : app_kit.o + icon_kit.o interface_kit.o storage_kit.o support_kit.o @@ -17,6 +18,7 @@ BuildPlatformSharedLibrary libbe_build.so : ; SubInclude HAIKU_TOP src build libbe app ; +SubInclude HAIKU_TOP src build libbe icon ; SubInclude HAIKU_TOP src build libbe interface ; SubInclude HAIKU_TOP src build libbe storage ; SubInclude HAIKU_TOP src build libbe support ; diff --git a/src/build/libbe/icon/Jamfile b/src/build/libbe/icon/Jamfile new file mode 100644 index 0000000000..3bad50a19e --- /dev/null +++ b/src/build/libbe/icon/Jamfile @@ -0,0 +1,92 @@ +SubDir HAIKU_TOP src build libbe icon ; + +# source directories +local sourceDirs = + $(DOT) + flat_icon + message + shape + style + transformable + transformer +; + +local sourceDir ; +for sourceDir in $(sourceDirs) { + SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src libs icon $(sourceDir) ] ; +} + +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src libs agg src ] ; + +# system headers +UseLibraryHeaders agg icon ; + +UsePrivateBuildHeaders shared ; + +USES_BE_API on icon_kit.o = true ; + +BuildPlatformMergeObjectPIC icon_kit.o : + # flat_icon + FlatIconFormat.cpp + FlatIconImporter.cpp + LittleEndianBuffer.cpp + PathCommandQueue.cpp + + # message + Defines.cpp + MessageImporter.cpp + + # shape + PathContainer.cpp + Shape.cpp + ShapeContainer.cpp + VectorPath.cpp + + # style + GradientTransformable.cpp + Style.cpp + StyleContainer.cpp + + # transformable + Transformable.cpp + + # transformer + AffineTransformer.cpp + ContourTransformer.cpp + PathSource.cpp + PerspectiveTransformer.cpp + StrokeTransformer.cpp + Transformer.cpp + TransformerFactory.cpp + + Icon.cpp + IconRenderer.cpp + IconUtils.cpp + + # agg + agg_arc.cpp + agg_arrowhead.cpp + agg_bezier_arc.cpp + agg_bspline.cpp + agg_curves.cpp + agg_embedded_raster_fonts.cpp + agg_gsv_text.cpp + agg_image_filters.cpp + agg_line_aa_basics.cpp + agg_line_profile_aa.cpp + agg_rounded_rect.cpp + agg_sqrt_tables.cpp + agg_trans_affine.cpp + agg_trans_double_path.cpp + agg_trans_single_path.cpp + agg_trans_warp_magnifier.cpp + agg_vcgen_bspline.cpp + agg_vcgen_contour.cpp + agg_vcgen_dash.cpp + agg_vcgen_markers_term.cpp + agg_vcgen_smooth_poly1.cpp + agg_vcgen_stroke.cpp + agg_vpgen_clip_polygon.cpp + agg_vpgen_clip_polyline.cpp + agg_vpgen_segmentator.cpp +; diff --git a/src/build/libbe/interface/Jamfile b/src/build/libbe/interface/Jamfile index 5b19f2b79e..4c7d415ff9 100644 --- a/src/build/libbe/interface/Jamfile +++ b/src/build/libbe/interface/Jamfile @@ -8,9 +8,11 @@ USES_BE_API on interface_kit.o = true ; BuildPlatformMergeObjectPIC interface_kit.o : Bitmap.cpp + Gradient.cpp GraphicsDefs.cpp Point.cpp Rect.cpp Region.cpp RegionSupport.cpp + SystemPalette.cpp ; diff --git a/src/build/libbe/interface/SystemPalette.cpp b/src/build/libbe/interface/SystemPalette.cpp new file mode 100644 index 0000000000..bd6977e678 --- /dev/null +++ b/src/build/libbe/interface/SystemPalette.cpp @@ -0,0 +1,126 @@ +/* + * Copyright 2001-2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + * Stefano Ceccherini (burton666@libero.it) + */ + +//! Methods to initialize and get the system color_map. + + +#include +#include + +#include + +// TODO: BWindowScreen has a method to set the palette. +// maybe we should have a lock to protect this variable. +static color_map sColorMap; + + +// color_distance +/*! \brief Returns the "distance" between two RGB colors. + + This functions defines an metric on the RGB color space. The distance + between two colors is 0, if and only if the colors are equal. + + \param red1 Red component of the first color. + \param green1 Green component of the first color. + \param blue1 Blue component of the first color. + \param red2 Red component of the second color. + \param green2 Green component of the second color. + \param blue2 Blue component of the second color. + \return The distance between the given colors. +*/ +static inline uint32 +color_distance(uint8 red1, uint8 green1, uint8 blue1, + uint8 red2, uint8 green2, uint8 blue2) +{ + int rd = (int)red1 - (int)red2; + int gd = (int)green1 - (int)green2; + int bd = (int)blue1 - (int)blue2; + + // distance according to psycho-visual tests + // algorithm taken from here: + // http://www.stud.uni-hannover.de/~michaelt/juggle/Algorithms.pdf + int rmean = ((int)red1 + (int)red2) / 2; + return (((512 + rmean) * rd * rd) >> 8) + + 4 * gd * gd + + (((767 - rmean) * bd * bd) >> 8); +} + + +static inline uint8 +FindClosestColor(const rgb_color &color, const rgb_color *palette) +{ + uint8 closestIndex = 0; + unsigned closestDistance = UINT_MAX; + for (int32 i = 0; i < 256; i++) { + const rgb_color &c = palette[i]; + unsigned distance = color_distance(color.red, color.green, color.blue, + c.red, c.green, c.blue); + if (distance < closestDistance) { + closestIndex = (uint8)i; + closestDistance = distance; + } + } + return closestIndex; +} + + +static inline rgb_color +InvertColor(const rgb_color &color) +{ + // For some reason, Inverting (255, 255, 255) on beos + // results in the same color. + if (color.red == 255 && color.green == 255 + && color.blue == 255) + return color; + + rgb_color inverted; + inverted.red = 255 - color.red; + inverted.green = 255 - color.green; + inverted.blue = 255 - color.blue; + inverted.alpha = 255; + + return inverted; +} + + +static void +FillColorMap(const rgb_color *palette, color_map *map) +{ + memcpy(map->color_list, palette, sizeof(map->color_list)); + + // init index map + for (int32 color = 0; color < 32768; color++) { + // get components + rgb_color rgbColor; + rgbColor.red = (color & 0x7c00) >> 7; + rgbColor.green = (color & 0x3e0) >> 2; + rgbColor.blue = (color & 0x1f) << 3; + + map->index_map[color] = FindClosestColor(rgbColor, palette); + } + + // init inversion map + for (int32 index = 0; index < 256; index++) { + rgb_color inverted = InvertColor(map->color_list[index]); + map->inversion_map[index] = FindClosestColor(inverted, palette); + } +} + + +const color_map * +system_colors() +{ + static bool sInitialized = false; + if (!sInitialized) { + FillColorMap(kSystemPalette, &sColorMap); + sInitialized = true; + } + + return &sColorMap; +} diff --git a/src/build/libbe/storage/AppFileInfo.cpp b/src/build/libbe/storage/AppFileInfo.cpp index 6ea04f461c..ab2208558d 100644 --- a/src/build/libbe/storage/AppFileInfo.cpp +++ b/src/build/libbe/storage/AppFileInfo.cpp @@ -1,11 +1,11 @@ -//---------------------------------------------------------------------- -// This software is part of the Haiku distribution and is covered -// by the MIT license. -//--------------------------------------------------------------------- -/*! - \file AppFileInfo.cpp - BAppFileInfo and related structures' implementation. -*/ +/* + * Copyright 2002-2007, Haiku Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ingo Weinhold, bonefish@users.sf.net + */ + #include #include @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -24,15 +26,17 @@ using namespace std; // attributes -static const char *kTypeAttribute = "BEOS:TYPE"; -static const char *kSignatureAttribute = "BEOS:APP_SIG"; -static const char *kAppFlagsAttribute = "BEOS:APP_FLAGS"; -static const char *kSupportedTypesAttribute = "BEOS:FILE_TYPES"; -static const char *kVersionInfoAttribute = "BEOS:APP_VERSION"; -static const char *kMiniIconAttribute = "BEOS:M:"; -static const char *kLargeIconAttribute = "BEOS:L:"; -static const char *kStandardIconType = "STD_ICON"; -static const char *kCatalogEntryAttribute = "SYS:NAME"; +static const char* kTypeAttribute = "BEOS:TYPE"; +static const char* kSignatureAttribute = "BEOS:APP_SIG"; +static const char* kAppFlagsAttribute = "BEOS:APP_FLAGS"; +static const char* kSupportedTypesAttribute = "BEOS:FILE_TYPES"; +static const char* kVersionInfoAttribute = "BEOS:APP_VERSION"; +static const char* kMiniIconAttribute = "BEOS:M:"; +static const char* kLargeIconAttribute = "BEOS:L:"; +static const char* kIconAttribute = "BEOS:"; +static const char* kStandardIconType = "STD_ICON"; +static const char* kIconType = "ICON"; +static const char* kCatalogEntryAttribute = "SYS:NAME"; // resource IDs static const int32 kTypeResourceID = 2; @@ -41,9 +45,11 @@ static const int32 kAppFlagsResourceID = 1; static const int32 kSupportedTypesResourceID = 1; static const int32 kMiniIconResourceID = 101; static const int32 kLargeIconResourceID = 101; +static const int32 kIconResourceID = 101; static const int32 kVersionInfoResourceID = 1; static const int32 kMiniIconForTypeResourceID = 0; static const int32 kLargeIconForTypeResourceID = 0; +static const int32 kIconForTypeResourceID = 0; static const int32 kCatalogEntryResourceID = 1; // type codes @@ -53,7 +59,7 @@ enum { }; // R5 also exports these (Tracker is using them): -// (maybe we better want to drop them silently and declare +// (maybe we better want to drop them silently and declare // the above in a public Haiku header - and use that one in // Tracker when compiled for Haiku) extern const uint32 MINI_ICON_TYPE, LARGE_ICON_TYPE; @@ -69,11 +75,13 @@ const uint32 LARGE_ICON_TYPE = 'ICON'; /*! \brief Creates an uninitialized BAppFileInfo object. */ BAppFileInfo::BAppFileInfo() - : fResources(NULL), - fWhere(B_USE_BOTH_LOCATIONS) + : + fResources(NULL), + fWhere(B_USE_BOTH_LOCATIONS) { } + // constructor /*! \brief Creates an BAppFileInfo object and initializes it to the supplied file. @@ -84,13 +92,15 @@ BAppFileInfo::BAppFileInfo() \param file The file the object shall be initialized to. */ -BAppFileInfo::BAppFileInfo(BFile *file) - : fResources(NULL), - fWhere(B_USE_BOTH_LOCATIONS) +BAppFileInfo::BAppFileInfo(BFile* file) + : + fResources(NULL), + fWhere(B_USE_BOTH_LOCATIONS) { SetTo(file); } + // destructor /*! \brief Frees all resources associated with this object. @@ -98,10 +108,10 @@ BAppFileInfo::BAppFileInfo(BFile *file) */ BAppFileInfo::~BAppFileInfo() { - if (fResources) - delete fResources; + delete fResources; } + // SetTo /*! \brief Initializes the BAppFileInfo to the supplied file. @@ -124,36 +134,52 @@ BAppFileInfo::SetTo(BFile *file) delete fResources; fResources = NULL; } + // check param status_t error = (file && file->InitCheck() == B_OK ? B_OK : B_BAD_VALUE); + + info_location where = B_USE_BOTH_LOCATIONS; + // create resources if (error == B_OK) { fResources = new(nothrow) BResources(); - if (fResources) + if (fResources) { error = fResources->SetTo(file); - else + if (error != B_OK) { + // no resources - this is no critical error, we'll just use + // attributes only, then + where = B_USE_ATTRIBUTES; + error = B_OK; + } + } else error = B_NO_MEMORY; } + // set node info if (error == B_OK) error = BNodeInfo::SetTo(file); + + if (error != B_OK || (where & B_USE_RESOURCES) == 0) { + delete fResources; + fResources = NULL; + } + // clean up on error if (error != B_OK) { - if (fResources) { - delete fResources; - fResources = NULL; - } if (InitCheck() == B_OK) BNodeInfo::SetTo(NULL); } + // set data location if (error == B_OK) - SetInfoLocation(B_USE_BOTH_LOCATIONS); + SetInfoLocation(where); + // set error fCStatus = error; return error; } + // GetType /*! \brief Gets the file's MIME type. @@ -193,6 +219,7 @@ BAppFileInfo::GetType(char *type) const return error; } + // SetType /*! \brief Sets the file's MIME type. @@ -208,7 +235,7 @@ BAppFileInfo::GetType(char *type) const - other error codes */ status_t -BAppFileInfo::SetType(const char *type) +BAppFileInfo::SetType(const char* type) { // check initialization status_t error = B_OK; @@ -231,6 +258,7 @@ BAppFileInfo::SetType(const char *type) return error; } + // GetSignature /*! \brief Gets the file's application signature. @@ -248,7 +276,7 @@ BAppFileInfo::SetType(const char *type) - other error codes */ status_t -BAppFileInfo::GetSignature(char *signature) const +BAppFileInfo::GetSignature(char* signature) const { // check param and initialization status_t error = (signature ? B_OK : B_BAD_VALUE); @@ -258,8 +286,8 @@ BAppFileInfo::GetSignature(char *signature) const size_t read = 0; if (error == B_OK) { error = _ReadData(kSignatureAttribute, kSignatureResourceID, - B_MIME_STRING_TYPE, signature, B_MIME_TYPE_LENGTH, - read); + B_MIME_STRING_TYPE, signature, + B_MIME_TYPE_LENGTH, read); } // check the read data -- null terminate the string if (error == B_OK && signature[read - 1] != '\0') { @@ -271,6 +299,7 @@ BAppFileInfo::GetSignature(char *signature) const return error; } + // SetSignature /*! \brief Sets the file's application signature. @@ -286,7 +315,7 @@ BAppFileInfo::GetSignature(char *signature) const - other error codes */ status_t -BAppFileInfo::SetSignature(const char *signature) +BAppFileInfo::SetSignature(const char* signature) { // check initialization status_t error = B_OK; @@ -368,7 +397,7 @@ BAppFileInfo::GetCatalogEntry(char *catalogEntry) const - other error codes */ status_t -BAppFileInfo::SetCatalogEntry(const char *catalogEntry) +BAppFileInfo::SetCatalogEntry(const char* catalogEntry) { if (InitCheck() != B_OK) return B_NO_INIT; @@ -400,7 +429,7 @@ BAppFileInfo::SetCatalogEntry(const char *catalogEntry) - other error codes */ status_t -BAppFileInfo::GetAppFlags(uint32 *flags) const +BAppFileInfo::GetAppFlags(uint32* flags) const { // check param and initialization status_t error = (flags ? B_OK : B_BAD_VALUE); @@ -419,6 +448,7 @@ BAppFileInfo::GetAppFlags(uint32 *flags) const return error; } + // SetAppFlags /*! \brief Sets the file's application flags. \param flags The application flags to be assigned to the file. @@ -436,14 +466,35 @@ BAppFileInfo::SetAppFlags(uint32 flags) error = B_NO_INIT; if (error == B_OK) { // write the data - if (error == B_OK) { - error = _WriteData(kAppFlagsAttribute, kAppFlagsResourceID, - B_APP_FLAGS_TYPE, &flags, sizeof(uint32)); - } + error = _WriteData(kAppFlagsAttribute, kAppFlagsResourceID, + B_APP_FLAGS_TYPE, &flags, sizeof(uint32)); } return error; } + +// RemoveAppFlags +/*! \brief Removes the file's application flags. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - other error codes +*/ +status_t +BAppFileInfo::RemoveAppFlags() +{ + // check initialization + status_t error = B_OK; + if (error == B_OK && InitCheck() != B_OK) + error = B_NO_INIT; + if (error == B_OK) { + // remove the data + error = _RemoveData(kAppFlagsAttribute, B_APP_FLAGS_TYPE); + } + return error; +} + + // GetSupportedTypes /*! \brief Gets the MIME types supported by the application. @@ -462,7 +513,7 @@ BAppFileInfo::SetAppFlags(uint32 flags) - other error codes */ status_t -BAppFileInfo::GetSupportedTypes(BMessage *types) const +BAppFileInfo::GetSupportedTypes(BMessage* types) const { // check param and initialization status_t error = (types ? B_OK : B_BAD_VALUE); @@ -479,11 +530,11 @@ BAppFileInfo::GetSupportedTypes(BMessage *types) const if (error == B_OK) error = types->Unflatten((const char*)buffer); // clean up - if (buffer) - free(buffer); + free(buffer); return error; } + // SetSupportedTypes /*! \brief Sets the MIME types supported by the application. @@ -511,7 +562,7 @@ BAppFileInfo::GetSupportedTypes(BMessage *types) const - other error codes */ status_t -BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll) +BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll) { // check initialization status_t error = B_OK; @@ -524,7 +575,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll) error = B_OK; if (types) { // check param -- supported types must be valid - const char *type; + const char* type; for (int32 i = 0; error == B_OK && types->FindString("types", i, &type) == B_OK; i++) { @@ -539,7 +590,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll) error = size; } // allocate a buffer for the flattened data - char *buffer = NULL; + char* buffer = NULL; if (error == B_OK) { buffer = new(nothrow) char[size]; if (!buffer) @@ -555,17 +606,17 @@ BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll) buffer, size); } // clean up - if (buffer) - delete[] buffer; + delete[] buffer; } else error = _RemoveData(kSupportedTypesAttribute, B_MESSAGE_TYPE); // update the MIME database, if the app signature is installed -// if (error == B_OK && mimeType.IsInstalled()) -// error = mimeType.SetSupportedTypes(types, syncAll); +// if (error == B_OK && mimeType.IsInstalled()) +// error = mimeType.SetSupportedTypes(types, syncAll); } return error; } + // SetSupportedTypes /*! \brief Sets the MIME types supported by the application. @@ -580,11 +631,12 @@ BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll) - other error codes */ status_t -BAppFileInfo::SetSupportedTypes(const BMessage *types) +BAppFileInfo::SetSupportedTypes(const BMessage* types) { return SetSupportedTypes(types, false); } + // IsSupportedType /*! \brief Returns whether the application supports the supplied MIME type. @@ -596,7 +648,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage *types) the application, \c false otherwise. */ bool -BAppFileInfo::IsSupportedType(const char *type) const +BAppFileInfo::IsSupportedType(const char* type) const { status_t error = (type ? B_OK : B_BAD_VALUE); // get the supported types @@ -610,7 +662,7 @@ BAppFileInfo::IsSupportedType(const char *type) const // iterate through the supported types bool found = false; if (error == B_OK) { - const char *supportedType; + const char* supportedType; for (int32 i = 0; !found && types.FindString("types", i, &supportedType) == B_OK; i++) { @@ -621,6 +673,7 @@ BAppFileInfo::IsSupportedType(const char *type) const return found; } + // Supports /*! \brief Returns whether the application supports the supplied MIME type explicitly. @@ -634,7 +687,7 @@ BAppFileInfo::IsSupportedType(const char *type) const supported by the application, \c false otherwise. */ bool -BAppFileInfo::Supports(BMimeType *type) const +BAppFileInfo::Supports(BMimeType* type) const { status_t error = (type && type->InitCheck() == B_OK ? B_OK : B_BAD_VALUE); // get the supported types @@ -644,7 +697,7 @@ BAppFileInfo::Supports(BMimeType *type) const // iterate through the supported types bool found = false; if (error == B_OK) { - const char *supportedType; + const char* supportedType; for (int32 i = 0; !found && types.FindString("types", i, &supportedType) == B_OK; i++) { @@ -654,6 +707,7 @@ BAppFileInfo::Supports(BMimeType *type) const return found; } + // GetIcon /*! \brief Gets the file's icon. \param icon A pointer to a pre-allocated BBitmap of the correct dimension @@ -669,11 +723,29 @@ BAppFileInfo::Supports(BMimeType *type) const - other error codes */ status_t -BAppFileInfo::GetIcon(BBitmap *icon, icon_size which) const +BAppFileInfo::GetIcon(BBitmap* icon, icon_size which) const { return GetIconForType(NULL, icon, which); } + +// GetIcon +/*! \brief Gets the file's icon. + \param data The pointer in which the flat icon data will be returned. + \param size The pointer in which the size of the data found will be returned. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - \c B_BAD_VALUE: \c NULL \a data or \c NULL size. + - other error codes +*/ +status_t +BAppFileInfo::GetIcon(uint8** data, size_t* size) const +{ + return GetIconForType(NULL, data, size); +} + + // SetIcon /*! \brief Sets the file's icon. @@ -691,11 +763,33 @@ BAppFileInfo::GetIcon(BBitmap *icon, icon_size which) const - other error codes */ status_t -BAppFileInfo::SetIcon(const BBitmap *icon, icon_size which) +BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which) { return SetIconForType(NULL, icon, which); } + +// SetIcon +/*! \brief Sets the file's icon. + + If \a icon is \c NULL the file's icon is unset. + + \param data A pointer to the data buffer containing the vector icon + to be set. May be \c NULL. + \param size Specifies the size of buffer pointed to by \a data. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - \c B_BAD_VALUE: \c NULL data. + - other error codes +*/ +status_t +BAppFileInfo::SetIcon(const uint8* data, size_t size) +{ + return SetIconForType(NULL, data, size); +} + + // GetVersionInfo /*! \brief Gets the file's version info. \param info A pointer to a pre-allocated version_info structure into which @@ -711,7 +805,7 @@ BAppFileInfo::SetIcon(const BBitmap *icon, icon_size which) - other error codes */ status_t -BAppFileInfo::GetVersionInfo(version_info *info, version_kind kind) const +BAppFileInfo::GetVersionInfo(version_info* info, version_kind kind) const { // check params and initialization if (!info) @@ -752,10 +846,11 @@ BAppFileInfo::GetVersionInfo(version_info *info, version_kind kind) const } else return B_ERROR; - // return result + // return result return B_OK; } + // SetVersionInfo /*! \brief Sets the file's version info. @@ -772,7 +867,7 @@ BAppFileInfo::GetVersionInfo(version_info *info, version_kind kind) const - other error codes */ status_t -BAppFileInfo::SetVersionInfo(const version_info *info, version_kind kind) +BAppFileInfo::SetVersionInfo(const version_info* info, version_kind kind) { // check initialization status_t error = B_OK; @@ -824,6 +919,7 @@ BAppFileInfo::SetVersionInfo(const version_info *info, version_kind kind) return error; } + // GetIconForType /*! \brief Gets the icon the application provides for a given MIME type. @@ -844,16 +940,61 @@ BAppFileInfo::SetVersionInfo(const version_info *info, version_kind kind) - other error codes */ status_t -BAppFileInfo::GetIconForType(const char *type, BBitmap *icon, - icon_size which) const +BAppFileInfo::GetIconForType(const char* type, BBitmap* icon, + icon_size size) const { - status_t error = B_OK; + if (InitCheck() != B_OK) + return B_NO_INIT; + + if (!icon || icon->InitCheck() != B_OK) + return B_BAD_VALUE; + + // TODO: for consistency with attribute based icon reading, we + // could also prefer B_CMAP8 icons here if the provided bitmap + // is in that format. Right now, an existing B_CMAP8 icon resource + // would be ignored as soon as a vector icon is present. On the other + // hand, maybe this still results in a more consistent user interface, + // since Tracker/Deskbar would surely show the vector icon. + + // try vector icon first + BString vectorAttributeName(kIconAttribute); + + // check type param + if (type) { + if (BMimeType::IsValid(type)) + vectorAttributeName += type; + else + return B_BAD_VALUE; + } else { + vectorAttributeName += kIconType; + } + const char* attribute = vectorAttributeName.String(); + + size_t bytesRead; + void* allocatedBuffer; + status_t error = _ReadData(attribute, -1, B_VECTOR_ICON_TYPE, NULL, 0, + bytesRead, &allocatedBuffer); + if (error == B_OK) { + error = BIconUtils::GetVectorIcon((uint8*)allocatedBuffer, + bytesRead, icon); + free(allocatedBuffer); + return error; + } + + // no vector icon if we got this far, + // align size argument just in case + if (size < B_LARGE_ICON) + size = B_MINI_ICON; + else + size = B_LARGE_ICON; + + error = B_OK; // set some icon size related variables BString attributeString; BRect bounds; uint32 attrType = 0; size_t attrSize = 0; - switch (which) { + switch (size) { case B_MINI_ICON: attributeString = kMiniIconAttribute; bounds.Set(0, 0, 15, 15); @@ -867,39 +1008,36 @@ BAppFileInfo::GetIconForType(const char *type, BBitmap *icon, attrSize = 32 * 32; break; default: - error = B_BAD_VALUE; - break; + return B_BAD_VALUE; } // check type param - if (error == B_OK) { - if (type) { - if (BMimeType::IsValid(type)) - attributeString += type; - else - error = B_BAD_VALUE; - } else - attributeString += kStandardIconType; - } - const char *attribute = attributeString.String(); + if (type) { + if (BMimeType::IsValid(type)) + attributeString += type; + else + return B_BAD_VALUE; + } else + attributeString += kStandardIconType; + + attribute = attributeString.String(); + + // check parameters + // currently, scaling B_CMAP8 icons is not supported + if (icon->ColorSpace() == B_CMAP8 && icon->Bounds() != bounds) + return B_BAD_VALUE; - // check parameter and initialization - if (error == B_OK - && (!icon || icon->InitCheck() != B_OK || icon->Bounds() != bounds)) { - error = B_BAD_VALUE; - } - if (error == B_OK && InitCheck() != B_OK) - error = B_NO_INIT; // read the data if (error == B_OK) { - bool otherColorSpace = (icon->ColorSpace() != B_CMAP8); - char *buffer = NULL; + bool tempBuffer = (icon->ColorSpace() != B_CMAP8 + || icon->Bounds() != bounds); + uint8* buffer = NULL; size_t read; - if (otherColorSpace) { - // other color space than stored in attribute - buffer = new(nothrow) char[attrSize]; - if (!buffer) + if (tempBuffer) { + // other color space or bitmap size than stored in attribute + buffer = new(nothrow) uint8[attrSize]; + if (!buffer) { error = B_NO_MEMORY; - if (error == B_OK) { + } else { error = _ReadData(attribute, -1, attrType, buffer, attrSize, read); } @@ -909,11 +1047,14 @@ BAppFileInfo::GetIconForType(const char *type, BBitmap *icon, } if (error == B_OK && read != attrSize) error = B_ERROR; - if (otherColorSpace) { + if (tempBuffer) { // other color space than stored in attribute if (error == B_OK) { - error = icon->ImportBits(buffer, attrSize, B_ANY_BYTES_PER_ROW, - 0, B_CMAP8); + error = BIconUtils::ConvertFromCMAP8(buffer, + (uint32)size, + (uint32)size, + (uint32)size, + icon); } delete[] buffer; } @@ -921,6 +1062,58 @@ BAppFileInfo::GetIconForType(const char *type, BBitmap *icon, return error; } + +// GetIconForType +/*! \brief Gets the icon the application provides for a given MIME type. + + If \a type is \c NULL, the application's icon is retrieved. + + \param type The MIME type in question. May be \c NULL. + \param data A pointer in which the icon data will be returned. When you + are done with the data, you should use free() to deallocate it. + \param size A pointer in which the size of the retrieved data is returned. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - \c B_BAD_VALUE: \c NULL \a data and/or \a size. Or the supplied + \a type is not a valid MIME type. + - other error codes +*/ +status_t +BAppFileInfo::GetIconForType(const char* type, uint8** data, + size_t* size) const +{ + if (InitCheck() != B_OK) + return B_NO_INIT; + + if (!data || !size) + return B_BAD_VALUE; + + // get vector icon + BString attributeName(kIconAttribute); + + // check type param + if (type) { + if (BMimeType::IsValid(type)) + attributeName += type; + else + return B_BAD_VALUE; + } else { + attributeName += kIconType; + } + + void* allocatedBuffer = NULL; + status_t ret = _ReadData(attributeName.String(), -1, + B_VECTOR_ICON_TYPE, NULL, 0, *size, &allocatedBuffer); + + if (ret < B_OK) + return ret; + + *data = (uint8*)allocatedBuffer; + return B_OK; +} + + // SetIconForType /*! \brief Sets the icon the application provides for a given MIME type. @@ -939,12 +1132,13 @@ BAppFileInfo::GetIconForType(const char *type, BBitmap *icon, \return - \c B_OK: Everything went fine. - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: Unknown icon size \a which or bitmap dimensions (\a icon) - and icon size (\a which) do not match. + - \c B_BAD_VALUE: Either the icon size \a which is unkown, bitmap dimensions (\a icon) + and icon size (\a which) do not match, or the provided \a type is + not a valid MIME type. - other error codes */ status_t -BAppFileInfo::SetIconForType(const char *type, const BBitmap *icon, +BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon, icon_size which) { status_t error = B_OK; @@ -985,7 +1179,7 @@ BAppFileInfo::SetIconForType(const char *type, const BBitmap *icon, } else attributeString += kStandardIconType; } - const char *attribute = attributeString.String(); + const char* attribute = attributeString.String(); // check parameter and initialization if (error == B_OK && icon && (icon->InitCheck() != B_OK || icon->Bounds() != bounds)) { @@ -1014,16 +1208,79 @@ BAppFileInfo::SetIconForType(const char *type, const BBitmap *icon, error = _RemoveData(attribute, attrType); } // set the attribute on the MIME type, if the file has a signature - BMimeType mimeType; - if (error == B_OK && GetMetaMime(&mimeType) == B_OK) { +// BMimeType mimeType; +// if (error == B_OK && GetMetaMime(&mimeType) == B_OK) { // if (!mimeType.IsInstalled()) // error = mimeType.Install(); // if (error == B_OK) // error = mimeType.SetIconForType(type, icon, which); - } +// } return error; } + +// SetIconForType +/*! \brief Sets the icon the application provides for a given MIME type. + + If \a type is \c NULL, the application's icon is set. + If \a data is \c NULL the icon is unset. + + If the file has a signature, then the icon is also set on the MIME type. + If the type for the signature has not been installed yet, it is installed + before. + + \param type The MIME type in question. May be \c NULL. + \param data A pointer to the data containing the icon to be set. + May be \c NULL. + \param size Specifies the size of buffer provided in \a data. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - \c B_BAD_VALUE: The provided \a type is not a valid MIME type. + - other error codes +*/ +status_t +BAppFileInfo::SetIconForType(const char* type, const uint8* data, + size_t size) +{ + if (InitCheck() != B_OK) + return B_NO_INIT; + + // set some icon related variables + BString attributeString = kIconAttribute; + int32 resourceID = type ? kIconForTypeResourceID : kIconResourceID; + uint32 attrType = B_VECTOR_ICON_TYPE; + + // check type param + if (type) { + if (BMimeType::IsValid(type)) + attributeString += type; + else + return B_BAD_VALUE; + } else + attributeString += kIconType; + + const char* attribute = attributeString.String(); + + status_t error; + // write/remove the attribute + if (data) + error = _WriteData(attribute, resourceID, attrType, data, size, true); + else // no icon given => remove + error = _RemoveData(attribute, attrType); + + // set the attribute on the MIME type, if the file has a signature +// BMimeType mimeType; +// if (error == B_OK && GetMetaMime(&mimeType) == B_OK) { +// if (!mimeType.IsInstalled()) +// error = mimeType.Install(); +// if (error == B_OK) +// error = mimeType.SetIconForType(type, data, size); +// } + return error; +} + + // SetInfoLocation /*! \brief Specifies the location where the meta data shall be stored. @@ -1037,6 +1294,10 @@ BAppFileInfo::SetIconForType(const char *type, const BBitmap *icon, void BAppFileInfo::SetInfoLocation(info_location location) { + // if the resources failed to initialize, we must not use them + if (fResources == NULL) + location = info_location(location & ~B_USE_RESOURCES); + fWhere = location; } @@ -1049,9 +1310,10 @@ BAppFileInfo::SetInfoLocation(info_location location) bool BAppFileInfo::IsUsingAttributes() const { - return (fWhere & B_USE_ATTRIBUTES); + return (fWhere & B_USE_ATTRIBUTES) != 0; } + // IsUsingResources /*! \brief Returns whether the object stores the meta data (also) in the file's resources. @@ -1061,14 +1323,16 @@ BAppFileInfo::IsUsingAttributes() const bool BAppFileInfo::IsUsingResources() const { - return (fWhere & B_USE_RESOURCES); + return (fWhere & B_USE_RESOURCES) != 0; } + // FBC void BAppFileInfo::_ReservedAppFileInfo1() {} void BAppFileInfo::_ReservedAppFileInfo2() {} void BAppFileInfo::_ReservedAppFileInfo3() {} + // = /*! \brief Privatized assignment operator to prevent usage. */ @@ -1078,6 +1342,7 @@ BAppFileInfo::operator=(const BAppFileInfo &) return *this; } + // copy constructor /*! \brief Privatized copy constructor to prevent usage. */ @@ -1085,6 +1350,7 @@ BAppFileInfo::BAppFileInfo(const BAppFileInfo &) { } + // GetMetaMime /*! \brief Initializes a BMimeType to the file's signature. @@ -1101,7 +1367,7 @@ BAppFileInfo::BAppFileInfo(const BAppFileInfo &) - other error codes */ status_t -BAppFileInfo::GetMetaMime(BMimeType *meta) const +BAppFileInfo::GetMetaMime(BMimeType* meta) const { char signature[B_MIME_TYPE_LENGTH]; status_t error = GetSignature(signature); @@ -1114,6 +1380,7 @@ BAppFileInfo::GetMetaMime(BMimeType *meta) const return error; } + // _ReadData /*! \brief Reads data from an attribute or resource. @@ -1137,12 +1404,12 @@ BAppFileInfo::GetMetaMime(BMimeType *meta) const - error code */ status_t -BAppFileInfo::_ReadData(const char *name, int32 id, type_code type, - void *buffer, size_t bufferSize, - size_t &bytesRead, void **allocatedBuffer) const +BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, + void* buffer, size_t bufferSize, + size_t &bytesRead, void** allocatedBuffer) const { status_t error = B_OK; - + if (allocatedBuffer) buffer = NULL; @@ -1209,7 +1476,7 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type, error = B_BAD_VALUE; // load resource - const void *resourceData = NULL; + const void* resourceData = NULL; if (error == B_OK) { resourceData = fResources->LoadResource(type, name, &bytesRead); if (resourceData && sizeFound == bytesRead) @@ -1217,7 +1484,6 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type, else error = B_ERROR; } - } else if (!foundData) error = B_BAD_VALUE; @@ -1232,6 +1498,7 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type, return error; } + // _WriteData /*! \brief Writes data to an attribute or resource. @@ -1253,12 +1520,16 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type, - error code */ status_t -BAppFileInfo::_WriteData(const char *name, int32 id, type_code type, - const void *buffer, size_t bufferSize, bool findID) +BAppFileInfo::_WriteData(const char* name, int32 id, type_code type, + const void* buffer, size_t bufferSize, bool findID) { + if (!IsUsingAttributes() && !IsUsingResources()) + return B_NO_INIT; + status_t error = B_OK; + // write to attribute - if (IsUsingAttributes() && error == B_OK) { + if (IsUsingAttributes()) { ssize_t written = fNode->WriteAttr(name, type, 0, buffer, bufferSize); if (written < 0) error = written; @@ -1298,11 +1569,15 @@ BAppFileInfo::_WriteData(const char *name, int32 id, type_code type, - error code */ status_t -BAppFileInfo::_RemoveData(const char *name, type_code type) +BAppFileInfo::_RemoveData(const char* name, type_code type) { + if (!IsUsingAttributes() && !IsUsingResources()) + return B_NO_INIT; + status_t error = B_OK; + // remove the attribute - if (IsUsingAttributes() && error == B_OK) { + if (IsUsingAttributes()) { error = fNode->RemoveAttr(name); // It's no error, if there has been no attribute. if (error == B_ENTRY_NOT_FOUND) diff --git a/src/build/libbe/storage/Entry.cpp b/src/build/libbe/storage/Entry.cpp index 6c744b6feb..2f6accfdaa 100644 --- a/src/build/libbe/storage/Entry.cpp +++ b/src/build/libbe/storage/Entry.cpp @@ -352,6 +352,16 @@ BEntry::Exists() const } +const char* +BEntry::Name() const +{ + if (fCStatus != B_OK) + return NULL; + + return fName; +} + + /*! \brief Fills in a stat structure for the entry. The information is copied into the \c stat structure pointed to by \a result. diff --git a/src/build/libbe/storage/Jamfile b/src/build/libbe/storage/Jamfile index cb2b27c53e..69f1a99092 100644 --- a/src/build/libbe/storage/Jamfile +++ b/src/build/libbe/storage/Jamfile @@ -6,6 +6,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) mime ] ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits storage ] ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits storage mime ] ; +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits storage sniffer ] ; USES_BE_API on storage_kit.o = true ; @@ -17,6 +18,7 @@ BuildPlatformMergeObjectPIC storage_kit.o : File.cpp FileIO.cpp FindDirectory.cpp + MergedDirectory.cpp Mime.cpp MimeType.cpp Node.cpp @@ -33,7 +35,31 @@ BuildPlatformMergeObjectPIC storage_kit.o : Volume.cpp storage_support.cpp + # mime + AppMetaMimeCreator.cpp + AssociatedTypes.cpp + Database.cpp + DatabaseDirectory.cpp + DatabaseLocation.cpp database_support.cpp + InstalledTypes.cpp + MimeSniffer.cpp + SnifferRules.cpp + Supertype.cpp + SupportingApps.cpp + MimeUpdateThread.cpp UpdateMimeInfoThread.cpp + + # sniffer + CharStream.cpp + Err.cpp + DisjList.cpp + Pattern.cpp + PatternList.cpp + Parser.cpp + Range.cpp + RPattern.cpp + RPatternList.cpp + Rule.cpp ; diff --git a/src/build/libbe/storage/MergedDirectory.cpp b/src/build/libbe/storage/MergedDirectory.cpp new file mode 100644 index 0000000000..cbbbaad0dd --- /dev/null +++ b/src/build/libbe/storage/MergedDirectory.cpp @@ -0,0 +1,240 @@ +/* + * Copyright 2013, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ingo Weinhold + */ + + +#include + +#include +#include +#include + +#include +#include + +#include + +#include "storage_support.h" + + +struct BMergedDirectory::EntryNameSet : std::set { +}; + + +BMergedDirectory::BMergedDirectory(BPolicy policy) + : + BEntryList(), + fDirectories(10, true), + fPolicy(policy), + fDirectoryIndex(0), + fVisitedEntries(NULL) +{ +} + + +BMergedDirectory::~BMergedDirectory() +{ + delete fVisitedEntries; +} + + +status_t +BMergedDirectory::Init() +{ + delete fVisitedEntries; + fDirectories.MakeEmpty(true); + + fVisitedEntries = new(std::nothrow) EntryNameSet; + return fVisitedEntries != NULL ? B_OK : B_NO_MEMORY; +} + + +BMergedDirectory::BPolicy +BMergedDirectory::Policy() const +{ + return fPolicy; +} + + +void +BMergedDirectory::SetPolicy(BPolicy policy) +{ + fPolicy = policy; +} + + +status_t +BMergedDirectory::AddDirectory(BDirectory* directory) +{ + return fDirectories.AddItem(directory) ? B_OK : B_NO_MEMORY; +} + + +status_t +BMergedDirectory::AddDirectory(const char* path) +{ + BDirectory* directory = new(std::nothrow) BDirectory(path); + if (directory == NULL) + return B_NO_MEMORY; + ObjectDeleter directoryDeleter(directory); + + if (directory->InitCheck() != B_OK) + return directory->InitCheck(); + + status_t error = AddDirectory(directory); + if (error != B_OK) + return error; + directoryDeleter.Detach(); + + return B_OK; +} + + +status_t +BMergedDirectory::GetNextEntry(BEntry* entry, bool traverse) +{ + entry_ref ref; + status_t error = GetNextRef(&ref); + if (error != B_OK) + return error; + + return entry->SetTo(&ref, traverse); +} + + +status_t +BMergedDirectory::GetNextRef(entry_ref* ref) +{ + BPrivate::Storage::LongDirEntry dirEntry; + int32 result = GetNextDirents(&dirEntry, sizeof(dirEntry), 1); + if (result < 0) + return result; + if (result == 0) + return B_ENTRY_NOT_FOUND; + + BEntry entry; + status_t error + = entry.SetTo(fDirectories.ItemAt(fDirectoryIndex), dirEntry.d_name); + if (error != B_OK) + return error; + + return entry.GetRef(ref); +} + + +int32 +BMergedDirectory::GetNextDirents(struct dirent* direntBuffer, size_t bufferSize, + int32 maxEntries) +{ + if (maxEntries <= 0) + return B_BAD_VALUE; + + while (fDirectoryIndex < fDirectories.CountItems()) { + int32 count = fDirectories.ItemAt(fDirectoryIndex)->GetNextDirents( + direntBuffer, bufferSize, 1); + if (count < 0) + return count; + if (count == 0) { + fDirectoryIndex++; + continue; + } + + if (strcmp(direntBuffer->d_name, ".") == 0 + || strcmp(direntBuffer->d_name, "..") == 0) { + continue; + } + + switch (fPolicy) { + case B_ALLOW_DUPLICATES: + return count; + + case B_ALWAYS_FIRST: + case B_COMPARE: + if (fVisitedEntries != NULL + && fVisitedEntries->find(direntBuffer->d_name) + != fVisitedEntries->end()) { + continue; + } + + if (fVisitedEntries != NULL) { + try { + fVisitedEntries->insert(direntBuffer->d_name); + } catch (std::bad_alloc&) { + return B_NO_MEMORY; + } + } + + if (fPolicy == B_ALWAYS_FIRST + || _IsBestEntry(direntBuffer->d_name)) { + return 1; + } + + fVisitedEntries->erase(direntBuffer->d_name); + break; + } + } + + return B_ENTRY_NOT_FOUND; +} + + +status_t +BMergedDirectory::Rewind() +{ + for (int32 i = 0; BDirectory* directory = fDirectories.ItemAt(i); i++) + directory->Rewind(); + + if (fVisitedEntries != NULL) + fVisitedEntries->clear(); + + fDirectoryIndex = 0; + return B_OK; +} + + +int32 +BMergedDirectory::CountEntries() +{ + int32 count = 0; + char buffer[sizeof(dirent) + B_FILE_NAME_LENGTH]; + while (GetNextDirents((dirent*)&buffer, sizeof(buffer), 1) == 1) + count++; + return count; +} + + +bool +BMergedDirectory::ShallPreferFirstEntry(const entry_ref& entry1, int32 index1, + const entry_ref& entry2, int32 index2) +{ + // That's basically B_ALWAYS_FIRST semantics. A derived class will implement + // the desired semantics. + return true; +} + + +bool +BMergedDirectory::_IsBestEntry(const char* name) +{ + entry_ref bestEntry; + if (BEntry(fDirectories.ItemAt(fDirectoryIndex), name).GetRef(&bestEntry) + != B_OK) { + return false; + } + + int32 directoryCount = fDirectories.CountItems(); + for (int32 i = fDirectoryIndex + 1; i < directoryCount; i++) { + BEntry entry(fDirectories.ItemAt(i), name); + entry_ref ref; + if (entry.Exists() && entry.GetRef(&ref) == B_OK + && !ShallPreferFirstEntry(bestEntry, fDirectoryIndex, ref, i)) { + return false; + } + } + + return true; +} diff --git a/src/build/libbe/storage/Mime.cpp b/src/build/libbe/storage/Mime.cpp index 9515e8f414..1c899a8e78 100644 --- a/src/build/libbe/storage/Mime.cpp +++ b/src/build/libbe/storage/Mime.cpp @@ -12,7 +12,8 @@ Mime type C functions implementation. */ -#include +#include + #include using namespace BPrivate; diff --git a/src/build/libbe/storage/mime/database_support.cpp b/src/build/libbe/storage/mime/database_support.cpp deleted file mode 100644 index 9282991957..0000000000 --- a/src/build/libbe/storage/mime/database_support.cpp +++ /dev/null @@ -1,378 +0,0 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- -/*! - \file database_support.cpp - Private mime database functions and constants -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include // For struct attr_info -#include // For new(nothrow) -#include -#include - -#include "mime/database_support.h" - -//#define DBG(x) x -#define DBG(x) -#define OUT printf - -namespace BPrivate { -namespace Storage { -namespace Mime { - -#if 0 - -static const char *get_user_settings_dir(BPath &path); - -static BPath sSettingsDirPath; -static const std::string sSettingsDir = get_user_settings_dir(sSettingsDirPath); - -static const char *sHaikuDBDirName = "beos_mime"; - // when running natively under Haiku -static const char *sBeOSDBDirName = "obos_mime"; - // when running under BeOS -const std::string kDatabaseDir = sSettingsDir + "/" - + (is_running_on_haiku() ? sHaikuDBDirName : sBeOSDBDirName); -const std::string kApplicationDatabaseDir = kDatabaseDir + "/application"; - -#endif // 0 - -#define ATTR_PREFIX "META:" -#define MINI_ICON_ATTR_PREFIX ATTR_PREFIX "M:" -#define LARGE_ICON_ATTR_PREFIX ATTR_PREFIX "L:" - -const char *kMiniIconAttrPrefix = MINI_ICON_ATTR_PREFIX; -const char *kLargeIconAttrPrefix = LARGE_ICON_ATTR_PREFIX; - -// attribute names -const char *kFileTypeAttr = "BEOS:TYPE"; -const char *kTypeAttr = ATTR_PREFIX "TYPE"; -const char *kAppHintAttr = ATTR_PREFIX "PPATH"; -const char *kAttrInfoAttr = ATTR_PREFIX "ATTR_INFO"; -const char *kShortDescriptionAttr = ATTR_PREFIX "S:DESC"; -const char *kLongDescriptionAttr = ATTR_PREFIX "L:DESC"; -const char *kFileExtensionsAttr = ATTR_PREFIX "EXTENS"; -const char *kMiniIconAttr = MINI_ICON_ATTR_PREFIX "STD_ICON"; -const char *kLargeIconAttr = LARGE_ICON_ATTR_PREFIX "STD_ICON"; -const char *kPreferredAppAttr = ATTR_PREFIX "PREF_APP"; -const char *kSnifferRuleAttr = ATTR_PREFIX "SNIFF_RULE"; -const char *kSupportedTypesAttr = ATTR_PREFIX "FILE_TYPES"; - -// attribute data types (as used in the R5 database) -const int32 kFileTypeType = 'MIMS'; // B_MIME_STRING_TYPE -const int32 kTypeType = B_STRING_TYPE; -const int32 kAppHintType = 'MPTH'; -const int32 kAttrInfoType = B_MESSAGE_TYPE; -const int32 kShortDescriptionType = 'MSDC'; -const int32 kLongDescriptionType = 'MLDC'; -const int32 kFileExtensionsType = B_MESSAGE_TYPE; -const int32 kMiniIconType = B_MINI_ICON_TYPE; -const int32 kLargeIconType = B_LARGE_ICON_TYPE; -const int32 kPreferredAppType = 'MSIG'; -const int32 kSnifferRuleType = B_STRING_TYPE; -const int32 kSupportedTypesType = B_MESSAGE_TYPE; - -// Message fields -const char *kApplicationsField = "applications"; -const char *kExtensionsField = "extensions"; -const char *kSupertypesField = "super_types"; -const char *kSupportingAppsSubCountField = "be:sub"; -const char *kSupportingAppsSuperCountField = "be:super"; -const char *kTypesField = "types"; - -// Mime types -const char *kGenericFileType = "application/octet-stream"; -const char *kDirectoryType = "application/x-vnd.Be-directory"; -const char *kSymlinkType = "application/x-vnd.Be-symlink"; -const char *kMetaMimeType = "application/x-vnd.Be-meta-mime"; - -// Error codes -const status_t kMimeGuessFailureError = B_ERRORS_END+1; - -#if 0 - -// get_settings_dir -/*! \brief Sets the supplied BPath to the user settings directory and returns - it as C string. - \param path BPath to be set to the user settings path. - \return the user settings path as C string (\code path.Path() \endcode). -*/ -static -const char* -get_user_settings_dir(BPath &path) -{ - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) - path.SetTo("/boot/home/config/settings"); - return path.Path(); -} - -// type_to_filename -//! Converts the given MIME type to an absolute path in the MIME database. -std::string -type_to_filename(const char *type) -{ - return kDatabaseDir + "/" + BPrivate::Storage::to_lower(type); -} - -// open_type -/*! \brief Opens a BNode on the given type, failing if the type has no - corresponding file in the database. - \param type The MIME type to open - \param result Pointer to a pre-allocated BNode into which - is opened on the given MIME type -*/ -status_t -open_type(const char *type, BNode *result) -{ - status_t err = (type && result ? B_OK : B_BAD_VALUE); - if (!err) - err = result->SetTo(type_to_filename(type).c_str()); - return err; -} - -// open_or_create_type -/*! \brief Opens a BNode on the given type, creating a node of the - appropriate flavor if necessary. - - All MIME types are converted to lowercase for use in the filesystem. - \param type The MIME type to open - \param result Pointer to a pre-allocated BNode into which - is opened on the given MIME type -*/ -status_t -open_or_create_type(const char *type, BNode *result, bool *didCreate) -{ - if (didCreate) - *didCreate = false; - std::string filename; - std::string typeLower = BPrivate::Storage::to_lower(type); - status_t err = (type && result ? B_OK : B_BAD_VALUE); - if (!err) { - filename = type_to_filename(type); - err = result->SetTo(filename.c_str()); - } - if (err == B_ENTRY_NOT_FOUND) { - // Figure out what type of node we need to create - // + Supertype == directory - // + Non-supertype == file - uint32 pos = typeLower.find_first_of('/'); - if (pos == std::string::npos) { - // Supertype == directory - BDirectory parent(kDatabaseDir.c_str()); - err = parent.InitCheck(); - if (!err) - err = parent.CreateDirectory(typeLower.c_str(), NULL); - } else { - // Non-supertype == file - std::string super(typeLower, 0, pos); - std::string sub(typeLower, pos+1); - BDirectory parent((kDatabaseDir + "/" + super).c_str()); - err = parent.InitCheck(); - if (!err) - err = parent.CreateFile(sub.c_str(), NULL); - } - // Now try opening again - err = result->SetTo(filename.c_str()); - if (!err && didCreate) - *didCreate = true; - } - return err; -} - -// read_mime_attr -/*! \brief Reads up to \c len bytes of the given data from the given attribute - for the given MIME type. - - If no entry for the given type exists in the database, the function fails, - and the contents of \c data are undefined. - - \param type The MIME type - \param attr The attribute name - \param data Pointer to a memory buffer into which the data should be copied - \param len The maximum number of bytes to read - \param datatype The expected data type - \return If successful, the number of bytes read is returned, otherwise, an - error code is returned. -*/ -ssize_t -read_mime_attr(const char *type, const char *attr, void *data, - size_t len, type_code datatype) -{ - BNode node; - ssize_t err = (type && attr && data ? B_OK : B_BAD_VALUE); - if (!err) - err = open_type(type, &node); - if (!err) - err = node.ReadAttr(attr, datatype, 0, data, len); - return err; -} - -// read_mime_attr_message -/*! \brief Reads a flattened BMessage from the given attribute of the given - MIME type. - - If no entry for the given type exists in the database, or if the data - stored in the attribute is not a flattened BMessage, the function fails - and the contents of \c msg are undefined. - - \param type The MIME type - \param attr The attribute name - \param data Pointer to a pre-allocated BMessage into which the attribute - data is unflattened. -*/ -status_t -read_mime_attr_message(const char *type, const char *attr, BMessage *msg) -{ - BNode node; - attr_info info; - char *buffer = NULL; - ssize_t err = (type && attr && msg ? B_OK : B_BAD_VALUE); - if (!err) - err = open_type(type, &node); - if (!err) - err = node.GetAttrInfo(attr, &info); - if (!err) - err = info.type == B_MESSAGE_TYPE ? B_OK : B_BAD_VALUE; - if (!err) { - buffer = new(std::nothrow) char[info.size]; - if (!buffer) - err = B_NO_MEMORY; - } - if (!err) - err = node.ReadAttr(attr, B_MESSAGE_TYPE, 0, buffer, info.size); - if (err >= 0) - err = err == info.size ? (status_t)B_OK : (status_t)B_FILE_ERROR; - if (!err) - err = msg->Unflatten(buffer); - delete [] buffer; - return err; -} - -// read_mime_attr_string -/*! \brief Reads a BString from the given attribute of the given - MIME type. - - If no entry for the given type exists in the database, the function fails - and the contents of \c str are undefined. - - \param type The MIME type - \param attr The attribute name - \param str Pointer to a pre-allocated BString into which the attribute - data stored. -*/ -status_t -read_mime_attr_string(const char *type, const char *attr, BString *str) -{ - BNode node; - status_t err = (type && attr && str ? B_OK : B_BAD_VALUE); - if (!err) - err = open_type(type, &node); - if (!err) - err = node.ReadAttrString(attr, str); - return err; -} - -// write_mime_attr -/*! \brief Writes \c len bytes of the given data to the given attribute - for the given MIME type. - - If no entry for the given type exists in the database, it is created. - - \param type The MIME type - \param attr The attribute name - \param data Pointer to the data to write - \param len The number of bytes to write - \param datatype The data type of the given data -*/ -status_t -write_mime_attr(const char *type, const char *attr, const void *data, - size_t len, type_code datatype, bool *didCreate) -{ - BNode node; - status_t err = (type && attr && data ? B_OK : B_BAD_VALUE); - if (!err) - err = open_or_create_type(type, &node, didCreate); - if (!err) { - ssize_t bytes = node.WriteAttr(attr, datatype, 0, data, len); - if (bytes < B_OK) - err = bytes; - else - err = (bytes != (ssize_t)len ? (status_t)B_FILE_ERROR : (status_t)B_OK); - } - return err; -} - -// write_mime_attr_message -/*! \brief Flattens the given \c BMessage and writes it to the given attribute - of the given MIME type. - - If no entry for the given type exists in the database, it is created. - - \param type The MIME type - \param attr The attribute name - \param msg The BMessage to flatten and write -*/ -status_t -write_mime_attr_message(const char *type, const char *attr, const BMessage *msg, bool *didCreate) -{ - BNode node; - BMallocIO data; - ssize_t bytes; - ssize_t err = (type && attr && msg ? B_OK : B_BAD_VALUE); - if (!err) - err = data.SetSize(msg->FlattenedSize()); - if (!err) - err = msg->Flatten(&data, &bytes); - if (!err) - err = bytes == msg->FlattenedSize() ? B_OK : B_ERROR; - if (!err) - err = open_or_create_type(type, &node, didCreate); - if (!err) - err = node.WriteAttr(attr, B_MESSAGE_TYPE, 0, data.Buffer(), data.BufferLength()); - if (err >= 0) - err = err == (ssize_t)data.BufferLength() ? (ssize_t)B_OK : (ssize_t)B_FILE_ERROR; - return err; -} - -// delete_attribute -//! Deletes the given attribute for the given type -/*! - \param type The mime type - \param attr The attribute name - \return - - B_OK: success - - B_ENTRY_NOT_FOUND: no such type or attribute - - "error code": failure -*/ -status_t -delete_attribute(const char *type, const char *attr) -{ - status_t err = type ? B_OK : B_BAD_VALUE; - BNode node; - if (!err) - err = open_type(type, &node); - if (!err) - err = node.RemoveAttr(attr); - return err; -} - -#endif // 0 - - -} // namespace Mime -} // namespace Storage -} // namespace BPrivate - diff --git a/src/build/libicon/Jamfile b/src/build/libicon/Jamfile new file mode 100644 index 0000000000..76797b9108 --- /dev/null +++ b/src/build/libicon/Jamfile @@ -0,0 +1,63 @@ +SubDir HAIKU_TOP src build libicon ; + +# source directories +local sourceDirs = + $(DOT) + flat_icon + message + shape + style + transformable + transformer +; + +local sourceDir ; +for sourceDir in $(sourceDirs) { + SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src libs icon $(sourceDir) ] ; +} + +# system headers +UseLibraryHeaders agg icon ; + +UsePrivateBuildHeaders shared ; + +USES_BE_API on libicon_build.a = true ; + +BuildPlatformStaticLibrary libicon_build.a : + # flat_icon + FlatIconFormat.cpp + FlatIconImporter.cpp + LittleEndianBuffer.cpp + PathCommandQueue.cpp + + # message + Defines.cpp + MessageImporter.cpp + + # shape + PathContainer.cpp + Shape.cpp + ShapeContainer.cpp + VectorPath.cpp + + # style + GradientTransformable.cpp + Style.cpp + StyleContainer.cpp + + # transformable + Transformable.cpp + + # transformer + AffineTransformer.cpp + ContourTransformer.cpp + PathSource.cpp + PerspectiveTransformer.cpp + StrokeTransformer.cpp + Transformer.cpp + TransformerFactory.cpp + + Icon.cpp + IconRenderer.cpp + IconUtils.cpp +; diff --git a/src/tools/Jamfile b/src/tools/Jamfile index 6c7fe4a175..8e9e08724a 100644 --- a/src/tools/Jamfile +++ b/src/tools/Jamfile @@ -61,10 +61,9 @@ if $(HOST_PLATFORM_BEOS_COMPATIBLE) { local mimesetSources = mimeset.cpp - Mime.cpp - database_support.cpp - UpdateMimeInfoThread.cpp - MimeUpdateThread.cpp +# Mime.cpp +# UpdateMimeInfoThread.cpp +# MimeUpdateThread.cpp ; if $(HOST_PLATFORM) = haiku_host {