File indexing completed on 2024-04-28 05:46:35

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2014-2017 Andrius Štikonas <andrius@stikonas.eu>
0004 
0005     SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 
0008 #if !defined(PARTPROPSDIALOG_H)
0009 
0010 #define PARTPROPSDIALOG_H
0011 
0012 #include <fs/filesystem.h>
0013 
0014 #include <core/partition.h>
0015 #include <core/partitiontable.h>
0016 
0017 #include <QDialog>
0018 
0019 class Device;
0020 class PartPropsWidget;
0021 
0022 class QDialogButtonBox;
0023 class QVBoxLayout;
0024 class QWidget;
0025 class QString;
0026 
0027 
0028 /** Show Partition properties.
0029 
0030     Dialog that shows a Partition's properties and allows the user to change (or recreate)
0031     the Partition's FileSystem, its label and its flags.
0032 
0033     @author Volker Lanz <vl@fidra.de>
0034 */
0035 class PartPropsDialog : public QDialog
0036 {
0037     Q_DISABLE_COPY(PartPropsDialog)
0038 
0039 public:
0040     PartPropsDialog(QWidget* parent, Device& d, Partition& p);
0041     ~PartPropsDialog();
0042 
0043 public:
0044     QString newLabel() const;
0045     PartitionTable::Flags newFlags() const;
0046     FileSystem::Type newFileSystemType() const;
0047     bool forceRecreate() const {
0048         return m_ForceRecreate;    /**< @return true if user wants to recreate the FileSystem on the Partition */
0049     }
0050 
0051 protected:
0052     void setupDialog();
0053     void setupConnections();
0054     void setupFileSystemComboBox();
0055     void setupFlagsList();
0056     void updateHideAndShow();
0057 
0058     bool warnFileSystemChange() const {
0059         return m_WarnFileSystemChange;
0060     }
0061     void setWarnFileSystemChange() {
0062         m_WarnFileSystemChange = true;
0063     }
0064 
0065     Device& device() {
0066         return m_Device;
0067     }
0068     const Device& device() const {
0069         return m_Device;
0070     }
0071 
0072     Partition& partition() {
0073         return m_Partition;
0074     }
0075     const Partition& partition() const {
0076         return m_Partition;
0077     }
0078 
0079     PartPropsWidget& dialogWidget() {
0080         Q_ASSERT(m_DialogWidget);
0081         return *m_DialogWidget;
0082     }
0083     const PartPropsWidget& dialogWidget() const {
0084         Q_ASSERT(m_DialogWidget);
0085         return *m_DialogWidget;
0086     }
0087 
0088     bool isReadOnly() const {
0089         return m_ReadOnly;
0090     }
0091     void setForceRecreate(bool b) {
0092         m_ForceRecreate = b;
0093     }
0094 
0095     void updatePartitionFileSystem();
0096 
0097 protected:
0098     void setDirty(void *unused = nullptr);
0099     void onFilesystemChanged(int idx);
0100     void onRecreate(int);
0101 
0102 private:
0103     // m_Device and m_Partition cannot be const because the PartResizerWidget takes
0104     // both as nonconst even in read only mode (which is a bad design flaw and should be
0105     // fixed by splitting it in a PartDisplayWidget that is read-only and a PartResizerWidget
0106     // subclassed from that, maybe)
0107     Device& m_Device;
0108     // m_Partition is also not a reference because we want to be able to change it and
0109     // forget the changes if the user cancels the dialog
0110     Partition m_Partition;
0111     bool m_WarnFileSystemChange;
0112     PartPropsWidget* m_DialogWidget;
0113     bool m_ReadOnly;
0114     bool m_ForceRecreate;
0115 
0116     QDialogButtonBox* dialogButtonBox;
0117     QPushButton* okButton;
0118     QPushButton* cancelButton;
0119     QVBoxLayout *mainLayout;
0120 };
0121 
0122 #endif