Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / system / AboutAROS / aboutaros.c
blobc7d93cf2b195162f2f33a5199da3fa27cbc31e81
1 /*
2 Copyright © 2003-2008, The AROS Development Team. All rights reserved.
3 This file is part of the About program, which is distributed under
4 the terms of version 2 of the GNU General Public License.
6 $Id$
7 */
9 #define MUIMASTER_YES_INLINE_STDARG
11 #include <aros/debug.h>
12 #include <aros/build.h>
13 #include <aros/inquire.h>
14 #include <exec/types.h>
15 #include <utility/tagitem.h>
16 #include <libraries/mui.h>
18 #include <proto/aros.h>
19 #include <proto/exec.h>
20 #include <proto/dos.h>
21 #include <proto/intuition.h>
22 #include <proto/utility.h>
23 #include <proto/muimaster.h>
24 #include <proto/workbench.h>
26 #include <zune/aboutwindow.h>
27 #include <zune/customclasses.h>
29 #include <stdio.h>
30 #include <string.h>
32 #include "aboutaros.h"
33 #include "locale.h"
34 #include "logotype.h"
36 #include "authors.h"
37 #include "sponsors.h"
38 #include "acknowledgements.h"
39 #include "svnrev.h"
41 #define VERSION "$VER: AboutAROS 0.1 ("ADATE") ©AROS Dev Team"
43 #define WINDOW_BG ((IPTR) "2:00000000,00000000,00000000")
44 #define REGISTER_BG ((IPTR) "7:V,00000000,92000000,91000000-00000000,82000000,81000000")
45 #define LIST_BG ((IPTR) "2:00000000,82000000,81000000")
47 #define SETUP_INST_DATA struct AboutAROS_DATA *data = INST_DATA(CLASS, self)
49 /*** Private methods ********************************************************/
50 #define MUIM_AboutAROS_ShowLicense (TAG_USER | 0x20000000)
52 /*** Instance Data **********************************************************/
53 struct AboutAROS_DATA
55 Object *aad_Window;
56 APTR aad_Pool;
59 /*** Utility Functions ******************************************************/
60 STRPTR Section2Name(ULONG section)
62 switch (section)
64 case SID_COORDINATION: return _(MSG_SECTION_COORDINATION);
65 case SID_EVANGELISM: return _(MSG_SECTION_EVANGELISM);
66 case SID_HIDD: return _(MSG_SECTION_HIDD);
67 case SID_INTUITION: return _(MSG_SECTION_INTUITION);
68 case SID_GRAPHICS: return _(MSG_SECTION_GRAPHICS);
69 case SID_SHELL_COMMANDS: return _(MSG_SECTION_SHELL_COMMANDS);
70 case SID_WORKBENCH: return _(MSG_SECTION_WORKBENCH);
71 case SID_TOOLS: return _(MSG_SECTION_TOOLS);
72 case SID_PREFERENCES: return _(MSG_SECTION_PREFERENCES);
73 case SID_BGUI: return _(MSG_SECTION_BGUI);
74 case SID_ZUNE: return _(MSG_SECTION_ZUNE);
75 case SID_KERNEL: return _(MSG_SECTION_KERNEL);
76 case SID_DOS: return _(MSG_SECTION_DOS);
77 case SID_NETWORKING: return _(MSG_SECTION_NETWORK);
78 case SID_LIBC_POSIX: return _(MSG_SECTION_LIBC_POSIX);
79 case SID_DOCUMENTATION: return _(MSG_SECTION_DOCUMENTATION);
80 case SID_TRANSLATION: return _(MSG_SECTION_TRANSLATION);
81 case SID_ARTISTRY: return _(MSG_SECTION_ARTISTRY);
82 case SID_WEBSITE: return _(MSG_SECTION_WEBSITE);
83 case SID_DATATYPES: return _(MSG_SECTION_DATATYPES);
84 default: return NULL;
88 BOOL NamesToList
90 Object *list, struct TagItem *tags, struct AboutAROS_DATA *data
93 const struct TagItem *tstate = tags;
94 struct TagItem *tag = NULL;
95 BOOL success = TRUE;
96 IPTR section = SID_NONE;
97 STRPTR sectionName = NULL;
98 BOOL sectionFirst = TRUE;
99 STRPTR name;
100 STRPTR buffer;
101 ULONG length = 0;
103 if (tags == NULL) return FALSE;
105 while ((tag = NextTagItem(&tstate)) != NULL && success == TRUE)
107 switch (tag->ti_Tag)
109 case SECTION_ID:
110 section = tag->ti_Data;
111 sectionName = Section2Name(section);
113 if (sectionName != NULL)
115 sectionFirst
116 ? sectionFirst = FALSE
117 : DoMethod
119 list, MUIM_List_InsertSingle, (IPTR) "",
120 MUIV_List_Insert_Bottom
123 length = strlen(MUIX_B) + strlen(sectionName) + 1;
124 buffer = AllocPooled(data->aad_Pool, length);
125 if (buffer != NULL)
127 buffer[0] = '\0';
128 strcat(buffer, MUIX_B);
129 strcat(buffer, sectionName);
131 DoMethod
133 list, MUIM_List_InsertSingle,
134 (IPTR) buffer, MUIV_List_Insert_Bottom
137 else
139 success = FALSE;
140 break;
144 break;
146 case NAME_STRING:
147 name = (STRPTR) tag->ti_Data;
149 length = strlen(name) + 1;
150 if (sectionName != NULL) length += 4;
152 buffer = AllocPooled(data->aad_Pool, length);
153 if (buffer != NULL)
155 buffer[0] = '\0';
156 if (sectionName != NULL) strcat(buffer, " ");
157 strcat(buffer, name);
159 DoMethod
161 list, MUIM_List_InsertSingle,
162 (IPTR) buffer, MUIV_List_Insert_Bottom
165 else
167 success = FALSE;
168 break;
171 break;
175 return success;
178 /*** Methods ****************************************************************/
179 Object *AboutAROS__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
181 Object *window,
182 *licenseButton,
183 *authorsList,
184 *sponsorsList,
185 *acknowledgementsList;
187 STRPTR pages[4] = { NULL };
188 STRPTR str_builddate;
189 STRPTR str_variant;
190 STRPTR str_arosarch;
191 STRPTR str_buildtype;
192 BOOL showLogotype;
193 BPTR lock;
194 APTR pool;
196 /* Allocate memory pool ------------------------------------------------*/
197 pool = CreatePool(MEMF_ANY, 4096, 4096);
198 if (pool == NULL) return NULL;
200 /* Check if the logotype is available ----------------------------------*/
201 if ((lock = Lock(LOGOTYPE_IMAGE, ACCESS_READ)) != NULL)
203 showLogotype = TRUE;
204 UnLock(lock);
206 else
208 showLogotype = FALSE;
211 /* Retrieve the build date and the variant name ------------------------*/
212 ArosInquire(AI_ArosBuildDate, (IPTR) &str_builddate,
213 AI_ArosVariant, (IPTR) &str_variant,
214 AI_ArosArchitecture, (IPTR) &str_arosarch,
215 TAG_DONE);
217 str_buildtype = AllocPooled(pool, strlen(_(MSG_BUILD_TYPE)) + strlen(str_arosarch) + 1);
218 sprintf(str_buildtype, _(MSG_BUILD_TYPE), str_arosarch);
220 /* Initialize page labels ----------------------------------------------*/
221 pages[0] = _(MSG_PAGE_AUTHORS);
222 pages[1] = _(MSG_PAGE_SPONSORS);
223 pages[2] = _(MSG_PAGE_ACKNOWLEDGEMENTS);
225 /* Create application and window objects -------------------------------*/
226 self = (Object *) DoSuperNewTags
228 CLASS, self, NULL,
230 MUIA_Application_Title, __(MSG_TITLE),
231 MUIA_Application_Version, (IPTR)VERSION,
232 MUIA_Application_Copyright, (IPTR)"© 2006, The AROS Development Team",
233 MUIA_Application_Description, __(MSG_TITLE),
234 MUIA_Application_Base, (IPTR) "ABOUTAROS",
235 SubWindow, (IPTR) (window = (Object *)WindowObject,
236 MUIA_Window_Title, __(MSG_TITLE),
237 MUIA_Window_Width, MUIV_Window_Width_MinMax(0),
238 MUIA_Window_NoMenus, TRUE,
239 MUIA_Window_Activate, TRUE,
240 MUIA_Window_ID, MAKE_ID('A','B','W','N'),
241 WindowContents, (IPTR) VGroup,
242 InnerSpacing(0, 0),
243 GroupSpacing(2),
244 MUIA_Background, WINDOW_BG,
246 Child, showLogotype
247 ? (IPTR) ImageObject,
248 MUIA_Image_Spec, (IPTR) "3:"LOGOTYPE_IMAGE,
250 : (IPTR) TextObject,
251 MUIA_Font, MUIV_Font_Fixed,
252 MUIA_Text_PreParse, (IPTR) "\0333\033b\033c",
253 MUIA_Text_Contents, (IPTR) LOGOTYPE_ASCII,
254 MUIA_Weight, 0,
257 Child, (IPTR) VSpace(4),
258 Child, (IPTR) HGroup,
259 InnerSpacing(0,0),
261 GroupSpacing(6),
262 Child, (IPTR) HVSpace,
263 Child, (IPTR) TextObject,
264 MUIA_Font, MUIV_Font_Big,
265 MUIA_Text_PreParse, (IPTR) "\0333\033b",
266 MUIA_Text_Contents, (IPTR) str_buildtype,
267 MUIA_Weight, 0,
268 End,
270 Child, (IPTR) TextObject,
271 MUIA_Font, MUIV_Font_Big,
272 MUIA_Text_PreParse, (IPTR) "\0333\033b",
273 MUIA_Text_Contents, (IPTR) str_variant,
274 MUIA_Weight, 0,
275 End,
276 Child, (IPTR) TextObject,
277 MUIA_Font, MUIV_Font_Big,
278 MUIA_Text_PreParse, (IPTR) "\0333\033b",
279 MUIA_Text_Contents, (IPTR) str_builddate,
280 MUIA_Weight, 0,
281 End,
282 Child, (IPTR) TextObject,
283 MUIA_Font, MUIV_Font_Big,
284 MUIA_Text_PreParse, (IPTR) "\0333\033b",
285 MUIA_Text_Contents, (IPTR) "SVN: " SVNREV,
286 MUIA_Weight, 0,
287 End,
288 Child, (IPTR) HVSpace,
289 End,
290 Child, (IPTR) VSpace(4),
291 Child, (IPTR) TextObject,
292 MUIA_Text_PreParse, (IPTR) "\0333\033c",
293 MUIA_Text_Contents, __(MSG_COPYRIGHT),
294 End,
295 Child, (IPTR) HGroup,
296 InnerSpacing(0,0),
297 GroupSpacing(0),
299 Child, (IPTR) HVSpace,
300 Child, (IPTR) TextObject,
301 MUIA_Text_PreParse, (IPTR) "\0333",
302 MUIA_Text_Contents, __(MSG_LICENSE_1),
303 MUIA_Weight, 0,
304 End,
305 Child, (IPTR) TextObject,
306 MUIA_Text_Contents, (IPTR) " ",
307 MUIA_Weight, 0,
308 End,
309 Child, (IPTR) (licenseButton = (Object *)TextObject,
310 MUIA_InputMode, MUIV_InputMode_RelVerify,
311 MUIA_Text_PreParse, (IPTR) "\0333\033u",
312 MUIA_Text_Contents, __(MSG_LICENSE_2),
313 MUIA_Weight, 0,
314 End),
315 Child, (IPTR) TextObject,
316 MUIA_Text_PreParse, (IPTR) "\0333",
317 MUIA_Text_Contents, __(MSG_LICENSE_3),
318 MUIA_Weight, 0,
319 End,
320 Child, (IPTR) HVSpace,
321 End,
322 Child, (IPTR) TextObject,
323 MUIA_Text_PreParse, (IPTR) "\0333\033c",
324 MUIA_Text_Contents, __(MSG_MORE_INFORMATION),
325 End,
326 Child, (IPTR) VSpace(4),
327 Child, (IPTR) VGroup,
328 InnerSpacing(4,4),
330 Child, (IPTR) RegisterGroup(pages),
331 MUIA_Background, REGISTER_BG,
333 Child, (IPTR) ListviewObject,
334 MUIA_Listview_List, (IPTR) (authorsList = (Object *)ListObject,
335 TextFrame,
336 MUIA_Background, LIST_BG,
337 End),
338 End,
339 Child, (IPTR) ListviewObject,
340 MUIA_Listview_List, (IPTR) (sponsorsList = (Object *)ListObject,
341 TextFrame,
342 MUIA_Background, LIST_BG,
343 End),
344 End,
345 Child, (IPTR) ListviewObject,
346 MUIA_Listview_List, (IPTR) (acknowledgementsList = (Object *)ListObject,
347 TextFrame,
348 MUIA_Background, LIST_BG,
349 End),
350 End,
351 End,
352 End,
353 End,
354 End),
356 TAG_DONE
359 if (self != NULL)
361 SETUP_INST_DATA;
363 data->aad_Window = window;
364 data->aad_Pool = pool;
366 /*-- Initialize lists --------------------------------------------------*/
367 NamesToList(authorsList, AUTHORS, data);
368 NamesToList(sponsorsList, SPONSORS, data);
370 DoMethod
372 acknowledgementsList, MUIM_List_Insert,
373 (IPTR) ACKNOWLEDGEMENTS, ACKNOWLEDGEMENTS_SIZE, MUIV_List_Insert_Top
376 /*-- Setup notifications -----------------------------------------------*/
377 DoMethod
379 window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
380 (IPTR) self, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
383 DoMethod
385 licenseButton, MUIM_Notify, MUIA_Pressed, FALSE,
386 (IPTR) self, 1, MUIM_AboutAROS_ShowLicense
390 return self;
393 IPTR AboutAROS__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
395 SETUP_INST_DATA;
397 if (data->aad_Pool != NULL) DeletePool(data->aad_Pool);
399 return DoSuperMethodA(CLASS, self, message);
402 IPTR AboutAROS__MUIM_Application_Execute(Class *CLASS, Object *self, Msg message)
404 SETUP_INST_DATA;
406 SET(data->aad_Window, MUIA_Window_Open, TRUE);
407 DoSuperMethodA(CLASS, self, message);
408 SET(data->aad_Window, MUIA_Window_Open, FALSE);
410 return 0;
413 IPTR AboutAROS__MUIM_AboutAROS_ShowLicense(Class *CLASS, Object *self, Msg message)
415 OpenWorkbenchObject("HELP:LICENSE", TAG_DONE);
417 return 0;
420 /*** Setup ******************************************************************/
421 ZUNE_CUSTOMCLASS_4
423 AboutAROS, NULL, MUIC_Application, NULL,
424 OM_NEW, struct opSet *,
425 OM_DISPOSE, Msg,
426 MUIM_Application_Execute, Msg,
427 MUIM_AboutAROS_ShowLicense, Msg