diff --git a/src/AppHosts/SuperMemoAssistant/CollectionSelectionWindow.xaml b/src/AppHosts/SuperMemoAssistant/CollectionSelectionWindow.xaml index c84673b..9724ea0 100644 --- a/src/AppHosts/SuperMemoAssistant/CollectionSelectionWindow.xaml +++ b/src/AppHosts/SuperMemoAssistant/CollectionSelectionWindow.xaml @@ -34,6 +34,7 @@ + @@ -91,6 +92,37 @@ + + + "Good learning is inherently pleasurable, and without pleasure there is no good learning." + + + Piotr Wozniak + + + + + Pleasure of Learning + + + + + + + diff --git a/src/AppHosts/SuperMemoAssistant/CollectionSelectionWindow.xaml.cs b/src/AppHosts/SuperMemoAssistant/CollectionSelectionWindow.xaml.cs index 77982a3..bec8222 100644 --- a/src/AppHosts/SuperMemoAssistant/CollectionSelectionWindow.xaml.cs +++ b/src/AppHosts/SuperMemoAssistant/CollectionSelectionWindow.xaml.cs @@ -44,6 +44,10 @@ using SuperMemoAssistant.SMA.Configs; using SuperMemoAssistant.Sys.IO; using SuperMemoAssistant.Sys.Windows.Input; +using SuperMemoAssistant.Interop; +using Anotar.Serilog; +using System.Diagnostics; +using System.Windows.Navigation; namespace SuperMemoAssistant { @@ -72,6 +76,7 @@ public CollectionSelectionWindow(StartupCfg startupCfg) lbCollections.SelectedIndex = 0; Loaded += CollectionSelectionWindow_Loaded; + Loaded += ShowQuoteOfTheDay; } #endregion @@ -244,6 +249,61 @@ private void CollectionSelectionWindow_Loaded(object sender, lbCollections.SelectFirstItem(); } + private void TitleLink_RequestNavigate(object sender, RequestNavigateEventArgs e) + { + Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); + e.Handled = true; + } + + private void ShowQuoteOfTheDay(object sender, RoutedEventArgs e) + { + + var QuoteFile = SMAFileSystem.AppRootDir.CombineFile("quotes.tsv"); + + if (QuoteFile.Exists()) + { + try + { + var Lines = File.ReadAllLines(QuoteFile.FullPath); + + // Line 1 is .tsv heading + if (Lines.Length <= 1) + { + return; + } + + var RandInt = new Random(); + var RandomLineNumber = RandInt.Next(1, Lines.Length - 1); + var QuoteLine = Lines[RandomLineNumber]; + var SplitQuoteLine = QuoteLine.Split('\t'); + + // Tab separated file + // Field 0: Quote + // Field 1: Author + // Field 2: Url + // Field 3: Title + if (!SplitQuoteLine[0].EndsWith(".") + && !SplitQuoteLine[0].EndsWith("!") + && !SplitQuoteLine[0].EndsWith("?")) + { + SplitQuoteLine[0] += "."; + } + + QuoteBodyTextBlock.Text = "\"" + SplitQuoteLine[0] + "\""; + QuoteAuthorTextBlock.Text = SplitQuoteLine[1]; + TitleHyperlink.NavigateUri = new Uri(SplitQuoteLine[2]); + QuoteTitleTextBlock.Text = SplitQuoteLine[3]; + } + catch (IOException ex) + { + LogTo.Warning(ex, $"IOException when trying to open {QuoteFile.FullPath}"); + } + catch (Exception ex) + { + LogTo.Error(ex, $"Exception caught while opening file {QuoteFile.FullPath}"); + } + } + } #endregion } }