xref: /haiku/src/apps/icon-o-matic/import_export/Exporter.h (revision e1c4049fed1047bdb957b0529e1921e97ef94770)
1 /*
2  * Copyright 2006, 2007, 2011, Stephan Aßmus <superstippi@gmx.de>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef EXPORTER_H
6 #define EXPORTER_H
7 
8 
9 #include <string.h>
10 
11 #include <Entry.h>
12 #include <OS.h>
13 
14 #include "IconBuild.h"
15 
16 
17 class BPositionIO;
18 class Document;
19 
20 
21 _BEGIN_ICON_NAMESPACE
22 	class Icon;
23 _END_ICON_NAMESPACE
24 
25 _USING_ICON_NAMESPACE
26 
27 /*! Base class for all exporters to implement. */
28 class Exporter {
29  public:
30 								Exporter();
31 	virtual						~Exporter();
32 
33 	/*! Export the Document to the specified entry_ref.
34 		Spawns a separate thread to do the actual exporting.
35 		Uses the virtual Export function defined after this function to do the
36 		actual export.
37 	*/
38 			status_t			Export(Document* document,
39 									   const entry_ref& ref);
40 
41 	virtual	status_t			Export(const Icon* icon,
42 									   BPositionIO* stream) = 0;
43 	/*! Turns the status_t error code returned by \c Export into a string. */
44 	virtual const char*			ErrorCodeToString(status_t code)
45 									{ return strerror(code); }
46 	virtual	const char*			MIMEType() = 0;
47 
48 	/*! If \a selfDestroy is true, class deletes itself when export thread is
49 		finished.
50 	*/
51 			void				SetSelfDestroy(bool selfDestroy);
52 
53 			void				WaitForExportThread();
54 
55  private:
56 	static	int32				_ExportThreadEntry(void* cookie);
57 			int32				_ExportThread();
58 			status_t			_Export(const Icon* icon,
59 										const entry_ref* docRef);
60 
61 			Document*			fDocument;
62 			Icon*				fClonedIcon;
63 			entry_ref			fRef;
64 			thread_id			fExportThread;
65 			bool				fSelfDestroy;
66 };
67 
68 #endif // EXPORTER_H
69