summaryrefslogtreecommitdiffstats
path: root/filesystemwidget.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-11-20 16:43:40 +0100
committerArno <am@disconnect.de>2010-11-20 16:43:40 +0100
commitc5963017115e630c52cf6380b63266c9963568de (patch)
treed62ef40ab9a963d7384b38ed6ebdb890a729a7a6 /filesystemwidget.cpp
parent3411f7ef7f44a3933aef256d26954e323e2b2175 (diff)
downloadSheMov-c5963017115e630c52cf6380b63266c9963568de.tar.gz
SheMov-c5963017115e630c52cf6380b63266c9963568de.tar.bz2
SheMov-c5963017115e630c52cf6380b63266c9963568de.zip
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...
Diffstat (limited to 'filesystemwidget.cpp')
-rw-r--r--filesystemwidget.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp
index 5d63aef..037c5f5 100644
--- a/filesystemwidget.cpp
+++ b/filesystemwidget.cpp
@@ -21,6 +21,11 @@
#include <QFile>
#include <QAction>
#include <QRegExp>
+#include <QFile>
+#include <QTextStream>
+
+#include <errno.h>
+#include <string.h>
#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);