21 #include <tqstringlist.h> 24 #include <tqfileinfo.h> 33 #include <tdeversion.h> 40 int slashPos = name.findRev(
"/");
41 return slashPos<0 ? name : name.mid(slashPos+1);
47 int slashPos = name.findRev(
"/");
48 return slashPos<0 ? TQString(
"") : name.left(slashPos);
55 TQString relpath =
".";
56 if (!TQFile::exists(basepath) ||
57 !TQFile::exists(destpath))
59 TQStringList basedirs = TQStringList::split(TQString( TQChar( TQDir::separator() ) ),basepath);
60 TQStringList destdirs = TQStringList::split(TQString( TQChar( TQDir::separator() ) ),destpath);
63 if (basedirs.count()>=destdirs.count())
64 maxCompare=destdirs.count();
66 maxCompare=basedirs.count();
68 for (
int i=0; i<maxCompare; i++)
70 if (basedirs[i] != destdirs[i])
74 for (uint i=0;i<basedirs.count()-(lastCommonDir+1); i++)
75 relpath += TQString( TQChar( TQDir::separator() ) )+TQString(
"..");
76 for (
int i=0; i<lastCommonDir+1; i++)
79 relpath += TQString( TQChar( TQDir::separator() ) )+destdirs.join( TQChar( TQDir::separator() ) );
80 return TQDir::cleanDirPath(relpath);
88 if (parent.equals(child,
true))
89 return slashPrefix ? TQString(
"/") : TQString(
"");
91 if (!parent.isParentOf(child))
return TQString();
92 int a=slashPrefix ? -1 : 1;
93 int b=slashSuffix ? 1 : -1;
94 return child.path(b).mid(parent.path(a).length());
100 return relativePath(KURL(parent), KURL(child), slashPolicy);
106 int slashPos = path.findRev(
"/");
107 if (slashPos<1)
return TQString();
108 return path.mid(0,slashPos+ (slashSuffix ? 1 : 0) );
116 if (source.isParentOf(child) || source.equals(child,
true))
return child;
119 if (!dest.isParentOf(child) && !dest.equals(child,
true))
return KURL();
122 if (dest.equals(child,
true))
return source;
125 TQString childUrlStr = child.url(-1);
126 TQString destStemStr = dest.url(1);
127 TQString sourceStemStr = source.url(1);
128 return KURL(sourceStemStr.append( childUrlStr.mid( destStemStr.length() ) ) );
135 int dotPos = path.findRev(
'.');
136 if (dotPos<0)
return TQString(
"");
137 return path.mid(dotPos+1);
146 int i = absRef.find( absBase, 0,
true );
151 if (absRef == absBase)
152 return TQString(
"." );
154 return absRef.replace( 0, absBase.length(), TQString() );
161 KURL baseDirUrl = KURL::fromPathOrURL( basePath );
169 KURL baseDirUrl = KURL::fromPathOrURL( basePath ),
170 fileUrl = KURL::fromPathOrURL( absFilePath );
179 return url.path( +1 );
204 return TQDir( absFilePath ).exists();
211 if (!aMessage.isNull())
213 kdDebug(9000) << aMessage << endl;
215 kdDebug(9000) <<
" List has " << urls.count() <<
" elements." << endl;
217 for (
size_t i = 0; i<urls.count(); ++i)
219 KURL url = urls[ i ];
230 for (
size_t i=0; i<urls.count(); ++i)
242 if (dirUrl.isEmpty() || (dirUrl ==
"/"))
245 TQStringList dir = TQStringList::split(
"/", dirUrl,
false);
246 TQStringList file = TQStringList::split(
"/", fileUrl,
false);
248 TQString resFileName = file.last();
249 file.remove(file.last());
252 while ( (i < dir.count()) && (i < (file.count())) && (dir[i] == file[i]) )
256 TQString result_down;
261 i >= dir.count() ? currDir =
"" : currDir = dir[i];
262 i >= file.count() ? currFile =
"" : currFile = file[i];
264 if (currDir.isEmpty() && currFile.isEmpty())
266 else if (currDir.isEmpty())
267 result_down += file[i] +
"/";
268 else if (currFile.isEmpty())
272 result_down += file[i] +
"/";
277 while ( (!currDir.isEmpty()) || (!currFile.isEmpty()) );
279 return result_up + result_down + resFileName;
288 return dir.canonicalPath();
297 uint len = str.length();
299 if (len > 1 && str[0] ==
'$')
301 int pos = str.find (
'/');
306 char* ret = getenv( TQConstString(str.unicode()+1, pos-1).
string().local8Bit().data() );
310 TQString expandedStr ( TQFile::decodeName( ret ) );
312 expandedStr += str.mid(pos);
bool isDirectory(const KURL &url)
TQString getRelativePath(const TQString &base, const TQString &dest)
TQString extractPathNameAbsolute(const KURL &url)
TQStringList toRelativePaths(const TQString &baseDir, const KURL::List &urls)
TQString filename(const TQString &pathName)
TQString getExtension(const TQString &path)
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...
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 relativePathToFile(const TQString &dirUrl, const TQString &fileUrl)
TQString canonicalPath(const TQString &path)
Same as TQDir::canonicalPath in later versions of TQt.
Utility functions to operate on URLs.
TQString upDir(const TQString &path, bool slashSuffix=false)
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. ...
TQString directory(const TQString &pathName)
URL has slash as a suffix.
TQString envExpand(const TQString &variable)
Performs environment variable expansion on variable.
URL has slash as a prefix.
TQString relativePath(const KURL &parent, const KURL &child, uint slashPolicy=SLASH_PREFIX)