Add option to preserve "modification date" on file saving for UI
See https://github.com/Martchus/tageditor/issues/67
This commit is contained in:
parent
fef97aa1db
commit
1e084f8eae
|
@ -128,6 +128,8 @@ void restore()
|
|||
v.tagPocessing.unsupportedFieldHandling = UnsupportedFieldHandling::Ignore;
|
||||
}
|
||||
v.tagPocessing.autoTagManagement = settings.value(QStringLiteral("autotagmanagement"), true).toBool();
|
||||
v.tagPocessing.preserveModificationTime
|
||||
= settings.value(QStringLiteral("preservemodificationtime"), v.tagPocessing.preserveModificationTime).toBool();
|
||||
settings.beginGroup(QStringLiteral("id3v1"));
|
||||
switch (settings.value(QStringLiteral("usage"), 0).toInt()) {
|
||||
case 1:
|
||||
|
@ -259,6 +261,7 @@ void save()
|
|||
settings.setValue(QStringLiteral("preferredencoding"), static_cast<int>(v.tagPocessing.preferredEncoding));
|
||||
settings.setValue(QStringLiteral("unsupportedfieldhandling"), static_cast<int>(v.tagPocessing.unsupportedFieldHandling));
|
||||
settings.setValue(QStringLiteral("autotagmanagement"), v.tagPocessing.autoTagManagement);
|
||||
settings.setValue(QStringLiteral("preservemodificationtime"), v.tagPocessing.preserveModificationTime);
|
||||
settings.beginGroup(QStringLiteral("id3v1"));
|
||||
settings.setValue(QStringLiteral("usage"), static_cast<int>(v.tagPocessing.creationSettings.id3v1usage));
|
||||
settings.endGroup();
|
||||
|
|
|
@ -79,6 +79,7 @@ struct TagProcessing {
|
|||
TagParser::TagTextEncoding preferredEncoding = TagParser::TagTextEncoding::Utf8;
|
||||
UnsupportedFieldHandling unsupportedFieldHandling = UnsupportedFieldHandling::Ignore;
|
||||
bool autoTagManagement = true;
|
||||
bool preserveModificationTime = false;
|
||||
TagParser::TagCreationSettings creationSettings;
|
||||
FileLayout fileLayout;
|
||||
};
|
||||
|
|
|
@ -357,6 +357,7 @@ bool TagProcessingGeneralOptionPage::apply()
|
|||
settings.unsupportedFieldHandling = UnsupportedFieldHandling::Discard;
|
||||
}
|
||||
settings.autoTagManagement = ui()->autoTagManagementCheckBox->isChecked();
|
||||
settings.preserveModificationTime = ui()->preserveModificationTimeCheckBox->isChecked();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -391,6 +392,7 @@ void TagProcessingGeneralOptionPage::reset()
|
|||
break;
|
||||
}
|
||||
ui()->autoTagManagementCheckBox->setChecked(settings.autoTagManagement);
|
||||
ui()->preserveModificationTimeCheckBox->setChecked(settings.preserveModificationTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include <QtConcurrent>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -1161,7 +1162,7 @@ bool TagEditorWidget::startSaving()
|
|||
m_fileInfo.setMaxPadding(fileLayoutSettings.maxPadding);
|
||||
m_fileInfo.setPreferredPadding(fileLayoutSettings.preferredPadding);
|
||||
m_fileInfo.setBackupDirectory(settings.editor.backupDirectory);
|
||||
const auto startThread = [this] {
|
||||
const auto startThread = [this, preserveModificationTime = settings.tagPocessing.preserveModificationTime] {
|
||||
// define functions to show the saving progress and to actually applying the changes
|
||||
auto showPercentage([this](AbortableProgressFeedback &progress) {
|
||||
if (m_abortClicked) {
|
||||
|
@ -1183,6 +1184,13 @@ bool TagEditorWidget::startSaving()
|
|||
auto ioError = QString();
|
||||
auto processingError = false, canceled = false;
|
||||
try {
|
||||
auto modificationDateError = std::error_code();
|
||||
auto modificationDate = std::filesystem::file_time_type();
|
||||
auto modifiedFilePath = std::filesystem::path();
|
||||
if (preserveModificationTime) {
|
||||
modifiedFilePath = m_fileInfo.saveFilePath().empty() ? m_fileInfo.path() : m_fileInfo.saveFilePath();
|
||||
modificationDate = std::filesystem::last_write_time(modifiedFilePath, modificationDateError);
|
||||
}
|
||||
try {
|
||||
m_fileInfo.applyChanges(m_diag, progress);
|
||||
} catch (const OperationAbortedException &) {
|
||||
|
@ -1194,8 +1202,18 @@ bool TagEditorWidget::startSaving()
|
|||
ioError = tr("unknown error");
|
||||
}
|
||||
}
|
||||
if (preserveModificationTime) {
|
||||
if (!modificationDateError) {
|
||||
std::filesystem::last_write_time(modifiedFilePath, modificationDate, modificationDateError);
|
||||
}
|
||||
if (modificationDateError) {
|
||||
m_diag.emplace_back(
|
||||
DiagLevel::Critical, "Unable to preserve modification time: " + modificationDateError.message(), "applying changes");
|
||||
}
|
||||
}
|
||||
} catch (const exception &e) {
|
||||
m_diag.emplace_back(TagParser::DiagLevel::Critical, argsToString("Something completely unexpected happened: ", e.what()), "making");
|
||||
m_diag.emplace_back(
|
||||
TagParser::DiagLevel::Critical, argsToString("Something completely unexpected happened: ", e.what()), "applying changes");
|
||||
processingError = true;
|
||||
}
|
||||
QMetaObject::invokeMethod(
|
||||
|
|
|
@ -98,21 +98,45 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><span style="font-weight: bold;">Automatic tag management</span>
|
||||
<br>If enabled, appropriate tags will be created and removed according to the settings automatically when opening a file. Otherwise you have to do this manually (eg. adding an ID3 tag if none is present yet) and settings like ID3 usage have no effect.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
<widget class="QGroupBox" name="timestampsGroupBox_2">
|
||||
<property name="title">
|
||||
<string>Automatic tag management</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>If enabled, appropriate tags will be created and removed according to the settings automatically when opening a file. Otherwise you have to do this manually (eg. adding an ID3 tag if none is present yet) and settings like ID3 usage have no effect.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="autoTagManagementCheckBox">
|
||||
<property name="text">
|
||||
<string>Enable automatic tag management (default)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="autoTagManagementCheckBox">
|
||||
<property name="text">
|
||||
<string>Enable automatic tag management (default)</string>
|
||||
<widget class="QGroupBox" name="timestampsGroupBox">
|
||||
<property name="title">
|
||||
<string>Timestamps</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="preserveModificationTimeCheckBox">
|
||||
<property name="text">
|
||||
<string>Preserve modification time</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -133,7 +157,7 @@
|
|||
<resources/>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="preferredTextEncodingButtonGroup"/>
|
||||
<buttongroup name="unsupportedButtonGroup"/>
|
||||
<buttongroup name="preferredTextEncodingButtonGroup"/>
|
||||
</buttongroups>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in New Issue