File indexing completed on 2024-06-23 05:14:18

0001 /*  utils/overwritedialog.h
0002 
0003     This file is part of Kleopatra, the KDE keymanager
0004     SPDX-FileCopyrightText: 2023 g10 Code GmbH
0005     SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include <QDialog>
0012 
0013 #include <memory>
0014 
0015 namespace Kleo
0016 {
0017 
0018 /**
0019  * @class Kleo::OverwriteDialog overwritedialog.h <overwritedialog.h>
0020  *
0021  * This dialog can be shown when you realize that a file you want to write
0022  * already exists and you want to offer the user the choice to either Rename,
0023  * Overwrite, or Skip.
0024  */
0025 class OverwriteDialog : public QDialog
0026 {
0027     Q_OBJECT
0028 public:
0029     /**
0030      * @see Options
0031      */
0032     enum Option {
0033         AllowRename = 1, ///< Allow the user to enter a different file name.
0034         AllowSkip = 2, ///< Offer a "Skip" button, to skip other files too. Requires MultipleItems.
0035         MultipleItems =
0036             4, ///< Set if the current operation concerns multiple files, so it makes sense to offer buttons that apply the user's choice to all files/folders.
0037     };
0038     /**
0039      * Stores a combination of #Option values.
0040      */
0041     Q_DECLARE_FLAGS(Options, Option)
0042 
0043     enum Result {
0044         Cancel = 0, // = QDialog::Rejected
0045         Overwrite = 1,
0046         OverwriteAll = 2,
0047         Rename = 3,
0048         AutoRename = 4,
0049         Skip = 5,
0050         AutoSkip = 6,
0051     };
0052 
0053     /**
0054      * Construct an "overwrite" dialog to let the user know that the file @p fileName is about to be overwritten.
0055      *
0056      * @param parent parent widget
0057      * @param title the title for the dialog
0058      * @param fileName the path of the file that already exists
0059      * @param options parameters for the dialog (which buttons to show...),
0060      */
0061     OverwriteDialog(QWidget *parent, const QString &title, const QString &fileName, Options options);
0062 
0063     ~OverwriteDialog() override;
0064 
0065     /**
0066      * Returns the new file name to use if the user selected the Rename option.
0067      * Otherwise, returns an empty string.
0068      *
0069      * @return the new file name or an empty string
0070      */
0071     QString newFileName() const;
0072 
0073 private:
0074     class Private;
0075     std::unique_ptr<Private> const d;
0076 };
0077 
0078 Q_DECLARE_OPERATORS_FOR_FLAGS(OverwriteDialog::Options)
0079 
0080 }