From cb211b4763a27196abeb206a5ab2e3762d6747fe Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Wed, 14 Sep 2011 04:25:01 +0000 Subject: [PATCH] Added copy/refresh support. --- src/sbbs3/ctrl/LoginAttemptsFormUnit.cpp | 64 +++++++++++++++++++++--- src/sbbs3/ctrl/LoginAttemptsFormUnit.dfm | 28 +++++++++-- src/sbbs3/ctrl/LoginAttemptsFormUnit.h | 9 ++++ 3 files changed, 92 insertions(+), 9 deletions(-) diff --git a/src/sbbs3/ctrl/LoginAttemptsFormUnit.cpp b/src/sbbs3/ctrl/LoginAttemptsFormUnit.cpp index e56f37f926..532956546a 100644 --- a/src/sbbs3/ctrl/LoginAttemptsFormUnit.cpp +++ b/src/sbbs3/ctrl/LoginAttemptsFormUnit.cpp @@ -36,6 +36,7 @@ #include "sbbs.h" #include <vcl.h> +#include <vcl/Clipbrd.hpp> #pragma hdrstop #include "LoginAttemptsFormUnit.h" @@ -53,7 +54,7 @@ __fastcall TLoginAttemptsForm::TLoginAttemptsForm(TComponent* Owner) { } //--------------------------------------------------------------------------- -void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender) +void __fastcall TLoginAttemptsForm::FillListView(TObject *Sender) { char str[128]; TListItem* Item; @@ -61,8 +62,6 @@ void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender) struct tm tm; login_attempt_t* attempt; - ColumnToSort=0; - SortBackwards=false; Screen->Cursor=crAppStart; listLock(&login_attempt_list); @@ -71,12 +70,12 @@ void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender) ListView->Items->BeginUpdate(); - for(node=listFirstNode(&login_attempt_list); node!=NULL; node=listNextNode(node)) { + for(node=login_attempt_list.first; node!=NULL; node=node->next) { attempt=(login_attempt_t*)node->data; if(attempt==NULL) continue; Item=ListView->Items->Add(); - Item->Caption=AnsiString(attempt->count); + Item->Caption=AnsiString(attempt->count-attempt->dupes); Item->Data=(void*)attempt->time; Item->SubItems->Add(attempt->dupes); Item->SubItems->Add(inet_ntoa(attempt->addr)); @@ -88,11 +87,20 @@ void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender) ,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec); Item->SubItems->Add(str); } + ListView->AlphaSort(); ListView->Items->EndUpdate(); listUnlock(&login_attempt_list); Screen->Cursor=crDefault; } +//--------------------------------------------------------------------------- +void __fastcall TLoginAttemptsForm::FormShow(TObject *Sender) +{ + ColumnToSort=0; + SortBackwards=true; + FillListView(Sender); +} + //--------------------------------------------------------------------------- void __fastcall TLoginAttemptsForm::FormClose(TObject *Sender, TCloseAction &Action) @@ -122,9 +130,13 @@ void __fastcall TLoginAttemptsForm::ListViewCompare(TObject *Sender, if(ColumnToSort==6) { /* Date */ num1=(ulong)Item1->Data; num2=(ulong)Item2->Data; - } else { + } else if(ColumnToSort==0) { num1=Item1->Caption.ToIntDef(0); num2=Item2->Caption.ToIntDef(0); + } else { + int ix = ColumnToSort - 1; + num1=Item1->SubItems->Strings[ix].ToIntDef(0); + num2=Item2->SubItems->Strings[ix].ToIntDef(0); } if(SortBackwards) Compare=(num2-num1); @@ -142,3 +154,43 @@ void __fastcall TLoginAttemptsForm::ListViewCompare(TObject *Sender, } //--------------------------------------------------------------------------- +static AnsiString ListItemString(TListItem* item) +{ + AnsiString str = item->Caption; + int i; + + for(i=0;i<item->SubItems->Count;i++) + str += "\t" + item->SubItems->Strings[i]; + + return str + "\r\n"; +} +//--------------------------------------------------------------------------- +void __fastcall TLoginAttemptsForm::CopyPopupClick(TObject *Sender) +{ + if(ListView->Selected==NULL) + return; + Clipboard()->SetTextBuf(ListItemString(ListView->Selected).c_str()); +} +//--------------------------------------------------------------------------- + +void __fastcall TLoginAttemptsForm::CopyAllPopupClick(TObject *Sender) +{ + AnsiString buf; + int i; + + for(i=0;i<ListView->Items->Count;i++) + buf += ListItemString(ListView->Items->Item[i]); + + Clipboard()->SetTextBuf(buf.c_str()); +} +//--------------------------------------------------------------------------- + +void __fastcall TLoginAttemptsForm::RefreshPopupClick(TObject *Sender) +{ + ListView->Items->BeginUpdate(); + ListView->Items->Clear(); + ListView->Items->EndUpdate(); + FillListView(Sender); +} +//--------------------------------------------------------------------------- + diff --git a/src/sbbs3/ctrl/LoginAttemptsFormUnit.dfm b/src/sbbs3/ctrl/LoginAttemptsFormUnit.dfm index ebaff9a607..a5b949bd92 100644 --- a/src/sbbs3/ctrl/LoginAttemptsFormUnit.dfm +++ b/src/sbbs3/ctrl/LoginAttemptsFormUnit.dfm @@ -1,8 +1,9 @@ object LoginAttemptsForm: TLoginAttemptsForm - Left = 522 - Top = 454 + Left = 729 + Top = 203 Width = 496 Height = 793 + BorderIcons = [biSystemMenu, biMaximize] Caption = 'Failed Login Attempts' Color = clBtnFace Font.Charset = DEFAULT_CHARSET @@ -10,6 +11,7 @@ object LoginAttemptsForm: TLoginAttemptsForm Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] + FormStyle = fsStayOnTop OldCreateOrder = False Position = poDefault OnClose = FormClose @@ -24,7 +26,7 @@ object LoginAttemptsForm: TLoginAttemptsForm Align = alClient Columns = < item - Caption = 'Count' + Caption = 'Unique' end item Caption = 'Dupes' @@ -49,9 +51,29 @@ object LoginAttemptsForm: TLoginAttemptsForm AutoSize = True Caption = 'Time' end> + PopupMenu = PopupMenu TabOrder = 0 ViewStyle = vsReport OnColumnClick = ListViewColumnClick OnCompare = ListViewCompare end + object PopupMenu: TPopupMenu + Left = 168 + Top = 184 + object CopyPopup: TMenuItem + Caption = 'Copy' + ShortCut = 16451 + OnClick = CopyPopupClick + end + object CopyAllPopup: TMenuItem + Caption = 'Copy All' + ShortCut = 16449 + OnClick = CopyAllPopupClick + end + object RefreshPopup: TMenuItem + Caption = 'Refresh' + ShortCut = 116 + OnClick = RefreshPopupClick + end + end end diff --git a/src/sbbs3/ctrl/LoginAttemptsFormUnit.h b/src/sbbs3/ctrl/LoginAttemptsFormUnit.h index 62af55428d..ed5bdf4e2f 100644 --- a/src/sbbs3/ctrl/LoginAttemptsFormUnit.h +++ b/src/sbbs3/ctrl/LoginAttemptsFormUnit.h @@ -8,18 +8,27 @@ #include <StdCtrls.hpp> #include <Forms.hpp> #include <ComCtrls.hpp> +#include <Menus.hpp> //--------------------------------------------------------------------------- class TLoginAttemptsForm : public TForm { __published: // IDE-managed Components TListView *ListView; + TPopupMenu *PopupMenu; + TMenuItem *CopyPopup; + TMenuItem *CopyAllPopup; + TMenuItem *RefreshPopup; void __fastcall FormShow(TObject *Sender); void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall ListViewColumnClick(TObject *Sender, TListColumn *Column); void __fastcall ListViewCompare(TObject *Sender, TListItem *Item1, TListItem *Item2, int Data, int &Compare); + void __fastcall CopyPopupClick(TObject *Sender); + void __fastcall CopyAllPopupClick(TObject *Sender); + void __fastcall RefreshPopupClick(TObject *Sender); private: // User declarations + void __fastcall FillListView(TObject *Sender); public: // User declarations __fastcall TLoginAttemptsForm(TComponent* Owner); int ColumnToSort; -- GitLab