revert between 56095 -> 55830 in arch
[AROS.git] / workbench / classes / zune / aboutwindow / aboutwindow.c
blob40f51b427985c9533c8ee648809fd9d6ffa52a55
1 /*
2 Copyright © 2003-2004, The AROS Development Team. All rights reserved.
3 This file is part of the AboutWindow class, which is distributed under
4 the terms of version 2.1 of the GNU Lesser General Public License.
6 $Id$
7 */
9 #define MUIMASTER_YES_INLINE_STDARG
11 #include <exec/memory.h>
12 #include <utility/tagitem.h>
13 #include <dos/dos.h>
14 #include <libraries/mui.h>
15 #include <zune/iconimage.h>
17 #include <proto/exec.h>
18 #include <proto/muimaster.h>
19 #include <proto/intuition.h>
20 #include <proto/utility.h>
21 #include <proto/locale.h>
22 #include <proto/dos.h>
23 #include <clib/alib_protos.h> /* StrDup() */
25 #include <string.h>
27 #include "aboutwindow.h"
28 #include "aboutwindow_private.h"
30 #define CATCOMP_ARRAY
31 #include "strings.h"
33 /*** Locale Functions *******************************************************/
34 CONST_STRPTR MSG(struct Catalog *catalog, ULONG id)
36 if (catalog != NULL)
38 return GetCatalogStr(catalog, id, CatCompArray[id].cca_Str);
40 else
42 return CatCompArray[id].cca_Str;
46 #define _(id) MSG(catalog,id)
48 /*** Macros and Defines *****************************************************/
49 #define IGNORE ((APTR)(1UL))
51 /*** Utility ****************************************************************/
52 CONST_STRPTR Section2Name(struct Catalog *catalog, ULONG section)
54 switch (section)
56 case SID_PROGRAMMING:
57 return _(MSG_SECTION_PROGRAMMING);
59 case SID_TRANSLATING:
60 return _(MSG_SECTION_TRANSLATING);
62 default:
63 return NULL;
67 BOOL NamesToList
69 Object *list, struct TagItem *tags, struct AboutWindow_DATA *data
72 struct TagItem *tag = NULL, *tstate = tags;
73 BOOL success = TRUE;
74 IPTR section = SID_NONE;
75 CONST_STRPTR sectionName = NULL;
76 BOOL sectionFirst = TRUE;
77 STRPTR name;
78 STRPTR buffer;
79 ULONG length = 0;
81 if (tags == NULL) return FALSE;
83 while ((tag = NextTagItem(&tstate)) != NULL && success == TRUE)
85 switch (tag->ti_Tag)
87 case SECTION_ID:
88 section = tag->ti_Data;
89 sectionName = Section2Name(data->awd_Catalog, section);
91 if (sectionName != NULL)
93 sectionFirst
94 ? sectionFirst = FALSE
95 : DoMethod(list, MUIM_List_InsertSingle, (IPTR) "");
97 length = strlen(MUIX_B) + strlen(sectionName) + 1;
98 buffer = AllocPooled(data->awd_Pool, length);
99 if (buffer != NULL)
101 buffer[0] = '\0';
102 strcat(buffer, MUIX_B);
103 strcat(buffer, sectionName);
105 DoMethod
107 list, MUIM_List_InsertSingle,
108 (IPTR) buffer, MUIV_List_Insert_Bottom
111 else
113 success = FALSE;
114 break;
118 break;
120 case NAME_STRING:
121 name = (STRPTR) tag->ti_Data;
123 length = strlen(name) + 1;
124 if (sectionName != NULL) length += 4;
126 buffer = AllocPooled(data->awd_Pool, length);
127 if (buffer != NULL)
129 buffer[0] = '\0';
130 if (sectionName != NULL) strcat(buffer, " ");
131 strcat(buffer, name);
133 DoMethod
135 list, MUIM_List_InsertSingle,
136 (IPTR) buffer, MUIV_List_Insert_Bottom
139 else
141 success = FALSE;
142 break;
145 break;
149 return success;
152 /*** Methods ****************************************************************/
153 Object *AboutWindow__OM_NEW
155 Class *CLASS, Object *self, struct opSet *message
158 struct AboutWindow_DATA *data = NULL;
159 struct TagItem *tag = NULL,
160 *tstate = message->ops_AttrList,
161 *authorsTags = NULL,
162 *sponsorsTags = NULL;
163 struct Catalog *catalog = NULL;
164 APTR pool;
165 Object *rootGroup = NULL,
166 *imageGroup = NULL,
167 *imageObject = NULL,
168 *versionObject = NULL,
169 *copyrightObject = NULL,
170 *descriptionGroup = NULL,
171 *descriptionObject = NULL,
172 *authorsList = NULL,
173 *sponsorsList = NULL;
175 STRPTR title = NULL,
176 versionNumber = NULL,
177 versionDate = NULL,
178 versionExtra = NULL,
179 description = NULL,
180 copyright = NULL;
182 CONST_STRPTR pages[] = { NULL, NULL, NULL };
183 UBYTE nextPage = 0;
185 /* Allocate memory pool ------------------------------------------------*/
186 pool = CreatePool(MEMF_ANY, 4096, 4096);
187 if (pool == NULL) return NULL;
189 /* Initialize locale ---------------------------------------------------*/
190 catalog = OpenCatalogA
192 NULL, "System/Classes/Zune/AboutWindow.catalog", NULL
195 /* Parse initial attributes --------------------------------------------*/
196 while ((tag = NextTagItem(&tstate)) != NULL)
198 switch (tag->ti_Tag)
200 case MUIA_AboutWindow_Image:
201 imageObject = (Object *) tag->ti_Data;
202 break;
204 case MUIA_AboutWindow_Title:
205 title = StrDup((STRPTR) tag->ti_Data);
206 if (title == NULL) title = IGNORE;
207 break;
209 case MUIA_AboutWindow_Version_Number:
210 versionNumber = StrDup((STRPTR) tag->ti_Data);
211 if (versionNumber == NULL) versionNumber = IGNORE;
212 break;
214 case MUIA_AboutWindow_Version_Date:
215 versionDate = StrDup((STRPTR) tag->ti_Data);
216 if (versionDate == NULL) versionDate = IGNORE;
217 break;
219 case MUIA_AboutWindow_Version_Extra:
220 versionExtra = StrDup((STRPTR) tag->ti_Data);
221 if (versionExtra == NULL) versionExtra = IGNORE;
222 break;
224 case MUIA_AboutWindow_Copyright:
225 copyright = StrDup((STRPTR) tag->ti_Data);
226 if (copyright == NULL) copyright = IGNORE;
227 break;
229 case MUIA_AboutWindow_Description:
230 description = StrDup((STRPTR) tag->ti_Data);
231 if (description == NULL) description = IGNORE;
232 break;
234 case MUIA_AboutWindow_Authors:
235 authorsTags = (struct TagItem *) tag->ti_Data;
236 break;
238 case MUIA_AboutWindow_Sponsors:
239 sponsorsTags = (struct TagItem *) tag->ti_Data;
240 break;
242 default:
243 continue; /* Don't supress non-processed tags */
246 tag->ti_Tag = TAG_IGNORE;
249 /* Setup image ---------------------------------------------------------*/
250 if (imageObject == NULL)
252 TEXT path[512], program[1024]; path[0] = '\0'; program[0] = '\0';
254 if (GetProgramName(program, 1024))
256 strlcat(path, "PROGDIR:", 512);
257 strlcat(path, FilePart(program), 512);
258 imageObject = (Object *)IconImageObject,
259 MUIA_IconImage_File, (IPTR) path,
260 End;
263 if (imageObject == NULL)
265 imageObject = HVSpace;
269 /* Setup pages ---------------------------------------------------------*/
270 if (authorsTags != NULL)
272 pages[nextPage] = _(MSG_AUTHORS);
273 nextPage++;
276 if (sponsorsTags != NULL)
278 pages[nextPage] = _(MSG_SPONSORS);
279 nextPage++;
282 self = (Object *) DoSuperNewTags
284 CLASS, self, NULL,
286 MUIA_Window_Activate, TRUE,
287 MUIA_Window_NoMenus, TRUE,
288 MUIA_Window_Height, MUIV_Window_Height_Visible(25),
289 MUIA_Window_Width, MUIV_Window_Width_Visible(25),
291 WindowContents, (IPTR) VGroup,
292 GroupSpacing(6),
294 Child, (IPTR) (imageGroup = (Object *)HGroup,
295 MUIA_Weight, 0,
297 Child, (IPTR) HVSpace,
298 Child, (IPTR) imageObject,
299 Child, (IPTR) HVSpace,
300 End),
301 Child, (IPTR) (versionObject = (Object *)TextObject,
302 MUIA_Text_PreParse, (IPTR) MUIX_C,
303 MUIA_Text_Contents, (IPTR) NULL,
304 End),
305 Child, (IPTR) (copyrightObject = (Object *)TextObject,
306 MUIA_Text_PreParse, (IPTR) MUIX_C,
307 MUIA_Text_Contents, (IPTR) NULL,
308 End),
309 Child, (IPTR) (descriptionGroup = (Object *)VGroup,
310 Child, (IPTR) VSpace(6),
311 Child, (IPTR) (descriptionObject = (Object *)TextObject,
312 MUIA_Text_PreParse, (IPTR) MUIX_I MUIX_C,
313 MUIA_Text_Contents, (IPTR) NULL,
314 End),
315 End),
316 Child, (IPTR) VSpace(6),
317 Child, (IPTR) RegisterGroup(pages),
318 Child, (IPTR) ListviewObject,
319 MUIA_Listview_List, (IPTR) (authorsList = (Object *)ListObject,
320 ReadListFrame,
321 End),
322 End,
323 Child, (IPTR) ListviewObject,
324 MUIA_Listview_List, (IPTR) (sponsorsList = (Object *)ListObject,
325 ReadListFrame,
326 End),
327 End,
328 End,
329 End,
331 TAG_MORE, (IPTR) message->ops_AttrList
334 if (self == NULL) goto error;
336 data = INST_DATA(CLASS, self);
337 data->awd_Catalog = catalog;
338 data->awd_Pool = pool;
339 data->awd_RootGroup = rootGroup;
340 data->awd_ImageGroup = imageGroup;
341 data->awd_ImageObject = imageObject;
342 data->awd_VersionObject = versionObject;
343 data->awd_CopyrightObject = copyrightObject;
344 data->awd_DescriptionGroup = descriptionGroup;
345 data->awd_DescriptionObject = descriptionObject;
346 data->awd_Title = title;
347 data->awd_VersionNumber = versionNumber;
348 data->awd_VersionDate = versionDate;
349 data->awd_VersionExtra = versionExtra;
350 data->awd_Copyright = copyright;
351 data->awd_Description = description;
353 if (authorsTags != NULL) NamesToList(authorsList, authorsTags, data);
354 if (sponsorsTags != NULL) NamesToList(sponsorsList, sponsorsTags, data);
356 /* Setup notifications */
357 DoMethod
359 self, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
360 (IPTR) self, 2, MUIA_Window_Open, FALSE
363 return self;
365 error:
366 if (catalog != NULL) CloseCatalog(catalog);
368 return NULL;
371 IPTR AboutWindow__MUIM_Window_Setup
373 Class *CLASS, Object *self, Msg message
376 struct AboutWindow_DATA *data = INST_DATA(CLASS, self);
377 struct Catalog *catalog = data->awd_Catalog;
378 STRPTR string = NULL;
380 if (!DoSuperMethodA(CLASS, self, message)) return FALSE;
382 /*= Setup window title =================================================*/
384 STRPTR buffer = NULL;
385 ULONG length = 0;
387 string = data->awd_Title;
388 if (string == NULL)
390 GET(self, MUIA_AboutWindow_Title, &string);
392 if (string != IGNORE)
394 if (string == NULL)
396 GET(_app(self), MUIA_Application_Title, &string);
399 if (string != NULL)
401 length = strlen(string) + strlen(_(MSG_ABOUT)) + 2; /* space + newline */
402 buffer = AllocVec(length, MEMF_ANY);
404 if (buffer != NULL)
406 buffer[0] = '\0';
407 strlcat(buffer, _(MSG_ABOUT), length);
408 strlcat(buffer, " ", length);
409 strlcat(buffer, string, length);
411 set(self, MUIA_Window_Title, buffer);
413 FreeVec(buffer);
420 /*= Setup image ========================================================*/
421 if (data->awd_ImageObject == NULL)
423 DoMethod(data->awd_RootGroup, OM_REMMEMBER, (IPTR) data->awd_ImageGroup);
426 /*= Setup version ======================================================*/
428 The version string will have the format:
429 MUIX_B"<title>"MUIX_N" <version> (<date>) [<extra>]"
432 STRPTR title = data->awd_Title,
433 versionNumber = data->awd_VersionNumber,
434 versionDate = data->awd_VersionDate,
435 versionExtra = data->awd_VersionExtra,
436 buffer = NULL;
437 ULONG length = 0;
439 /*- Setup default values -------------------------------------------*/
440 if (title == NULL)
442 GET(_app(self), MUIA_Application_Title, &title);
445 if (versionNumber == NULL)
447 GET(_app(self), MUIA_Application_Version_Number, &versionNumber);
450 if (versionDate == NULL)
452 GET(_app(self), MUIA_Application_Version_Date, &versionDate);
455 if (versionExtra == NULL)
457 GET(_app(self), MUIA_Application_Version_Extra, &versionExtra);
460 /* Simplify later checks a little */
461 if (title == IGNORE) title = NULL;
462 if (versionNumber == IGNORE) versionNumber = NULL;
463 if (versionDate == IGNORE) versionDate = NULL;
464 if (versionExtra == IGNORE) versionExtra = NULL;
466 /*- Calculate length -----------------------------------------------*/
467 if (title != NULL)
469 length += strlen(MUIX_B) + strlen(title) + strlen(MUIX_N) + 1;
472 if (versionNumber != NULL)
474 length += 1 /* space */ + strlen(versionNumber);
477 if (versionDate != NULL)
479 length += 1 /* space */ + 1 /* ( */ + strlen(versionDate) + 1 /* ) */;
482 if (versionExtra != NULL)
484 length += 1 /* space */ + 1 /* [ */ + strlen(versionExtra) + 1 /* ] */;
487 /*- Setup version object -------------------------------------------*/
488 if (length > 0)
490 /*- Allocate memory --------------------------------------------*/
491 buffer = AllocVec(length, MEMF_ANY);
493 if (buffer != NULL)
495 buffer[0] = '\0';
497 /*- Generate text ------------------------------------------*/
498 if (title != NULL)
500 strlcat(buffer, MUIX_B, length);
501 strlcat(buffer, title, length);
502 strlcat(buffer, MUIX_N, length);
505 if (versionNumber != NULL)
507 strlcat(buffer, " ", length);
508 strlcat(buffer, versionNumber, length);
511 if (versionDate != NULL)
513 strlcat(buffer, " (", length);
514 strlcat(buffer, versionDate, length);
515 strlcat(buffer, ")", length);
518 if (versionExtra != NULL)
520 strlcat(buffer, " [", length);
521 strlcat(buffer, versionExtra, length);
522 strlcat(buffer, "]", length);
525 set(data->awd_VersionObject, MUIA_Text_Contents, buffer);
526 FreeVec(buffer); /* don't need it anymore */
528 else
530 DoMethod
532 data->awd_RootGroup, OM_REMMEMBER, (IPTR) data->awd_VersionObject
538 /*= Setup copyright ====================================================*/
539 if (data->awd_Copyright == NULL)
541 GET(_app(self), MUIA_Application_Copyright, &data->awd_Copyright);
544 if (data->awd_Copyright != IGNORE && data->awd_Copyright != NULL)
546 SET(data->awd_CopyrightObject, MUIA_Text_Contents, data->awd_Copyright);
548 else
550 DoMethod(data->awd_RootGroup, OM_REMMEMBER, (IPTR) data->awd_CopyrightObject);
553 /*= Setup description ==================================================*/
554 if (data->awd_Description == NULL)
556 GET(_app(self), MUIA_Application_Description, &data->awd_Description);
559 if (data->awd_Description != IGNORE && data->awd_Description != NULL)
563 data->awd_DescriptionObject,
564 MUIA_Text_Contents, data->awd_Description
567 else
569 DoMethod
571 data->awd_RootGroup, OM_REMMEMBER, (IPTR) data->awd_DescriptionGroup
575 /* We no longer need to know whether to IGNORE or not */
576 if (data->awd_Title == IGNORE) data->awd_Title = NULL;
577 if (data->awd_VersionNumber == IGNORE) data->awd_VersionNumber = NULL;
578 if (data->awd_VersionDate == IGNORE) data->awd_VersionDate = NULL;
579 if (data->awd_VersionExtra == IGNORE) data->awd_VersionExtra = NULL;
580 if (data->awd_Copyright == IGNORE) data->awd_Copyright = NULL;
581 if (data->awd_Description == IGNORE) data->awd_Description = NULL;
583 return TRUE;
586 IPTR AboutWindow__OM_DISPOSE
588 Class *CLASS, Object *self, Msg message
591 struct AboutWindow_DATA *data = INST_DATA(CLASS, self);
592 UBYTE i;
593 APTR ptrs[] =
595 data->awd_Title, data->awd_VersionNumber, data->awd_VersionDate,
596 data->awd_VersionExtra, data->awd_Copyright, data->awd_VersionExtra
599 for (i = 0; i < (sizeof(ptrs) / sizeof(APTR)); i++)
601 if (ptrs[i] != NULL) FreeVec(ptrs[i]);
604 if (data->awd_Pool != NULL) DeletePool(data->awd_Pool);
606 if (data->awd_Catalog != NULL) CloseCatalog(data->awd_Catalog);
608 return DoSuperMethodA(CLASS, self, message);