From c5963017115e630c52cf6380b63266c9963568de Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 20 Nov 2010 16:43:40 +0100 Subject: Added support for mounting cd/dvds DVDs or CDs can be mounted under *NIX like OS now. It still eludes me how to refresh a directory from a QFileSystemModel when it's mounted. Maybe it's a qt bug... --- filesystemwidget.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'filesystemwidget.cpp') diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 5d63aef..037c5f5 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -21,6 +21,11 @@ #include #include #include +#include +#include + +#include +#include #include "filesystemwidget.h" #include "filesystemdirproxy.h" @@ -32,6 +37,8 @@ #include "pictureviewer.h" #include "smglobals.h" +extern int errno; + FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { mModel = new QFileSystemModel; mModel->setRootPath("/"); @@ -107,6 +114,27 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { setLayout(mainLayout); } +bool FilesystemWidget::isMounted(){ + QSettings s; + QString mount = s.value("paths/dvdmount").toString(); + if(mount.isEmpty()){ + return false; + } + QFile mounts("/proc/mounts"); + if(!mounts.exists() || !mounts.open(QFile::ReadOnly)){ + return false; + } + QTextStream mountStream(&mounts); + QString line; + do { + line = mountStream.readLine(); + if(line.contains(mount)){ + return true; + } + } while(!line.isNull()); + return false; +} + void FilesystemWidget::directoryChanged(const QModelIndex &selected, const QModelIndex &deselected){ QModelIndex real = mDirProxy->mapToSource(selected); if(!real.isValid()){ @@ -397,6 +425,30 @@ void FilesystemWidget::writeSettings(){ s.setValue("windows/picviewer", mPicViewer->pos()); } +void FilesystemWidget::dvdMount(){ + QSettings s; + QString mountDir = s.value("paths/dvdmount").toString(); + if(isMounted()){ + goBack(); + int retval = QProcess::execute("umount", QStringList() << mountDir); + if(retval){ + QString message = QString(tr("Could not unmount %1: %2")).arg(mountDir).arg(strerror(retval)); + QMessageBox::critical(this, tr("Error"), message); + return; + } + emit mounted(false); + }else{ + int retval = QProcess::execute("mount", QStringList() << mountDir); + if(retval){ + QString message = QString(tr("Could not mount %1: %2")).arg(mountDir).arg(strerror(retval)); + QMessageBox::critical(this, tr("Error"), message); + return; + } + QModelIndex mountIdx = mModel->index(mountDir); + emit mounted(true); + } +} + void FilesystemWidget::setWindowTitle(const QString &dir){ mWindowTitle = QString("%1 - %2").arg(qApp->applicationName()).arg(dir); emit windowTitle(mWindowTitle); -- cgit v1.2.3-70-g09d2