Use it to prevent going to mass storage mode while capturing or recording.
return;
}
+ if (!mountProtector.lock()) {
+ showError(qsTr("Failed to lock images directory."));
+ return;
+ }
+
metaData.setMetaData();
if (!imageMode.capture(fileNaming.imageFileName())) {
id: imageMode
camera: cam
onPreviewAvailable: page.setPreview(preview);
+ onSaved: mountProtector.unlock();
}
FlashButton {
onAcquiredChanged: {
if (resourcePolicy.acquired && policyMode == CameraResources.Recording) {
metaData.setMetaData();
+
+ if (!mountProtector.lock()) {
+ showError(qsTr("Failed to lock images directory."));
+ policyMode = CameraResources.Video
+ return;
+ }
+
+
if (!videoMode.startRecording(fileNaming.videoFileName())) {
showError(qsTr("Failed to record video. Please restart the camera."));
policyMode = CameraResources.Video
page.setPreview(preview);
}
}
+
+ onSaved: mountProtector.unlock();
}
VideoTorchButton {
// TODO: portrait/landscape
// TODO: record video in a hidden directory and then copy the video to avoid tracker indexing it.
// TODO: stop viewfinder in settings pages ?
-// TODO: prevent going to mass storage while recording and capturing
// TODO: grid lines, face tracking, ambr
// TODO: complete settings pages
// TODO: stop camera properly when we get closed.
videoSuffix: cam.videoSuffix
}
+ MountProtector {
+ id: mountProtector
+ path: fileNaming.path
+ }
+
function replacePage(file) {
pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
}
showError(qsTr("Camera error. Please restart the application."));
cam.stop();
resourcePolicy.acquire(CameraResources.None);
+ mountProtector.unlock();
+ }
+
+ onRunningChanged: {
+ if (!cam.running) {
+ mountProtector.unlock();
+ }
}
// TODO: hardcoding device id
#include "compass.h"
#include "orientation.h"
#include "geocode.h"
+#include "mountprotector.h"
Q_DECL_EXPORT int main(int argc, char *argv[]) {
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
qmlRegisterType<Compass>("CameraPlus", 1, 0, "Compass");
qmlRegisterType<Orientation>("CameraPlus", 1, 0, "Orientation");
qmlRegisterType<Geocode>("CameraPlus", 1, 0, "ReverseGeocode");
+ qmlRegisterType<MountProtector>("CameraPlus", 1, 0, "MountProtector");
QUrl sourceUrl = QUrl::fromLocalFile(QDir::currentPath() + "/main.qml");
view.setSource(sourceUrl);
--- /dev/null
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "mountprotector.h"
+#include <QDir>
+#include <QDebug>
+
+MountProtector::MountProtector(QObject *parent) :
+ QObject(parent), m_fd(-1) {
+
+}
+
+MountProtector::~MountProtector() {
+ unlock();
+}
+
+QString MountProtector::path() const {
+ return m_path;
+}
+
+void MountProtector::setPath(const QString& path) {
+ if (m_path != path) {
+ m_path = path;
+ emit pathChanged();
+ }
+}
+
+bool MountProtector::lock() {
+ if (m_fd != -1) {
+ return true;
+ }
+
+ if (m_path.isEmpty()) {
+ return false;
+ }
+
+ QString path = QString("%1%2.cameraplus_tmp_XXXXXX").arg(m_path).arg(QDir::separator());
+
+ m_fd = mkstemp(path.toLocal8Bit().data());
+
+ if (m_fd == -1) {
+ perror("mkstemp");
+ return false;
+ }
+
+ return true;
+}
+
+void MountProtector::unlock() {
+ if (m_fd != -1) {
+ close(m_fd);
+ m_fd = -1;
+ }
+}
--- /dev/null
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef MOUNT_PROTECTOR_H
+#define MOUNT_PROTECTOR_H
+
+#include <QObject>
+
+class MountProtector : public QObject {
+ Q_OBJECT
+
+ Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged);
+
+public:
+ MountProtector(QObject *parent = 0);
+ ~MountProtector();
+
+ QString path() const;
+ void setPath(const QString& path);
+
+ Q_INVOKABLE bool lock();
+
+public slots:
+ void unlock();
+
+signals:
+ void pathChanged();
+
+private:
+ int m_fd;
+ QString m_path;
+};
+
+#endif /* MOUNT_PROTECTOR_H */
LIBS += -L../imports/ -limports -L../lib/ -lqtcamera
SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp fsmonitor.cpp \
- cameraresources.cpp compass.cpp orientation.cpp geocode.cpp
+ cameraresources.cpp compass.cpp orientation.cpp geocode.cpp mountprotector.cpp
HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \
- cameraresources.h compass.h orientation.h geocode.h
+ cameraresources.h compass.h orientation.h geocode.h mountprotector.h