Added support for setting the vector icons under Linux - not yet tested, though.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19200 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-11-04 16:22:03 +00:00
parent 7191645844
commit 2a105bc1e6
3 changed files with 132 additions and 33 deletions
+11 -4
View File
@@ -1,7 +1,12 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku Inc.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
* Authors:
* Tyler Dauwalder
* Ingo Weinhold, [email protected]
*/
/*! /*!
\file Mime.cpp \file Mime.cpp
Mime type C functions implementation. Mime type C functions implementation.
@@ -10,7 +15,9 @@
#include <Entry.h> #include <Entry.h>
#include <Messenger.h> #include <Messenger.h>
#include <Mime.h> #include <Mime.h>
#if !defined(HAIKU_HOST_PLATFORM_DANO) && !defined(HAIKU_HOST_PLATFORM_BEOS) && !defined(HAIKU_HOST_PLATFORM_BONE)
# include <MimeType.h> # include <MimeType.h>
#endif
#include <mime/database_access.h> #include <mime/database_access.h>
#include <mime/UpdateMimeInfoThread.h> #include <mime/UpdateMimeInfoThread.h>
#include <Node.h> #include <Node.h>
@@ -1,7 +1,12 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku Inc.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
* Authors:
* Tyler Dauwalder
* Ingo Weinhold, [email protected]
*/
/*! /*!
\file MimeUpdateThread.cpp \file MimeUpdateThread.cpp
MimeUpdateThread implementation MimeUpdateThread implementation
@@ -22,8 +27,19 @@
#define DBG(x) #define DBG(x)
#define OUT printf #define OUT printf
namespace BPrivate { namespace BPrivate {
namespace Storage { namespace Storage {
#if defined(HAIKU_HOST_PLATFORM_DANO) || defined(HAIKU_HOST_PLATFORM_BEOS) || defined(HAIKU_HOST_PLATFORM_BONE)
// device_is_root_device
bool
device_is_root_device(dev_t device)
{
return device == 1;
}
#endif
namespace Mime { namespace Mime {
/*! \class MimeUpdateThread /*! \class MimeUpdateThread
@@ -1,7 +1,12 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku Inc.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
* Authors:
* Tyler Dauwalder
* Ingo Weinhold, [email protected]
*/
/*! /*!
\file UpdateMimeInfoThread.h \file UpdateMimeInfoThread.h
UpdateMimeInfoThread implementation UpdateMimeInfoThread implementation
@@ -13,9 +18,24 @@
#include <Bitmap.h> #include <Bitmap.h>
#include <fs_attr.h> #include <fs_attr.h>
#include <Message.h> #include <Message.h>
#include <MimeType.h>
#include <mime/database_support.h> #include <mime/database_support.h>
#include <Node.h> #include <Node.h>
#include <Resources.h>
#include <String.h>
#if !defined(HAIKU_HOST_PLATFORM_DANO) && !defined(HAIKU_HOST_PLATFORM_BEOS) && !defined(HAIKU_HOST_PLATFORM_BONE)
# include <MimeType.h>
#endif
#ifndef B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL
# define B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL 2
#endif
#ifndef B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE
# define B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE 1
#endif
#ifndef B_BITMAP_NO_SERVER_LINK
# define B_BITMAP_NO_SERVER_LINK 0
#endif
namespace BPrivate { namespace BPrivate {
namespace Storage { namespace Storage {
@@ -23,7 +43,7 @@ namespace Mime {
static const char *kAppFlagsAttribute = "BEOS:APP_FLAGS"; static const char *kAppFlagsAttribute = "BEOS:APP_FLAGS";
// update_icon
static status_t static status_t
update_icon(BAppFileInfo &appFileInfoRead, BAppFileInfo &appFileInfoWrite, update_icon(BAppFileInfo &appFileInfoRead, BAppFileInfo &appFileInfoWrite,
const char *type, BBitmap &icon, icon_size iconSize) const char *type, BBitmap &icon, icon_size iconSize)
@@ -36,7 +56,51 @@ update_icon(BAppFileInfo &appFileInfoRead, BAppFileInfo &appFileInfoWrite,
return err; return err;
} }
// is_shared_object_mime_type
/*!
This updates the vector icon of the file from its resources.
Instead of putting this functionality into BAppFileInfo (as done in Haiku),
we're doing it here, so that the mimeset executable that runs under BeOS
can make use of it as well.
*/
static status_t
update_vector_icon(BFile& file, const char *type)
{
// try to read icon from resources
BResources resources(&file);
BString name("BEOS:");
// check type param
if (type) {
if (BMimeType::IsValid(type))
name += type;
else
return B_BAD_VALUE;
} else
name += "ICON";
size_t size;
const void* data = resources.LoadResource(B_RAW_TYPE, name.String(), &size);
if (data == NULL) {
// remove attribute; the resources don't have an icon
file.RemoveAttr(name.String());
return B_OK;
}
// update icon
ssize_t written = file.WriteAttr(name.String(), B_RAW_TYPE, 0, data, size);
if (written < B_OK)
return written;
if ((size_t)written < size) {
file.RemoveAttr(name.String());
return B_ERROR;
}
return B_OK;
}
static bool static bool
is_shared_object_mime_type(BMimeType &type) is_shared_object_mime_type(BMimeType &type)
{ {
@@ -44,7 +108,9 @@ is_shared_object_mime_type(BMimeType &type)
} }
// constructor // #pragma mark -
//! Creates a new UpdateMimeInfoThread object //! Creates a new UpdateMimeInfoThread object
UpdateMimeInfoThread::UpdateMimeInfoThread(const char *name, int32 priority, UpdateMimeInfoThread::UpdateMimeInfoThread(const char *name, int32 priority,
BMessenger managerMessenger, const entry_ref *root, bool recursive, BMessenger managerMessenger, const entry_ref *root, bool recursive,
@@ -63,24 +129,25 @@ UpdateMimeInfoThread::UpdateMimeInfoThread(const char *name, int32 priority,
status_t status_t
UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir) UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
{ {
status_t err = entry ? B_OK : B_BAD_VALUE; if (entry == NULL)
return B_BAD_VALUE;
bool updateType = false; bool updateType = false;
bool updateAppInfo = false; bool updateAppInfo = false;
BNode node;
if (!err) BNode node;
err = node.SetTo(entry); status_t err = node.SetTo(entry);
if (!err && entryIsDir) if (!err && entryIsDir)
*entryIsDir = node.IsDirectory(); *entryIsDir = node.IsDirectory();
if (!err) { if (!err) {
// If not forced, only update if the entry has no file type attribute // If not forced, only update if the entry has no file type attribute
attr_info info; attr_info info;
if (fForce == B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL if (fForce == B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL
|| node.GetAttrInfo(kFileTypeAttr, &info) == B_ENTRY_NOT_FOUND) { || node.GetAttrInfo(kFileTypeAttr, &info) == B_ENTRY_NOT_FOUND)
updateType = true; updateType = true;
}
updateAppInfo = (updateType updateAppInfo = updateType
|| fForce == B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE); || fForce == B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE;
} }
// guess the MIME type // guess the MIME type
@@ -95,8 +162,8 @@ UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
if (!err && updateType) { if (!err && updateType) {
const char *typeStr = type.Type(); const char *typeStr = type.Type();
ssize_t len = strlen(typeStr) + 1; ssize_t len = strlen(typeStr) + 1;
ssize_t bytes = node.WriteAttr(kFileTypeAttr, kFileTypeType, 0, typeStr, ssize_t bytes = node.WriteAttr(kFileTypeAttr, kFileTypeType, 0,
len); typeStr, len);
if (bytes < B_OK) if (bytes < B_OK)
err = bytes; err = bytes;
else else
@@ -112,7 +179,6 @@ UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
&& file.SetTo(entry, B_READ_WRITE) == B_OK && file.SetTo(entry, B_READ_WRITE) == B_OK
&& appFileInfoRead.SetTo(&file) == B_OK && appFileInfoRead.SetTo(&file) == B_OK
&& appFileInfoWrite.SetTo(&file) == B_OK) { && appFileInfoWrite.SetTo(&file) == B_OK) {
// we read from resources and write to attributes // we read from resources and write to attributes
appFileInfoRead.SetInfoLocation(B_USE_RESOURCES); appFileInfoRead.SetInfoLocation(B_USE_RESOURCES);
appFileInfoWrite.SetInfoLocation(B_USE_ATTRIBUTES); appFileInfoWrite.SetInfoLocation(B_USE_ATTRIBUTES);
@@ -151,6 +217,11 @@ UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
if (err != B_OK) if (err != B_OK)
return err; return err;
// vector icon
err = update_vector_icon(file, NULL);
if (err != B_OK)
return err;
// small icon // small icon
BBitmap smallIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK, BBitmap smallIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK,
B_CMAP8); B_CMAP8);
@@ -192,6 +263,11 @@ UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
for (int32 i = 0; for (int32 i = 0;
supportedTypes.FindString("types", i, &supportedType) == B_OK; supportedTypes.FindString("types", i, &supportedType) == B_OK;
i++) { i++) {
// vector icon
err = update_vector_icon(file, supportedType);
if (err != B_OK)
return err;
// small icon // small icon
err = update_icon(appFileInfoRead, appFileInfoWrite, err = update_icon(appFileInfoRead, appFileInfoWrite,
supportedType, smallIcon, B_MINI_ICON); supportedType, smallIcon, B_MINI_ICON);