KIO

mimetypejob.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
4 SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "mimetypejob.h"
10#include "job_p.h"
11
12using namespace KIO;
13
14class KIO::MimetypeJobPrivate : public KIO::TransferJobPrivate
15{
16public:
17 MimetypeJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs)
18 : TransferJobPrivate(url, command, packedArgs, QByteArray())
19 {
20 }
21
22 Q_DECLARE_PUBLIC(MimetypeJob)
23
24 static inline MimetypeJob *newJob(const QUrl &url, int command, const QByteArray &packedArgs, JobFlags flags)
25 {
26 MimetypeJob *job = new MimetypeJob(*new MimetypeJobPrivate(url, command, packedArgs));
28 if (!(flags & HideProgressInfo)) {
31 emitStating(job, url);
32 }
33 return job;
34 }
35};
36
37MimetypeJob::MimetypeJob(MimetypeJobPrivate &dd)
38 : TransferJob(dd)
39{
40}
41
42MimetypeJob::~MimetypeJob()
43{
44}
45
46void MimetypeJob::slotFinished()
47{
49 // qDebug();
51 // It is in fact a directory. This happens when HTTP redirects to FTP.
52 // Due to the "protocol doesn't support listing" code in KRun, we
53 // assumed it was a file.
54 // qDebug() << "It is in fact a directory!";
55 d->m_mimetype = QStringLiteral("inode/directory");
56 Q_EMIT TransferJob::mimeTypeFound(this, d->m_mimetype);
57 setError(0);
58 }
59
60 if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() && !error()) {
61 // qDebug() << "Redirection to " << m_redirectionURL;
62 if (queryMetaData(QStringLiteral("permanent-redirect")) == QLatin1String("true")) {
63 Q_EMIT permanentRedirection(this, d->m_url, d->m_redirectionURL);
64 }
65
66 if (d->m_redirectionHandlingEnabled) {
67 d->staticData.truncate(0);
68 d->m_internalSuspended = false;
69 d->m_packedArgs.truncate(0);
70 QDataStream stream(&d->m_packedArgs, QIODevice::WriteOnly);
71 stream << d->m_redirectionURL;
72
73 d->restartAfterRedirection(&d->m_redirectionURL);
74 return;
75 }
76 }
77
78 // Return worker to the scheduler
79 TransferJob::slotFinished();
80}
81
83{
84 KIO_ARGS << url;
85 return MimetypeJobPrivate::newJob(url, CMD_MIMETYPE, packedArgs, flags);
86}
87
88#include "moc_mimetypejob.cpp"
QString queryMetaData(const QString &key)
Query meta data received from the worker.
Definition job.cpp:210
A MimetypeJob is a TransferJob that allows you to get the MIME type of a URL.
Definition mimetypejob.h:27
The transfer job pumps data into and/or out of a KIO worker.
Definition transferjob.h:26
void mimeTypeFound(KIO::Job *job, const QString &mimeType)
MIME type determined.
void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl)
Signals a permanent redirection.
virtual void registerJob(KJob *job)
int error() const
void setError(int errorCode)
void setUiDelegate(KJobUiDelegate *delegate)
void setFinishedNotificationHidden(bool hide=true)
A namespace for KIO globals.
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there's one, to create a delegate and return it.
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
Find MIME type for one file or directory.
@ HideProgressInfo
Hide progress information dialog, i.e. don't show a GUI.
Definition job_base.h:251
@ ERR_IS_DIRECTORY
... where a file was expected
Definition global.h:120
KIOCORE_EXPORT KJobTrackerInterface * getJobTracker()
Returns the job tracker to be used by all KIO jobs (in which HideProgressInfo is not set)
Q_EMITQ_EMIT
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:51 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.