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