unit vwmain.presenter;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils,
obs_prosu, vwmain.intf, vwmain.decl, vwmain.model, vwmain.trxman;//,
//Settings;
type
{ alias from vwmain.trxman }
TTransactionManager = vwmain.trxman.TTransactionManager;
TDirTransaction = vwmain.trxman.TDirTransaction;
TSettingsTransaction = vwmain.trxman.TSettingsTransaction;
//TCreateDbFileTransaction = vwmain.trxman.TCreateDbFileTransaction;
{ TPresenter }
TPresenter = class(TObject, IPresenter)
private
FProvider: TobsProvider;
FModel: TModel;
FTrxMan: TTransactionManager;
FAppLocation : String;
function get_AppLocation: String;
function get_Provider: IobsProvider;
function get_TrxMan: ITransactionManager; // <--- HERE
function Obj: TObject;
procedure set_AppLocation(AValue: String);
protected
public
constructor Create;
destructor Destroy; override;
procedure GetStaticTexts(aRegion: word);
procedure SetStatusbartext(aText: string; panel: word);
function GetSettingsrecord: TSettingsRec;
procedure ReadSettings;
//procedure StartLogging(logFile: string);
property Provider: IobsProvider read get_Provider;
property TrxMan: ITransactionManager read get_TrxMan; // <--- HERE
property ApplicationLocation: String read get_AppLocation write set_AppLocation;
end;
implementation
{ TPresenter }
{%region Prpoerties}
function TPresenter.get_Provider: IobsProvider;
begin
Result := FProvider;
end;
function TPresenter.get_TrxMan: ITransactionManager; // <--- HERE
begin
Result := FTrxMan;
end;
function TPresenter.get_AppLocation: String;
begin
Result := FAppLocation;
end;
procedure TPresenter.set_AppLocation(AValue: String);
begin
FAppLocation := AValue;
end;
{%endregion Prpoerties}
function TPresenter.Obj: TObject;
begin
Result := Self;
end;
procedure TPresenter.ReadSettings;
var
lStrx : TSettingsTransaction;
SettingsFile : String;
begin
SettingsFile := FAppLocation + adSettings + PathDelim + afSettingsFile;
lStrx := TrxMan.StartTransaction(msReadSettings) as TSettingsTransaction;
try
lStrx.SettingsFile := SettingsFile;
TrxMan.CommitTransaction;
except
TrxMan.RollbackTransaction;
end; // mandatory, does NOTHING and _frees_ transaction
end;
constructor TPresenter.Create;
begin
inherited Create;
FProvider := CreateObsProvider;
FModel := TModel.Create(Self); // Presenter owns the model.
FTrxMan := TTransactionManager.Create(Self, FModel);
end;
destructor TPresenter.Destroy;
begin
FTrxMan.Free;
FModel.Free;
FProvider.Free;
inherited Destroy;
end;
procedure TPresenter.GetStaticTexts(aRegion: word);
var
lstaRec: TStaticTextsAll;
begin
case aRegion of
gstAll: if Assigned(fModel) then begin
lstaRec:= fModel.FetchViewTextsFull;
fProvider.NotifySubscribers(prStaticTexts,Self,@lstaRec);
end;
end;
end;
procedure TPresenter.SetStatusbartext(aText: string; panel: word);
var
lsbpRec : TStatusbarPanelText;
begin
lsbpRec := fModel.SetStatusbartext(aText, panel);
fProvider.NotifySubscribers(prStatusBarPanelText,Self,@lsbpRec);
end;
function TPresenter.GetSettingsrecord: TSettingsRec;
begin
Result := FModel.SettingsRec;
end;
end.