1 unit PackageLinkIntf;
2
3 {$mode objfpc}{$H+}
4
5 interface
6
7 uses
8 SysUtils, Classes,
9 // LCL
10 Forms,
11 // LazUtils
12 LazFileUtils,
13 // IdeIntf
14 PackageDependencyIntf, PackageIntf;
15
16 type
17
18 { TPackageLink
19 There are several types of package links.
20
21 Global: These are collected from the lazarus source directory.
22 EnvironmentOptions.LazarusDirectory+'packager/globallinks/*.lpl'
23 This way packages can install/uninstall themselves to one lazarus
24 source directory, and this lazarus directory can then be shared
25 by several users/configs.
26
27 Online: Got through Online Package Manager
28
29 User: These are collected from the user config directory, from the file
30 packagelinks.xml.
31 These links are maintained by the IDE. Everytime the user opens a
32 package a user link is created, so that the next time the package
33 can be automatically opened. The list is checked by the IDE from
34 time to time and missing packages are first marked and after several
35 months deleted from the list.
36 Relative files are expanded with the Lazarus directory.
37 }
38
39 TPkgLinkOrigin = (
40 ploGlobal,
41 ploOnline,
42 ploUser
43 );
44 TPkgLinkOrigins = set of TPkgLinkOrigin;
45
46 const
47 AllPkgLinkOrigins = [low(TPkgLinkOrigin)..high(TPkgLinkOrigin)];
48
49 type
50
51 { TPackageLink }
52
53 TPackageLink = class(TLazPackageID)
54 private
55 procedure SetFilename(const AValue: string);
56 protected
57 FFileDate: TDateTime;
58 FFileDateValid: boolean;
59 FFilename: string;
60 FURL: String;
61 FLPLFileDate: TDateTime;
62 FLPLFilename: string;
63 FPackageType: TLazPackageType;
64 FOrigin: TPkgLinkOrigin;
65 FLastUsed: TDateTime;
66 FOPMFileName: string;
67 FOPMFileDate: TDateTime;
68 FAuthor: string;
69 FDescription: string;
70 FLicense: string;
71 public
72 constructor Create; override;
73 destructor Destroy; override;
IsMakingSensenull74 function IsMakingSense: boolean;
GetEffectiveFilenamenull75 function GetEffectiveFilename: string; virtual; abstract;
76 procedure Reference; virtual; abstract;
77 procedure Release; virtual; abstract;
78 public
79 property LPKFileDateValid: boolean read FFileDateValid write FFileDateValid;
80 property LPKFileDate: TDateTime read FFileDate write FFileDate;
81 // if relative it is relative to the LazarusDir
82 property LPKFilename: string read FFilename write SetFilename;
83 property LPKUrl: string read FURL write FURL;
84 property LPLFilename: string read FLPLFilename write FLPLFilename;
85 property LPLFileDate: TDateTime read FLPLFileDate write FLPLFileDate;
86 property PackageType: TLazPackageType read FPackageType write FPackageType;
87 property Origin: TPkgLinkOrigin read FOrigin write FOrigin;
88 property LastUsed: TDateTime read FLastUsed write FLastUsed;
89 property OPMFileName: string read FOPMFileName write FOPMFileName;
90 property OPMFileDate: TDateTime read FOPMFileDate write FOPMFileDate;
91 property Author: string read FAuthor write FAuthor;
92 property Description: string read FDescription write FDescription;
93 property License: string read FLicense write FLicense;
94 end;
95
96 { TPackageLinks }
97
98 TPackageLinks = class
99 private
100 public
FindLinkWithPkgNamenull101 function FindLinkWithPkgName(const PkgName: string): TPackageLink; virtual; abstract;
FindLinkWithDependencynull102 function FindLinkWithDependency(Dependency: TPkgDependencyID): TPackageLink; virtual; abstract;
FindLinkWithPackageIDnull103 function FindLinkWithPackageID(APackageID: TLazPackageID): TPackageLink; virtual; abstract;
FindLinkWithFilenamenull104 function FindLinkWithFilename(const PkgName, LPKFilename: string): TPackageLink; virtual; abstract;
105 procedure IteratePackages(MustExist: boolean; Event: TIteratePackagesEvent;
106 Origins: TPkgLinkOrigins = AllPkgLinkOrigins); virtual; abstract;
AddOnlineLinknull107 function AddOnlineLink(const PkgFilename, PkgName, PkgURL: string): TPackageLink; virtual; abstract;
AddUserLinknull108 function AddUserLink(APackage: TIDEPackage): TPackageLink; virtual; abstract;
109 // do not use this if package is open in IDE
AddUserLinknull110 function AddUserLink(const PkgFilename, PkgName: string): TPackageLink; virtual; abstract;
111 procedure RemoveUserLink(Link: TPackageLink); virtual; abstract;
112 procedure RemoveUserLinks(APackageID: TLazPackageID); virtual; abstract;
113 procedure ClearOnlineLinks; virtual; abstract;
114 procedure SaveUserLinks(Immediately: boolean = false); virtual; abstract;
115 end;
116
117 { TOPMInterface }
118
119 TOPMInterface = class
120 private
121 FPackageListAvailable: TNotifyEvent;
122 public
123 {confirmation/install/extract/download dialogs will be displayed in the center of WorkArea}
DownloadPackagesnull124 function DownloadPackages(APkgLinks: TList): TModalResult; virtual; abstract;
InstallPackagesnull125 function InstallPackages(APkgLinks: TList; var ANeedToRebuild: Boolean): TModalResult; virtual; abstract;
IsPackageAvailablenull126 function IsPackageAvailable(APkgLink: TPackageLink; AType: Integer): Boolean; virtual; abstract;
FindOnlineLinknull127 function FindOnlineLink(const AName: String): TPackageLink; virtual; abstract;
128 property OnPackageListAvailable: TNotifyEvent read FPackageListAvailable write FPackageListAvailable;
129 end;
130
131 var
132 PkgLinks: TPackageLinks;
133 OPMInterface: TOPMInterface;
134
135 implementation
136
137 { TPackageLink }
138
139 constructor TPackageLink.Create;
140 begin
141 inherited Create;
142 end;
143
144 destructor TPackageLink.Destroy;
145 begin
146 inherited Destroy;
147 end;
148
149 procedure TPackageLink.SetFilename(const AValue: string);
150 begin
151 if FFilename=AValue then exit;
152 FFilename:=TrimFilename(AValue);
153 end;
154
TPackageLink.IsMakingSensenull155 function TPackageLink.IsMakingSense: boolean;
156 begin
157 Result:=IsValidPkgName(Name)
158 and PackageFileNameIsValid(LPKFilename)
159 and (CompareText(Name,ExtractFileNameOnly(LPKFilename))=0);
160 end;
161
162 end.
163
164