Using QFileInfo to strip trailing slash(es) is bad when input contains non-
native paths (i.e. Windows paths on non-Windows system and vice versa) as it
may mistakenly treat the path as relative and change it in unespected way.
extern QPixmap qt_pixmapFromWinHICON(HICON icon);
#endif
-#ifdef _WIN32
namespace
{
+#ifdef _WIN32
void
addAssociatedFileIcon (const QFileInfo& fileInfo, UINT iconSize, QIcon& icon)
{
if (!pixmap.isNull ())
icon.addPixmap (pixmap);
}
-} // namespace
#endif
+ bool
+ isSlashChar (const QChar& c)
+ {
+ return c == QLatin1Char ('/') || c == QLatin1Char ('\\');
+ }
+} // namespace
+
QIcon
Utils::guessMimeIcon (const QString& filename)
{
QString
Utils::removeTrailingDirSeparator (const QString& path)
{
- const QFileInfo pathInfo (path);
- return pathInfo.fileName ().isEmpty () ? pathInfo.absolutePath () : pathInfo.absoluteFilePath ();
+ int i = path.size ();
+ while (i > 1 && isSlashChar (path[i - 1]))
+ --i;
+ return path.left (i);
}
int