Skip to content

Commit

Permalink
Merge pull request #29 from UltraStar-Deluxe/fixes
Browse files Browse the repository at this point in the history
Signal/Slot fix and added support for sync files (*.usdb).
  • Loading branch information
bohning authored Apr 18, 2024
2 parents 9a5aca1 + 80a39c6 commit c806a6b
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 49 deletions.
48 changes: 24 additions & 24 deletions src/QUMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,14 @@ void QUMainWindow::initRibbonBar() {
_menu->mediumVideoQualityComboBox->setCurrentIndex(_menu->mediumVideoQualityComboBox->findText(QString::number(QUSongSupport::mediumVideoQuality()), Qt::MatchStartsWith));
_menu->highVideoQualityComboBox->setCurrentIndex(_menu->highVideoQualityComboBox->findText(QString::number(QUSongSupport::highVideoQuality()), Qt::MatchStartsWith));

connect(_menu->mediumMp3QualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumMp3Quality(QString)));
connect(_menu->highMp3QualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighMp3Quality(QString)));
connect(_menu->mediumCoverQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumCoverQuality(QString)));
connect(_menu->highCoverQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighCoverQuality(QString)));
connect(_menu->mediumBackgroundQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumBackgroundQuality(QString)));
connect(_menu->highBackgroundQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighBackgroundQuality(QString)));
connect(_menu->mediumVideoQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumVideoQuality(QString)));
connect(_menu->highVideoQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighVideoQuality(QString)));
connect(_menu->mediumMp3QualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumMp3Quality(QString)));
connect(_menu->highMp3QualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighMp3Quality(QString)));
connect(_menu->mediumCoverQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumCoverQuality(QString)));
connect(_menu->highCoverQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighCoverQuality(QString)));
connect(_menu->mediumBackgroundQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumBackgroundQuality(QString)));
connect(_menu->highBackgroundQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighBackgroundQuality(QString)));
connect(_menu->mediumVideoQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumVideoQuality(QString)));
connect(_menu->highVideoQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighVideoQuality(QString)));

connect(_menu->langUsBtn, SIGNAL(clicked()), this, SLOT(enableEnglish()));
connect(_menu->langDeBtn, SIGNAL(clicked()), this, SLOT(enableGerman()));
Expand Down Expand Up @@ -1758,9 +1758,9 @@ void QUMainWindow::setMediumMp3Quality(QString quality) {

// ensure that highMp3Quality is at least one level higher
if(_menu->highMp3QualityComboBox->currentIndex() <= _menu->highMp3QualityComboBox->findText(quality)) {
disconnect(_menu->highMp3QualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighMp3Quality(QString)));
disconnect(_menu->highMp3QualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighMp3Quality(QString)));
_menu->highMp3QualityComboBox->setCurrentIndex(_menu->highMp3QualityComboBox->findText(quality) + 1);
connect(_menu->highMp3QualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighMp3Quality(QString)));
connect(_menu->highMp3QualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighMp3Quality(QString)));
settings.setValue("highMp3Quality", _menu->highMp3QualityComboBox->currentText().split(" ").first().toInt());
}

Expand All @@ -1785,9 +1785,9 @@ void QUMainWindow::setHighMp3Quality(QString quality) {
// ensure that mediumMp3Quality is at least one level lower
if(_menu->mediumMp3QualityComboBox->findText(quality) != -1) {
if(_menu->mediumMp3QualityComboBox->currentIndex() >= _menu->mediumMp3QualityComboBox->findText(quality)) {
disconnect(_menu->mediumMp3QualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumMp3Quality(QString)));
disconnect(_menu->mediumMp3QualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumMp3Quality(QString)));
_menu->mediumMp3QualityComboBox->setCurrentIndex(_menu->mediumMp3QualityComboBox->findText(quality) - 1);
connect(_menu->mediumMp3QualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumMp3Quality(QString)));
connect(_menu->mediumMp3QualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumMp3Quality(QString)));
settings.setValue("mediumMp3Quality", _menu->mediumMp3QualityComboBox->currentText().split(" ").first().toInt());
}
}
Expand All @@ -1813,9 +1813,9 @@ void QUMainWindow::setMediumCoverQuality(QString quality) {

// ensure that highCoverQuality is at least one level higher
if(_menu->highCoverQualityComboBox->currentIndex() <= _menu->highCoverQualityComboBox->findText(quality)) {
disconnect(_menu->highCoverQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighCoverQuality(QString)));
disconnect(_menu->highCoverQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighCoverQuality(QString)));
_menu->highCoverQualityComboBox->setCurrentIndex(_menu->highCoverQualityComboBox->findText(quality) + 1);
connect(_menu->highCoverQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighCoverQuality(QString)));
connect(_menu->highCoverQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighCoverQuality(QString)));
settings.setValue("highCoverQuality", _menu->highCoverQualityComboBox->currentText().split(" ").first().toInt());
}

Expand All @@ -1840,9 +1840,9 @@ void QUMainWindow::setHighCoverQuality(QString quality) {
// ensure that mediumCoverQuality is at least one level lower
if(_menu->mediumCoverQualityComboBox->findText(quality) != -1) {
if(_menu->mediumCoverQualityComboBox->currentIndex() >= _menu->mediumCoverQualityComboBox->findText(quality)) {
disconnect(_menu->mediumCoverQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumCoverQuality(QString)));
disconnect(_menu->mediumCoverQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumCoverQuality(QString)));
_menu->mediumCoverQualityComboBox->setCurrentIndex(_menu->mediumCoverQualityComboBox->findText(quality) - 1);
connect(_menu->mediumCoverQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumCoverQuality(QString)));
connect(_menu->mediumCoverQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumCoverQuality(QString)));
settings.setValue("mediumCoverQuality", _menu->mediumCoverQualityComboBox->currentText().split(" ").first().toInt());
}
}
Expand All @@ -1867,9 +1867,9 @@ void QUMainWindow::setMediumBackgroundQuality(QString quality) {

// ensure that highBackgroundQuality is at least one level higher
if(_menu->highBackgroundQualityComboBox->currentIndex() <= _menu->highBackgroundQualityComboBox->findText(quality)) {
disconnect(_menu->highBackgroundQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighBackgroundQuality(QString)));
disconnect(_menu->highBackgroundQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighBackgroundQuality(QString)));
_menu->highBackgroundQualityComboBox->setCurrentIndex(_menu->highBackgroundQualityComboBox->findText(quality) + 1);
connect(_menu->highBackgroundQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighBackgroundQuality(QString)));
connect(_menu->highBackgroundQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighBackgroundQuality(QString)));
settings.setValue("highBackgroundQuality", _menu->highBackgroundQualityComboBox->currentText().split(" ").first().toInt());
}

Expand All @@ -1894,9 +1894,9 @@ void QUMainWindow::setHighBackgroundQuality(QString quality) {
// ensure that mediumBackgroundQuality is at least one level lower
if(_menu->mediumBackgroundQualityComboBox->findText(quality) != -1) {
if(_menu->mediumBackgroundQualityComboBox->currentIndex() >= _menu->mediumBackgroundQualityComboBox->findText(quality)) {
disconnect(_menu->mediumBackgroundQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumBackgroundQuality(QString)));
disconnect(_menu->mediumBackgroundQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumBackgroundQuality(QString)));
_menu->mediumBackgroundQualityComboBox->setCurrentIndex(_menu->mediumBackgroundQualityComboBox->findText(quality) - 1);
connect(_menu->mediumBackgroundQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumBackgroundQuality(QString)));
connect(_menu->mediumBackgroundQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumBackgroundQuality(QString)));
settings.setValue("mediumBackgroundQuality", _menu->mediumBackgroundQualityComboBox->currentText().split(" ").first().toInt());
}
}
Expand All @@ -1921,9 +1921,9 @@ void QUMainWindow::setMediumVideoQuality(QString quality) {

// ensure that highVideoQuality is at least one level higher
if(_menu->highVideoQualityComboBox->currentIndex() <= _menu->highVideoQualityComboBox->findText(quality)) {
disconnect(_menu->highVideoQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighVideoQuality(QString)));
disconnect(_menu->highVideoQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighVideoQuality(QString)));
_menu->highVideoQualityComboBox->setCurrentIndex(_menu->highVideoQualityComboBox->findText(quality) + 1);
connect(_menu->highVideoQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setHighVideoQuality(QString)));
connect(_menu->highVideoQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setHighVideoQuality(QString)));
settings.setValue("highVideoQuality", _menu->highVideoQualityComboBox->currentText().split(" ").first().toInt());
}

Expand All @@ -1948,9 +1948,9 @@ void QUMainWindow::setHighVideoQuality(QString quality) {
// ensure that mediumVideoQuality is at least one level lower
if(_menu->mediumVideoQualityComboBox->findText(quality) != -1) {
if(_menu->mediumVideoQualityComboBox->currentIndex() >= _menu->mediumVideoQualityComboBox->findText(quality)) {
disconnect(_menu->mediumVideoQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumVideoQuality(QString)));
disconnect(_menu->mediumVideoQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumVideoQuality(QString)));
_menu->mediumVideoQualityComboBox->setCurrentIndex(_menu->mediumVideoQualityComboBox->findText(quality) - 1);
connect(_menu->mediumVideoQualityComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setMediumVideoQuality(QString)));
connect(_menu->mediumVideoQualityComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setMediumVideoQuality(QString)));
settings.setValue("mediumVideoQuality", _menu->mediumVideoQualityComboBox->currentText().split(" ").first().toInt());
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/QUSongSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ QStringList QUSongSupport::allowedVocaluxePlaylistFiles() {
return registryKey("allowedVocaluxePlaylistFiles", "*.xml");
}

QStringList QUSongSupport::allowedSyncFiles() {
return registryKey("allowedSyncFiles", "*.usdb");
}

QStringList QUSongSupport::allowedEncodingTypes() {
QStringList result;

Expand Down
1 change: 1 addition & 0 deletions src/QUSongSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class QUSongSupport: QObject {
static QStringList allowedPlaylistFiles();
static QStringList allowedUltraStarPlaylistFiles();
static QStringList allowedVocaluxePlaylistFiles();
static QStringList allowedSyncFiles();

static QStringList allowedEncodingTypes();
static QStringList availableSongLanguages();
Expand Down
68 changes: 68 additions & 0 deletions src/preview/QUPreviewTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ using namespace MediaInfoLib;
#include <QMessageBox>
#include <QImage>
#include <QTextStream>
#include <QJsonDocument>
#include <QJsonObject>

#include <QDebug>
#include <codecvt>
Expand Down Expand Up @@ -75,6 +77,7 @@ QUPreviewTree::QUPreviewTree(QWidget *parent): QTreeWidget(parent) {
types->addChild(this->createInfoItem(QIcon(":/types/midi.png"), tr("MIDI"), QUSongSupport::allowedMidiFiles().join(" ")));
types->addChild(this->createInfoItem(QIcon(":/types/midi_kar.png"), tr("Karaoke"),QUSongSupport::allowedKaraokeFiles().join(" ")));
types->addChild(this->createInfoItem(QIcon(":/types/score.png"), tr("Score"), QUSongSupport::allowedScoreFiles().join(" ")));
types->addChild(this->createInfoItem(QIcon(":/types/sync.png"), tr("Sync"), QUSongSupport::allowedSyncFiles().join(" ")));
types->addChild(this->createInfoItem("", ""));

// set up "dir" toplevel item
Expand Down Expand Up @@ -142,6 +145,19 @@ QUPreviewTree::QUPreviewTree(QWidget *parent): QTreeWidget(parent) {
video->setExpanded(true);
video->setHidden(true);

// set up "sync" toplevel item

sync = new QTreeWidgetItem();
this->addTopLevelItem(sync);

sync->setText(0, tr("Sync File Information"));
sync->setFlags(Qt::ItemIsEnabled);
sync->setForeground(0, Qt::darkGray);
sync->setFirstColumnSpanned(true);

sync->setExpanded(true);
sync->setHidden(true);

// set up "file" toplevel item

file = new QTreeWidgetItem();
Expand Down Expand Up @@ -230,13 +246,15 @@ void QUPreviewTree::showFileInformation(const QFileInfo &fi, bool deleteAndHide)
qDeleteAll(audio->takeChildren());
qDeleteAll(video->takeChildren());
qDeleteAll(text->takeChildren());
qDeleteAll(sync->takeChildren());
qDeleteAll(dir->takeChildren());

file->setHidden(true);
image->setHidden(true);
audio->setHidden(true);
video->setHidden(true);
text->setHidden(true);
sync->setHidden(true);
dir->setHidden(true);
}

Expand All @@ -261,6 +279,8 @@ void QUPreviewTree::showFileInformation(const QFileInfo &fi, bool deleteAndHide)
showSimpleFileInformation(fi, tr("playlist file"));
else if(QUSongSupport::allowedScoreFiles().contains(fileScheme, Qt::CaseInsensitive))
showSimpleFileInformation(fi, tr("score file"));
else if(QUSongSupport::allowedSyncFiles().contains(fileScheme, Qt::CaseInsensitive))
showSyncFileInformation(fi);
} else {
showDirectoryFileInformation(fi);
}
Expand Down Expand Up @@ -531,6 +551,54 @@ void QUPreviewTree::showTextFileInformation(const QFileInfo &fi) {
text->setHidden(false);
}

void QUPreviewTree::showSyncFileInformation(const QFileInfo &fi) {
sync->addChild(this->createInfoItem(tr("Filename"), fi.fileName()));
sync->addChild(this->createInfoItem(tr("Size"), QString("%1 KiB").arg(fi.size() / 1024., 0, 'f', 2)));
QFile file(fi.filePath());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
logSrv->add(QString("Failed to open sync file: " + fi.absoluteFilePath()), QU::Error);
return;
}

QByteArray jsonData = file.readAll();
file.close();

// Parse JSON data
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &error);
if (jsonDoc.isNull())
{
logSrv->add(QString("Failed to parse JSON: " + error.errorString()), QU::Error);
return;
}

// Get the root object
QJsonObject jsonObj = jsonDoc.object();

// Access values from the JSON object
int songId = jsonObj["song_id"].toInt();
QStringList metaTags = jsonObj["meta_tags"].toString().split(",");
bool pinned = jsonObj["pinned"].toBool();
int version = jsonObj["version"].toInt();

// Access nested objects
//QJsonObject txtObj = jsonObj["txt"].toObject();
//QString txtFileName = txtObj["fname"].toString();
//QString txtResource = txtObj["resource"].toString();

sync->addChild(this->createInfoItem("Song ID", QString::number(songId)));
sync->addChild(this->createInfoItem("Metatags", metaTags.first()));
for (int i = 1; i < metaTags.size(); ++i) {
sync->addChild(createInfoItem("", metaTags[i]));
}
sync->addChild(this->createInfoItem("Pinned", QVariant(pinned).toString()));
sync->addChild(this->createInfoItem("Version", QString::number(version)));

sync->addChild(this->createInfoItem("", ""));
sync->setHidden(false);
}

void QUPreviewTree::showSimpleFileInformation(const QFileInfo &fi, const QString type) {
file->addChild(this->createInfoItem(tr("Filename"), fi.fileName()));
file->addChild(this->createInfoItem(tr("Type"), type));
Expand Down
2 changes: 2 additions & 0 deletions src/preview/QUPreviewTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public slots:
QTreeWidgetItem *video;
QTreeWidgetItem *text;
QTreeWidgetItem *dir;
QTreeWidgetItem *sync;

QTreeWidgetItem* createInfoItem(const QString &tag, const QString &value);
QTreeWidgetItem* createInfoItem(const QIcon &icon, const QString &tag, const QString &value);
Expand All @@ -54,6 +55,7 @@ public slots:
void showTextFileInformation(const QFileInfo &fi);
void showSimpleFileInformation(const QFileInfo &fi, const QString type);
void showDirectoryFileInformation(const QFileInfo &fi);
void showSyncFileInformation(const QFileInfo &fi);

void showSelectedLength(QTreeWidgetItem *child, int seconds);
};
Expand Down
1 change: 1 addition & 0 deletions src/resources/UltraStar-Manager.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
<file>source.png</file>
<file>rap_notes.png</file>
<file>writeID3.png</file>
<file>sync.png</file>
</qresource>
<qresource prefix="/big">
<file>save_big.png</file>
Expand Down
Binary file added src/resources/sync.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions src/songtree/QUSongItem.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#include "QUSongItem.h"

#include "QUSongTree.h"

#include "audioproperties.h"
#include "fileref.h"
#include "tag.h"
#include "tstring.h"
#include "MediaInfo/MediaInfo.h"
using namespace MediaInfoLib;

Expand Down Expand Up @@ -91,6 +87,8 @@ void QUSongItem::update() {
child->updateAsKaraoke();
} else if(QUSongSupport::allowedScoreFiles().contains(fileScheme, Qt::CaseInsensitive)) {
child->updateAsScore();
} else if(QUSongSupport::allowedSyncFiles().contains(fileScheme, Qt::CaseInsensitive)) {
child->updateAsSync();
} else {
child->updateAsUnknown();
}
Expand Down Expand Up @@ -314,6 +312,17 @@ void QUSongItem::updateAsScore() {
(dynamic_cast<QUSongItem*>(this->parent()))->showUnusedFilesIcon(this->text(FOLDER_COLUMN));
}

void QUSongItem::updateAsSync() {
clearContents();

this->setIcon(FOLDER_COLUMN, QIcon(":/types/sync.png"));
(dynamic_cast<QUSongItem*>(this->parent()))->setData(SYNC_COLUMN, Qt::UserRole, QVariant(-1));
(dynamic_cast<QUSongItem*>(this->parent()))->setIcon(SYNC_COLUMN, QIcon(":/types/sync.png"));

// special files, special color ^_^
// this->setTextColor(FOLDER_COLUMN, Qt::darkGreen);
}

void QUSongItem::updateAsUnknown() {
this->setIcon(FOLDER_COLUMN, QIcon(":/types/file.png"));
this->setForeground(FOLDER_COLUMN, Qt::gray);
Expand Down Expand Up @@ -579,6 +588,7 @@ bool QUSongItem::operator< (const QTreeWidgetItem &other) const {
case UNUSED_FILES_COLUMN:
case MULTIPLE_SONGS_COLUMN:
case SCORE_COLUMN:
case SYNC_COLUMN:
case LENGTH_COLUMN:
case LENGTH_DIFF_COLUMN:
case LENGTH_MP3_COLUMN:
Expand Down Expand Up @@ -675,6 +685,10 @@ void QUSongItem::updateFileCheckColumns() {
// score files
if(song()->score())
this->setIcon(SCORE_COLUMN, QIcon(":/types/score.png"));

// sync files
//if(song()->sync())
// this->setIcon(SYNC_COLUMN, QIcon(":/types/sync.png"));
}

void QUSongItem::updateTypeColumns() {
Expand Down
Loading

0 comments on commit c806a6b

Please sign in to comment.