browserrun.h
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2002 David Faure <faure@kde.org> 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License version 2, as published by the Free Software Foundation. 00007 * 00008 * This library is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Library General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Library General Public License 00014 * along with this library; see the file COPYING.LIB. If not, write to 00015 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 * Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef kparts_browserrun_h 00020 #define kparts_browserrun_h 00021 00022 #include <krun.h> 00023 #include <kservice.h> 00024 #include <kparts/browserextension.h> 00025 00026 namespace KParts { 00027 00042 class KPARTS_EXPORT BrowserRun : public KRun 00043 { 00044 Q_OBJECT 00045 public: 00055 BrowserRun( const KURL& url, const KParts::URLArgs& args, 00056 KParts::ReadOnlyPart *part, QWidget *window, 00057 bool removeReferrer, bool trustedSource ); 00058 00059 // BIC: merge with above constructor 00071 BrowserRun( const KURL& url, const KParts::URLArgs& args, 00072 KParts::ReadOnlyPart *part, QWidget *window, 00073 bool removeReferrer, bool trustedSource, bool hideErrorDialog ); 00074 00075 virtual ~BrowserRun(); 00076 00077 //KParts::URLArgs urlArgs() const { return m_args; } 00078 //KParts::ReadOnlyPart* part() const { return m_part; } 00079 00083 KURL url() const { return m_strURL; } 00084 00088 bool hideErrorDialog() const; 00089 00093 QString suggestedFilename() const { return m_suggestedFilename; } 00094 00099 QString contentDisposition() const; 00100 00101 bool serverSuggestsSave() const { return contentDisposition() == QString::fromLatin1("attachment"); } 00102 00103 enum AskSaveResult { Save, Open, Cancel }; 00112 static AskSaveResult askSave( const KURL & url, KService::Ptr offer, const QString& mimeType, const QString & suggestedFilename = QString::null ); 00113 00114 enum AskEmbedOrSaveFlags { InlineDisposition = 0, AttachmentDisposition = 1 }; 00124 static AskSaveResult askEmbedOrSave( const KURL & url, const QString& mimeType, const QString & suggestedFilename = QString::null, int flags = 0 ); 00125 00126 // virtual so that KHTML can implement differently (HTML cache) 00127 virtual void save( const KURL & url, const QString & suggestedFilename ); 00128 00129 // static so that it can be called from other classes 00130 static void simpleSave( const KURL & url, const QString & suggestedFilename, 00131 QWidget* window ); 00132 00134 static void simpleSave( const KURL & url, const QString & suggestedFilename ); 00135 00136 static bool allowExecution( const QString &serviceType, const KURL &url ); 00137 00139 static bool isExecutable( const QString &serviceType ); 00140 static bool isTextExecutable( const QString &serviceType ); 00141 00142 protected: 00146 virtual void scanFile(); 00150 virtual void init(); 00158 virtual void handleError( KIO::Job * job ); 00159 00164 enum NonEmbeddableResult { Handled, NotHandled, Delayed }; 00165 00169 NonEmbeddableResult handleNonEmbeddable( const QString& mimeType ); 00170 00171 protected slots: 00172 void slotBrowserScanFinished(KIO::Job *job); 00173 void slotBrowserMimetype(KIO::Job *job, const QString &type); 00174 void slotCopyToTempFileResult(KIO::Job *job); 00175 virtual void slotStatResult( KIO::Job *job ); 00176 00177 protected: 00178 KParts::URLArgs m_args; 00179 KParts::ReadOnlyPart *m_part; // QGuardedPtr? 00180 QGuardedPtr<QWidget> m_window; 00181 // Suggested filename given by the server (e.g. HTTP content-disposition) 00182 // When set, we should really be saving instead of embedding 00183 QString m_suggestedFilename; 00184 QString m_sMimeType; 00185 bool m_bRemoveReferrer; 00186 bool m_bTrustedSource; 00187 private: 00188 void redirectToError( int error, const QString& errorText ); 00189 class BrowserRunPrivate; 00190 BrowserRunPrivate* d; 00191 00192 }; 00193 } 00194 #endif