project: implemented autorecovery core

Not done yet, but nearly.
This commit is contained in:
itsmattkc
2021-04-01 13:10:43 +11:00
parent 6a841bde82
commit 0ee98a47ea
14 changed files with 504 additions and 56 deletions
+1
View File
@@ -16,6 +16,7 @@
add_subdirectory(about)
add_subdirectory(actionsearch)
add_subdirectory(autorecovery)
add_subdirectory(color)
add_subdirectory(configbase)
add_subdirectory(diskcache)
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2020 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/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
dialog/autorecovery/autorecoverydialog.h
dialog/autorecovery/autorecoverydialog.cpp
PARENT_SCOPE
)
@@ -0,0 +1,134 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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 "autorecoverydialog.h"
#include <QDateTime>
#include <QDialogButtonBox>
#include <QDir>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include "core.h"
namespace olive {
#define super QDialog
AutoRecoveryDialog::AutoRecoveryDialog(const QString &message, const QStringList &recoveries, bool autocheck_latest, QWidget* parent) :
QDialog(parent)
{
Init(message);
PopulateTree(recoveries, autocheck_latest);
}
void AutoRecoveryDialog::accept()
{
foreach (QTreeWidgetItem* checkable, checkable_items_) {
if (checkable->checkState(0) == Qt::Checked) {
QString filename = checkable->data(0, kFilenameRole).toString();
Core::instance()->OpenRecoveryProject(filename);
}
}
super::accept();
}
void AutoRecoveryDialog::Init(const QString& header_text)
{
QVBoxLayout* layout = new QVBoxLayout(this);
setWindowTitle(tr("Auto-Recovery"));
layout->addWidget(new QLabel(header_text));
tree_widget_ = new QTreeWidget();
tree_widget_->setHeaderHidden(true);
layout->addWidget(tree_widget_);
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
buttons->button(QDialogButtonBox::Ok)->setText(tr("Load"));
connect(buttons, &QDialogButtonBox::accepted, this, &AutoRecoveryDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &AutoRecoveryDialog::reject);
layout->addWidget(buttons);
}
void AutoRecoveryDialog::PopulateTree(const QStringList& recoveries, bool autocheck_latest)
{
// Each entry in `recoveries` is a directory with 1+ recovery projects in it
foreach (const QString& recovery_folder, recoveries) {
QDir recovery_dir(recovery_folder);
QString pretty_name;
{
// Retrieve pretty name
QFile pretty_name_file(recovery_dir.filePath(QStringLiteral("realname.txt")));
if (pretty_name_file.open(QFile::ReadOnly)) {
// Read pretty name that we should have written in the autorecovery process
pretty_name = QString::fromUtf8(pretty_name_file.readAll());
pretty_name_file.close();
}
if (pretty_name.isEmpty()) {
// Fallback to just the UUID. While it won't mean much to the user, it's better than nothing.
pretty_name = recovery_dir.dirName();
}
}
QTreeWidgetItem* top_level = new QTreeWidgetItem(tree_widget_);
top_level->setText(0, pretty_name);
{
// Populate with recoveries
QStringList entries = recovery_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::Reversed);
for (int i=0; i<entries.size(); i++) {
const QString& entry = entries.at(i);
if (entry.endsWith(QStringLiteral(".ove"), Qt::CaseInsensitive)) {
QTreeWidgetItem* entry_item = new QTreeWidgetItem(top_level);
bool ok;
qint64 recovery_time = entry.left(entry.indexOf('.')).toLongLong(&ok);
QString entry_name;
if (ok) {
// Set as time/date of recovery
entry_name = QDateTime::fromSecsSinceEpoch(recovery_time).toString();
} else {
// Fallback if we couldn't discern a date from this
entry_name = entry;
}
entry_item->setText(0, entry_name);
entry_item->setData(0, kFilenameRole, recovery_dir.filePath(entry));
// Allow to be checked, auto-checking the first entry
entry_item->setCheckState(0, (autocheck_latest && top_level->childCount() == 1) ? Qt::Checked : Qt::Unchecked);
checkable_items_.append(entry_item);
}
}
}
}
}
}
@@ -0,0 +1,57 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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/>.
***/
#ifndef AUTORECOVERYDIALOG_H
#define AUTORECOVERYDIALOG_H
#include <QDialog>
#include <QTreeWidget>
#include "common/define.h"
namespace olive {
class AutoRecoveryDialog : public QDialog
{
Q_OBJECT
public:
AutoRecoveryDialog(const QString& message, const QStringList& recoveries, bool autocheck_latest, QWidget* parent);
public slots:
virtual void accept() override;
private:
void Init(const QString &header_text);
void PopulateTree(const QStringList &recoveries, bool autocheck);
QTreeWidget* tree_widget_;
QVector<QTreeWidgetItem*> checkable_items_;
enum DataRole {
kFilenameRole = Qt::UserRole
};
};
}
#endif // AUTORECOVERYDIALOG_H
@@ -21,6 +21,7 @@
#include "preferencesgeneraltab.h"
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
@@ -36,66 +37,116 @@ PreferencesGeneralTab::PreferencesGeneralTab()
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setMargin(0);
QGridLayout* general_layout = new QGridLayout();
layout->addLayout(general_layout);
{
QGroupBox* global_groupbox = new QGroupBox(tr("Locale"));
QGridLayout* global_layout = new QGridLayout(global_groupbox);
layout->addWidget(global_groupbox);
int row = 0;
int row = 0;
// General -> Language
general_layout->addWidget(new QLabel(tr("Language:")), row, 0);
// General -> Language
global_layout->addWidget(new QLabel(tr("Language:")), row, 0);
language_combobox_ = new QComboBox();
language_combobox_ = new QComboBox();
// Add default language (en-US)
QDir language_dir(QStringLiteral(":/ts"));
QStringList languages = language_dir.entryList();
foreach (const QString& l, languages) {
AddLanguage(l);
}
QString current_language = Config::Current()[QStringLiteral("Language")].toString();
if (current_language.isEmpty()) {
// No configured language, use system language
current_language = QLocale::system().name();
// If we don't have a language for this, default to en_US
if (!languages.contains(current_language)) {
current_language = QStringLiteral("en_US");
// Add default language (en-US)
QDir language_dir(QStringLiteral(":/ts"));
QStringList languages = language_dir.entryList();
foreach (const QString& l, languages) {
AddLanguage(l);
}
QString current_language = Config::Current()[QStringLiteral("Language")].toString();
if (current_language.isEmpty()) {
// No configured language, use system language
current_language = QLocale::system().name();
// If we don't have a language for this, default to en_US
if (!languages.contains(current_language)) {
current_language = QStringLiteral("en_US");
}
}
language_combobox_->setCurrentIndex(languages.indexOf(current_language));
global_layout->addWidget(language_combobox_, row, 1);
}
language_combobox_->setCurrentIndex(languages.indexOf(current_language));
general_layout->addWidget(language_combobox_, row, 1);
{
QGroupBox* timeline_groupbox = new QGroupBox(tr("Timeline"));
QGridLayout* timeline_layout = new QGridLayout(timeline_groupbox);
layout->addWidget(timeline_groupbox);
row++;
int row = 0;
general_layout->addWidget(new QLabel(tr("Auto-Scroll Method:")), row, 0);
timeline_layout->addWidget(new QLabel(tr("Auto-Scroll Method:")), row, 0);
// ComboBox indices match enum indices
autoscroll_method_ = new QComboBox();
autoscroll_method_->addItem(tr("None"), AutoScroll::kNone);
autoscroll_method_->addItem(tr("Page Scrolling"), AutoScroll::kPage);
autoscroll_method_->addItem(tr("Smooth Scrolling"), AutoScroll::kSmooth);
autoscroll_method_->setCurrentIndex(Config::Current()["Autoscroll"].toInt());
general_layout->addWidget(autoscroll_method_, row, 1);
// ComboBox indices match enum indices
autoscroll_method_ = new QComboBox();
autoscroll_method_->addItem(tr("None"), AutoScroll::kNone);
autoscroll_method_->addItem(tr("Page Scrolling"), AutoScroll::kPage);
autoscroll_method_->addItem(tr("Smooth Scrolling"), AutoScroll::kSmooth);
autoscroll_method_->setCurrentIndex(Config::Current()["Autoscroll"].toInt());
timeline_layout->addWidget(autoscroll_method_, row, 1);
row++;
row++;
general_layout->addWidget(new QLabel(tr("Rectified Waveforms:")), row, 0);
timeline_layout->addWidget(new QLabel(tr("Rectified Waveforms:")), row, 0);
rectified_waveforms_ = new QCheckBox();
rectified_waveforms_->setChecked(Config::Current()["RectifiedWaveforms"].toBool());
general_layout->addWidget(rectified_waveforms_, row, 1);
rectified_waveforms_ = new QCheckBox();
rectified_waveforms_->setChecked(Config::Current()["RectifiedWaveforms"].toBool());
timeline_layout->addWidget(rectified_waveforms_, row, 1);
row++;
row++;
general_layout->addWidget(new QLabel(tr("Default Still Image Length:")), row, 0);
timeline_layout->addWidget(new QLabel(tr("Default Still Image Length:")), row, 0);
default_still_length_ = new FloatSlider();
default_still_length_->SetMinimum(0.1);
default_still_length_->SetFormat(tr("%1 second(s)"));
default_still_length_->SetValue(Config::Current()["DefaultStillLength"].value<rational>().toDouble());
general_layout->addWidget(default_still_length_);
default_still_length_ = new FloatSlider();
default_still_length_->SetMinimum(0.1);
default_still_length_->SetFormat(tr("%1 second(s)"));
default_still_length_->SetValue(Config::Current()["DefaultStillLength"].value<rational>().toDouble());
timeline_layout->addWidget(default_still_length_);
}
{
QGroupBox* autorecovery_groupbox = new QGroupBox(tr("Auto-Recovery"));
QGridLayout* autorecovery_layout = new QGridLayout(autorecovery_groupbox);
layout->addWidget(autorecovery_groupbox);
int row = 0;
autorecovery_layout->addWidget(new QLabel(tr("Enable Auto-Recovery:")), row, 0);
autorecovery_enabled_ = new QCheckBox();
autorecovery_enabled_->setChecked(Config::Current()[QStringLiteral("AutorecoveryEnabled")].toBool());
autorecovery_layout->addWidget(autorecovery_enabled_, row, 1);
row++;
autorecovery_layout->addWidget(new QLabel(tr("Auto-Recovery Interval:")), row, 0);
autorecovery_interval_ = new IntegerSlider();
autorecovery_interval_->SetMinimum(1);
autorecovery_interval_->SetMaximum(60);
autorecovery_interval_->SetFormat(tr("%1 minute(s)"));
autorecovery_interval_->SetValue(Config::Current()[QStringLiteral("AutorecoveryInterval")].toLongLong());
autorecovery_layout->addWidget(autorecovery_interval_, row, 1);
row++;
autorecovery_layout->addWidget(new QLabel(tr("Maximum Versions Per Project:")), row, 0);
autorecovery_maximum_ = new IntegerSlider();
autorecovery_maximum_->SetMinimum(1);
autorecovery_maximum_->SetMaximum(1000);
autorecovery_maximum_->SetValue(Config::Current()[QStringLiteral("AutorecoveryMaximum")].toLongLong());
autorecovery_layout->addWidget(autorecovery_maximum_, row, 1);
row++;
QPushButton* browse_autorecoveries = new QPushButton(tr("Browse Auto-Recoveries"));
connect(browse_autorecoveries, &QPushButton::clicked, Core::instance(), &Core::BrowseAutoRecoveries);
autorecovery_layout->addWidget(browse_autorecoveries, row, 1);
}
layout->addStretch();
}
@@ -121,6 +172,11 @@ void PreferencesGeneralTab::Accept(MultiUndoCommand *command)
Config::Current()[QStringLiteral("Language")] = set_language;
Core::instance()->SetLanguage(set_language.isEmpty() ? QLocale::system().name() : set_language);
}
Config::Current()[QStringLiteral("AutorecoveryEnabled")] = autorecovery_enabled_->isChecked();
Config::Current()[QStringLiteral("AutorecoveryInterval")] = QVariant::fromValue(autorecovery_interval_->GetValue());
Config::Current()[QStringLiteral("AutorecoveryMaximum")] = QVariant::fromValue(autorecovery_maximum_->GetValue());
Core::instance()->SetAutorecoveryInterval(autorecovery_interval_->GetValue());
}
void PreferencesGeneralTab::AddLanguage(const QString &locale_name)
@@ -28,6 +28,7 @@
#include "dialog/configbase/configdialogbase.h"
#include "project/item/sequence/sequence.h"
#include "widget/slider/floatslider.h"
#include "widget/slider/integerslider.h"
namespace olive {
@@ -50,6 +51,12 @@ private:
FloatSlider* default_still_length_;
QCheckBox* autorecovery_enabled_;
IntegerSlider* autorecovery_interval_;
IntegerSlider* autorecovery_maximum_;
};
}