[Lazarus] OpenDocument and Linux Mint

silvioprog silvioprog at gmail.com
Fri Apr 25 17:08:31 CEST 2014


2014-04-25 3:23 GMT-03:00 zeljko <zeljko at holobit.net>:

> On 04/25/2014 07:21 AM, silvioprog wrote:
>
>> 2014-04-17 14:50 GMT-03:00 Mattias Gaertner <nc-gaertnma at netcologne.de
>> <mailto:nc-gaertnma at netcologne.de>>:
>>
>>
>>     On Thu, 17 Apr 2014 14:35:07 -0300
>>     silvioprog <silvioprog at gmail.com <mailto:silvioprog at gmail.com>>
>> wrote:
>>
>>      > 2014-04-16 22:07 GMT-03:00 waldo kitty <wkitty42 at windstream.net
>>     <mailto:wkitty42 at windstream.net>>:
>>
>>      > [...]
>>      >
>>      > > and you don't get any kind of exception or other error results??
>>      > >
>>      >
>>      > No error occurs, and it doesn't opens file. :/
>>      >
>>      > I'm trying to debug LCL in trying to figure out the problem ...
>>
>>     The OpenDocument function does not raise exceptions under Linux. It
>>     returns false if no application was found.
>>
>>     It should be improved to raise an exception for the errors it can
>> spot.
>>     Like not finding the application or if the program returns bytes on
>>     Stderr or if the ExitCode<>0.
>>
>>
>> I found the error. In a terminal, when I call:
>>
>> $ xdg-open test.txt
>>
>> The "test.txt" file is opened into terminal. But when I call:
>>
>> $ gnome-open test.txt
>>
>> The "test.txt" file is opened into Pluma Editor (native text editor on
>> Linux Mint, like GEdit in Ubuntu).
>>
>> Then seems a problem in Linux Mint (Mate).
>>
>> To solve my problem, I changed the function from:
>>
>> [code]
>> function OpenDocument(APath: String): Boolean;
>> var
>>    lApp: string;
>> begin
>>    // Android uses this
>>    if Assigned(OpenDocumentWidgetsetImplementation) then
>>    begin
>>      Result := OpenDocumentWidgetsetImplementation(APath);
>>      Exit;
>>    end;
>>
>>    Result := True;
>>    if not FileExistsUTF8(APath) then exit(false);
>>
>>    lApp:=FindFilenameOfCmd('xdg-open'); // Portland OSDL/FreeDesktop
>> standard on Linux
>>    if lApp='' then
>>      lApp:=FindFilenameOfCmd('kfmclient'); // KDE command
>>    if lApp='' then
>>      lApp:=FindFilenameOfCmd('gnome-open'); // GNOME command
>>    if lApp='' then
>>      Exit(False);
>>
>>    if (APath<>'') and (APath[1]<>'"') then
>>      APath:=QuotedStr(APath);
>>    RunCmdFromPath(lApp,APath);
>> end;
>> [/code]
>>
>> To:
>>
>> [code]
>> function OpenDocument(const APath: String): Boolean;
>> var
>>    lApp: string;
>> begin
>>    // Android uses this
>>    if Assigned(OpenDocumentWidgetsetImplementation) then
>>    begin
>>      Result := OpenDocumentWidgetsetImplementation(APath);
>>      Exit;
>>    end;
>>
>>    Result := True;
>>    if not FileExistsUTF8(APath) then exit(false);
>>
>>    lApp:=FindFilenameOfCmd('gnome-open'); // GNOME command
>>    if lApp='' then
>>      lApp:=FindFilenameOfCmd('kfmclient') // KDE command
>>    else
>>    if lApp='' then
>>      lApp:=FindFilenameOfCmd('xdg-open') // Portland OSDL/FreeDesktop
>> standard on Linux
>>    else
>>    if lApp='' then
>>      Exit(False);
>>
>>    if (APath<>'') and (APath[1]<>'"') then
>>      APath:=QuotedStr(APath);
>>    RunCmdFromPath(lApp,APath);
>> end;
>> [/code]
>>
>> Quick fix! :p
>>
>
> But not so good. Maybe you have kde and gnome and you are currently using
> gnome desktop. Calling kfclient can be pita in this case since kde isn't
> loaded so kfmclient will load bulk of libs and it can be slow.
> My proposal for fallback will be check for current desktop env and then
> call appropriate application (only if xdg-open fails).


Yes, and I implemented a 'quick fix' local in my program, to call the
"gnome-open" directly, solving my problem, until a better solution comes
along.

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140425/76107b10/attachment-0003.html>


More information about the Lazarus mailing list