2 ** Trident V0.0 (08-Mar-02) by Chris Hodges <hodges@in.tum.de>
4 ** Project started: 08-Mar-02
10 #define USE_INLINE_STDARG
12 #include <proto/muimaster.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <proto/poseidon.h>
16 #include <proto/intuition.h>
17 #include <proto/graphics.h>
18 #include <proto/usbclass.h>
19 #include <proto/icon.h>
20 #include <proto/utility.h>
22 #include <workbench/startup.h>
25 #include "ActionClass.h"
26 #include "IconListClass.h"
27 #include "DevWinClass.h"
28 #include "CfgListClass.h"
32 #define TMPL_NUMERIC 2
33 #define TMPL_ARGUMENT 4
41 struct WBStartup
*_WBenchMsg
;
43 extern struct ExecBase
*SysBase
;
44 extern struct DosLibrary
*DOSBase
;
45 extern struct IntuitionBase
*IntuitionBase
;
46 extern struct Library
*UtilityBase
;
47 extern struct Library
*MUIMasterBase
;
49 extern struct Library
*IconBase
;
51 struct MUI_CustomClass
*ActionClass
= NULL
;
52 struct MUI_CustomClass
*IconListClass
= NULL
;
53 struct MUI_CustomClass
*DevWinClass
= NULL
;
54 struct MUI_CustomClass
*CfgListClass
= NULL
;
56 Object
*appobj
= NULL
;
57 Object
*mainwinobj
= NULL
;
58 Object
*actionobj
= NULL
;
59 BOOL registermode
= FALSE
;
61 static Object
*mi_about
;
62 static Object
*mi_aboutmui
;
63 static Object
*mi_help
;
64 static Object
*mi_online
;
65 static Object
*mi_offline
;
66 static Object
*mi_iconify
;
67 static Object
*mi_quit
;
68 static Object
*mi_saveerrors
;
69 static Object
*mi_flusherrors
;
70 static Object
*mi_savedevlist
;
71 static Object
*mi_loadprefs
;
72 static Object
*mi_saveprefs
;
73 static Object
*mi_saveprefsas
;
74 static Object
*mi_muiprefs
;
76 #define ARGS_REGMODE 0
81 static char *template = "REGISTERMODE/S,NOGUI/S,SAVE/S";
82 static IPTR ArgsArray
[ARGS_SIZEOF
];
83 static struct RDArgs
*ArgsHook
= NULL
;
84 static struct DiskObject
*IconObject
= NULL
;
85 static LONG NumericArgsBuffer
[32];
87 /* /// "GetToolTypes()" */
88 BOOL
GetToolTypes(void)
95 char *templatepos
= template;
99 IPTR
*argsptr
= ArgsArray
;
100 LONG
*numargsptr
= NumericArgsBuffer
;
102 if(!_WBenchMsg
) return(0);
103 wba
= _WBenchMsg
->sm_ArgList
;
105 dir
= CurrentDir(wba
->wa_Lock
);
106 if((IconObject
= GetDiskObject(wba
->wa_Name
)))
109 if(IconObject
->do_ToolTypes
)
116 if(*templatepos
== ',')
121 *bufpos
++ = *templatepos
++;
133 currtype
|= TMPL_SWITCH
;
136 currtype
|= TMPL_ARGUMENT
;
139 currtype
|= TMPL_NUMERIC
;
153 bufpos2
= currtemp
+ strlen(currtemp
);
161 *bufpos
++ = *bufpos2
++;
164 if((bufpos
= FindToolType(IconObject
->do_ToolTypes
, currkey
)))
166 if(currtype
& TMPL_SWITCH
)
170 if(currtype
& TMPL_NUMERIC
)
172 *numargsptr
= atoi(bufpos
);
173 *argsptr
= (IPTR
) numargsptr
++;
175 *argsptr
= (IPTR
) bufpos
;
180 if((currtype
& TMPL_ARGUMENT
) && (*argsptr
== 0L))
194 /* /// "CleanupClasses()" */
195 void CleanupClasses(void)
199 MUI_DeleteCustomClass(DevWinClass
);
204 MUI_DeleteCustomClass(ActionClass
);
209 MUI_DeleteCustomClass(IconListClass
);
210 IconListClass
= NULL
;
214 MUI_DeleteCustomClass(CfgListClass
);
220 /* /// "SetupClasses()" */
221 BOOL
SetupClasses(void)
223 DevWinClass
= MUI_CreateCustomClass(NULL
, MUIC_Window
, NULL
, sizeof(struct DevWinData
) , DevWinDispatcher
);
224 ActionClass
= MUI_CreateCustomClass(NULL
, MUIC_Group
, NULL
, sizeof(struct ActionData
) , ActionDispatcher
);
225 IconListClass
= MUI_CreateCustomClass(NULL
, MUIC_List
, NULL
, sizeof(struct IconListData
) , IconListDispatcher
);
226 CfgListClass
= MUI_CreateCustomClass(NULL
, MUIC_List
, NULL
, sizeof(struct CfgListData
) , CfgListDispatcher
);
228 if(ActionClass
&& IconListClass
&& DevWinClass
&& CfgListClass
)
240 MUI_DisposeObject(appobj
);
259 FreeDiskObject(IconObject
);
263 if(_WBenchMsg
&& str
)
265 struct EasyStruct errorReq
= { sizeof(struct EasyStruct
), 0, "Trident", NULL
, "Cancel" };
266 errorReq
.es_TextFormat
= str
;
267 EasyRequest(NULL
, &errorReq
, NULL
, NULL
);
272 CloseLibrary(MUIMasterBase
);
273 MUIMasterBase
= NULL
;
286 int main(int argc
, char *argv
[])
290 _WBenchMsg
= (struct WBStartup
*) argv
;
293 fail("Wrong or missing ToolTypes!");
296 if(!(ArgsHook
= ReadArgs(template, ArgsArray
, NULL
)))
298 fail("Wrong arguments!\n");
304 if(!(ps
= OpenLibrary("poseidon.library", 4)))
306 fail("Failed to open version 4 of poseidon.library.\n");
309 if(ArgsArray
[ARGS_NOGUI
])
311 if(ArgsArray
[ARGS_SAVE
])
313 InternalCreateConfig();
314 psdSaveCfgToDisk(NULL
, FALSE
);
316 IPTR cfgread
= FALSE
;
317 psdGetAttrs(PGA_STACK
, NULL
, PA_ConfigRead
, &cfgread
, TAG_DONE
);
320 psdLoadCfgFromDisk(NULL
);
328 if((ps
->lib_Version
== 4) && (ps
->lib_Revision
< 3))
330 fail("Sorry, this version of Trident requires at least version 4.3 of poseidon.library!\n");
334 struct Task
*thistask
;
336 thistask
= FindTask(NULL
);
337 stackfree
= ((IPTR
) thistask
->tc_SPUpper
) - ((IPTR
) thistask
->tc_SPLower
);
338 if(stackfree
< 16000)
340 fail("Trident needs at least 16KB of stack! Please change the tooltypes accordingly!\n");
345 IPTR cfgread
= FALSE
;
346 psdGetAttrs(PGA_STACK
, NULL
, PA_ConfigRead
, &cfgread
, TAG_DONE
);
349 psdLoadCfgFromDisk(NULL
);
354 registermode
= ArgsArray
[ARGS_REGMODE
];
356 if(!(MUIMasterBase
= OpenLibrary(MUIMASTER_NAME
,MUIMASTER_VMIN
)))
357 fail("Failed to open "MUIMASTER_NAME
". This application requires MUI!\n");
360 fail("Could not create custom classes.\n");
362 appobj
= ApplicationObject
,
363 MUIA_Application_Title
, __(MSG_APP_TITLE
),
364 MUIA_Application_Version
, __(MSG_APP_VERSION
),
365 MUIA_Application_Copyright
, (IPTR
) "©2002-2009 Chris Hodges",
366 MUIA_Application_Author
, (IPTR
) "Chris Hodges <chrisly@platon42.de>",
367 MUIA_Application_Description
, __(MSG_APP_DESC
),
368 MUIA_Application_Base
, "TRIDENT",
369 MUIA_Application_SingleTask
, TRUE
,
370 MUIA_Application_DiskObject
, IconObject
,
371 MUIA_Application_HelpFile
, "HELP:Poseidon.guide",
372 MUIA_Application_Menustrip
, MenustripObject
,
373 Child
, MenuObjectT(_(MSG_MENU_PROJECT
)),
374 Child
, mi_about
= MenuitemObject
,
375 MUIA_Menuitem_Title
, __(MSG_MENU_ABOUT
),
376 MUIA_Menuitem_Shortcut
, "?",
378 Child
, mi_aboutmui
= MenuitemObject
,
379 MUIA_Menuitem_Title
, __(MSG_MENU_ABOUTMUI
),
381 Child
, mi_help
= MenuitemObject
,
382 MUIA_Menuitem_Title
, __(MSG_MENU_HELP
),
384 Child
, MenuitemObject
,
385 MUIA_Menuitem_Title
, NM_BARLABEL
,
387 Child
, mi_online
= MenuitemObject
,
388 MUIA_Menuitem_Title
, __(MSG_MENU_ONLINE
),
389 MUIA_Menuitem_Shortcut
, __(MSG_MENU_SC_ONLINE
),
391 Child
, mi_offline
= MenuitemObject
,
392 MUIA_Menuitem_Title
, __(MSG_MENU_OFFLINE
),
393 MUIA_Menuitem_Shortcut
, __(MSG_MENU_SC_OFFLINE
),
395 Child
, MenuitemObject
,
396 MUIA_Menuitem_Title
, NM_BARLABEL
,
398 Child
, mi_iconify
= MenuitemObject
,
399 MUIA_Menuitem_Title
, __(MSG_MENU_ICONIFY
),
400 MUIA_Menuitem_Shortcut
, __(MSG_MENU_SC_ICONIFY
),
402 Child
, MenuitemObject
,
403 MUIA_Menuitem_Title
, NM_BARLABEL
,
405 Child
, mi_quit
= MenuitemObject
,
406 MUIA_Menuitem_Title
, __(MSG_MENU_QUIT
),
407 MUIA_Menuitem_Shortcut
, __(MSG_MENU_SC_QUIT
),
410 Child
, MenuObjectT(_(MSG_MENU_INFO
)),
411 Child
, mi_saveerrors
= MenuitemObject
,
412 MUIA_Menuitem_Title
, __(MSG_MENU_SAVELOG
),
414 Child
, mi_flusherrors
= MenuitemObject
,
415 MUIA_Menuitem_Title
, __(MSG_MENU_FLUSH
),
417 Child
, MenuitemObject
,
418 MUIA_Menuitem_Title
, NM_BARLABEL
,
420 Child
, mi_savedevlist
= MenuitemObject
,
421 MUIA_Menuitem_Title
, __(MSG_MENU_SAVEDEV
),
424 Child
, MenuObjectT(_(MSG_MENU_SETTINGS
)),
425 Child
, mi_loadprefs
= MenuitemObject
,
426 MUIA_Menuitem_Title
, __(MSG_MENU_LOAD
),
427 MUIA_Menuitem_Shortcut
, __(MSG_MENU_SC_LOAD
),
429 Child
, mi_saveprefs
= MenuitemObject
,
430 MUIA_Menuitem_Title
, __(MSG_MENU_SAVE
),
431 MUIA_Menuitem_Shortcut
, _(MSG_MENU_SC_SAVE
),
433 Child
, mi_saveprefsas
= MenuitemObject
,
434 MUIA_Menuitem_Title
, __(MSG_MENU_SAVEAS
),
435 MUIA_Menuitem_Shortcut
, __(MSG_MENU_SC_SAVEAS
),
437 Child
, MenuitemObject
,
438 MUIA_Menuitem_Title
, NM_BARLABEL
,
440 Child
, mi_muiprefs
= MenuitemObject
,
441 MUIA_Menuitem_Title
, __(MSG_MENU_MUISETTINGS
),
442 MUIA_Menuitem_Shortcut
, __(MSG_MENU_SC_MUISETTINGS
),
447 SubWindow
, mainwinobj
= WindowObject
,
448 MUIA_Window_ID
, MAKE_ID('M','A','I','N'),
449 MUIA_Window_Title
, __(MSG_WINDOW_TITLE
),
450 MUIA_HelpNode
, "usingtrident",
452 WindowContents
, actionobj
= NewObject(ActionClass
->mcc_Class
, 0, TAG_END
),
456 if(!appobj
) fail("Failed to create Application. Already running?\n");
461 DoMethod(mi_aboutmui
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
462 appobj
, 2, MUIM_Application_AboutMUI
, mainwinobj
);
463 DoMethod(mi_about
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
464 actionobj
, 1, MUIM_Action_About
);
465 DoMethod(mi_online
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
466 actionobj
, 1, MUIM_Action_Online
);
467 DoMethod(mi_offline
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
468 actionobj
, 1, MUIM_Action_Offline
);
469 DoMethod(mi_help
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
470 appobj
, 5, MUIM_Application_ShowHelp
, mainwinobj
, NULL
, "main", 0);
471 DoMethod(mi_iconify
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
472 appobj
, 3, MUIM_Set
, MUIA_Application_Iconified
, TRUE
);
473 DoMethod(mi_quit
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
474 appobj
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
476 DoMethod(mi_saveerrors
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
477 actionobj
, 1, MUIM_Action_SaveErrors
);
478 DoMethod(mi_flusherrors
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
479 actionobj
, 1, MUIM_Action_FlushErrors
);
480 DoMethod(mi_savedevlist
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
481 actionobj
, 1, MUIM_Action_SaveDeviceList
);
483 DoMethod(mi_loadprefs
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
484 actionobj
, 1, MUIM_Action_LoadPrefs
);
485 DoMethod(mi_saveprefs
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
486 actionobj
, 1, MUIM_Action_SavePrefs
);
487 DoMethod(mi_saveprefsas
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
488 actionobj
, 1, MUIM_Action_SavePrefsAs
);
489 DoMethod(mi_muiprefs
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
490 appobj
, 2, MUIM_Application_OpenConfigWindow
, 0);
492 DoMethod(mainwinobj
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
493 actionobj
, 1, MUIM_Action_UseQuit
);
494 DoMethod(appobj
, MUIM_Notify
, MUIA_Application_DoubleStart
, MUIV_EveryTime
,
495 actionobj
, 1, MUIM_Action_WakeUp
);
497 DoMethod(appobj
, MUIM_Application_Load
, MUIV_Application_Load_ENVARC
);
500 ** This is the ideal input loop for an object oriented MUI application.
501 ** Everything is encapsulated in classes, no return ids need to be used,
502 ** we just check if the program shall terminate.
503 ** Note that MUIM_Application_NewInput expects sigs to contain the result
504 ** from Wait() (or 0). This makes the input loop significantly faster.
513 get(appobj
, MUIA_Application_Iconified
, &iconify
);
514 set(mainwinobj
, MUIA_Window_Open
, TRUE
);
515 get(mainwinobj
, MUIA_Window_Open
, &isopen
);
516 if(!(isopen
|| iconify
))
517 fail("Couldn't open window! Maybe screen is too small. Try a higher resolution!\n");
519 sigmask
= 0;// FIXME 1L<<eventmsgport->mp_SigBit;
520 while(DoMethod(appobj
, MUIM_Application_NewInput
, &sigs
) != MUIV_Application_ReturnID_Quit
)
524 sigs
= Wait(sigs
| sigmask
| SIGBREAKF_CTRL_C
);
525 if(sigs
& SIGBREAKF_CTRL_C
)
529 set(mainwinobj
, MUIA_Window_Open
, FALSE
);
531 DoMethod(appobj
, MUIM_Application_Save
, MUIV_Application_Save_ENVARC
);
536 Locale_Deinitialize();
539 return(0); // never gets here, just to shut the compiler up