Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-04

OpenDocument and Linux Mint

19 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello,

I'm trying to open a TXT file in my app, but it does not works.

The test is very simple:

uses
  LCLIntf;
procedure TForm1.Button1Click(Sender: TObject);
begin
  OpenDocument('test.txt');
end;

My environment is:

Lazarus 1.0.14 rUnknown FPC 2.6.2 x86_64-linux-gtk 2

(Linux Mint Mate 16 - 64 bit)

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140416/aaeccc6c/attachment.html>

Reply by email

Junior
to silvioprog
OpenDocument('./test.txt');
silvioprog wrote 30 lines
Hello, I'm trying to open a TXT file in my app, but it does not works. The test is very simple: uses LCLIntf; procedure TForm1.Button1Click(Sender: TObject); begin OpenDocument('test.txt'); end; My environment is: Lazarus 1.0.14 rUnknown FPC 2.6.2 x86_64-linux-gtk 2 (Linux Mint Mate 16 - 64 bit) -- Silvio Cl?cio My public projects - github.com/silvioprog <http://github.com/silvioprog> -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140416/7ecd19bb/attachment.html>

Reply by email

Junior
to silvioprog

What is the error?

silvioprog wrote 17 lines
2014-04-16 15:30 GMT-03:00 Junior < <mailto:>>: OpenDocument('./test.txt'); Same error. -- Silvio Cl?cio My public projects - github.com/silvioprog <http://github.com/silvioprog> -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140416/e152552d/attachment-0001.html>

Reply by email

waldo kitty
to silvioprog: 2014-04-16 16:34 GMT-03:00 waldo kitty : [...] Oops, sorry! XD The file doesn't open. I…
silvioprog wrote 10 lines
2014-04-16 16:34 GMT-03:00 waldo kitty < <mailto:>>: [...] what is the error? you haven't told us that piece of important information ;) Oops, sorry! XD The file doesn't open. I click the button and nothing happens.

and you don't get any kind of exception or other error results??

NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted.

Reply by email

Lazarus Linux
to waldo kitty

Here the example indicated works perfect.

Ubuntu 14.04 - Lazarus 1.3 trunk - fpc 2.6.2

2014-04-17 1:07 GMT+00:00 waldo kitty :

Show quoted text 28 lines
On 4/16/2014 3:39 PM, silvioprog wrote: > 2014-04-16 16:34 GMT-03:00 waldo kitty < > <mailto:>>: > [...] > > what is the error? you haven't told us that piece of important > information ;) > > > Oops, sorry! XD > > The file doesn't open. I click the button and nothing happens. > and you don't get any kind of exception or other error results?? -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
*Livro T?cnicas Avan?adas no Lazarus* -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140417/36d71f96/attachment.html>

Reply by email

Lukasz Sokol
to Lazarus Linux

Hi,

unless you really have a good reason, can you avoid replying on top of previous replies ? It's not a corporate environment here, you know.

Lazarus Linux wrote 5 lines
Here the example indicated works perfect. Ubuntu 14.04 - Lazarus 1.3 trunk - fpc 2.6.2

May it be that there is no 'default text editor' set in your Mint OS? (I don't have one, just guessing).

What happens if you just 'dobule-click' the text file out of the file manager window ?

Kind Regards,
-L.

Show quoted text 25 lines
2014-04-17 1:07 GMT+00:00 waldo kitty < <mailto:>>: On 4/16/2014 3:39 PM, silvioprog wrote: 2014-04-16 16:34 GMT-03:00 waldo kitty < <mailto:> <mailto: <mailto:>>>: [...] what is the error? you haven't told us that piece of important information ;) Oops, sorry! XD The file doesn't open. I click the button and nothing happens. and you don't get any kind of exception or other error results?? -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. --

Reply by email

silvioprog
to waldo kitty: and you don't get any kind of exception or other error results?? NOTE: No off-list…

2014-04-16 22:07 GMT-03:00 waldo kitty :
[...]

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 ...

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140417/5d2a17b3/attachment.html>

Reply by email

silvioprog
to Lukasz Sokol: unless you really have a good reason, can you avoid replying on top of previous replies ?…

2014-04-17 5:33 GMT-03:00 Lukasz Sokol :
[...]

May it be that there is no 'default text editor' set in your Mint OS? (I don't have one, just guessing).

I'm using Mint with MATE, so Pluma is the default text editor. ( http://en.wikipedia.org/wiki/MATE_(software))

What happens if you just 'dobule-click' the text file out of the file manager window ?

The file opens in Pluma editor.

Soon I'll try to debug LCL to discover this problem ...

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140417/4e4ce141/attachment.html>

Reply by email

Mattias Gaertner
to silvioprog: 2014-04-16 22:07 GMT-03:00 waldo kitty : [...] No error occurs, and it doesn't opens…
Show quoted text 9 lines
2014-04-16 22:07 GMT-03:00 waldo kitty : [...] > 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 ExitCode0.

Mattias

Reply by email

silvioprog
to Mattias Gaertner

2014-04-17 14:50 GMT-03:00 Mattias Gaertner :

Show quoted text 19 lines
On Thu, 17 Apr 2014 14:35:07 -0300 silvioprog wrote: > 2014-04-16 22:07 GMT-03:00 waldo kitty : > [...] > > > 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 ExitCode0.

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

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140425/28afc570/attachment-0001.html>

Reply by email

zeljko
to silvioprog
silvioprog wrote 105 lines
2014-04-17 14:50 GMT-03:00 Mattias Gaertner < <mailto:>>: On Thu, 17 Apr 2014 14:35:07 -0300 silvioprog < <mailto:>> wrote: > 2014-04-16 22:07 GMT-03:00 waldo kitty < <mailto:>>: > [...] > > > 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 ExitCode0. 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

Reply by email

silvioprog
to zeljko

2014-04-25 3:23 GMT-03:00 zeljko :

Show quoted text 118 lines
On 04/25/2014 07:21 AM, silvioprog wrote: > 2014-04-17 14:50 GMT-03:00 Mattias Gaertner < > <mailto:>>: > > > On Thu, 17 Apr 2014 14:35:07 -0300 > silvioprog < <mailto:>> > wrote: > > > 2014-04-16 22:07 GMT-03:00 waldo kitty < > <mailto:>>: > > > [...] > > > > > 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 ExitCode0. > > > 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.freepascal.org/pipermail/lazarus/attachments/20140425/76107b10/attachment.html>

Reply by email

Lukasz Sokol
to silvioprog
silvioprog wrote
2014-04-25 3:23 GMT-03:00 zeljko < <mailto:>>:

[...]

Show quoted text 15 lines
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 <http://github.com/silvioprog>

what if the function checked some result code from the external program, and tried another possibility [maybe from a configurable list?] if not getting what it expects?

-L.

Reply by email

Mattias Gaertner
to Lukasz Sokol
[...] what if the function checked some result code from the external program, and tried another possibility [maybe from a configurable list?] if not getting what it expects?

How do you want to test if a program starts a gui program instead of a console program?

Probably xdg-open just needs some environment variables.

Mattias

Reply by email

Mark Morgan Lloyd
to zeljko: But not so good. Maybe you have kde and gnome and you are currently using gnome desktop.…
zeljko wrote
My proposal for fallback will be check for current desktop env and then call appropriate application (only if xdg-open fails).

Since most desktop environments at least pay lipservice to the xdg interface utilities, I'm not sure whether having an automatic fallback is advisable or valid.

If xdg-open fails, then I think I'd argue that a bug-report dialogue should be presented, and only after the user has responded to that should "heuristics" be applied.

The next obvious question is whether there's a component to raise a bug with the current desktop's developers.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email