add more spacing
[personal-kdebase.git] / apps / konqueror / src / konqrun.cpp
blob7bcb7a0138b5abd694038fed750a3207d134ff38
1 /* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 // Own
21 #include "konqrun.h"
23 // std
24 #include <assert.h>
26 // KDE
27 #include <kdebug.h>
28 #include <kmessagebox.h>
29 #include <klocale.h>
30 #include <kio/job.h>
32 // Local
33 #include "konqview.h"
34 #include "konqframestatusbar.h"
35 #include "konqhistorymanager.h"
36 #include "konqsettings.h"
39 KonqRun::KonqRun(KonqMainWindow* mainWindow, KonqView *_childView,
40 const KUrl & _url, const KonqOpenURLRequest & req, bool trustedSource)
41 : KParts::BrowserRun(_url, req.args, req.browserArgs, _childView ? _childView->part() : 0L, mainWindow,
42 //remove referrer if request was typed in manually.
43 // ### TODO: turn this off optionally.
44 !req.typedUrl.isEmpty(), trustedSource,
45 // Don't use inline errors on reloading due to auto-refresh sites, but use them in all other cases
46 // (no reload or user-requested reload)
47 !req.args.reload() || req.userRequestedReload),
48 m_pMainWindow(mainWindow), m_pView(_childView), m_bFoundMimeType(false), m_req(req)
50 //kDebug(1202) << "KonqRun::KonqRun() " << this;
51 assert(!m_pMainWindow.isNull());
52 if (m_pView)
53 m_pView->setLoading(true);
56 KonqRun::~KonqRun()
58 //kDebug(1202) << "KonqRun::~KonqRun() " << this;
59 if (m_pView && m_pView->run() == this)
60 m_pView->setRun(0);
63 void KonqRun::foundMimeType(const QString & _type)
65 //kDebug(1202) << "KonqRun::foundMimeType " << _type << " m_req=" << m_req.debug();
67 QString mimeType = _type; // this ref comes from the job, we lose it when using KIO again
69 m_bFoundMimeType = true;
71 if (m_pView)
72 m_pView->setLoading(false); // first phase finished, don't confuse KonqView
74 // Check if the main window wasn't deleted meanwhile
75 if (!m_pMainWindow) {
76 setFinished(true);
77 setError(true);
78 timer().start(0);
79 return;
82 // Grab the args back from BrowserRun
83 m_req.args = arguments();
84 m_req.browserArgs = browserArguments();
86 bool tryEmbed = true;
87 // One case where we shouldn't try to embed, is when the server asks us to save
88 if (serverSuggestsSave())
89 tryEmbed = false;
91 const bool associatedAppIsKonqueror = KonqMainWindow::isMimeTypeAssociatedWithSelf(mimeType);
93 if (tryEmbed && tryOpenView(mimeType, associatedAppIsKonqueror)) {
94 return;
97 // If we were following another view, do nothing if opening didn't work.
98 if (m_req.followMode) {
99 setFinished(true);
102 if (!hasFinished()) {
103 // Use askSave from filetypesrc
104 KMessageBox::setDontShowAskAgainConfig(KonqFMSettings::settings()->fileTypesConfig().data());
105 // If we couldn't embed the mimetype, call BrowserRun::handleNonEmbeddable()
106 KParts::BrowserRun::NonEmbeddableResult res = handleNonEmbeddable(mimeType);
107 KMessageBox::setDontShowAskAgainConfig(0);
108 if (res == KParts::BrowserRun::Delayed)
109 return;
110 setFinished(res == KParts::BrowserRun::Handled);
111 if (hasFinished()) {
112 // save or cancel -> nothing else will happen in m_pView, so clear statusbar (#163628)
113 m_pView->frame()->statusbar()->slotClear();
114 } else if (!tryEmbed) {
115 // "Open" selected for a serverSuggestsSave() file - let's open. #171869
116 if (tryOpenView(mimeType, associatedAppIsKonqueror))
117 return;
121 // make Konqueror think there was an error, in order to stop the spinning wheel
122 // (we saved, canceled, or we're starting another app... in any case the current view should stop loading).
123 setError(true);
125 if (!hasFinished()) { // only if we're going to open
126 if (associatedAppIsKonqueror && m_pMainWindow->refuseExecutingKonqueror(mimeType)) {
127 setFinished(true);
131 if (hasFinished()) {
132 m_pMainWindow = 0L;
133 timer().start(0);
134 return;
137 kDebug(1202) << "Nothing special to do in KonqRun, falling back to KRun";
138 KRun::foundMimeType(mimeType);
141 bool KonqRun::tryOpenView(const QString& mimeType, bool associatedAppIsKonqueror)
143 KMimeType::Ptr mime = KMimeType::mimeType(mimeType, KMimeType::ResolveAliases);
144 if (associatedAppIsKonqueror)
145 m_req.forceAutoEmbed = true;
146 else if (mime && mime->is("text/html") && m_pMainWindow->hasViewWithMimeType(mimeType)) {
147 m_req.forceAutoEmbed = true;
148 // When text/html is associated with another browser,
149 // we need to find out if we should keep browsing the web in konq,
150 // or if we are clicking on an html file in a directory view (which should
151 // then open the other browser)
153 // The text/html check is to reduce the effects of the above!
154 // Otherwise, once you have an embedded PDF,
155 // all future PDFs are opened embedded, even after changing settings!
158 const bool ok = m_pMainWindow->openView(mimeType, KRun::url(), m_pView, m_req);
159 setFinished(ok);
161 if (ok) {
162 m_pMainWindow = 0;
163 timer().start(0);
165 return ok;
168 void KonqRun::handleError(KJob *job)
170 kDebug(1202) << "KonqRun::handleError error:" << job->errorString();
171 if (!m_mailto.isEmpty()) {
172 setJob(0);
173 setFinished(true);
174 timer().start(0);
175 return;
177 KParts::BrowserRun::handleError(job);
180 void KonqRun::init()
182 KParts::BrowserRun::init();
183 // Maybe init went to the "let's try stat'ing" part. Then connect to info messages.
184 // (in case it goes to scanFile, this will be done below)
185 KIO::StatJob *job = dynamic_cast<KIO::StatJob*>(KRun::job());
186 if (job && !job->error() && m_pView) {
187 connect(job, SIGNAL(infoMessage(KJob*, const QString&, const QString&)),
188 m_pView, SLOT(slotInfoMessage(KJob*, const QString&)));
192 void KonqRun::scanFile()
194 KParts::BrowserRun::scanFile();
195 // could be a static cast as of now, but who would notify when
196 // BrowserRun changes
197 KIO::TransferJob *job = dynamic_cast<KIO::TransferJob*>(KRun::job());
198 if (job && !job->error()) {
199 connect(job, SIGNAL(redirection(KIO::Job *, const KUrl&)),
200 SLOT(slotRedirection(KIO::Job *, const KUrl&)));
201 if (m_pView && m_pView->service()->desktopEntryName() != "konq_sidebartng") {
202 connect(job, SIGNAL(infoMessage(KJob*, const QString&, const QString&)),
203 m_pView, SLOT(slotInfoMessage(KJob*, const QString&)));
208 void KonqRun::slotRedirection(KIO::Job *job, const KUrl& redirectedToURL)
210 KUrl redirectFromURL = static_cast<KIO::TransferJob *>(job)->url();
211 kDebug(1202) << redirectFromURL << "->" << redirectedToURL;
212 KonqHistoryManager::kself()->confirmPending(redirectFromURL);
214 if (redirectedToURL.protocol() == "mailto") {
215 m_mailto = redirectedToURL;
216 return; // Error will follow
218 KonqHistoryManager::kself()->addPending(redirectedToURL);
220 // Do not post data on reload if we were redirected to a new URL when
221 // doing a POST request.
222 if (redirectFromURL != redirectedToURL)
223 browserArguments().setDoPost (false);
224 browserArguments().setRedirectedRequest(true);
227 KonqView * KonqRun::childView() const
229 return m_pView;
232 #include "konqrun.moc"