You've already forked lazarus-ccr
tvplanit: Implement resource groups for flat-file datastores.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8171 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -34,12 +34,13 @@ unit VpBaseDS; { Base DataStore classes }
|
|||||||
|
|
||||||
{$I vp.inc}
|
{$I vp.inc}
|
||||||
|
|
||||||
|
{.$DEFINE DEBUG_RESOURCE_GROUPS}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF LCL}
|
{$IFDEF LCL}
|
||||||
LMessages, LCLProc, LCLIntf, LCLVersion, LazFileUtils,
|
LMessages, LCLProc, LCLIntf, LCLVersion, LazFileUtils, LazLogger,
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Windows, Messages,
|
Windows, Messages,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@@ -272,6 +273,9 @@ type
|
|||||||
|
|
||||||
procedure DeregisterAllWatchers;
|
procedure DeregisterAllWatchers;
|
||||||
procedure DeregisterWatcher(Watcher: THandle);
|
procedure DeregisterWatcher(Watcher: THandle);
|
||||||
|
{$IFDEF DEBUG_RESOURCE_GROUPS}
|
||||||
|
procedure DumpResources;
|
||||||
|
{$ENDIF}
|
||||||
function GetNextID(TableName: string): Integer; virtual; abstract;
|
function GetNextID(TableName: string): Integer; virtual; abstract;
|
||||||
procedure NotifyDependents;
|
procedure NotifyDependents;
|
||||||
procedure RegisterWatcher(Watcher: THandle);
|
procedure RegisterWatcher(Watcher: THandle);
|
||||||
@@ -627,7 +631,36 @@ begin
|
|||||||
end; { with }
|
end; { with }
|
||||||
end; { if }
|
end; { if }
|
||||||
end;
|
end;
|
||||||
{=====}
|
|
||||||
|
{$IFDEF DEBUG_RESOURCE_GROUPS}
|
||||||
|
procedure TVpCustomDatastore.DumpResources;
|
||||||
|
var
|
||||||
|
i, j: Integer;
|
||||||
|
res: TVpResource;
|
||||||
|
ev: TVpEvent;
|
||||||
|
s: String;
|
||||||
|
begin
|
||||||
|
for i := 0 to Resources.Count-1 do
|
||||||
|
begin
|
||||||
|
res := Resources.Items[i];
|
||||||
|
DebugLn('Resource #' + IntToStr(i));
|
||||||
|
DebugLn(' Description: ' + res.Description);
|
||||||
|
DebugLn(' ResourceID: ' + IntToStr(res.ResourceID));
|
||||||
|
if res.Group = nil then
|
||||||
|
DebugLn(' not grouped')
|
||||||
|
else
|
||||||
|
DebugLn(' Group: ' + res.Group.Caption);
|
||||||
|
for j := 0 to res.Schedule.EventCount-1 do
|
||||||
|
begin
|
||||||
|
ev := res.Schedule.GetEvent(j);
|
||||||
|
DebugLn(' Event #' + IntToStr(j));
|
||||||
|
DebugLn(' ResourceID: ' + IntToStr(ev.ResourceID));
|
||||||
|
DebugLn(' EventID: ' + IntToStr(ev.RecordID));
|
||||||
|
DebugLn(' Description: ' + ev.Description);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
function TVpCustomDatastore.IsStoredMediaFolder: Boolean;
|
function TVpCustomDatastore.IsStoredMediaFolder: Boolean;
|
||||||
begin
|
begin
|
||||||
|
@@ -305,6 +305,7 @@ type
|
|||||||
constructor Create(Owner: TVpSchedule);
|
constructor Create(Owner: TVpSchedule);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function CanEdit: Boolean;
|
function CanEdit: Boolean;
|
||||||
|
function CopyToSchedule(ASchedule: TVpSchedule): TVpEvent;
|
||||||
function GetResource: TVpResource;
|
function GetResource: TVpResource;
|
||||||
function IsOverlayed: Boolean;
|
function IsOverlayed: Boolean;
|
||||||
procedure LoadFromICalendar(AEntry: TVpICalEvent);
|
procedure LoadFromICalendar(AEntry: TVpICalEvent);
|
||||||
@@ -1049,8 +1050,11 @@ begin
|
|||||||
for i := Low(AResources) to High(AResources) do
|
for i := Low(AResources) to High(AResources) do
|
||||||
grp.AddID(AResources[i].ResourceID);
|
grp.AddID(AResources[i].ResourceID);
|
||||||
|
|
||||||
FGroup := grp;
|
if grp.Count > 0 then
|
||||||
Result := grp;
|
FGroup := grp
|
||||||
|
else
|
||||||
|
FGroup := nil;
|
||||||
|
Result := FGroup;
|
||||||
|
|
||||||
// Repaint the events
|
// Repaint the events
|
||||||
TVpCustomDatastore(FOwner.FOwner).RefreshEvents;
|
TVpCustomDatastore(FOwner.FOwner).RefreshEvents;
|
||||||
@@ -1287,6 +1291,37 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TVpEvent.CopyToSchedule(ASchedule: TVpSchedule): TVpEvent;
|
||||||
|
begin
|
||||||
|
Result := ASchedule.AddEvent(FResourceID, FStartTime, FEndTime);
|
||||||
|
// ResourceID will be assigned outside
|
||||||
|
Result.RecordID := FRecordID;
|
||||||
|
Result.DingPath := FDingPath;
|
||||||
|
Result.AlertDisplayed := FAlertDisplayed;
|
||||||
|
Result.AllDayEvent := FAllDayEvent;
|
||||||
|
Result.Description := FDescription;
|
||||||
|
Result.Notes := FNotes;
|
||||||
|
Result.Category := FCategory;
|
||||||
|
Result.AlarmSet := FAlarmSet;
|
||||||
|
Result.AlarmAdvance := FAlarmAdv;
|
||||||
|
Result.Location := FLocation;
|
||||||
|
Result.AlarmAdvanceType := FAlarmAdvType;
|
||||||
|
Result.SnoozeTime := FSnoozeTime;
|
||||||
|
Result.RepeatCode := FRepeatCode;
|
||||||
|
Result.RepeatRangeEnd := FRepeatRangeEnd;
|
||||||
|
Result.CustomInterval := FCustInterval;
|
||||||
|
Result.UserField0 := FUserField0;
|
||||||
|
Result.UserField1 := FUserField1;
|
||||||
|
Result.UserField2 := FUserField2;
|
||||||
|
Result.UserField3 := FUserField3;
|
||||||
|
Result.UserField4 := FUserField4;
|
||||||
|
Result.UserField5 := FUserField5;
|
||||||
|
Result.UserField6 := FUserField6;
|
||||||
|
Result.UserField7 := FUserField7;
|
||||||
|
Result.UserField8 := FUserField8;
|
||||||
|
Result.UserField8 := FUserField9;
|
||||||
|
end;
|
||||||
|
|
||||||
{ Returns the resource to which the event belongs. }
|
{ Returns the resource to which the event belongs. }
|
||||||
function TVpEvent.GetResource: TVpResource;
|
function TVpEvent.GetResource: TVpResource;
|
||||||
begin
|
begin
|
||||||
|
@@ -11,15 +11,80 @@ unit VpFileDS;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
VpBase, VpData, VpBaseDS;
|
VpData, VpBaseDS;
|
||||||
|
|
||||||
type
|
type
|
||||||
TVpCustomFileDataStore = class(TVpCustomDataStore)
|
TVpCustomFileDataStore = class(TVpCustomDataStore)
|
||||||
private
|
private
|
||||||
protected
|
protected
|
||||||
public
|
public
|
||||||
|
procedure RefreshEvents; override;
|
||||||
|
procedure UngroupEvents; virtual;
|
||||||
|
procedure UpdateGroupEvents; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
procedure TVpCustomFileDataStore.RefreshEvents;
|
||||||
|
begin
|
||||||
|
UpdateGroupEvents;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TVpCustomFileDataStore.UngroupEvents;
|
||||||
|
var
|
||||||
|
i, j: Integer;
|
||||||
|
res: TVpResource;
|
||||||
|
event, newEvent: TVpEvent;
|
||||||
|
eventRes: TVpResource;
|
||||||
|
begin
|
||||||
|
for i := 0 to Resources.Count-1 do
|
||||||
|
begin
|
||||||
|
res := Resources.Items[i];
|
||||||
|
for j := res.Schedule.EventCount-1 downto 0 do
|
||||||
|
begin
|
||||||
|
event := res.Schedule.GetEvent(j);
|
||||||
|
if event.IsOverlayed then
|
||||||
|
begin
|
||||||
|
eventRes := Resources.GetResource(event.ResourceID);
|
||||||
|
newEvent := event.CopyToSchedule(eventres.Schedule);
|
||||||
|
newEvent.ResourceID := eventRes.ResourceID;
|
||||||
|
event.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Iterates through all events and moves them to the resource as specified by the
|
||||||
|
resource groups. }
|
||||||
|
procedure TVpCustomFileDataStore.UpdateGroupEvents;
|
||||||
|
var
|
||||||
|
i, j, k: Integer;
|
||||||
|
res, gres: TVpResource;
|
||||||
|
event, newevent: TVpEvent;
|
||||||
|
begin
|
||||||
|
UngroupEvents;
|
||||||
|
|
||||||
|
for i := 0 to Resources.Count-1 do
|
||||||
|
begin
|
||||||
|
res := Resources.Items[i];
|
||||||
|
if res.Group <> nil then begin
|
||||||
|
for j := 0 to res.Group.Count-1 do
|
||||||
|
begin
|
||||||
|
gres := res.Group.Items[j];
|
||||||
|
for k := gres.Schedule.EventCount-1 downto 0 do
|
||||||
|
begin
|
||||||
|
event := gres.Schedule.GetEvent(k);
|
||||||
|
if event.ResourceID = gres.ResourceID then
|
||||||
|
begin
|
||||||
|
newEvent := event.CopyToSchedule(res.Schedule);
|
||||||
|
newEvent.ResourceID := event.ResourceID;
|
||||||
|
event.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@@ -323,7 +323,7 @@ begin
|
|||||||
try
|
try
|
||||||
L.AddDateTimeField('StartTime', AEvent.StartTime, 'c'); // short date + long time
|
L.AddDateTimeField('StartTime', AEvent.StartTime, 'c'); // short date + long time
|
||||||
L.AddDateTimeField('EndTime', AEvent.EndTime, 'c'); // 1
|
L.AddDateTimeField('EndTime', AEvent.EndTime, 'c'); // 1
|
||||||
L.AddField('ResourceID', IntToStr(AEvent.ResourceID));
|
L.AddField('ResourceID', IntToStr(AEvent.ResourceID)); //wp: inserted - don't know how it affects the numbers at the right...
|
||||||
L.AddField('Description', AEvent.Description);
|
L.AddField('Description', AEvent.Description);
|
||||||
L.AddField('Location', AEvent.Location);
|
L.AddField('Location', AEvent.Location);
|
||||||
L.AddField('Notes', EncodeLineEndings(AEvent.Notes));
|
L.AddField('Notes', EncodeLineEndings(AEvent.Notes));
|
||||||
@@ -828,6 +828,9 @@ begin
|
|||||||
for i:=0 to L.Count-1 do begin
|
for i:=0 to L.Count-1 do begin
|
||||||
L.Extract(i, fn, fv);
|
L.Extract(i, fn, fv);
|
||||||
fn := Lowercase(fn);
|
fn := Lowercase(fn);
|
||||||
|
if fn = 'resourceid' then begin
|
||||||
|
// this will be handled outside...
|
||||||
|
end else
|
||||||
if fn = 'starttime' then begin
|
if fn = 'starttime' then begin
|
||||||
if fv = '' then
|
if fv = '' then
|
||||||
AEvent.StartTime := 0 else
|
AEvent.StartTime := 0 else
|
||||||
@@ -1236,6 +1239,10 @@ begin
|
|||||||
if FFileName = '' then
|
if FFileName = '' then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
// We do not yet store grouped events. Until this is implemented we must
|
||||||
|
// move the events back into their original resources.
|
||||||
|
UngroupEvents;
|
||||||
|
|
||||||
ini := TMemIniFile.Create(FFileName);
|
ini := TMemIniFile.Create(FFileName);
|
||||||
try
|
try
|
||||||
ini.Clear;
|
ini.Clear;
|
||||||
|
@@ -766,6 +766,10 @@ begin
|
|||||||
if not Connected then
|
if not Connected then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
// We do not yet store grouped events. Until this is implemented we must
|
||||||
|
// move the events back into their original resources.
|
||||||
|
UngroupEvents;
|
||||||
|
|
||||||
json := TJSONObject.Create;
|
json := TJSONObject.Create;
|
||||||
try
|
try
|
||||||
resObjArray := TJSONArray.Create;
|
resObjArray := TJSONArray.Create;
|
||||||
|
@@ -1694,6 +1694,10 @@ begin
|
|||||||
if FFileName = '' then
|
if FFileName = '' then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
// We do not yet store grouped events. Until this is implemented we must
|
||||||
|
// move the events back into their original resources.
|
||||||
|
UngroupEvents;
|
||||||
|
|
||||||
doc := nil;
|
doc := nil;
|
||||||
try
|
try
|
||||||
if FileExists(FFileName) then begin
|
if FileExists(FFileName) then begin
|
||||||
|
Reference in New Issue
Block a user