diff --git a/src/gui/editmountpointdialogwidget.cpp b/src/gui/editmountpointdialogwidget.cpp index 64fb1a3..756abcc 100644 --- a/src/gui/editmountpointdialogwidget.cpp +++ b/src/gui/editmountpointdialogwidget.cpp @@ -41,23 +41,27 @@ struct MountEntry { - MountEntry(const QString& n, const QString& p, const QString& t, const QStringList& o, qint32 d, qint32 pn) : + enum IdentifyType { deviceNode, uuid, label }; + + MountEntry(const QString& n, const QString& p, const QString& t, const QStringList& o, qint32 d, qint32 pn, IdentifyType type) : name(n), path(p), type(t), options(o), dumpFreq(d), - passNumber(pn) + passNumber(pn), + identifyType(type) { } - MountEntry(struct mntent* p) : + MountEntry(struct mntent* p, IdentifyType type) : name(p->mnt_fsname), path(p->mnt_dir), type(p->mnt_type), options(QString(p->mnt_opts).split(',')), dumpFreq(p->mnt_freq), - passNumber(p->mnt_passno) + passNumber(p->mnt_passno), + identifyType(type) { } @@ -67,6 +71,7 @@ struct MountEntry QStringList options; qint32 dumpFreq; qint32 passNumber; + IdentifyType identifyType; }; static QString findBlkIdDevice(const QString& token, const QString& value) @@ -89,19 +94,20 @@ static QString findBlkIdDevice(const QString& token, const QString& value) } EditMountPointDialogWidget::EditMountPointDialogWidget(QWidget* parent, const Partition& p) : - QWidget(parent) + QWidget(parent), + m_Partition(p) { readMountpoints("/etc/fstab"); setupUi(this); - labelName().setText(p.deviceNode()); - labelType().setText(p.fileSystem().name()); + labelName().setText(partition().deviceNode()); + labelType().setText(partition().fileSystem().name()); - if (mountPoints().find(p.deviceNode()) == mountPoints().end()) - mountPoints()[p.deviceNode()] = new MountEntry(p.deviceNode(), QString(), p.fileSystem().name(), QStringList(), 0, 0); + if (mountPoints().find(partition().deviceNode()) == mountPoints().end()) + mountPoints()[partition().deviceNode()] = new MountEntry(partition().deviceNode(), QString(), partition().fileSystem().name(), QStringList(), 0, 0, MountEntry::deviceNode); - MountEntry* entry = mountPoints()[p.deviceNode()]; + MountEntry* entry = mountPoints()[partition().deviceNode()]; Q_ASSERT(entry); @@ -112,6 +118,20 @@ EditMountPointDialogWidget::EditMountPointDialogWidget(QWidget* parent, const Pa spinDumpFreq().setValue(entry->dumpFreq); spinPassNumber().setValue(entry->passNumber); + switch(entry->identifyType) + { + case MountEntry::uuid: + radioUUID().setChecked(true); + break; + + case MountEntry::label: + radioLabel().setChecked(true); + break; + + default: + radioDeviceNode().setChecked(true); + } + boxOptions()["ro"] = m_CheckReadOnly; boxOptions()["users"] = m_CheckUsers; boxOptions()["noauto"] = m_CheckNoAuto; @@ -123,6 +143,20 @@ EditMountPointDialogWidget::EditMountPointDialogWidget(QWidget* parent, const Pa 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); + } } EditMountPointDialogWidget::~EditMountPointDialogWidget() @@ -183,21 +217,28 @@ bool EditMountPointDialogWidget::readMountpoints(const QString& filename) return false; } - struct mntent* p = NULL; + struct mntent* mnt = NULL; - while ((p = getmntent(fp)) != NULL) + while ((mnt = getmntent(fp)) != NULL) { - QString device = p->mnt_fsname; + QString device = mnt->mnt_fsname; + MountEntry::IdentifyType type = MountEntry::deviceNode; if (device.startsWith("UUID=")) + { + type = MountEntry::uuid; device = findBlkIdDevice("UUID", QString(device).remove("UUID=")); + } else if (device.startsWith("LABEL=")) + { + type = MountEntry::label; device = findBlkIdDevice("LABEL", QString(device).remove("LABEL=")); + } if (!device.isEmpty()) { - QString mountPoint = p->mnt_dir; - mountPoints()[device] = new MountEntry(p); + QString mountPoint = mnt->mnt_dir; + mountPoints()[device] = new MountEntry(mnt, type); } } @@ -214,6 +255,7 @@ static void writeEntry(QFile& output, const MountEntry* entry) return; QTextStream s(&output); + s << entry->name << "\t" << entry->path << "\t" << entry->type << "\t" @@ -224,7 +266,7 @@ static void writeEntry(QFile& output, const MountEntry* entry) bool EditMountPointDialogWidget::acceptChanges() { - MountEntry* mp = NULL; + MountEntry* entry = NULL; if (mountPoints().find(labelName().text()) == mountPoints().end()) { @@ -233,12 +275,19 @@ bool EditMountPointDialogWidget::acceptChanges() } else { - mp = mountPoints()[labelName().text()]; + entry = mountPoints()[labelName().text()]; - mp->dumpFreq = spinDumpFreq().value(); - mp->passNumber = spinPassNumber().value(); - mp->path = editPath().text(); - mp->options = options(); + entry->dumpFreq = spinDumpFreq().value(); + entry->passNumber = spinPassNumber().value(); + entry->path = editPath().text(); + entry->options = options(); + + if (radioUUID().isChecked() && !partition().fileSystem().uuid().isEmpty()) + entry->name = "UUID=" + partition().fileSystem().uuid(); + else if (radioLabel().isChecked() && !partition().fileSystem().label().isEmpty()) + entry->name = "LABEL=" + partition().fileSystem().label(); + else + entry->name = partition().deviceNode(); } return true; diff --git a/src/gui/editmountpointdialogwidget.h b/src/gui/editmountpointdialogwidget.h index d856010..e066782 100644 --- a/src/gui/editmountpointdialogwidget.h +++ b/src/gui/editmountpointdialogwidget.h @@ -36,6 +36,7 @@ class QWidget; class QSpinBox; class QCheckBox; class QStringList; +class QFile; struct MountEntry; @@ -55,6 +56,9 @@ class EditMountPointDialogWidget : public QWidget, public Ui::EditMountPointDial QSpinBox& spinPassNumber() { return *m_SpinPassNumber; } QLabel& labelType() { return *m_LabelTypeValue; } QStringList options(); + QRadioButton& radioUUID() { return *m_RadioUUID; } + QRadioButton& radioLabel() { return *m_RadioLabel; } + QRadioButton& radioDeviceNode() { return *m_RadioDeviceNode; } bool acceptChanges(); bool writeMountpoints(const QString& filename); @@ -69,8 +73,10 @@ class EditMountPointDialogWidget : public QWidget, public Ui::EditMountPointDial const QMap& boxOptions() const { return m_BoxOptions; } bool readMountpoints(const QString& filename); QMap& mountPoints() { return m_MountPoints; } + const Partition& partition() const { return m_Partition; } private: + const Partition& m_Partition; QMap m_MountPoints; QString m_Options; QMap m_BoxOptions; diff --git a/src/gui/editmountpointdialogwidgetbase.ui b/src/gui/editmountpointdialogwidgetbase.ui index 3c7acc8..a066302 100644 --- a/src/gui/editmountpointdialogwidgetbase.ui +++ b/src/gui/editmountpointdialogwidgetbase.ui @@ -14,7 +14,7 @@ Form - + Path: @@ -27,7 +27,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -50,7 +50,7 @@ - + Type: @@ -60,7 +60,7 @@ - + Options: @@ -70,63 +70,63 @@ - + Read-only - + Users can mount and unmount - + No automatic mount - + No update of file access times - + Synchronuous access - + No update of directory access times - + No binary execution - + Update access times relative to modification - + Qt::Horizontal @@ -139,14 +139,14 @@ - + More... - + Dump Frequency: @@ -159,10 +159,10 @@ - + - + Qt::Horizontal @@ -175,7 +175,7 @@ - + Pass Number: @@ -188,10 +188,10 @@ - + - + Qt::Horizontal @@ -220,7 +220,7 @@ - + @@ -266,7 +266,7 @@ - + Qt::Vertical @@ -282,6 +282,40 @@ + + + + Device Node + + + true + + + + + + + UUID + + + + + + + Label + + + + + + + Identify by: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + +