From 740089b05a6dcb95ee442a2e370c2b795a518d97 Mon Sep 17 00:00:00 2001 From: Citlali del Rey Date: Wed, 7 Aug 2024 13:58:11 -0700 Subject: [PATCH 1/4] feat: add checkbox to initial settings ui --- gui/initialsettingswizard.ui | 158 +++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 65 deletions(-) diff --git a/gui/initialsettingswizard.ui b/gui/initialsettingswizard.ui index 91fd30ea..661fafe4 100644 --- a/gui/initialsettingswizard.ui +++ b/gui/initialsettingswizard.ui @@ -6,8 +6,8 @@ 0 0 - 668 - 607 + 1007 + 855 @@ -38,7 +38,6 @@ - 75 true @@ -50,10 +49,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -69,20 +68,20 @@ <p>Cantata is a feature-rich and user friendly client for Music Player Daemon (MPD). MPD is a flexible, powerful, server-side application for playing music.</p><p>For more information on MPD itself, please refer to the MPD website <a href="http://www.musicpd.org"><span style=" text-decoration: underline; color:#0000ff;">http://www.musicpd.org</span></a></p><p>This 'wizard' will guide you through the basic settings required for Cantata to function correctly.</p> - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true - Qt::NoTextInteraction + Qt::TextInteractionFlag::NoTextInteraction - Qt::Vertical + Qt::Orientation::Vertical @@ -100,7 +99,6 @@ - 75 true @@ -108,17 +106,17 @@ <p>Welcome to Cantata</p> - Qt::NoTextInteraction + Qt::TextInteractionFlag::NoTextInteraction - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -134,13 +132,13 @@ <p>Cantata is a feature-rich and user friendly client for Music Player Daemon (MPD). MPD is a flexible, powerful, server-side application for playing music. MPD may be started either system-wide, or on a per-user basis.<br/><br/>Please select how you would like to have Cantata initially connect to (or startup) MPD:</p> - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true - Qt::NoTextInteraction + Qt::TextInteractionFlag::NoTextInteraction @@ -172,7 +170,7 @@ <i>Select this option if your music collection is shared between users, your MPD instance is running on another machine, you already have a personal MPD setup, or you wish to enable access from other clients (e.g. MPDroid). If you select this option then Cantata itself cannot control the starting and stopping of the MPD server. You will therefore need to ensure that MPD is already configured and running.</i> - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true @@ -185,10 +183,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -217,7 +215,7 @@ <i>Select this option if your music collection is not shared with others, and you wish Cantata to configure and control the MPD instance. This setup will be exclusive to Cantata, and will <b>not</b> be accessible to other MPD clients (e.g. MPDroid)</i> - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true @@ -233,17 +231,17 @@ - If you wish to have an advanced MPD setup (e.g. multiple audio outputs, full DSD support, etc) then you <b>must</b> choose 'Standard' + If you wish to have an advanced MPD setup (e.g. multiple audio outputs, full DSD support, etc) then you <b>must</b> choose 'Standard' - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -259,20 +257,20 @@ For more information on MPD itself, please refer to the MPD website <a href="http://www.musicpd.org"><span style=" text-decoration: underline; color:#0000ff;">http://www.musicpd.org</span></a><br/><br/>This 'wizard' will guide you through the basic settings required for Cantata to function correctly. - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true - Qt::NoTextInteraction + Qt::TextInteractionFlag::NoTextInteraction - Qt::Vertical + Qt::Orientation::Vertical @@ -286,6 +284,45 @@ + + + + + + + 0 + 0 + + + + Migrate data from older versions of Cantata + + + + + + + + 0 + 0 + + + + true + + + <i>Data from Cantata v2 has been detected on your computer. Leave this box checked to copy the old data and preserve your preferences.</i> + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop + + + true + + + + + @@ -313,7 +350,6 @@ - 75 true @@ -325,10 +361,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -344,7 +380,7 @@ The settings below are the basic settings required by Cantata. Please enter the relevant details, and use the 'Connect' button to test the connection. - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true @@ -354,10 +390,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -370,7 +406,7 @@ - QFormLayout::ExpandingFieldsGrow + QFormLayout::FieldGrowthPolicy::ExpandingFieldsGrow @@ -384,9 +420,6 @@ - - 0 - @@ -418,7 +451,7 @@ - QLineEdit::Password + QLineEdit::EchoMode::Password @@ -441,7 +474,6 @@ - 75 true true @@ -450,7 +482,7 @@ - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -459,7 +491,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -488,7 +520,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -506,7 +538,6 @@ - 75 true @@ -518,10 +549,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -537,7 +568,7 @@ Please choose the folder containing your music collection. - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true @@ -547,10 +578,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -580,7 +611,6 @@ - 75 true true @@ -593,7 +623,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -615,7 +645,6 @@ - 75 true @@ -627,10 +656,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -646,23 +675,23 @@ <p>Cantata can download missing covers, and store these either in the music folder or within your personal cache folder.</p> - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true - Qt::NoTextInteraction + Qt::TextInteractionFlag::NoTextInteraction - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -696,7 +725,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -714,7 +743,6 @@ - 75 true @@ -726,10 +754,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -745,23 +773,23 @@ Cantata is now configured!<br/><br/>Cantata's configuration dialog maybe used to customise Cantata's appearance, as well as to add extra MPD hosts, etc. - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true - Qt::NoTextInteraction + Qt::TextInteractionFlag::NoTextInteraction - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -781,10 +809,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -797,7 +825,7 @@ - Qt::Vertical + Qt::Orientation::Vertical From fcba26faceb401f63cabe5469276f3f8e067f211 Mon Sep 17 00:00:00 2001 From: Citlali del Rey Date: Wed, 7 Aug 2024 14:10:42 -0700 Subject: [PATCH 2/4] feat: make initial wizard skip to end when migrating --- gui/initialsettingswizard.cpp | 16 ++++++++++++++++ gui/initialsettingswizard.h | 1 + 2 files changed, 17 insertions(+) diff --git a/gui/initialsettingswizard.cpp b/gui/initialsettingswizard.cpp index 18cb09db..7ef1fcb9 100644 --- a/gui/initialsettingswizard.cpp +++ b/gui/initialsettingswizard.cpp @@ -255,4 +255,20 @@ void InitialSettingsWizard::reject() QDialog::reject(); } +int InitialSettingsWizard::nextId() const { + switch(currentId()) { + case PAGE_INTRO: + if (migrateDataBox->isChecked()) { + return PAGE_END; + } + return PAGE_CONNECTION; + case PAGE_CONNECTION: + return PAGE_COVERS; + case PAGE_COVERS: + return PAGE_END; + default: + return -1; + } +} + #include "moc_initialsettingswizard.cpp" diff --git a/gui/initialsettingswizard.h b/gui/initialsettingswizard.h index 4c27a73f..90e80984 100644 --- a/gui/initialsettingswizard.h +++ b/gui/initialsettingswizard.h @@ -56,6 +56,7 @@ private Q_SLOTS: #endif private: + int nextId() const override; #ifdef Avahi_FOUND QPushButton* discoveryButton; #endif From 61bad5e01b184f4b83a6211979fa201c1a6b55ea Mon Sep 17 00:00:00 2001 From: Citlali del Rey Date: Wed, 7 Aug 2024 15:43:05 -0700 Subject: [PATCH 3/4] feat: #30 migrate data from older cantata versions --- gui/initialsettingswizard.cpp | 96 ++++++++++++++++++++++++++++++----- gui/main.cpp | 1 + 2 files changed, 85 insertions(+), 12 deletions(-) diff --git a/gui/initialsettingswizard.cpp b/gui/initialsettingswizard.cpp index 7ef1fcb9..07150cc0 100644 --- a/gui/initialsettingswizard.cpp +++ b/gui/initialsettingswizard.cpp @@ -35,9 +35,11 @@ #include "findmpddialog.h" #endif #include +#include #include #include #include +#include enum Pages { PAGE_INTRO, @@ -113,6 +115,26 @@ InitialSettingsWizard::InitialSettingsWizard(QWidget* p) hostLayout->insertWidget(hostLayout->count(), discoveryButton); connect(discoveryButton, &QPushButton::clicked, this, &InitialSettingsWizard::detectMPDs); #endif + + // Note that this type of migration is only relevant on Linux/other + // Unix systems. +#if !Q_OS_WIN && !Q_OS_MACOS + auto oldConfig = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/cantata"); + + if (oldConfig.exists()) { + migrateDataBox->setChecked(true); + } + else { + migrateDataBox->setChecked(false); + migrateDataBox->setDisabled(true); + migrateDataBoxLabel->setDisabled(true); + migrateDataBoxLabel->setText(tr("Data from an older version of Cantata is missing or cannot be located.")); + } +#else + migrateDataBox->hide(); + migrateDataBoxLabel->hide(); + migrateDataBox->setChecked(false); +#endif } InitialSettingsWizard::~InitialSettingsWizard() @@ -200,6 +222,55 @@ void InitialSettingsWizard::pageChanged(int p) fetchCovers->setChecked(Settings::self()->fetchCovers()); } } + if (PAGE_END == p) { + // Perform data migration. + if (migrateDataBox->isChecked()) { + auto oldConfig = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/cantata"); + auto oldCache = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/cantata"); + auto oldData = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/cantata"); + + auto newConfig = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/Cantata"); + auto newCache = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/Cantata"); + auto newData = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Cantata"); + + newConfig.removeRecursively(); + newCache.removeRecursively(); + newData.removeRecursively(); + + auto copyOpts = std::filesystem::copy_options::overwrite_existing | std::filesystem::copy_options::recursive; + + try { + std::filesystem::copy(oldConfig.absolutePath().toStdString(), newConfig.absolutePath().toStdString(), copyOpts); + std::filesystem::rename(newConfig.absolutePath().toStdString() + "/cantata.conf", newConfig.absolutePath().toStdString() + "/Cantata.conf"); + } + catch (std::filesystem::filesystem_error& e) { + qWarning() << "Failed to migrate config."; + qWarning() << e.what(); + } + + try { + std::filesystem::copy(oldCache.absolutePath().toStdString(), newCache.absolutePath().toStdString(), copyOpts); + } + catch (std::filesystem::filesystem_error& e) { + qWarning() << "Failed to migrate cache."; + qWarning() << e.what(); + } + + try { + std::filesystem::copy(oldData.absolutePath().toStdString(), newData.absolutePath().toStdString(), copyOpts); + } + catch (std::filesystem::filesystem_error& e) { + qWarning() << "Failed to migrate data."; + qWarning() << e.what(); + } + + auto app = QCoreApplication::applicationFilePath(); + auto args = QCoreApplication::arguments(); + auto pwd = QDir::currentPath(); + QProcess::startDetached(app, args, pwd); + QCoreApplication::exit(); + } + } button(NextButton)->setEnabled(PAGE_END != p); } @@ -255,19 +326,20 @@ void InitialSettingsWizard::reject() QDialog::reject(); } -int InitialSettingsWizard::nextId() const { - switch(currentId()) { - case PAGE_INTRO: - if (migrateDataBox->isChecked()) { - return PAGE_END; - } - return PAGE_CONNECTION; - case PAGE_CONNECTION: - return PAGE_COVERS; - case PAGE_COVERS: +int InitialSettingsWizard::nextId() const +{ + switch (currentId()) { + case PAGE_INTRO: + if (migrateDataBox->isChecked()) { return PAGE_END; - default: - return -1; + } + return PAGE_CONNECTION; + case PAGE_CONNECTION: + return PAGE_COVERS; + case PAGE_COVERS: + return PAGE_END; + default: + return -1; } } diff --git a/gui/main.cpp b/gui/main.cpp index 7994920d..9e688fb9 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -437,6 +437,7 @@ int main(int argc, char* argv[]) if (QDialog::Rejected == wz.exec()) { return 0; } + Settings::self()->save(); } else if (cmdLineParser.isSet(collectionOption)) { QString col = cmdLineParser.value(collectionOption); From a9741e33aa022df6fc44312694d79bd859676242 Mon Sep 17 00:00:00 2001 From: Citlali del Rey Date: Wed, 7 Aug 2024 15:49:29 -0700 Subject: [PATCH 4/4] fix: malformed preprocessor directive --- gui/initialsettingswizard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/initialsettingswizard.cpp b/gui/initialsettingswizard.cpp index 07150cc0..d54f9264 100644 --- a/gui/initialsettingswizard.cpp +++ b/gui/initialsettingswizard.cpp @@ -118,7 +118,7 @@ InitialSettingsWizard::InitialSettingsWizard(QWidget* p) // Note that this type of migration is only relevant on Linux/other // Unix systems. -#if !Q_OS_WIN && !Q_OS_MACOS +#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS) auto oldConfig = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/cantata"); if (oldConfig.exists()) {