unit ViewConfigure;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
obs_prosu, vwmain.intf, vwmain.decl, vwmain.presenter, vwmain.types;
type
{ TfrmViewConfigure }
TfrmViewConfigure = class(TForm, IView) // same View interface as the MainView
btnClose: TButton;
chkActiveLogging: TCheckBox;
chkAppenLogging: TCheckBox;
gbLogging: TGroupBox;
PageControlConfigure: TPageControl;
TabSheetMiscellaneous: TTabSheet;
TabSheetAppDb: TTabSheet;
procedure btnCloseClick(Sender: TObject);
procedure chkActiveLoggingChange(Sender: TObject);
procedure chkAppenLoggingChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FSubscriber : TobsSubscriber; // Holds the Observer.
FPresenter : IPresenter; // Holds the Presenter.
function get_Presenter: IPresenter;
function get_Subscriber: IobsSubscriber;
procedure set_Presenter(AValue: IPresenter);
function Obj: TObject;
procedure DoSetChecks(Sender: TObject);
protected
procedure HandleObsNotify(aReason: TProviderReason;aNotifyClass: TObject;UserData: pointer);
procedure DoSetStaticTexts(aTextRec: PStaticTextsAll);
procedure ReadSettings;
procedure DoReadSettings({%H-}aSender: TObject; aData: Pointer);
public
constructor CreateWith(anOwner: TComponent;aPresenter: IPresenter);
property Subscriber: IobsSubscriber read get_Subscriber;
property Presenter: IPresenter read get_Presenter write set_Presenter;
end;
var
frmViewConfigure: TfrmViewConfigure;
implementation
{$R *.lfm}
{ TfrmViewConfigure }
procedure TfrmViewConfigure.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmViewConfigure.chkActiveLoggingChange(Sender: TObject);
begin
DoSetChecks(Sender);
end;
procedure TfrmViewConfigure.chkAppenLoggingChange(Sender: TObject);
begin
DoSetChecks(Sender);
end;
procedure TfrmViewConfigure.FormCreate(Sender: TObject);
begin
// at the moment it's not in use
end;
procedure TfrmViewConfigure.FormDestroy(Sender: TObject);
begin
if Assigned(FPresenter) then begin
FPresenter.Provider.UnSubscribe(FSubscriber);
FSubscriber.Free;
FPresenter:= nil;
end;
end;
procedure TfrmViewConfigure.FormShow(Sender: TObject);
begin
FPresenter.ReadSettings;
end;
function TfrmViewConfigure.get_Presenter: IPresenter;
begin
Result := FPresenter;
end;
function TfrmViewConfigure.get_Subscriber: IobsSubscriber;
begin
Result := FSubscriber;
end;
procedure TfrmViewConfigure.set_Presenter(AValue: IPresenter);
begin
{ This is called when the view is created. }
if aValue = nil then begin
if Assigned(fPresenter) then FPresenter.Provider.UnSubscribe(FSubscriber); // ==> Provider = property from TPresenter. LET OP: Hier koppel je de HandleObsNotify
FPresenter:= nil;
exit;
end;
if aValue <> fPresenter then begin
if Assigned(FPresenter) then fPresenter.Provider.UnSubscribe(FSubscriber); { we can't detach nil }
if Assigned(aValue) then begin
FPresenter:= aValue;
FPresenter.Provider.Subscribe(FSubscriber);
FPresenter.GetStaticTexts(gstAll); // Get All static texts
end;
end;
end;
function TfrmViewConfigure.Obj: TObject;
begin
Result := self;
end;
procedure TfrmViewConfigure.DoSetChecks(Sender: TObject);
var
lStrx : TSettingsTransaction;
lPrepareRec : TSettingsRec;
begin
lStrx := FPresenter.TrxMan.StartTransaction(msUpdateSettings) as TSettingsTransaction;
try
lPrepareRec := FPresenter.GetSettingsrecord; // Get the current record.
if (Sender as TCheckBox).Name = 'chkActiveLogging' then
lPrepareRec.setActivateLogging := chkActiveLogging.Checked
else if (Sender as TCheckBox).Name = 'chkAppenLogging' then
lPrepareRec.setAppendLogFile := chkAppenLogging.Checked;
//..
lStrx.AllAppSettings := lPrepareRec;
FPresenter.TrxMan.CommitTransaction;
except
fPresenter.TrxMan.RollbackTransaction;
end;
end;
procedure TfrmViewConfigure.HandleObsNotify(aReason: TProviderReason;
aNotifyClass: TObject; UserData: pointer);
begin
case aReason of
prStaticTexts: DoSetStaticTexts(UserData);
prAppSettings: DoReadSettings(aNotifyClass,UserData);
end;
end;
procedure TfrmViewConfigure.DoSetStaticTexts(aTextRec: PStaticTextsAll);
begin
with aTextRec^ do begin
Caption := staVwConfigure;
btnClose.caption := staOptionsBtnCloseCaption;
TabSheetAppDb.Caption := staTbsAppDdCaption;
TabSheetMiscellaneous.Caption := staTbsMiscellaneousCaption;
gbLogging.Caption := staGbLoggingCaption;
chkActiveLogging.Caption := staChkActiveLoggingCaption;
chkAppenLogging.Caption := staChkAppendLoggingCaption;
end;
end;
procedure TfrmViewConfigure.ReadSettings;
begin
end;
procedure TfrmViewConfigure.DoReadSettings(aSender: TObject; aData: Pointer);
begin
with PSettingsRec(aData)^ do begin
// if setSucces then begin
chkActiveLogging.Checked := setActivateLogging;
chkAppenLogging.Checked := setAppendLogFile;
// end else begin
// Caption := 'read setting: failed';
// end;
end;
end;
constructor TfrmViewConfigure.CreateWith(anOwner: TComponent; aPresenter: IPresenter);
begin
Create(anOwner);
FSubscriber := CreateObsSubscriber(@HandleObsNotify); { here's just fine }
Presenter:= aPresenter; { it's an interface, NO need to free :-) }
end;
end.