1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*
* ========================================================================== *
* *
* This file is part of the Openterface Mini KVM App QT version *
* *
* Copyright (C) 2024 <info@openterface.com> *
* *
* 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 version 3. *
* *
* 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, see <http://www.gnu.org/licenses/>. *
* *
* ========================================================================== *
*/
#include "metadatadialog.h"
#include <QMediaMetaData>
#include <QDialog>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QWidget>
#include <QString>
static QString defaultValue(QMediaMetaData::Key key)
{
switch (key) {
case QMediaMetaData::Title:
return MetaDataDialog::tr("Openterface Mini KVM");
case QMediaMetaData::Author:
return MetaDataDialog::tr("TechxArtisan");
case QMediaMetaData::Date:
return QDateTime::currentDateTime().toString();
default:
break;
}
return {};
}
MetaDataDialog::MetaDataDialog(QWidget *parent) : QDialog(parent)
{
auto *viewport = new QWidget;
auto *metaDataLayout = new QFormLayout(viewport);
for (int i = 0; i < QMediaMetaData::NumMetaData; ++i) {
const auto key = static_cast<QMediaMetaData::Key>(i);
QString label = QMediaMetaData::metaDataKeyToString(key);
auto *lineEdit = new QLineEdit(defaultValue(key));
lineEdit->setClearButtonEnabled(true);
m_metaDataFields[key] = lineEdit;
switch (key) {
case QMediaMetaData::ThumbnailImage: {
QPushButton *openThumbnail = new QPushButton(tr("Open"));
connect(openThumbnail, &QPushButton::clicked, this,
&MetaDataDialog::openThumbnailImage);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(lineEdit);
layout->addWidget(openThumbnail);
metaDataLayout->addRow(label, layout);
}
break;
case QMediaMetaData::CoverArtImage: {
QPushButton *openCoverArt = new QPushButton(tr("Open"));
connect(openCoverArt, &QPushButton::clicked, this, &MetaDataDialog::openCoverArtImage);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(lineEdit);
layout->addWidget(openCoverArt);
metaDataLayout->addRow(label, layout);
}
break;
default:
metaDataLayout->addRow(label, lineEdit);
break;
}
}
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setWidget(viewport);
auto *dialogLayout = new QVBoxLayout(this);
dialogLayout->addWidget(scrollArea);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialogLayout->addWidget(buttonBox);
setWindowTitle(tr("Set Metadata"));
resize(400, 300);
connect(buttonBox, &QDialogButtonBox::accepted, this, &MetaDataDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &MetaDataDialog::reject);
}
void MetaDataDialog::openThumbnailImage()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), QDir::currentPath(),
tr("Image Files (*.png *.jpg *.bmp)"));
if (!fileName.isEmpty())
m_metaDataFields[QMediaMetaData::ThumbnailImage]->setText(fileName);
}
void MetaDataDialog::openCoverArtImage()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), QDir::currentPath(),
tr("Image Files (*.png *.jpg *.bmp)"));
if (!fileName.isEmpty())
m_metaDataFields[QMediaMetaData::CoverArtImage]->setText(fileName);
}
|