Skip to content

Commit

Permalink
Added tool for batch adding photos (fix #520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Jan 29, 2024
1 parent 963c96b commit abd903b
Show file tree
Hide file tree
Showing 32 changed files with 184 additions and 9 deletions.
2 changes: 2 additions & 0 deletions locales/Belarusian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Chinese Simplified.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Dutch.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/English.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Hungarian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Icelandic.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Japanese.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Kazakh (Cyrillic).lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Portuguese.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Serbian (Latin).lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/Spanish.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/czech.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/french.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/german.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p>
<b>??.??.2024 [v2.29.0 &amp; v3.5.0]</b><ul>
<li>Added a tool for batch adding photos.
<li>Added support for multiple names and date periods in location records (GEDCOM 5.5 EL).
<li>Added a non-standard date attribute to source records (for clarifying and sorting censuses, parish books, confession books and personal documents).
<li>Fixed missing empty lines in notes.
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p>
<b>??.??.2024 [v2.29.0 &amp; v3.5.0]</b><ul>
<li>Добавлен инструмент пакетного добавления фотографий.
<li>Добавлена поддержка множественных названий и периодов дат в записи мест (GEDCOM 5.5 EL).
<li>Добавлен нестандартный атрибут даты в записи источников (для уточнения и сортировки переписей, метрических книг, ревизских сказок, исповедных книг и личных документов).
<li>Исправлены отсутствующие пустые строки в заметках.
Expand Down
2 changes: 2 additions & 0 deletions locales/italian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/polish.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
2 changes: 2 additions & 0 deletions locales/russian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=История
939=Периоды названий места пересекаются. Это приведет к ошибкам при поиске названия места по дате.
940=Расширенная обработка мест
941=Пакетное добавление фотографий
942=Добавлено {0} фотографий из {1}.
2 changes: 2 additions & 0 deletions locales/ukrainian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,5 @@
938=History
939=The periods of place names overlap. This will cause errors when searching for a place name by date.
940=Extended locations
941=Photos batch adding
942=Added {0} photos from {1}.
30 changes: 29 additions & 1 deletion projects/GKCore/GKCore/BaseContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -395,6 +395,34 @@ public bool IsRecordAccess(GDMRestriction restriction)

#region Data search

public GDMIndividualRecord FindIndividual(string searchName, Dictionary<string, string> facts)
{
int num = fTree.RecordsCount;
for (int i = 0; i < num; i++) {
var rec = fTree[i] as GDMIndividualRecord;
if (rec == null) continue;

string indiName = GKUtils.GetNameString(rec, false);
if (indiName == searchName) {
var res = true;
foreach (var pair in facts) {
if (pair.Key == "birth_year") {
int birthYear = rec.GetChronologicalYear(GEDCOMTagName.BIRT);
res = res && (birthYear.ToString() == pair.Value);
}

if (!res) break;
}

if (res) {
return rec;
}
}
}

return null;
}

public GDMSourceRecord FindSource(string sourceName)
{
GDMSourceRecord result = null;
Expand Down
56 changes: 55 additions & 1 deletion projects/GKCore/GKCore/Controllers/BaseWinController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -935,6 +935,7 @@ public override void SetLocale()
GetControl<IMenuItem>("miTreeCheck").Text = LangMan.LS(LSID.TreeCheck);
GetControl<IMenuItem>("miPatSearch").Text = LangMan.LS(LSID.PatriarchsSearch);
GetControl<IMenuItem>("miPlacesManager").Text = LangMan.LS(LSID.PlacesManager);
GetControl<IMenuItem>("miPhotosBatchAdding").Text = LangMan.LS(LSID.PhotosBatchAdding);

GetControl<IMenuItem>("miContext").Text = LangMan.LS(LSID.MIContext);
GetControl<IMenuItem>("miAbout").Text = LangMan.LS(LSID.MIAbout) + @"...";
Expand Down Expand Up @@ -1204,6 +1205,59 @@ public void ShowFamilyGroups()
}
}

public async void ShowPhotosBatchAdding()
{
try {
if (!fContext.CheckBasePath())
return;

string[] fileNames = await AppHost.StdDialogs.GetOpenFiles("", string.Empty, LangMan.LS(LSID.ImagesFilter), 1, "");
if (fileNames == null || fileNames.Length == 0) return;

int added = 0;
for (int i = 0; i < fileNames.Length; i++) {
var filePath = fileNames[i];

try {
string fName = Path.GetFileNameWithoutExtension(filePath);
if (!string.IsNullOrEmpty(fName) && fName.Contains(",")) {
string[] parts = fName.Split(',');
string indiName = parts[0].Trim();
string indiYear = parts[1].Trim();

Dictionary<string, string> facts = new Dictionary<string, string>();
facts.Add("birth_year", indiYear);

var indi = fContext.FindIndividual(indiName, facts);
if (indi != null) {
var mediaRec = new GDMMultimediaRecord(fContext.Tree);
fContext.Tree.NewXRef(mediaRec);

var fileRef = mediaRec.FileReferences.Add(new GDMFileReferenceWithTitle());
fileRef.MediaType = GDMMediaType.mtPhoto;
fileRef.Title = fName;

if (fContext.MediaSave(fileRef, filePath, GlobalOptions.Instance.MediaStoreDefault)) {
fContext.Tree.AddRecord(mediaRec);

var mmLink = indi.AddMultimedia(mediaRec);
added += 1;
}
}
}
} catch (Exception ex) {
Logger.WriteError("BaseWinController.ShowPhotosBatchAdding().1", ex);
}
}

RefreshLists(false);

AppHost.StdDialogs.ShowMessage(LangMan.LS(LSID.AddedNPhotos, added, fileNames.Length));
} catch (Exception ex) {
Logger.WriteError("BaseWinController.ShowPhotosBatchAdding().0", ex);
}
}

public void SendMail()
{
if (fView.CheckModified()) {
Expand Down
4 changes: 3 additions & 1 deletion projects/GKCore/GKCore/Design/Views/IStdDialogs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -32,6 +32,8 @@ public interface IStdDialogs

Task<string> GetOpenFile(string title, string context, string filter, int filterIndex, string defaultExt);

Task<string[]> GetOpenFiles(string title, string context, string filter, int filterIndex, string defaultExt);

Task<string> GetPassword(string prompt);

//Task<string> GetSaveFile(string filter);
Expand Down
3 changes: 2 additions & 1 deletion projects/GKCore/GKCore/Interfaces/IBaseContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -110,6 +110,7 @@ public interface IBaseContext : IDisposable
void UnlockRecord(GDMRecord record);
bool IsAvailableRecord(GDMRecord record);

GDMIndividualRecord FindIndividual(string searchName, Dictionary<string, string> facts);
GDMSourceRecord FindSource(string sourceName);
void GetSourcesList(StringList sources);

Expand Down
6 changes: 5 additions & 1 deletion projects/GKCore/GKCore/LangMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,10 @@ public enum LSID
/* 938 */ History,
/* 939 */ ThePeriodsOfPlaceNamesOverlap,
/* 940 */ ExtendedLocations,
/* 941 */ PhotosBatchAdding,
/* 942 */ AddedNPhotos,

/* 000 */ Last = ExtendedLocations
/* 000 */ Last = AddedNPhotos
}


Expand Down Expand Up @@ -1975,6 +1977,8 @@ public static class LangMan
/* 938 */ "History",
/* 939 */ "The periods of place names overlap. This will cause errors when searching for a place name by date.",
/* 940 */ "Extended locations",
/* 941 */ "Photos batch adding",
/* 942 */ "Added {0} photos from {1}.",
};

private static readonly LangManager fLangMan = new LangManager();
Expand Down
5 changes: 5 additions & 0 deletions projects/GKTests/Stubs/StdDialogsStub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public async Task<string> GetOpenFile(string title, string context, string filte
return await Task.FromResult(string.Empty);
}

public async Task<string[]> GetOpenFiles(string title, string context, string filter, int filterIndex, string defaultExt)
{
return await Task.FromResult(new string[0]);
}

public async Task<string> GetPassword(string prompt)
{
return await Task.FromResult(string.Empty);
Expand Down
12 changes: 11 additions & 1 deletion projects/GKv2/GEDKeeper2/GKUI/Forms/BaseWinSDI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion projects/GKv2/GEDKeeper2/GKUI/Forms/BaseWinSDI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -844,6 +844,11 @@ private void miTTFamilyGroups_Click(object sender, EventArgs e)
fController.ShowFamilyGroups();
}

private void miPhotosBatchAdding_Click(object sender, EventArgs e)
{
fController.ShowPhotosBatchAdding();
}

private void miOptions_Click(object sender, EventArgs e)
{
AppHost.Instance.ShowOptions(this);
Expand Down
9 changes: 9 additions & 0 deletions projects/GKv2/GKComponents/GKUI/Platform/WFStdDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public async Task<string> GetOpenFile(string title, string context, string filte
}
}

public async Task<string[]> GetOpenFiles(string title, string context, string filter, int filterIndex, string defaultExt)
{
filter = filter.Replace(',', ';');
using (OpenFileDialog ofd = CreateOpenFileDialog(title, context, filter, filterIndex, defaultExt, true)) {
string[] retStr = (ofd.ShowDialog() == DialogResult.OK) ? ofd.FileNames : new string[0];
return await Task.FromResult(retStr);
}
}

private static OpenFileDialog CreateOpenFileDialog(string title, string context, string filter,
int filterIndex, string defaultExt, bool multiSelect)
{
Expand Down
Loading

0 comments on commit abd903b

Please sign in to comment.