Re: [Lazarus] Cross platform 'open file with default program'
Hello. Under Linux with distros supporting the freedesktop.org standards you can execute the 'xdg-open' command. This will use the mime-type and the each users preference on that system. This works for URL's too. Great! For Windows you can use a wrapper for ShellExecute function. I copied my code below. If OSX supports your 'xdg-open' then most environments are covered. This makes sense only with GUI. Command line progs can't use it. This should be included in FPC/Lazarus libraries, but which one? Regards, Juha Manninen - procedure OpenWithAssociatedProg(aFilePath, aFileName: string); overload; var Params: string; begin Params := ''; if (aFileName '') and FileExists(aFilePath + aFileName) then // Calls automatically the program associated with the file type. ShellExecute(Application.MainForm.Handle, 'open', PChar(aFileName), // FileName PChar(Params),// Parameters PChar(aFilePath), // Current Directory SW_SHOWNORMAL); // ShowCmd end; procedure OpenWithAssociatedProg(aFileNameFull: string); overload; var FilePath, FileName: string; begin FilePath := ExtractFilePath(aFileNameFull); FileName := ExtractFileName(aFileNameFull); OpenWithAssociatedProg(FilePath, FileName); end; -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Cross platform 'open file with default program'
On Sun, Jan 24, 2010 at 12:05 PM, Juha Manninen juha.manni...@phnet.fi wrote: If OSX supports your 'xdg-open' then most environments are covered. It doesn't, by default. There's an external tool 'open' available for such task. But, it's better to use launcher API (see OpenURL darwin code). thanks, dmitry -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Cross platform 'open file with default program'
2010/1/24 Juha Manninen juha.manni...@phnet.fi: If OSX supports your 'xdg-open' then most environments are covered. I doubt it will. As far as I know xdg tools are for Linux only (maybe other unix OSes too, but ain't sure). This makes sense only with GUI. Command line progs can't use it. There are other scripts for command line tools too, like opening URL's with lynx, or editing files with a console editor (vi, mcedit, joe,...) etc.. This should be included in FPC/Lazarus libraries, but which one? I know that Lazarus IDE already uses xdg-open under Linux for OpenURL - before trying other known web browsers. As for where in LCL such code should go, I have no idea. Where is OpenURL defined? -- Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Cross platform 'open file with default program'
Graeme Geldenhuys escreveu: 2010/1/24 Juha Manninen juha.manni...@phnet.fi: This should be included in FPC/Lazarus libraries, but which one? I know that Lazarus IDE already uses xdg-open under Linux for OpenURL - before trying other known web browsers. As for where in LCL such code should go, I have no idea. Where is OpenURL defined LCLIntf Luiz -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Cross platform 'open file with default program'
Amazing, OpenURL already implements what you are asking! I tested with a local '.patch' file and it opened nicely in Kompare (KDE prog for diffs). OpenURL uses ShellExecuteW for Windows, 'xdg-open' for *nix and some API functions for Darwin. There seems to be lots of quality code in FPC/Lazarus. Good! One thing is missing though. There is no portable way of getting application's icon like ExtractAssociatedIcon does in Windows? This is somewhat related to opening the file. I asked about it some time ago in FPC mailing list and didn't get answers, so I guess there is no such function. Does anyone have an idea about how to implement it (except for Windows)? Regards, Juha Manninen -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Cross platform 'open file with default program'
On Sun, Jan 24, 2010 at 2:08 PM, Juha Manninen juha.manni...@phnet.fi wrote: One thing is missing though. There is no portable way of getting application's icon like ExtractAssociatedIcon does in Windows? This is somewhat related to opening the file. It depends on what you exactly need. If you need just to get an icon associated with a file extension, you'll need to use ShellAPI functions in Windows, and different API in OSX. I guess there should some similar API in Gtk/Qt for Linux, too. If you just need to extract an Icon of the program's exectuable... well you can use Application.Icon. thanks, dmitry -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Cross platform 'open file with default program'
Does someone implemented a function to open the system default app associated of a given file type? Similar to OpenURL? Luiz -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Cross platform 'open file with default program'
2010/1/24 Luiz Americo Pereira Camara luiz...@oi.com.br: Does someone implemented a function to open the system default app associated of a given file type? Similar to OpenURL? Under Linux with distros supporting the freedesktop.org standards you can execute the 'xdg-open' command. This will use the mime-type and the each users preference on that system. This works for URL's too. If the distro doesn't support xdg, I recommend you email the maintainers of that distor. Also xdg tools are downloadable from freedesktop.org, is small and user installable (without root access). Anyway, in my projects I have abstracted various platforms into a single command, similar to OpenURL. Our projects only need to support Linux and Windows though, so I don't know the solutions for other platforms. -- Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus