File indexing completed on 2024-04-28 15:29:19
0001 /* 0002 SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef BROWSEROPENORSAVEQUESTION_H 0008 #define BROWSEROPENORSAVEQUESTION_H 0009 0010 #include <kparts/browserrun.h> 0011 #include <kparts/kparts_export.h> 0012 0013 #include <KService> 0014 #include <memory> 0015 0016 namespace KParts 0017 { 0018 class BrowserOpenOrSaveQuestionPrivate; 0019 0020 /** 0021 * @class BrowserOpenOrSaveQuestion browseropenorsavequestion.h <KParts/BrowserOpenOrSaveQuestion> 0022 * 0023 * @short This class shows the dialog that asks the user whether to 0024 * save a url or open a url in another application. 0025 * 0026 * It also has the variant which asks "save or embed" (e.g. into konqueror). 0027 * 0028 * @since 4.4 0029 */ 0030 class KPARTS_EXPORT BrowserOpenOrSaveQuestion 0031 { 0032 public: 0033 /** 0034 * Constructor, for all kinds of dialogs shown in this class. 0035 * @param url the URL in question 0036 * @param mimeType the mimetype of the URL 0037 */ 0038 BrowserOpenOrSaveQuestion(QWidget *parent, const QUrl &url, const QString &mimeType); 0039 ~BrowserOpenOrSaveQuestion(); 0040 0041 /** 0042 * Sets the suggested filename, shown in the dialog. 0043 * @param suggestedFileName optional file name suggested by the server (HTTP Content-Disposition) 0044 */ 0045 void setSuggestedFileName(const QString &suggestedFileName); 0046 0047 /** 0048 * Set of features that should be enabled in this dialog. 0049 * This allows to add features before making all applications ready for those features 0050 * (e.g. applications need to read selectedService() otherwise the dialog should not 0051 * show the service selection button) 0052 * @see Features 0053 */ 0054 enum Feature { 0055 BasicFeatures = 0, /**< Only the basic save, open, embed, cancel button */ 0056 ServiceSelection = 1, /**< Shows "Open With..." with the associated applications for the mimetype */ 0057 }; 0058 /** 0059 * Stores a combination of #Feature values. 0060 */ 0061 Q_DECLARE_FLAGS(Features, Feature) 0062 0063 /** 0064 * Enables the given features in the dialog 0065 */ 0066 void setFeatures(Features features); 0067 0068 enum Result { Save, Open, Embed, Cancel }; 0069 0070 /** 0071 * Ask the user whether to save or open a url in another application. 0072 * @return Save, Open or Cancel. 0073 */ 0074 Result askOpenOrSave(); 0075 0076 /** 0077 * @since 5.65 0078 */ 0079 enum AskEmbedOrSaveFlags { 0080 InlineDisposition = 0, 0081 AttachmentDisposition = 1, 0082 }; 0083 0084 /** 0085 * Ask the user whether to save or open a url in another application. 0086 * @param flags set to AttachmentDisposition if suggested by the server 0087 * This is used because by default text/html files are opened embedded in browsers, not saved. 0088 * But if the server said "attachment", it means the user is download a file for saving it. 0089 * @return Save, Embed or Cancel. 0090 */ 0091 Result askEmbedOrSave(int flags = 0); 0092 0093 // TODO askOpenEmbedOrSave 0094 0095 /** 0096 * @return the service that was selected during askOpenOrSave, 0097 * if it returned Open. 0098 * In all other cases (no associated application, Save or Cancel 0099 * selected), this returns 0. 0100 * 0101 * Requires setFeatures(BrowserOpenOrSaveQuestion::ServiceSelection). 0102 */ 0103 KService::Ptr selectedService() const; 0104 0105 private: 0106 std::unique_ptr<BrowserOpenOrSaveQuestionPrivate> const d; 0107 Q_DISABLE_COPY(BrowserOpenOrSaveQuestion) 0108 }; 0109 0110 } 0111 0112 #endif /* BROWSEROPENORSAVEQUESTION_H */