hrev48695 adds 2 changesets to branch 'master' old head: 658f64c3f17d34e2cec57c47ad3f58c34ed40694 new head: 4bb4130ff2b8e2c9c93ef4ce2ee46d644a9bd5e9 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=4bb4130ff2b8+%5E658f64c3f17d ---------------------------------------------------------------------------- 412f030b0f95: Some clarifications to BInvoker docs. 4bb4130ff2b8: Fix instanciate_catalog prototype The prototype didn't match what the Locale Kit actually uses, making the plaintext catalog (and any other add-on) unusable. [ Adrien Destugues <pulkomandy@xxxxxxxxx> ] ---------------------------------------------------------------------------- 4 files changed, 64 insertions(+), 24 deletions(-) docs/user/app/Invoker.dox | 34 ++++++++++------ headers/os/locale/CatalogData.h | 4 +- headers/private/locale/PlainTextCatalog.h | 8 ++-- .../locale/catalogs/plaintext/Catalog.cpp | 42 +++++++++++++++++--- ############################################################################ Commit: 412f030b0f95e4d79cb88955e4b6c954d8db3cdd URL: http://cgit.haiku-os.org/haiku/commit/?id=412f030b0f95 Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Sat Jan 17 12:41:55 2015 UTC Some clarifications to BInvoker docs. ---------------------------------------------------------------------------- diff --git a/docs/user/app/Invoker.dox b/docs/user/app/Invoker.dox index ae82a18..3c5d2ca 100644 --- a/docs/user/app/Invoker.dox +++ b/docs/user/app/Invoker.dox @@ -103,10 +103,12 @@ You may pass \c NULL into \a message to delete the current message without replacing it. - When Invoke() is called, the message is sent to the designated BHandler - known as the "target". The message is sent as a BMessage. The message is - not copied, rather ownership of the BMessage object is transferred to - the invoker. + When Invoke() is called without a specific message, a copy of the + message given here is sent to the "target" BHandler. The message + is sent as a BMessage. + + BInvoker takes ownership of the BMessage object, so you must not delete + it yourself. \since BeOS R3 */ @@ -128,7 +130,7 @@ \brief Returns the message's \c what data member. \note If a message has not been assigned to the invoker this method - returns \c NULL instead. + returns \c 0 instead. \since BeOS R3 */ @@ -138,6 +140,9 @@ \fn status_t BInvoker::SetTarget(BMessenger messenger) \brief Sets the invoker's target to \a messenger. + A BMessenger target can be used to designate a remote handler (living + in another team). + \since BeOS R3 */ @@ -151,12 +156,10 @@ \note It is not necessary to specify both the \a handler and the \a looper, the unused parameter should be passed in as \c NULL. - If given a \a handler, it must be attached to a BLooper. The message - is always sent to a BLooper which distributes the message to the - correct handler (which might be the \a looper itself). + If given only a \a handler, it must already be attached to a BLooper. - The preferred handler, i.e. for a window, is the view that currently - has focus. + If given only a \a looper, the message will be sent to its preferred + handler (in the case of a BWindow that is the focused view). \since BeOS R3 */ @@ -220,8 +223,11 @@ \fn status_t BInvoker::Invoke(BMessage* message) \brief Sends the \a message to the invoker's target. - If \a message is \c NULL the message previously set on the invoker is sent - to the invoker's target instead. + If \a message is \c NULL the default message is sent instead. You can set + the default message using \a SetMessage or in the constructor. + + This method also sends a B_CONTROL_INVOKED notification to handlers + which registered themselves using StartWatching \since BeOS R3 */ @@ -236,7 +242,11 @@ of the invoker's handler will receive their expected notifications. By default, \a kind is \c B_CONTROL_INVOKED, the same as sent by Invoke(). + BInvoker does not send the notification itself, it is up to subclasses to + do that as needed. + \sa BLooper::StartWatching() + \sa BLooper::SendNotices() \sa BHandler::NoticeChange() \since BeOS R5 ############################################################################ Revision: hrev48695 Commit: 4bb4130ff2b8e2c9c93ef4ce2ee46d644a9bd5e9 URL: http://cgit.haiku-os.org/haiku/commit/?id=4bb4130ff2b8 Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Sat Jan 17 16:02:40 2015 UTC Fix instanciate_catalog prototype The prototype didn't match what the Locale Kit actually uses, making the plaintext catalog (and any other add-on) unusable. ---------------------------------------------------------------------------- diff --git a/headers/os/locale/CatalogData.h b/headers/os/locale/CatalogData.h index 5c6d91b..f371f87 100644 --- a/headers/os/locale/CatalogData.h +++ b/headers/os/locale/CatalogData.h @@ -99,8 +99,8 @@ BCatalogData::Next() // // 1. the function that instantiates a catalog for this add-on-type extern "C" -BCatalogData* instantiate_catalog(const char* signature, const char* language, - uint32 fingerprint); +BCatalogData* instantiate_catalog(const entry_ref& signature, + const char* language, uint32 fingerprint); // 2. the function that creates an empty catalog for this add-on-type extern "C" diff --git a/headers/private/locale/PlainTextCatalog.h b/headers/private/locale/PlainTextCatalog.h index b31031b..cbfcb8b 100644 --- a/headers/private/locale/PlainTextCatalog.h +++ b/headers/private/locale/PlainTextCatalog.h @@ -18,22 +18,22 @@ namespace BPrivate { class PlainTextCatalog : public HashMapCatalog { public: - PlainTextCatalog(const char *signature, const char *language, + PlainTextCatalog(const entry_ref& owner, const char *language, uint32 fingerprint); // constructor for normal use - PlainTextCatalog(entry_ref *appOrAddOnRef); - // constructor for embedded catalog PlainTextCatalog(const char *path, const char *signature, const char *language); // constructor for editor-app ~PlainTextCatalog(); + void SetSignature(const entry_ref &catalogOwner); + // implementation for editor-interface: status_t ReadFromFile(const char *path = NULL); status_t WriteToFile(const char *path = NULL); - static BCatalogData *Instantiate(const char *signature, + static BCatalogData *Instantiate(const entry_ref &signature, const char *language, uint32 fingerprint); static const char *kCatMimeType; diff --git a/src/add-ons/locale/catalogs/plaintext/Catalog.cpp b/src/add-ons/locale/catalogs/plaintext/Catalog.cpp index aefe570..d794595 100644 --- a/src/add-ons/locale/catalogs/plaintext/Catalog.cpp +++ b/src/add-ons/locale/catalogs/plaintext/Catalog.cpp @@ -14,6 +14,7 @@ #include <sstream> #include <string> +#include <AppFileInfo.h> #include <Application.h> #include <Directory.h> #include <File.h> @@ -74,11 +75,14 @@ escapeQuotedChars(BString& stringToEscape) * InitCheck() will be B_OK if catalog could be loaded successfully, it will * give an appropriate error-code otherwise. */ -PlainTextCatalog::PlainTextCatalog(const char *signature, const char *language, +PlainTextCatalog::PlainTextCatalog(const entry_ref &owner, const char *language, uint32 fingerprint) : - HashMapCatalog(signature, language, fingerprint) + HashMapCatalog("", language, fingerprint) { + // We created the catalog with an invalid signature, but we fix that now. + SetSignature(owner); + // give highest priority to catalog living in sub-folder of app's folder: app_info appInfo; be_app->GetAppInfo(&appInfo); @@ -146,6 +150,32 @@ PlainTextCatalog::~PlainTextCatalog() } +void +PlainTextCatalog::SetSignature(const entry_ref &catalogOwner) +{ + // figure out mimetype from image + BFile objectFile(&catalogOwner, B_READ_ONLY); + BAppFileInfo objectInfo(&objectFile); + char objectSignature[B_MIME_TYPE_LENGTH]; + if (objectInfo.GetSignature(objectSignature) != B_OK) { + fSignature = ""; + return; + } + + // drop supertype from mimetype (should be "application/"): + char* stripSignature = objectSignature; + while (*stripSignature != '/' && *stripSignature != '\0') + stripSignature ++; + + if (*stripSignature == '\0') + stripSignature = objectSignature; + else + stripSignature ++; + + fSignature = stripSignature; +} + + status_t PlainTextCatalog::ReadFromFile(const char *path) { @@ -353,11 +383,11 @@ PlainTextCatalog::UpdateAttributes(const char* path) BCatalogData * -PlainTextCatalog::Instantiate(const char *signature, const char *language, +PlainTextCatalog::Instantiate(const entry_ref& owner, const char *language, uint32 fingerprint) { PlainTextCatalog *catalog - = new(std::nothrow) PlainTextCatalog(signature, language, fingerprint); + = new(std::nothrow) PlainTextCatalog(owner, language, fingerprint); if (catalog && catalog->InitCheck() != B_OK) { delete catalog; return NULL; @@ -367,11 +397,11 @@ PlainTextCatalog::Instantiate(const char *signature, const char *language, extern "C" BCatalogData * -instantiate_catalog(const char *signature, const char *language, +instantiate_catalog(const entry_ref& owner, const char *language, uint32 fingerprint) { PlainTextCatalog *catalog - = new(std::nothrow) PlainTextCatalog(signature, language, fingerprint); + = new(std::nothrow) PlainTextCatalog(owner, language, fingerprint); if (catalog && catalog->InitCheck() != B_OK) { delete catalog; return NULL;