1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/* This file is part of the KDE project
Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include "konq_run.h"
#include "konq_view.h"
#include <kuserprofile.h>
#include <tdemessagebox.h>
#include <tdelocale.h>
#include <konq_historymgr.h>
#include <assert.h>
#define HINT_UTF8 106
KonqRun::KonqRun( KonqMainWindow* mainWindow, KonqView *_childView,
const KURL & _url, const KonqOpenURLRequest & req, bool trustedSource )
: KParts::BrowserRun( _url, req.args, _childView ? _childView->part() : 0L, mainWindow,
//remove referrer if request was typed in manually.
// ### TODO: turn this off optionally.
!req.typedURL.isEmpty(), trustedSource,
// Don't use inline errors on reloading due to auto-refresh sites, but use them in all other cases
// (no reload or user-requested reload)
!req.args.reload || req.userRequestedReload ),
m_pMainWindow( mainWindow ), m_pView( _childView ), m_bFoundMimeType( false ), m_req( req )
{
//kdDebug(1202) << "KonqRun::KonqRun() " << this << endl;
assert( !m_pMainWindow.isNull() );
if (m_pView)
m_pView->setLoading(true);
}
KonqRun::~KonqRun()
{
//kdDebug(1202) << "KonqRun::~KonqRun() " << this << endl;
if (m_pView && m_pView->run() == this)
m_pView->setRun(0L);
}
void KonqRun::foundMimeType( const TQString & _type )
{
//kdDebug(1202) << "KonqRun::foundMimeType " << _type << " m_req=" << m_req.debug() << endl;
TQString mimeType = _type; // this ref comes from the job, we lose it when using KIO again
m_bFoundMimeType = true;
if (m_pView)
m_pView->setLoading(false); // first phase finished, don't confuse KonqView
// Check if the main window wasn't deleted meanwhile
if( !m_pMainWindow )
{
m_bFinished = true;
m_bFault = true;
m_timer.start( 0, true );
return;
}
// Grab the args back from BrowserRun
m_req.args = m_args;
bool tryEmbed = true;
// One case where we shouldn't try to embed, is when the server asks us to save
if ( serverSuggestsSave() )
tryEmbed = false;
if ( KonqMainWindow::isMimeTypeAssociatedWithSelf( mimeType ) )
m_req.forceAutoEmbed = true;
if ( tryEmbed )
m_bFinished = m_pMainWindow->openView( mimeType, m_strURL, m_pView, m_req );
if ( m_bFinished ) {
m_pMainWindow = 0L;
m_timer.start( 0, true );
return;
}
// If we were following another view, do nothing if opening didn't work.
if ( m_req.followMode )
m_bFinished = true;
if ( !m_bFinished ) {
// If we couldn't embed the mimetype, call BrowserRun::handleNonEmbeddable()
KParts::BrowserRun::NonEmbeddableResult res = handleNonEmbeddable( mimeType );
if ( res == KParts::BrowserRun::Delayed )
return;
m_bFinished = ( res == KParts::BrowserRun::Handled );
if (!m_bFinished && !tryEmbed) // Open selected for a serverSuggestsSave() file
m_bFinished = m_pMainWindow->openView( mimeType, m_strURL, m_pView, m_req );
}
// make Konqueror think there was an error, in order to stop the spinning wheel
// (we saved, canceled, or we're starting another app... in any case the current view should stop loading).
m_bFault = true;
if ( !m_bFinished && // only if we're going to open
KonqMainWindow::isMimeTypeAssociatedWithSelf( mimeType ) ) {
KMessageBox::error( m_pMainWindow, i18n( "There appears to be a configuration error. You have associated Konqueror with %1, but it cannot handle this file type." ).arg( mimeType ) );
m_bFinished = true;
}
if ( m_bFinished ) {
m_pMainWindow = 0L;
m_timer.start( 0, true );
return;
}
kdDebug(1202) << "Nothing special to do in KonqRun, falling back to KRun" << endl;
KRun::foundMimeType( mimeType );
}
void KonqRun::handleError( TDEIO::Job *job )
{
kdDebug(1202) << "KonqRun::handleError error:" << job->errorString() << endl;
if (!m_mailto.isEmpty())
{
m_job = 0;
m_bFinished = true;
m_timer.start( 0, true );
return;
}
KParts::BrowserRun::handleError( job );
}
void KonqRun::init()
{
KParts::BrowserRun::init();
// Maybe init went to the "let's try stat'ing" part. Then connect to info messages.
// (in case it goes to scanFile, this will be done below)
TDEIO::StatJob *job = tqt_dynamic_cast<TDEIO::StatJob*>( m_job );
if ( job && !job->error() && m_pView ) {
connect( job, TQT_SIGNAL( infoMessage( TDEIO::Job*, const TQString& ) ),
m_pView, TQT_SLOT( slotInfoMessage(TDEIO::Job*, const TQString& ) ) );
}
}
void KonqRun::scanFile()
{
KParts::BrowserRun::scanFile();
// could be a static cast as of now, but who would notify when
// BrowserRun changes
TDEIO::TransferJob *job = tqt_dynamic_cast<TDEIO::TransferJob*>( m_job );
if ( job && !job->error() ) {
connect( job, TQT_SIGNAL( redirection( TDEIO::Job *, const KURL& )),
TQT_SLOT( slotRedirection( TDEIO::Job *, const KURL& ) ));
if ( m_pView && m_pView->service()->desktopEntryName() != "konq_sidebartng") {
connect( job, TQT_SIGNAL( infoMessage( TDEIO::Job*, const TQString& ) ),
m_pView, TQT_SLOT( slotInfoMessage(TDEIO::Job*, const TQString& ) ) );
}
}
}
void KonqRun::slotRedirection( TDEIO::Job *job, const KURL& redirectedToURL )
{
KURL redirectFromURL = static_cast<TDEIO::TransferJob *>(job)->url();
kdDebug(1202) << "KonqRun::slotRedirection from " <<
redirectFromURL.prettyURL() << " to " << redirectedToURL.prettyURL() << endl;
KonqHistoryManager::kself()->confirmPending( redirectFromURL );
if (redirectedToURL.protocol() == "mailto")
{
m_mailto = redirectedToURL;
return; // Error will follow
}
KonqHistoryManager::kself()->addPending( redirectedToURL );
// Do not post data on reload if we were redirected to a new URL when
// doing a POST request.
if (redirectFromURL != redirectedToURL)
m_args.setDoPost (false);
m_args.setRedirectedRequest(true);
}
#include "konq_run.moc"
|