Skip to content

Commit

Permalink
Add file extension automatically for record plugin (#303)
Browse files Browse the repository at this point in the history
Signed-off-by: John Shepherd <[email protected]>

Co-authored-by: Louise Poubel <[email protected]>
Co-authored-by: Nate Koenig <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2020
1 parent 4e6c6ec commit 0af2c5f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/gui/plugins/video_recorder/VideoRecorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <iostream>
#include <ignition/common/Console.hh>
#include <ignition/common/Filesystem.hh>
#include <ignition/gui/Application.hh>
#include <ignition/plugin/Register.hh>
#include <ignition/transport/Node.hh>
Expand Down Expand Up @@ -106,6 +107,22 @@ void VideoRecorder::OnStop()
void VideoRecorder::OnSave(const QString &_url)
{
std::string path = QUrl(_url).toLocalFile().toStdString();

// If we cannot find an extension in the user entered file name,
// append the format of the selected codec
if (common::basename(path).find(".") == std::string::npos)
{
// Get the user selected file extension
std::string filenameBaseName = common::basename(this->dataPtr->filename);
std::string::size_type filenameExtensionIndex =
filenameBaseName.rfind(".");
std::string fileExtension =
filenameBaseName.substr(filenameExtensionIndex + 1);

// Append file extension to the user entered path
path += "." + fileExtension;
}

bool result = common::moveFile(this->dataPtr->filename, path);

if (!result)
Expand Down

0 comments on commit 0af2c5f

Please sign in to comment.