21#include <tqstringlist.h>
24#include <tqfileinfo.h>
39 int slashPos = name.findRev(
"/");
40 return slashPos<0 ? name : name.mid(slashPos+1);
46 int slashPos = name.findRev(
"/");
47 return slashPos<0 ? TQString(
"") : name.left(slashPos);
54 TQString relpath =
".";
55 if (!TQFile::exists(basepath) ||
56 !TQFile::exists(destpath))
58 TQStringList basedirs = TQStringList::split(TQString( TQChar( TQDir::separator() ) ),basepath);
59 TQStringList destdirs = TQStringList::split(TQString( TQChar( TQDir::separator() ) ),destpath);
62 if (basedirs.count()>=destdirs.count())
63 maxCompare=destdirs.count();
65 maxCompare=basedirs.count();
67 for (
int i=0; i<maxCompare; i++)
69 if (basedirs[i] != destdirs[i])
73 for (uint i=0;i<basedirs.count()-(lastCommonDir+1); i++)
74 relpath += TQString( TQChar( TQDir::separator() ) )+TQString(
"..");
75 for (
int i=0; i<lastCommonDir+1; i++)
78 relpath += TQString( TQChar( TQDir::separator() ) )+destdirs.join( TQChar( TQDir::separator() ) );
79 return TQDir::cleanDirPath(relpath);
87 if (parent.equals(child,
true))
88 return slashPrefix ? TQString(
"/") : TQString(
"");
90 if (!parent.isParentOf(child))
return TQString();
91 int a=slashPrefix ? -1 : 1;
92 int b=slashSuffix ? 1 : -1;
93 return child.path(b).mid(parent.path(a).length());
99 return relativePath(KURL(parent), KURL(child), slashPolicy);
105 int slashPos = path.findRev(
"/");
106 if (slashPos<1)
return TQString();
107 return path.mid(0,slashPos+ (slashSuffix ? 1 : 0) );
115 if (source.isParentOf(child) || source.equals(child,
true))
return child;
118 if (!dest.isParentOf(child) && !dest.equals(child,
true))
return KURL();
121 if (dest.equals(child,
true))
return source;
124 TQString childUrlStr = child.url(-1);
125 TQString destStemStr = dest.url(1);
126 TQString sourceStemStr = source.url(1);
127 return KURL(sourceStemStr.append( childUrlStr.mid( destStemStr.length() ) ) );
134 int dotPos = path.findRev(
'.');
135 if (dotPos<0)
return TQString(
"");
136 return path.mid(dotPos+1);
145 int i = absRef.find( absBase, 0,
true );
150 if (absRef == absBase)
151 return TQString(
"." );
153 return absRef.replace( 0, absBase.length(), TQString() );
160 KURL baseDirUrl = KURL::fromPathOrURL( basePath );
168 KURL baseDirUrl = KURL::fromPathOrURL( basePath ),
169 fileUrl = KURL::fromPathOrURL( absFilePath );
178 return url.path( +1 );
203 return TQDir( absFilePath ).exists();
210 if (!aMessage.isNull())
212 kdDebug(9000) << aMessage << endl;
214 kdDebug(9000) <<
" List has " << urls.count() <<
" elements." << endl;
216 for (
size_t i = 0; i<urls.count(); ++i)
218 KURL url = urls[ i ];
229 for (
size_t i=0; i<urls.count(); ++i)
241 if (dirUrl.isEmpty() || (dirUrl ==
"/"))
244 TQStringList dir = TQStringList::split(
"/", dirUrl,
false);
245 TQStringList file = TQStringList::split(
"/", fileUrl,
false);
247 TQString resFileName = file.last();
248 file.remove(file.last());
251 while ( (i < dir.count()) && (i < (file.count())) && (dir[i] == file[i]) )
255 TQString result_down;
260 i >= dir.count() ? currDir =
"" : currDir = dir[i];
261 i >= file.count() ? currFile =
"" : currFile = file[i];
263 if (currDir.isEmpty() && currFile.isEmpty())
265 else if (currDir.isEmpty())
266 result_down += file[i] +
"/";
267 else if (currFile.isEmpty())
271 result_down += file[i] +
"/";
276 while ( (!currDir.isEmpty()) || (!currFile.isEmpty()) );
278 return result_up + result_down + resFileName;
287 return dir.canonicalPath();
296 uint len = str.length();
298 if (len > 1 && str[0] ==
'$')
300 int pos = str.find (
'/');
305 char* ret = getenv( TQConstString(str.unicode()+1, pos-1).string().local8Bit().data() );
309 TQString expandedStr ( TQFile::decodeName( ret ) );
311 expandedStr += str.mid(pos);
TQString envExpand(const TQString &variable)
Performs environment variable expansion on variable.
TQString filename(const TQString &pathName)
TQString directory(const TQString &pathName)
void dump(const KURL::List &urls, const TQString &aMessage=TQString())
Dumps the list of KURL urls on standard output, eventually printing aMessage if it is not null.
TQString canonicalPath(const TQString &path)
Same as TQDir::canonicalPath in later versions of TQt.
TQString extractPathNameRelative(const KURL &baseDirUrl, const KURL &url)
Given a base directory url in baseDirUrl and the url referring to the sub-directory or file,...
TQString relativePathToFile(const TQString &dirUrl, const TQString &fileUrl)
KURL mergeURL(const KURL &source, const KURL &dest, const KURL &child)
'Merges' URLs - changes a URL that starts with dest to start with source instead.
bool isDirectory(const KURL &url)
TQStringList toRelativePaths(const TQString &baseDir, const KURL::List &urls)
TQString extractPathNameAbsolute(const KURL &url)
TQString getRelativePath(const TQString &base, const TQString &dest)
TQString relativePath(const KURL &parent, const KURL &child, uint slashPolicy=SLASH_PREFIX)
TQString getExtension(const TQString &path)
@ SLASH_PREFIX
URL has slash as a prefix.
@ SLASH_SUFFIX
URL has slash as a suffix.
TQString upDir(const TQString &path, bool slashSuffix=false)
Utility functions to operate on URLs.