File indexing completed on 2024-09-15 03:38:33
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 Q_EMIT TransferJob::mimeTypeFound(this, d->m_mimetype); 0057 setError(0); 0058 } 0059 0060 if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() && !error()) { 0061 // qDebug() << "Redirection to " << m_redirectionURL; 0062 if (queryMetaData(QStringLiteral("permanent-redirect")) == QLatin1String("true")) { 0063 Q_EMIT permanentRedirection(this, d->m_url, d->m_redirectionURL); 0064 } 0065 0066 if (d->m_redirectionHandlingEnabled) { 0067 d->staticData.truncate(0); 0068 d->m_internalSuspended = false; 0069 d->m_packedArgs.truncate(0); 0070 QDataStream stream(&d->m_packedArgs, QIODevice::WriteOnly); 0071 stream << d->m_redirectionURL; 0072 0073 d->restartAfterRedirection(&d->m_redirectionURL); 0074 return; 0075 } 0076 } 0077 0078 // Return worker to the scheduler 0079 TransferJob::slotFinished(); 0080 } 0081 0082 MimetypeJob *KIO::mimetype(const QUrl &url, JobFlags flags) 0083 { 0084 KIO_ARGS << url; 0085 return MimetypeJobPrivate::newJob(url, CMD_MIMETYPE, packedArgs, flags); 0086 } 0087 0088 #include "moc_mimetypejob.cpp"