00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include <qstringlist.h>
00013
#include <qfile.h>
00014
#include <qdir.h>
00015
#include "pathutil.h"
00016
00017
00018 QString getRelativePath(
const QString& basepath,
const QString& destpath)
00019 {
00020
QString relpath =
".";
00021
if (!QFile::exists(basepath) ||
00022 !QFile::exists(destpath))
00023
return "";
00024
QStringList basedirs = QStringList::split(
'/',basepath);
00025
QStringList destdirs = QStringList::split(
'/',destpath);
00026
00027
int maxCompare=0;
00028
if (basedirs.count()>=destdirs.count())
00029 maxCompare=destdirs.count();
00030
else
00031 maxCompare=basedirs.count();
00032
int lastCommonDir=-1;
00033
for (
int i=0; i<maxCompare; i++)
00034 {
00035
if (basedirs[i] != destdirs[i])
00036
break;
00037 lastCommonDir=i;
00038 }
00039
for (uint i=0;i<basedirs.count()-(lastCommonDir+1); i++)
00040 relpath +=
"/..";
00041
for (
int i=0; i<lastCommonDir+1; i++)
00042 destdirs.pop_front();
00043
if (destdirs.count())
00044 relpath +=
"/"+destdirs.join(
"/");
00045
return QDir::cleanDirPath(relpath);
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069