Skip to content

Commit

Permalink
Merge pull request #46 from lizaalert/dev_desktopApp
Browse files Browse the repository at this point in the history
feat: add geo tags and prepare 0.3.0 release
  • Loading branch information
gosha20777 authored Sep 26, 2019
2 parents 32c79cf + c2b8ad1 commit eda8512
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 2 deletions.
118 changes: 118 additions & 0 deletions RescuerLaApp/Models/TextTableBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace RescuerLaApp.Models
{
public interface ITextRow
{
String Output();
void Output(StringBuilder sb);
Object Tag { get; set; }
}

public class TextTableBuilder : IEnumerable<ITextRow>
{
protected class TextRow : List<String>, ITextRow
{
protected TextTableBuilder owner = null;
public TextRow(TextTableBuilder Owner)
{
owner = Owner;
if (owner == null) throw new ArgumentException("Owner");
}
public String Output()
{
StringBuilder sb = new StringBuilder();
Output(sb);
return sb.ToString();
}
public void Output(StringBuilder sb)
{
sb.AppendFormat(owner.FormatString, this.ToArray());
}
public Object Tag { get; set; }
}

public String Separator { get; set; }

protected List<ITextRow> rows = new List<ITextRow>();
protected List<int> colLength = new List<int>();

public TextTableBuilder()
{
Separator = " ";
}

public TextTableBuilder(String separator)
: this()
{
Separator = separator;
}

public ITextRow AddRow(params object[] cols)
{
TextRow row = new TextRow(this);
foreach (object o in cols)
{
String str = o.ToString().Trim();
row.Add(str);
if (colLength.Count >= row.Count)
{
int curLength = colLength[row.Count - 1];
if (str.Length > curLength) colLength[row.Count - 1] = str.Length;
}
else
{
colLength.Add(str.Length);
}
}
rows.Add(row);
return row;
}

protected String _fmtString = null;
public String FormatString
{
get
{
if (_fmtString == null)
{
String format = "";
int i = 0;
foreach (int len in colLength)
{
format += String.Format("{{{0},-{1}}}{2}", i++, len, Separator);
}
format += "\r\n";
_fmtString = format;
}
return _fmtString;
}
}

public String Output()
{
StringBuilder sb = new StringBuilder();
foreach (TextRow row in rows)
{
row.Output(sb);
}
return sb.ToString();
}

#region IEnumerable Members

public IEnumerator<ITextRow> GetEnumerator()
{
return rows.GetEnumerator();
}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return rows.GetEnumerator();
}

#endregion
}
}
1 change: 1 addition & 0 deletions RescuerLaApp/RescuerLaApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Avalonia.Skia.Linux.Natives" Version="1.68.0.2" />
<PackageReference Include="Docker.DotNet" Version="3.125.2" />
<PackageReference Include="MessageBox.Avalonia" Version="0.8.3" />
<PackageReference Include="MetadataExtractor" Version="2.1.0" />
<PackageReference Include="NewtonSoft.Json" Version="12.0.2" />
<PackageReference Include="ReactiveUI.Fody" Version="9.16.3" />
</ItemGroup>
Expand Down
66 changes: 66 additions & 0 deletions RescuerLaApp/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reactive;
using System.Reactive.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
Expand All @@ -15,9 +16,11 @@
using MessageBox.Avalonia.DTO;
using MessageBox.Avalonia.Enums;
using MessageBox.Avalonia.Models;
using MetadataExtractor;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Newtonsoft.Json;
using Directory = System.IO.Directory;

namespace RescuerLaApp.ViewModels
{
Expand Down Expand Up @@ -68,6 +71,8 @@ public MainWindowViewModel()
ShowPerestriansCommand = ReactiveCommand.Create(ShowPedestrians, canExecute);
ImportAllCommand = ReactiveCommand.Create(ImportAll, canExecute);
SaveAllImagesWithObjectsCommand = ReactiveCommand.Create(SaveAllImagesWithObjects, canExecute);
ShowAllMetadataCommand = ReactiveCommand.Create(ShowAllMetadata, canExecute);
ShowGeoDataCommand = ReactiveCommand.Create(ShowGeoData, canExecute);
HelpCommand = ReactiveCommand.Create(Help);
AboutCommand = ReactiveCommand.Create(About);
ExitCommand = ReactiveCommand.Create(Exit, canExecute);
Expand Down Expand Up @@ -130,6 +135,9 @@ public void UpdateFramesRepo()
public ReactiveCommand<Unit, Unit> ShowPerestriansCommand { get; }

public ReactiveCommand<Unit, Unit> SaveAllImagesWithObjectsCommand { get; }

public ReactiveCommand<Unit, Unit> ShowAllMetadataCommand { get; }
public ReactiveCommand<Unit, Unit> ShowGeoDataCommand { get; }
public ReactiveCommand<Unit, Unit> HelpCommand { get; }
public ReactiveCommand<Unit, Unit> AboutCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; }
Expand Down Expand Up @@ -542,6 +550,64 @@ public void Help()
{
OpenUrl("https://github.com/lizaalert/lacmus/wiki");
}

public void ShowGeoData()
{
string msg = string.Empty;
int rows = 0;
var directories = ImageMetadataReader.ReadMetadata(Frames[SelectedIndex].Patch);
foreach (var directory in directories)
foreach (var tag in directory.Tags)
{
if (directory.Name.ToLower() == "gps")
{
if (tag.Name.ToLower() == "gps latitude" ||
tag.Name.ToLower() == "gps longitude" ||
tag.Name.ToLower() == "gps altitude")
{
rows++;
msg += $"{tag.Name}: {tag.Description}\n";
}
}
}

if (rows != 3)
msg = "This image have hot geo tags.\nUse `Show all metadata` more for more details.";
var msgbox = new MessageBox.Avalonia.MessageBoxWindow(new MessageBoxParams
{
Button = ButtonEnum.Ok,
ContentTitle = $"Geo position of {Path.GetFileName(Frames[SelectedIndex].Patch)}",
ContentMessage = msg,
Icon = Icon.Info,
Style = Style.None,
ShowInCenter = true
});
msgbox.Show();
}

public void ShowAllMetadata()
{
var tb = new TextTableBuilder();
tb.AddRow("Group", "Tag name", "Description");
tb.AddRow("-----", "--------", "-----------");


var directories = ImageMetadataReader.ReadMetadata(Frames[SelectedIndex].Patch);
foreach (var directory in directories)
foreach (var tag in directory.Tags)
tb.AddRow(directory.Name, tag.Name, tag.Description);

var msgbox = new MessageBox.Avalonia.MessageBoxWindow(new MessageBoxParams
{
Button = ButtonEnum.Ok,
ContentTitle = $"Metadata of {Path.GetFileName(Frames[SelectedIndex].Patch)}",
ContentMessage = tb.Output(),
Icon = Icon.Info,
Style = Style.None,
ShowInCenter = true
});
msgbox.Show();
}

public async void About()
{
Expand Down
11 changes: 9 additions & 2 deletions RescuerLaApp/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,15 @@
VerticalAlignment="Stretch"
Background="{Binding ImageBrush}"
Height="{Binding CanvasHeight, Mode=TwoWay}"
Width="{Binding CanvasWidth, Mode=TwoWay}"
/>
Width="{Binding CanvasWidth, Mode=TwoWay}">
<Canvas.ContextMenu>
<ContextMenu>
<MenuItem Header="Show geo position" Command="{Binding ShowGeoDataCommand}"/>
<!-- <MenuItem Header="Find nearest photo"/> -->
<MenuItem Header="Show all metadata" Command="{Binding ShowAllMetadataCommand}"/>
</ContextMenu>
</Canvas.ContextMenu>
</Canvas>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
Expand Down

0 comments on commit eda8512

Please sign in to comment.