TDE core libraries
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.

browserrun.h 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 2002 David Faure <faure@kde.org>
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License version 2, as published by the Free Software Foundation.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public License
  14. * along with this library; see the file COPYING.LIB. If not, write to
  15. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef tdeparts_browserrun_h
  19. #define tdeparts_browserrun_h
  20. #include <krun.h>
  21. #include <kservice.h>
  22. #include <tdeparts/browserextension.h>
  23. namespace KParts {
  24. /**
  25. * This class extends KRun to provide additional functionality for browsers:
  26. * <ul>
  27. * <li>"save or open" dialog boxes
  28. * <li>"save" functionality
  29. * <li>support for HTTP POST (including saving the result to a temp file if
  30. * opening a separate application)
  31. * <li>warning before launching executables off the web
  32. * <li>custom error handling (i.e. treating errors as HTML pages)
  33. * <li>generation of SSL metadata depending on the previous URL shown by the part
  34. * </ul>
  35. *
  36. * @author David Faure <faure@kde.org>
  37. */
  38. class TDEPARTS_EXPORT BrowserRun : public KRun
  39. {
  40. Q_OBJECT
  41. public:
  42. /**
  43. * @param url the URL we're probing
  44. * @param args URL args - includes data for a HTTP POST, etc.
  45. * @param part the part going to open this URL - can be 0L if not created yet
  46. * @param window the mainwindow - passed to TDEIO::Job::setWindow()
  47. * @param removeReferrer if true, the "referrer" metadata from @p args isn't passed on
  48. * @param trustedSource if false, a warning will be shown before launching an executable
  49. * Always pass false for @p trustedSource, except for local directory views.
  50. */
  51. BrowserRun( const KURL& url, const KParts::URLArgs& args,
  52. KParts::ReadOnlyPart *part, TQWidget *window,
  53. bool removeReferrer, bool trustedSource );
  54. // BIC: merge with above constructor
  55. /**
  56. * @param url the URL we're probing
  57. * @param args URL args - includes data for a HTTP POST, etc.
  58. * @param part the part going to open this URL - can be 0L if not created yet
  59. * @param window the mainwindow - passed to TDEIO::Job::setWindow()
  60. * @param removeReferrer if true, the "referrer" metadata from @p args isn't passed on
  61. * @param trustedSource if false, a warning will be shown before launching an executable.
  62. * Always pass false for @p trustedSource, except for local directory views.
  63. * @param hideErrorDialog if true, no dialog will be shown in case of errors.
  64. *
  65. */
  66. BrowserRun( const KURL& url, const KParts::URLArgs& args,
  67. KParts::ReadOnlyPart *part, TQWidget *window,
  68. bool removeReferrer, bool trustedSource, bool hideErrorDialog );
  69. virtual ~BrowserRun();
  70. //KParts::URLArgs urlArgs() const { return m_args; }
  71. //KParts::ReadOnlyPart* part() const { return m_part; }
  72. /**
  73. * @return the URL we're probing
  74. */
  75. KURL url() const { return m_strURL; }
  76. /**
  77. * @return true if no dialog will be shown in case of errors
  78. */
  79. bool hideErrorDialog() const;
  80. /**
  81. * @return Suggested filename given by the server (e.g. HTTP content-disposition filename)
  82. */
  83. TQString suggestedFilename() const { return m_suggestedFilename; }
  84. /**
  85. * @return Suggested disposition by the server (e.g. HTTP content-disposition)
  86. * @since 3.5.2
  87. */
  88. TQString contentDisposition() const;
  89. bool serverSuggestsSave() const { return contentDisposition() == TQString::fromLatin1("attachment"); }
  90. enum AskSaveResult { Save, Open, Cancel };
  91. /**
  92. * Ask the user whether to save or open a url in another application.
  93. * @param url the URL in question
  94. * @param offer the application that will be used to open the URL
  95. * @param mimeType the mimetype of the URL
  96. * @param suggestedFilename optional filename suggested by the server
  97. * @return Save, Open or Cancel.
  98. */
  99. static AskSaveResult askSave( const KURL & url, KService::Ptr offer, const TQString& mimeType, const TQString & suggestedFilename = TQString::null );
  100. enum AskEmbedOrSaveFlags { InlineDisposition = 0, AttachmentDisposition = 1 };
  101. /**
  102. * Similar to askSave() but for the case where the current application is
  103. * able to embed the url itself (instead of passing it to another app).
  104. * @param url the URL in question
  105. * @param mimeType the mimetype of the URL
  106. * @param suggestedFilename optional filename suggested by the server
  107. * @param flags set to AttachmentDisposition if suggested by the server
  108. * @return Save, Open or Cancel.
  109. */
  110. static AskSaveResult askEmbedOrSave( const KURL & url, const TQString& mimeType, const TQString & suggestedFilename = TQString::null, int flags = 0 );
  111. // virtual so that TDEHTML can implement differently (HTML cache)
  112. virtual void save( const KURL & url, const TQString & suggestedFilename );
  113. // static so that it can be called from other classes
  114. static void simpleSave( const KURL & url, const TQString & suggestedFilename,
  115. TQWidget* window );
  116. /** BIC: Combine with the above function for KDE 4.0. */
  117. static void simpleSave( const KURL & url, const TQString & suggestedFilename );
  118. static bool allowExecution( const TQString &serviceType, const KURL &url );
  119. /** BIC: Obsoleted by KRun::isExecutable( const TQString &serviceType ); */
  120. static bool isExecutable( const TQString &serviceType );
  121. static bool isTextExecutable( const TQString &serviceType );
  122. protected:
  123. /**
  124. * Reimplemented from KRun
  125. */
  126. virtual void scanFile();
  127. /**
  128. * Reimplemented from KRun
  129. */
  130. virtual void init();
  131. /**
  132. * Called when an error happens.
  133. * NOTE: @p job could be 0L, if you passed hideErrorDialog=true.
  134. * The default implementation shows a message box, but only when job != 0 ....
  135. * It is strongly recommended to reimplement this method if
  136. * you passed hideErrorDialog=true.
  137. */
  138. virtual void handleError( TDEIO::Job * job );
  139. /**
  140. * NotHandled means that foundMimeType should call KRun::foundMimeType,
  141. * i.e. launch an external app.
  142. */
  143. enum NonEmbeddableResult { Handled, NotHandled, Delayed };
  144. /**
  145. * Helper for foundMimeType: call this if the mimetype couldn't be embedded
  146. */
  147. NonEmbeddableResult handleNonEmbeddable( const TQString& mimeType );
  148. protected slots:
  149. void slotBrowserScanFinished(TDEIO::Job *job);
  150. void slotBrowserMimetype(TDEIO::Job *job, const TQString &type);
  151. void slotCopyToTempFileResult(TDEIO::Job *job);
  152. virtual void slotStatResult( TDEIO::Job *job );
  153. protected:
  154. KParts::URLArgs m_args;
  155. KParts::ReadOnlyPart *m_part; // QGuardedPtr?
  156. TQGuardedPtr<TQWidget> m_window;
  157. // Suggested filename given by the server (e.g. HTTP content-disposition)
  158. // When set, we should really be saving instead of embedding
  159. TQString m_suggestedFilename;
  160. TQString m_sMimeType;
  161. bool m_bRemoveReferrer;
  162. bool m_bTrustedSource;
  163. private:
  164. void redirectToError( int error, const TQString& errorText );
  165. class BrowserRunPrivate;
  166. BrowserRunPrivate* d;
  167. };
  168. }
  169. #endif