File indexing completed on 2025-01-12 12:26:25
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2001,2002 Rolf Magnus <ramagnus@kde.org> 0003 0004 library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License version 2 as published by the Free Software Foundation. 0007 0008 This library is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 Library General Public License for more details. 0012 0013 You should have received a copy of the GNU Library General Public License 0014 along with this library; see the file COPYING.LIB. If not, write to 0015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include "kmetaprops.h" 0020 0021 #include <kfileitem.h> 0022 #include <kfilemetadatawidget.h> 0023 #include <kfilemetadataconfigurationwidget.h> 0024 #include <klocalizedstring.h> 0025 #include <ksharedconfig.h> 0026 #include <kwindowconfig.h> 0027 0028 #include <QDialog> 0029 #include <QDialogButtonBox> 0030 #include <QPointer> 0031 #include <QLabel> 0032 #include <QScrollArea> 0033 #include <QVBoxLayout> 0034 0035 class Q_DECL_HIDDEN KFileMetaPropsPlugin::KFileMetaPropsPluginPrivate 0036 { 0037 public: 0038 KFileMetaPropsPluginPrivate(); 0039 ~KFileMetaPropsPluginPrivate(); 0040 void configureShownMetaData(); 0041 0042 KFileMetaDataWidget *m_fileMetaDataWidget; 0043 }; 0044 0045 KFileMetaPropsPlugin::KFileMetaPropsPluginPrivate::KFileMetaPropsPluginPrivate() : 0046 m_fileMetaDataWidget(nullptr) 0047 { 0048 } 0049 0050 KFileMetaPropsPlugin::KFileMetaPropsPluginPrivate::~KFileMetaPropsPluginPrivate() 0051 { 0052 } 0053 0054 void KFileMetaPropsPlugin::KFileMetaPropsPluginPrivate::configureShownMetaData() 0055 { 0056 QPointer<QDialog> dialog = new QDialog(); 0057 dialog->setWindowTitle(i18nc("@title:window", "Configure Shown Data")); 0058 0059 QLabel *descriptionLabel = new QLabel(i18nc("@label::textbox", 0060 "Select which data should " 0061 "be shown:")); 0062 descriptionLabel->setWordWrap(true); 0063 0064 KFileMetaDataConfigurationWidget *configWidget = new KFileMetaDataConfigurationWidget(); 0065 const KFileItemList items = m_fileMetaDataWidget->items(); 0066 configWidget->setItems(items); 0067 0068 QDialogButtonBox *buttonBox = new QDialogButtonBox(); 0069 buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0070 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); 0071 connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); 0072 0073 QVBoxLayout *topLayout = new QVBoxLayout; 0074 topLayout->addWidget(descriptionLabel); 0075 topLayout->addWidget(configWidget); 0076 topLayout->addWidget(buttonBox); 0077 dialog->setLayout(topLayout); 0078 0079 KConfigGroup dialogConfig(KSharedConfig::openConfig(), "KFileMetaPropsPlugin"); 0080 KWindowConfig::restoreWindowSize(dialog->windowHandle(), dialogConfig); 0081 0082 if ((dialog->exec() == QDialog::Accepted) && (dialog != nullptr)) { 0083 configWidget->save(); 0084 0085 // TODO: Check whether a kind of refresh() method might make sense 0086 // for KFileMetaDataWidget or whether the widget can verify internally 0087 // whether a change has been done 0088 m_fileMetaDataWidget->setItems(KFileItemList()); 0089 m_fileMetaDataWidget->setItems(items); 0090 } 0091 0092 if (dialog != nullptr) { 0093 KWindowConfig::saveWindowSize(dialog->windowHandle(), dialogConfig); 0094 delete dialog; 0095 dialog = nullptr; 0096 } 0097 } 0098 0099 KFileMetaPropsPlugin::KFileMetaPropsPlugin(KPropertiesDialog *props) 0100 : KPropertiesDialogPlugin(props), d(new KFileMetaPropsPluginPrivate) 0101 { 0102 d->m_fileMetaDataWidget = new KFileMetaDataWidget(); 0103 d->m_fileMetaDataWidget->setItems(properties->items()); 0104 0105 // Embed the FileMetaDataWidget inside a container that has a dummy widget 0106 // at the bottom. This prevents that the file meta data widget gets vertically stretched. 0107 QWidget *metaDataWidgetContainer = new QWidget(); 0108 QVBoxLayout *containerLayout = new QVBoxLayout(metaDataWidgetContainer); 0109 containerLayout->addWidget(d->m_fileMetaDataWidget); 0110 QWidget *stretchWidget = new QWidget(metaDataWidgetContainer); 0111 stretchWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); 0112 containerLayout->addWidget(stretchWidget); 0113 0114 // The height of FileMetaDataWidget can get very large, so it is embedded 0115 // into a scrollarea 0116 QScrollArea *metaDataArea = new QScrollArea(); 0117 metaDataArea->setWidget(metaDataWidgetContainer); 0118 metaDataArea->setWidgetResizable(true); 0119 metaDataArea->setFrameShape(QFrame::NoFrame); 0120 0121 // Add label 'Configure...' to be able to adjust which meta data should be shown 0122 QLabel *configureLabel = new QLabel("<a href=\"configure\">" + 0123 i18nc("@action:button", "Configure...") + 0124 "</a>"); 0125 connect(configureLabel, SIGNAL(linkActivated(QString)), 0126 this, SLOT(configureShownMetaData())); 0127 0128 QWidget *mainWidget = new QWidget(); 0129 QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget); 0130 mainLayout->addWidget(metaDataArea); 0131 mainLayout->addWidget(configureLabel, 0, Qt::AlignRight); 0132 0133 properties->addPage(mainWidget, i18nc("@title:tab", "Information")); 0134 } 0135 0136 KFileMetaPropsPlugin::~KFileMetaPropsPlugin() 0137 { 0138 delete d; 0139 } 0140 0141 bool KFileMetaPropsPlugin::supports(const KFileItemList &_items) 0142 { 0143 Q_UNUSED(_items); 0144 return true; 0145 } 0146 0147 void KFileMetaPropsPlugin::applyChanges() 0148 { 0149 } 0150 0151 #include "moc_kmetaprops.cpp"