fix logic
[personal-kdelibs.git] / khtml / khtml_run.cpp
blobb80cc7bb5360844bf3e40145f510bcad4b7a24e7
1 /* This file is part of the KDE project
3 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4 * 1999 Lars Knoll <knoll@kde.org>
5 * 1999 Antti Koivisto <koivisto@kde.org>
6 * 2000 Simon Hausmann <hausmann@kde.org>
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.
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.
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.
23 #include "khtml_run.h"
24 #include "khtmlpart_p.h"
25 #include <kio/job.h>
26 #include <kdebug.h>
27 #include <klocale.h>
28 #include "khtml_ext.h"
29 #include <QtGui/QImage>
31 KHTMLRun::KHTMLRun( KHTMLPart *part, khtml::ChildFrame *child, const KUrl &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() : 0,
36 false, false, hideErrorDialog ),
37 m_child( child )
39 // Don't use an external browser for parts of a webpage we are rendering. (iframes at least are one example)
40 setEnableExternalBrowser(false);
42 // get the wheel to start spinning
43 part->started(0L);
46 //KHTMLPart *KHTMLRun::htmlPart() const
47 //{ return static_cast<KHTMLPart *>(part()); }
49 void KHTMLRun::foundMimeType( const QString &_type )
51 //kDebug(6050) << this << _type;
52 Q_ASSERT(!hasFinished());
53 QString mimeType = _type; // this ref comes from the job, we lose it when using KIO again
55 bool requestProcessed = static_cast<KHTMLPart *>(part())->processObjectRequest( m_child, KRun::url(), mimeType );
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 // Couldn't embed -> call BrowserRun::handleNonEmbeddable()
63 KParts::BrowserRun::NonEmbeddableResult res = handleNonEmbeddable( mimeType );
64 if ( res == KParts::BrowserRun::Delayed )
65 return;
66 setFinished( res == KParts::BrowserRun::Handled );
67 if ( hasFinished() ) { // saved or canceled -> flag completed
68 m_child->m_bCompleted = true;
69 static_cast<KHTMLPart *>(part())->checkCompleted();
73 if ( hasFinished() ) {
74 kDebug() << "finished";
75 timer().setSingleShot( true );
76 timer().start( 0 );
77 return;
80 //kDebug(6050) << _type << " couldn't open";
81 KRun::foundMimeType( mimeType );
83 // "open" is finished -> flag completed
84 m_child->m_bCompleted = true;
85 static_cast<KHTMLPart *>(part())->checkCompleted();
88 void KHTMLRun::handleError(KJob*)
90 // Tell KHTML that loading failed.
91 static_cast<KHTMLPart *>(part())->processObjectRequest( m_child, KUrl(), QString() );
92 setJob(0);
95 void KHTMLRun::save( const KUrl & url, const QString & suggestedFilename )
97 KHTMLPopupGUIClient::saveURL( part()->widget(), i18n( "Save As" ), url, arguments().metaData(), QString(), 0, suggestedFilename );
100 #include "khtml_run.moc"