misc.cpp
changeset 158 a33a2bdd8299
parent 139 087e60400acc
child 163 30b22f7bd009
     1.1 --- a/misc.cpp	Fri Aug 19 07:42:32 2005 +0000
     1.2 +++ b/misc.cpp	Tue Aug 30 14:09:19 2005 +0000
     1.3 @@ -81,35 +81,45 @@
     1.4  	QString s=src;
     1.5  	QString d=dst;
     1.6  	int i;
     1.7 -	// Find relative path from src to dst
     1.8  
     1.9 -	// Remove the first "/"
    1.10 -	if (s.section ("/",0,0).isEmpty()) 
    1.11 +	if (s==d) 
    1.12  	{
    1.13 -		s=s.right (s.length()-1);
    1.14 -		d=d.right (d.length()-1);
    1.15 -	}
    1.16 -	
    1.17 -	// remove identical left parts
    1.18 -	while (s.section("/",0,0) == d.section("/",0,0) ) 
    1.19 +		// Special case, we just need the name of the file,
    1.20 +		// not the complete path
    1.21 +		i=d.findRev ("/");
    1.22 +		d=d.right (d.length()-i-1);
    1.23 +	} else
    1.24  	{
    1.25 -		i=s.find ("/");
    1.26 -		s=s.right (s.length()-i-1);
    1.27 -		d=d.right (d.length()-i-1);
    1.28 -	}
    1.29 +		// Find relative path from src to dst
    1.30  
    1.31 -	int srcsep=s.contains("/");
    1.32 -	int dstsep=d.contains("/");
    1.33 -	if (srcsep >=  dstsep )
    1.34 -	{
    1.35 -		// find path to go up first and then back to dst
    1.36 -		i=1;
    1.37 -		while (i<=srcsep) 
    1.38 +		// Remove the first "/"
    1.39 +		if (s.section ("/",0,0).isEmpty()) 
    1.40  		{
    1.41 -			d="../"+d;
    1.42 -			i++;
    1.43 -		}	
    1.44 -	}
    1.45 +			s=s.right (s.length()-1);
    1.46 +			d=d.right (d.length()-1);
    1.47 +		}
    1.48 +		
    1.49 +		// remove identical left parts
    1.50 +		while (s.section("/",0,0) == d.section("/",0,0) ) 
    1.51 +		{
    1.52 +			i=s.find ("/");
    1.53 +			s=s.right (s.length()-i-1);
    1.54 +			d=d.right (d.length()-i-1);
    1.55 +		}
    1.56 +
    1.57 +		int srcsep=s.contains("/");
    1.58 +		int dstsep=d.contains("/");
    1.59 +		if (srcsep >=  dstsep )
    1.60 +		{
    1.61 +			// find path to go up first and then back to dst
    1.62 +			i=1;
    1.63 +			while (i<=srcsep) 
    1.64 +			{
    1.65 +				d="../"+d;
    1.66 +				i++;
    1.67 +			}	
    1.68 +		}
    1.69 +	}	
    1.70  	return d;
    1.71  }
    1.72