summaryrefslogtreecommitdiffstats
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
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...
-rw-r--r--filesystemwidget.cpp52
-rw-r--r--filesystemwidget.h4
-rw-r--r--shemov.cpp22
-rw-r--r--shemov.h2
-rw-r--r--shemov.qrc1
5 files changed, 80 insertions, 1 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);
diff --git a/filesystemwidget.h b/filesystemwidget.h
index cf8774e..b04feca 100644
--- a/filesystemwidget.h
+++ b/filesystemwidget.h
@@ -35,11 +35,13 @@ class FilesystemWidget : public QWidget {
QFileSystemModel *dirModel() { return mModel; };
const QString windowTitle() const { return mWindowTitle; };
PictureViewer *pictureViewer() { return mPicViewer; };
+ bool isMounted();
signals:
void windowTitle(const QString &);
void statusbarMessage(const QString &);
void newTemplate(const QString &);
+ void mounted(bool);
public slots:
void directoryChanged(const QModelIndex &selected, const QModelIndex &);
@@ -56,6 +58,7 @@ class FilesystemWidget : public QWidget {
void playSelected(const QString &player = QString());
void readSettings();
void writeSettings();
+ void dvdMount();
private slots:
void doRenameFile();
@@ -79,7 +82,6 @@ class FilesystemWidget : public QWidget {
MessageDialog *mRenameDialog;
QString mTemplate;
qint64 mSize;
- QAction *mRefreshAction;
PictureViewer *mPicViewer;
QString mLastDir;
};
diff --git a/shemov.cpp b/shemov.cpp
index cd524ff..1b3aca3 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -90,6 +90,7 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla
connect(mFSWidget->dirModel(), SIGNAL(layoutChanged()), this, SLOT(setFsFree()));
connect(mFSWidget->dirModel(), SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(setFsFree()));
connect(this, SIGNAL(configChanged()), mFSWidget->fileView(), SLOT(readConfig()));
+ connect(mFSWidget, SIGNAL(mounted(bool)), this, SLOT(checkMount(bool)));
QWidget *centralWidget = new QWidget;
centralWidget->setLayout(mainLayout);
@@ -332,6 +333,9 @@ void SheMov::createActions(){
mRenameA = new QAction(tr("Rename file..."), this);
mRenameA->setShortcut(tr("CTRL+r"));
connect(mRenameA, SIGNAL(triggered()), mFSWidget, SLOT(renameFile()));
+ mMountDvdA = new QAction(QIcon(":/diaper.png"), tr("(Un)mount DVD drive"), this);
+ mMountDvdA->setCheckable(true);
+ connect(mMountDvdA, SIGNAL(triggered()), mFSWidget, SLOT(dvdMount()));
mConfigA = new QAction(QIcon(":/chastity_belt.png"), tr("Configure..."), this);
connect(mConfigA, SIGNAL(triggered()), this, SLOT(configure()));
@@ -475,6 +479,8 @@ void SheMov::createMenus(){
mRenameMenuA->setMenu(mRenameMenu);
mEditFSMenu->addAction(mRenameMenuA);
mEditFSMenu->addSeparator();
+ mEditFSMenu->addAction(mMountDvdA);
+ mEditFSMenu->addSeparator();
mEditFSMenu->addAction(mConfigA);
mEditFSMenuA = menuBar()->addMenu(mEditFSMenu);
@@ -628,6 +634,8 @@ void SheMov::createToolBar(){
toolBar->addSeparator();
toolBar->addAction(mHoverPicsA);
toolBar->addAction(mHoverArchiveA);
+ toolBar->addSeparator();
+ toolBar->addAction(mMountDvdA);
addToolBar(Qt::LeftToolBarArea, toolBar);
}
@@ -675,6 +683,16 @@ void SheMov::readSettings(){
mHoverPicsA->setChecked(hoverPics);
bool hoverArchive = s.value("ui/hoverarchive").toBool();
mHoverArchiveA->setChecked(hoverArchive);
+ QString dvdMount = s.value("paths/dvdmount").toString();
+ if(dvdMount.isEmpty()){
+ mMountDvdA->setEnabled(false);
+ }else{
+ if(mFSWidget->isMounted()){
+ mMountDvdA->setChecked(true);
+ }else{
+ mMountDvdA->setChecked(false);
+ }
+ }
}
void SheMov::checkConsistency(){
@@ -693,3 +711,7 @@ void SheMov::toggleHoverPics(bool toggled){
s.setValue("ui/hoverpics", toggled);
emit configChanged();
}
+
+void SheMov::checkMount(bool mounted){
+ mMountDvdA->setChecked(mounted);
+}
diff --git a/shemov.h b/shemov.h
index b6cdb15..963faf8 100644
--- a/shemov.h
+++ b/shemov.h
@@ -47,6 +47,7 @@ class SheMov : public QMainWindow {
void checkConsistency();
void toggleHoverPics(bool toggled);
void toggleHoverArchive(bool toggled);
+ void checkMount(bool mounted);
signals:
void configChanged();
@@ -79,6 +80,7 @@ class SheMov : public QMainWindow {
QAction *mRenameA;
QAction *mCdupA;
QAction *mBackDirA;
+ QAction *mMountDvdA;
QAction *mRenameCoverFA;
QAction *mRenameCoverBA;
QAction *mRenameCoverCA;
diff --git a/shemov.qrc b/shemov.qrc
index 8066501..068dfef 100644
--- a/shemov.qrc
+++ b/shemov.qrc
@@ -15,5 +15,6 @@
<file>nipple_up.png</file>
<file>bald_pussy.png</file>
<file>prince_albert.png</file>
+ <file>diaper.png</file>
</qresource>
</RCC>