Skip to content

Commit bab0425

Browse files
committed
Nicer settings form plus supports Free AI
1 parent 09c040b commit bab0425

File tree

2 files changed

+125
-93
lines changed

2 files changed

+125
-93
lines changed

FetchXmlBuilder/Forms/Settings.Designer.cs

Lines changed: 68 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FetchXmlBuilder/Forms/Settings.cs

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public Settings(FetchXmlBuilder fxb, string tab)
2626
InitializeComponent();
2727
this.fxb = fxb;
2828
cmbAiSupplier.Items.Clear();
29+
cmbAiSupplier.Items.Add("");
2930
cmbAiSupplier.Items.AddRange(OnlineSettings.Instance.AiSupport.AiSuppliers.ToArray());
3031
PopulateSettings(fxb.settings);
3132
tabSettings.SelectedTab = tabSettings.TabPages
@@ -189,8 +190,18 @@ private void btnOK_Click(object sender, EventArgs e)
189190
}
190191
catch (Exception ex)
191192
{
192-
MessageBox.Show(ex.Message, "XML Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
193+
MessageBoxEx.Show(this, ex.Message, "XML Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
193194
DialogResult = DialogResult.None;
195+
return;
196+
}
197+
if (cmbAiSupplier.SelectedItem is AiSupplier supplier &&
198+
supplier.IsFree &&
199+
cmbAiModel.SelectedItem is AiModel model &&
200+
string.IsNullOrEmpty(model.ApiKeyDecrypted))
201+
{
202+
MessageBoxEx.Show(this, $"The selected Free AI model '{model.Name}' is not available right now. Please select another model.", "AI Chat Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
203+
DialogResult = DialogResult.None;
204+
return;
194205
}
195206
}
196207

@@ -313,10 +324,30 @@ cmbAiModel.SelectedItem is AiModel model &&
313324
}
314325
}
315326

327+
private void HandlingFreeAI()
328+
{
329+
if (cmbAiModel.SelectedItem is AiModel selectedmodel && string.IsNullOrEmpty(selectedmodel.ApiKeyDecrypted))
330+
{
331+
txtAiApiKey.Text = "Unfortunately, this model is currently not supported.";
332+
}
333+
else
334+
{
335+
if (AiChatControl.IsFreeAiUser(fxb))
336+
{
337+
txtAiApiKey.Text = "ApiKey is handled by Jonas for this free provider.";
338+
}
339+
else
340+
{
341+
txtAiApiKey.Text = "To use the free provider, you have to submit a form only for Jonas to make sure you are not using gazillian tokens. Click the (i) button on the provider above!";
342+
picAiSupplier.Tag = "FREE";
343+
tt.SetToolTip(picAiSupplier, $"Click to fill in the form to get free provider! at {OnlineSettings.Instance.AiSupport.UrlToUseForFree}");
344+
}
345+
}
346+
}
347+
316348
private void cmbAiSupplier_SelectedIndexChanged(object sender = null, EventArgs e = null)
317349
{
318350
cmbAiModel.Items.Clear();
319-
picAiSupplier.Tag = null;
320351
if (cmbAiSupplier.SelectedItem is AiSupplier supplier)
321352
{
322353
tt.SetToolTip(picAiSupplier, $"Read about {supplier.Name} at {supplier.Url}");
@@ -330,43 +361,42 @@ private void cmbAiSupplier_SelectedIndexChanged(object sender = null, EventArgs
330361
{
331362
cmbAiModel.SelectedIndex = 0;
332363
}
364+
}
365+
else
366+
{
367+
picAiSupplier.Tag = null;
368+
}
369+
cmbAiModel_SelectedIndexChanged();
370+
}
371+
372+
private void cmbAiModel_SelectedIndexChanged(object sender = null, EventArgs e = null)
373+
{
374+
if (cmbAiSupplier.SelectedItem is AiSupplier supplier && cmbAiModel.SelectedItem is AiModel model)
375+
{
376+
picAiUrl.Tag = OnlineSettings.Instance.AiSupport.Supplier(cmbAiSupplier.Text)?.Models.FirstOrDefault(m => m.Name == cmbAiModel.Text)?.Url;
333377
if (supplier.IsFree)
334378
{
335-
if (AiChatControl.IsFreeAiUser(fxb))
336-
{
337-
txtAiApiKey.Text = "ApiKey is handled by Jonas for this free provider.";
338-
}
339-
else
340-
{
341-
txtAiApiKey.Text = "To use the free provider, you have to submit a form only for Jonas to make sure you are not using gazillian tokens. Click the (i) button on the provider above!";
342-
picAiSupplier.Tag = "FREE";
343-
tt.SetToolTip(picAiSupplier, $"Click to fill in the form to get free provider! at {OnlineSettings.Instance.AiSupport.UrlToUseForFree}");
344-
}
345-
txtAiApiKey.Enabled = false;
379+
HandlingFreeAI();
346380
}
347-
else
381+
else //if (sender != null)
348382
{
349-
txtAiApiKey.Enabled = true;
383+
LoadAiSettingsKey();
350384
}
385+
txtAiApiKey.Enabled = !supplier.IsFree;
351386
}
352-
picAiSupplier.Visible = !string.IsNullOrWhiteSpace(picAiSupplier.Tag as string);
353-
if (sender != null)
387+
else
354388
{
355-
LoadAiSettingsKey();
389+
picAiUrl.Tag = null;
390+
txtAiApiKey.Text = "";
391+
txtAiApiKey.Enabled = false;
356392
}
357-
}
358-
359-
private void cmbAiModel_SelectedIndexChanged(object sender, EventArgs e)
360-
{
361-
var aimodelurl = OnlineSettings.Instance.AiSupport.Supplier(cmbAiSupplier.Text)?.Models.FirstOrDefault(m => m.Name == cmbAiModel.Text)?.Url;
362-
picAiUrl.Tag = aimodelurl;
363-
picAiUrl.Visible = !string.IsNullOrWhiteSpace(aimodelurl);
364-
LoadAiSettingsKey();
393+
picAiSupplier.Visible = picAiSupplier.Tag != null;
394+
picAiUrl.Visible = picAiUrl.Tag != null;
365395
}
366396

367397
private void picAiSupplier_Click(object sender, EventArgs e)
368398
{
369-
if (sender is PictureBox pic && pic.Tag == "FREE")
399+
if (sender is PictureBox pic && pic.Tag is string text && text == "FREE")
370400
{
371401
AiChatControl.PromptToUseForFree(fxb);
372402
}

0 commit comments

Comments
 (0)