Skip to content

Commit c9e0b0a

Browse files
committed
Correct IQDB max filesize; minor UI fixes
1 parent f850f95 commit c9e0b0a

File tree

7 files changed

+61
-45
lines changed

7 files changed

+61
-45
lines changed

SmartImage 3/Modes/GuiMode.cs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ public override void Dispose()
373373

374374
protected override void ProcessArg(object? val, IEnumerator e)
375375
{
376+
376377
if (val is string s && s == Resources.Arg_Input) {
377378
e.MoveNext();
378379
var s2 = e.Current?.ToString();
@@ -385,15 +386,15 @@ protected override void ProcessArg(object? val, IEnumerator e)
385386

386387
#endregion
387388

389+
//note: ideally some of these computations aren't necessary and can be stored as respective fields but this is to ensure program correctness
390+
388391
private bool IsQueryReady()
389392
{
390-
//note: ideally this computation isn't necessary and can be stored as a bool field but this is to ensure program correctness
391393
return Query != SearchQuery.Null && Url.IsValid(Query.Upload);
392394
}
393395

394396
private bool IsInputValidIndicator()
395397
{
396-
//note: ideally this computation isn't necessary and can be stored as a bool field but this is to ensure program correctness
397398
return SearchQuery.IsIndicatorValid(Tf_Input.Text.ToString());
398399
}
399400

@@ -402,12 +403,6 @@ private void ApplyConfig()
402403
Integration.KeepOnTop(Config.OnTop);
403404
}
404405

405-
public void SetInfoText(string s)
406-
{
407-
Lbl_InputInfo2.Text = $"{s}";
408-
Lbl_InputInfo2.SetNeedsDisplay();
409-
}
410-
411406
internal void SetInputText(ustring s)
412407
{
413408
Tf_Input.Text = s;
@@ -476,7 +471,8 @@ private bool ClipboardCallback(MainLoop c)
476471
*/
477472
if (Integration.ReadClipboard(out var str) && !IsInputValidIndicator() && !m_clipboard.Contains(str)) {
478473
SetInputText(str);
479-
Lbl_InputOk.Text = Values.Clp;
474+
// Lbl_InputOk.Text = Values.Clp;
475+
Lbl_InputInfo.Text = $"Clipboard data";
480476

481477
m_clipboard.Add(str);
482478
}
@@ -499,6 +495,10 @@ private bool ClipboardCallback(MainLoop c)
499495
private void OnClear()
500496
{
501497
Tf_Input.DeleteAll();
498+
Lbl_InputOk.Text = Values.NA;
499+
Lbl_InputOk.SetNeedsDisplay();
500+
Lbl_InputInfo.Text = ustring.Empty;
501+
Lbl_InputInfo2.Text = ustring.Empty;
502502
}
503503

504504
private void OnConfigDialog()
@@ -630,32 +630,39 @@ void ReloadDialog()
630630

631631
private void ClearControls()
632632
{
633-
try {
634-
Tf_Input.DeleteAll();
635-
Tf_Input.ClearHistoryChanges();
636-
Query = SearchQuery.Null;
633+
Tf_Input.DeleteAll();
634+
Tf_Input.ClearHistoryChanges();
637635

638-
Lbl_InputOk.Text = Values.NA;
639-
Dt_Results.Clear();
636+
Query = SearchQuery.Null;
637+
638+
Lbl_InputOk.Text = Values.NA;
639+
Lbl_InputOk.SetNeedsDisplay();
640640

641-
IsReady.Reset();
642-
ResultCount = 0;
643-
Pbr_Status.Fraction = 0;
641+
Dt_Results.Clear();
644642

645-
Lbl_InputInfo.Text = ustring.Empty;
646-
Lbl_QueryUpload.Text = ustring.Empty;
647-
Lbl_InputInfo2.Text = ustring.Empty;
648-
Lbl_Status.Text = ustring.Empty;
643+
IsReady.Reset();
644+
ResultCount = 0;
645+
Pbr_Status.Fraction = 0;
649646

650-
Tv_Results.SetNeedsDisplay();
651-
Tf_Input.SetFocus();
652-
Tf_Input.EnsureFocus();
653-
Btn_Cancel.Enabled = false;
647+
Lbl_InputInfo.Text = ustring.Empty;
648+
Lbl_QueryUpload.Text = ustring.Empty;
649+
Lbl_InputInfo2.Text = ustring.Empty;
650+
Lbl_Status.Text = ustring.Empty;
651+
652+
Tv_Results.SetNeedsDisplay();
653+
Tf_Input.SetFocus();
654+
Tf_Input.EnsureFocus();
655+
Btn_Cancel.Enabled = false;
656+
657+
/*Application.MainLoop.Invoke(() =>
658+
{ });*/
659+
660+
/*try {
654661
// Application.Refresh();
655662
}
656663
catch (Exception e) {
657664
Debug.WriteLine($"{e.Message}", nameof(ClearControls));
658-
}
665+
}*/
659666
}
660667

661668
private void OnRestart()
@@ -682,6 +689,8 @@ private void OnRestart()
682689
Tf_Input.SetFocus();
683690
Tf_Input.EnsureFocus();
684691

692+
/*Application.MainLoop.Invoke(() =>
693+
{ });*/
685694
}
686695

687696
private void OnCellActivated(TableView.CellActivatedEventArgs args)

SmartImage.Lib 3 Unit Test/UnitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public async Task SearchQuery_Test2(string s)
186186

187187
public async Task Test3(string s)
188188
{
189-
var o = await QFileHandle.GetHandleAsync(s);
189+
var o = await UniFile.GetHandleAsync(s);
190190
var o2 = await SearchQuery.TryCreateAsync(s);
191191
Assert.Pass();
192192
}

SmartImage.Lib 3/Engines/Search/IqdbEngine.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static SearchResultItem ParseResult(IHtmlCollection<IElement> tr, Search
9494
else {
9595
uri = null;
9696
}
97-
97+
9898
var result = new SearchResultItem(r)
9999
{
100100
Url = uri,
@@ -108,9 +108,10 @@ private static SearchResultItem ParseResult(IHtmlCollection<IElement> tr, Search
108108
return result;
109109
}
110110

111+
public const int MAX_FILE_SIZE = 8192 * 1024; // NOTE: assuming IQDB uses kilobytes instead of kibibytes
112+
111113
private async Task<IDocument> GetDocumentAsync(SearchQuery query)
112114
{
113-
const int MAX_FILE_SIZE = 0x800000;
114115

115116
if (query.Size > MAX_FILE_SIZE) {
116117
return null;

SmartImage.Lib 3/Engines/Search/SauceNaoEngine.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public sealed class SauceNaoEngine : BaseSearchEngine, IClientSearchEngine
4040
* https://github.com/luk1337/SauceNAO/blob/master/app/src/main/java/com/luk/saucenao/MainActivity.java
4141
*/
4242

43+
public string EndpointUrl => BASE_ENDPOINT;
44+
45+
public FlurlClient Client { get; }
46+
4347
public SauceNaoEngine(string authentication) : base(BASIC_RESULT)
4448
{
4549
Authentication = authentication;
@@ -467,14 +471,6 @@ private sealed class SauceNaoDataResult
467471

468472
public string Creator { get; internal set; }
469473
}
470-
471-
#region Implementation of IClientSearchEngine
472-
473-
public string EndpointUrl => BASE_ENDPOINT;
474-
475-
public FlurlClient Client { get; }
476-
477-
#endregion
478474
}
479475

480476
public enum SauceNaoSiteIndex

SmartImage.Lib 3/SearchClient.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ public async Task<List<SearchResult>> RunSearchAsync(SearchQuery query, Cancella
7272

7373
var url1 = result.Best?.Url ?? result.RawUrl;
7474

75-
if (url1 is { } && Url.IsValid(url1)) {
76-
HttpUtilities.OpenUrl(url1);
77-
}
78-
75+
HttpUtilities.TryOpenUrl(url1);
7976
}
8077

8178
results.Add(result);
@@ -104,7 +101,7 @@ public async Task<List<SearchResult>> RunSearchAsync(SearchQuery query, Cancella
104101
try {
105102
var result = results.SelectMany(r => r.Results)
106103
.Where(r => Url.IsValid(r.Url))
107-
.OrderByDescending(r => r.Similarity)
104+
.OrderByDescending(r => r.Score)
108105
.First();
109106

110107
Debug.WriteLine($"{result}");

SmartImage.Lib 3/SearchQuery.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.Runtime.CompilerServices;
66
using Flurl.Http;
7+
using Kantan.Net.Utilities;
78
using Novus.FileTypes;
89
using Kantan.Text;
910
using SmartImage.Lib.Engines.Upload;
@@ -12,6 +13,7 @@
1213
namespace SmartImage.Lib;
1314

1415
//todo: DynamicResource
16+
1517
public sealed class SearchQuery : IDisposable
1618
{
1719
public string Value { get; }
@@ -54,7 +56,10 @@ public static async Task<SearchQuery> TryCreateAsync(string value)
5456
}
5557
else {
5658
try {
57-
var res = await value.AllowAnyHttpStatus()
59+
var res = await value.AllowAnyHttpStatus().WithHeaders(new
60+
{
61+
User_Agent=HttpUtilities.UserAgent
62+
})
5863
.GetAsync();
5964

6065
/*if (!res.ResponseMessage.IsSuccessStatusCode) {

SmartImage.Lib 3/SearchResult.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ public sealed class SearchResult : IDisposable
3939
[CBN]
4040
public string Overview { get; internal set; }
4141

42+
[MN]
4243
public SearchResultItem Best
4344
{
44-
get { return Results.MaxBy(r => r.Score); }
45+
get
46+
{
47+
if (!Results.Any()) {
48+
return null;
49+
}
50+
51+
return Results.MaxBy(r => r.Score);
52+
}
4553
}
4654

4755
internal SearchResult(BaseSearchEngine bse)

0 commit comments

Comments
 (0)