From c722a7d91ac70325277998e2a07d4041705ffc6d Mon Sep 17 00:00:00 2001 From: Hasenlauefer Date: Thu, 11 Feb 2016 12:22:36 +0100 Subject: Extract GPS heading from EXIF for {{Location}} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This enhancement is available for users of a Lightroom (LR) version 6 or higher. The function to retrieve the direction has been introduced by Adobe with version 6. Therefore this enhancement is not available by users of versions lower 6. This enhancement differs several LR versions. Depending on the version, different information messages are shown (or not): * LR 6 or higher: If the `Direction` field is set, the user gets informed about this feature. Uploads of files without a direction setting don’t cause this information message, because at such cases the user is not affected. * LR 5: Users get informed, the feature is not available, due to the insufficient LR version. Adobe introduced the “Direction” field with LR version 5, but forgot to include it at the corresponding LR SDK 5. Therefore this feature can not be used by users of LR 5. At release notes of LR SDK 6 this has been mentioned to be a bug fix of LR SDK 5. * LR 4: Users of this version are not affected, because Adobe introduced the “Direction” field with version 5. Therefore users of LR 4 don’t get any information message. * LR versions lower 4: These versions are not supported by LrMediaWiki. The information messages include a “Don’t show again” (German: „Nicht erneut anzeigen“) checkbox. If the user decides, to set this option and decides to revert this decision later, a reset of warning dialogs at LR is needed: * English: Edit -> Preferences... -> General -> Prompts -> Reset all * warning dialogs * German: Bearbeiten -> Voreinstellungen -> Allgemein -> * Eingabeaufforderungen -> Alle Warndialogfelder zurücksetzen LR can store a direction value with up to 4 digits beyond a decimal point, but shows at user interface a rounded value without decimal places (by mouse over the direction field). The information message shows the same rounded value, to avoid confusion of the user seeing different values. The `{{Location}}` template parameter `heading` is filled by the stored value of LR. Sample: A direction input of 359.987654321 is stored as 359.9876, shown as 360°. At `{{Location}}` template the LR stored value of 359.9876 is set. Affected code: - MediaWikiExportServiceProvider.processRenderedPhotos: use the heading value to generate the Location template - Info: change SDK version to 6.0 Fix #35. --- mediawiki.lrdevplugin/Info.lua | 77 +++++++++++----------- .../MediaWikiExportServiceProvider.lua | 66 ++++++++++++++++++- mediawiki.lrdevplugin/TranslatedStrings_de.txt | 9 +++ 3 files changed, 112 insertions(+), 40 deletions(-) mode change 100755 => 100644 mediawiki.lrdevplugin/Info.lua (limited to 'mediawiki.lrdevplugin') diff --git a/mediawiki.lrdevplugin/Info.lua b/mediawiki.lrdevplugin/Info.lua old mode 100755 new mode 100644 index a3aa55b..7a1e0b2 --- a/mediawiki.lrdevplugin/Info.lua +++ b/mediawiki.lrdevplugin/Info.lua @@ -1,38 +1,39 @@ --- This file is part of the LrMediaWiki project and distributed under the terms --- of the MIT license (see LICENSE.txt file in the project root directory or --- [0]). See [1] for more information about LrMediaWiki. --- --- Copyright (C) 2014 by the LrMediaWiki team (see CREDITS.txt file in the --- project root directory or [2]) --- --- [0] --- [1] --- [2] - -return { - LrSdkVersion = 5.0, - LrToolkitIdentifier = 'org.ireas.lightroom.mediawiki', - LrPluginName = LOC '$$$/LrMediaWiki/PluginName=MediaWiki for Lightroom', - - LrInitPlugin = 'MediaWikiInit.lua', - - LrLibraryMenuItems = { - title = LOC '$$$/LrMediaWiki/Menu/Mapping=Keyword/category mapping', - file = 'MediaWikiMappingMenuItem.lua', - }, - - LrExportServiceProvider = { - title = LOC '$$$/LrMediaWiki/MediaWiki=MediaWiki', - file = 'MediaWikiExportServiceProvider.lua', - }, - - LrMetadataProvider = 'MediaWikiMetadataProvider.lua', - - LrPluginInfoProvider = 'MediaWikiPluginInfoProvider.lua', - - VERSION = { - major = 0, - minor = 4, - revision = 1, - }, -} +-- This file is part of the LrMediaWiki project and distributed under the terms +-- of the MIT license (see LICENSE.txt file in the project root directory or +-- [0]). See [1] for more information about LrMediaWiki. +-- +-- Copyright (C) 2014 by the LrMediaWiki team (see CREDITS.txt file in the +-- project root directory or [2]) +-- +-- [0] +-- [1] +-- [2] + +return { + LrSdkVersion = 6.0, + LrSdkMinimumVersion = 4.0, + LrToolkitIdentifier = 'org.ireas.lightroom.mediawiki', + LrPluginName = LOC '$$$/LrMediaWiki/PluginName=MediaWiki for Lightroom', + + LrInitPlugin = 'MediaWikiInit.lua', + + LrLibraryMenuItems = { + title = LOC '$$$/LrMediaWiki/Menu/Mapping=Keyword/category mapping', + file = 'MediaWikiMappingMenuItem.lua', + }, + + LrExportServiceProvider = { + title = LOC '$$$/LrMediaWiki/MediaWiki=MediaWiki', + file = 'MediaWikiExportServiceProvider.lua', + }, + + LrMetadataProvider = 'MediaWikiMetadataProvider.lua', + + LrPluginInfoProvider = 'MediaWikiPluginInfoProvider.lua', + + VERSION = { + major = 0, + minor = 4, + revision = 2, + }, +} \ No newline at end of file diff --git a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua index b940cc8..26050f0 100755 --- a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua +++ b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua @@ -19,7 +19,7 @@ local LrErrors = import 'LrErrors' local LrFileUtils = import 'LrFileUtils' local LrPathUtils = import 'LrPathUtils' local LrView = import 'LrView' - +local LrApplication = import 'LrApplication' local bind = LrView.bind local Info = require 'Info' @@ -105,8 +105,70 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext, local additionalCategories = photo:getPropertyForPlugin(Info.LrToolkitIdentifier, 'categories') or '' local gps = photo:getRawMetadata('gps') + local LrMajorVersion = LrApplication.versionTable().major -- number type + local LrVersionString = LrApplication.versionString() -- string with major, minor and revison numbers + local subText = LOC('$$$/LrMediaWiki/Interface/MessageByMediaWiki=Message by MediaWiki for Lightroom') if gps and gps.latitude and gps.longitude then - local location = '{{Location|' .. gps.latitude .. '|' .. gps.longitude .. '}}\n' + local location = '{{Location|' .. gps.latitude .. '|' .. gps.longitude + -- If LR field "Direction" (German: "Richtung") is set, add "heading" parameter to Commons template "Location" + + -- The LR version is checked, because Adobe introduced the parameter "gpsImgDirection" to the + -- call of photo:getRawMetadata with LR SDK 6.0. + -- Without LR version check, the usage of this plug-in shows + -- a warning message at export, if using LR version < 6 (e.g. 5): + -- English: Warning – Unable to Export: An internal error has occurred: Unknown key: "gpsImgDirection" + -- German: Warnung – Export nicht möglich: Ein interner Fehler ist aufgetreten: Unknown key: "gpsImgDirection" + -- Even it's a warning, the export is cancelled. + -- To avoid this warning message, the version check is needed – substituted by a hint message. + + -- The version check differs between two cases of major LR versions: (a) >= 6 and (b) < 6 + -- At both cases a hint message box is shown – with different messages, depending on the LR version: + -- * (a) Users of LR 6 or higher get informed about this feature, if the user has set the "Direction" field. + -- * (b) Users of LR 5 or LR 4 get informed, the feature is not available, due to the insufficient LR version. + -- At both cases the hint message box includes a "Don't show again" (German: "Nicht erneut anzeigen") checkbox. + -- If the user decides, to set this option and decides to revert this decision later, a reset of warning dialogs at LR is needed: + -- English: Edit -> Preferences... -> General -> Prompts -> Reset all warning dialogs + -- German: Bearbeiten -> Voreinstellungen -> Allgemein -> Eingabeaufforderungen -> Alle Warndialogfelder zurücksetzen + + if LrMajorVersion >= 6 then + local heading = photo:getRawMetadata('gpsImgDirection') + -- The call of "getRawMetadata" with parameter "gpsImgDirection" is supported since LR 6.0 + if heading then + -- At users with a LR version >= 6: + -- LR can store a direction value with up to 4 digits beyond a decimal point, + -- but shows at user interface a rounded value without decimal places (by mouse over the direction field). + -- Showing a rounded value is done by the two LrMediaWiki hint messages too, to avoid confusion of the user seeing different values. + -- The Location template parameter "heading" is filled by the storage value of LR. + -- Sample: A LR direction input of 359.987654321 is stored by LR as 359.9876, shown by LR and by the hint messages + -- as 360°, at Location template the LR stored value of 359.9876 is set. + location = location .. '|heading:' .. heading -- append heading at location + local headingRounded = string.format("%.0f", heading) -- rounding, e.g. 359.9876 -> 360 + -- There are problems inserting newlines (\n) in JASON strings. Workaround, splitting the message in 4 parts: + local hintLine1 = LOC('$$$/LrMediaWiki/Interface/HintHeadingTrueL1=Hint: The Lightroom field “Direction” has a value of ^1°.', headingRounded) + local hintLine2 = LOC('$$$/LrMediaWiki/Interface/HintHeadingTrueL2=This value has been used to set the “heading” parameter at {{Location}} template.') + local hintLine3 = LOC('$$$/LrMediaWiki/Interface/HintHeadingTrueL3=This feature requires a Lightroom version 6/CC or higher.') + local hintLine4 = LOC('$$$/LrMediaWiki/Interface/HintHeadingTrueL4=This Lightroom version is ^1, therefore this feature works.', LrVersionString ) + local hintMessage = hintLine1 .. '\n' .. hintLine2 .. '\n' .. hintLine3 .. '\n' .. hintLine4 + local messageTable = {message = hintMessage, info = subText, actionPrefKey = 'Show hint message of used LR version'} + LrDialogs.messageWithDoNotShow(messageTable) + else + -- This shouldn't happen, because LR has a good direction field check, accepting only valid values. + -- It might be impossible, to test this case. However, shit happens. + LrDialogs.message(LOC '$$$/LrMediaWiki/Interface/InvalidDirectionValue=“Direction” has an invalid value.', subText, 'critical') + end + else -- LrMajorVersion < 6 + if LrMajorVersion == 5 then + -- LR versions < 5 don't have a "Direction" field + -- There are problems inserting newlines (\n) in JASON strings. Workaround, splitting the message in 3 parts: + local hintLine1 = LOC('$$$/LrMediaWiki/Interface/HintHeadingFalseL1=Hint: If the Lightroom field “Direction” has a value, this can not be used to set a “heading” parameter at {{Location}} template.') + local hintLine2 = LOC('$$$/LrMediaWiki/Interface/HintHeadingFalseL2=This feature requires a Lightroom version 6/CC or higher.') + local hintLine3 = LOC('$$$/LrMediaWiki/Interface/HintHeadingFalseL3=This Lightroom version is ^1, therefore this feature works not.', LrVersionString ) + local hintMessage = hintLine1 .. '\n' .. hintLine2 .. '\n' .. hintLine3 + local table = {message = hintMessage, info = subText, actionPrefKey = 'Show hint message of used LR version'} + LrDialogs.messageWithDoNotShow(table) + end + end + location = location .. '}}\n' -- close Location template templates = location .. templates end diff --git a/mediawiki.lrdevplugin/TranslatedStrings_de.txt b/mediawiki.lrdevplugin/TranslatedStrings_de.txt index c97751b..bd83674 100755 --- a/mediawiki.lrdevplugin/TranslatedStrings_de.txt +++ b/mediawiki.lrdevplugin/TranslatedStrings_de.txt @@ -14,7 +14,15 @@ "$$$/LrMediaWiki/Export/Snapshot=MediaWiki-Export, ^1 ^2, ^3" "$$$/LrMediaWiki/Init/Version/Info=Bitte aktualisiere LrMediaWiki auf die neue Version ^1." "$$$/LrMediaWiki/Init/Version/Message=Neue Version verfügbar" +"$$$/LrMediaWiki/Interface/HintHeadingFalseL1=Hinweis: Falls das Lightroom-Feld „Richtung“ einen Wert hat, kann dieser nicht als Parameter „heading“ in der {{Location}}-Vorlage gesetzt werden." +"$$$/LrMediaWiki/Interface/HintHeadingFalseL2=Diese Feature erfordert eine Lightroom-Version 6/CC oder höher." +"$$$/LrMediaWiki/Interface/HintHeadingFalseL3=Diese Lightroom-Version ist ^1, daher funktioniert das Feature nicht." +"$$$/LrMediaWiki/Interface/HintHeadingTrueL1=Hinweis: Das Lightroom-Feld „Richtung“ hat einen Wert von ^1°." +"$$$/LrMediaWiki/Interface/HintHeadingTrueL2=Dieser Wert wurde benutzt, um den „heading“-Parameter in der {{Location}}-Vorlage zu setzen." +"$$$/LrMediaWiki/Interface/HintHeadingTrueL3=Dieses Feature erfordert eine Lightroom-Version 6/CC oder höher." +"$$$/LrMediaWiki/Interface/HintHeadingTrueL4=Diese Lightroom-Version ist ^1, daher funktioniert das Feature." "$$$/LrMediaWiki/Interface/Internal/NotLoggedIn=Interner Fehler: vor dem Upload nicht angemeldet." +"$$$/LrMediaWiki/Interface/InvalidDirectionValue=„Richtung“ hat einen ungültigen Wert." "$$$/LrMediaWiki/Interface/InUse/Cancel=Abbrechen" "$$$/LrMediaWiki/Interface/InUse/Details=Es gibt bereits eine Datei mit dem Namen ^1. Überschreiben? (Die Dateibeschreibung wird nicht verändert.)" "$$$/LrMediaWiki/Interface/InUse/OK=Überschreiben" @@ -22,6 +30,7 @@ "$$$/LrMediaWiki/Interface/InUse=Dateiname schon verwendet" "$$$/LrMediaWiki/Interface/LoadingDescriptionFailed=Die Datei mit der Vorlage für die Bildbeschreibung konnte nicht geöffnet werden: ^1" "$$$/LrMediaWiki/Interface/LoginFailed=Login fehlgeschlagen: ^1." +"$$$/LrMediaWiki/Interface/MessageByMediaWiki=Mitteilung von MediaWiki für Lightroom" "$$$/LrMediaWiki/Interface/ReadingDescriptionFailed=Die Datei mit der Vorlage für die Bildbeschreibung konnte nicht gelesen werden." "$$$/LrMediaWiki/Interface/Rename/NewName=Neuer Dateiname" "$$$/LrMediaWiki/Interface/Rename=Datei umbenennen" -- cgit v1.2.3