7 #include <proto/exec.h>
9 #include <proto/intuition.h>
10 #include <proto/muimaster.h>
11 #include <proto/locale.h>
12 #include <clib/alib_protos.h>
14 #include <libraries/mui.h>
16 #include <proto/miami.h>
17 #include <proto/socket.h>
19 #define ioctl IoctlSocket
21 #include <sys/param.h>
22 #include <sys/socket.h>
27 #include <netinet/in_systm.h>
28 #include <netinet/in.h>
29 #include <netinet/ip.h>
30 #include <netinet/ip_icmp.h>
31 #include <netinet/ip_var.h>
37 #include "colorlist.h"
40 extern struct Library
*UtilityBase
;
42 #if !defined(__AROS__)
43 extern struct Library
*SysBase
,
47 struct Library
*MUIMasterBase
,
50 #if !defined(__AROS__)
51 struct Library
*IntuitionBase
,
55 Object
*App
, *Win
, *SWin
, *List
, *DbgLevel
;
59 struct Locale
*Locale
;
61 STRPTR DebugLevels
[] = {"emergency", "alerts", "critical", "errors", "warnings", "notice", "info", "debug", "off", NULL
};
65 if (!(GfxBase
= OpenLibrary("graphics.library", 0))) return FALSE
;
66 if (!(IntuitionBase
= OpenLibrary("intuition.library", 0))) return FALSE
;
67 if (!(MUIMasterBase
= OpenLibrary("muimaster.library", 0))) return FALSE
;
68 if (!(LocaleBase
= OpenLibrary("locale.library", 0))) return FALSE
;
69 if (!(ColorList
= CreateColorListClass())) return FALSE
;
70 Locale
= OpenLocale(NULL
);
71 if (FindPort("SysLog")) return FALSE
;
78 if (ColorList
) MUI_DeleteCustomClass(ColorList
);
79 if (LocaleBase
) CloseLibrary(LocaleBase
);
80 if (MUIMasterBase
) CloseLibrary(MUIMasterBase
);
81 if (IntuitionBase
) CloseLibrary(IntuitionBase
);
82 if (GfxBase
) CloseLibrary(GfxBase
);
85 #define MUIA_InnerSpacing(a) MUIA_InnerLeft, a,\
90 Object
*BuildSettingsWindow(void)
94 win
= MUI_NewObject(MUIC_Window
,
95 MUIA_Window_Title
, (ULONG
)"SysLog settings",
96 MUIA_Window_ID
, 0x4D444C50,
97 MUIA_Window_RootObject
, (ULONG
)MUI_NewObject(MUIC_Group
,
98 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Group
,
99 MUIA_Group_Columns
, 2,
100 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Text
,
101 MUIA_Text_Contents
, (ULONG
)"\33rColor of error messages",
104 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Poppen
,
105 MUIA_FixWidthTxt
, (ULONG
)"6EDA",
106 MUIA_InnerSpacing(1),
108 MUIA_UserData
, PREFS_POPPEN_ERRORS
,
109 MUIA_Window_Title
, (ULONG
)"Error messages",
111 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Text
,
112 MUIA_Text_Contents
, (ULONG
)"\33rColor of important information",
115 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Poppen
,
116 MUIA_FixWidthTxt
, (ULONG
)"6EDA",
117 MUIA_InnerSpacing(1),
119 MUIA_UserData
, PREFS_POPPEN_IMPORTANT
,
120 MUIA_Window_Title
, (ULONG
)"Important information",
122 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Text
,
123 MUIA_Text_Contents
, (ULONG
)"\33rColor of debug information",
126 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Poppen
,
127 MUIA_FixWidthTxt
, (ULONG
)"6EDA",
128 MUIA_InnerSpacing(1),
130 MUIA_UserData
, PREFS_POPPEN_OTHERS
,
131 MUIA_Window_Title
, (ULONG
)"Debug information",
134 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Group
,
135 MUIA_Group_Horiz
, TRUE
,
136 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Text
,
137 MUIA_Text_Contents
, (ULONG
)"Save",
138 MUIA_Text_PreParse
, (ULONG
)"\33c",
139 MUIA_Text_HiChar
, 's',
140 MUIA_ControlChar
, 's',
141 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
142 MUIA_Background
, MUII_ButtonBack
,
143 MUIA_Frame
, MUIV_Frame_Button
,
144 MUIA_Font
, MUIV_Font_Button
,
145 MUIA_UserData
, PREFS_BUTTON_SAVE
,
147 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Text
,
148 MUIA_Text_Contents
, (ULONG
)"Use",
149 MUIA_Text_PreParse
, (ULONG
)"\33c",
150 MUIA_Text_HiChar
, 'u',
151 MUIA_ControlChar
, 'u',
152 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
153 MUIA_Background
, MUII_ButtonBack
,
154 MUIA_Frame
, MUIV_Frame_Button
,
155 MUIA_Font
, MUIV_Font_Button
,
156 MUIA_UserData
, PREFS_BUTTON_USE
,
158 MUIA_Group_Child
, (ULONG
)MUI_NewObject(MUIC_Text
,
159 MUIA_Text_Contents
, (ULONG
)"Cancel",
160 MUIA_Text_PreParse
, (ULONG
)"\33c",
161 MUIA_Text_HiChar
, 'c',
162 MUIA_ControlChar
, 'c',
163 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
164 MUIA_Background
, MUII_ButtonBack
,
165 MUIA_Frame
, MUIV_Frame_Button
,
166 MUIA_Font
, MUIV_Font_Button
,
167 MUIA_UserData
, PREFS_BUTTON_CANCEL
,
177 void MainLoop(Object
*win
)
179 ULONG signals
, portmask
;
181 SetAttrs(win
, MUIA_Window_Open
, TRUE
, TAG_END
);
182 portmask
= 1 << Port
->mp_SigBit
;
184 while (DoMethod(App
, MUIM_Application_NewInput
, (ULONG
)&signals
) != (ULONG
)MUIV_Application_ReturnID_Quit
)
188 signals
= Wait(signals
| portmask
| SIGBREAKF_CTRL_C
);
189 if (signals
& portmask
)
191 struct SysLogPacket
*slp
;
193 while (slp
= (struct SysLogPacket
*)GetMsg(Port
))
195 if (slp
->Level
!= LOG_CLOSE
)
197 DoMethod(List
, MUIM_List_InsertSingle
, (ULONG
)slp
, MUIV_List_Insert_Bottom
);
198 DoMethod(List
, MUIM_List_Jump
, MUIV_List_Jump_Bottom
, TAG_END
);
203 if (signals
& SIGBREAKF_CTRL_C
) break;
207 SetAttrs(win
, MUIA_Window_Open
, FALSE
, TAG_END
);
213 #if !defined(__AROS__)
214 LONG
SettingsHook(void)
219 AROS_UFHA(struct Hook
*, hook
, A0
),
220 AROS_UFHA(APTR
*, obj
, A2
),
221 AROS_UFHA(APTR
, param
, A1
)
228 SetAttrs(Win
, MUIA_Window_Sleep
, TRUE
, TAG_END
);
230 SetAttrs(Win
, MUIA_Window_Sleep
, FALSE
, TAG_END
);
231 #if !defined(__AROS__)
239 #if !defined(__AROS__)
240 struct EmulLibEntry g_SettingsHook
= {TRAP_LIB
, 0, (void (*)(void))SettingsHook
};
241 struct Hook h_SettingsHook
= {{NULL
, NULL
}, (HOOKFUNC
)&g_SettingsHook
, NULL
, NULL
};
243 struct Hook h_SettingsHook
;
246 Object
* CreateMenu(void)
250 o
= MUI_NewObject(MUIC_Menustrip
,
251 MUIA_Family_Child
, (ULONG
)MUI_NewObject(MUIC_Menu
,
252 MUIA_Menu_Title
, (ULONG
)"Project",
253 MUIA_Family_Child
, (ULONG
)MUI_NewObject(MUIC_Menuitem
,
254 MUIA_Menuitem_Title
, (ULONG
)"Clear",
255 MUIA_Menuitem_Shortcut
, (ULONG
)"C",
256 MUIA_UserData
, MENU_CLEAR
,
258 /* MUIA_Family_Child, (ULONG)MUI_NewObject(MUIC_Menuitem,
259 MUIA_Menuitem_Title, (ULONG)"Save as...",
260 MUIA_Menuitem_Shortcut, (ULONG)"S",
261 MUIA_UserData, MENU_SAVEAS,
263 MUIA_Family_Child
, (ULONG
)MUI_NewObject(MUIC_Menuitem
,
264 MUIA_Menuitem_Title
, (ULONG
)"Settings...",
265 MUIA_UserData
, MENU_SETTINGS
,
267 MUIA_Family_Child
, (ULONG
)MUI_NewObject(MUIC_Menuitem
,
268 MUIA_Menuitem_Title
, MENUBAR
,
270 MUIA_Family_Child
, (ULONG
)MUI_NewObject(MUIC_Menuitem
,
271 MUIA_Menuitem_Title
, (ULONG
)"Quit",
272 MUIA_Menuitem_Shortcut
, (ULONG
)"Q",
273 MUIA_UserData
, MENU_QUIT
,
286 App
= MUI_NewObject(MUIC_Application
,
287 MUIA_Application_Author
, (ULONG
)"Grzegorz \"Krashan\" Kraszewski, Pavel \"Sonic\" Fedin, Nick \"Kalamatee\" Andrews",
288 MUIA_Application_Base
, (ULONG
)"SysLog",
289 MUIA_Application_Copyright
, (ULONG
)"(c) 2005 by Grzegorz Kraszewski, Pavel Fedin, Nick Andrews",
290 MUIA_Application_Description
, (ULONG
)"AROSTCP syslog viewer",
291 MUIA_Application_SingleTask
, TRUE
,
292 MUIA_Application_Title
, (ULONG
)"SysLog",
293 MUIA_Application_Version
, (ULONG
)"$VER: SysLog 1.2 (15.11.2005)\n",
294 MUIA_Application_Menustrip
, (ULONG
)CreateMenu(),
295 MUIA_Application_Window
, (ULONG
)(Win
= MUI_NewObject(MUIC_Window
,
296 MUIA_Window_Title
, (ULONG
)"AROSTCP syslog viewer",
297 MUIA_Window_ScreenTitle
, (ULONG
)"SysLog 1.2 (c) 2005-2007 Grzegorz Kraszewski, Pavel Fedin, Nick Andrews",
298 MUIA_Window_ID
, 0x4D444C47,
299 MUIA_Window_RootObject
, (ULONG
)MUI_NewObject(MUIC_Group
,
300 MUIA_Group_Child
, (ULONG
)(lv
= MUI_NewObject(MUIC_Listview
,
301 MUIA_Listview_List
, (ULONG
)(List
= NewObject(ColorList
->mcc_Class
, NULL
,
302 MUIA_Frame
, MUIV_Frame_ReadList
,
303 MUIA_List_Format
, (ULONG
)"BAR,BAR,BAR,",
304 MUIA_List_Title
, TRUE
,
306 MUIA_Listview_Input
, FALSE
,
308 MUIA_Group_Child
, MUI_NewObject(MUIC_Group
,
309 MUIA_Group_Horiz
, TRUE
,
310 MUIA_Group_Child
, MUI_NewObject(MUIC_Text
,
311 MUIA_Text_SetMax
, TRUE
,
312 MUIA_Text_Contents
, (ULONG
)"Debug level",
314 MUIA_Group_Child
, DbgLevel
= MUI_NewObject(MUIC_Cycle
,
315 MUIA_Cycle_Entries
, (ULONG
)DebugLevels
,
318 MUIA_Group_Child
, MUI_NewObject(MUIC_Rectangle
,
322 MUIA_Window_DefaultObject
, (ULONG
)lv
,
324 MUIA_Application_Window
, SWin
= BuildSettingsWindow(),
327 if (App
) return TRUE
;
332 void SetNotifications (void)
334 #if defined(__AROS__)
335 h_SettingsHook
.h_Entry
= ( HOOKFUNC
)SettingsHook
;
337 DoMethod(Win
, MUIM_Notify
, MUIA_Window_CloseRequest
, MUIV_EveryTime
, (ULONG
)App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
338 DoMethod(App
, MUIM_Notify
, MUIA_Application_MenuAction
, MENU_QUIT
, (ULONG
)App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
339 /*DoMethod(App, MUIM_Notify, MUIA_Application_MenuAction, MENU_SAVEAS, (ULONG)List, 2, MUIM_CallHook, (ULONG)&h_SaveAsHook);*/
340 DoMethod(App
, MUIM_Notify
, MUIA_Application_MenuAction
, MENU_SETTINGS
, (ULONG
)App
, 2, MUIM_CallHook
, (ULONG
)&h_SettingsHook
);
341 DoMethod(App
, MUIM_Notify
, MUIA_Application_MenuAction
, MENU_CLEAR
,
342 (ULONG
)List
, 1, MUIM_List_Clear
);
344 /* close prefs window */
346 DoMethod(SWin
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
, App
, 2,
347 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
348 DoMethod(findobj(SWin
, PREFS_BUTTON_CANCEL
), MUIM_Notify
, MUIA_Pressed
,
349 FALSE
, App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
350 DoMethod(findobj(SWin
, PREFS_BUTTON_USE
), MUIM_Notify
, MUIA_Pressed
,
351 FALSE
, App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
352 DoMethod(findobj(SWin
, PREFS_BUTTON_SAVE
), MUIM_Notify
, MUIA_Pressed
,
353 FALSE
, App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
357 DoMethod(findobj(SWin
, PREFS_BUTTON_USE
), MUIM_Notify
, MUIA_Pressed
,
358 FALSE
, App
, 2, MUIM_Application_Save
, MUIV_Application_Save_ENV
);
359 DoMethod(findobj(SWin
, PREFS_BUTTON_SAVE
), MUIM_Notify
, MUIA_Pressed
,
360 FALSE
, App
, 2, MUIM_Application_Save
, MUIV_Application_Save_ENV
);
361 DoMethod(findobj(SWin
, PREFS_BUTTON_SAVE
), MUIM_Notify
, MUIA_Pressed
,
362 FALSE
, App
, 2, MUIM_Application_Save
, MUIV_Application_Save_ENVARC
);
366 DoMethod(findobj(SWin
, PREFS_BUTTON_USE
), MUIM_Notify
, MUIA_Pressed
,
367 FALSE
, List
, 1, CLL_ChangePens
);
368 DoMethod(findobj(SWin
, PREFS_BUTTON_SAVE
), MUIM_Notify
, MUIA_Pressed
,
369 FALSE
, List
, 1, CLL_ChangePens
);
376 struct Library
*MiamiBase
;
379 if (Port
= CreateMsgPort())
383 Port
->mp_Node
.ln_Name
= "SysLog";
384 Port
->mp_Node
.ln_Pri
= 12;
386 MiamiBase
= OpenLibrary("miami.library",13);
389 CloseLibrary(MiamiBase
);
393 DoMethod(App
, MUIM_Application_Load
, MUIV_Application_Load_ENV
);
396 MUI_DisposeObject(App
);
399 MiamiBase
= OpenLibrary("miami.library",13);
402 CloseLibrary(MiamiBase
);
404 while (m
= GetMsg(Port
)) ReplyMsg(m
);
408 else Printf("Setup() failed.\n");