From 64fcfd33a49c4207ae1c94ced5e523b959e1d451 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Fri, 21 Apr 2017 22:38:53 +0100 Subject: [PATCH] working on loading files --- .../qml/hifi/tablet/InputRecorder.qml | 32 +++++++++++++++---- .../src/controllers/InputRecorder.cpp | 23 ++++++++++++- .../src/controllers/InputRecorder.h | 4 ++- .../src/controllers/ScriptingInterface.cpp | 10 ++++++ .../src/controllers/ScriptingInterface.h | 2 ++ 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/InputRecorder.qml b/interface/resources/qml/hifi/tablet/InputRecorder.qml index 28804ee219..d726d16f9c 100644 --- a/interface/resources/qml/hifi/tablet/InputRecorder.qml +++ b/interface/resources/qml/hifi/tablet/InputRecorder.qml @@ -14,6 +14,7 @@ import QtQuick.Dialogs 1.2 as OriginalDialogs import "../../styles-uit" import "../../controls-uit" as HifiControls import "../../windows" +import "../../dialogs" Rectangle { id: inputRecorder @@ -21,8 +22,10 @@ Rectangle { HifiConstants { id: hifi } signal sendToScript(var message); color: hifi.colors.baseGray; + property string path: "" + property var dialog: null; - + Component { id: fileDialog; TabletFileDialog { } } Row { id: topButtons width: parent.width @@ -39,6 +42,9 @@ Rectangle { text: "Start" color: hifi.buttons.blue enabled: true + onClicked: { + sendToScript({method: "Start"}); + } } HifiControls.Button { @@ -46,6 +52,9 @@ Rectangle { text: "Stop" color: hifi.buttons.blue enabled: true + onClicked: { + sendToScript({method: "Stop"}); + } } HifiControls.Button { @@ -53,6 +62,9 @@ Rectangle { text: "Save" color: hifi.buttons.blue enabled: true + onClicked: { + sendToScript({method: "Save"}); + } } } @@ -80,6 +92,7 @@ Rectangle { text: "Load" color: hifi.buttons.black enabled: true + onClicked: sendToScript({method: "Load", params: {file: path }}); } HifiControls.Button { @@ -91,13 +104,18 @@ Rectangle { text: "Browse" color: hifi.buttons.black enabled: true + onClicked: { + dialog = fileDialog.createObject(inputRecorder); + dialog.selectedFile.connect(getFileSelected); + } + } - Trigger { - id: browseTimer - interval: 5 - repeat: false - running: false - + + function getFileSelected(file) { + console.log("------------> file selected <----------------"); + //sendToScript({ method: "Load", params: { file: file} }); + selectedFile.text = file; + inputRecorder.path = file; } } diff --git a/libraries/controllers/src/controllers/InputRecorder.cpp b/libraries/controllers/src/controllers/InputRecorder.cpp index e404048ffd..782f44d0ac 100644 --- a/libraries/controllers/src/controllers/InputRecorder.cpp +++ b/libraries/controllers/src/controllers/InputRecorder.cpp @@ -74,6 +74,18 @@ namespace controller { QByteArray compressedData = qCompress(saveData.toJson(QJsonDocument::Compact)); saveFile.write(compressedData); } + + bool openFile(const QString& file, QJsonObject& object) { + QFile openFile(file); + if (!openFile.open(QIODevice::ReadOnly)) { + qWarning() << "could not open file: " << file; + return false; + } + QByteArray compressedData = qUncompress(openFile.readAll()); + QJsonDocument jsonDoc = QJsonDocument::fromBinaryData(compressedData); + object = jsonDoc.object(); + return true; + } InputRecorder::InputRecorder() {} @@ -119,7 +131,16 @@ namespace controller { exportToFile(data); } - void InputRecorder::loadRecording() { + void InputRecorder::loadRecording(const QString& path) { + QFileInfo info(path); + QString extension = info.suffix(); + if (extension != "gz") { + qWarning() << "Could not open file of that type"; + return; + } + QJsonObject data; + bool success = openFile(path, data); + qDebug() << "-------------------> loading file -------------->"; } void InputRecorder::stopRecording() { diff --git a/libraries/controllers/src/controllers/InputRecorder.h b/libraries/controllers/src/controllers/InputRecorder.h index 5417cdc927..8656966962 100644 --- a/libraries/controllers/src/controllers/InputRecorder.h +++ b/libraries/controllers/src/controllers/InputRecorder.h @@ -13,6 +13,8 @@ #include #include +#include + #include "Pose.h" #include "Actions.h" @@ -28,7 +30,7 @@ namespace controller { static InputRecorder* getInstance(); void saveRecording(); - void loadRecording(); + void loadRecording(const QString& path); void startRecording(); void startPlayback(); void stopPlayback(); diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index f09e366df8..9225579732 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -175,6 +175,16 @@ namespace controller { inputRecorder->stopPlayback(); } + void ScriptingInterface::saveInputRecording() { + InputRecorder* inputRecorder = InputRecorder::getInstance(); + inputRecorder->saveRecording(); + } + + void ScriptingInterface::loadInputRecording(const QString& file) { + InputRecorder* inputRecorder = InputRecorder::getInstance(); + inputRecorder->loadRecording(file); + } + bool ScriptingInterface::triggerHapticPulseOnDevice(unsigned int device, float strength, float duration, controller::Hand hand) const { return DependencyManager::get()->triggerHapticPulseOnDevice(device, strength, duration, hand); } diff --git a/libraries/controllers/src/controllers/ScriptingInterface.h b/libraries/controllers/src/controllers/ScriptingInterface.h index 961ed5ef72..9ed2c60790 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.h +++ b/libraries/controllers/src/controllers/ScriptingInterface.h @@ -103,6 +103,8 @@ namespace controller { Q_INVOKABLE void stopInputRecording(); Q_INVOKABLE void startInputPlayback(); Q_INVOKABLE void stopInputPlayback(); + Q_INVOKABLE void saveInputRecording(); + Q_INVOKABLE void loadInputRecording(const QString& file); bool isMouseCaptured() const { return _mouseCaptured; } bool isTouchCaptured() const { return _touchCaptured; }