Bug 221689 - Relative and absolute data file paths in kst
Summary: Relative and absolute data file paths in kst
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 2.0.0
Platform: unspecified Microsoft Windows
: NOR wishlist
Target Milestone: 2.0.0
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-07 18:12 UTC by Nicolas Brisset
Modified: 2010-11-12 10:42 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Change kst's CWD when loading a .kst file (365 bytes, patch)
2010-01-07 18:29 UTC, Nicolas Brisset
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Brisset 2010-01-07 18:12:59 UTC
Version:           2.0.0_devel (using unspecified)
Compiler:          mingw delivered with QtCreator 1.1.0
OS:                Windows 32-Bit

There was the beginning of a discussion some time ago on the list regarding absolute vs relative file paths in kst 2.0 for data files. Since then time has passed, and we've been bitten as well. I think this is an important issue to be solved, preferably even before 2.0.0 final as it may have impact on file compatibility. So here we go...

Back then, Don suggested something, which I'm going to import as comment:
Comment 1 Nicolas Brisset 2010-01-07 18:14:52 UTC
(copy/pasted from Don's email on the list http://mail.kde.org/pipermail/kst/2009-September/016558.html)

I'd like to see a kst with a flexible, adaptable approach to paths.
Specifically:

1) kst should honour the method by which users specify paths.  An
absolute path specified should be saved as absolute:

  $ kst -y 1 /tmp/datafile

as should a relative one:

  $ kst -y 1 ./datafile

(Presumably the user has a better understanding of whether absolute or
relative is more appropriate.)

2) Store paths to files selected with the file selection widget relative
to some known base; store the base path, too.  Store kst's cwd in the
file, too, while your at it.

Then, when the .kst file is loaded later, attempt to find a data source
specified by relative path by trying different bases (in some specified
order, though not necessarily this one):

* the base path to the relative file stored in the .kst file (this is
  effectively and absolute path)
* the current working directory (kst 2.x style)
* the cwd stored in the .kst file (another form of "absolute path")
* the directory containing the .kst file (Josh style)

3) If this is done, there needs to be a facility in kst to allow users
to rewrite data source paths, so that they can change absolute paths to
relative ones, &c.

Bottom line: there are cases were absolute paths work best, and cases
where relative paths work best.  Restricting yourself to one or the
other will always create problems.  Be flexible.
Comment 2 Nicolas Brisset 2010-01-07 18:26:18 UTC
Now, my comments to that:

1) I agree: whether the data file is passed from the command line or from the wizard, it should be kept relative if relative and absolute if absolute (which is as far as I know what happens right now, at least for the wizard)

2) sounds a bit too complex to me. Based on experience, I'd suggest something a bit more simple: when loading data, if the file is relative then look for it from the current path (which implies changing kst's cwd to that of the just opened file before processing the contents, anything else would be plain crazy) and if it is absolute then load it as absolute. In fact, I have a one-line patch locally that does just that and it works very well. 

3) as a complement to 2), you indeed need to be able to "rewrite" paths. Firing up an editor is of course always possible, but I don't think we want to force that on the average user. I'd rather suggest a "Use relative paths to data files" checkbox in the save dialog, which would save the paths relative to the directory where the .kst is being saved in. Default would probably be relative paths, but that has to be discussed. And of course, there is an underlying assumption which is that an average user will never need to mix absolute and relative paths (!), which I think we can live with.

If we go for that, I think my use cases would be catered for. And the implementation would be pretty trivial: the one-line patch I'm going to attach and a custom save dialog, and checking that relative/absolute paths are handled correctly, which I believe is the case right now already.

What do you think?
Comment 3 Nicolas Brisset 2010-01-07 18:29:18 UTC
Created attachment 39656 [details]
Change kst's CWD when loading a .kst file
Comment 4 Nicolas Brisset 2010-02-02 16:27:01 UTC
Could we apply the proposed patch, as it allows working with relative file paths conveniently? It wouldn't close the bug as a user-friendly way of choosing between relative and absolute paths is still needed, but it is still definitely an improvement (I even think trying to load a .kst with relative file paths from the wrong dir crashes kst without that patch).
Comment 5 Nicolas Brisset 2010-04-21 08:20:38 UTC
SVN commit 1117077 by brisset:

Simple one-liner to allow working with relative paths to datasources. I'm tired of keeping it around locally, and it seems to work well enough to commit.
This path allows loading files with absolute file paths. For complete functionality, we should also be able to save them :-) I think it would be nice to provide an option for that in the file save dialog. Note that it is already possible to have relative paths in 2 ways:
- hand-edit the .kst, after all xml is ASCII and easy to edit!
- use in the data wizard only relative paths, they are then stored as such.
But I still think an option when saving the .kst could/should be added.

CCBUG: 221689

 M  +1 -1      mainwindow.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1117077
Comment 6 Peter Kümmel 2010-08-12 16:29:40 UTC
SVN commit 1162736 by kuemmel:

better data source path handling:
    - save absolute and relative path if possible
    - when loading try relative path for data sources first
    - fall back to absolute path if relative path does not exists

CCBUG: 221689




 M  +16 -2     libkst/dataprimitive.cpp  
 M  +3 -1      libkstapp/mainwindow.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1162736
Comment 7 Peter Kümmel 2010-08-14 12:14:39 UTC
Change version from 2.0.0_devel to 2.0.0 to simplify version numbering.
Comment 8 Peter Kümmel 2010-08-30 14:55:24 UTC
See commit 1162736.
Comment 9 Peter Kümmel 2010-11-12 10:42:23 UTC
These bugs are solved with 2.0.0