CreateAppMetaMimeThread::DoMimeUpdate() now also updates the supported types

of an application as well as the their icons.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16541 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-02-28 01:27:22 +00:00
parent c469e0a1d3
commit 7500f29455
4 changed files with 215 additions and 189 deletions
+15 -34
View File
@@ -1,14 +1,11 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
/*!
\file MimeType.h
BMimeType interface declarations.
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _MIME_TYPE_H
#define _MIME_TYPE_H
#include <SupportDefs.h>
#include <StorageDefs.h>
@@ -24,6 +21,11 @@ class BMessenger;
namespace BPrivate {
class MimeDatabase;
namespace Storage {
namespace Mime {
class CreateAppMetaMimeThread;
}
}
}
enum app_verb {
@@ -126,7 +128,7 @@ public:
static status_t GetInstalledTypes(BMessage *types);
static status_t GetInstalledTypes(const char* supertype,
BMessage* subtypes);
static status_t GetWildcardApps(BMessage *wild_ones);
static status_t GetWildcardApps(BMessage* wildcardApps);
static bool IsValid(const char *mimeType);
status_t GetAppHint(entry_ref *ref) const;
@@ -153,7 +155,7 @@ public:
static status_t StartWatching(BMessenger target);
static status_t StopWatching(BMessenger target);
/* Deprecated Use SetTo instead. */
/* Deprecated. Use SetTo() instead. */
status_t SetType(const char *mimeType);
/* Brand new Delete() methods */
@@ -173,19 +175,10 @@ private:
// if mimePath is NULL, defaults to "/boot/home/config/settings/beos_mime/"
friend class MimeTypeTest;
// Uncomment, when needed...
// for testing only
friend class BAppFileInfo;
// friend class BRoster;
// friend class TRosterApp;
// friend class TMimeWorker;
// friend status_t _update_mime_info_(const char *, int32);
// friend status_t _real_update_app_(BAppFileInfo *, const char *, bool);
// static void _set_local_dispatch_target_(BMessenger *, void (*)(BMessage *));
// void _touch_();
friend class BPrivate::Storage::Mime::CreateAppMetaMimeThread;
virtual void _ReservedMimeType1();
virtual void _ReservedMimeType2();
@@ -194,30 +187,18 @@ private:
BMimeType &operator=(const BMimeType &);
BMimeType(const BMimeType &);
// void InitData(const char *type);
// void InitData(const char *type);
// status_t OpenFile(bool create_file = false, dev_t dev = -1) const;
// status_t CloseFile() const;
status_t GetSupportedTypes(BMessage* types);
status_t SetSupportedTypes(const BMessage* types, bool fullSync = true);
static status_t GetAssociatedTypes(const char *extension, BMessage *types);
// void MimeChanged(int32 w, const char *type = NULL,
// bool large = true) const;
private:
char* fType;
BFile* fMeta;
void* _unused;
entry_ref fRef;
int fWhere;
status_t fCStatus;
uint32 _reserved[3];
uint32 _reserved[4];
};
#endif // _MIME_TYPE_H
+6 -5
View File
@@ -46,8 +46,9 @@ const char *B_APP_MIME_TYPE = B_ELF_APP_MIME_TYPE;
/*! \brief Creates an uninitialized BMimeType object.
*/
BMimeType::BMimeType()
: fType(NULL)
, fCStatus(B_NO_INIT)
:
fType(NULL),
fCStatus(B_NO_INIT)
{
}
@@ -59,8 +60,9 @@ BMimeType::BMimeType()
\param mimeType The MIME string.
*/
BMimeType::BMimeType(const char *mimeType)
: fType(NULL)
, fCStatus(B_NO_INIT)
:
fType(NULL),
fCStatus(B_NO_INIT)
{
SetTo(mimeType);
}
@@ -119,7 +121,6 @@ BMimeType::SetTo(const char *mimeType)
void
BMimeType::Unset()
{
if (fType)
delete [] fType;
fType = NULL;
fCStatus = B_NO_INIT;
@@ -1,28 +1,32 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
/*!
\file CreateAppMetaMimeThread.h
CreateAppMetaMimeThread implementation
/*
* Copyright 2002-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Tyler Dauwalder
* Axel Dörfler, [email protected]
*/
#include "mime/CreateAppMetaMimeThread.h"
#include "mime/CreateAppMetaMimeThread.h"
#include "mime/database_support.h"
#include <AppFileInfo.h>
#include <Bitmap.h>
#include <fs_attr.h>
#include <MimeType.h>
#include <mime/database_support.h>
#include <Node.h>
#include <Path.h>
#include <String.h>
#include <stdio.h>
namespace BPrivate {
namespace Storage {
namespace Mime {
CreateAppMetaMimeThread::CreateAppMetaMimeThread(const char *name,
int32 priority, BMessenger managerMessenger, const entry_ref *root,
bool recursive, int32 force, BMessage *replyee)
@@ -31,67 +35,107 @@ CreateAppMetaMimeThread::CreateAppMetaMimeThread(const char *name,
{
}
status_t
CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir)
{
status_t err = entry ? B_OK : B_BAD_VALUE;
BNode node;
BString sig;
BMimeType mime;
BPath path;
attr_info info;
BBitmap miniIcon(BRect(0,0,15,15), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
if (ref == NULL)
return B_BAD_VALUE;
BNode typeNode;
if (!err)
err = node.SetTo(entry);
if (!err && entryIsDir)
*entryIsDir = node.IsDirectory();
BFile file;
status_t status = file.SetTo(ref, B_READ_ONLY);
if (status < B_OK)
return status;
BAppFileInfo appInfo(&file);
status = appInfo.InitCheck();
if (status < B_OK)
return status;
BPath path;
status = path.SetTo(ref);
if (status < B_OK)
return status;
// Read the app sig (which consequently keeps us from updating
// non-applications, since we get an error if the file has no
// app sig)
if (!err)
err = node.ReadAttrString("BEOS:APP_SIG", &sig);
if (!err) {
sig.ToLower();
BString signature;
status = file.ReadAttrString("BEOS:APP_SIG", &signature);
if (status < B_OK)
return B_BAD_TYPE;
signature.ToLower();
// Signatures and MIME types are case insensitive
// Init our various objects
err = mime.SetTo(sig.String());
if (!err && !mime.IsInstalled())
BMimeType mime;
status = mime.SetTo(signature.String());
if (status < B_OK)
return status;
if (!mime.IsInstalled())
mime.Install();
if (!err) {
char metaMimePath[B_PATH_NAME_LENGTH];
sprintf(metaMimePath, "%s/%s", kDatabaseDir.c_str(), sig.String());
err = typeNode.SetTo(metaMimePath);
}
if (!err)
err = path.SetTo(entry);
sprintf(metaMimePath, "%s/%s", kDatabaseDir.c_str(), signature.String());
status = typeNode.SetTo(metaMimePath);
if (status < B_OK)
return status;
// Preferred App
if (!err && (fForce || typeNode.GetAttrInfo(kPreferredAppAttr, &info) == B_ENTRY_NOT_FOUND)) {
err = mime.SetPreferredApp(sig.String());
attr_info info;
if (status == B_OK && (fForce || typeNode.GetAttrInfo(kPreferredAppAttr, &info) != B_OK)) {
status = mime.SetPreferredApp(signature.String());
}
// Short Description
if (!err && (fForce || typeNode.GetAttrInfo(kShortDescriptionAttr, &info) == B_ENTRY_NOT_FOUND)) {
err = mime.SetShortDescription(path.Leaf());
// Short Description (name of the application)
if (status == B_OK && (fForce || typeNode.GetAttrInfo(kShortDescriptionAttr, &info) != B_OK)) {
status = mime.SetShortDescription(path.Leaf());
}
// App Hint
if (!err && (fForce || typeNode.GetAttrInfo(kAppHintAttr, &info) == B_ENTRY_NOT_FOUND)) {
err = mime.SetAppHint(entry);
if (status == B_OK && (fForce || typeNode.GetAttrInfo(kAppHintAttr, &info) != B_OK)) {
status = mime.SetAppHint(ref);
}
// Mini icon
if (!err && (fForce || typeNode.GetAttrInfo(kMiniIconAttr, &info) == B_ENTRY_NOT_FOUND)) {
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 ? (status_t)B_OK : (status_t)B_FILE_ERROR;
// Mini Icon
BBitmap miniIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
if (status == B_OK && (fForce || typeNode.GetAttrInfo(kMiniIconAttr, &info) != B_OK)) {
if (appInfo.GetIcon(&miniIcon, B_MINI_ICON) == B_OK)
status = mime.SetIcon(&miniIcon, B_MINI_ICON);
}
if (!err)
err = mime.SetIcon(&miniIcon, B_MINI_ICON);
// Large Icon
BBitmap largeIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
if (status == B_OK && (fForce || typeNode.GetAttrInfo(kLargeIconAttr, &info) != B_OK)) {
if (appInfo.GetIcon(&miniIcon, B_LARGE_ICON) == B_OK)
status = mime.SetIcon(&miniIcon, B_LARGE_ICON);
}
// Supported Types
BMessage supportedTypes;
if (status == B_OK && (fForce || typeNode.GetAttrInfo(kSupportedTypesAttr, &info) != B_OK)) {
if (appInfo.GetSupportedTypes(&supportedTypes) == B_OK)
status = mime.SetSupportedTypes(&supportedTypes);
}
return err;
// Icons for supported types
const char* type;
for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++) {
// mini icon
if (status == B_OK && appInfo.GetIconForType(type, &miniIcon, B_MINI_ICON) == B_OK)
status = mime.SetIconForType(type, &miniIcon, B_MINI_ICON);
// large icon
if (status == B_OK && appInfo.GetIconForType(type, &largeIcon, B_LARGE_ICON) == B_OK)
status = mime.SetIconForType(type, &largeIcon, B_LARGE_ICON);
}
if (status == B_OK && _entryIsDir != NULL)
*_entryIsDir = file.IsDirectory();
return status;
}
} // namespace Mime