From 53efb5d8ff3a1fa08adb334a415dba5be6e45505 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 31 Jan 2021 21:21:14 +0000 Subject: prepare for cue editor implementation git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9672 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/cue/cuefile.cpp | 20 ++++--- src/plugins/Input/cue/cuefile.h | 2 + src/plugins/Input/cue/cuemetadatamodel.cpp | 42 +++++++++++---- src/plugins/Input/cue/cuemetadatamodel.h | 6 ++- src/qmmpui/cueeditor.cpp | 85 ++++++++++++++++++++++++++++++ src/qmmpui/cueeditor_p.h | 53 +++++++++++++++++++ src/qmmpui/detailsdialog.cpp | 12 +++++ src/qmmpui/forms/cueeditor.ui | 75 ++++++++++++++++++++++++++ src/qmmpui/qmmpui.pro | 9 ++-- 9 files changed, 284 insertions(+), 20 deletions(-) create mode 100644 src/qmmpui/cueeditor.cpp create mode 100644 src/qmmpui/cueeditor_p.h create mode 100644 src/qmmpui/forms/cueeditor.ui (limited to 'src') diff --git a/src/plugins/Input/cue/cuefile.cpp b/src/plugins/Input/cue/cuefile.cpp index 5bcedff49..15b40093a 100644 --- a/src/plugins/Input/cue/cuefile.cpp +++ b/src/plugins/Input/cue/cuefile.cpp @@ -34,13 +34,16 @@ CueFile::CueFile(const QString &path) : CueParser() { - QString filePath = path; + m_filePath = path; + if(path.contains("://")) { - filePath.remove("cue://"); - filePath.remove(QRegularExpression("#\\d+$")); + m_filePath.remove("cue://"); + m_filePath.remove(QRegularExpression("#\\d+$")); } - QFile file(filePath); + qDebug("+%s+", qPrintable(m_filePath)); + + QFile file(m_filePath); if (!file.open(QIODevice::ReadOnly)) { qDebug("CueFile: error: %s", qPrintable(file.errorString())); @@ -81,10 +84,10 @@ CueFile::CueFile(const QString &path) : CueParser() settings.endGroup(); //qDebug("CUEParser: using %s encoding", codec->name().constData()); loadData(data, codec); - setUrl("cue", filePath); + setUrl("cue", m_filePath); for(const QString &dataFileName : files()) { - QString dataFilePath = getDirtyPath(filePath, QFileInfo(filePath).dir().filePath(dataFileName)); + QString dataFilePath = getDirtyPath(m_filePath, QFileInfo(m_filePath).dir().filePath(dataFileName)); m_dataFiles.insert(dataFileName, dataFilePath); QList pl = MetaDataManager::instance()->createPlayList(dataFilePath, TrackInfo::Properties); if(!pl.isEmpty()) @@ -110,6 +113,11 @@ CueFile::CueFile(const QString &path) : CueParser() CueFile::~CueFile() {} +QString CueFile::cueFilePath() const +{ + return m_filePath; +} + QString CueFile::dataFilePath(int track) const { return m_dataFiles.value(file(track)); diff --git a/src/plugins/Input/cue/cuefile.h b/src/plugins/Input/cue/cuefile.h index 96c26144e..673927c2c 100644 --- a/src/plugins/Input/cue/cuefile.h +++ b/src/plugins/Input/cue/cuefile.h @@ -38,6 +38,7 @@ public: explicit CueFile(const QString &path); ~CueFile(); + QString cueFilePath() const; QString dataFilePath(int track) const; QStringList dataFilePaths() const; @@ -46,6 +47,7 @@ private: QString getDirtyPath(const QString &cue_path, const QString &path); QMap m_dataFiles; //name, full path bool m_dirty; + QString m_filePath; }; diff --git a/src/plugins/Input/cue/cuemetadatamodel.cpp b/src/plugins/Input/cue/cuemetadatamodel.cpp index 676a8d936..8e58e47b6 100644 --- a/src/plugins/Input/cue/cuemetadatamodel.cpp +++ b/src/plugins/Input/cue/cuemetadatamodel.cpp @@ -18,31 +18,37 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include +#include #include #include "cuefile.h" #include "cuemetadatamodel.h" -CUEMetaDataModel::CUEMetaDataModel(const QString &url) : MetaDataModel(true) +CUEMetaDataModel::CUEMetaDataModel(const QString &url) : MetaDataModel(false, IsCueEditable) { - m_cueFile = new CueFile(url); - if (m_cueFile->count() == 0) + qDebug() << Q_FUNC_INFO << url; + + CueFile file(url); + if (file.isEmpty()) { qWarning("CUEMetaDataModel: invalid cue file"); return; } int track = url.section("#", -1).toInt(); - m_path = m_cueFile->dataFilePath(track); + m_dataFilePath = file.dataFilePath(track); + m_cueFilePath = file.cueFilePath(); + qDebug() << m_cueFilePath << url; + if(!QFileInfo(m_cueFilePath).isWritable()) + setReadOnly(true); } CUEMetaDataModel::~CUEMetaDataModel() -{ - delete m_cueFile; -} +{} QList CUEMetaDataModel::extraProperties() const { QList ep; - MetaDataModel *model = MetaDataManager::instance()->createMetaDataModel(m_path, true); + MetaDataModel *model = MetaDataManager::instance()->createMetaDataModel(m_dataFilePath, true); if(model) { ep = model->extraProperties(); @@ -53,5 +59,23 @@ QList CUEMetaDataModel::extraProperties() const QString CUEMetaDataModel::coverPath() const { - return MetaDataManager::instance()->findCoverFile(m_path); + return MetaDataManager::instance()->findCoverFile(m_dataFilePath); +} + +QString CUEMetaDataModel::cue() const +{ + qDebug() << m_cueFilePath; + QFile file(m_cueFilePath); + file.open(QIODevice::ReadOnly); + return QString::fromUtf8(file.readAll()); +} + +void CUEMetaDataModel::setCue(const QString &content) +{ + +} + +void CUEMetaDataModel::removeCue() +{ + } diff --git a/src/plugins/Input/cue/cuemetadatamodel.h b/src/plugins/Input/cue/cuemetadatamodel.h index 1f149687f..79186e10f 100644 --- a/src/plugins/Input/cue/cuemetadatamodel.h +++ b/src/plugins/Input/cue/cuemetadatamodel.h @@ -32,10 +32,12 @@ public: ~CUEMetaDataModel(); QList extraProperties() const override; QString coverPath() const override; + QString cue() const override; + void setCue(const QString &content) override; + void removeCue() override; private: - CueFile *m_cueFile; - QString m_path; + QString m_dataFilePath, m_cueFilePath; }; #endif // CUEMETADATAMODEL_H diff --git a/src/qmmpui/cueeditor.cpp b/src/qmmpui/cueeditor.cpp new file mode 100644 index 000000000..ae93ec6e2 --- /dev/null +++ b/src/qmmpui/cueeditor.cpp @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (C) 2021 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include "cueeditor_p.h" +#include "filedialog.h" +#include "ui_cueeditor.h" + +CueEditor::CueEditor(MetaDataModel *model, QWidget *parent) : + QWidget(parent), + m_ui(new Ui::CueEditor), + m_model(model) +{ + m_ui->setupUi(this); + m_ui->plainTextEdit->setPlainText(model->cue()); + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + m_lastDir = settings.value("CueEditor/last_dir", QDir::homePath()).toString(); +} + +CueEditor::~CueEditor() +{ + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.setValue("CueEditor/last_dir", m_lastDir); + + delete m_ui; +} + +void CueEditor::save() +{ + QString data = m_ui->plainTextEdit->toPlainText().trimmed(); + if(data.isEmpty()) + { + m_model->removeCue(); + } + else + { + data.append(QChar::LineFeed); + m_model->setCue(data); + } +} + +void CueEditor::on_loadButton_clicked() +{ + QString path = FileDialog::getOpenFileName(this, tr("Open CUE File"), + m_lastDir, + tr("CUE Files") +" (*.cue)"); + if(!path.isEmpty()) + { + m_lastDir = QFileInfo(path).absoluteDir().path(); + QFile file(path); + file.open(QIODevice::ReadOnly); + m_ui->plainTextEdit->setPlainText(QString::fromUtf8(file.readAll())); + } +} + +void CueEditor::on_deleteButton_clicked() +{ + m_ui->plainTextEdit->clear(); +} + +void CueEditor::on_saveAsButton_clicked() +{ + +} diff --git a/src/qmmpui/cueeditor_p.h b/src/qmmpui/cueeditor_p.h new file mode 100644 index 000000000..f0a9d4075 --- /dev/null +++ b/src/qmmpui/cueeditor_p.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2021 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef CUEEDITOR_P_H +#define CUEEDITOR_P_H + +#include + +namespace Ui { +class CueEditor; +} + +class MetaDataModel; + +class CueEditor : public QWidget +{ + Q_OBJECT + +public: + explicit CueEditor(MetaDataModel *model, QWidget *parent = nullptr); + ~CueEditor(); + + void save(); + +private slots: + void on_loadButton_clicked(); + void on_deleteButton_clicked(); + void on_saveAsButton_clicked(); + +private: + Ui::CueEditor *m_ui; + MetaDataModel *m_model; + QString m_lastDir; +}; + +#endif // CUEEDITOR_P_H diff --git a/src/qmmpui/detailsdialog.cpp b/src/qmmpui/detailsdialog.cpp index 2b44fae60..8e423305b 100644 --- a/src/qmmpui/detailsdialog.cpp +++ b/src/qmmpui/detailsdialog.cpp @@ -32,6 +32,7 @@ #include "playlisttrack.h" #include "tageditor_p.h" #include "covereditor_p.h" +#include "cueeditor_p.h" #include "detailsdialog.h" DetailsDialog::DetailsDialog(const QList &tracks, QWidget *parent) @@ -82,6 +83,7 @@ void DetailsDialog::on_buttonBox_clicked(QAbstractButton *button) { TagEditor *tagEditor = qobject_cast(m_ui->tabWidget->currentWidget()); CoverEditor *coverEditor = nullptr; + CueEditor *cueEditor = nullptr; if(tagEditor) tagEditor->save(); else if((coverEditor = qobject_cast(m_ui->tabWidget->currentWidget()))) @@ -89,6 +91,10 @@ void DetailsDialog::on_buttonBox_clicked(QAbstractButton *button) coverEditor->save(); MetaDataManager::instance()->clearCoverCache(); } + else if((cueEditor = qobject_cast(m_ui->tabWidget->currentWidget()))) + { + cueEditor->save(); + } } else { @@ -206,6 +212,12 @@ void DetailsDialog::updatePage() m_ui->tabWidget->addTab(coverEditor, tr("Cover")); } + if(m_metaDataModel && (m_metaDataModel->dialogHints() & MetaDataModel::IsCueEditable)) + { + CueEditor *cueEditor = new CueEditor(m_metaDataModel, this); + m_ui->tabWidget->addTab(cueEditor, "CUE"); + } + if(m_metaDataModel) { for(TagModel *tagModel : m_metaDataModel->tags()) diff --git a/src/qmmpui/forms/cueeditor.ui b/src/qmmpui/forms/cueeditor.ui new file mode 100644 index 000000000..90fdebc5f --- /dev/null +++ b/src/qmmpui/forms/cueeditor.ui @@ -0,0 +1,75 @@ + + + CueEditor + + + + 0 + 0 + 420 + 347 + + + + Form + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 74 + + + + + + + + Load + + + + + + + Delete + + + + + + + Save as... + + + + + + + Qt::Vertical + + + + 20 + 150 + + + + + + + + + diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index 41f2a2a03..c8e4ca2f4 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -74,7 +74,8 @@ HEADERS += general.h \ metadataformattermenu.h \ qmmpui_export.h \ covereditor_p.h \ - commandlinehandler.h + commandlinehandler.h \ + cueeditor_p.h SOURCES += general.cpp \ playlistparser.cpp \ @@ -116,7 +117,8 @@ SOURCES += general.cpp \ metadataformattermenu.cpp \ covereditor.cpp \ commandlinehandler.cpp \ - generalfactory.cpp + generalfactory.cpp \ + cueeditor.cpp FORMS += forms/detailsdialog.ui \ forms/tageditor.ui \ @@ -126,7 +128,8 @@ FORMS += forms/detailsdialog.ui \ forms/aboutdialog.ui \ forms/addurldialog.ui \ forms/columneditor.ui \ - forms/covereditor.ui + forms/covereditor.ui \ + forms/cueeditor.ui unix:DESTDIR = . RESOURCES += translations/libqmmpui_locales.qrc \ -- cgit v1.2.3-13-gbd6f