You've already forked lazarus-ccr
tvplanit: Import event category from ical file.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6501 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -241,9 +241,12 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent);
|
constructor Create(AOwner: TComponent);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function GetColor(Index: Integer): TColor;
|
function GetColor(AIndex: Integer): TColor;
|
||||||
function GetName(Index: Integer):string;
|
function GetName(AIndex: Integer):string;
|
||||||
function GetCategory(AIndex: Integer): TVpCategoryInfo;
|
function GetCategory(AIndex: Integer): TVpCategoryInfo;
|
||||||
|
function IndexOfCategory(AName: String): Integer;
|
||||||
|
function IndexOfFirstUnusedCategory: Integer;
|
||||||
|
procedure SetCategoryName(AIndex: Integer; AName: String);
|
||||||
published
|
published
|
||||||
property Category0: TVpCategoryInfo index 0 read GetCategory write SetCat;
|
property Category0: TVpCategoryInfo index 0 read GetCategory write SetCat;
|
||||||
property Category1: TVpCategoryInfo index 1 read GetCategory write SetCat;
|
property Category1: TVpCategoryInfo index 1 read GetCategory write SetCat;
|
||||||
@ -713,7 +716,7 @@ var
|
|||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FOwner := AOwner;
|
FOwner := AOwner;
|
||||||
for i:=0 to High(FCat) do
|
for i:=Low(FCat) to High(FCat) do
|
||||||
begin
|
begin
|
||||||
FCat[i] := TVpCategoryInfo.Create(FOwner);
|
FCat[i] := TVpCategoryInfo.Create(FOwner);
|
||||||
FCat[i].FIndex := i;
|
FCat[i].FIndex := i;
|
||||||
@ -726,7 +729,7 @@ destructor TVpCategoryColorMap.Destroy;
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
for i:=0 to High(FCat) do FCat[i].Free;
|
for i:=Low(FCat) to High(FCat) do FCat[i].Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -735,18 +738,42 @@ begin
|
|||||||
Result := FCat[AIndex];
|
Result := FCat[AIndex];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TVpCategoryColorMap.GetColor(Index: Integer): TColor;
|
function TVpCategoryColorMap.IndexOfCategory(AName: String): Integer;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if Index <= High(FCat) then
|
for i:=Low(FCat) to High(FCat) do
|
||||||
Result := FCat[Index].Color
|
if SameText(FCat[i].Description, AName) then begin
|
||||||
|
Result := i;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TVpCategoryColorMap.IndexOfFirstUnusedCategory: Integer;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := Low(FCat) to High(FCat) do
|
||||||
|
if FCat[i].Description = Format(RSCategoryDesc, [i]) then begin
|
||||||
|
Result := i;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TVpCategoryColorMap.GetColor(AIndex: Integer): TColor;
|
||||||
|
begin
|
||||||
|
if (AIndex >= Low(FCat)) and (AIndex <= High(FCat)) then
|
||||||
|
Result := FCat[AIndex].Color
|
||||||
else
|
else
|
||||||
Result := clBlack;
|
Result := clBlack;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TVpCategoryColorMap.GetName(Index: Integer): string;
|
function TVpCategoryColorMap.GetName(AIndex: Integer): string;
|
||||||
begin
|
begin
|
||||||
if Index <= High(FCat) then
|
if (AIndex >= Low(FCat)) and (AIndex <= High(FCat)) then
|
||||||
Result := FCat[Index].Description
|
Result := FCat[AIndex].Description
|
||||||
else
|
else
|
||||||
Result := '';
|
Result := '';
|
||||||
end;
|
end;
|
||||||
@ -756,6 +783,11 @@ begin
|
|||||||
FCat[AIndex] := AValue;
|
FCat[AIndex] := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TVpCategoryColorMap.SetCategoryName(AIndex: Integer; AName: String);
|
||||||
|
begin
|
||||||
|
if (AIndex >= Low(FCat)) and (AIndex <= High(FCat)) then
|
||||||
|
FCat[AIndex].Description := AName;
|
||||||
|
end;
|
||||||
|
|
||||||
(*****************************************************************************)
|
(*****************************************************************************)
|
||||||
{ TVpCategoryInfo }
|
{ TVpCategoryInfo }
|
||||||
|
@ -233,7 +233,7 @@ type
|
|||||||
FResource : TVpResource;
|
FResource : TVpResource;
|
||||||
dsAlertTimer : TTimer; { fires the alerts }
|
dsAlertTimer : TTimer; { fires the alerts }
|
||||||
FNotifiers : TList;
|
FNotifiers : TList;
|
||||||
FLinkedOwner: TComponent;
|
FLinkedOwner : TComponent;
|
||||||
|
|
||||||
{events}
|
{events}
|
||||||
FOnConnect : TNotifyEvent;
|
FOnConnect : TNotifyEvent;
|
||||||
|
@ -77,7 +77,7 @@ type
|
|||||||
|
|
||||||
TVpResources = class
|
TVpResources = class
|
||||||
private
|
private
|
||||||
FOwner: TObject;
|
FOwner: TObject; // This is the Datastore.
|
||||||
FResourceGroups: TList;
|
FResourceGroups: TList;
|
||||||
function GetCount: Integer;
|
function GetCount: Integer;
|
||||||
function GetItem(Index: Integer): TVpResource;
|
function GetItem(Index: Integer): TVpResource;
|
||||||
@ -695,7 +695,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Math, DateUtils,
|
Math, DateUtils,
|
||||||
VpException, VpConst, VpMisc;
|
VpException, VpConst, VpMisc, VpBaseDS;
|
||||||
|
|
||||||
const
|
const
|
||||||
TIME_EPS = 1.0 / SecondsInDay; // Epsilon for comparing times
|
TIME_EPS = 1.0 / SecondsInDay; // Epsilon for comparing times
|
||||||
@ -1269,6 +1269,9 @@ end;
|
|||||||
procedure TVpEvent.LoadFromICalendar(AEntry: TVpICalEvent);
|
procedure TVpEvent.LoadFromICalendar(AEntry: TVpICalEvent);
|
||||||
var
|
var
|
||||||
dt: Double;
|
dt: Double;
|
||||||
|
cat: String;
|
||||||
|
i, j, k: Integer;
|
||||||
|
datastore: TVpCustomDatastore;
|
||||||
begin
|
begin
|
||||||
if AEntry = nil then
|
if AEntry = nil then
|
||||||
exit;
|
exit;
|
||||||
@ -1279,6 +1282,30 @@ begin
|
|||||||
FLocation := AEntry.Location;
|
FLocation := AEntry.Location;
|
||||||
// Start and end time already have been set --> Skip .
|
// Start and end time already have been set --> Skip .
|
||||||
|
|
||||||
|
{ Category }
|
||||||
|
{ tvplanit has only 1 category, ical may have several. We pick the first one
|
||||||
|
defined in the datastore. If none is defined we create the first one. }
|
||||||
|
if AEntry.CategoryCount > 0 then begin
|
||||||
|
datastore := TVpCustomDatastore(Owner.Owner.Owner.Owner);
|
||||||
|
k := -1;
|
||||||
|
for i := 0 to AEntry.CategoryCount-1 do begin
|
||||||
|
cat := AEntry.category[i];
|
||||||
|
j := datastore.CategoryColorMap.IndexOfCategory(cat);
|
||||||
|
if j <> -1 then begin
|
||||||
|
k := j;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if k = -1 then begin // category not found in data store
|
||||||
|
k := datastore.CategoryColorMap.IndexOfFirstUnusedCategory;
|
||||||
|
if k <> -1 then
|
||||||
|
datastore.CategoryColorMap.SetCategoryName(k, AEntry.Category[0]);
|
||||||
|
end;
|
||||||
|
if k <> -1 then
|
||||||
|
FCategory := k;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ All-day event }
|
{ All-day event }
|
||||||
FAllDayEvent := (frac(FStartTime) = 0) and (frac(FEndTime) = 0);
|
FAllDayEvent := (frac(FStartTime) = 0) and (frac(FEndTime) = 0);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ type
|
|||||||
private
|
private
|
||||||
FCalendar: TVpICalendar;
|
FCalendar: TVpICalendar;
|
||||||
public
|
public
|
||||||
constructor Create(ACalendar: TVpICalendar);
|
constructor Create(ACalendar: TVpICalendar); virtual;
|
||||||
function FindItem(AKey: String): TVpICalItem;
|
function FindItem(AKey: String): TVpICalItem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -46,6 +46,8 @@ type
|
|||||||
property AudioSrc: String read FAudioSrc;
|
property AudioSrc: String read FAudioSrc;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TVpICalEvent }
|
||||||
|
|
||||||
TVpICalEvent = class(TVpICalEntry)
|
TVpICalEvent = class(TVpICalEntry)
|
||||||
private
|
private
|
||||||
FSummary: String; // --> Description
|
FSummary: String; // --> Description
|
||||||
@ -62,9 +64,13 @@ type
|
|||||||
FRecurrenceCount: Integer;
|
FRecurrenceCount: Integer;
|
||||||
FRecurrenceByXXX: String;
|
FRecurrenceByXXX: String;
|
||||||
FAlarm: TVpICalAlarm;
|
FAlarm: TVpICalAlarm;
|
||||||
|
FCategories: TStrings;
|
||||||
|
function GetCategory(AIndex: Integer): String;
|
||||||
|
function GetCategoryCount: Integer;
|
||||||
function GetEndTime(UTC: Boolean): TDateTime;
|
function GetEndTime(UTC: Boolean): TDateTime;
|
||||||
function GetStartTime(UTC: Boolean): TDateTime;
|
function GetStartTime(UTC: Boolean): TDateTime;
|
||||||
public
|
public
|
||||||
|
constructor Create(ACalendar: TVpICalendar); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Analyze; override;
|
procedure Analyze; override;
|
||||||
procedure UseAlarm;
|
procedure UseAlarm;
|
||||||
@ -73,6 +79,8 @@ type
|
|||||||
property Location: String read FLocation;
|
property Location: String read FLocation;
|
||||||
property StartTime[UTC: Boolean]: TDateTime read GetStartTime;
|
property StartTime[UTC: Boolean]: TDateTime read GetStartTime;
|
||||||
property EndTime[UTC: Boolean]: TDateTime read GetEndTime;
|
property EndTime[UTC: Boolean]: TDateTime read GetEndTime;
|
||||||
|
property Category[AIndex: Integer]: String read GetCategory;
|
||||||
|
property CategoryCount: Integer read GetCategoryCount;
|
||||||
property Alarm: TVpICalAlarm read FAlarm;
|
property Alarm: TVpICalAlarm read FAlarm;
|
||||||
property RecurrenceFrequency: String read FRecurrenceFreq;
|
property RecurrenceFrequency: String read FRecurrenceFreq;
|
||||||
property RecurrenceInterval: Integer read FRecurrenceInterval;
|
property RecurrenceInterval: Integer read FRecurrenceInterval;
|
||||||
@ -287,8 +295,17 @@ end;
|
|||||||
{ TVpICalEvent }
|
{ TVpICalEvent }
|
||||||
{==============================================================================}
|
{==============================================================================}
|
||||||
|
|
||||||
|
constructor TVpICalEvent.Create(ACalendar: TVpICalendar);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
FCategories := TStringList.Create;
|
||||||
|
FCategories.Delimiter := VALUE_DELIMITER;
|
||||||
|
FCategories.StrictDelimiter := True;
|
||||||
|
end;
|
||||||
|
|
||||||
destructor TVpICalEvent.Destroy;
|
destructor TVpICalEvent.Destroy;
|
||||||
begin
|
begin
|
||||||
|
FCategories.Free;
|
||||||
FAlarm.Free;
|
FAlarm.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
@ -328,6 +345,8 @@ begin
|
|||||||
FLocation := item.Value;
|
FLocation := item.Value;
|
||||||
'DURATION':
|
'DURATION':
|
||||||
FDuration := ICalDuration(item.Value);
|
FDuration := ICalDuration(item.Value);
|
||||||
|
'CATEGORIES':
|
||||||
|
FCategories.DelimitedText := item.Value;
|
||||||
'RRULE':
|
'RRULE':
|
||||||
begin
|
begin
|
||||||
L := TStringList.Create;
|
L := TStringList.Create;
|
||||||
@ -354,6 +373,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TVpICalEvent.GetCategory(AIndex: Integer): String;
|
||||||
|
begin
|
||||||
|
if (AIndex >= 0) and (AIndex < FCategories.Count) then
|
||||||
|
Result := FCategories[AIndex]
|
||||||
|
else
|
||||||
|
Result := '';
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TVpICalEvent.GetCategoryCount: Integer;
|
||||||
|
begin
|
||||||
|
Result := FCategories.Count;
|
||||||
|
end;
|
||||||
|
|
||||||
function TVpICalEvent.GetEndTime(UTC: Boolean): TDateTime;
|
function TVpICalEvent.GetEndTime(UTC: Boolean): TDateTime;
|
||||||
begin
|
begin
|
||||||
if FEndTime <> 0 then
|
if FEndTime <> 0 then
|
||||||
|
Reference in New Issue
Block a user