Hi,
I'm actually trying to convert a Delphi component to Lazarus. The work is
running Ok but I have some difficulties finding multiplatform equivalents
working
with FPC/Lazarus. This must be complicated as those functions are about shell
integration and each shell have it's own approach.
Here is the typical code giving me headackes :
{$ifndef FPC}
//this windows specific function should be hard to convert
//we should need here something using mime types, anyway many more code
//should be required
procedure GetFileExtensionShellDescription(Ext: string;
var FileTypeName: string; var ShellImageIndex: Integer);
var
A, B: Integer;
T: string;
L: TImageList;
sFI: TSHFileInfo; //this is windows specific but an other type could be
equivalent
I: TIcon;
Q: PChar;
P: PFileDescriptionRecord;
begin
FileTypeName := '';
A := RegisteredExtensions.IndexOf(Ext); //this is a TStringList defined as
global before
if A = -1 then
begin
New(P);
P^.FileType := '';
I := TIcon.Create;
for B := 0 to 1 do
begin
if B = 0 then
L := ShellSmallImageList
else L := ShellLargeImageList; //both are TImageList
GetMem(Q, MAX_PATH);
GetTempPath(MAX_PATH, Q); //those lines could be replaced by GetTempDir
in FileUtil
T := Q + 'TEMP' + Ext;
FreeMem(Q);
TFileStream.Create(T, fmCreate or fmOpenWrite).Destroy;
//the following is the biggest problem... Impossible to find any
//equivalent with Lazarus. Any ideas ? Mime types and Freedesktop
//should provide this...
if SHGetFileInfo(PChar(T), 0, sFI, SizeOf(sFI),
SHGFI_TYPENAME or SHGFI_ICON or
(SHGFI_SMALLICON * (1 - B) + B * SHGFI_LARGEICON)) <> 0 then
begin
I.ReleaseHandle;
I.Handle := sFI.hIcon;
P^.FileType := sFI.szTypeName;
end;
P^.OpenImageIndex := L.AddIcon(I);
P^.CloseImageIndex := P^.OpenImageIndex;
if B = 1 then
A := RegisteredExtensions.AddObject(Ext, TObject(P));
end;
I.Destroy;
end;
with PFileDescriptionRecord(RegisteredExtensions.Objects[A])^ do
begin
ShellImageIndex := CloseImageIndex;
FileTypeName := FileType;
end;
end;
{$endif}
The problem seems simple, we just need to get system icons from each each file
extension but nothing is currently available in lazarus to to that. I know
FreeDesktop is providing a common interface to be able to do that, as many
software that don't have the same API can do that (eg. Gnome app under KDE use
KDE theme). Is there a way to project a such implementation wich is the base
for desktop integration. This should be a very good added value to Lazarus !
Thanks.
--
Geoffray "fatalerrors" Levasseur
http://jeff.levasseur.tuxfamily.org/
Sic luceat lux et pax
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus