* Icon-O-Matic prepends a magic number when writing native files, this way
we can associate these native files with Icon-O-Matic (they also get their own mime type) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21295 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FilePanel.h>
|
#include <FilePanel.h>
|
||||||
#include <IconEditorProtocol.h>
|
#include <IconEditorProtocol.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Mime.h>
|
||||||
|
|
||||||
#include "support_settings.h"
|
#include "support_settings.h"
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@
|
|||||||
#include "BitmapExporter.h"
|
#include "BitmapExporter.h"
|
||||||
#include "BitmapSetSaver.h"
|
#include "BitmapSetSaver.h"
|
||||||
#include "CommandStack.h"
|
#include "CommandStack.h"
|
||||||
|
#include "Defines.h"
|
||||||
#include "Document.h"
|
#include "Document.h"
|
||||||
#include "FlatIconExporter.h"
|
#include "FlatIconExporter.h"
|
||||||
#include "FlatIconFormat.h"
|
#include "FlatIconFormat.h"
|
||||||
@@ -46,9 +49,11 @@
|
|||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
|
static const char* kAppSig = "application/x-vnd.haiku-icon_o_matic";
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
IconEditorApp::IconEditorApp()
|
IconEditorApp::IconEditorApp()
|
||||||
: BApplication("application/x-vnd.haiku-icon_o_matic"),
|
: BApplication(kAppSig),
|
||||||
fMainWindow(NULL),
|
fMainWindow(NULL),
|
||||||
fDocument(new Document("test")),
|
fDocument(new Document("test")),
|
||||||
|
|
||||||
@@ -227,6 +232,8 @@ IconEditorApp::ReadyToRun()
|
|||||||
_RestoreSettings();
|
_RestoreSettings();
|
||||||
|
|
||||||
fMainWindow->Show();
|
fMainWindow->Show();
|
||||||
|
|
||||||
|
_InstallDocumentMimeType();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RefsReceived
|
// RefsReceived
|
||||||
@@ -571,3 +578,80 @@ IconEditorApp::_RestoreSettings()
|
|||||||
fMainWindow->RestoreSettings(&settings);
|
fMainWindow->RestoreSettings(&settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _InstallDocumentMimeType
|
||||||
|
void
|
||||||
|
IconEditorApp::_InstallDocumentMimeType()
|
||||||
|
{
|
||||||
|
// install mime type of documents
|
||||||
|
BMimeType mime(kNativeIconMimeType);
|
||||||
|
status_t ret = mime.InitCheck();
|
||||||
|
if (ret < B_OK) {
|
||||||
|
fprintf(stderr, "Could not init native document mime type (%s): %s.\n",
|
||||||
|
kNativeIconMimeType, strerror(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mime.IsInstalled() && !(modifiers() & B_SHIFT_KEY)) {
|
||||||
|
// mime is already installed, and the user is not
|
||||||
|
// pressing the shift key to force a re-install
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = mime.Install();
|
||||||
|
if (ret < B_OK) {
|
||||||
|
fprintf(stderr, "Could not install native document mime type (%s): %s.\n",
|
||||||
|
kNativeIconMimeType, strerror(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// set preferred app
|
||||||
|
ret = mime.SetPreferredApp(kAppSig);
|
||||||
|
if (ret < B_OK)
|
||||||
|
fprintf(stderr, "Could not set native document preferred app: %s\n",
|
||||||
|
strerror(ret));
|
||||||
|
|
||||||
|
// set descriptions
|
||||||
|
ret = mime.SetShortDescription("Haiku Icon");
|
||||||
|
if (ret < B_OK)
|
||||||
|
fprintf(stderr, "Could not set short description of mime type: %s\n",
|
||||||
|
strerror(ret));
|
||||||
|
ret = mime.SetLongDescription("Native Haiku vector icon");
|
||||||
|
if (ret < B_OK)
|
||||||
|
fprintf(stderr, "Could not set long description of mime type: %s\n",
|
||||||
|
strerror(ret));
|
||||||
|
|
||||||
|
// set extensions
|
||||||
|
BMessage message('extn');
|
||||||
|
message.AddString("extensions", "icon");
|
||||||
|
ret = mime.SetFileExtensions(&message);
|
||||||
|
if (ret < B_OK)
|
||||||
|
fprintf(stderr, "Could not set extensions of mime type: %s\n",
|
||||||
|
strerror(ret));
|
||||||
|
|
||||||
|
// set sniffer rule
|
||||||
|
const char* snifferRule = "0.9 ('GSMI')";
|
||||||
|
ret = mime.SetSnifferRule(snifferRule);
|
||||||
|
if (ret < B_OK) {
|
||||||
|
BString parseError;
|
||||||
|
BMimeType::CheckSnifferRule(snifferRule, &parseError);
|
||||||
|
fprintf(stderr, "Could not set sniffer rule of mime type: %s\n",
|
||||||
|
parseError.String());
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Icon-O-Matic writes the icon being saved as icon of the file anyways
|
||||||
|
// therefor, the following code is not needed, it is also not tested and I am
|
||||||
|
// spotting an error with SetIcon()
|
||||||
|
// // set document icon
|
||||||
|
// BResources* resources = AppResources();
|
||||||
|
// // does not need to be freed (belongs to BApplication base)
|
||||||
|
// if (resources) {
|
||||||
|
// size_t size;
|
||||||
|
// const void* iconData = resources->LoadResource('VICN', "IOM:DOC_ICON", &size);
|
||||||
|
// if (iconData && size > 0) {
|
||||||
|
// memcpy(largeIcon.Bits(), iconData, size);
|
||||||
|
// if (mime.SetIcon(&largeIcon, B_LARGE_ICON) < B_OK)
|
||||||
|
// fprintf(stderr, "Could not set large icon of mime type.\n");
|
||||||
|
// } else
|
||||||
|
// fprintf(stderr, "Could not find icon in app resources (data: %p, size: %ld).\n", iconData, size);
|
||||||
|
// } else
|
||||||
|
// fprintf(stderr, "Could not find app resources.\n");
|
||||||
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ class IconEditorApp : public BApplication {
|
|||||||
|
|
||||||
void _StoreSettings();
|
void _StoreSettings();
|
||||||
void _RestoreSettings();
|
void _RestoreSettings();
|
||||||
|
void _InstallDocumentMimeType();
|
||||||
|
|
||||||
MainWindow* fMainWindow;
|
MainWindow* fMainWindow;
|
||||||
Document* fDocument;
|
Document* fDocument;
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ Application Icon-O-Matic :
|
|||||||
######## Icon-O-Matic ########
|
######## Icon-O-Matic ########
|
||||||
|
|
||||||
# document
|
# document
|
||||||
|
Defines.cpp
|
||||||
Document.cpp
|
Document.cpp
|
||||||
IconObject.cpp
|
IconObject.cpp
|
||||||
SetPropertiesCommand.cpp
|
SetPropertiesCommand.cpp
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007, Haiku. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
|
*/
|
||||||
|
#include "Defines.h"
|
||||||
|
|
||||||
|
const uint32 kNativeIconMagicNumber = 'GSMI';
|
||||||
|
const char* kNativeIconMimeType = "application/x-vnd.Haiku-icon";
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007, Haiku. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef DEFINES_H
|
||||||
|
#define DEFINES_H
|
||||||
|
|
||||||
|
extern const uint32 kNativeIconMagicNumber;
|
||||||
|
extern const char* kNativeIconMimeType;
|
||||||
|
|
||||||
|
#endif // DEFINES_H
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "NativeSaver.h"
|
#include "NativeSaver.h"
|
||||||
|
|
||||||
#include "FlatIconFormat.h"
|
#include "FlatIconFormat.h"
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NATIVE_SAVER_H
|
#ifndef NATIVE_SAVER_H
|
||||||
#define NATIVE_SAVER_H
|
#define NATIVE_SAVER_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku. All rights reserved.
|
* Copyright 2006-2007, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SimpleFileSaver.h"
|
#include "SimpleFileSaver.h"
|
||||||
|
|
||||||
#include "Exporter.h"
|
#include "Exporter.h"
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku. All rights reserved.
|
* Copyright 2006-2007, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SIMPLE_FILE_SAVER_H
|
#ifndef SIMPLE_FILE_SAVER_H
|
||||||
#define SIMPLE_FILE_SAVER_H
|
#define SIMPLE_FILE_SAVER_H
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,12 @@
|
|||||||
|
|
||||||
#include "MessageExporter.h"
|
#include "MessageExporter.h"
|
||||||
|
|
||||||
|
#include <ByteOrder.h>
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <TypeConstants.h>
|
#include <TypeConstants.h>
|
||||||
|
|
||||||
|
#include "Defines.h"
|
||||||
#include "Icon.h"
|
#include "Icon.h"
|
||||||
#include "PathContainer.h"
|
#include "PathContainer.h"
|
||||||
#include "Shape.h"
|
#include "Shape.h"
|
||||||
@@ -98,6 +100,20 @@ MessageExporter::Export(const Icon* icon, BPositionIO* stream)
|
|||||||
ret = archive.AddMessage("shapes", &allShapes);
|
ret = archive.AddMessage("shapes", &allShapes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepend the magic number to the file which
|
||||||
|
// later tells us that this file is one of us
|
||||||
|
if (ret == B_OK) {
|
||||||
|
ssize_t size = sizeof(uint32);
|
||||||
|
uint32 magic = B_HOST_TO_LENDIAN_INT32(kNativeIconMagicNumber);
|
||||||
|
ssize_t written = stream->Write(&magic, size);
|
||||||
|
if (written != size) {
|
||||||
|
if (written < 0)
|
||||||
|
ret = (status_t)written;
|
||||||
|
else
|
||||||
|
ret = B_IO_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ret == B_OK)
|
if (ret == B_OK)
|
||||||
ret = archive.Flatten(stream);
|
ret = archive.Flatten(stream);
|
||||||
|
|
||||||
@@ -108,8 +124,7 @@ MessageExporter::Export(const Icon* icon, BPositionIO* stream)
|
|||||||
const char*
|
const char*
|
||||||
MessageExporter::MIMEType()
|
MessageExporter::MIMEType()
|
||||||
{
|
{
|
||||||
// TODO: come up with a MIME type
|
return kNativeIconMimeType;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku. All rights reserved.
|
* Copyright 2006-2007, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MessageImporter.h"
|
#include "MessageImporter.h"
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Archivable.h>
|
#include <Archivable.h>
|
||||||
|
#include <ByteOrder.h>
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
|
||||||
|
#include "Defines.h"
|
||||||
#include "Icon.h"
|
#include "Icon.h"
|
||||||
#include "PathContainer.h"
|
#include "PathContainer.h"
|
||||||
#include "Shape.h"
|
#include "Shape.h"
|
||||||
@@ -46,6 +47,28 @@ MessageImporter::Import(Icon* icon, BPositionIO* stream)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 magic = 0;
|
||||||
|
ssize_t size = sizeof(magic);
|
||||||
|
off_t position = stream->Position();
|
||||||
|
ssize_t read = stream->Read(&magic, size);
|
||||||
|
if (read != size) {
|
||||||
|
if (read < 0)
|
||||||
|
ret = (status_t)read;
|
||||||
|
else
|
||||||
|
ret = B_IO_ERROR;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (B_LENDIAN_TO_HOST_INT32(magic) != kNativeIconMagicNumber) {
|
||||||
|
// this might be an old native icon file, where
|
||||||
|
// we didn't prepend the magic number yet, seek back
|
||||||
|
if (stream->Seek(position, SEEK_SET) != position) {
|
||||||
|
printf("MessageImporter::Import() - "
|
||||||
|
"failed to seek back to beginning of stream\n");
|
||||||
|
return B_IO_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BMessage archive;
|
BMessage archive;
|
||||||
ret = archive.Unflatten(stream);
|
ret = archive.Unflatten(stream);
|
||||||
if (ret < B_OK) {
|
if (ret < B_OK) {
|
||||||
|
|||||||
Reference in New Issue
Block a user