diff --git a/src/apps/icon-o-matic/Jamfile b/src/apps/icon-o-matic/Jamfile index 49846afa3d..5858a889e8 100644 --- a/src/apps/icon-o-matic/Jamfile +++ b/src/apps/icon-o-matic/Jamfile @@ -13,6 +13,7 @@ SubDirC++Flags $(defines) ; local iconSourceDirs = icon icon/flat_icon + icon/message icon/shape icon/style icon/transformable @@ -78,6 +79,10 @@ Application Icon-O-Matic : LittleEndianBuffer.cpp PathCommandQueue.cpp + # icon/message + Defines.cpp + MessageImporter.cpp + # icon/shape PathContainer.cpp Shape.cpp @@ -108,7 +113,6 @@ Application Icon-O-Matic : ######## Icon-O-Matic ######## # document - Defines.cpp Document.cpp IconObject.cpp SetPropertiesCommand.cpp @@ -228,7 +232,6 @@ Application Icon-O-Matic : # import_export/message MessageExporter.cpp - MessageImporter.cpp # import_export/styled_text StyledTextImporter.cpp diff --git a/src/apps/icon-o-matic/document/Defines.cpp b/src/apps/icon-o-matic/document/Defines.cpp deleted file mode 100644 index da93274a3f..0000000000 --- a/src/apps/icon-o-matic/document/Defines.cpp +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright 2007, Haiku. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus - */ -#include "Defines.h" - -const uint32 kNativeIconMagicNumber = 'IMSG'; -const char* kNativeIconMimeType = "application/x-vnd.Haiku-icon"; - - diff --git a/src/apps/icon-o-matic/document/Defines.h b/src/apps/icon-o-matic/document/Defines.h deleted file mode 100644 index 8d75a1cebf..0000000000 --- a/src/apps/icon-o-matic/document/Defines.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2007, Haiku. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus - */ -#ifndef DEFINES_H -#define DEFINES_H - -#include - - -extern const uint32 kNativeIconMagicNumber; -extern const char* kNativeIconMimeType; - -#endif // DEFINES_H diff --git a/src/apps/icon-o-matic/import_export/message/MessageImporter.cpp b/src/apps/icon-o-matic/import_export/message/MessageImporter.cpp deleted file mode 100644 index 6c3a5b544d..0000000000 --- a/src/apps/icon-o-matic/import_export/message/MessageImporter.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright 2006-2007, Haiku. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus - */ -#include "MessageImporter.h" - -#include -#include - -#include -#include -#include -#include - -#include "Defines.h" -#include "Icon.h" -#include "PathContainer.h" -#include "Shape.h" -#include "Style.h" -#include "StyleContainer.h" -#include "VectorPath.h" - -using std::nothrow; - -// constructor -MessageImporter::MessageImporter() - : Importer() -{ -} - -// destructor -MessageImporter::~MessageImporter() -{ -} - -// Import -status_t -MessageImporter::Import(Icon* icon, BPositionIO* stream) -{ - status_t ret = Init(icon); - if (ret < B_OK) { - printf("MessageImporter::Import() - " - "Init() error: %s\n", strerror(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_BENDIAN_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; - ret = archive.Unflatten(stream); - if (ret < B_OK) { - printf("MessageImporter::Import() - " - "error unflattening icon archive: %s\n", strerror(ret)); - return ret; - } - - // paths - PathContainer* paths = icon->Paths(); - ret = _ImportPaths(&archive, paths); - if (ret < B_OK) { - printf("MessageImporter::Import() - " - "error importing paths: %s\n", strerror(ret)); - return ret; - } - - // styles - StyleContainer* styles = icon->Styles(); - ret = _ImportStyles(&archive, styles); - if (ret < B_OK) { - printf("MessageImporter::Import() - " - "error importing styles: %s\n", strerror(ret)); - return ret; - } - - // shapes - ret = _ImportShapes(&archive, paths, styles, icon->Shapes()); - if (ret < B_OK) { - printf("MessageImporter::Import() - " - "error importing shapes: %s\n", strerror(ret)); - return ret; - } - - return B_OK; -} - -// #pragma mark - - -// _ImportPaths -status_t -MessageImporter::_ImportPaths(const BMessage* archive, - PathContainer* paths) const -{ - BMessage allPaths; - status_t ret = archive->FindMessage("paths", &allPaths); - if (ret < B_OK) - return ret; - - BMessage pathArchive; - for (int32 i = 0; - allPaths.FindMessage("path", i, &pathArchive) == B_OK; i++) { - VectorPath* path = new (nothrow) VectorPath(&pathArchive); - if (!path || !paths->AddPath(path)) { - delete path; - ret = B_NO_MEMORY; - } - if (ret < B_OK) - break; - } - - return ret; -} - -// _ImportStyles -status_t -MessageImporter::_ImportStyles(const BMessage* archive, - StyleContainer* styles) const -{ - BMessage allStyles; - status_t ret = archive->FindMessage("styles", &allStyles); - if (ret < B_OK) - return ret; - - BMessage styleArchive; - for (int32 i = 0; - allStyles.FindMessage("style", i, &styleArchive) == B_OK; i++) { - Style* style = new (nothrow) Style(&styleArchive); - if (!style || !styles->AddStyle(style)) { - delete style; - ret = B_NO_MEMORY; - } - if (ret < B_OK) - break; - } - - return ret; -} - -// _ImportShapes -status_t -MessageImporter::_ImportShapes(const BMessage* archive, - PathContainer* paths, - StyleContainer* styles, - ShapeContainer* shapes) const -{ - BMessage allShapes; - status_t ret = archive->FindMessage("shapes", &allShapes); - if (ret < B_OK) - return ret; - - BMessage shapeArchive; - for (int32 i = 0; - allShapes.FindMessage("shape", i, &shapeArchive) == B_OK; i++) { - // find the right style - int32 styleIndex; - if (shapeArchive.FindInt32("style ref", &styleIndex) < B_OK) { - printf("MessageImporter::_ImportShapes() - " - "Shape %ld doesn't reference a Style!", i); - continue; - } - Style* style = styles->StyleAt(StyleIndexFor(styleIndex)); - if (!style) { - printf("MessageImporter::_ImportShapes() - " - "Shape %ld wants Style %ld, which does not exist\n", - i, styleIndex); - continue; - } - - // create shape - Shape* shape = new (nothrow) Shape(style); - if (!shape || shape->InitCheck() < B_OK || !shapes->AddShape(shape)) { - delete shape; - ret = B_NO_MEMORY; - } - if (ret < B_OK) - break; - - // find the referenced paths - int32 pathIndex; - for (int32 j = 0; - shapeArchive.FindInt32("path ref", j, &pathIndex) == B_OK; - j++) { - VectorPath* path = paths->PathAt(PathIndexFor(pathIndex)); - if (!path) { - printf("MessageImporter::_ImportShapes() - " - "Shape %ld referenced path %ld, " - "which does not exist\n", i, pathIndex); - continue; - } - shape->Paths()->AddPath(path); - } - - // Shape properties - if (ret == B_OK) - shape->Unarchive(&shapeArchive); - } - - return ret; -} - diff --git a/src/apps/icon-o-matic/import_export/message/MessageImporter.h b/src/apps/icon-o-matic/import_export/message/MessageImporter.h deleted file mode 100644 index f2481b106f..0000000000 --- a/src/apps/icon-o-matic/import_export/message/MessageImporter.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2006-2007, Haiku. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus - */ -#ifndef MESSAGE_IMPORTER_H -#define MESSAGE_IMPORTER_H - - -#include "Importer.h" - -class BMessage; -class BPositionIO; - -namespace BPrivate { -namespace Icon { - class Icon; - class PathContainer; - class ShapeContainer; - class StyleContainer; -} -} - -class MessageImporter : public Importer { - public: - MessageImporter(); - virtual ~MessageImporter(); - - status_t Import(Icon* icon, - BPositionIO* stream); - - private: - status_t _ImportPaths(const BMessage* archive, - PathContainer* paths) const; - status_t _ImportStyles(const BMessage* archive, - StyleContainer* styles) const; - status_t _ImportShapes(const BMessage* archive, - PathContainer* paths, - StyleContainer* styles, - ShapeContainer* shapes) const; -}; - -#endif // MESSAGE_IMPORTER_H