View Issue Details

IDProjectCategoryView StatusLast Update
0006518ScribusGeneralpublic2024-01-02 19:22
ReporteraliB Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
Status acknowledgedResolutionopen 
PlatformDell Inspiron 9400OSSuSEOS Version10.2
Summary0006518: [patch] Better control for your paths
Description1. If you load an image there should be an option how the path of this image is stored.
a) relative to the working directory
b) relative to the document with your sla
c) absolute

Further there could be a function to change all pathes in the document to one of this 3 possibilities.
TagsNo tags attached.
PatchYes

Relationships

related to 0009056 acknowledged allow relative paths for images (and fonts) 
related to 0009177 new Feature Request -- full path for Image in the Properties Dialog and/or Context Menu>Information 
related to 0016661 new Path for copy'n'pasted inline images 
has duplicate 0013505 closedjghali Enhancement: PFILE Attribute for PAGEOBJECT be Configurable to Relative or Abosolute Path 
has duplicate 0016253 closedjghali Image path relative 

Activities

jghali

2007-11-30 09:54

administrator   ~0018058

In fact i plan to have both relative and absolute path stored in document at a point. That would provide a fallback path if document is moved.

jlpoole

2015-11-07 00:34

reporter   ~0037294

This ought to be easily scripted, assuming Python has Perl-like libraries that easily provide absolute paths for a given file. I have a need for this and have to refamiliarize myself with the Python scripting (it's been months since I worked on a Python script for Scribus) paradigm. I'll keep in mind the 3 states desired above.

jlpoole

2015-11-07 13:04

reporter   ~0037297

Last edited: 2015-11-07 13:11

Lo, it is not easily scripted as the PFILE value may be in relative form, but the Python accessor .getImageFile() returns an absolute path. As far as I know at this time, the underlying XML is not accessible through the Python interface, so this will require going deeper.

The heart of the matters is at line 2597 (rev. 20539 )in scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp:

   docu.writeAttribute("PFILE",Path2Relative(item->Pfile, baseDir));

where Path2Relative converts the value to relative.

jlpoole

2015-11-07 14:48

reporter   ~0037302

jghali: so if the relative (to what, document?) and absolute paths were to be stored in the XML, that would be acceptable?

I could try to accomplish that, perhaps using a new attribute PFILEABS ("PFILE Absolute") as the absolute path variant in the XML. That would be the easiest approach rather than having a configuration option and maintaining the stated choices.

I'm concerned that if I built that feature in, then the people who make decisions on the design of Scribus would not adopt it. I'd like to know what I'd be pursuing has tentative approval.

jlpoole

2015-11-08 16:25

reporter  

abs_file_fix.diff (2,975 bytes)   
Index: Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
===================================================================
--- Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(revision 20542)
+++ Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(working copy)
@@ -4751,7 +4751,21 @@
 				}
 			}
 			else
-				currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE"), baseDir);
+			  {
+			    if (!FileExists(Relative2Path(attrs.valueAsString("PFILE"), baseDir)))
+			      {
+				// try the PFILEABS, if that is empty, revert to PFILE since legacy
+				// xml may not have PFILEABS
+				if (attrs.hasAttribute("PFILEABS")
+				    && !attrs.valueAsString("PFILEABS").isEmpty()
+				    && FileExists(attrs.valueAsString("PFILEABS")))
+				  currItem->Pfile = attrs.valueAsString("PFILEABS");
+				else
+				  currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE"), baseDir);
+			      }
+			    else
+			      currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE"), baseDir);
+			  }
 #ifdef HAVE_OSG
 			if (currItem->asOSGFrame())
 			{
Index: Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
===================================================================
--- Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp	(revision 20542)
+++ Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp	(working copy)
@@ -2594,7 +2594,10 @@
 			}
 		}
 		else
+		  {
 			docu.writeAttribute("PFILE",Path2Relative(item->Pfile, baseDir));
+			docu.writeAttribute("PFILEABS",Relative2Path(item->Pfile, baseDir));
+		  }
 	}
 #ifdef HAVE_OSG
 	else if (item->asOSGFrame())
Index: Scribus/scribus/util.cpp
===================================================================
--- Scribus/scribus/util.cpp	(revision 20539)
+++ Scribus/scribus/util.cpp	(working copy)
@@ -309,6 +309,13 @@
 	return out;
 }
 
+bool FileExists(QString Path)
+{
+  if (Path.isEmpty())
+    return false;
+  return QFileInfo::exists(Path);   
+}
+
 QString Path2Relative(QString Path, const QString& baseDir)
 {
 	QDir d(baseDir);
Index: Scribus/scribus/util.h
===================================================================
--- Scribus/scribus/util.h	(revision 20539)
+++ Scribus/scribus/util.h	(working copy)
@@ -51,6 +51,7 @@
 void SCRIBUS_API ReOrderText(ScribusDoc *currentDoc, ScribusView *view);
 void SCRIBUS_API WordAndPara(PageItem *currItem, int *w, int *p, int *c, int *wN, int *pN, int *cN);
 bool SCRIBUS_API overwrite(QWidget *parent, QString filename);
+bool SCRIBUS_API FileExists(QString Path);
 QString SCRIBUS_API Path2Relative(QString Path, const QString& baseDir = QDir::currentPath());
 QString SCRIBUS_API Relative2Path(QString File, const QString& baseDir = QDir::currentPath());
 char SCRIBUS_API *toAscii85( quint32 value, bool& allZero );
abs_file_fix.diff (2,975 bytes)   

jlpoole

2015-11-08 16:27

reporter   ~0037321

I went ahead and fixed it, at least I can move forward. I added the PFILEABS attribute which hold the absolute path of the file. Modified the read to try PFILEABS if PFILE does not exist and PFILEABS does and is populated.

Added function FileExists to util.cpp

Kunda

2015-11-09 10:54

updater   ~0037336

Thanks jlpoole! Updating status of this ticket to patch.

Kunda

2015-11-09 11:08

updater   ~0037339

Here's op's reasoning behind patch, copied from 0013505:0037291
------
Here's my strategy:

All images are stored on a Linux server ("image server"), they are exposed on the Windows machine through a mount to P:

So I have my Scribus file ("sla") import the images using absolute paths,
e.g. P:\music\brahms\sym1\2P4H\P1\EVE001.TIF. The sla file can be anywhere on my Windows system, e.g. D:\projects\brahms88.sla, or D:\Temp\brahms88.sla, and the images will always appear (provided Scribus does not convert absolute paths to relative paths).

Then I can have the same file, brahms88.sla, on a Linux box, say in /home/jlpoole/work/music/brahms/sym1/2P4H/brahms88.sla and I have in that same directory a soft link named "P:" which points to a mounted share /P which, in turn mounts to the image server. I can move my brahms88.sla around anywhere on the Linux tree, I just have to have in the directory where it exists a soft link "P:".

Under this scenario, my brahms88.sla file can be free to be placed anywhere on either operating system tree and my images will always resolve.

ale

2015-11-09 12:21

manager   ~0037344

i'm not sure that this is the best solution for the issue (and the issue is getting imo more and more urgent!)

afaict, it's only on windows that you sometimes need absolute paths...
since you cannot have a relative reference from C:\test.sla to D:\picture.png.

on unix it might or not be useful to have relative paths ony depending on the way you are working.
but in my case, since i put all my work on github i need to always have relative paths only!

since the choice depends on your way to layout the directories (eventually, with exceptions for a specific project) i think that it should be a document setting (and preferences)

if the setting is not in the document, the old behavior should apply.
i would prefer this test being done when the document gets opened and not when scribus reads the path during normal work.

in that case i guess that scribus shuold simply default as absolute paths (as it is doing now)

one open question is what happens, when you switch from the one to the other for the current document... but there should be rather simple way to go from the one to the other... and refuse to switch to relative paths if (on windows) this cannot be done for the current document.

if "relative paths" is activated, scribus should also refuse to add paths that cannot be expressed as relative ones.

Kunda

2015-11-09 12:31

updater   ~0037346

Last edited: 2015-11-09 12:32

Another thing comes to mind, sometimes Absolute paths divulges personal information.
Example: C:\Confidential\Personal_Finances\Investments\That_Busisneses_Im_A_Silent_Partner_In\


How do we give the user the option to wipe their absolute paths so that they aren't included if the SLA is shared ?

jlpoole

2015-11-09 12:33

reporter   ~0037347

The problem of relative paths manifests itself in Linux. Example:

test.sla is located in /home/jlpoole along with an image smile.jpg. test.sla has a PAGEOBJECT element with an attribute PFILE="../../home/jlpoole/smile.jpg".

If I move test.sla down to /home/jlpoole/work/ the link is broken.

In Linux, if you keep your sla file at the same level, then the link will work. Example moving to /home/sam/test.sla. However, once you move downwards, e.g. /home/sam/sam_scribus, the link breaks.

ale

2015-11-09 13:15

manager   ~0037348

Last edited: 2015-11-09 13:17

jlpoole: of course, if you move the sla you have the problem on linux, too!

i was talking about "normal" work :-)

but your use case is also worth to be considered.
in that case, if you're in relative mode, you just set the document settings to absolute, close the file, move the file in the file manager, reopen the file, set the settings back to relative (if you want to do so).

the main use case i'm trying to address is sharing a .sla file over a git/svn repository, which seems to be something more and more people are doing.
or using a shared directory in the windows world.

of course, when setting the relative paths, you still have to make sure that the linked file are always accessible (that is: all of them must be inside of the repository! if possible "below" the .sla file itself).

in my eyes having a setting / preference is the simplest and most effective way to solve this issue.

if you like to move around your sla after having created it, you will prefer absolute paths.
if you value being able to easily share it with other people relative paths are a must have!

if you can change your patch to do all that, i will for sure sponsor it!

jlpoole

2015-11-09 13:26

reporter   ~0037349

Last edited: 2015-11-09 13:34

Don't laugh: I did not know that there was a switch for relative vs. absolute path. I quickly looked in File->Preferences and then Document Setup and did not find anything. Searching within Scribus Help using the term "absolute" reveals nothing. Am I totally missing something??

== edit == Using Windows 1.5.0svn

ale

2015-11-09 13:52

manager   ~0037350

euh...

i'm proposing such a switch... instead of storing both the absolute and relative path in the file and getting the one that first matches...

there is not such a preference, yet.

but i would be very happy if there was one in the near future!
then i could put .sla files on github that can be edited by other people!

ale

2015-11-09 15:06

manager   ~0037351

p.s.: i'm really not sure that jean's idea of having a fallback is a good idea. somehow i fear the complexity that leads to errors in unexpected places...

i really prefer to be sure that my documents on github are correct, if i take care that all relative links are inside of the repository.
otherpeople will prefer to be sure that their assets are correctly linked, wherever they place their .SLAs

in the future i think that we could even add a third way: relative paths for images below the current directory and absolute paths for all other paths.

ale

2015-11-09 18:53

manager   ~0037353

btw, jean, i would be really interested in knowing if you think there are benefits in storing both paths (against having a switch in the settings) and which they are...

jghali

2015-11-09 22:34

administrator   ~0037361

Storing absolute image path allows user to move the .sla document locally wherever he wants without moving images. If user stores .sla in a directory and image in subdirectories and move the top directory, then absolute path is not sufficient anymore. That's when we need the relative path. That's why I think storing both paths is something we should do as that responds to different usage scenarios.

jlpoole

2015-11-09 22:42

reporter   ~0037362

jghali: I'm confused.

You wrote: "then absolute path is not sufficient anymore. That's when we need the relative path."

Did you mean "then relative path is not sufficient anymore. That's when we need the absolute path."

Absolute paths will work from anywhere on the system.

jghali

2015-11-09 22:59

administrator   ~0037364

I really meant "then absolute path is not sufficient anymore. That's when we need the relative path." because of what precede : "and move the top directory". Typically the case of a user who collects doc for output and move the resulting directory to another computer. Usually absolute path is of no help in this case.

Kunda

2015-11-14 13:19

updater   ~0037479

So for the scenario where Absoulute path is relevant, can we apply a patch for that ?

ale

2015-11-16 09:58

manager   ~0037510

jghali, i fully agree with you that having both choices is a good thing!
but i would implement it as a choice that the user has to make and avoid letting scribus to guess what it should do.

except if scribus can always guess correctly and there is no chance that an image is then shown as missing or the wrong image gets display.
and that the guess mechanism is simple and understandable.

if it only works in most cases but can fail, i'd prefer an setting/option that the user can switch and, then, always have the correct results in the limits of her choice.
with a way to to go from one choice to the other.

Kunda

2015-11-24 21:34

updater   ~0037655

I'm in agreement here with ale

Kunda

2015-11-26 13:18

updater   ~0037688

I also would propose 0007966 being related to this because we can actually ask the user a this point if they want to maintain relative or absolute paths. With the option to checkbox 'Do not ask me again for this project'.

Kunda

2015-12-01 21:31

updater   ~0037778

jlpoole, obviously this issue a little more complex. Nevertheless, thank you for the patch and the generated discussion.

alpinekid

2016-12-11 23:24

reporter   ~0042902

Just to chime in here. I'm new and not sure of protocol but, i'm using 1.5.3svn, downloaded from ppa this morning, and have issues with the path to images thing. When I look at the sla file I see an relative path, but it backs up all the way to root and then goes down again, effectively making it absolute. When I move the project, I have all files stored in dirs below where the .sla file is, it breaks.

When I edit the .sla file manually and make it a real relative path,./assets/something.png it stays set and everything seems to work fine.
Why wouldnt a simple check box when selecting the file work, "make relative(yes/no) work.

Issue History

Date Modified Username Field Change
2007-11-30 09:24 aliB New Issue
2007-11-30 09:54 jghali Note Added: 0018058
2007-11-30 21:19 jghali Summary Better control for your pathes => Better control for your paths
2008-02-05 19:51 christoph_s Status new => acknowledged
2015-11-07 00:17 Kunda Relationship added has duplicate 0013505
2015-11-07 00:19 Kunda Relationship added related to 0009056
2015-11-07 00:34 jlpoole Note Added: 0037294
2015-11-07 13:04 jlpoole Note Added: 0037297
2015-11-07 13:11 jlpoole Note Edited: 0037297
2015-11-07 14:48 jlpoole Note Added: 0037302
2015-11-08 16:25 jlpoole File Added: abs_file_fix.diff
2015-11-08 16:27 jlpoole Note Added: 0037321
2015-11-09 10:54 Kunda Patch => Yes
2015-11-09 10:54 Kunda Note Added: 0037336
2015-11-09 10:54 Kunda Summary Better control for your paths => [patch] Better control for your paths
2015-11-09 11:08 Kunda Note Added: 0037339
2015-11-09 12:21 ale Note Added: 0037344
2015-11-09 12:31 Kunda Note Added: 0037346
2015-11-09 12:32 Kunda Note Edited: 0037346
2015-11-09 12:33 jlpoole Note Added: 0037347
2015-11-09 13:15 ale Note Added: 0037348
2015-11-09 13:17 ale Note Edited: 0037348
2015-11-09 13:26 jlpoole Note Added: 0037349
2015-11-09 13:34 jlpoole Note Edited: 0037349
2015-11-09 13:52 ale Note Added: 0037350
2015-11-09 15:06 ale Note Added: 0037351
2015-11-09 18:53 ale Note Added: 0037353
2015-11-09 21:31 Kunda Sticky Issue No => Yes
2015-11-09 22:34 jghali Note Added: 0037361
2015-11-09 22:42 jlpoole Note Added: 0037362
2015-11-09 22:59 jghali Note Added: 0037364
2015-11-14 13:19 Kunda Note Added: 0037479
2015-11-16 09:58 ale Note Added: 0037510
2015-11-24 13:36 Kunda Relationship added related to 0009177
2015-11-24 21:34 Kunda Note Added: 0037655
2015-11-26 13:18 Kunda Note Added: 0037688
2015-12-01 21:31 Kunda Note Added: 0037778
2016-12-11 23:24 alpinekid Note Added: 0042902
2020-09-26 13:06 jghali Relationship added has duplicate 0016253
2021-11-17 17:13 JLuc Relationship added related to 0016661
2024-01-02 19:22 cbradney Sticky Issue Yes => No