1 /* 2 * Copyright 2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "MessengerSaver.h" 10 11 #include <IconEditorProtocol.h> 12 #include <Message.h> 13 14 #include "Document.h" 15 #include "FlatIconExporter.h" 16 17 // constructor 18 MessengerSaver::MessengerSaver(const BMessenger& messenger) 19 : fMessenger(messenger) 20 { 21 } 22 23 // destructor 24 MessengerSaver::~MessengerSaver() 25 { 26 } 27 28 // Save 29 status_t 30 MessengerSaver::Save(Document* document) 31 { 32 #if HAIKU_TARGET_PLATFORM_HAIKU 33 if (!fMessenger.IsValid()) 34 return B_NO_INIT; 35 36 FlatIconExporter exporter; 37 BMallocIO stream; 38 status_t ret = exporter.Export(document->Icon(), &stream); 39 if (ret < B_OK) 40 return ret; 41 42 BMessage message(B_ICON_DATA_EDITED); 43 ret = message.AddData("icon data", B_VECTOR_ICON_TYPE, 44 stream.Buffer(), stream.BufferLength()); 45 if (ret < B_OK) 46 return ret; 47 48 return fMessenger.SendMessage(&message); 49 #else 50 return B_ERROR; 51 #endif 52 } 53 54