diff --git a/src/ubuntu/CaptureWidget.qml b/src/ubuntu/CaptureWidget.qml index e3fe20e..0a332e2 100644 --- a/src/ubuntu/CaptureWidget.qml +++ b/src/ubuntu/CaptureWidget.qml @@ -40,7 +40,6 @@ Rectangle { console.log(errorString); } videoRecorder.audioBitRate: 128000 - videoRecorder.mediaContainer: "mp4" imageCapture { onImageSaved: { root.exec("Camera", "onImageSaved", [path]); @@ -100,7 +99,7 @@ Rectangle { MouseArea { anchors.fill: parent onClicked: { - camera.imageCapture.capture(); + camera.imageCapture.captureToLocation(ui.parent.plugin('Camera').generateLocation("jpg")); } } } diff --git a/src/ubuntu/camera.cpp b/src/ubuntu/camera.cpp index eada5dc..c58af32 100644 --- a/src/ubuntu/camera.cpp +++ b/src/ubuntu/camera.cpp @@ -38,7 +38,7 @@ function createObject() { \ component.statusChanged.connect(finishCreation); \ } \ function finishCreation() { \ - CordovaWrapper.object = component.createObject(root, \ + CordovaWrapper.global.cameraPluginWidget = component.createObject(root, \ {root: root, cordova: cordova}); \ } \ createObject()"; @@ -68,18 +68,15 @@ bool Camera::preprocessImage(QString &path) { const char *type; if (convertToPNG) { - newImage.setFileTemplate("imgXXXXXX.png"); + path = generateLocation("png"); type = "png"; } else { - newImage.setFileTemplate("imgXXXXXX.jpg"); + path = generateLocation("jpg"); type = "jpg"; } - newImage.open(); - newImage.setAutoRemove(false); - image.save(newImage.fileName(), type, quality); + image.save(path, type, quality); - path = newImage.fileName(); oldImage.remove(); return true; @@ -98,7 +95,7 @@ void Camera::onImageSaved(QString path) { cbParams = QString("\"%1\"").arg(content.data()); image.remove(); } else { - cbParams = CordovaInternal::format(QUrl::fromLocalFile(absolutePath).toString()); + cbParams = CordovaInternal::format(QString("file://localhost") + absolutePath); } } @@ -136,7 +133,7 @@ void Camera::takePicture(int scId, int ecId, int quality, int destinationType, i } void Camera::cancel() { - m_cordova->execQML("CordovaWrapper.object.destroy()"); + m_cordova->execQML("CordovaWrapper.global.cameraPluginWidget.destroy()"); this->cb(_lastEcId, "canceled"); _lastEcId = _lastScId = 0; diff --git a/src/ubuntu/camera.h b/src/ubuntu/camera.h index aa06698..6d96038 100644 --- a/src/ubuntu/camera.h +++ b/src/ubuntu/camera.h @@ -54,6 +54,16 @@ public slots: void onImageSaved(QString path); + QString generateLocation(const QString &extension) { + int i = 1; + for (;;++i) { + QString path = QString("%1/.local/share/%2/persistent/%3.%4").arg(QDir::homePath()) + .arg(QCoreApplication::applicationName()).arg(i).arg(extension); + + if (!QFileInfo(path).exists()) + return path; + } + } private: bool preprocessImage(QString &path);