2015-05-03 16:49:26 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (C) 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 "kfilemetadataprovider_p.h"
|
|
|
|
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kstandarddirs.h>
|
2016-03-31 01:10:00 +00:00
|
|
|
#include <kdebug.h>
|
2015-05-03 16:49:26 +00:00
|
|
|
|
|
|
|
#include <QLabel>
|
2015-08-28 04:14:43 +03:00
|
|
|
#include <QDir>
|
2015-05-03 16:49:26 +00:00
|
|
|
|
2022-03-09 22:43:30 +02:00
|
|
|
KFileMetaDataProvider::KFileMetaDataProvider(QObject* parent)
|
|
|
|
: QObject(parent)
|
2015-05-03 16:49:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-09 22:43:30 +02:00
|
|
|
KFileMetaDataProvider::~KFileMetaDataProvider()
|
2015-05-03 16:49:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-09 22:43:30 +02:00
|
|
|
void KFileMetaDataProvider::setItems(const KFileItemList& items)
|
2015-05-03 16:49:26 +00:00
|
|
|
{
|
2022-03-09 22:43:30 +02:00
|
|
|
m_fileItems = items;
|
2022-03-12 21:35:15 +02:00
|
|
|
m_data.clear();
|
2022-03-09 22:43:30 +02:00
|
|
|
|
|
|
|
if (items.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-03 16:49:26 +00:00
|
|
|
if (m_fileItems.count() == 1) {
|
|
|
|
// TODO: Handle case if remote URLs are used properly. isDir() does
|
|
|
|
// not work, the modification date needs also to be adjusted...
|
|
|
|
const KFileItem& item = m_fileItems.first();
|
|
|
|
|
|
|
|
if (item.isDir()) {
|
|
|
|
const int count = subDirectoriesCount(item.url().pathOrUrl());
|
|
|
|
if (count == -1) {
|
|
|
|
m_data.insert(KUrl("kfileitem#size"), QString("Unknown"));
|
|
|
|
} else {
|
|
|
|
const QString itemCountString = i18ncp("@item:intable", "%1 item", "%1 items", count);
|
|
|
|
m_data.insert(KUrl("kfileitem#size"), itemCountString);
|
|
|
|
}
|
|
|
|
} else {
|
2022-03-27 19:42:07 +03:00
|
|
|
const KFileMetaInfo metaInfo(item.url(), KFileMetaInfo::TechnicalInfo);
|
|
|
|
foreach (const KFileMetaInfoItem& metaInfoItem, metaInfo.items()) {
|
|
|
|
m_data.insert(metaInfoItem.key(), metaInfoItem.value());
|
|
|
|
}
|
|
|
|
|
2015-05-03 16:49:26 +00:00
|
|
|
m_data.insert(KUrl("kfileitem#size"), KIO::convertSize(item.size()));
|
|
|
|
}
|
|
|
|
m_data.insert(KUrl("kfileitem#type"), item.mimeComment());
|
|
|
|
m_data.insert(KUrl("kfileitem#modified"), KGlobal::locale()->formatDateTime(item.time(KFileItem::ModificationTime), KLocale::FancyLongDate));
|
|
|
|
m_data.insert(KUrl("kfileitem#owner"), item.user());
|
|
|
|
m_data.insert(KUrl("kfileitem#permissions"), item.permissionsString());
|
2021-07-24 19:18:19 +03:00
|
|
|
m_data.insert(KUrl("kfileitem#mimetype"), item.mimetype());
|
2015-05-03 16:49:26 +00:00
|
|
|
} else if (m_fileItems.count() > 1) {
|
|
|
|
// Calculate the size of all items
|
|
|
|
quint64 totalSize = 0;
|
|
|
|
foreach (const KFileItem& item, m_fileItems) {
|
|
|
|
if (!item.isDir() && !item.isLink()) {
|
|
|
|
totalSize += item.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_data.insert(KUrl("kfileitem#totalSize"), KIO::convertSize(totalSize));
|
|
|
|
}
|
|
|
|
|
2022-03-09 22:43:30 +02:00
|
|
|
emit loadingFinished();
|
2015-05-03 16:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KFileMetaDataProvider::label(const KUrl& metaDataUri) const
|
|
|
|
{
|
2022-03-10 12:05:20 +02:00
|
|
|
return KFileMetaInfo::name(metaDataUri.prettyUrl());
|
2015-05-03 16:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KFileItemList KFileMetaDataProvider::items() const
|
|
|
|
{
|
2022-03-09 22:43:30 +02:00
|
|
|
return m_fileItems;
|
2015-05-03 16:49:26 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 02:05:34 +02:00
|
|
|
QHash<KUrl, QString> KFileMetaDataProvider::data() const
|
2015-05-03 16:49:26 +00:00
|
|
|
{
|
2022-03-09 22:43:30 +02:00
|
|
|
return m_data;
|
2015-05-03 16:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* KFileMetaDataProvider::createValueWidget(const KUrl& metaDataUri,
|
2022-03-11 02:05:34 +02:00
|
|
|
const QString& value,
|
2015-05-03 16:49:26 +00:00
|
|
|
QWidget* parent) const
|
|
|
|
{
|
|
|
|
Q_ASSERT(parent != 0);
|
2022-03-09 22:43:30 +02:00
|
|
|
QLabel* widget = new QLabel(parent);
|
2015-05-03 16:49:26 +00:00
|
|
|
|
2022-03-09 22:43:30 +02:00
|
|
|
widget->setWordWrap(true);
|
|
|
|
widget->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
|
|
widget->setTextFormat(Qt::PlainText);
|
2022-03-11 02:05:34 +02:00
|
|
|
widget->setText(value);
|
2015-05-03 16:49:26 +00:00
|
|
|
widget->setForegroundRole(parent->foregroundRole());
|
|
|
|
widget->setFont(parent->font());
|
2022-03-09 22:43:30 +02:00
|
|
|
connect(widget, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)));
|
2015-05-03 16:49:26 +00:00
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2022-03-09 22:43:30 +02:00
|
|
|
void KFileMetaDataProvider::slotLinkActivated(const QString& link)
|
|
|
|
{
|
|
|
|
emit urlActivated(KUrl(link));
|
|
|
|
}
|
|
|
|
|
|
|
|
int KFileMetaDataProvider::subDirectoriesCount(const QString& path)
|
2015-05-03 16:49:26 +00:00
|
|
|
{
|
|
|
|
QDir dir(path);
|
|
|
|
return dir.entryList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::System).count();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_kfilemetadataprovider_p.cpp"
|