File indexing completed on 2023-09-24 04:08:40
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org> 0004 SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "mimetypejob.h" 0010 #include "job_p.h" 0011 0012 using namespace KIO; 0013 0014 class KIO::MimetypeJobPrivate : public KIO::TransferJobPrivate 0015 { 0016 public: 0017 MimetypeJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs) 0018 : TransferJobPrivate(url, command, packedArgs, QByteArray()) 0019 { 0020 } 0021 0022 Q_DECLARE_PUBLIC(MimetypeJob) 0023 0024 static inline MimetypeJob *newJob(const QUrl &url, int command, const QByteArray &packedArgs, JobFlags flags) 0025 { 0026 MimetypeJob *job = new MimetypeJob(*new MimetypeJobPrivate(url, command, packedArgs)); 0027 job->setUiDelegate(KIO::createDefaultJobUiDelegate()); 0028 if (!(flags & HideProgressInfo)) { 0029 job->setFinishedNotificationHidden(); 0030 KIO::getJobTracker()->registerJob(job); 0031 emitStating(job, url); 0032 } 0033 return job; 0034 } 0035 }; 0036 0037 MimetypeJob::MimetypeJob(MimetypeJobPrivate &dd) 0038 : TransferJob(dd) 0039 { 0040 } 0041 0042 MimetypeJob::~MimetypeJob() 0043 { 0044 } 0045 0046 void MimetypeJob::slotFinished() 0047 { 0048 Q_D(MimetypeJob); 0049 // qDebug(); 0050 if (error() == KIO::ERR_IS_DIRECTORY) { 0051 // It is in fact a directory. This happens when HTTP redirects to FTP. 0052 // Due to the "protocol doesn't support listing" code in KRun, we 0053 // assumed it was a file. 0054 // qDebug() << "It is in fact a directory!"; 0055 d->m_mimetype = QStringLiteral("inode/directory"); 0056 #if KIOCORE_BUILD_DEPRECATED_SINCE(5, 78) 0057 Q_EMIT TransferJob::mimetype(this, d->m_mimetype); 0058 #endif 0059 Q_EMIT TransferJob::mimeTypeFound(this, d->m_mimetype); 0060 setError(0); 0061 } 0062 0063 if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() && !error()) { 0064 // qDebug() << "Redirection to " << m_redirectionURL; 0065 if (queryMetaData(QStringLiteral("permanent-redirect")) == QLatin1String("true")) { 0066 Q_EMIT permanentRedirection(this, d->m_url, d->m_redirectionURL); 0067 } 0068 0069 if (d->m_redirectionHandlingEnabled) { 0070 d->staticData.truncate(0); 0071 d->m_internalSuspended = false; 0072 d->m_packedArgs.truncate(0); 0073 QDataStream stream(&d->m_packedArgs, QIODevice::WriteOnly); 0074 stream << d->m_redirectionURL; 0075 0076 d->restartAfterRedirection(&d->m_redirectionURL); 0077 return; 0078 } 0079 } 0080 0081 // Return worker to the scheduler 0082 TransferJob::slotFinished(); 0083 } 0084 0085 MimetypeJob *KIO::mimetype(const QUrl &url, JobFlags flags) 0086 { 0087 KIO_ARGS << url; 0088 return MimetypeJobPrivate::newJob(url, CMD_MIMETYPE, packedArgs, flags); 0089 } 0090 0091 #include "moc_mimetypejob.cpp"