From 9c983d82f4d2a6c4b5b62624c35c4f3d680e7811 Mon Sep 17 00:00:00 2001 From: Lynne Date: Sun, 6 Sep 2020 15:27:11 +1000 Subject: [PATCH] i completely misunderstood how linq deferred execution worked... i'm surprised the whole thing didn't blow up with dozens of Gtk-CRITICALs every time you modified the watchlist 0uo --- MainWindow.cs | 94 +++++++++++++++++++++++++++++++++++---------------- ui/main.glade | 2 +- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/MainWindow.cs b/MainWindow.cs index 36f3fd5..60887e9 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -54,8 +54,36 @@ namespace Buypeeb { static SemaphoreSlim taskLimit = new SemaphoreSlim(6); private Queue updateQueue = new Queue(); - private IEnumerable filterQuery; - private IEnumerable outdatedItemQuery; + private IEnumerable filterQuery { + get { + // father forgive me for i have lynned + return + from item in this.settings.watchlist.Values.ToList() + where (item.favourite != this.filterChecks["Favourites"].Active || + item.favourite == this.filterChecks["NonFavourites"].Active) && + (item.available != this.filterChecks["Active"].Active || + item.available == this.filterChecks["Ended"].Active) && + (item.endingToday != this.filterChecks["EndingToday"].Active || + item.endingToday == this.filterChecks["EndingAfterToday"].Active) && + (item.hasWinPrice != this.filterChecks["WithWinPrice"].Active || + item.hasWinPrice == this.filterChecks["WithNoWinPrice"].Active) && + (String.IsNullOrWhiteSpace(this.searchEntry.Text) || + item.name.ToLower().Contains(this.searchEntry.Text.ToLower()) || + item.originalName.ToLower().Contains(this.searchEntry.Text.ToLower())) + select item; + } + } + private IEnumerable outdatedItemQuery { + get { + // only returns items that meet all of the following: + // - marked as "ready", as in, they aren't in the process of updating + // - not updated since the interval + return + from item in this.settings.watchlist.Values.ToList() + where item.ready && this.settings.ItemNotUpdatedSinceInterval(item) + select item; + } + } private YahooAuctionsItem selectedItem { get { @@ -121,30 +149,6 @@ namespace Buypeeb { this.filterChecks[name].Active = false; } - // only returns items that meet all of the following: - // - marked as "ready", as in, they aren't in the process of updating - // - not updated since the interval - this.outdatedItemQuery = - from item in this.settings.watchlist.Values.ToList() - where item.ready && this.settings.ItemNotUpdatedSinceInterval(item) - select item; - - // father forgive me for i have lynned - this.filterQuery = - from item in this.settings.watchlist.Values.ToList() - where (item.favourite != this.filterChecks["Favourites"].Active || - item.favourite == this.filterChecks["NonFavourites"].Active) && - (item.available != this.filterChecks["Active"].Active || - item.available == this.filterChecks["Ended"].Active) && - (item.endingToday != this.filterChecks["EndingToday"].Active || - item.endingToday == this.filterChecks["EndingAfterToday"].Active) && - (item.hasWinPrice != this.filterChecks["WithWinPrice"].Active || - item.hasWinPrice == this.filterChecks["WithNoWinPrice"].Active) && - (String.IsNullOrWhiteSpace(this.searchEntry.Text) || - item.name.ToLower().Contains(this.searchEntry.Text.ToLower()) || - item.originalName.ToLower().Contains(this.searchEntry.Text.ToLower())) - select item; - // bind treeview columns to watchlist instead of needing to manually sync its liststore this.itemTreeView = (TreeView)builder.GetObject("TreeViewItems"); this.items = new ListStore(typeof(YahooAuctionsItem)); @@ -266,9 +270,9 @@ namespace Buypeeb { } } - private void UpdateItem(string id, bool evenIfAlreadyUpdating = false, bool force = false) { + private void UpdateItem(string id, bool refilterWhenDone = false) { var item = this.settings.watchlist[id]; - if (item.updatedRecently && !force) { + if (item.updatedRecently) { // the item has been updated recently, and force is not true return; } @@ -278,7 +282,13 @@ namespace Buypeeb { taskLimit.Wait(); var t = Task.Factory.StartNew(() => { this.UpdateThread(id); - }).ContinueWith(task => { taskLimit.Release(); }); + }).ContinueWith(task => { + taskLimit.Release(); + if (refilterWhenDone) { + var m = (TreeModelFilter)this.itemTreeView.Model; + m.Refilter(); + } + }); } private void UpdateItems() { @@ -636,13 +646,30 @@ namespace Buypeeb { } catch (Exception e) { Console.WriteLine(e); - MsgBox($"Failed to write {sd.Filename}!\n{e.Message}.", ButtonsType.Ok); + var md = MsgBox($"Failed to write {sd.Filename}!\n{e.Message}.", ButtonsType.Ok); + md.Run(); + md.Dispose(); } } sd.Dispose(); } + private void ButtonHelpClicked(object sender, EventArgs args) { + Console.WriteLine("Watchlist:"); + foreach (var item in this.settings.watchlist) { + Console.WriteLine(item); + } + Console.WriteLine("---\nFilter results:"); + foreach (var item in this.filterQuery) { + Console.WriteLine(item); + } + Console.WriteLine("---\nListstore contents:"); + foreach (object[] item in this.items) { + Console.WriteLine(item[0]); + } + } + private void ButtonQuitClicked(object sender, EventArgs a) { var md = this.MsgBox("Are you sure you want to quit?"); @@ -846,6 +873,13 @@ namespace Buypeeb { private bool ItemFilter(ITreeModel model, TreeIter iter) { var item = (YahooAuctionsItem)model.GetValue(iter, 0); + if (item == null) { + return true; + } + if (item.price == 0) { + // the item has only just been added, so we can't compare it against the filters, since it's missing most of its data + return true; + } bool Filtered(string name) { return this.filterChecks[name].Active; diff --git a/ui/main.glade b/ui/main.glade index ae3234e..fa8f852 100644 --- a/ui/main.glade +++ b/ui/main.glade @@ -430,12 +430,12 @@ True - False False Help Help True gtk-help +