diff --git a/src/gui/editmountpointdialog.cpp b/src/gui/editmountpointdialog.cpp index f80b112..02b4f36 100644 --- a/src/gui/editmountpointdialog.cpp +++ b/src/gui/editmountpointdialog.cpp @@ -1,89 +1,89 @@ /************************************************************************* * Copyright (C) 2009, 2010 by Volker Lanz * * Copyright (C) 2015 by Teo Mrnjavac * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "gui/editmountpointdialog.h" #include "gui/editmountpointdialogwidget.h" #include #include #include #include #include #include #include #include EditMountPointDialog::EditMountPointDialog(QWidget* parent, Partition& p) : QDialog(parent), m_Partition(p), m_DialogWidget(new EditMountPointDialogWidget(this, partition())) { QVBoxLayout *mainLayout = new QVBoxLayout(this); setLayout(mainLayout); mainLayout->addWidget(&widget()); setWindowTitle(xi18nc("@title:window", "Edit mount point for %1", p.deviceNode())); KConfigGroup kcg(KSharedConfig::openConfig(), "editMountPointDialog"); restoreGeometry(kcg.readEntry("Geometry", QByteArray())); QDialogButtonBox* dbb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this ); mainLayout->addWidget(dbb); connect(dbb, &QDialogButtonBox::accepted, this, [=] () {accept_(Edit);} ); connect(dbb, &QDialogButtonBox::rejected, this, &EditMountPointDialog::reject); connect(widget().m_ButtonRemove, &QPushButton::clicked, this, [=] () {accept_(Remove);} ); } /** Destroys an EditMountOptionsDialog instance */ EditMountPointDialog::~EditMountPointDialog() { KConfigGroup kcg(KSharedConfig::openConfig(), "editMountPointDialog"); kcg.writeEntry("Geometry", saveGeometry()); } void EditMountPointDialog::accept_(MountPointAction action) { if (KMessageBox::warningContinueCancel(this, xi18nc("@info", "Are you sure you want to save the changes you made to the system table file /etc/fstab?" "This will overwrite the existing file on your hard drive now. This can not be undone."), xi18nc("@title:window", "Really save changes?"), KGuiItem(xi18nc("@action:button", "Save changes"), QStringLiteral("arrow-right")), KStandardGuiItem::cancel(), QStringLiteral("reallyWriteMountPoints")) == KMessageBox::Cancel) return; if(action == Remove) widget().removeMountPoint(); else if (action == Edit) widget().acceptChanges(); if (writeMountpoints(widget().fstabEntries())) { if (action == Edit) - partition().setMountPoint(widget().editPath().text()); + partition().setMountPoint(widget().editPath().currentText()); } else KMessageBox::sorry(this, xi18nc("@info", "Could not save mount points to file /etc/fstab."), xi18nc("@title:window", "Error While Saving Mount Points")); QDialog::accept(); } diff --git a/src/gui/editmountpointdialogwidget.cpp b/src/gui/editmountpointdialogwidget.cpp index 624b599..8af681f 100644 --- a/src/gui/editmountpointdialogwidget.cpp +++ b/src/gui/editmountpointdialogwidget.cpp @@ -1,213 +1,234 @@ /************************************************************************* * Copyright (C) 2009, 2010 by Volker Lanz * * Copyright (C) 2016, 2017 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "gui/editmountpointdialogwidget.h" #include "gui/editmountoptionsdialog.h" #include #include #include #include #include #include #include #include #include #include EditMountPointDialogWidget::EditMountPointDialogWidget(QWidget* parent, Partition& p) : QWidget(parent), m_Partition(p) { m_fstabEntries = readFstabEntries(); setupUi(this); m_deviceNode = partition().deviceNode(); if (partition().roles().has(PartitionRole::Luks) && partition().fileSystem().type() != FileSystem::Luks) { const FS::luks* luksFs = dynamic_cast(&partition().fileSystem()); m_deviceNode = luksFs->mapperName(); } labelName().setText(m_deviceNode); labelType().setText(partition().fileSystem().name()); bool entryFound = false; + editPath().setEditable(true); for (auto &e : m_fstabEntries) { QString canonicalEntryPath = QFileInfo(e.deviceNode()).canonicalFilePath(); QString canonicalDevicePath = QFileInfo(m_deviceNode).canonicalFilePath(); if (canonicalEntryPath == canonicalDevicePath) { // FIXME fix multiple mountpoints entryFound = true; - entry = &e; + entry.append(&e); + mountPointList = possibleMountPoints(e.deviceNode()); } } if (!entryFound) { FileSystem::Type type = partition().fileSystem().type(); QString fsName; switch (type) { case FileSystem::LinuxSwap: fsName = QStringLiteral("swap"); break; case FileSystem::Fat16: case FileSystem::Fat32: fsName = QStringLiteral("vfat"); break; default: fsName = partition().fileSystem().name(); } m_fstabEntries.append(FstabEntry(m_deviceNode, QString(), fsName, QString())); - entry = &m_fstabEntries.last(); - } - - editPath().setText(entry->mountPoint()); - - spinDumpFreq().setValue(entry->dumpFreq()); - spinPassNumber().setValue(entry->passNumber()); - - switch (entry->entryType()) { - case FstabEntryType::uuid: - radioUUID().setChecked(true); - break; - - case FstabEntryType::label: - radioLabel().setChecked(true); - break; - - case FstabEntryType::partuuid: - radioUUID().setChecked(true); - break; - - case FstabEntryType::partlabel: - radioLabel().setChecked(true); - break; - - case FstabEntryType::deviceNode: - radioDeviceNode().setChecked(true); - break; - case FstabEntryType::comment: - break; + entry.append(&m_fstabEntries.last()); } + currentEntry = entry[0]; + editPath().addItems(mountPointList); + spinDumpFreq().setValue(currentEntry->dumpFreq()); + spinPassNumber().setValue(currentEntry->passNumber()); boxOptions()[QStringLiteral("ro")] = m_CheckReadOnly; boxOptions()[QStringLiteral("users")] = m_CheckUsers; boxOptions()[QStringLiteral("noauto")] = m_CheckNoAuto; boxOptions()[QStringLiteral("noatime")] = m_CheckNoAtime; boxOptions()[QStringLiteral("nodiratime")] = m_CheckNoDirAtime; boxOptions()[QStringLiteral("sync")] = m_CheckSync; boxOptions()[QStringLiteral("noexec")] = m_CheckNoExec; boxOptions()[QStringLiteral("relatime")] = m_CheckRelAtime; - setupOptions(entry->options()); - - if (partition().fileSystem().uuid().isEmpty()) { - radioUUID().setEnabled(false); - if (radioUUID().isChecked()) - radioDeviceNode().setChecked(true); - } - - if (partition().fileSystem().label().isEmpty()) { - radioLabel().setEnabled(false); - if (radioLabel().isChecked()) - radioDeviceNode().setChecked(true); - } + setupRadio(currentEntry->entryType()); + setupOptions(currentEntry->options()); connect(m_ButtonMore, &QPushButton::clicked, this, &EditMountPointDialogWidget::buttonMoreClicked); connect(m_ButtonSelect, &QPushButton::clicked, this, &EditMountPointDialogWidget::buttonSelectClicked); + connect(m_EditPath, QOverload::of(&QComboBox::currentIndexChanged), + [=](int index){ currentEntry = entry[index]; + spinDumpFreq().setValue(currentEntry->dumpFreq()); + spinPassNumber().setValue(currentEntry->passNumber()); + setupRadio(currentEntry->entryType()); + for (iterator_BoxOptions = boxOptions().begin(); iterator_BoxOptions != boxOptions().end(); ++iterator_BoxOptions){ + boxOptions()[iterator_BoxOptions->first]->setChecked(false); + } + setupOptions(currentEntry->options()); + }); } EditMountPointDialogWidget::~EditMountPointDialogWidget() { } void EditMountPointDialogWidget::setupOptions(const QStringList& options) { QStringList optTmpList; - for (const auto &o : options) { if (boxOptions().find(o) != boxOptions().end()) boxOptions()[o]->setChecked(true); else optTmpList.append(o); } m_Options = optTmpList.join(QLatin1Char(',')); } +void EditMountPointDialogWidget::setupRadio(const FstabEntryType entryType) +{ + if (partition().fileSystem().uuid().isEmpty()) { + radioUUID().setEnabled(false); + if (radioUUID().isChecked()) + radioDeviceNode().setChecked(true); + } + + if (partition().fileSystem().label().isEmpty()) { + radioLabel().setEnabled(false); + if (radioLabel().isChecked()) + radioDeviceNode().setChecked(true); + } + switch (entryType) { + case FstabEntryType::uuid: + radioUUID().setChecked(true); + break; + + case FstabEntryType::label: + radioLabel().setChecked(true); + break; + + case FstabEntryType::partuuid: + radioUUID().setChecked(true); + break; + + case FstabEntryType::partlabel: + radioLabel().setChecked(true); + break; + + case FstabEntryType::deviceNode: + radioDeviceNode().setChecked(true); + break; + case FstabEntryType::comment: + break; + } +} + void EditMountPointDialogWidget::buttonSelectClicked(bool) { - const QString s = QFileDialog::getExistingDirectory(this, editPath().text()); + const QString s = QFileDialog::getExistingDirectory(this, editPath().currentText()); if (!s.isEmpty()) - editPath().setText(s); + editPath().setCurrentText(s); } void EditMountPointDialogWidget::removeMountPoint() { int i=0; for (const auto &e : fstabEntries()) { - if((e.fsSpec().contains(partition().deviceNode()) && !partition().deviceNode().isEmpty() ) || (e.fsSpec().contains(partition().fileSystem().uuid()) && !partition().fileSystem().uuid().isEmpty()) || - (e.fsSpec().contains(partition().fileSystem().label()) && !partition().fileSystem().label().isEmpty()) || (e.fsSpec().contains(partition().label()) && !partition().label().isEmpty() ) || (e.fsSpec().contains(partition().uuid()) && !partition().uuid().isEmpty() ) ) + if(editPath().count()<=1 && ((e.fsSpec().contains(partition().deviceNode()) && !partition().deviceNode().isEmpty() ) || (e.fsSpec().contains(partition().fileSystem().uuid()) && !partition().fileSystem().uuid().isEmpty()) || + (e.fsSpec().contains(partition().fileSystem().label()) && !partition().fileSystem().label().isEmpty()) || (e.fsSpec().contains(partition().label()) && !partition().label().isEmpty() ) || (e.fsSpec().contains(partition().uuid()) && !partition().uuid().isEmpty() ))) { fstabEntries().removeAt(i); partition().setMountPoint(QString()); i--; + } + else if(editPath().count()>1 && ((&e == currentEntry))) + { + fstabEntries().removeAt(i); + editPath().removeItem(editPath().currentIndex()); + partition().setMountPoint(editPath().itemText(editPath().currentIndex())); + i--; + break; } i++; } } void EditMountPointDialogWidget::buttonMoreClicked(bool) { QPointer dlg = new EditMountOptionsDialog(this, m_Options.split(QLatin1Char(','))); if (dlg->exec() == QDialog::Accepted) setupOptions(dlg->options()); delete dlg; } QStringList EditMountPointDialogWidget::options() const { QStringList optList = m_Options.split(QLatin1Char(','), QString::SkipEmptyParts); const auto keys = boxOptions(); for (const auto &s : keys) if (s.second->isChecked()) optList.append(s.first); return optList; } void EditMountPointDialogWidget::acceptChanges() { - entry->setDumpFreq(spinDumpFreq().value()); - entry->setPassNumber(spinPassNumber().value()); - entry->setMountPoint(editPath().text()); - entry->setOptions(options()); + currentEntry->setDumpFreq(spinDumpFreq().value()); + currentEntry->setPassNumber(spinPassNumber().value()); + currentEntry->setMountPoint(editPath().currentText()); + currentEntry->setOptions(options()); if (radioUUID().isChecked() && !partition().fileSystem().uuid().isEmpty()) - entry->setFsSpec(QStringLiteral("UUID=") + partition().fileSystem().uuid()); + currentEntry->setFsSpec(QStringLiteral("UUID=") + partition().fileSystem().uuid()); else if (radioLabel().isChecked() && !partition().fileSystem().label().isEmpty()) - entry->setFsSpec(QStringLiteral("LABEL=") + partition().fileSystem().label()); + currentEntry->setFsSpec(QStringLiteral("LABEL=") + partition().fileSystem().label()); else - entry->setFsSpec(m_deviceNode); + currentEntry->setFsSpec(m_deviceNode); } diff --git a/src/gui/editmountpointdialogwidget.h b/src/gui/editmountpointdialogwidget.h index da54790..56705bc 100644 --- a/src/gui/editmountpointdialogwidget.h +++ b/src/gui/editmountpointdialogwidget.h @@ -1,112 +1,115 @@ /************************************************************************* * Copyright (C) 2009, 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(EDITMOUNTPOINTDIALOGWIDGET_H) #define EDITMOUNTPOINTDIALOGWIDGET_H #include "ui_editmountpointdialogwidgetbase.h" #include #include #include #include class Partition; class QFile; class QSpinBox; class QCheckBox; -class QLineEdit; +class QComboBox; class QPushButton; class QStringList; class EditMountPointDialogWidget : public QWidget, public Ui::EditMountPointDialogWidgetBase { public: EditMountPointDialogWidget(QWidget* parent, Partition& p); ~EditMountPointDialogWidget(); QPushButton& buttonMore() { return *m_ButtonMore; } QLabel& labelName() { return *m_LabelNameValue; } - QLineEdit& editPath() { + QComboBox& editPath() { return *m_EditPath; } QSpinBox& spinDumpFreq() { return *m_SpinDumpFreq; } QSpinBox& spinPassNumber() { return *m_SpinPassNumber; } QLabel& labelType() { return *m_LabelTypeValue; } QStringList options() const; QRadioButton& radioUUID() { return *m_RadioUUID; } QRadioButton& radioLabel() { return *m_RadioLabel; } QRadioButton& radioDeviceNode() { return *m_RadioDeviceNode; } FstabEntryList& fstabEntries() { return m_fstabEntries; } void acceptChanges(); void removeMountPoint(); bool writeMountpoints(const QString& filename); protected: void buttonSelectClicked(bool); void buttonMoreClicked(bool); private: void setupOptions(const QStringList& options); + void setupRadio(const FstabEntryType entryType); std::map& boxOptions() { return m_BoxOptions; } const std::map& boxOptions() const { return m_BoxOptions; } Partition& partition() { return m_Partition; } const Partition& partition() const { return m_Partition; } private: FstabEntryList m_fstabEntries; - FstabEntry *entry; - + QList entry; + FstabEntry *currentEntry; Partition& m_Partition; QString m_Options; QString m_deviceNode; + QStringList mountPointList; std::map m_BoxOptions; + std::map::iterator iterator_BoxOptions; }; #endif diff --git a/src/gui/editmountpointdialogwidgetbase.ui b/src/gui/editmountpointdialogwidgetbase.ui index e83a459..0d95b5e 100644 --- a/src/gui/editmountpointdialogwidgetbase.ui +++ b/src/gui/editmountpointdialogwidgetbase.ui @@ -1,333 +1,323 @@ EditMountPointDialogWidgetBase 0 0 - 600 + 613 374 - - - - - 3 - 0 - + + + + UU&ID - - + + + + + - Path: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - m_EditPath + Users can mount and unmount - - + + - Type: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Update access times relative to modification - - + + - Options: + - - Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing + + + + + + Qt::Horizontal Read-only - - + + - Users can mount and unmount + Pass &Number: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + m_SpinPassNumber - - + + - No automatic mount + More... - - + + + + Qt::Horizontal + + + + 195 + 22 + + + + + + - No update of file access times + De&vice Node + + + true - - + + - Synchronous access + Options: + + + Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing - - + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + - No update of directory access times + &Label No binary execution - - - - Update access times relative to modification - - + + - - + + Qt::Horizontal - 195 - 22 + 135 + 23 - - + + - More... + No automatic mount + + + + + + + + 1 + 0 + + + + Remove + + + + + + + + 1 + 0 + + + + Select... + + + + + + + No update of directory access times Dump &Frequency: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter m_SpinDumpFreq - - - - - + + - Qt::Horizontal + Qt::Vertical + + + QSizePolicy::Fixed - 70 - 23 + 20 + 10 - - + + - Pass &Number: + Type: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - m_SpinPassNumber - - - + + + + Path: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + 75 true Qt::AlignCenter - - - - - - - - - - - Qt::Horizontal - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 10 - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 10 - - - - Qt::Vertical QSizePolicy::Fixed 20 20 - - - - De&vice Node - - - true - - - - - - - UU&ID - - - - - + + - &Label + No update of file access times - - + + - Identify by: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Synchronous access - - + + Qt::Horizontal - 135 + 70 23 - - - - - 1 - 0 - - + + - Select... - - - - - - - - 1 - 0 - + Identify by: - - Remove + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + +