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  Q_DECLARE_PUBLIC(MimetypeJob)
22 
23  static inline MimetypeJob *newJob(const QUrl &url, int command, const QByteArray &packedArgs,
24  JobFlags flags)
25  {
26  MimetypeJob *job = new MimetypeJob(*new MimetypeJobPrivate(url, command, packedArgs));
28  if (!(flags & HideProgressInfo)) {
30  emitStating(job, url);
31  }
32  return job;
33  }
34 };
35 
36 MimetypeJob::MimetypeJob(MimetypeJobPrivate &dd)
37  : TransferJob(dd)
38 {
39 }
40 
41 MimetypeJob::~MimetypeJob()
42 {
43 }
44 
45 void MimetypeJob::slotFinished()
46 {
47  Q_D(MimetypeJob);
48  //qDebug();
49  if (error() == KIO::ERR_IS_DIRECTORY) {
50  // It is in fact a directory. This happens when HTTP redirects to FTP.
51  // Due to the "protocol doesn't support listing" code in KRun, we
52  // assumed it was a file.
53  //qDebug() << "It is in fact a directory!";
54  d->m_mimetype = QStringLiteral("inode/directory");
55  emit TransferJob::mimetype(this, d->m_mimetype);
56  setError(0);
57  }
58 
59  if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() && !error()) {
60  //qDebug() << "Redirection to " << m_redirectionURL;
61  if (queryMetaData(QStringLiteral("permanent-redirect")) == QLatin1String("true")) {
62  emit permanentRedirection(this, d->m_url, d->m_redirectionURL);
63  }
64 
65  if (d->m_redirectionHandlingEnabled) {
66  d->staticData.truncate(0);
67  d->m_internalSuspended = false;
68  d->m_packedArgs.truncate(0);
69  QDataStream stream(&d->m_packedArgs, QIODevice::WriteOnly);
70  stream << d->m_redirectionURL;
71 
72  d->restartAfterRedirection(&d->m_redirectionURL);
73  return;
74  }
75  }
76 
77  // Return slave to the scheduler
78  TransferJob::slotFinished();
79 }
80 
82 {
83  KIO_ARGS << url;
84  return MimetypeJobPrivate::newJob(url, CMD_MIMETYPE, packedArgs, flags);
85 }
86 
87 #include "moc_mimetypejob.cpp"
void setUiDelegate(KJobUiDelegate *delegate)
A namespace for KIO globals.
Definition: authinfo.h:21
Hide progress information dialog, i.e.
Definition: job_base.h:275
QString mimetype() const
Call this in the slot connected to result, and only after making sure no error happened.
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there&#39;s one, to create a delegate and return it...
... where a file was expected
Definition: global.h:153
void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
Find mimetype for one file or directory.
Definition: mimetypejob.cpp:81
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
A MimetypeJob is a TransferJob that allows you to get the mime type of an URL.
Definition: mimetypejob.h:27
virtual void registerJob(KJob *job)
The transfer job pumps data into and/or out of a Slave.
Definition: transferjob.h:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Sep 23 2020 23:01:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.