File indexing completed on 2024-12-22 04:15:11

0001 /*
0002  *  SPDX-FileCopyrightText: 2023 Srirupa Datta <srirupa.sps@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "page_metadata_info.h"
0008 #include "ui_pagemetadatainfo.h"
0009 #include <kis_config.h>
0010 #include <KoDocumentInfo.h>
0011 #include <KisImportExportManager.h>
0012 #include <KoFileDialog.h>
0013 #include <KoResource.h>
0014 #include "KisResourceStorage.h"
0015 
0016 
0017 PageMetadataInfo::PageMetadataInfo(KoResourceBundleSP bundle, QWidget *parent) :
0018     QWizardPage(parent),
0019     m_ui(new Ui::PageMetadataInfo)
0020     , m_bundle(bundle)
0021 {
0022     m_ui->setupUi(this);
0023     KoDocumentInfo info;
0024     info.updateParameters();
0025 
0026     if (m_bundle) {
0027         m_ui->editAuthor->setText(m_bundle->metaData(KisResourceStorage::s_meta_author, info.authorInfo("creator")));
0028         m_ui->editEmail->setText(m_bundle->metaData(KisResourceStorage::s_meta_email, info.authorInfo("email")));
0029         m_ui->editWebsite->setText(m_bundle->metaData(KisResourceStorage::s_meta_website, "http://"));
0030         m_ui->editLicense->setText(m_bundle->metaData(KisResourceStorage::s_meta_license, "CC-BY-SA"));
0031         QString fileName = QFileInfo(m_bundle->filename()).baseName();
0032         m_ui->editBundleName->setText(fileName);
0033         m_ui->editDescription->document()->setPlainText(m_bundle->metaData(KisResourceStorage::s_meta_description, "New Bundle"));
0034         QImage img = m_bundle->image();
0035         img = img.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
0036         m_thumbnail = img;
0037         m_ui->lblPreview->setPixmap(QPixmap::fromImage(img));
0038     } else {
0039         KisConfig cfg(true);
0040 
0041         m_ui->editAuthor->setText(cfg.readEntry<QString>("BundleAuthorName", info.authorInfo("creator")));
0042         m_ui->editEmail->setText(cfg.readEntry<QString>("BundleAuthorEmail", info.authorInfo("email")));
0043         m_ui->editWebsite->setText(cfg.readEntry<QString>("BundleWebsite", "http://"));
0044         m_ui->editLicense->setText(cfg.readEntry<QString>("BundleLicense", "CC-BY-SA"));
0045         m_ui->editBundleName->setText(cfg.readEntry<QString>("BundleName", "New Bundle"));
0046         m_ui->editDescription->document()->setPlainText(cfg.readEntry<QString>("BundleDescription", "New Bundle"));
0047         m_previewImage = cfg.readEntry<QString>("BundleImage", "");
0048         if (!m_previewImage.isEmpty()) {
0049             QImage img(m_previewImage);
0050             img = img.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
0051             m_ui->lblPreview->setPixmap(QPixmap::fromImage(img));
0052         }
0053     }
0054 
0055     connect(m_ui->bnGetPreview, SIGNAL(clicked()), SLOT(getPreviewImage()));
0056 }
0057 
0058 PageMetadataInfo::~PageMetadataInfo()
0059 {
0060     delete m_ui;
0061 }
0062 
0063 QString PageMetadataInfo::bundleName() const
0064 {
0065     return m_ui->editBundleName->text();
0066 }
0067 
0068 QString PageMetadataInfo::authorName() const
0069 {
0070     return m_ui->editAuthor->text();
0071 }
0072 
0073 QString PageMetadataInfo::email() const
0074 {
0075     return m_ui->editEmail->text();
0076 }
0077 
0078 QString PageMetadataInfo::website() const
0079 {
0080     return m_ui->editWebsite->text();
0081 }
0082 
0083 QString PageMetadataInfo::license() const
0084 {
0085     return m_ui->editLicense->text();
0086 }
0087 
0088 QString PageMetadataInfo::description() const
0089 {
0090     return m_ui->editDescription->document()->toPlainText();
0091 }
0092 
0093 
0094 QString PageMetadataInfo::previewImage() const
0095 {
0096     return m_previewImage;
0097 }
0098 
0099 QImage PageMetadataInfo::thumbnail() const
0100 {
0101     return m_thumbnail;
0102 }
0103 
0104 void PageMetadataInfo::getPreviewImage()
0105 {
0106     KoFileDialog dialog(this, KoFileDialog::OpenFile, "BundlePreviewImage");
0107     dialog.setCaption(i18n("Select file to use as bundle icon"));
0108     dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
0109     dialog.setMimeTypeFilters(KisImportExportManager::supportedMimeTypes(KisImportExportManager::Import));
0110     m_previewImage = dialog.filename();
0111     QImage img(m_previewImage);
0112     img = img.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
0113     m_ui->lblPreview->setPixmap(QPixmap::fromImage(img));
0114 }
0115 
0116 void PageMetadataInfo::showWarning()
0117 {
0118      m_ui->editBundleName->setStyleSheet(QString(" border: 1px solid red"));
0119 }
0120 
0121 void PageMetadataInfo::removeWarning()
0122 {
0123      m_ui->editBundleName->setStyleSheet(QString(""));
0124 }