1/*
2 Copyright (c) 2009 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2 of the License or ( at
7 your option ) version 3 or, at the discretion of KDE e.V. ( which shall
8 act as a proxy as in section 14 of the GPLv3 ), any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef BROWSEROPENORSAVEQUESTION_H
22#define BROWSEROPENORSAVEQUESTION_H
23
24#include "kparts_export.h"
25#include <kdialog.h>
26#include "browserrun.h"
27#include <kservice.h>
28
29namespace KParts {
30
31class BrowserOpenOrSaveQuestionPrivate;
32
33/**
34 * This class shows the dialog that asks the user whether to
35 * save a url or open a url in another application.
36 *
37 * It also has the variant which asks "save or embed" (e.g. into konqueror).
38 *
39 * @since 4.4
40 */
41class KPARTS_EXPORT BrowserOpenOrSaveQuestion
42{
43public:
44 /**
45 * Constructor, for all kinds of dialogs shown in this class.
46 * @param url the URL in question
47 * @param mimeType the mimetype of the URL
48 */
49 BrowserOpenOrSaveQuestion(QWidget* parent, const KUrl& url, const QString& mimeType);
50 ~BrowserOpenOrSaveQuestion();
51
52 /**
53 * Sets the suggested filename, shown in the dialog.
54 * @param suggestedFileName optional file name suggested by the server (HTTP Content-Disposition)
55 */
56 void setSuggestedFileName(const QString& suggestedFileName);
57
58 /**
59 * Set of features that should be enabled in this dialog.
60 * This allows to add features before making all applications ready for those features
61 * (e.g. applications need to read selectedService() otherwise the dialog should not
62 * show the service selection button)
63 */
64 enum Feature { BasicFeatures = 0, /**< Only the basic save, open, embed, cancel button */
65 ServiceSelection = 1 /**< Shows "Open With..." with the associated applications for the mimetype */
66 };
67 Q_DECLARE_FLAGS(Features, Feature)
68
69 /**
70 * Enables the given features in the dialog
71 */
72 void setFeatures(Features features);
73
74 enum Result { Save, Open, Embed, Cancel };
75
76 /**
77 * Ask the user whether to save or open a url in another application.
78 * @param parent parent widget for the dialog
79 * @return Save, Open or Cancel.
80 */
81 Result askOpenOrSave();
82
83 /**
84 * Ask the user whether to save or open a url in another application.
85 * @param parent parent widget for the dialog
86 * @param flags set to BrowserRun::AttachmentDisposition if suggested by the server
87 * This is used because by default text/html files are opened embedded in browsers, not saved.
88 * But if the server said "attachment", it means the user is download a file for saving it.
89 * @return Save, Embed or Cancel.
90 */
91 Result askEmbedOrSave(int flags = 0);
92 // KDE5 TODO: move BrowserRun::AskEmbedOrSaveFlags to this class.
93
94 // TODO askOpenEmbedOrSave
95
96 /**
97 * @return the service that was selected during askOpenOrSave,
98 * if it returned Open.
99 * In all other cases (no associated application, Save or Cancel
100 * selected), this returns 0.
101 *
102 * Requires setFeatures(BrowserOpenOrSaveQuestion::ServiceSelection).
103 */
104 KService::Ptr selectedService() const;
105
106private:
107 BrowserOpenOrSaveQuestionPrivate* const d;
108};
109
110}
111
112#endif /* BROWSEROPENORSAVEQUESTION_H */
113
114