summaryrefslogtreecommitdiffabout
path: root/KLogDlg.cpp
Side-by-side diff
Diffstat (limited to 'KLogDlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--KLogDlg.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/KLogDlg.cpp b/KLogDlg.cpp
index 5f1c6c0..bdcb881 100644
--- a/KLogDlg.cpp
+++ b/KLogDlg.cpp
@@ -1,320 +1,323 @@
// KLogDlg.cpp : implementation file
//
#include "stdafx.h"
#include "KLog.h"
#include "SyslogSocket.h"
#include "KLogDlg.h"
#include "Trayer.h"
#include "LogPattern.h"
#include "WarnBlocking.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_SERIAL( CKLogDlg, CDialog, VERSIONABLE_SCHEMA|1 );
IMPLEMENT_SERIAL( CLogger, CObject, VERSIONABLE_SCHEMA|1 );
IMPLEMENT_SERIAL( CLogEntry, CObject, VERSIONABLE_SCHEMA|1 );
IMPLEMENT_SERIAL( CHostMask, CObject, VERSIONABLE_SCHEMA|1 );
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg void OnKlevernet();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(IDC_KLEVERNET, OnKlevernet)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKLogDlg dialog
CKLogDlg::CKLogDlg(CWnd* pParent /*=NULL*/)
: CDialog(CKLogDlg::IDD, pParent)
{
m_Logger=NULL;
m_LogItems=15;
m_bShown=TRUE;
m_bExiting=FALSE;
m_bWarnBlocking=TRUE;
m_bDontWarn=TRUE;
//{{AFX_DATA_INIT(CKLogDlg)
m_Logto = -1;
m_Desc = _T("");
m_Facility = _T("");
m_HFName = _T("");
m_HFNameCaption = _T("");
m_hlIP = _T("");
m_hlMask = _T("");
m_Sound = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bmpBack.LoadBitmap(IDB_BACKGROUND);
m_bmpBack.GetBitmap(&m_bitmapBack);
m_Trayer = new CTrayer(this);
ASSERT(m_Trayer);
LoadSettings();
}
void CKLogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKLogDlg)
+ DDX_Control(pDX, IDCANCEL, m_CancelCtl);
DDX_Control(pDX, IDC_LOGPATTERN, m_LogPatternCtl);
DDX_Control(pDX, IDC_FILES, m_FilesCtl);
DDX_Control(pDX, IDC_LOGLENSPIN, m_LogLenSpinCtl);
DDX_Control(pDX, IDC_LOGLENGTH, m_LogLengthCtl);
DDX_Control(pDX, IDC_INVERT, m_PriInvertCtl);
DDX_Control(pDX, IDC_TYPE_FILE, m_LogtoFileCtl);
DDX_Control(pDX, IDC_TYPE_HOST, m_LogtoHostCtl);
DDX_Control(pDX, IDC_TYPE_NONE, m_LogtoNoneCtl);
DDX_Control(pDX, IDC_HOSTORFILE, m_HFNameCaptionCtl);
DDX_Control(pDX, IDC_HOSTS, m_hlCtl);
DDX_Control(pDX, IDC_BROWSESOUND, m_BrowseSoundCtl);
DDX_Control(pDX, IDC_NONE, m_PriNoneCtl);
DDX_Control(pDX, IDC_HL_REMOVE, m_hlRemoveCtl);
DDX_Control(pDX, IDC_HL_MASK, m_hlMaskCtl);
DDX_Control(pDX, IDC_HL_IP, m_hlIPCtl);
DDX_Control(pDX, IDC_HL_ADD, m_hlAddCtl);
DDX_Control(pDX, IDC_ALL, m_PriAllCtl);
DDX_Control(pDX, IDC_SOUND, m_SoundCtl);
DDX_Control(pDX, IDC_REMOVE, m_RemoveCtl);
DDX_Control(pDX, IDC_PLAYSOUND, m_PlaySoundCtl);
DDX_Control(pDX, IDC_LOG, m_Log);
DDX_Control(pDX, IDC_HOSTFILE, m_HFNameCtl);
DDX_Control(pDX, IDC_FACILITY, m_FacilityCtl);
DDX_Control(pDX, IDC_BROWSE, m_BrowseCtl);
DDX_Control(pDX, IDC_DESC, m_DescCtl);
DDX_Control(pDX, IDC_TABS, m_Tabs);
DDX_Radio(pDX, IDC_TYPE_FILE, m_Logto);
DDX_Text(pDX, IDC_DESC, m_Desc);
DDV_MaxChars(pDX, m_Desc, 50);
DDX_CBString(pDX, IDC_FACILITY, m_Facility);
DDX_Text(pDX, IDC_HOSTFILE, m_HFName);
DDX_Text(pDX, IDC_HOSTORFILE, m_HFNameCaption);
DDX_Text(pDX, IDC_HL_IP, m_hlIP);
DDV_MaxChars(pDX, m_hlIP, 15);
DDX_Text(pDX, IDC_HL_MASK, m_hlMask);
DDV_MaxChars(pDX, m_hlMask, 15);
DDX_CBString(pDX, IDC_SOUND, m_Sound);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKLogDlg, CDialog)
//{{AFX_MSG_MAP(CKLogDlg)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_NOTIFY(TCN_SELCHANGE, IDC_TABS, OnSelchangeTabs)
ON_CBN_SELCHANGE(IDC_FACILITY, OnSelchangeFacility)
ON_BN_CLICKED(IDC_ALERT, OnPriority)
ON_BN_CLICKED(IDC_TYPE_FILE, OnLogto)
ON_BN_CLICKED(IDC_ALL, OnPriAll)
ON_BN_CLICKED(IDC_NONE, OnPriNone)
ON_EN_CHANGE(IDC_DESC, OnChangeDesc)
ON_BN_CLICKED(IDC_INVERT, OnPriInvert)
ON_BN_CLICKED(IDC_HL_ADD, OnHlAdd)
ON_LBN_SELCHANGE(IDC_HOSTS, OnSelchangeHosts)
ON_BN_CLICKED(IDC_HL_REMOVE, OnHlRemove)
ON_BN_CLICKED(IDC_REMOVE, OnRemove)
ON_BN_CLICKED(IDC_PLAYSOUND, OnPlaysound)
ON_CBN_EDITCHANGE(IDC_SOUND, OnEditchangeSound)
ON_CBN_KILLFOCUS(IDC_SOUND, OnKillfocusSound)
ON_NOTIFY(UDN_DELTAPOS, IDC_LOGLENSPIN, OnDeltaposLoglenspin)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_FILES, OnFiles)
ON_COMMAND(ID_FILES_EXPORT, OnFilesExport)
ON_COMMAND(ID_FILES_IMPORT, OnFilesImport)
ON_BN_CLICKED(IDC_BROWSESOUND, OnBrowsesound)
ON_EN_KILLFOCUS(IDC_HOSTFILE, OnKillfocusHostfile)
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_COMMAND(ID_FILES_RESET, OnFilesReset)
ON_LBN_SELCHANGE(IDC_LOG, OnSelchangeLog)
ON_WM_CREATE()
ON_WM_CLOSE()
ON_COMMAND(ID_TRAY_ABOUTKLOG, OnTrayAboutklog)
ON_COMMAND(ID_TRAY_EXIT, OnTrayExit)
ON_COMMAND(ID_TRAY_SHOWKLOGWINDOW, OnTrayShowklogwindow)
ON_WM_WINDOWPOSCHANGING()
ON_BN_CLICKED(IDC_LOGPATTERN, OnLogpattern)
+ ON_WM_GETMINMAXINFO()
ON_BN_CLICKED(IDC_CRIT, OnPriority)
ON_BN_CLICKED(IDC_DEBUG, OnPriority)
ON_BN_CLICKED(IDC_EMERG, OnPriority)
ON_BN_CLICKED(IDC_ERR, OnPriority)
ON_BN_CLICKED(IDC_INFO, OnPriority)
ON_BN_CLICKED(IDC_NOTICE, OnPriority)
ON_BN_CLICKED(IDC_WARNING, OnPriority)
ON_BN_CLICKED(IDC_TYPE_HOST, OnLogto)
ON_BN_CLICKED(IDC_TYPE_NONE, OnLogto)
+ ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKLogDlg message handlers
BOOL CKLogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_KLS.m_Daddy=this;
VERIFY(m_KLS.CreateListen());
m_SLS.Create(0,SOCK_DGRAM);
m_LogLenSpinCtl.SetRange(5,50);
UpdateLogLength(FALSE,FALSE);
// Adjust Tab control rectangle size and padding
CRect rbrc,tcrc;
m_DescCtl.GetWindowRect(&rbrc);
m_Tabs.GetClientRect(&tcrc);
m_Tabs.ClientToScreen(&tcrc);
m_Tabs.SetItemSize(CSize(0,rbrc.top-tcrc.top-4));
m_Tabs.SetPadding(CSize(5,5));
// Load Image List
m_Images.Create(16,16,TRUE,2,1);
m_iNormal=m_Images.Add(AfxGetApp()->LoadIcon(IDI_KLOG));
m_iTriggered=m_Images.Add(AfxGetApp()->LoadIcon(IDI_KLOG_TRIGGERED));
m_Tabs.SetImageList(&m_Images);
// Set Icons
m_BrowseSoundCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_BROWSE));
m_PlaySoundCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_PREPLAY));
m_LogPatternCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_LOGPATTERN));
// Create ToolTip Control
m_tooltip.Create(this);
m_tooltip.Activate(TRUE);
// Restore Layout
OnFilesReset();
SetWindowPos(NULL,6,6,0,0,SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE);
if(m_bShown)
ShowWindow(SW_SHOW);
else
ShowWindow(SW_HIDE);
// Add Tips captions
m_tooltip.AddTool(GetDlgItem(IDC_ADD),IDC_ADD);
m_tooltip.AddTool(&m_RemoveCtl,IDC_REMOVE);
m_tooltip.AddTool(&m_LogLengthCtl,IDC_LOGLENGTH);
m_tooltip.AddTool(&m_LogLenSpinCtl,IDC_LOGLENGTH);
m_tooltip.AddTool(GetDlgItem(IDC_STATIC_LOGLENGTH),IDC_LOGLENGTH);
m_tooltip.AddTool(GetDlgItem(IDC_FILES),IDC_FILES);
m_tooltip.AddTool(GetDlgItem(IDC_EXIT),IDC_EXIT);
m_tooltip.AddTool(&m_LogtoFileCtl,IDC_TYPE_FILE);
m_tooltip.AddTool(&m_LogtoHostCtl,IDC_TYPE_HOST);
m_tooltip.AddTool(&m_LogtoNoneCtl,IDC_TYPE_NONE);
m_tooltip.AddTool(&m_hlCtl,IDC_HOSTS);
m_tooltip.AddTool(&m_Log,IDC_LOG);
m_tooltip.AddTool(&m_LogPatternCtl,IDC_LOGPATTERN);
return TRUE; // return TRUE unless you set the focus to a control
}
void CKLogDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
switch(nID&0xFFF0){
case IDM_ABOUTBOX:
{
OnTrayAboutklog();
}
break;
case SC_CONTEXTHELP:
AfxGetApp()->WinHelp(0,HELP_FINDER);
break;
default:
CDialog::OnSysCommand(nID, lParam);
break;
}
}
void CKLogDlg::OnDestroy()
{
NOTIFYICONDATA nid;
memset(&nid,0,sizeof(nid));
nid.cbSize=sizeof(nid);
nid.hWnd=m_Trayer->m_hWnd;
nid.uID=IDC_TRAYICON;
nid.uFlags=0;
VERIFY(Shell_NotifyIcon(NIM_DELETE,&nid));
WinHelp(0L, HELP_QUIT);
CDialog::OnDestroy();
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CKLogDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
@@ -1240,128 +1243,155 @@ NOTIFYICONDATA nid;
return 0;
}
void CKLogDlg::OnClose()
{
OnTrayShowklogwindow();
}
void CKLogDlg::OnTrayAboutklog()
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CKLogDlg::OnTrayExit()
{
OnExit();
}
void CKLogDlg::OnTrayShowklogwindow()
{
if(IsWindowVisible()){
m_bShown=FALSE;
ShowWindow(SW_HIDE);
}else{
m_bShown=TRUE;
ShowWindow(SW_SHOW);
SetForegroundWindow();
SetFocus();
}
}
void CKLogDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
CDialog::OnWindowPosChanging(lpwndpos);
if(!m_bExiting){
if(m_bShown){
lpwndpos->flags&=~SWP_HIDEWINDOW;
lpwndpos->flags|=SWP_SHOWWINDOW;
}else{
lpwndpos->flags&=~SWP_SHOWWINDOW;
lpwndpos->flags|=SWP_HIDEWINDOW;
if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu))
GetDesktopWindow()->SetForegroundWindow();
}
}
}
void CKLogDlg::LoadSettings()
{
CWinApp *app = AfxGetApp();
ASSERT(app);
m_LogItems=app->GetProfileInt("UISettings","LogLength",m_LogItems);
m_bShown=app->GetProfileInt("UISettings","Visible",m_bShown);
m_bWarnBlocking=app->GetProfileInt("Resolve","WarnBlocking",m_bWarnBlocking);
m_bDontWarn=app->GetProfileInt("Resolve","DontWarn",m_bDontWarn);
}
void CKLogDlg::SaveSettings()
{
CWinApp *app = AfxGetApp();
ASSERT(app);
app->WriteProfileInt("UISettings","LogLength",m_LogItems);
app->WriteProfileInt("UISettings","Visible",m_bShown);
app->WriteProfileInt("Resolve","WarnBlocking",m_bWarnBlocking);
app->WriteProfileInt("Resolve","DontWarn",m_bDontWarn);
CMemFile mf(4096);
CArchive ar(&mf,CArchive::store);
Serialize(ar);
ar.Close();
DWORD dataLength = mf.GetLength();
if(dataLength&0xFFFF0000l){
CString tmp;
tmp.LoadString(IDS_MSG_FAILEDTOSTORE);
MessageBox(tmp,NULL,MB_ICONHAND|MB_OK);
}else{
UINT dl = (UINT)dataLength;
BYTE *data = mf.Detach();
app->WriteProfileBinary("Layout","Destinations",data,dl);
delete data;
}
}
CKLogDlg::~CKLogDlg()
{
delete m_Trayer;
}
void CKLogDlg::OnLogpattern()
{
CLogPattern lp(IDS_LOGPATTERN_TITLE,this);
memmove(lp.m_Pattern,m_Logger->m_LogPattern,sizeof(lp.m_Pattern));
if(lp.DoModal()==IDOK){
memmove(m_Logger->m_LogPattern,lp.m_Pattern,sizeof(m_Logger->m_LogPattern));
UpdatePriface(FALSE,TRUE);
}
}
void CLogger::LookupHost(CKLogDlg *daddy)
{
m_LogToHost.sin_addr.s_addr=inet_addr((LPCTSTR)m_LogToName);
if(m_LogToHost.sin_addr.s_addr==INADDR_NONE){
if(daddy->m_bWarnBlocking){
CWarnBlocking wb(::IsWindow(daddy->m_hWnd)?daddy:NULL);
wb.m_bDontWarn = daddy->m_bDontWarn;
if(wb.DoModal()!=IDOK)
return;
daddy->m_bDontWarn=wb.m_bDontWarn;
daddy->m_bWarnBlocking=!wb.m_bDontWarn;
}
daddy->BeginWaitCursor();
hostent *he = gethostbyname(m_LogToName);
daddy->EndWaitCursor();
if(he){
m_LogToHost.sin_addr.s_addr = *(DWORD*)he->h_addr;
}else{
m_LogToHost.sin_addr.s_addr = INADDR_NONE;
if(daddy->m_bWarnBlocking){
CString sux;
sux.Format(IDS_MSG_LOOKUPFAILED,(LPCTSTR)m_LogToName);
daddy->MessageBox(sux,NULL,MB_ICONSTOP|MB_OK);
}else
MessageBeep(MB_ICONHAND);
}
}
}
+
+void CKLogDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
+{
+ CDialog::OnGetMinMaxInfo(lpMMI);
+ WINDOWPLACEMENT wp;
+ if(IsWindow(m_CancelCtl.m_hWnd) && m_CancelCtl.GetWindowPlacement(&wp)) {
+ CRect wr; GetWindowRect(wr);
+ CRect cr; GetClientRect(cr);
+ CSize ncs = (wr-cr).Size();
+ CRect ctlr = wp.rcNormalPosition;
+ CSize corner = ctlr.BottomRight()+ncs;
+ lpMMI->ptMaxTrackSize.x = lpMMI->ptMinTrackSize.x = corner.cx;
+ lpMMI->ptMinTrackSize.y = corner.cy;
+ }
+}
+
+void CKLogDlg::OnSize(UINT nType, int cx, int cy)
+{
+ CDialog::OnSize(nType, cx, cy);
+ if(!IsWindow(m_Log.m_hWnd))
+ return;
+ WINDOWPLACEMENT lp; m_Log.GetWindowPlacement(&lp);
+ CRect lr = lp.rcNormalPosition;
+ lr.bottom = cy-2;
+ CSize ls = lr.Size();
+ m_Log.SetWindowPos(0,0,0,ls.cx,ls.cy,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER);
+}