On 04/25/2014 07:21 AM, silvioprog wrote:
2014-04-17 14:50 GMT-03:00 Mattias Gaertner <[email protected]
<mailto:[email protected]>>:

    On Thu, 17 Apr 2014 14:35:07 -0300
    silvioprog <[email protected] <mailto:[email protected]>> wrote:

     > 2014-04-16 22:07 GMT-03:00 waldo kitty <[email protected]
    <mailto:[email protected]>>:
     > [...]
     >
     > > 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).

zeljko




--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to