home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Musik / Misc / Amster / Source / gui.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-27  |  19.8 KB  |  611 lines

  1. /*
  2. ** GUI Functions
  3. */
  4.  
  5. #include "include/config.h"
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <stdarg.h>
  10. #include <string.h>
  11.  
  12. #include <exec/memory.h>
  13.  
  14. #include <proto/asl.h>
  15. #include <proto/dos.h>
  16. #include <proto/icon.h>
  17. #include <proto/utility.h>
  18.  
  19. #include <libraries/gadtools.h>
  20. #include <libraries/asl.h>
  21.  
  22. #include "include/mui.h"
  23. #include <MUI/Lamp_mcc.h>
  24. #include <MUI/NListview_mcc.h>
  25.  
  26. #include "include/gui.h"
  27. #include "include/protos.h"
  28. #include "include/napster.h"
  29. #include "include/transfer.h"
  30. #include "include/download.h"
  31. #include "include/upload.h"
  32. #include "include/prefs.h"
  33. #include "include/info.h"
  34. #include "include/msg.h"
  35. #include "include/navigator.h"
  36. #include "include/rexx.h"
  37. #include "include/search.h"
  38. #include "include/share.h"
  39. #include "include/panel.h"
  40. #include "include/chat.h"
  41. #include "include/about.h"
  42. #include "include/thread.h"
  43. #include "include/url.h"
  44. #include "amster_Cat.h"
  45.  
  46. struct Library *MUIMasterBase=0;
  47. struct Library *NListBase=0;
  48. struct Library *LampBase=0;
  49. struct guidata mygui;
  50. struct guidata *gui = &mygui;
  51. int gui_napon=0;
  52. int gui_napcon=0;
  53.  
  54. void gui_free(void);
  55. int gui_setup(void);
  56. MUIF gui_handle(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) u_long *id);
  57. void gui_about(void);
  58. void gui_appicon(int t);
  59.  
  60. struct Hook handleHook = {{0,0}, &gui_handle, NULL, NULL};
  61.  
  62.  
  63. void gui_run(unsigned long tcpsig)
  64. {
  65.     ULONG sigs=0;
  66.  
  67.     memset(gui,0,sizeof(struct guidata));
  68.     if (gui_setup()) {
  69.         prf_event(PRFE_STARTUP);
  70.         DoMethod(gui->shwin, SHARE_LOAD);
  71.         while (1) {
  72.             while (DoMethod(gui->app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit) {
  73.                 if (sigs) {
  74.                     sigs = Wait(sigs|SIGBREAKF_CTRL_C|tcpsig|th_sigmask);
  75.                     if(sigs&SIGBREAKF_CTRL_C) break;
  76.                     if(sigs&tcpsig) nap_listen();
  77.                     if(sigs&th_sigmask) th_poll();
  78.                 }
  79.             }
  80.             if (!dl_count) break;
  81.             if (dl_count && MUI_Request(gui->app,gui->win,0L,
  82.                                        (char *)MSG_REALLYQUIT_TITLE,
  83.                                        (char *)MSG_REALLYQUIT_GAD,
  84.                                        (char *)MSG_REALLYQUIT)) break;
  85.         }
  86.         prf_event(PRFE_EXIT);
  87.         if (prf->autosave && sharechanged) DoMethod(gui->shwin, SHARE_SAVE);
  88.         if (prf->ServerList > 0 && ServerListChanged) DoMethod(gui->WI_Navigator, NAVI_SAVE);
  89.         if (gui_napon || gui_napcon) nap_logout();
  90.     }
  91.     gui_free();
  92. }
  93.  
  94.  
  95. void gui_free(void)
  96. {
  97.     gui_appicon(-1);
  98.     if (gui->app) MUI_DisposeObject(gui->app);
  99.     lamp_dispose();
  100.     if (gui->url_mcc) MUI_DeleteCustomClass(gui->url_mcc);
  101.     if (gui->msg_mcc) MUI_DeleteCustomClass(gui->msg_mcc);
  102.     if (gui->info_mcc) MUI_DeleteCustomClass(gui->info_mcc);
  103.     if (gui->about_mcc) MUI_DeleteCustomClass(gui->about_mcc);
  104.     if (gui->prf_mcc) MUI_DeleteCustomClass(gui->prf_mcc);
  105.     if (gui->dl_mcc) MUI_DeleteCustomClass(gui->dl_mcc);
  106.     if (gui->ul_mcc) MUI_DeleteCustomClass(gui->ul_mcc);
  107.     if (gui->share_mcc) MUI_DeleteCustomClass(gui->share_mcc);
  108.     if (gui->search_mcc) MUI_DeleteCustomClass(gui->search_mcc);
  109.     if (gui->panel_mcc) MUI_DeleteCustomClass(gui->panel_mcc);
  110.     if (gui->chat_mcc) MUI_DeleteCustomClass(gui->chat_mcc);
  111.     if (gui->navi_mcc) MUI_DeleteCustomClass(gui->navi_mcc);
  112.     if (MUIMasterBase) CloseLibrary(MUIMasterBase);
  113. }
  114.  
  115.  
  116. int gui_setup(void)
  117. {
  118.     long winopen;
  119.     u_long *MI_Navigator, *MI_Connect, *MI_ConnectTo, *MI_Reconnect, *MI_Disconnect;
  120.     u_long *aboutmenu, *muimenu, *helpmenu, *hidemenu, *quitmenu;
  121.     u_long *openmenu, *savemenu, *saveasmenu;
  122.     u_long *debugmenu, *dlmenu, *ulmenu, *sharemenu, *usermenu, *chatmenu;
  123.     u_long *muiprfmenu, *prfmenu, *MI_LastSaved, *saveprfmenu;
  124.     u_long *rxexemenu;
  125.  
  126.     localize_array(nap_linktype);
  127.  
  128.     MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN);
  129.     if (!MUIMasterBase) {
  130.         printf(MSG_NO_LIBRARY, MUIMASTER_NAME, MUIMASTER_VMIN);
  131.         return(0);
  132.     }
  133.  
  134.     NListBase = OpenLibrary("MUI/NList.mcc", 19);
  135.     if (!NListBase) {
  136.         printf(MSG_NO_LIBRARY, "NList.mcc", 19);
  137.         return(0);
  138.     }
  139.     if (NListBase->lib_Version == 19 && NListBase->lib_Revision < 97) {
  140.         printf(MSG_NO_LIBRARY, "NList.mcc", 19);
  141.         CloseLibrary(NListBase);
  142.         return(0);
  143.     }
  144.     CloseLibrary(NListBase);
  145.  
  146.     LampBase = OpenLibrary("MUI/Lamp.mcc", 11);
  147.     if (!LampBase) {
  148.         printf(MSG_NO_LIBRARY, "Lamp.mcc", 11);
  149.         return(0);
  150.     }
  151.     if (LampBase->lib_Version == 11 && LampBase->lib_Revision == 0) {
  152.         printf(MSG_NO_LIBRARY, "Lamp.mcc", 11);
  153.         CloseLibrary(LampBase);
  154.         return(0);
  155.     }
  156.     CloseLibrary(LampBase);
  157.  
  158.     if (!prf_load("ENV:"AMSTER_PREFS)) prf_load("ENVARC:"AMSTER_PREFS);
  159.  
  160.     gui->url_mcc = MUI_CreateCustomClass(NULL,MUIC_Text,NULL,sizeof(struct urldata),url_dispatch);
  161.     if(!gui->url_mcc) return(0);
  162.  
  163.     gui->panel_mcc = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct paneldata),panel_dispatch);
  164.     if(!gui->panel_mcc) return(0);
  165.  
  166.     gui->search_mcc = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct searchdata),search_dispatch);
  167.     if(!gui->search_mcc) return(0);
  168.  
  169.     gui->dl_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct TransferData),dl_dispatch);
  170.     if (!gui->dl_mcc) return(0);
  171.  
  172.     gui->ul_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct TransferData),ul_dispatch);
  173.     if (!gui->ul_mcc) return(0);
  174.  
  175.     gui->share_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct shdata),share_dispatch);
  176.     if (!gui->share_mcc) return(0);
  177.  
  178.     gui->prf_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct prfdata),prf_dispatch);
  179.     if (!gui->prf_mcc) return(0);
  180.  
  181.     gui->info_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct infodata),info_dispatch);
  182.     if (!gui->info_mcc) return(0);
  183.  
  184.     gui->about_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct aboutdata),about_dispatch);
  185.     if (!gui->about_mcc) return(0);
  186.  
  187.     gui->msg_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct msgdata),msg_dispatch);
  188.     if (!gui->msg_mcc) return(0);
  189.  
  190.     gui->chat_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct chatdata),chat_dispatch);
  191.     if (!gui->chat_mcc) return(0);
  192.  
  193.     gui->navi_mcc = MUI_CreateCustomClass(NULL, MUIC_Window, NULL, sizeof(struct NavigatorData), NavigatorDispatch);
  194.     if (!gui->navi_mcc) return(0);
  195.  
  196.     if(!lamp_create()) return(0);
  197.  
  198.     gui->app = ApplicationObject,
  199.         MUIA_Application_Title,       "Amster",
  200.         MUIA_Application_Version,     "$VER: Amster "AMSTER_VERSION" ("AMSTER_DATE")",
  201.         MUIA_Application_Author,      "Jacob Laursen",
  202.         MUIA_Application_Description, MSG_CX_DESCRIPTION,
  203.         MUIA_Application_Base,        "AMSTER",
  204.         MUIA_Application_Commands,    &rexx_cmds,
  205.         MUIA_Application_HelpFile,    AMSTER_HELP,
  206.         MUIA_Application_Menustrip,   MenustripObject,
  207.             Child, MenuObject,
  208.                 MUIA_Menu_Title, MSG_AMSTER_MENU,
  209.                 Child, MI_Navigator = makemenu(MSG_AMSTER_NAVIGATOR),
  210.                 Child, makemenu(NULL),
  211.                 Child, MI_Connect = makemenu(MSG_AMSTER_CONNECT),
  212.                 Child, MI_ConnectTo = makemenu(MSG_AMSTER_CONNECTTO),
  213.                 Child, MI_Reconnect = makemenu(MSG_AMSTER_RECONNECT),
  214.                 Child, MI_Disconnect = makemenu(MSG_AMSTER_DISCONNECT),
  215.                 Child, makemenu(NULL),
  216.                 Child, aboutmenu = makemenu(MSG_AMSTER_ABOUT),
  217.                 Child, muimenu = makemenu(MSG_AMSTER_ABOUTMUI),
  218.                 Child, helpmenu = makemenu(MSG_AMSTER_HELP),
  219.                 Child, makemenu(NULL),
  220.                 Child, hidemenu = makemenu(MSG_AMSTER_HIDE),
  221.                 Child, quitmenu = makemenu(MSG_AMSTER_QUIT),
  222.             End,
  223.             Child, MenuObject,
  224.                 MUIA_Menu_Title, MSG_PROJECT_MENU,
  225.                 Child, openmenu = makemenu(MSG_PROJECT_OPEN),
  226.                 Child, savemenu = makemenu(MSG_PROJECT_SAVE),
  227.                 Child, saveasmenu = makemenu(MSG_PROJECT_SAVEAS),
  228.             End,
  229.             Child, MenuObject,
  230.                 MUIA_Menu_Title, MSG_WINDOWS_MENU,
  231.                 Child, debugmenu = makemenu(MSG_WINDOWS_DEBUG),
  232.                 Child, sharemenu = makemenu(MSG_WINDOWS_SHARE),
  233.                 Child, dlmenu = makemenu(MSG_WINDOWS_DOWNLOAD),
  234.                 Child, ulmenu = makemenu(MSG_WINDOWS_UPLOAD),
  235.                 Child, usermenu = makemenu(MSG_WINDOWS_USER),
  236.                 Child, chatmenu = makemenu(MSG_WINDOWS_CHAT),
  237.             End,
  238.             Child, MenuObject,
  239.                 MUIA_Menu_Title, MSG_SETTINGS_MENU,
  240.                 Child, gui->iconpanelmenu = maketmenu(MSG_SETTINGS_ICONPANEL),
  241.                 Child, makemenu(NULL),
  242.                 Child, muiprfmenu = makemenu(MSG_SETTINGS_MUI),
  243.                 Child, prfmenu = makemenu(MSG_SETTINGS_CONFIG),
  244.                 Child, makemenu(NULL),
  245.                 Child, MI_LastSaved = makemenu(MSG_SETTINGS_LASTSAVED),
  246.                 Child, saveprfmenu = makemenu(MSG_SETTINGS_SAVE),
  247.             End,
  248.             Child, MenuObject,
  249.                 MUIA_Menu_Title, MSG_AREXX_MENU,
  250.                 Child, rxexemenu = makemenu(MSG_AREXX_EXECUTE),
  251.             End,
  252.         End,
  253.  
  254.         SubWindow, gui->win = WindowObject,
  255.         MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  256.         MUIA_Window_Title, "Amster v"AMSTER_VERSION,
  257.         WindowContents, HGroup,
  258.             Child, VGroup,
  259.                 Child, gui->searchpanel = NewObject(gui->search_mcc->mcc_Class,NULL,TAG_DONE),
  260.                 Child, RectangleObject,
  261.                     MUIA_FixHeight, 8,
  262.                     MUIA_Rectangle_HBar, TRUE,
  263.                 End,
  264.                 Child, HGroup,
  265.                     Child, gui->stat = TextObject,
  266.                         TextFrame,
  267.                         MUIA_Background, MUII_TextBack,
  268.                         MUIA_Text_PreParse, "\33c",
  269.                     End,
  270.                     Child, gui->lamp = LampObject,
  271.                         MUIA_Lamp_Type, MUIV_Lamp_Type_Huge,
  272.                         MUIA_Lamp_Color, MUIV_Lamp_Color_Off,
  273.                     End,
  274.                 End,
  275.                 Child, HGroup,
  276.                     Child, gui->inbut  = SimpleButton(MSG_CONNECT_GAD),
  277.                     Child, gui->outbut = SimpleButton(MSG_DISCONNECT_GAD),
  278.                     Child, gui->rebut  = SimpleButton(MSG_RECONNECT_GAD),
  279.                 End,
  280.             End,
  281.             Child, gui->rect = HGroup,
  282.                 Child, RectangleObject,
  283.                     MUIA_FixWidth, 4,
  284.                     MUIA_Rectangle_VBar, TRUE,
  285.                 End,
  286.                 Child, gui->iconpanel = NewObject(gui->panel_mcc->mcc_Class,NULL,TAG_DONE),
  287.             End,
  288.         End,
  289.         End,
  290.  
  291.         SubWindow, gui->WI_ConnectTo = WindowObject,
  292.         MUIA_HelpNode, "connectto",
  293.         MUIA_Window_Title, MSG_CONNECTTO_TITLE,
  294.         MUIA_Window_ID, MAKE_ID('C','O','N','N'),
  295.         WindowContents, VGroup,
  296.             Child, HGroup,
  297.                 Child, ColGroup(2),
  298.                     Child, Label2(MSG_CONNECTTO_SERVER),
  299.                     Child, gui->ST_ConnectServer = StringObject,
  300.                         StringFrame,
  301.                         MUIA_CycleChain, 1,
  302.                     End,
  303.                     Child, Label2(MSG_CONNECTTO_USERNAME),
  304.                     Child, gui->ST_ConnectUser = StringObject,
  305.                         StringFrame,
  306.                         MUIA_CycleChain, 1,
  307.                     End,
  308.                     Child, Label2(MSG_CONNECTTO_PASSWORD),
  309.                     Child, gui->ST_ConnectPw = StringObject,
  310.                         StringFrame,
  311.                         MUIA_String_Secret, TRUE,
  312.                         MUIA_CycleChain, 1,
  313.                     End,
  314.                 End,
  315.             End,
  316.             Child, maketoggle(MSG_CONNECTTO_REG, &gui->TG_ConnectReg),
  317.             Child, gui->BT_ConnectServer = SimpleButton(MSG_CONNECTTO_CONNECT_GAD),
  318.         End,
  319.         End,
  320.  
  321.         SubWindow, gui->awin = NewObject(gui->about_mcc->mcc_Class,NULL,TAG_DONE),
  322.         SubWindow, gui->swin = NewObject(gui->prf_mcc->mcc_Class,NULL,TAG_DONE),
  323.         SubWindow, gui->iwin = NewObject(gui->info_mcc->mcc_Class,NULL,TAG_DONE),
  324.         SubWindow, gui->dwin = NewObject(gui->dl_mcc->mcc_Class,NULL,TAG_DONE),
  325.         SubWindow, gui->uwin = NewObject(gui->ul_mcc->mcc_Class,NULL,TAG_DONE),
  326.         SubWindow, gui->shwin = NewObject(gui->share_mcc->mcc_Class,NULL,TAG_DONE),
  327.         SubWindow, gui->mwin = NewObject(gui->msg_mcc->mcc_Class,NULL,TAG_DONE),
  328.         SubWindow, gui->WI_Navigator = NewObject(gui->navi_mcc->mcc_Class, NULL, TAG_DONE),
  329.  
  330.     End;
  331.  
  332.     if (!gui->app) {
  333.         printf(MSG_APP_ERROR);
  334.         return(0);
  335.     }
  336.  
  337.     DoMethod(gui->inbut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, CONNECT);
  338.     DoMethod(gui->outbut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, DISCONNECT);
  339.     DoMethod(gui->rebut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, RECONNECT);
  340.  
  341.     DoMethod(gui->iconpanelmenu,MUIM_Notify,MUIA_Menuitem_Checked,MUIV_EveryTime,gui->app,3,MUIM_CallHook,&handleHook, UPDATEPANEL);
  342.  
  343.     DoMethod(MI_Navigator, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->WI_Navigator, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  344.     DoMethod(MI_Connect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, CONNECT);
  345.     DoMethod(MI_ConnectTo, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->WI_ConnectTo, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  346.     DoMethod(MI_Reconnect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, RECONNECT);
  347.     DoMethod(MI_Disconnect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, DISCONNECT);
  348.     DoMethod(gui->WI_Navigator, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, gui->WI_Navigator, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  349.     DoMethod(gui->WI_ConnectTo, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, gui->WI_ConnectTo, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  350.  
  351.     /* Connect to... */
  352.  
  353.     DoMethod(gui->BT_ConnectServer, MUIM_Notify, MUIA_Pressed, FALSE, gui->app, 3, MUIM_CallHook, &handleHook, CONNECTSERVER);
  354.  
  355.     /* Pulldown menu */
  356.  
  357.     DoMethod(aboutmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->awin,3,MUIM_Set,MUIA_Window_Open,TRUE);
  358.     DoMethod(muimenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_AboutMUI,gui->win);
  359.     DoMethod(helpmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,5,MUIM_Application_ShowHelp,gui->win,AMSTER_HELP,0,0);
  360.     DoMethod(hidemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,3,MUIM_Set,MUIA_Application_Iconified,TRUE);
  361.     DoMethod(quitmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  362.  
  363.     DoMethod(openmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->shwin,1,SHARE_LOADAS);
  364.     DoMethod(savemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->shwin,1,SHARE_SAVE);
  365.     DoMethod(saveasmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->shwin,1,SHARE_SAVEAS);
  366.  
  367.     DoMethod(debugmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENDEBUG);
  368.     DoMethod(dlmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENDL);
  369.     DoMethod(ulmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->uwin,1,UPLOAD_OPEN);
  370.     DoMethod(sharemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENSHARE);
  371.     DoMethod(usermenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENMSG);
  372.     DoMethod(chatmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_NEWCHAT);
  373.  
  374.     DoMethod(muiprfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_OpenConfigWindow,0);
  375.     DoMethod(prfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENPRF);
  376.     DoMethod(MI_LastSaved, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->swin, 1, PRF_LASTSAVED);
  377.     DoMethod(saveprfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->swin,1,PRF_SAVEALL);
  378.  
  379.     DoMethod(rxexemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,3,MUIM_CallHook,&handleHook, EXECUTEAREXX);
  380.  
  381.     DoMethod(gui->win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,gui->app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  382.     DoMethod(gui->app, MUIM_Notify, MUIA_Application_Iconified, FALSE, gui->app,3, MUIM_CallHook, &handleHook, DEICONIFIED);
  383.  
  384.     DoMethod(gui->searchpanel, SEARCH_SET);
  385.  
  386.     set(gui->ST_ConnectUser, MUIA_String_Contents, prf->user);
  387.     set(gui->ST_ConnectPw,   MUIA_String_Contents, prf->pass);
  388.     set(gui->TG_ConnectReg,  MUIA_Selected,        TRUE);
  389.  
  390.     if (prf->noiconpanel) {
  391.         set(gui->iconpanelmenu, MUIA_Menuitem_Checked, FALSE);
  392.         set(gui->rect, MUIA_ShowMe, FALSE);
  393.     } else {
  394.         set(gui->iconpanelmenu, MUIA_Menuitem_Checked, TRUE);
  395.     }
  396.  
  397. /*    strcpy(sharepath, prf->dlpath);*/
  398.     gui_appicon(0);
  399.     gui_state(-2);
  400.  
  401.     /* Set screen title for all windows */
  402.     DoMethod(gui->app, MUIM_MultiSet, MUIA_Window_ScreenTitle,
  403.         "Amster "AMSTER_VERSION" ("AMSTER_DATE") © 1999-2000 Gürer Özen & Jacob Laursen",
  404.         gui->win, gui->awin, gui->swin, gui->shwin, gui->mwin, gui->iwin,
  405.         gui->dwin, gui->uwin, gui->WI_ConnectTo, gui->WI_Navigator, NULL);
  406.  
  407.     set(gui->win, MUIA_Window_Open, TRUE);
  408.     get(gui->win, MUIA_Window_Open, &winopen);
  409.     if (!winopen) {
  410.         printf(MSG_ERR_NOWINDOW);
  411.         return(0);
  412.     }
  413.  
  414.     if (!prf->user) DoMethod(gui->iconpanel, PANEL_OPENPRF);
  415.     /* If no account is configured, open configuration window */
  416.  
  417.     if (prf->user && prf->autocon) {
  418.         nap_login();
  419.         return(1);
  420.     }
  421.  
  422.     set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_NOTCONNECTED);
  423.     return(1);
  424. }
  425.  
  426.  
  427. MUIF gui_handle(REG(a0) struct Hook *h, REG(a2) Object *app, REG(a1) u_long *id)
  428. {
  429.     u_long tmp;
  430.     char *buf;
  431.  
  432.     switch(*id) {
  433.         case CONNECT:
  434.             if (!gui_napon) nap_login();
  435.             break;
  436.         case DISCONNECT:
  437.             nap_logout();
  438.             set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_NOTCONNECTED);
  439.             break;
  440.         case RECONNECT:
  441.             if (gui_napon) nap_logout();
  442.             nap_login();
  443.             break;
  444.         case CONNECTSERVER:
  445.             if (gui_napon) nap_logout();
  446.             get(gui->ST_ConnectServer, MUIA_String_Contents, &buf);
  447.             get(gui->ST_ConnectUser,   MUIA_String_Contents, &gui->ConnectUser);
  448.             get(gui->ST_ConnectPw,     MUIA_String_Contents, &gui->ConnectPw);
  449.             get(gui->TG_ConnectReg,    MUIA_Selected,        &tmp);
  450.             set(gui->WI_ConnectTo, MUIA_Window_Open, FALSE);
  451.             if (tmp) prf->regflag = 2;
  452.             else prf->regflag = 0;
  453.             nap_login_fromlist(buf);
  454.             break;
  455.         case EXECUTEAREXX:
  456.             {
  457.             struct FileRequester *freq;
  458.             freq = AllocAslRequestTags(ASL_FileRequest,TAG_DONE);
  459.             if(!freq) break;
  460.             tmp = AslRequestTags(freq,
  461.                 ASLFR_TitleText, MSG_SELECTRX_TITLE,
  462.                 ASLFR_DoSaveMode, TRUE,
  463.                 TAG_DONE);
  464.             if (tmp) {
  465.                 static char buf[512];
  466.                 strcpy(buf, freq->fr_Drawer);
  467.                 AddPart(buf, freq->fr_File,511);
  468.                 rexx_execute(buf, NULL);
  469.             }
  470.             FreeAslRequest(freq);
  471.             break;
  472.             }
  473.         case UPDATEPANEL:
  474.             GetAttr(MUIA_Menuitem_Checked, gui->iconpanelmenu, &tmp);
  475.             if (tmp==TRUE)
  476.                 set(gui->rect, MUIA_ShowMe, TRUE);
  477.             else
  478.                 set(gui->rect, MUIA_ShowMe, FALSE);
  479.             break;
  480.         case DEICONIFIED:
  481.             /* Work-around for a bug in Lamp.mcc */
  482.             if (!gui_napon && !gui_napcon) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Off);
  483.             else if (gui_napon && !gui_napcon) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Ok);
  484.             else set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Connecting);
  485.             break;
  486.     }
  487.     return(0);
  488. }
  489.  
  490.  
  491. void gui_state(int s)
  492. {
  493.     u_long tmp;
  494.  
  495.     switch (s) {
  496.         case -1:
  497.             prf_event(PRFE_DISCONNECT);
  498.         case -2:
  499.             gui_napon = 0;
  500.             gui_napcon = 0;
  501.             set(gui->inbut, MUIA_Disabled, FALSE);
  502.             set(gui->outbut, MUIA_Disabled, TRUE);
  503.             set(gui->rebut, MUIA_Disabled, TRUE);
  504.  
  505.             /* Work-around for a bug in Lamp.mcc */
  506.             get(gui->app, MUIA_Application_Iconified, &tmp);
  507.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Off);
  508.  
  509.             DoMethod(gui->searchpanel, SEARCH_CLEAR, 1);
  510.             gui_appicon(2);
  511.             break;
  512.         case 0:
  513.             gui_napcon = 1;
  514.             set(gui->inbut, MUIA_Disabled, TRUE);
  515.             set(gui->outbut, MUIA_Disabled, FALSE);
  516.  
  517.             /* Work-around for a bug in Lamp.mcc */
  518.             get(gui->app, MUIA_Application_Iconified, &tmp);
  519.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Connecting);
  520.  
  521.             set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_CONNECTING);
  522.             break;
  523.         case 1:
  524.             prf_event(PRFE_CONNECT);
  525.             gui_napon = 1;
  526.             gui_napcon = 0;
  527.             set(gui->inbut, MUIA_Disabled, TRUE);
  528.             set(gui->outbut, MUIA_Disabled, FALSE);
  529.             set(gui->rebut, MUIA_Disabled, FALSE);
  530.  
  531.             /* Work-around for a bug in Lamp.mcc */
  532.             get(gui->app, MUIA_Application_Iconified, &tmp);
  533.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_SendingData);
  534.  
  535.             break;
  536.         case 2:
  537.             gui_napon = 1;
  538.             gui_napcon = 0;
  539.             set(gui->inbut, MUIA_Disabled, TRUE);
  540.             set(gui->outbut, MUIA_Disabled, FALSE);
  541.             set(gui->rebut, MUIA_Disabled, FALSE);
  542.  
  543.             /* Work-around for a bug in Lamp.mcc */
  544.             get(gui->app, MUIA_Application_Iconified, &tmp);
  545.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Ok);
  546.  
  547.             gui_appicon(1);
  548.             break;
  549.     }
  550. }
  551.  
  552.  
  553. void gui_srvstat(int a, int b, int c)
  554. {
  555.     gui_stat((char*)MSG_STATUS2_SONGSONLINE, b, a, c);
  556. }
  557.  
  558.  
  559. void gui_found(song s)
  560. {
  561.     DoMethod(gui->searchpanel, SEARCH_FOUND, s);
  562. }
  563.  
  564.  
  565. void localize_array(char *array[])
  566. {
  567.     char **x;
  568.  
  569.     for (x=array;*x;x++)
  570.         *x = (char *)((struct FC_String *)(*x))->msg;
  571. }
  572.  
  573.  
  574. void gui_stat(char *msg, ...)
  575. {
  576.     static char buf[256];
  577.     va_list ap;
  578.  
  579.     va_start(ap,msg);
  580.     vsprintf(buf,msg,ap);
  581.     va_end(ap);
  582.     set(gui->stat, MUIA_Text_Contents, buf);
  583. }
  584.  
  585.  
  586. void gui_appicon(int t)
  587. {
  588.     static struct DiskObject *on, *off;
  589.  
  590.     switch(t) {
  591.         case 0:
  592.             on = GetDiskObject("PROGDIR:Icons/Amster_online");
  593.             off = GetDiskObject("PROGDIR:Icons/Amster_offline");
  594.             break;
  595.  
  596.         case -1:
  597.             if (on) FreeDiskObject(on);
  598.             if (off) FreeDiskObject(off);
  599.             break;
  600.  
  601.         case 1:
  602.             if (on) set(gui->app, MUIA_Application_DiskObject, on);
  603.             break;
  604.  
  605.         case 2:
  606.             if (off) set(gui->app, MUIA_Application_DiskObject, off);
  607.             break;
  608.  
  609.     }
  610. }
  611.