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

0001 /*
0002     SPDX-FileCopyrightText: 2008-2012 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2014-2019 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
0005     SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-3.0-or-later
0008 */
0009 
0010 #if !defined(MAINWINDOW_H)
0011 
0012 #define MAINWINDOW_H
0013 
0014 #include <core/operationrunner.h>
0015 #include <core/operationstack.h>
0016 #include <core/devicescanner.h>
0017 
0018 #include "ui_mainwindowbase.h"
0019 
0020 #include <KMessageWidget>
0021 #include <KXmlGuiWindow>
0022 
0023 class ApplyProgressDialog;
0024 class ScanProgressDialog;
0025 class Device;
0026 class Partition;
0027 class InfoPane;
0028 
0029 class KActionCollection;
0030 
0031 class QWidget;
0032 class QLabel;
0033 class QCloseEvent;
0034 class QEvent;
0035 
0036 /** The application's main window.
0037 
0038     @author Volker Lanz <vl@fidra.de>
0039 */
0040 class MainWindow : public KXmlGuiWindow, public Ui::MainWindowBase
0041 {
0042     Q_OBJECT
0043     Q_DISABLE_COPY(MainWindow)
0044 
0045 public:
0046     explicit MainWindow(QWidget* parent = nullptr);
0047 
0048     // for instance `/dev/sda`
0049     void setCurrentDeviceByName(const QString& name);
0050 
0051     void setCurrentPartitionByName(const QString& partitionNumber);
0052 
0053     // forbids the user to select another device.
0054     // this is used in conjunction with --device
0055     // rationale is that if the user specifies a device,
0056     // we can't allow him to select another one by mistake while
0057     // clicking in the UI.
0058     void setDisallowOtherDevices();
0059 
0060     // disallowOtherDevices hides the DockWidget, but unfortunately
0061     // this is saved by the Window State when restored, even if we
0062     // are not disallowing it this time. At the same time the user
0063     // could have hidden it, so we need to restore only if hidden
0064     // just by the call to disallowOtherDevices().
0065     void showDevicePanelIfPreviouslyHiddenByDisallowOtherDevices();
0066 
0067 Q_SIGNALS:
0068     void settingsChanged();
0069     void scanFinished();
0070 
0071 protected:
0072     void init();
0073     void setupObjectNames();
0074     void setupActions();
0075     void setupConnections();
0076     void setupStatusBar();
0077     void loadConfig();
0078     void saveConfig() const;
0079     void updateWindowTitle();
0080     void updateSeletedDeviceMenu();
0081     void checkFileSystemSupport();
0082 
0083     void enableActions();
0084 
0085     void closeEvent(QCloseEvent*) override;
0086     void changeEvent(QEvent* event) override;
0087 
0088     void setSavedSelectedDeviceNode(const QString& s) {
0089         m_SavedSelectedDeviceNode = s;
0090     }
0091     const QString& savedSelectedDeviceNode() const {
0092         return m_SavedSelectedDeviceNode;
0093     }
0094 
0095     InfoPane& infoPane() {
0096         Q_ASSERT(m_InfoPane);
0097         return *m_InfoPane;
0098     }
0099 
0100     PartitionManagerWidget& pmWidget() {
0101         Q_ASSERT(m_PartitionManagerWidget);
0102         return *m_PartitionManagerWidget;
0103     }
0104     const PartitionManagerWidget& pmWidget() const {
0105         Q_ASSERT(m_PartitionManagerWidget);
0106         return *m_PartitionManagerWidget;
0107     }
0108 
0109     ListDevices& listDevices() {
0110         Q_ASSERT(m_ListDevices);
0111         return *m_ListDevices;
0112     }
0113     const ListDevices& listDevices() const {
0114         Q_ASSERT(m_ListDevices);
0115         return *m_ListDevices;
0116     }
0117 
0118     ListOperations& listOperations() {
0119         Q_ASSERT(m_ListOperations);
0120         return *m_ListOperations;
0121     }
0122     const ListOperations& listOperations() const {
0123         Q_ASSERT(m_ListOperations);
0124         return *m_ListOperations;
0125     }
0126 
0127     TreeLog& treeLog() {
0128         Q_ASSERT(m_TreeLog);
0129         return *m_TreeLog;
0130     }
0131     const TreeLog& treeLog() const {
0132         Q_ASSERT(m_TreeLog);
0133         return *m_TreeLog;
0134     }
0135 
0136     QDockWidget& dockInformation() {
0137         Q_ASSERT(m_DockInformation);
0138         return *m_DockInformation;
0139     }
0140     const QDockWidget& dockInformation() const {
0141         Q_ASSERT(m_DockInformation);
0142         return *m_DockInformation;
0143     }
0144 
0145     QDockWidget& dockDevices() {
0146         Q_ASSERT(m_DockDevices);
0147         return *m_DockDevices;
0148     }
0149     const QDockWidget& dockDevices() const {
0150         Q_ASSERT(m_DockDevices);
0151         return *m_DockDevices;
0152     }
0153 
0154     QDockWidget& dockOperations() {
0155         Q_ASSERT(m_DockOperations);
0156         return *m_DockOperations;
0157     }
0158     const QDockWidget& dockOperations() const {
0159         Q_ASSERT(m_DockOperations);
0160         return *m_DockOperations;
0161     }
0162 
0163     QDockWidget& dockLog() {
0164         Q_ASSERT(m_DockLog);
0165         return *m_DockLog;
0166     }
0167     const QDockWidget& dockLog() const {
0168         Q_ASSERT(m_DockLog);
0169         return *m_DockLog;
0170     }
0171 
0172     QLabel& statusText() {
0173         Q_ASSERT(m_StatusText);
0174         return *m_StatusText;
0175     }
0176     const QLabel& statusText() const {
0177         Q_ASSERT(m_StatusText);
0178         return *m_StatusText;
0179     }
0180 
0181     OperationStack& operationStack() {
0182         Q_ASSERT(m_OperationStack);
0183         return *m_OperationStack;
0184     }
0185     const OperationStack& operationStack() const {
0186         Q_ASSERT(m_OperationStack);
0187         return *m_OperationStack;
0188     }
0189 
0190     OperationRunner& operationRunner() {
0191         Q_ASSERT(m_OperationRunner);
0192         return *m_OperationRunner;
0193     }
0194     const OperationRunner& operationRunner() const {
0195         Q_ASSERT(m_OperationRunner);
0196         return *m_OperationRunner;
0197     }
0198 
0199     DeviceScanner& deviceScanner() {
0200         Q_ASSERT(m_DeviceScanner);
0201         return *m_DeviceScanner;
0202     }
0203     const DeviceScanner& deviceScanner() const {
0204         Q_ASSERT(m_DeviceScanner);
0205         return *m_DeviceScanner;
0206     }
0207 
0208     ApplyProgressDialog& applyProgressDialog() {
0209         Q_ASSERT(m_ApplyProgressDialog);
0210         return *m_ApplyProgressDialog;
0211     }
0212     const ApplyProgressDialog& applyProgressDialog() const {
0213         Q_ASSERT(m_ApplyProgressDialog);
0214         return *m_ApplyProgressDialog;
0215     }
0216 
0217     ScanProgressDialog& scanProgressDialog() {
0218         Q_ASSERT(m_ScanProgressDialog);
0219         return *m_ScanProgressDialog;
0220     }
0221     const ScanProgressDialog& scanProgressDialog() const {
0222         Q_ASSERT(m_ScanProgressDialog);
0223         return *m_ScanProgressDialog;
0224     }
0225 
0226     KMessageWidget &MessageWidget() {
0227         Q_ASSERT(m_MessageWidget);
0228         return *m_MessageWidget;
0229     }
0230     const KMessageWidget &MessageWidget() const {
0231         Q_ASSERT(m_MessageWidget);
0232         return *m_MessageWidget;
0233     }
0234 
0235     void onSelectedDeviceMenuTriggered(bool);
0236 
0237 protected Q_SLOTS:
0238     void on_m_PartitionManagerWidget_selectedPartitionChanged(const Partition* p);
0239     void on_m_PartitionManagerWidget_contextMenuRequested(const QPoint& pos);
0240     void on_m_PartitionManagerWidget_deviceDoubleClicked(const Device*);
0241     void on_m_PartitionManagerWidget_partitionDoubleClicked(const Partition*);
0242 
0243     void on_m_DockInformation_dockLocationChanged(Qt::DockWidgetArea);
0244 
0245     void on_m_OperationStack_operationsChanged();
0246     void on_m_OperationStack_devicesChanged();
0247 
0248     void on_m_DeviceScanner_finished();
0249     void on_m_DeviceScanner_progress(const QString& device_node, int percent);
0250 
0251     void on_m_ApplyProgressDialog_finished();
0252 
0253     void listDevicesContextMenuRequested(const QPoint& pos);
0254     void on_m_ListDevices_selectionChanged(const QString& device_node);
0255 
0256     void treeLogContextMenuRequested(const QPoint& pos);
0257     void listOperationsContextMenuRequested(const QPoint& pos);
0258 
0259 protected:
0260     void scanDevices();
0261 
0262     void onRefreshDevices();
0263     void onCreateNewPartitionTable();
0264     void onCreateNewVolumeGroup();
0265     void onRemoveVolumeGroup();
0266     void onResizeVolumeGroup();
0267     void onDeactivateVolumeGroup();
0268     void onExportPartitionTable();
0269     void onImportPartitionTable();
0270 
0271     void onApplyAllOperations();
0272     void onUndoOperation();
0273     void onClearAllOperations();
0274 
0275     void onConfigureOptions();
0276     void onSettingsChanged();
0277 
0278     void onFileSystemSupport();
0279     void onShowAboutKPMcore();
0280 
0281     void onSmartStatusDevice();
0282     void onPropertiesDevice(const QString& deviceNode = {});
0283 
0284 private:
0285     QMenu* createPopupMenu() override;
0286 
0287     void askForPermissions();
0288 
0289 Q_SIGNALS:
0290     void showMessageWidget();
0291     void hideMessageWidget();
0292 
0293 private:
0294     OperationStack* m_OperationStack;
0295     OperationRunner* m_OperationRunner;
0296     DeviceScanner* m_DeviceScanner;
0297     ApplyProgressDialog* m_ApplyProgressDialog;
0298     ScanProgressDialog* m_ScanProgressDialog;
0299     QLabel* m_StatusText;
0300     QString m_SavedSelectedDeviceNode;
0301 
0302     bool m_permissionGranted;
0303 };
0304 
0305 #endif