Baloo Widgets

baloofilepropertiesplugin.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "baloofilepropertiesplugin.h"
8
9#include <QFrame>
10#include <QScrollArea>
11#include <QVBoxLayout>
12
13#include <kio_version.h>
14#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
15#include <KIO/JobUiDelegateFactory>
16#else
17#include <KIO/JobUiDelegate>
18#endif
19
20#include <KIO/OpenUrlJob>
21#include <KLocalizedString>
22#include <KPluginFactory>
23
24#include "filemetadatawidget.h"
25
26K_PLUGIN_CLASS_WITH_JSON(BalooFilePropertiesPlugin, "baloofilepropertiesplugin.json")
27
28BalooFilePropertiesPlugin::BalooFilePropertiesPlugin(QObject *parent, const QList<QVariant> &args)
29#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
30 : KPropertiesDialogPlugin(qobject_cast<KPropertiesDialog *>(parent))
31#else
33#endif
34{
35 Q_UNUSED(args);
36
37 auto widgetContainer = new QWidget();
38
39 auto containerLayout = new QVBoxLayout(widgetContainer);
40 containerLayout->setContentsMargins(0, 0, 0, 0);
41 containerLayout->setSpacing(0);
42
43 auto metaDataWidget = new Baloo::FileMetaDataWidget();
44 metaDataWidget->setItems(properties->items());
45 connect(metaDataWidget, &Baloo::FileMetaDataWidget::urlActivated, this, [this](const QUrl &url) {
46 auto job = new KIO::OpenUrlJob(url);
47#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
49#else
50 job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, properties));
51#endif
52 job->start();
53 });
54
55 containerLayout->addWidget(metaDataWidget);
56 containerLayout->addStretch(1);
57
58 auto metaDataArea = new QScrollArea();
59
60 metaDataArea->setWidget(widgetContainer);
61 metaDataArea->setWidgetResizable(true);
62 metaDataArea->setFrameShape(QFrame::NoFrame);
63
64 connect(metaDataWidget, &Baloo::FileMetaDataWidget::metaDataRequestFinished, this, [this, metaDataArea] {
65 properties->addPage(metaDataArea, i18nc("Tab page with file meta data", "&Details"));
66 });
67}
68
69BalooFilePropertiesPlugin::~BalooFilePropertiesPlugin() = default;
70
71#include "baloofilepropertiesplugin.moc"
72
73#include "moc_baloofilepropertiesplugin.cpp"
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
KGuiItem properties()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:45:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.