Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions RPS 4/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public Monitor(IntPtr previewHwnd, int id, Screensaver screensaver): this(id, sc
public void defaultShowHide() {
this.InvokeScript("setBackgroundColour", new string[] { Convert.ToString(this.screensaver.config.getPersistant("backgroundColour")) });
this.InvokeScript("toggle", new string[] { "#quickMetadata", Convert.ToString(this.screensaver.config.getPersistantBool("showQuickMetadataM" + (this.id + 1))) });
this.InvokeScript("toggle", new string[] { "#location", Convert.ToString(this.screensaver.config.getPersistantBool("showLocationM" + (this.id + 1))) });
this.InvokeScript("toggle", new string[] { "#filename", Convert.ToString(this.screensaver.config.getPersistantBool("showFilenameM" + (this.id + 1))) });
this.InvokeScript("toggle", new string[] { "#filename .root", Convert.ToString(this.screensaver.config.getPersistantBool("showPathRoot")) });
this.InvokeScript("toggle", new string[] { "#filename .subfolders", Convert.ToString(this.screensaver.config.getPersistantBool("showPathSubfolders")) });
Expand Down Expand Up @@ -440,6 +441,12 @@ public void readMetadataImage() {
}
if (rawMetadata != null && rawMetadata != "") {
this.quickMetadata = new MetadataTemplate(rawMetadata, Utils.HtmlDecode(this.screensaver.config.getPersistantString("quickMetadata")));
if (this.quickMetadata.metadata.ContainsKey("gpslatitude") && this.quickMetadata.metadata.ContainsKey("gpslongitude")) {
string location = Utils.GetLocationFromGps(this.quickMetadata.metadata["gpslatitude"], this.quickMetadata.metadata["gpslongitude"]);
if (location != null) {
this.imageSettings["location"] = location;
}
}
this.imageSettings["metadata"] = this.quickMetadata.fillTemplate();
}
this.imageSettings["mediatype"] = "image";
Expand Down
2 changes: 1 addition & 1 deletion RPS 4/RPS 4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.94.0\build\net40\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.94.0\build\net40\System.Data.SQLite.Core.targets'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>call "$(DevEnvDir)..\Tools\vsvars32.bat"
<PostBuildEvent>call "$(DevEnvDir)..\Tools\VsDevCmd.bat"
IF NOT EXIST "$(TargetDir)vendor" MKDIR "$(TargetDir)vendor"
xcopy /d /s "$(ProjectDir)vendor\*.*" "$(TargetDir)vendor"
rem IF NOT EXIST "$(TargetDir)data" MKDIR "$(TargetDir)data"
Expand Down
48 changes: 48 additions & 0 deletions RPS 4/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,57 @@
using System.Globalization;
using System.Collections;
using System.Collections.Concurrent;
using System.Net;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;

namespace RPS {
class Utils {
private static double ConvertDmsToDd(string dms) {
var matches = System.Text.RegularExpressions.Regex.Matches(dms, @"[0-9\.]+");
var parts = matches.Cast<System.Text.RegularExpressions.Match>().Select(m => m.Value).ToList();

if (parts.Count >= 3) {
double deg = double.Parse(parts[0], CultureInfo.InvariantCulture);
double min = double.Parse(parts[1], CultureInfo.InvariantCulture);
double sec = double.Parse(parts[2], CultureInfo.InvariantCulture);
return deg + (min / 60.0) + (sec / 3600.0);
} else if (parts.Count == 1) {
return double.Parse(parts[0], CultureInfo.InvariantCulture);
}
return 0;
}

public static string GetLocationFromGps(string latitudeStr, string longitudeStr) {
if (latitudeStr == null || longitudeStr == null) return null;
try {
double latitude = ConvertDmsToDd(latitudeStr);
double longitude = ConvertDmsToDd(longitudeStr);

if (latitudeStr.ToUpper().Contains("S")) latitude = -latitude;
if (longitudeStr.ToUpper().Contains("W")) longitude = -longitude;

string url = $"https://nominatim.openstreetmap.org/reverse?format=json&lat={latitude.ToString(CultureInfo.InvariantCulture)}&lon={longitude.ToString(CultureInfo.InvariantCulture)}&accept-language=en";
Debug.WriteLine("GetLocationFromGps url:" + url);
using (WebClient wc = new WebClient()) {
wc.Headers.Add("User-Agent", "RPS/4.0 (a screensaver)"); // Per Nominatim requirements
string json = wc.DownloadString(url);
JObject data = JObject.Parse(json);
if (data["error"] == null && data["address"] != null) {
string townish = new[] { "town", "city", "municipality", "village" }
.Select(key => (string)data["address"][key])
.FirstOrDefault(val => !string.IsNullOrEmpty(val)) ?? "";
string country = (string)data["address"]["country"] ?? "";
string prettyName = !string.IsNullOrEmpty(townish) ? $"{townish}, {country}" : country;
Debug.WriteLine("GetLocationFromGps:" + prettyName);
return prettyName;
}
}
} catch (Exception ex) {
Debug.WriteLine("Error in GetLocationFromGps: " + ex.Message);
}
return null;
}
public struct MSG {
IntPtr hwnd;
uint message;
Expand Down
1 change: 1 addition & 0 deletions RPS 4/data/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ <h2>Monitor 1</h2>
<h3>Information</h3>
<label for="showFilenameM1" class="tooltip" data-title="Toggle with F key whilst screensaver is running. Show advanced settings to set which parts of the filepath to show."><input type="checkbox" id="showFilenameM1" checked /> Show filename</label><br/>
<label for="showQuickMetadataM1" class="tooltip" data-title="Toggle with N key whilst screensaver is running"><input type="checkbox" id="showQuickMetadataM1" checked /> Show quick metadata</label><br/>
<label for="showLocationM1" class="tooltip" data-title="Show photo location information (if available in EXIF data)."><input type="checkbox" id="showLocationM1" checked /> Show location</label><br/>
<label for="showIndexProgressM1" class="tooltip" data-title="Show info on number of files: in database, selected by filter, metadata queue and files/folders scanned"><input type="checkbox" id="showIndexProgressM1" checked /> Show database / index / filter info</label>
</div>
<div class="set radioGroup">
Expand Down
7 changes: 7 additions & 0 deletions RPS 4/data/css/monitor.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ html, body {
text-align: right;
}

#location {
z-index: 100;
right: 0.5em;
bottom: 2.5em;
text-align: right;
}

#debug {
z-index: 100;
right: 0.5em;
Expand Down
5 changes: 5 additions & 0 deletions RPS 4/data/js/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ function showImage(source, displayPath, settings) {
$("#filename .filename")[0].innerHTML = settings["path.filename"];
$("#filename .extension")[0].innerHTML = settings["path.extension"];
document.getElementById("quickMetadata").innerHTML = settings["metadata"];
if (settings["location"] != undefined) {
document.getElementById("location").innerHTML = settings["location"];
} else {
document.getElementById("location").innerHTML = "";
}

if (settings["pano"] != undefined && settings["pano"] == true) {
// window.prompt("Copy to clipboard: Ctrl+C, Enter", html);
Expand Down
1 change: 1 addition & 0 deletions RPS 4/data/monitor.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div id="indexprogress" class="info">#indexprogress#</div>
<div id="debug" class="info">#debug#</div>
<div id="quickMetadata" class="info">#metadata#</div>
<div id="location" class="info">#location#</div>
<div id="clock" class="info">hh:mm:ss</div>
<div id="rolodex" class=""></div>
</body>
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Random Photo Screensaver(tm) 4

Random Photo Screensaver 4 (RPS4) is a photo slideshow screensaver written in Visual Studio C#.

* This fork adds support for displaying photo location using EXIF GPS data. Most of the work was done by Jules, I just added some finishing touches and tweaks.

Download / preview
------------------
You can download the latest executable for Windows 7 & 8/8.1 from [abScreensavers.com](http://www.abscreensavers.com/random-photo-screensaver). This also showcases some of its many features.
Expand Down