diff --git a/Listing.cs b/Listing.cs index 8c6d83a..efa3bb8 100644 --- a/Listing.cs +++ b/Listing.cs @@ -12,7 +12,7 @@ namespace Buypeeb { } } - public string buyee_url { + public string buyeeUrl { get { return $"https://buyee.jp/item/yahoo/auction/{this.id}"; } @@ -21,12 +21,12 @@ namespace Buypeeb { public string id { get; set; } public string name { get; set; } public int price = 0; - public int win_price; - public string original_name; + public int winPrice; + public string originalName; public bool favourite { get; set; } = false; // start_date, end_date public int bids; - public bool auto_extension; + public bool autoExtension; public bool ready; private bool success { get; set; } // TODO: custom setter that throws an exception if set to false or something idk @@ -59,13 +59,13 @@ namespace Buypeeb { } var j = j_full["items"]; - this.original_name = j["productName"]; + this.originalName = j["productName"]; this.success = int.TryParse(j["price"], out this.price); - this.success = int.TryParse(j["winPrice"], out this.win_price); + this.success = int.TryParse(j["winPrice"], out this.winPrice); this.success = int.TryParse(j["bids"], out this.bids); if (String.IsNullOrWhiteSpace(this.name)) { - this.name = this.original_name; + this.name = this.originalName; } // as far as i can tell, neither the `pageData` nor the `conf` variables in the html seem to store whether or not the auction uses automatic extension @@ -75,17 +75,17 @@ namespace Buypeeb { var autoExtensionCheck = new Regex(@"自動延長.+\n.+>(.+)<"); m = rx.Match(html); if (m.Groups[1].Value != null) { - this.auto_extension = (m.Groups[1].Value == "あり"); + this.autoExtension = (m.Groups[1].Value == "あり"); } } public string PriceAUD(bool win = false) { - double aud = win ? this.win_price / 75.0 : this.price / 75.0; + double aud = win ? this.winPrice / 75.0 : this.price / 75.0; return $"${aud:f2}"; } public string PriceJPY(bool win = false) { - return win ? $"¥{this.win_price}" : $"¥{this.price}"; + return win ? $"¥{this.winPrice}" : $"¥{this.price}"; } } } diff --git a/MainWindow.cs b/MainWindow.cs index f33e582..09bccff 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -50,10 +50,15 @@ namespace Buypeeb { // TODO: whenever we get something from the builder, cache it for later // that way we don't need to constantly do "builder.GetObject"s - static SemaphoreSlim tasklimit = new SemaphoreSlim(4); + static SemaphoreSlim taskLimit = new SemaphoreSlim(4); - private YahooAuctionsItem SelectedItem { + private YahooAuctionsItem selectedItem { get { + if (this.itemTreeView.Selection.CountSelectedRows() == 0) { + // avoids incurring the wrath of Gtk-CRITICAL ** + return null; + } + this.itemTreeView.Selection.GetSelected(out TreeIter iter); return (YahooAuctionsItem)this.itemTreeView.Model.GetValue(iter, 0); } @@ -116,10 +121,10 @@ namespace Buypeeb { this.UpdateItems(); - DeleteEvent += Window_Shutdown; + DeleteEvent += WindowShutdown; } - private void Window_Shutdown(object sender, DeleteEventArgs args) { + private void WindowShutdown(object sender, DeleteEventArgs args) { SaveSettings(); Application.Quit(); } @@ -184,7 +189,7 @@ namespace Buypeeb { Gtk.Application.Invoke(delegate { var pathAndIter = this.GetRow(id); this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter); - if (item == this.SelectedItem) { + if (item == this.selectedItem) { // if the user has this item selected and it just became ready, enable the selection box var s = (Box)this.builder.GetObject("SelectionViewBox"); s.Sensitive = true; @@ -199,10 +204,10 @@ namespace Buypeeb { // don't start a new task if there are more than [tasklimit] tasks currently running // this makes sure we don't make 1000 simultaneous requests to yahoo auctions if there are 1000 items on the watchlist this.settings.watchlist[id].ready = false; - tasklimit.Wait(); + taskLimit.Wait(); var t = Task.Factory.StartNew(() => { this.UpdateThread(id); - }).ContinueWith(task => { tasklimit.Release(); }); + }).ContinueWith(task => { taskLimit.Release(); }); } private void UpdateItems() { @@ -219,11 +224,10 @@ namespace Buypeeb { private void UpdateSelectionView() { // get the currently selected item - var item = this.SelectedItem; + var item = this.selectedItem; var s = (Box)this.builder.GetObject("SelectionViewBox"); var infobox = (Box)this.builder.GetObject("SelectionInfoBox"); - if (item == null) { s.Sensitive = false; infobox.Visible = false; @@ -237,13 +241,13 @@ namespace Buypeeb { var info = new Dictionary(); info.Add("Name", item.name); - info.Add("YahooName", item.original_name); + info.Add("YahooName", item.originalName); info.Add("Price", item.PriceJPY()); info.Add("PriceAUD", item.PriceAUD()); info.Add("Ending", "whenever"); info.Add("Bids", $"{item.bids}"); - info.Add("BuyItNow", item.win_price == 0 ? "No" : $"¥{item.PriceJPY(true)} (${item.PriceAUD(true)})"); - info.Add("AutoExtension", item.auto_extension ? "Yes" : "No"); + info.Add("BuyItNow", item.winPrice == 0 ? "No" : $"¥{item.PriceJPY(true)} (${item.PriceAUD(true)})"); + info.Add("AutoExtension", item.autoExtension ? "Yes" : "No"); info.Add("LastUpdated", "Last updated: heeeenlo"); foreach (var row in info) { @@ -375,15 +379,15 @@ namespace Buypeeb { } private void ButtonViewBuyeeClicked(object sender, EventArgs a) { - this.OpenUrl(this.SelectedItem.buyee_url); + this.OpenUrl(this.selectedItem.buyeeUrl); } private void ButtonViewYahooClicked(object sender, EventArgs a) { - this.OpenUrl(this.SelectedItem.url); + this.OpenUrl(this.selectedItem.url); } private void ButtonSelectedRemoveClicked(object sender, EventArgs a) { - var item = this.SelectedItem; + var item = this.selectedItem; var md = this.OkCancelDialogue($"Are you sure you want to remove the item \"{item.name}\"?"); // TODO: this looks bad being all on one line @@ -396,7 +400,7 @@ namespace Buypeeb { } private void ButtonSelectedRenameClicked(object sender, EventArgs a) { - var item = this.SelectedItem; + var item = this.selectedItem; (bool accepted, string response) = this.EntryDialogue("Rename item", $"Enter a new name for the item \"{item.name}\".", item.name); if (accepted) { item.name = response; @@ -407,7 +411,7 @@ namespace Buypeeb { private void ButtonSelectedUpdateClicked(object sender, EventArgs args) { var s = (Box)this.builder.GetObject("SelectionViewBox"); s.Sensitive = false; - this.UpdateItem(this.SelectedItem.id); + this.UpdateItem(this.selectedItem.id); } // column renderers