diff options
author | Arno <am@disconnect.de> | 2010-11-20 11:12:22 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-11-20 11:12:22 +0100 |
commit | 3411f7ef7f44a3933aef256d26954e323e2b2175 (patch) | |
tree | 7c6e280c041a979d443ad48b22b1129119d0128f | |
parent | 9916f94525d6c87ed938f64b8303c22e4473b0f8 (diff) | |
download | SheMov-3411f7ef7f44a3933aef256d26954e323e2b2175.tar.gz SheMov-3411f7ef7f44a3933aef256d26954e323e2b2175.tar.bz2 SheMov-3411f7ef7f44a3933aef256d26954e323e2b2175.zip |
Added configuration option for dvd mount
Preparation for new action dvd mount. Add setting for dvd mount
directory.
-rw-r--r-- | configurationdialog.cpp | 66 | ||||
-rw-r--r-- | configurationdialog.h | 3 |
2 files changed, 67 insertions, 2 deletions
diff --git a/configurationdialog.cpp b/configurationdialog.cpp index 20e424b..be6fea8 100644 --- a/configurationdialog.cpp +++ b/configurationdialog.cpp @@ -22,6 +22,10 @@ #include <QGroupBox> #include <QCheckBox> #include <QSpinBox> +#include <QFileInfo> +#include <QMessageBox> +#include <QFile> +#include <QTextStream> #include "configurationdialog.h" #include "programconfigurator.h" @@ -66,6 +70,10 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : Q mFfProbePath->setCompleter(fsCompleter); pathGrid->addWidget(miscl4, 2, 0); pathGrid->addWidget(mFfProbePath, 2, 1); + QLabel *miscl5 = new QLabel(tr("DVD mount directory")); + mDvdMountPath = new QLineEdit; + pathGrid->addWidget(miscl5, 3, 0); + pathGrid->addWidget(mDvdMountPath, 3, 1); pathBox->setLayout(pathGrid); //misc - hover @@ -78,9 +86,9 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : Q mHoverOpacity = new QSpinBox; mHoverOpacity->setMinimum(1); mHoverOpacity->setMaximum(10); - QLabel *miscl5 = new QLabel(tr("Opacity of hover window")); + QLabel *miscl6 = new QLabel(tr("Opacity of hover window")); QHBoxLayout *opacityLayout = new QHBoxLayout; - opacityLayout->addWidget(miscl5); + opacityLayout->addWidget(miscl6); opacityLayout->addWidget(mHoverOpacity); hoverLayout->addLayout(opacityLayout); hoverBox->setLayout(hoverLayout); @@ -163,6 +171,7 @@ void ConfigurationDialog::readSettings(){ mArchiveDir->setText(s.value("paths/archivedir").toString()); mBurnDir->setText(s.value("paths/burn").toString()); mFfProbePath->setText(s.value("paths/ffprobe").toString()); + mDvdMountPath->setText(s.value("paths/dvdmount").toString()); mHoverPics->setChecked(s.value("ui/hoverpics", false).toBool()); mHoverArchive->setChecked(s.value("ui/hoverarchive", false).toBool()); mHoverOpacity->setValue(s.value("ui/hoveropacity", 10).toInt()); @@ -187,6 +196,9 @@ void ConfigurationDialog::writeSettings(){ if(ffProbeInfo.exists() && ffProbeInfo.isExecutable()){ s.setValue("paths/ffprobe", ffprobe); } + if(checkDvdPath()){ + s.setValue("paths/dvdmount", mDvdMountPath->text()); + } s.setValue("ui/hoverpics", (mHoverPics->checkState() == Qt::Checked)); s.setValue("ui/hoverarchive", (mHoverArchive->checkState() == Qt::Checked)); s.setValue("ui/hoveropacity", mHoverOpacity->value()); @@ -204,3 +216,53 @@ void ConfigurationDialog::writeSettings(){ mPicConfig->writeSettings(); } +bool ConfigurationDialog::checkDvdPath(){ + QString path = mDvdMountPath->text(); + if(path.isEmpty()){ + return true; + } + QFileInfo mountInfo(path); + if(!mountInfo.exists() || !mountInfo.isDir()){ + QString message = QString(tr("%1 does not exist or is not a directory. Ignoring.")).arg(path); + mountError(message); + return false; + } + QFile fstab("/etc/fstab"); + if(!fstab.exists() || !fstab.open(QFile::ReadOnly)){ + mountError(QString()); + return true; + } + QTextStream fStream(&fstab); + QString line; + bool ok = false; + do { + line = fStream.readLine(); + if(line.contains(path)){ + QStringList fsParts = line.split(QRegExp("\\s+")); + if(fsParts.isEmpty() || (fsParts.size() < 4)){ + continue; + } + QStringList options = fsParts.at(3).split(','); + foreach(QString opt, options){ + if(opt.toLower().trimmed() == "user"){ + ok = true; + break; + } + } + } + } while(!line.isNull()); + if(!ok){ + QString message = QString(tr("Didn't find %1 in fstab or it isn't user mountable. Ignoring.")).arg(path); + mountError(message); + return false; + } + return true; +} + +void ConfigurationDialog::mountError(const QString &error){ + if(!error.isEmpty()){ + QMessageBox::critical(this, tr("Mount Path Error"), error); + } + QSettings s; + s.setValue("paths/dvdmount", QString()); +} diff --git a/configurationdialog.h b/configurationdialog.h index f41cabe..f97a2d9 100644 --- a/configurationdialog.h +++ b/configurationdialog.h @@ -31,6 +31,8 @@ class ConfigurationDialog : public QDialog { private: void readSettings(); void writeSettings(); + bool checkDvdPath(); + void mountError(const QString &error); QPushButton *mOk; QPushButton *mCancel; QTabWidget *mTab; @@ -39,6 +41,7 @@ class ConfigurationDialog : public QDialog { QLineEdit *mArchiveDir; QLineEdit *mBurnDir; QLineEdit *mFfProbePath; + QLineEdit *mDvdMountPath; QLineEdit *mDatabaseHost; QLineEdit *mDatabaseName; QLineEdit *mDatabaseUsername; |