KIO

mimetypejob.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000 Stephan Kulow <[email protected]>
4  SPDX-FileCopyrightText: 2000-2009 David Faure <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "mimetypejob.h"
10 #include "job_p.h"
11 
12 using namespace KIO;
13 
14 class KIO::MimetypeJobPrivate : public KIO::TransferJobPrivate
15 {
16 public:
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 
37 MimetypeJob::MimetypeJob(MimetypeJobPrivate &dd)
38  : TransferJob(dd)
39 {
40 }
41 
42 MimetypeJob::~MimetypeJob()
43 {
44 }
45 
46 void MimetypeJob::slotFinished()
47 {
49  // qDebug();
50  if (error() == KIO::ERR_IS_DIRECTORY) {
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 #if KIOCORE_BUILD_DEPRECATED_SINCE(5, 78)
57  Q_EMIT TransferJob::mimetype(this, d->m_mimetype);
58 #endif
59  Q_EMIT TransferJob::mimeTypeFound(this, d->m_mimetype);
60  setError(0);
61  }
62 
63  if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() && !error()) {
64  // qDebug() << "Redirection to " << m_redirectionURL;
65  if (queryMetaData(QStringLiteral("permanent-redirect")) == QLatin1String("true")) {
66  Q_EMIT permanentRedirection(this, d->m_url, d->m_redirectionURL);
67  }
68 
69  if (d->m_redirectionHandlingEnabled) {
70  d->staticData.truncate(0);
71  d->m_internalSuspended = false;
72  d->m_packedArgs.truncate(0);
73  QDataStream stream(&d->m_packedArgs, QIODevice::WriteOnly);
74  stream << d->m_redirectionURL;
75 
76  d->restartAfterRedirection(&d->m_redirectionURL);
77  return;
78  }
79  }
80 
81  // Return worker to the scheduler
82  TransferJob::slotFinished();
83 }
84 
86 {
87  KIO_ARGS << url;
88  return MimetypeJobPrivate::newJob(url, CMD_MIMETYPE, packedArgs, flags);
89 }
90 
91 #include "moc_mimetypejob.cpp"
virtual void registerJob(KJob *job)
void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl)
Signals a permanent redirection.
Q_EMITQ_EMIT
QString mimetype() const
Call this in the slot connected to result, and only after making sure no error happened.
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
Find MIME type for one file or directory.
Definition: mimetypejob.cpp:85
QString queryMetaData(const QString &key)
Query meta data received from the worker.
Definition: job.cpp:217
KIOCORE_EXPORT KJobTrackerInterface * getJobTracker()
Returns the job tracker to be used by all KIO jobs (in which HideProgressInfo is not set)
Definition: jobtracker.cpp:14
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there's one, to create a delegate and return it.
void setFinishedNotificationHidden(bool hide=true)
@ ERR_IS_DIRECTORY
... where a file was expected
Definition: global.h:153
void mimeTypeFound(KIO::Job *job, const QString &mimeType)
MIME type determined.
void setUiDelegate(KJobUiDelegate *delegate)
A namespace for KIO globals.
@ HideProgressInfo
Hide progress information dialog, i.e. don't show a GUI.
Definition: job_base.h:275
int error() const
void setError(int errorCode)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 28 2023 03:52:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.