libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / resedit / ResourceRoster.cpp
blob0a87ced3978df4535c1c5a449a8ade4defaaafec
1 /*
2 * Copyright (c) 2005-2010, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Author:
6 * DarkWyrm <darkwyrm@gmail.com>
7 */
8 #include "ResourceRoster.h"
10 #include <Application.h>
11 #include <Bitmap.h>
12 #include <Directory.h>
13 #include <Entry.h>
14 #include <image.h>
15 #include <Path.h>
16 #include <Roster.h>
17 #include <String.h>
19 #include "InternalEditors.h"
20 #include "ResourceData.h"
21 #include "ResFields.h"
23 // For the MakeFieldForType temp code
24 #include <TranslatorFormats.h>
25 #include <TranslationUtils.h>
26 #include <DataIO.h>
27 #include <Mime.h>
28 #include <TypeConstants.h>
30 class EditorInfo
32 public:
33 EditorInfo(const image_id &id, const char *name,
34 create_editor *allocator);
35 ~EditorInfo(void);
37 status_t ID(void) const { return fID; }
38 const char * Name(void) const { return fName.String(); }
39 Editor * Instantiate(void);
41 private:
42 image_id fID;
43 BString fName;
44 create_editor * fAllocator;
47 EditorInfo::EditorInfo(const image_id &id, const char *name,
48 create_editor *allocator)
49 : fID(id),
50 fName(name),
51 fAllocator(allocator)
56 EditorInfo::~EditorInfo(void)
61 Editor *
62 EditorInfo::Instantiate(void)
64 return fAllocator();
68 ResourceRoster::ResourceRoster(void)
73 ResourceRoster::~ResourceRoster(void)
78 BField *
79 ResourceRoster::MakeFieldForType(const int32 &type, const char *data,
80 const size_t &length)
82 // temporary code until editors are done
83 switch (type) {
84 case B_MIME_STRING_TYPE:
85 return new StringPreviewField(data);
86 case B_GIF_FORMAT:
87 case B_PPM_FORMAT:
88 case B_TGA_FORMAT:
89 case B_BMP_FORMAT:
90 case B_TIFF_FORMAT:
91 case B_PNG_FORMAT:
92 case B_JPEG_FORMAT: {
93 BMemoryIO memio(data, length);
94 BBitmap *bitmap = BTranslationUtils::GetBitmap(&memio);
95 if (bitmap) {
96 BitmapPreviewField *field = new BitmapPreviewField(bitmap);
97 return field;
99 break;
101 default:
102 return NULL;
105 return NULL;
109 void
110 ResourceRoster::LoadEditors(void)
112 app_info info;
113 be_app->GetAppInfo(&info);
115 BDirectory dir;
116 BEntry entry(&info.ref);
117 entry.GetParent(&dir);
118 entry.SetTo(&dir, "addons");
119 dir.SetTo(&entry);
121 entry_ref ref;
122 dir.Rewind();
123 while (dir.GetNextRef(&ref) == B_OK) {
124 BPath path(&ref);
126 image_id addon = load_add_on(path.Path());
127 if (addon < 0)
128 continue;
130 char *temp;
131 if (get_image_symbol(addon, "description", B_SYMBOL_TYPE_DATA, (void **)(&temp)) != B_OK) {
132 unload_add_on(addon);
133 continue;
136 create_editor *createFunc;
137 if (get_image_symbol(addon, "instantiate_editor", B_SYMBOL_TYPE_TEXT, (void **)(&createFunc)) != B_OK) {
138 delete temp;
139 unload_add_on(addon);
140 continue;
143 if (createFunc && temp)
144 fList.AddItem(new EditorInfo(addon, temp, createFunc));
146 delete temp;
150 void
151 ResourceRoster::SpawnEditor(ResourceData *data, BHandler *handler)
153 // temporary code until editors are done
154 switch (data->GetType()) {
155 case B_STRING_TYPE:
156 case B_MIME_STRING_TYPE: {
157 StringEditor *strEd = new StringEditor(BRect(100, 100, 400, 200),
158 data, handler);
159 strEd->Show();
160 break;
162 case B_GIF_FORMAT:
163 case B_PPM_FORMAT:
164 case B_TGA_FORMAT:
165 case B_BMP_FORMAT:
166 case B_TIFF_FORMAT:
167 case B_PNG_FORMAT:
168 case B_JPEG_FORMAT: {
169 ImageEditor *imgEd = new ImageEditor(BRect(100, 100, 300, 200),
170 data, handler);
171 imgEd->Show();
172 break;
174 default:
175 break;