TDE base libraries and programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

konq_run.cc 6.8KB

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