Commit f93b9a34 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Add "GPS location" property with clickable geo: link

Instead of showing a separate "GPS latitude" and "GPS longitude"
show it in a single field and add a `geo:` URL to it, which allows
opening the location in the designated map viewer (e.g. Marble)
parent 66425c44
Pipeline #206075 passed with stage
in 53 seconds
......@@ -31,7 +31,7 @@ include(ECMQtDeclareLoggingCategory)
include(CMakePackageConfigHelpers)
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Widgets Test)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Config KIO I18n FileMetaData Baloo)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Config KIO I18n FileMetaData Baloo Service)
ecm_setup_version(PROJECT
VARIABLE_PREFIX BALOO_WIDGETS
......
......@@ -68,6 +68,7 @@ target_link_libraries(KF5BalooWidgets
KF5::Baloo
KF5::CoreAddons
KF5::ConfigGui
KF5::Service
)
target_include_directories(KF5BalooWidgets INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF}/BalooWidgets>")
......
......@@ -16,6 +16,7 @@
#include <KShell>
#include <QDebug>
#include <QPair>
#include <QTimer>
// Required includes for subDirectoriesCount():
......@@ -133,6 +134,15 @@ void FileMetaDataProvider::slotFileFetchFinished(KJob *job)
if ((width.type() == QVariant::Double || width.type() == QVariant::Int) && (height.type() == QVariant::Double || height.type() == QVariant::Int)) {
m_data.insert(QStringLiteral("dimensions"), i18nc("width × height", "%1 × %2", width.toInt(), height.toInt()));
}
bool okLatitude;
const auto gpsLatitude = m_data.value(QStringLiteral("photoGpsLatitude")).toFloat(&okLatitude);
bool okLongitude;
const auto gpsLongitude = m_data.value(QStringLiteral("photoGpsLongitude")).toFloat(&okLongitude);
if (okLatitude && okLongitude) {
m_data.insert(QStringLiteral("gpsLocation"), QVariant::fromValue(QPair<float, float>(gpsLatitude, gpsLongitude)));
}
}
m_readOnly = !fetchJob->canEditAll();
......@@ -454,6 +464,7 @@ QString FileMetaDataProvider::label(const QString &metaDataLabel) const
{QStringLiteral("userComment"), i18nc("@label", "Comment")},
{QStringLiteral("originUrl"), i18nc("@label", "Downloaded From")},
{QStringLiteral("dimensions"), i18nc("@label", "Dimensions")},
{QStringLiteral("gpsLocation"), i18nc("@label", "GPS Location")},
};
QString value = hash.value(metaDataLabel);
......@@ -525,11 +536,12 @@ QString FileMetaDataProvider::group(const QString &label) const
{QStringLiteral("photoFocalLengthIn35mmFilm"), QStringLiteral("2ImageH")},
{QStringLiteral("photoFlash"), QStringLiteral("2ImageI")},
{QStringLiteral("imageOrientation"), QStringLiteral("2ImageJ")},
{QStringLiteral("photoGpsLatitude"), QStringLiteral("2ImageK")},
{QStringLiteral("photoGpsLongitude"), QStringLiteral("2ImageL")},
{QStringLiteral("photoGpsAltitude"), QStringLiteral("2ImageM")},
{QStringLiteral("manufacturer"), QStringLiteral("2ImageN")},
{QStringLiteral("model"), QStringLiteral("2ImageO")},
{QStringLiteral("photoGpsLocation"), QStringLiteral("2ImageK")},
{QStringLiteral("photoGpsLatitude"), QStringLiteral("2ImageL")},
{QStringLiteral("photoGpsLongitude"), QStringLiteral("2ImageM")},
{QStringLiteral("photoGpsAltitude"), QStringLiteral("2ImageN")},
{QStringLiteral("manufacturer"), QStringLiteral("2ImageO")},
{QStringLiteral("model"), QStringLiteral("2ImageP")},
// Media Data
{QStringLiteral("title"), QStringLiteral("3MediaA")},
......
......@@ -25,7 +25,7 @@ MetadataFilter::~MetadataFilter() = default;
void MetadataFilter::initMetaInformationSettings()
{
const int currentVersion = 12; // increase version, if the blacklist of disabled
const int currentVersion = 13; // increase version, if the blacklist of disabled
// properties should be updated
KConfig config(QStringLiteral("baloofileinformationrc"), KConfig::NoGlobals);
......@@ -66,6 +66,8 @@ void MetadataFilter::initMetaInformationSettings()
"photoSaturation",
"photoPixelXDimension",
"photoPixelYDimension",
"photoGpsLongitude",
"photoGpsLatitude",
};
for (const auto property : disabledProperties) {
......
......@@ -21,6 +21,7 @@
#include <QTime>
#include <QUrl>
#include <KApplicationTrader>
#include <KFormat>
#include <KJob>
#include <KLocalizedString>
......@@ -102,6 +103,29 @@ QWidget *WidgetFactory::createWidget(const QString &prop, const QVariant &value,
return coll.compare(s1, s2) < 0;
});
widget = createTagWidget(tags, parent);
} else if (prop == QLatin1String("gpsLocation")) {
const auto pair = value.value<QPair<float, float>>();
const auto latitude = pair.first;
const auto longitude = pair.second;
const QString geoUri = QStringLiteral("geo:%1,%2").arg(latitude).arg(longitude);
const QString latitudeStr = latitude < 0 ? i18nc("Latitude (South)", "%1°S", -latitude) : i18nc("Latitude (North)", "%1°N", latitude);
const QString longitudeStr = longitude < 0 ? i18nc("Longitude (West)", "%1°W", -longitude) : i18nc("Longitude (East)", "%1°E", longitude);
const QString gpsLocationStr = latitudeStr + QLatin1Char(' ') + longitudeStr;
QLabel *valueWidget = createValueWidget(parent);
if (const auto geoService = KApplicationTrader::preferredService(QStringLiteral("x-scheme-handler/geo"))) {
valueWidget->setTextFormat(Qt::RichText);
valueWidget->setTextInteractionFlags(Qt::TextBrowserInteraction);
valueWidget->setText(QStringLiteral("<a href='%1'>%2</a>").arg(geoUri, gpsLocationStr));
valueWidget->setToolTip(i18nc("@info:tooltip Show location in map viewer", "Show location in %1", geoService->name()));
} else {
valueWidget->setText(gpsLocationStr);
}
widget = valueWidget;
} else {
QString valueString;
QLabel *valueWidget = createValueWidget(parent);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment