KHtml

khtml_run.cpp
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 1998, 1999 Torben Weis <[email protected]>
4  * 1999 Lars Knoll <[email protected]>
5  * 1999 Antti Koivisto <[email protected]>
6  * 2000 Simon Hausmann <[email protected]>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 #include "khtml_run.h"
24 #include "khtmlpart_p.h"
25 #include <kio/job.h>
26 #include "khtml_debug.h"
27 #include <klocalizedstring.h>
28 #include "khtml_ext.h"
29 #include <QImage>
30 
31 KHTMLRun::KHTMLRun(KHTMLPart *part, khtml::ChildFrame *child, const QUrl &url,
32  const KParts::OpenUrlArguments &args,
33  const KParts::BrowserArguments &browserArgs,
34  bool hideErrorDialog)
35  : KParts::BrowserRun(url, args, browserArgs, part, part->widget() ? part->widget()->topLevelWidget() : nullptr,
36  false, false, hideErrorDialog),
37  m_child(child)
38 {
39  // Don't use an external browser for parts of a webpage we are rendering. (iframes at least are one example)
40  setEnableExternalBrowser(false);
41 
42  // get the wheel to start spinning
43  part->started(nullptr);
44 }
45 
46 //KHTMLPart *KHTMLRun::htmlPart() const
47 //{ return static_cast<KHTMLPart *>(part()); }
48 
49 void KHTMLRun::foundMimeType(const QString &_type)
50 {
51  //qCDebug(KHTML_LOG) << this << _type;
52  Q_ASSERT(!hasFinished());
53  QString mimeType = _type; // this ref comes from the job, we lose it when using KIO again
54 
55  bool requestProcessed = static_cast<KHTMLPart *>(part())->processObjectRequest(m_child, KRun::url(), mimeType);
56 
57  if (requestProcessed) {
58  setFinished(true);
59  } else {
60  if (hasFinished()) { // abort was called (this happens with the activex fallback for instance)
61  return;
62  }
63  // Couldn't embed -> call BrowserRun::handleNonEmbeddable()
64  KService::Ptr selectedService;
65  KParts::BrowserRun::NonEmbeddableResult res = handleNonEmbeddable(mimeType, &selectedService);
66  if (res == KParts::BrowserRun::Delayed) {
67  return;
68  }
69  setFinished(res == KParts::BrowserRun::Handled);
70  if (hasFinished()) { // saved or canceled -> flag completed
71  m_child->m_bCompleted = true;
72  static_cast<KHTMLPart *>(part())->checkCompleted();
73  } else {
74  // "Open" selected, possible with a specific application
75  if (selectedService) {
76  KRun::setPreferredService(selectedService->desktopEntryName());
77  } else {
78  KRun::displayOpenWithDialog(QList<QUrl>() << url(), part()->widget(), false /*tempfile*/, suggestedFileName());
79  setFinished(true);
80  }
81  }
82  }
83 
84  if (hasFinished()) {
85  // qCDebug(KHTML_LOG) << "finished";
86  return;
87  }
88 
89  //qCDebug(KHTML_LOG) << _type << " couldn't open";
90  KRun::foundMimeType(mimeType);
91 
92  // "open" is finished -> flag completed
93  m_child->m_bCompleted = true;
94  static_cast<KHTMLPart *>(part())->checkCompleted();
95 }
96 
97 void KHTMLRun::handleError(KJob *)
98 {
99  // Tell KHTML that loading failed.
100  static_cast<KHTMLPart *>(part())->processObjectRequest(m_child, QUrl(), QString());
101  setJob(nullptr);
102 }
103 
104 void KHTMLRun::save(const QUrl &url, const QString &suggestedFilename)
105 {
106  KHTMLPopupGUIClient::saveURL(part()->widget(), i18n("Save As"), url, arguments().metaData(), QString(), 0, suggestedFilename);
107 }
108 
void started(KIO::Job *job)
static bool displayOpenWithDialog(const QList< QUrl > &lst, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
virtual void foundMimeType(const QString &type)
QUrl url() const
This class is khtml&#39;s main class.
Definition: khtml_part.h:208
QString i18n(const char *text, const TYPE &arg...)
void setPreferredService(const QString &desktopEntryName)
QString mimeType(Type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:04 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.