From 56a452bb2c3c41053cd9df6db56c73494ce2dfcd Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Sun, 29 Sep 2002 07:08:21 +0000 Subject: [PATCH] CreateAppMetaMimeThread class, which is a subclass of MimeUpdateThread that implements updating specific to create_app_meta_mime(). Note that the implementation is not 100% correct yet, and the OBOS::BMimeType::create_app_meta_mime() tests still fail. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1267 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../storage/mime/CreateAppMetaMimeThread.h | 30 +++++++ .../storage/mime/CreateAppMetaMimeThread.cpp | 89 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 headers/private/storage/mime/CreateAppMetaMimeThread.h create mode 100644 src/kits/storage/mime/CreateAppMetaMimeThread.cpp diff --git a/headers/private/storage/mime/CreateAppMetaMimeThread.h b/headers/private/storage/mime/CreateAppMetaMimeThread.h new file mode 100644 index 0000000000..02be36ba8f --- /dev/null +++ b/headers/private/storage/mime/CreateAppMetaMimeThread.h @@ -0,0 +1,30 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +//--------------------------------------------------------------------- +/*! + \file CreateAppMetaMimeThread.h + CreateAppMetaMimeThread interface declaration +*/ + +#ifndef _CREATE_APP_META_MIME_THREAD_H +#define _CREATE_APP_META_MIME_THREAD_H + +#include + +namespace BPrivate { +namespace Storage { +namespace Mime { + +class CreateAppMetaMimeThread : public MimeUpdateThread { +public: + CreateAppMetaMimeThread(const char *name, int32 priority, BMessenger managerMessenger, + const entry_ref *root, bool recursive, bool force, BMessage *replyee); + status_t DoMimeUpdate(const entry_ref *entry, bool *entryIsDir); +}; + +} // namespace Mime +} // namespace Storage +} // namespace BPrivate + +#endif // _CREATE_APP_META_MIME_THREAD_H diff --git a/src/kits/storage/mime/CreateAppMetaMimeThread.cpp b/src/kits/storage/mime/CreateAppMetaMimeThread.cpp new file mode 100644 index 0000000000..d84b5449c4 --- /dev/null +++ b/src/kits/storage/mime/CreateAppMetaMimeThread.cpp @@ -0,0 +1,89 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +//--------------------------------------------------------------------- +/*! + \file CreateAppMetaMimeThread.h + CreateAppMetaMimeThread implementation +*/ + +#include "mime/CreateAppMetaMimeThread.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace BPrivate { +namespace Storage { +namespace Mime { + +CreateAppMetaMimeThread::CreateAppMetaMimeThread(const char *name, int32 priority, + BMessenger managerMessenger, const entry_ref *root, bool recursive, bool force, BMessage *replyee) + : MimeUpdateThread(name, priority, managerMessenger, root, recursive, force, replyee) +{ +} + +status_t +CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir) +{ + status_t err = entry ? B_OK : B_BAD_VALUE; + bool doUpdate = false; + BNode node; + BString sig; + + if (!err) + err = node.SetTo(entry); + // Read the app sig (which consequently keeps us from updating non-applications) + if (!err) + err = node.ReadAttrString("BEOS:APP_SIG", &sig); + if (!err && !fForce) { + // If not forced, only update if the entry has no file type attribute +// attr_info info; +// if (!err) +// doUpdate = node.GetAttrInfo(kFileTypeAttr, &info) == B_ENTRY_NOT_FOUND; + } + if (!err && doUpdate) { + BMimeType mime; + BPath path; + attr_info info; + BBitmap miniIcon(BRect(0,0,15,15), B_CMAP8); + + // Init our various objects + err = mime.SetTo(sig.String()); + if (!err) + err = path.SetTo(entry); + + // Preferred App + if (!err) + err = mime.SetPreferredApp(sig.String()); + // Short Description + if (!err) + err = mime.SetShortDescription(path.Leaf()); + // App Hint + if (!err) + err = mime.SetAppHint(entry); + // Mini icon + if (!err) + err = node.GetAttrInfo("BEOS:M:STD_ICON", &info); + if (!err) + err = info.size == 16*16 ? B_OK : B_BAD_VALUE; + if (!err) { + ssize_t bytes = node.ReadAttr("BEOS:M:STD_ICON", kMiniIconType, 0, miniIcon.Bits(), 16*16); + err = bytes == 16*16 ? B_OK : B_FILE_ERROR; + } + if (!err) + err = mime.SetIcon(&miniIcon, B_MINI_ICON); + } + if (!err && entryIsDir) + *entryIsDir = node.IsDirectory(); + return err; +} + +} // namespace Mime +} // namespace Storage +} // namespace BPrivate +