37
37
#include <archiveutils.h>
38
38
#include <mimetypeutils.h>
44
bool urlIsFastLocalFile(const KUrl& url) {
45
if (!url.isLocalFile()) {
49
KMountPoint::List list = KMountPoint::currentMountPoints();
50
KMountPoint::Ptr mountPoint = list.findByPath(url.toLocalFile());
52
// We couldn't find a mount point for the url. We are probably in a
53
// chroot. Assume everything is fast then.
57
return !mountPoint->probablySlow();
61
bool urlIsDirectory(const KUrl& url) {
62
if( url.fileName(KUrl::ObeyTrailingSlash).isEmpty()) {
63
return true; // file:/somewhere/<nothing here>
66
// Do direct stat instead of using KIO if the file is local (faster)
67
if (UrlUtils::urlIsFastLocalFile(url)) {
69
if ( KDE_stat( QFile::encodeName(url.toLocalFile()), &buff ) == 0 ) {
70
return S_ISDIR( buff.st_mode );
74
QWidgetList list = QApplication::topLevelWidgets();
76
if (list.count() > 0) {
82
if( KIO::NetAccess::stat( url, entry, parent)) {
89
KUrl fixUserEnteredUrl(const KUrl& in) {
90
if (!in.isRelative() && !in.isLocalFile()) {
94
QFileInfo info(in.toLocalFile());
95
QString path = info.absoluteFilePath();
97
KUrl out = KUrl::fromPath(path);
98
QString mimeType = MimeTypeUtils::urlMimeType(out);
100
const QString protocol = ArchiveUtils::protocolForMimeType(mimeType);
101
if (!protocol.isEmpty()) {
102
out.setProtocol(protocol);
46
bool urlIsFastLocalFile(const KUrl& url)
48
if (!url.isLocalFile()) {
52
KMountPoint::List list = KMountPoint::currentMountPoints();
53
KMountPoint::Ptr mountPoint = list.findByPath(url.toLocalFile());
55
// We couldn't find a mount point for the url. We are probably in a
56
// chroot. Assume everything is fast then.
60
return !mountPoint->probablySlow();
63
bool urlIsDirectory(const KUrl& url)
65
if (url.fileName(KUrl::ObeyTrailingSlash).isEmpty()) {
66
return true; // file:/somewhere/<nothing here>
69
// Do direct stat instead of using KIO if the file is local (faster)
70
if (UrlUtils::urlIsFastLocalFile(url)) {
72
if (KDE_stat(QFile::encodeName(url.toLocalFile()), &buff) == 0) {
73
return S_ISDIR(buff.st_mode);
77
QWidgetList list = QApplication::topLevelWidgets();
79
if (list.count() > 0) {
85
if (KIO::NetAccess::stat(url, entry, parent)) {
91
KUrl fixUserEnteredUrl(const KUrl& in)
93
if (!in.isRelative() && !in.isLocalFile()) {
97
QFileInfo info(in.toLocalFile());
98
QString path = info.absoluteFilePath();
100
KUrl out = KUrl::fromPath(path);
101
QString mimeType = MimeTypeUtils::urlMimeType(out);
103
const QString protocol = ArchiveUtils::protocolForMimeType(mimeType);
104
if (!protocol.isEmpty()) {
105
out.setProtocol(protocol);