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
00070         BrowserRun( const KURL& url, const KParts::URLArgs& args,
00071                     KParts::ReadOnlyPart *part, QWidget *window,
00072                     bool removeReferrer, bool trustedSource, bool hideErrorDialog );
00073 
00074         virtual ~BrowserRun();
00075 
00076         //KParts::URLArgs urlArgs() const { return m_args; }
00077         //KParts::ReadOnlyPart* part() const { return m_part; }
00078 
00082         KURL url() const { return m_strURL; }
00083 
00087         bool hideErrorDialog() const;
00088 
00092         QString suggestedFilename() const { return m_suggestedFilename; }
00093 
00098         QString contentDisposition() const;
00099 
00100         bool serverSuggestsSave() const { return contentDisposition() == QString::fromLatin1("attachment"); }
00101 
00102         enum AskSaveResult { Save, Open, Cancel };
00111         static AskSaveResult askSave( const KURL & url, KService::Ptr offer, const QString& mimeType, const QString & suggestedFilename = QString::null );
00112 
00113         enum AskEmbedOrSaveFlags { InlineDisposition = 0, AttachmentDisposition = 1 };
00123         static AskSaveResult askEmbedOrSave( const KURL & url, const QString& mimeType, const QString & suggestedFilename = QString::null, int flags = 0 );
00124 
00125         // virtual so that KHTML can implement differently (HTML cache)
00126         virtual void save( const KURL & url, const QString & suggestedFilename );
00127 
00128         // static so that it can be called from other classes
00129         static void simpleSave( const KURL & url, const QString & suggestedFilename,
00130                                 QWidget* window );
00131 
00133         static void simpleSave( const KURL & url, const QString & suggestedFilename );
00134 
00135         static bool allowExecution( const QString &serviceType, const KURL &url );
00136 
00138         static bool isExecutable( const QString &serviceType );
00139         static bool isTextExecutable( const QString &serviceType );
00140 
00141     protected:
00145         virtual void scanFile();
00149         virtual void init();
00157         virtual void handleError( KIO::Job * job );
00158 
00163         enum NonEmbeddableResult { Handled, NotHandled, Delayed };
00164 
00168         NonEmbeddableResult handleNonEmbeddable( const QString& mimeType );
00169 
00170     protected slots:
00171         void slotBrowserScanFinished(KIO::Job *job);
00172         void slotBrowserMimetype(KIO::Job *job, const QString &type);
00173         void slotCopyToTempFileResult(KIO::Job *job);
00174         virtual void slotStatResult( KIO::Job *job );
00175 
00176     protected:
00177         KParts::URLArgs m_args;
00178         KParts::ReadOnlyPart *m_part; // QGuardedPtr?
00179         QGuardedPtr<QWidget> m_window;
00180         // Suggested filename given by the server (e.g. HTTP content-disposition)
00181         // When set, we should really be saving instead of embedding
00182         QString m_suggestedFilename;
00183         QString m_sMimeType;
00184         bool m_bRemoveReferrer;
00185         bool m_bTrustedSource;
00186     private:
00187         void redirectToError( int error, const QString& errorText );
00188         class BrowserRunPrivate;
00189         BrowserRunPrivate* d;
00190 
00191     };
00192 }
00193 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys