File indexing completed on 2024-07-21 04:17:24

0001 /*
0002     SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "baloofilepropertiesplugin.h"
0008 
0009 #include <QFrame>
0010 #include <QScrollArea>
0011 #include <QVBoxLayout>
0012 
0013 #include <kio_version.h>
0014 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
0015 #include <KIO/JobUiDelegateFactory>
0016 #else
0017 #include <KIO/JobUiDelegate>
0018 #endif
0019 
0020 #include <KIO/OpenUrlJob>
0021 #include <KLocalizedString>
0022 #include <KPluginFactory>
0023 
0024 #include "filemetadatawidget.h"
0025 
0026 K_PLUGIN_CLASS_WITH_JSON(BalooFilePropertiesPlugin, "baloofilepropertiesplugin.json")
0027 
0028 BalooFilePropertiesPlugin::BalooFilePropertiesPlugin(QObject *parent, const QList<QVariant> &args)
0029 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0030     : KPropertiesDialogPlugin(qobject_cast<KPropertiesDialog *>(parent))
0031 #else
0032     : KPropertiesDialogPlugin(parent)
0033 #endif
0034 {
0035     Q_UNUSED(args);
0036 
0037     auto widgetContainer = new QWidget();
0038 
0039     auto containerLayout = new QVBoxLayout(widgetContainer);
0040     containerLayout->setContentsMargins(0, 0, 0, 0);
0041     containerLayout->setSpacing(0);
0042 
0043     auto metaDataWidget = new Baloo::FileMetaDataWidget();
0044     metaDataWidget->setItems(properties->items());
0045     connect(metaDataWidget, &Baloo::FileMetaDataWidget::urlActivated, this, [this](const QUrl &url) {
0046         auto job = new KIO::OpenUrlJob(url);
0047 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
0048         job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, properties));
0049 #else
0050         job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, properties));
0051 #endif
0052         job->start();
0053     });
0054 
0055     containerLayout->addWidget(metaDataWidget);
0056     containerLayout->addStretch(1);
0057 
0058     auto metaDataArea = new QScrollArea();
0059 
0060     metaDataArea->setWidget(widgetContainer);
0061     metaDataArea->setWidgetResizable(true);
0062     metaDataArea->setFrameShape(QFrame::NoFrame);
0063 
0064     connect(metaDataWidget, &Baloo::FileMetaDataWidget::metaDataRequestFinished, this, [this, metaDataArea] {
0065         properties->addPage(metaDataArea, i18nc("Tab page with file meta data", "&Details"));
0066     });
0067 }
0068 
0069 BalooFilePropertiesPlugin::~BalooFilePropertiesPlugin() = default;
0070 
0071 #include "baloofilepropertiesplugin.moc"
0072 
0073 #include "moc_baloofilepropertiesplugin.cpp"