You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-2.2-install.../src/mountpointdialog.cpp

160 lines
3.9 KiB

#include "mountpointdialog.h"
#include <QLabel>
#include <QComboBox>
#include <QCheckBox>
#include <QLineEdit>
#include <QBoxLayout>
#include <QPushButton>
#include <QRegExp>
#include <QRegExpValidator>
#include <QMessageBox>
#include <QDebug>
MountPointDialog::MountPointDialog ( QWidget* parent, MountPoint* mountPoint )
: QDialog(parent), m_MountPoint(mountPoint)
{
setupUi();
if (mountPoint != 0)
{
m_edDevice->setText( mountPoint->dev );
m_edMountPoint->setText( mountPoint->mountpoint );
m_chkboxFormat->setChecked(mountPoint->format);
QString fs = mountPoint->fs;
if ( !mountPoint->fs_new.isEmpty() )
fs = mountPoint->fs_new;
//
int fsIndx = m_cmbboxFS->findText( fs );
qDebug() << "FS: " << fs << " fsIndex: " << fsIndx;
if ( fsIndx >= 0)
m_cmbboxFS->setCurrentIndex( fsIndx );
if (m_cmbboxFS->currentText() == "swap" )
{
m_edMountPoint->setText("swap");
m_chkboxFormat->setChecked( true );
m_chkboxFormat->setEnabled( false );
}
if (m_edMountPoint->text() == "swap")
m_edMountPoint->setEnabled(false);
connect( m_butOk, SIGNAL(clicked(bool)), this, SLOT(preAccept()) );
}
connect( m_butCancel, SIGNAL(clicked(bool)), this, SLOT(reject()) );
connect( m_cmbboxFS, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeFS(QString)));
}
MountPointDialog::~MountPointDialog()
{
}
void MountPointDialog::setupUi()
{
QRegExp rxDir("/[0-9a-zA-Z_\\-/]{0,64}");
m_labDevice = new QLabel( tr("Device: ") );
m_edDevice = new QLineEdit;
m_edDevice->setReadOnly(true);
m_labMountPoint = new QLabel( tr("Mount point: ") );
m_edMountPoint = new QLineEdit;
m_edMountPoint->setValidator( new QRegExpValidator(rxDir, this) );
QGridLayout* gbox_0 = new QGridLayout;
gbox_0->setContentsMargins(0, 0, 0, 0);
gbox_0->addWidget(m_labDevice, 0, 0);
gbox_0->addWidget(m_edDevice, 0, 1);
gbox_0->addWidget(m_labMountPoint, 1, 0);
gbox_0->addWidget(m_edMountPoint, 1, 1);
m_chkboxFormat = new QCheckBox( tr("Format partition") );
m_widgetFS = new QWidget;
m_labFS = new QLabel( tr("File system: ") );
m_cmbboxFS = new QComboBox;
m_cmbboxFS->addItem( "ext2" );
m_cmbboxFS->addItem( "ext3" );
m_cmbboxFS->addItem( "ext4" );
m_cmbboxFS->addItem( "jfs" );
m_cmbboxFS->addItem( "reiserfs" );
m_cmbboxFS->addItem( "xfs" );
m_cmbboxFS->addItem( "swap" );
QHBoxLayout* hbox_format = new QHBoxLayout;
hbox_format->addWidget(m_labFS);
hbox_format->addWidget(m_cmbboxFS);
m_widgetFS->setLayout(hbox_format);
m_widgetFS->setVisible(false);
connect(m_chkboxFormat, SIGNAL(toggled(bool)), m_widgetFS, SLOT(setVisible(bool)) );
m_butOk = new QPushButton( tr("OK") );
m_butCancel = new QPushButton( tr("Cancel") );
QHBoxLayout* hbox_2 = new QHBoxLayout;
hbox_2->addStretch();
hbox_2->addWidget(m_butOk);
hbox_2->addWidget(m_butCancel);
QVBoxLayout* vbox_0 = new QVBoxLayout;
vbox_0->addLayout(gbox_0);
vbox_0->addWidget(m_chkboxFormat);
vbox_0->addWidget(m_widgetFS);
vbox_0->addStretch();
vbox_0->addLayout(hbox_2);
setLayout( vbox_0 );
}
void MountPointDialog::preAccept()
{
if ( m_edMountPoint->text().isEmpty() )
{
qDebug() << "Reset mount point";
// reset mount point
m_MountPoint->mountpoint = "";
m_MountPoint->format = false;
m_MountPoint->fs_new = "";
}
else
{
qDebug() << "Store mount point";
m_MountPoint->mountpoint = m_edMountPoint->text();
m_MountPoint->format = m_chkboxFormat->isChecked();
if (m_MountPoint->format)
m_MountPoint->fs_new = m_cmbboxFS->currentText();
else
m_MountPoint->fs_new = "";
}
accept();
}
void MountPointDialog::changeFS( QString fs )
{
static QString oldMountPoint = "";
if (fs == "swap")
{
oldMountPoint = m_edMountPoint->text();
m_edMountPoint->setText("swap");
m_edMountPoint->setEnabled(false);
} else {
m_chkboxFormat->setEnabled(true);
m_edMountPoint->setEnabled(true);
if ( m_edMountPoint->text() == "swap" )
{
m_edMountPoint->setText(oldMountPoint);
oldMountPoint.clear();
}
}
}