Disable automatic conversions from 8-bit strings
This commit is contained in:
@@ -248,7 +248,7 @@ void Organize::ProcessSomeFiles() {
|
||||
}
|
||||
|
||||
if (!job.cover_source_.isEmpty()) {
|
||||
job.cover_dest_ = QFileInfo(job.destination_).path() + "/" + QFileInfo(job.cover_source_).fileName();
|
||||
job.cover_dest_ = QFileInfo(job.destination_).path() + QLatin1Char('/') + QFileInfo(job.cover_source_).fileName();
|
||||
}
|
||||
|
||||
job.progress_ = std::bind(&Organize::SetSongProgress, this, std::placeholders::_1, !task.transcoded_filename_.isEmpty());
|
||||
@@ -258,7 +258,7 @@ void Organize::ProcessSomeFiles() {
|
||||
if (job.remove_original_ && song.is_collection_song() && destination_->source() == Song::Source::Collection) {
|
||||
// Notify other aspects of system that song has been invalidated
|
||||
QString root = destination_->LocalPath();
|
||||
QFileInfo new_file = QFileInfo(root + "/" + task.song_info_.new_filename_);
|
||||
QFileInfo new_file = QFileInfo(root + QLatin1Char('/') + task.song_info_.new_filename_);
|
||||
emit SongPathChanged(song, new_file, destination_->collection_directory_id());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "core/iconloader.h"
|
||||
#include "core/musicstorage.h"
|
||||
#include "core/tagreaderclient.h"
|
||||
#include "core/settings.h"
|
||||
#include "utilities/strutils.h"
|
||||
#include "utilities/screenutils.h"
|
||||
#include "widgets/freespacebar.h"
|
||||
@@ -75,8 +76,10 @@
|
||||
|
||||
using std::make_unique;
|
||||
|
||||
constexpr char OrganizeDialog::kSettingsGroup[] = "OrganizeDialog";
|
||||
constexpr char OrganizeDialog::kDefaultFormat[] = "%albumartist/%album{ (Disc %disc)}/{%track - }{%albumartist - }%album{ (Disc %disc)} - %title.%extension";
|
||||
namespace {
|
||||
constexpr char kSettingsGroup[] = "OrganizeDialog";
|
||||
constexpr char kDefaultFormat[] = "%albumartist/%album{ (Disc %disc)}/{%track - }{%albumartist - }%album{ (Disc %disc)} - %title.%extension";
|
||||
}
|
||||
|
||||
OrganizeDialog::OrganizeDialog(SharedPtr<TaskManager> task_manager, SharedPtr<CollectionBackend> collection_backend, QWidget *parentwindow, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
@@ -213,7 +216,7 @@ void OrganizeDialog::LoadGeometry() {
|
||||
AdjustSize();
|
||||
}
|
||||
else {
|
||||
QSettings s;
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
if (s.contains("geometry")) {
|
||||
restoreGeometry(s.value("geometry").toByteArray());
|
||||
@@ -231,7 +234,7 @@ void OrganizeDialog::LoadGeometry() {
|
||||
void OrganizeDialog::SaveGeometry() {
|
||||
|
||||
if (parentwindow_) {
|
||||
QSettings s;
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("geometry", saveGeometry());
|
||||
s.endGroup();
|
||||
@@ -270,7 +273,7 @@ void OrganizeDialog::AdjustSize() {
|
||||
|
||||
void OrganizeDialog::RestoreDefaults() {
|
||||
|
||||
ui_->naming->setPlainText(kDefaultFormat);
|
||||
ui_->naming->setPlainText(QLatin1String(kDefaultFormat));
|
||||
ui_->remove_problematic->setChecked(true);
|
||||
ui_->remove_non_fat->setChecked(false);
|
||||
ui_->remove_non_ascii->setChecked(false);
|
||||
@@ -284,9 +287,9 @@ void OrganizeDialog::RestoreDefaults() {
|
||||
|
||||
void OrganizeDialog::LoadSettings() {
|
||||
|
||||
QSettings s;
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
ui_->naming->setPlainText(s.value("format", kDefaultFormat).toString());
|
||||
ui_->naming->setPlainText(s.value("format", QLatin1String(kDefaultFormat)).toString());
|
||||
ui_->remove_problematic->setChecked(s.value("remove_problematic", true).toBool());
|
||||
ui_->remove_non_fat->setChecked(s.value("remove_non_fat", false).toBool());
|
||||
ui_->remove_non_ascii->setChecked(s.value("remove_non_ascii", false).toBool());
|
||||
@@ -310,7 +313,7 @@ void OrganizeDialog::LoadSettings() {
|
||||
|
||||
void OrganizeDialog::SaveSettings() {
|
||||
|
||||
QSettings s;
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("format", ui_->naming->toPlainText());
|
||||
s.setValue("remove_problematic", ui_->remove_problematic->isChecked());
|
||||
@@ -430,7 +433,7 @@ void OrganizeDialog::SetPlaylist(const QString &playlist) {
|
||||
}
|
||||
|
||||
void OrganizeDialog::InsertTag(const QString &tag) {
|
||||
ui_->naming->insertPlainText("%" + tag);
|
||||
ui_->naming->insertPlainText(QLatin1Char('%') + tag);
|
||||
}
|
||||
|
||||
Organize::NewSongInfoList OrganizeDialog::ComputeNewSongsFilenames(const SongList &songs, const OrganizeFormat &format, const QString &extension) {
|
||||
@@ -449,7 +452,7 @@ Organize::NewSongInfoList OrganizeDialog::ComputeNewSongsFilenames(const SongLis
|
||||
if (result.unique_filename) {
|
||||
if (filenames.contains(result.filename)) {
|
||||
QString song_number = QString::number(++filenames[result.filename]);
|
||||
result.filename = Utilities::PathWithoutFilenameExtension(result.filename) + "(" + song_number + ")." + QFileInfo(result.filename).suffix();
|
||||
result.filename = Utilities::PathWithoutFilenameExtension(result.filename) + QStringLiteral("(") + song_number + QStringLiteral(").") + QFileInfo(result.filename).suffix();
|
||||
}
|
||||
else {
|
||||
filenames.insert(result.filename, 1);
|
||||
@@ -529,7 +532,7 @@ void OrganizeDialog::UpdatePreviews() {
|
||||
ui_->groupbox_naming->setVisible(has_local_destination);
|
||||
if (has_local_destination) {
|
||||
for (const Organize::NewSongInfo &song_info : new_songs_info_) {
|
||||
QString filename = storage->LocalPath() + "/" + song_info.new_filename_;
|
||||
QString filename = storage->LocalPath() + QLatin1Char('/') + song_info.new_filename_;
|
||||
QListWidgetItem *item = new QListWidgetItem(song_info.unique_filename_ ? IconLoader::Load(QStringLiteral("dialog-ok-apply")) : IconLoader::Load(QStringLiteral("dialog-warning")), QDir::toNativeSeparators(filename), ui_->preview);
|
||||
ui_->preview->addItem(item);
|
||||
if (!song_info.unique_filename_) {
|
||||
|
||||
@@ -105,9 +105,6 @@ class OrganizeDialog : public QDialog {
|
||||
void AllowExtASCII(const bool checked);
|
||||
|
||||
private:
|
||||
static const char kSettingsGroup[];
|
||||
static const char kDefaultFormat[];
|
||||
|
||||
QWidget *parentwindow_;
|
||||
Ui_OrganizeDialog *ui_;
|
||||
SharedPtr<TaskManager> task_manager_;
|
||||
|
||||
@@ -43,8 +43,10 @@
|
||||
|
||||
#include "organizeformat.h"
|
||||
|
||||
constexpr char OrganizeFormat::kBlockPattern[] = "\\{([^{}]+)\\}";
|
||||
constexpr char OrganizeFormat::kTagPattern[] = "\\%([a-zA-Z]*)";
|
||||
namespace {
|
||||
constexpr char kBlockPattern[] = "\\{([^{}]+)\\}";
|
||||
constexpr char kTagPattern[] = "\\%([a-zA-Z]*)";
|
||||
}
|
||||
|
||||
const QStringList OrganizeFormat::kKnownTags = QStringList() << QStringLiteral("title")
|
||||
<< QStringLiteral("album")
|
||||
@@ -88,7 +90,7 @@ OrganizeFormat::OrganizeFormat(const QString &format)
|
||||
|
||||
void OrganizeFormat::set_format(const QString &v) {
|
||||
format_ = v;
|
||||
format_.replace('\\', '/');
|
||||
format_.replace(QLatin1Char('\\'), QLatin1Char('/'));
|
||||
}
|
||||
|
||||
bool OrganizeFormat::IsValid() const {
|
||||
@@ -119,21 +121,21 @@ OrganizeFormat::GetFilenameForSongResult OrganizeFormat::GetFilenameForSong(cons
|
||||
filepath.clear();
|
||||
if (!path.isEmpty()) {
|
||||
filepath.append(path);
|
||||
if (path.right(1) != '/') {
|
||||
filepath.append('/');
|
||||
if (path.right(1) != QLatin1Char('/')) {
|
||||
filepath.append(QLatin1Char('/'));
|
||||
}
|
||||
}
|
||||
filepath.append(song.basefilename());
|
||||
}
|
||||
}
|
||||
|
||||
if (filepath.isEmpty() || (filepath.contains('/') && (filepath.section('/', 0, -2).isEmpty() || filepath.section('/', 0, -2).isEmpty()))) {
|
||||
if (filepath.isEmpty() || (filepath.contains(QLatin1Char('/')) && (filepath.section(QLatin1Char('/'), 0, -2).isEmpty() || filepath.section(QLatin1Char('/'), 0, -2).isEmpty()))) {
|
||||
return GetFilenameForSongResult();
|
||||
}
|
||||
|
||||
if (remove_problematic_) filepath = filepath.remove(QRegularExpression(QString(kProblematicCharactersRegex), QRegularExpression::PatternOption::CaseInsensitiveOption));
|
||||
if (remove_problematic_) filepath = filepath.remove(QRegularExpression(QLatin1String(kProblematicCharactersRegex), QRegularExpression::PatternOption::CaseInsensitiveOption));
|
||||
if (remove_non_fat_ || (remove_non_ascii_ && !allow_ascii_ext_)) filepath = Utilities::Transliterate(filepath);
|
||||
if (remove_non_fat_) filepath = filepath.remove(QRegularExpression(QString(kInvalidFatCharactersRegex), QRegularExpression::PatternOption::CaseInsensitiveOption));
|
||||
if (remove_non_fat_) filepath = filepath.remove(QRegularExpression(QLatin1String(kInvalidFatCharactersRegex), QRegularExpression::PatternOption::CaseInsensitiveOption));
|
||||
|
||||
if (remove_non_ascii_) {
|
||||
int ascii = 128;
|
||||
@@ -168,9 +170,9 @@ OrganizeFormat::GetFilenameForSongResult OrganizeFormat::GetFilenameForSong(cons
|
||||
extension = info.suffix();
|
||||
}
|
||||
}
|
||||
if (!info.path().isEmpty() && info.path() != ".") {
|
||||
if (!info.path().isEmpty() && info.path() != QStringLiteral(".")) {
|
||||
filepath.append(info.path());
|
||||
filepath.append("/");
|
||||
filepath.append(QLatin1Char('/'));
|
||||
}
|
||||
filepath.append(info.completeBaseName());
|
||||
|
||||
@@ -180,7 +182,7 @@ OrganizeFormat::GetFilenameForSongResult OrganizeFormat::GetFilenameForSong(cons
|
||||
for (int i = 0; i < parts_old.count(); ++i) {
|
||||
QString part = parts_old[i];
|
||||
for (int j = 0; j < kInvalidPrefixCharactersCount; ++j) {
|
||||
if (part.startsWith(kInvalidPrefixCharacters[j])) {
|
||||
if (part.startsWith(QLatin1Char(kInvalidPrefixCharacters[j]))) {
|
||||
part = part.remove(0, 1);
|
||||
break;
|
||||
}
|
||||
@@ -204,7 +206,7 @@ QString OrganizeFormat::ParseBlock(QString block, const Song &song, bool *have_t
|
||||
|
||||
// Find any blocks first
|
||||
qint64 pos = 0;
|
||||
const QRegularExpression block_regexp(kBlockPattern);
|
||||
const QRegularExpression block_regexp(QString::fromLatin1(kBlockPattern));
|
||||
QRegularExpressionMatch re_match;
|
||||
for (re_match = block_regexp.match(block, pos); re_match.hasMatch(); re_match = block_regexp.match(block, pos)) {
|
||||
pos = re_match.capturedStart();
|
||||
@@ -221,7 +223,7 @@ QString OrganizeFormat::ParseBlock(QString block, const Song &song, bool *have_t
|
||||
// Now look for tags
|
||||
bool empty = false;
|
||||
pos = 0;
|
||||
const QRegularExpression tag_regexp(kTagPattern);
|
||||
const QRegularExpression tag_regexp(QString::fromLatin1(kTagPattern));
|
||||
for (re_match = tag_regexp.match(block, pos); re_match.hasMatch(); re_match = tag_regexp.match(block, pos)) {
|
||||
pos = re_match.capturedStart();
|
||||
const QString tag = re_match.captured(1);
|
||||
@@ -249,79 +251,79 @@ QString OrganizeFormat::TagValue(const QString &tag, const Song &song) const {
|
||||
|
||||
QString value;
|
||||
|
||||
if (tag == "title") {
|
||||
if (tag == QStringLiteral("title")) {
|
||||
value = song.title();
|
||||
}
|
||||
else if (tag == "album") {
|
||||
else if (tag == QStringLiteral("album")) {
|
||||
value = song.album();
|
||||
}
|
||||
else if (tag == "artist") {
|
||||
else if (tag == QStringLiteral("artist")) {
|
||||
value = song.artist();
|
||||
}
|
||||
else if (tag == "composer") {
|
||||
else if (tag == QStringLiteral("composer")) {
|
||||
value = song.composer();
|
||||
}
|
||||
else if (tag == "performer") {
|
||||
else if (tag == QStringLiteral("performer")) {
|
||||
value = song.performer();
|
||||
}
|
||||
else if (tag == "grouping") {
|
||||
else if (tag == QStringLiteral("grouping")) {
|
||||
value = song.grouping();
|
||||
}
|
||||
else if (tag == "lyrics") {
|
||||
else if (tag == QStringLiteral("lyrics")) {
|
||||
value = song.lyrics();
|
||||
}
|
||||
else if (tag == "genre") {
|
||||
else if (tag == QStringLiteral("genre")) {
|
||||
value = song.genre();
|
||||
}
|
||||
else if (tag == "comment") {
|
||||
else if (tag == QStringLiteral("comment")) {
|
||||
value = song.comment();
|
||||
}
|
||||
else if (tag == "year") {
|
||||
else if (tag == QStringLiteral("year")) {
|
||||
value = QString::number(song.year());
|
||||
}
|
||||
else if (tag == "originalyear") {
|
||||
else if (tag == QStringLiteral("originalyear")) {
|
||||
value = QString::number(song.effective_originalyear());
|
||||
}
|
||||
else if (tag == "track") {
|
||||
else if (tag == QStringLiteral("track")) {
|
||||
value = QString::number(song.track());
|
||||
}
|
||||
else if (tag == "disc") {
|
||||
else if (tag == QStringLiteral("disc")) {
|
||||
value = QString::number(song.disc());
|
||||
}
|
||||
else if (tag == "length") {
|
||||
else if (tag == QStringLiteral("length")) {
|
||||
value = QString::number(song.length_nanosec() / kNsecPerSec);
|
||||
}
|
||||
else if (tag == "bitrate") {
|
||||
else if (tag == QStringLiteral("bitrate")) {
|
||||
value = QString::number(song.bitrate());
|
||||
}
|
||||
else if (tag == "samplerate") {
|
||||
else if (tag == QStringLiteral("samplerate")) {
|
||||
value = QString::number(song.samplerate());
|
||||
}
|
||||
else if (tag == "bitdepth") {
|
||||
else if (tag == QStringLiteral("bitdepth")) {
|
||||
value = QString::number(song.bitdepth());
|
||||
}
|
||||
else if (tag == "extension") {
|
||||
else if (tag == QStringLiteral("extension")) {
|
||||
value = QFileInfo(song.url().toLocalFile()).suffix();
|
||||
}
|
||||
else if (tag == "artistinitial") {
|
||||
else if (tag == QStringLiteral("artistinitial")) {
|
||||
value = song.effective_albumartist().trimmed();
|
||||
if (!value.isEmpty()) {
|
||||
value.replace(QRegularExpression(QStringLiteral("^the\\s+"), QRegularExpression::CaseInsensitiveOption), QLatin1String(""));
|
||||
value = value[0].toUpper();
|
||||
}
|
||||
}
|
||||
else if (tag == "albumartist") {
|
||||
else if (tag == QStringLiteral("albumartist")) {
|
||||
value = song.is_compilation() ? QStringLiteral("Various Artists") : song.effective_albumartist();
|
||||
}
|
||||
|
||||
if (value == "0" || value == "-1") value = QLatin1String("");
|
||||
if (value == QStringLiteral("0") || value == QStringLiteral("-1")) value = QLatin1String("");
|
||||
|
||||
// Prepend a 0 to single-digit track numbers
|
||||
if (tag == "track" && value.length() == 1) value.prepend('0');
|
||||
if (tag == QStringLiteral("track") && value.length() == 1) value.prepend(QLatin1Char('0'));
|
||||
|
||||
// Replace characters that really shouldn't be in paths
|
||||
value = value.remove(QRegularExpression(QString(kInvalidDirCharactersRegex), QRegularExpression::PatternOption::CaseInsensitiveOption));
|
||||
if (remove_problematic_) value = value.remove('.');
|
||||
value = value.remove(QRegularExpression(QString::fromLatin1(kInvalidDirCharactersRegex), QRegularExpression::PatternOption::CaseInsensitiveOption));
|
||||
if (remove_problematic_) value = value.remove(QLatin1Char('.'));
|
||||
value = value.trimmed();
|
||||
|
||||
return value;
|
||||
@@ -335,10 +337,10 @@ QValidator::State OrganizeFormat::Validator::validate(QString &input, int&) cons
|
||||
// Make sure all the blocks match up
|
||||
int block_level = 0;
|
||||
for (int i = 0; i < input.length(); ++i) {
|
||||
if (input[i] == '{') {
|
||||
if (input[i] == QLatin1Char('{')) {
|
||||
++block_level;
|
||||
}
|
||||
else if (input[i] == '}') {
|
||||
else if (input[i] == QLatin1Char('}')) {
|
||||
--block_level;
|
||||
}
|
||||
|
||||
@@ -348,7 +350,7 @@ QValidator::State OrganizeFormat::Validator::validate(QString &input, int&) cons
|
||||
if (block_level != 0) return QValidator::Invalid;
|
||||
|
||||
// Make sure the tags are valid
|
||||
const QRegularExpression tag_regexp(kTagPattern);
|
||||
const QRegularExpression tag_regexp(QString::fromLatin1(kTagPattern));
|
||||
QRegularExpressionMatch re_match;
|
||||
qint64 pos = 0;
|
||||
for (re_match = tag_regexp.match(input, pos); re_match.hasMatch(); re_match = tag_regexp.match(input, pos)) {
|
||||
@@ -384,7 +386,7 @@ void OrganizeFormat::SyntaxHighlighter::highlightBlock(const QString &text) {
|
||||
setFormat(0, static_cast<int>(text.length()), QTextCharFormat());
|
||||
|
||||
// Blocks
|
||||
const QRegularExpression block_regexp(kBlockPattern);
|
||||
const QRegularExpression block_regexp(QString::fromLatin1(kBlockPattern));
|
||||
QRegularExpressionMatch re_match;
|
||||
qint64 pos = 0;
|
||||
for (re_match = block_regexp.match(text, pos); re_match.hasMatch(); re_match = block_regexp.match(text, pos)) {
|
||||
@@ -394,7 +396,7 @@ void OrganizeFormat::SyntaxHighlighter::highlightBlock(const QString &text) {
|
||||
}
|
||||
|
||||
// Tags
|
||||
const QRegularExpression tag_regexp(kTagPattern);
|
||||
const QRegularExpression tag_regexp(QString::fromLatin1(kTagPattern));
|
||||
pos = 0;
|
||||
for (re_match = tag_regexp.match(text, pos); re_match.hasMatch(); re_match = tag_regexp.match(text, pos)) {
|
||||
pos = re_match.capturedStart();
|
||||
|
||||
@@ -85,8 +85,6 @@ class OrganizeFormat {
|
||||
};
|
||||
|
||||
private:
|
||||
static const char kBlockPattern[];
|
||||
static const char kTagPattern[];
|
||||
static const QStringList kKnownTags;
|
||||
static const QStringList kUniqueTags;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user