2014-11-13 01:04:59 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (C) 2008-2010 by Sebastian Trueg <trueg@kde.org> *
|
|
|
|
* Copyright (C) 2009-2010 by Peter Penz <peter.penz@gmx.at> *
|
|
|
|
* *
|
|
|
|
* This library is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Library General Public *
|
|
|
|
* License as published by the Free Software Foundation; either *
|
|
|
|
* version 2 of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This library 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 *
|
|
|
|
* Library General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Library General Public License *
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to *
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
|
|
|
* Boston, MA 02110-1301, USA. *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "kfilemetadatawidget.h"
|
|
|
|
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kfileitem.h>
|
|
|
|
#include <klocale.h>
|
2015-05-03 16:49:26 +00:00
|
|
|
#include "kfilemetadataprovider_p.h"
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QList>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTimer>
|
2015-05-03 16:49:26 +00:00
|
|
|
#include <QSpacerItem>
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
class KFileMetaDataWidget::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Row
|
|
|
|
{
|
|
|
|
QLabel* label;
|
|
|
|
QWidget* value;
|
|
|
|
};
|
|
|
|
|
|
|
|
Private(KFileMetaDataWidget* parent);
|
|
|
|
~Private();
|
|
|
|
|
|
|
|
void deleteRows();
|
|
|
|
|
|
|
|
void slotLoadingFinished();
|
|
|
|
void slotLinkActivated(const QString& link);
|
|
|
|
|
|
|
|
QList<Row> m_rows;
|
2015-05-03 16:49:26 +00:00
|
|
|
KFileMetaDataProvider* m_provider;
|
2014-11-13 01:04:59 +02:00
|
|
|
QGridLayout* m_gridLayout;
|
|
|
|
|
|
|
|
private:
|
|
|
|
KFileMetaDataWidget* const q;
|
|
|
|
};
|
|
|
|
|
2023-07-30 04:49:10 +03:00
|
|
|
KFileMetaDataWidget::Private::Private(KFileMetaDataWidget* parent)
|
|
|
|
: m_rows(),
|
|
|
|
m_provider(nullptr),
|
|
|
|
m_gridLayout(nullptr),
|
2014-11-13 01:04:59 +02:00
|
|
|
q(parent)
|
|
|
|
{
|
2015-11-27 00:25:55 +00:00
|
|
|
// increase version, if the blacklist of disabled properties should be updated
|
2021-07-25 00:19:26 +03:00
|
|
|
static const int currentVersion = 7;
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
KConfig config("kmetainformationrc", KConfig::NoGlobals);
|
|
|
|
if (config.group("Misc").readEntry("version", 0) < currentVersion) {
|
|
|
|
// The resource file is read the first time. Assure
|
2015-07-13 15:57:49 +03:00
|
|
|
// that some meta information is enabled per default.
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
// clear old info
|
|
|
|
config.deleteGroup("Show");
|
|
|
|
KConfigGroup settings = config.group("Show");
|
|
|
|
|
2015-07-27 02:02:50 +03:00
|
|
|
static const char* enabledProperties[] = {
|
2022-03-11 00:55:52 +02:00
|
|
|
"http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#musicAlbum",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#artist",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#trackNumber",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#genre",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#audioBitDepth",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#audioBitRate",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#videoBitDepth",
|
2014-11-13 01:04:59 +02:00
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#averageBitrate",
|
2022-03-11 00:55:52 +02:00
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/05/10/nid3#beatsPerMinute",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#codec",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#videoCodec",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#audioCodec",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#description",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#duration",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/05/10/nid3#encoder",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height",
|
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated",
|
2014-11-13 01:04:59 +02:00
|
|
|
"http://www.semanticdesktop.org/ontologies/2007/08/15/nao#lastModified",
|
|
|
|
"kfileitem#owner",
|
|
|
|
"kfileitem#permissions",
|
2021-07-24 19:18:19 +03:00
|
|
|
"kfileitem#mimetype",
|
2014-11-13 01:04:59 +02:00
|
|
|
0 // mandatory last entry
|
|
|
|
};
|
|
|
|
|
2022-03-11 00:55:52 +02:00
|
|
|
foreach (const QString &key, KFileMetaInfo::supportedKeys()) {
|
|
|
|
settings.writeEntry(key, false);
|
|
|
|
}
|
2015-07-27 02:02:50 +03:00
|
|
|
|
2015-07-13 15:29:55 +03:00
|
|
|
for (int i = 0; enabledProperties[i] != 0; ++i) {
|
|
|
|
settings.writeEntry(enabledProperties[i], true);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// mark the group as initialized
|
|
|
|
config.group("Misc").writeEntry("version", currentVersion);
|
|
|
|
}
|
2023-07-30 04:49:10 +03:00
|
|
|
|
|
|
|
// TODO: If KFileMetaDataProvider might get a public class in future KDE releases,
|
|
|
|
// the following code should be moved into KFileMetaDataWidget::setModel():
|
|
|
|
m_provider = new KFileMetaDataProvider(q);
|
|
|
|
connect(m_provider, SIGNAL(loadingFinished()), q, SLOT(slotLoadingFinished()));
|
|
|
|
connect(m_provider, SIGNAL(urlActivated(KUrl)), q, SIGNAL(urlActivated(KUrl)));
|
|
|
|
}
|
|
|
|
|
|
|
|
KFileMetaDataWidget::Private::~Private()
|
|
|
|
{
|
|
|
|
deleteRows();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KFileMetaDataWidget::Private::deleteRows()
|
|
|
|
{
|
|
|
|
foreach (const Row& row, m_rows) {
|
|
|
|
delete row.label;
|
|
|
|
delete row.value;
|
|
|
|
}
|
|
|
|
m_rows.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KFileMetaDataWidget::Private::slotLoadingFinished()
|
|
|
|
{
|
2015-05-03 16:49:26 +00:00
|
|
|
deleteRows();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-07-30 04:49:10 +03:00
|
|
|
if (!m_gridLayout) {
|
2015-05-04 11:02:47 +00:00
|
|
|
m_gridLayout = new QGridLayout(q);
|
|
|
|
m_gridLayout->setMargin(0);
|
|
|
|
m_gridLayout->setSpacing(q->fontMetrics().height() / 4);
|
|
|
|
}
|
|
|
|
|
2022-05-27 15:23:48 +03:00
|
|
|
KFileMetaInfoItemList data = m_provider->data();
|
2015-05-04 11:02:47 +00:00
|
|
|
|
|
|
|
// Remove all items, that are marked as hidden in kmetainformationrc
|
|
|
|
KConfig config("kmetainformationrc", KConfig::NoGlobals);
|
|
|
|
KConfigGroup settings = config.group("Show");
|
2022-05-27 15:23:48 +03:00
|
|
|
KFileMetaInfoItemList::iterator it = data.begin();
|
2015-05-04 11:02:47 +00:00
|
|
|
while (it != data.end()) {
|
2022-05-27 15:23:48 +03:00
|
|
|
if (!settings.readEntry(it->key(), true)) {
|
2015-05-04 11:02:47 +00:00
|
|
|
it = data.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through all remaining items embed the label
|
|
|
|
// and the value as new row in the widget
|
|
|
|
int rowIndex = 0;
|
2022-05-27 15:23:48 +03:00
|
|
|
foreach (const KFileMetaInfoItem& item, data) {
|
|
|
|
const QString key = item.key();
|
|
|
|
const QString value = item.value();
|
2022-03-11 02:05:34 +02:00
|
|
|
if (value.isEmpty()) {
|
2020-01-30 13:52:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2023-06-07 22:10:22 +03:00
|
|
|
QString itemLabel = KFileMetaInfo::name(key);
|
2015-05-04 11:02:47 +00:00
|
|
|
itemLabel.append(QLatin1Char(':'));
|
|
|
|
|
|
|
|
// Create label
|
|
|
|
QLabel* label = new QLabel(itemLabel, q);
|
|
|
|
label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
|
|
|
label->setForegroundRole(q->foregroundRole());
|
|
|
|
label->setFont(q->font());
|
|
|
|
label->setWordWrap(true);
|
|
|
|
label->setAlignment(Qt::AlignTop | Qt::AlignRight);
|
|
|
|
|
|
|
|
// Create value-widget
|
|
|
|
QWidget* valueWidget = m_provider->createValueWidget(key, value, q);
|
|
|
|
|
|
|
|
// Add the label and value-widget to grid layout
|
|
|
|
m_gridLayout->addWidget(label, rowIndex, 0, Qt::AlignRight);
|
2021-03-22 14:57:20 +02:00
|
|
|
m_gridLayout->addWidget(valueWidget, rowIndex, 1, Qt::AlignLeft);
|
2015-05-04 11:02:47 +00:00
|
|
|
|
|
|
|
// Remember the label and value-widget as row
|
|
|
|
Row row;
|
|
|
|
row.label = label;
|
|
|
|
row.value = valueWidget;
|
|
|
|
m_rows.append(row);
|
|
|
|
|
|
|
|
++rowIndex;
|
|
|
|
}
|
|
|
|
|
2014-11-13 01:04:59 +02:00
|
|
|
q->updateGeometry();
|
2015-05-03 16:49:26 +00:00
|
|
|
emit q->metaDataRequestFinished(m_provider->items());
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KFileMetaDataWidget::Private::slotLinkActivated(const QString& link)
|
|
|
|
{
|
|
|
|
const KUrl url(link);
|
|
|
|
if (url.isValid()) {
|
|
|
|
emit q->urlActivated(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KFileMetaDataWidget::KFileMetaDataWidget(QWidget* parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
d(new Private(this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KFileMetaDataWidget::~KFileMetaDataWidget()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KFileMetaDataWidget::setItems(const KFileItemList& items)
|
|
|
|
{
|
2015-05-03 16:49:26 +00:00
|
|
|
d->m_provider->setItems(items);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KFileItemList KFileMetaDataWidget::items() const
|
|
|
|
{
|
2015-05-03 16:49:26 +00:00
|
|
|
return d->m_provider->items();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize KFileMetaDataWidget::sizeHint() const
|
|
|
|
{
|
2023-07-30 04:49:10 +03:00
|
|
|
if (!d->m_gridLayout) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return QWidget::sizeHint();
|
|
|
|
}
|
|
|
|
|
2022-03-27 20:56:42 +03:00
|
|
|
return d->m_gridLayout->sizeHint();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 07:40:26 +00:00
|
|
|
#include "moc_kfilemetadatawidget.cpp"
|