2020-09-16 00:35:12 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2010 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2020 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2010-02-17 13:18:25 +00:00
|
|
|
|
|
|
|
#include "gui/devicepropsdialog.h"
|
|
|
|
#include "gui/devicepropswidget.h"
|
|
|
|
|
2010-03-27 13:47:32 +00:00
|
|
|
#include "gui/smartdialog.h"
|
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <core/device.h>
|
2016-06-10 19:04:05 +01:00
|
|
|
#include <core/diskdevice.h>
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <core/partitiontable.h>
|
|
|
|
#include <core/smartstatus.h>
|
2010-02-17 13:18:25 +00:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <util/capacity.h>
|
|
|
|
#include <util/helpers.h>
|
2010-02-17 13:18:25 +00:00
|
|
|
|
2014-05-17 03:06:58 +01:00
|
|
|
#include <KConfigGroup>
|
2016-08-23 16:40:16 +01:00
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KSharedConfig>
|
2010-03-27 13:47:32 +00:00
|
|
|
|
2014-05-17 03:06:58 +01:00
|
|
|
#include <QDialogButtonBox>
|
2010-03-27 13:47:32 +00:00
|
|
|
#include <QPointer>
|
2014-05-17 03:06:58 +01:00
|
|
|
#include <QPushButton>
|
2020-09-29 22:15:28 +01:00
|
|
|
#include <QStyle>
|
2010-02-17 13:18:25 +00:00
|
|
|
|
|
|
|
/** Creates a new DevicePropsDialog
|
2015-07-13 15:17:41 +01:00
|
|
|
@param parent pointer to the parent widget
|
|
|
|
@param d the Device to show properties for
|
2010-02-17 13:18:25 +00:00
|
|
|
*/
|
|
|
|
DevicePropsDialog::DevicePropsDialog(QWidget* parent, Device& d) :
|
2015-07-13 15:17:41 +01:00
|
|
|
QDialog(parent),
|
|
|
|
m_Device(d),
|
|
|
|
m_DialogWidget(new DevicePropsWidget(this))
|
2010-02-17 13:18:25 +00:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
mainLayout = new QVBoxLayout(this);
|
|
|
|
setLayout(mainLayout);
|
|
|
|
mainLayout->addWidget(&dialogWidget());
|
|
|
|
setWindowTitle(xi18nc("@title:window", "Device Properties: <filename>%1</filename>", device().deviceNode()));
|
2010-02-17 13:18:25 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
setupDialog();
|
|
|
|
setupConnections();
|
2010-02-17 13:18:25 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
KConfigGroup kcg(KSharedConfig::openConfig(), "devicePropsDialog");
|
|
|
|
restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray()));
|
2014-05-17 03:06:58 +01:00
|
|
|
|
2010-02-17 13:18:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Destroys a DevicePropsDialog */
|
|
|
|
DevicePropsDialog::~DevicePropsDialog()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
KConfigGroup kcg(KSharedConfig::openConfig(), "devicePropsDialog");
|
|
|
|
kcg.writeEntry("Geometry", saveGeometry());
|
2010-02-17 13:18:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DevicePropsDialog::setupDialog()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
dialogButtonBox = new QDialogButtonBox;
|
|
|
|
okButton = dialogButtonBox->addButton(QDialogButtonBox::Ok);
|
|
|
|
cancelButton = dialogButtonBox->addButton(QDialogButtonBox::Cancel);
|
|
|
|
mainLayout->addWidget(dialogButtonBox);
|
|
|
|
okButton->setEnabled(false);
|
|
|
|
cancelButton->setFocus();
|
|
|
|
cancelButton->setDefault(true);
|
2016-05-18 22:23:59 +01:00
|
|
|
connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &DevicePropsDialog::accept);
|
|
|
|
connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &DevicePropsDialog::reject);
|
2015-07-13 15:17:41 +01:00
|
|
|
|
|
|
|
QString type = QStringLiteral("---");
|
|
|
|
QString maxPrimaries = QStringLiteral("---");
|
|
|
|
|
2016-04-14 19:18:36 +01:00
|
|
|
if (device().partitionTable() != nullptr) {
|
2015-07-13 15:17:41 +01:00
|
|
|
type = (device().partitionTable()->isReadOnly())
|
2016-07-18 02:21:14 +01:00
|
|
|
? xi18nc("@label device", "%1 (read only)", device().partitionTable()->typeName())
|
2015-07-13 15:17:41 +01:00
|
|
|
: device().partitionTable()->typeName();
|
|
|
|
maxPrimaries = QStringLiteral("%1/%2").arg(device().partitionTable()->numPrimaries()).arg(device().partitionTable()->maxPrimaries());
|
|
|
|
|
|
|
|
dialogWidget().partTableWidget().setReadOnly(true);
|
|
|
|
dialogWidget().partTableWidget().setPartitionTable(device().partitionTable());
|
|
|
|
|
|
|
|
if (device().partitionTable()->type() == PartitionTable::msdos)
|
|
|
|
dialogWidget().radioCylinderBased().setChecked(true);
|
|
|
|
else if (device().partitionTable()->type() == PartitionTable::msdos_sectorbased)
|
|
|
|
dialogWidget().radioSectorBased().setChecked(true);
|
|
|
|
else
|
|
|
|
dialogWidget().hideTypeRadioButtons();
|
|
|
|
} else {
|
|
|
|
dialogWidget().partTableWidget().setVisible(false);
|
|
|
|
dialogWidget().hideTypeRadioButtons();
|
|
|
|
}
|
|
|
|
|
2016-06-29 10:14:54 +01:00
|
|
|
dialogWidget().type().setText(type);
|
2015-07-13 15:17:41 +01:00
|
|
|
dialogWidget().capacity().setText(Capacity::formatByteSize(device().capacity()));
|
2016-06-29 10:14:54 +01:00
|
|
|
dialogWidget().totalSectors().setText(QLocale().toString(device().totalLogical()));
|
2015-07-13 15:17:41 +01:00
|
|
|
|
2018-04-09 02:58:03 +01:00
|
|
|
if (device().type() == Device::Type::Disk_Device) {
|
2015-07-13 15:17:41 +01:00
|
|
|
|
2016-06-10 19:04:05 +01:00
|
|
|
const DiskDevice& disk = dynamic_cast<const DiskDevice&>(device());
|
2015-07-13 15:17:41 +01:00
|
|
|
|
2016-06-10 19:04:05 +01:00
|
|
|
dialogWidget().primariesMax().setText(maxPrimaries);
|
|
|
|
dialogWidget().logicalSectorSize().setText(Capacity::formatByteSize(disk.logicalSectorSize()));
|
|
|
|
dialogWidget().physicalSectorSize().setText(Capacity::formatByteSize(disk.physicalSectorSize()));
|
2016-08-07 22:51:27 +01:00
|
|
|
if (device().smartStatus().isValid()) {
|
|
|
|
if (device().smartStatus().status()) {
|
|
|
|
dialogWidget().smartStatusText().setText(xi18nc("@label SMART disk status", "good"));
|
2020-09-29 22:15:28 +01:00
|
|
|
dialogWidget().smartStatusIcon().setPixmap(QIcon::fromTheme(QStringLiteral("dialog-ok"))
|
|
|
|
.pixmap(QApplication::style()->pixelMetric(QStyle::PixelMetric::PM_SmallIconSize)));
|
2020-09-29 17:54:53 +01:00
|
|
|
|
2016-08-07 22:51:27 +01:00
|
|
|
} else {
|
|
|
|
dialogWidget().smartStatusText().setText(xi18nc("@label SMART disk status", "BAD"));
|
2020-09-29 22:15:28 +01:00
|
|
|
dialogWidget().smartStatusIcon().setPixmap(QIcon::fromTheme(QStringLiteral("dialog-warning"))
|
|
|
|
.pixmap(QApplication::style()->pixelMetric(QStyle::PixelMetric::PM_SmallIconSize)));
|
2016-08-07 22:51:27 +01:00
|
|
|
}
|
2015-07-13 15:17:41 +01:00
|
|
|
} else {
|
2016-08-07 22:51:27 +01:00
|
|
|
dialogWidget().smartStatusText().setText(xi18nc("@label", "(unknown)"));
|
|
|
|
dialogWidget().smartStatusIcon().setVisible(false);
|
|
|
|
dialogWidget().buttonSmartMore().setVisible(false);
|
2015-07-13 15:17:41 +01:00
|
|
|
}
|
|
|
|
} else {
|
2018-04-09 02:58:03 +01:00
|
|
|
if (device().type() == Device::Type::LVM_Device)
|
2016-08-23 16:06:37 +01:00
|
|
|
dialogWidget().type().setText(xi18nc("@label device", "LVM Volume Group"));
|
2018-07-11 16:23:10 +01:00
|
|
|
else if (device().type() == Device::Type::SoftwareRAID_Device)
|
|
|
|
dialogWidget().type().setText(xi18nc("@label device", "Software RAID Device"));
|
2016-08-23 16:06:37 +01:00
|
|
|
else
|
|
|
|
dialogWidget().type().setText(xi18nc("@label device", "Volume Manager Device"));
|
2016-08-07 22:51:27 +01:00
|
|
|
//TODO: add Volume Manger Device info
|
|
|
|
dialogWidget().smartStatusText().setVisible(false);
|
2015-07-13 15:17:41 +01:00
|
|
|
dialogWidget().smartStatusIcon().setVisible(false);
|
|
|
|
dialogWidget().buttonSmartMore().setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
setMinimumSize(dialogWidget().size());
|
|
|
|
resize(dialogWidget().size());
|
2010-02-17 13:18:25 +00:00
|
|
|
}
|
2010-02-24 10:47:22 +00:00
|
|
|
|
|
|
|
void DevicePropsDialog::setupConnections()
|
|
|
|
{
|
2016-05-22 20:03:49 +01:00
|
|
|
connect(&dialogWidget().radioSectorBased(), &QRadioButton::toggled, this, &DevicePropsDialog::setDirty);
|
|
|
|
connect(&dialogWidget().radioCylinderBased(), &QRadioButton::toggled, this, &DevicePropsDialog::setDirty);
|
|
|
|
connect(&dialogWidget().buttonSmartMore(), &QPushButton::clicked, this, &DevicePropsDialog::onButtonSmartMore);
|
2010-02-24 10:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DevicePropsDialog::setDirty(bool)
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
okButton->setEnabled(true);
|
|
|
|
okButton->setDefault(true);
|
2010-02-24 10:47:22 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 12:00:07 +00:00
|
|
|
bool DevicePropsDialog::cylinderBasedAlignment() const
|
2010-02-24 10:47:22 +00:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
return dialogWidget().radioCylinderBased().isChecked();
|
2010-02-24 10:47:22 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 12:00:07 +00:00
|
|
|
bool DevicePropsDialog::sectorBasedAlignment() const
|
2010-02-24 10:47:22 +00:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
return dialogWidget().radioSectorBased().isChecked();
|
2010-02-24 10:47:22 +00:00
|
|
|
}
|
2010-03-27 13:47:32 +00:00
|
|
|
|
|
|
|
void DevicePropsDialog::onButtonSmartMore(bool)
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
QPointer<SmartDialog> dlg = new SmartDialog(this, device());
|
|
|
|
dlg->exec();
|
|
|
|
delete dlg;
|
2010-03-27 13:47:32 +00:00
|
|
|
}
|