Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file extension automatically for record plugin #303

Merged
merged 8 commits into from
Sep 16, 2020
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