Files
oak-editor/app/project/project.cpp
T
itsmattkc 45917cfd29 project: use backslashes on windows
Backslashes are the normal directory delimiter for Windows so Windows users
will likely be more comfortable with this. Also prevents issues where a
filename may appear twice in the "open recent" list for both slash
directions.
2020-06-15 18:20:49 +10:00

182 lines
4.0 KiB
C++

/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "project.h"
#include <QDir>
#include <QFileInfo>
#include "common/xmlutils.h"
#include "core.h"
#include "dialog/progress/progress.h"
#include "window/mainwindow/mainwindow.h"
OLIVE_NAMESPACE_ENTER
Project::Project() :
is_modified_(false),
autorecovery_saved_(true)
{
root_.set_project(this);
}
void Project::Load(QXmlStreamReader *reader, const QAtomicInt* cancelled)
{
XMLNodeData xml_node_data;
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("folder")) {
// Assume this folder is our root
root_.Load(reader, xml_node_data, cancelled);
} else if (reader->name() == QStringLiteral("colormanagement")) {
// Read color management info
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("config")) {
color_manager_.SetConfig(reader->readElementText());
} else if (reader->name() == QStringLiteral("default")) {
color_manager_.SetDefaultInputColorSpace(reader->readElementText());
} else {
reader->skipCurrentElement();
}
}
} else if (reader->name() == QStringLiteral("layout")) {
Core::instance()->main_window()->LoadLayout(reader, xml_node_data);
} else {
reader->skipCurrentElement();
}
}
foreach (const XMLNodeData::FootageConnection& con, xml_node_data.footage_connections) {
if (con.footage) {
con.input->set_standard_value(QVariant::fromValue(xml_node_data.footage_ptrs.value(con.footage)));
}
}
}
void Project::Save(QXmlStreamWriter *writer) const
{
writer->writeStartElement("project");
writer->writeTextElement("url", filename_);
root_.Save(writer);
writer->writeStartElement("colormanagement");
writer->writeTextElement("config", color_manager_.GetConfigFilename());
writer->writeTextElement("default", color_manager_.GetDefaultInputColorSpace());
writer->writeEndElement(); // colormanagement
// Save main window project layout
Core::instance()->main_window()->SaveLayout(writer);
writer->writeEndElement(); // project
}
Folder *Project::root()
{
return &root_;
}
QString Project::name() const
{
if (filename_.isEmpty()) {
return tr("(untitled)");
} else {
return QFileInfo(filename_).completeBaseName();
}
}
const QString &Project::filename() const
{
return filename_;
}
QString Project::pretty_filename() const
{
QString fn = filename();
if (fn.isEmpty()) {
return tr("(untitled)");
} else {
return fn;
}
}
void Project::set_filename(const QString &s)
{
filename_ = s;
#ifdef Q_OS_WINDOWS
// Prevents filenames
filename_.replace('/', '\\');
#endif
emit NameChanged();
}
ColorManager *Project::color_manager()
{
return &color_manager_;
}
QList<ItemPtr> Project::get_items_of_type(Item::Type type) const
{
return root_.get_children_of_type(type, true);
}
bool Project::is_modified() const
{
return is_modified_;
}
void Project::set_modified(bool e)
{
is_modified_ = e;
autorecovery_saved_ = !e;
emit ModifiedChanged(is_modified_);
}
bool Project::has_autorecovery_been_saved() const
{
return autorecovery_saved_;
}
void Project::set_autorecovery_saved(bool e)
{
autorecovery_saved_ = e;
}
bool Project::is_new() const
{
return !is_modified_ && filename_.isEmpty();
}
OLIVE_NAMESPACE_EXIT