From 32ff00d8be0775c5fe1475d1a2c4360ff3a2d365 Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Fri, 4 Sep 2020 17:23:32 +1000 Subject: [PATCH] the selection view is half done now! --- Listing.cs | 15 +- MainWindow.cs | 94 +++++++- Settings.cs | 7 +- ui/main.glade | 634 ++++++++++++++++++++++++++------------------------ 4 files changed, 424 insertions(+), 326 deletions(-) diff --git a/Listing.cs b/Listing.cs index 31e0593..02635b2 100644 --- a/Listing.cs +++ b/Listing.cs @@ -11,6 +11,13 @@ namespace Buypeeb { return $"https://page.auctions.yahoo.co.jp/jp/auction/{this.id}"; } } + + public string buyee_url { + get { + return $"https://buyee.jp/item/yahoo/auction/{this.id}"; + } + } + public string id { get; set; } public string name { get; set; } public int price = 0; @@ -72,13 +79,13 @@ namespace Buypeeb { } } - public string PriceAUD() { - double aud = this.price / 75.0; + public string PriceAUD(bool win = false) { + double aud = win ? this.win_price / 75.0 : this.price / 75.0; return $"${aud:f2}"; } - public string PriceJPY() { - return $"¥{this.price}"; + public string PriceJPY(bool win = false) { + return win ? $"¥{this.win_price}" : $"¥{this.price}"; } } } diff --git a/MainWindow.cs b/MainWindow.cs index b731891..6bd0e14 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -24,6 +24,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; using System.Net; +using System.Diagnostics; using Gtk; namespace Buypeeb { @@ -44,9 +45,20 @@ namespace Buypeeb { private Settings settings; private TreeView itemTreeView; private Label statusLabel; + private Builder builder; + + // 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); + private Listing SelectedItem { + get { + this.itemTreeView.Selection.GetSelected(out TreeIter iter); + return (Listing)this.itemTreeView.Model.GetValue(iter, 0); + } + } + public MainWindow() : this(new Builder("main.glade")) { } private MainWindow(Builder builder) : base(builder.GetObject("wndMain").Handle) { @@ -78,6 +90,7 @@ namespace Buypeeb { this.SaveSettings(); this.Title = "Buypeeb"; + this.builder = builder; builder.Autoconnect(this); this.statusLabel = (Label)builder.GetObject("LabelStatus"); @@ -164,13 +177,18 @@ namespace Buypeeb { using (WebClient client = new WebClient()) { // TODO: download should have timeout - item.Update(client.DownloadString(item.url)); - // item.Update(File.ReadAllText("yahoo.html")); + // item.Update(client.DownloadString(item.url)); + item.Update(File.ReadAllText("yahoo.html")); } Gtk.Application.Invoke(delegate { var pathAndIter = this.GetRow(id); this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter); + 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; + } }); item.ready = true; @@ -188,11 +206,65 @@ namespace Buypeeb { } private void UpdateItems() { + var s = (Box)this.builder.GetObject("SelectionViewBox"); + s.Sensitive = false; + var t = Task.Factory.StartNew(() => { foreach (var item in this.settings.watchlist) { this.UpdateItem(item.Key); } }); + + } + + private void UpdateSelectionView() { + // get the currently selected item + 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; + var l = (Label)this.builder.GetObject("LabelSelectedName"); + l.Text = "buypeeb"; + return; + } + + s.Sensitive = item.ready; + infobox.Visible = true; + + var info = new Dictionary(); + info.Add("Name", item.name); + info.Add("YahooName", item.original_name); + 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("LastUpdated", "Last updated: heeeenlo"); + + foreach (var row in info) { + var l = (Label)this.builder.GetObject($"LabelSelected{row.Key}"); + l.Text = row.Value; + } + + } + private void OpenUrl(string url) { + // https://github.com/dotnet/runtime/issues/17938 + if (Environment.OSVersion.Platform == PlatformID.Win32NT) { + ProcessStartInfo psi = new ProcessStartInfo { + FileName = url, + UseShellExecute = true + }; + Process.Start(psi); + } + else { + // let's hope you have xdg-open installed + Process.Start("xdg-open", url); + } } // show a simple entry dialogue that allows the user to enter text and either cancel or submit it @@ -222,7 +294,7 @@ namespace Buypeeb { } } - // button handlers + // event handlers private void ButtonAddClicked(object sender, EventArgs a) { // Console.WriteLine("ButtonAddClicked"); @@ -236,7 +308,7 @@ namespace Buypeeb { Regex rx = new Regex(@"^http.+yahoo.+"); if (rx.IsMatch(url)) { Console.WriteLine("{0} will be added", url); - this.settings.Watch(url, name); + this.UpdateItem(this.settings.Watch(url, name).id); this.RenderList(); } else { @@ -270,16 +342,16 @@ namespace Buypeeb { } } - private void tveItemsSelectionChanged(object sender, EventArgs a) { - Console.WriteLine("tveItemsSelectionChanged"); + private void TreeViewItemsSelectionChanged(object sender, EventArgs a) { + this.UpdateSelectionView(); } private void ButtonViewBuyeeClicked(object sender, EventArgs a) { - Console.WriteLine("ButtonViewBuyeeClicked"); + this.OpenUrl(this.SelectedItem.buyee_url); } private void ButtonViewYahooClicked(object sender, EventArgs a) { - Console.WriteLine("ButtonViewYahooClicked"); + this.OpenUrl(this.SelectedItem.url); } private void ButtonSelectedRemoveClicked(object sender, EventArgs a) { @@ -290,6 +362,12 @@ namespace Buypeeb { Console.WriteLine("ButtonSelectedRenameClicked"); } + private void ButtonSelectedUpdateClicked(object sender, EventArgs args) { + var s = (Box)this.builder.GetObject("SelectionViewBox"); + s.Sensitive = false; + this.UpdateItem(this.SelectedItem.id); + } + // column renderers private void RenderColumnName(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) { diff --git a/Settings.cs b/Settings.cs index c816602..56cdeb7 100644 --- a/Settings.cs +++ b/Settings.cs @@ -28,14 +28,11 @@ namespace Buypeeb { } - public void Watch(string url, string name) { + public Listing Watch(string url, string name) { string id = BuypeebApp.IDFromURL(url); Console.WriteLine(id); this.watchlist[id] = new Listing(id, name); - - foreach (KeyValuePair entry in this.watchlist) { - Console.WriteLine("{0} - {1}", entry.Value.name, entry.Value.price); - } + return this.watchlist[id]; } } } diff --git a/ui/main.glade b/ui/main.glade index 8aa4071..22f4934 100644 --- a/ui/main.glade +++ b/ui/main.glade @@ -275,7 +275,7 @@ True - + @@ -335,14 +335,15 @@ - + + 200 True False 5 5 vertical - + True False precious peebus polytonal player @@ -376,245 +377,216 @@ - - True - False - start - 5 - - - True - False - start - Original name - - - 0 - 0 - - - - - True - False - start - Price (Yen) - - - 0 - 1 - - - - - True - False - start - Price (AUD) - - - 0 - 2 - - - - - True - False - start - Ending in - - - 0 - 3 - - - - - True - False - start - Bid count - - - 0 - 4 - - - - - True - False - end - something in japanese - end - - - 2 - 0 - - - - - True - False - end - ¥12345 - - - 2 - 1 - - - - - True - False - end - $123.45 - - - 2 - 2 - - - - - True - False - end - 1h 17m 23s - - - 2 - 3 - - - - - True - False - end - 5 - - - 2 - 4 - - - - - True - False - 10 - 10 - True - - - 1 - 1 - - - - - True - False - start - Buy it now? - - - 0 - 5 - - - - - True - False - start - Auto extension? - - - 0 - 6 - - - - - True - False - end - Yes - - - 2 - 5 - - - - - True - False - end - N/A - - - 2 - 6 - - - - - - - - - - - - - - - - - - - - - - - True - True - 2 - - - - - True - False - Last updated: 12:34:56 - center - True - - - False - True - 3 - - - - + True False vertical - 5 - - View on Buyee + True - True - True - + False + start + 5 + + + True + False + start + Original name + + + 0 + 0 + + + + + True + False + start + Price (Yen) + + + 0 + 1 + + + + + True + False + start + Price (AUD) + + + 0 + 2 + + + + + True + False + start + Ending in + + + 0 + 3 + + + + + True + False + start + Bid count + + + 0 + 4 + + + + + True + False + end + something in japanese + end + + + 2 + 0 + + + + + True + False + end + ¥12345 + + + 2 + 1 + + + + + True + False + end + $123.45 + + + 2 + 2 + + + + + True + False + end + 1h 17m 23s + + + 2 + 3 + + + + + True + False + end + 5 + + + 2 + 4 + + + + + True + False + 10 + 10 + True + + + 1 + 1 + + + + + True + False + start + Buy it now? + + + 0 + 5 + + + + + True + False + start + Auto extension? + + + 0 + 6 + + + + + True + False + end + Yes + + + 2 + 5 + + + + + True + False + end + N/A + + + 2 + 6 + + + + + + + + + + + + + + + + + + + + False @@ -623,121 +595,165 @@ - - View on Yahoo! Auctions - True - True - True - - - - False - True - 1 - - - - + True False - True - True - expand + vertical + 5 - + + View on Buyee True True True - Remove - - - - True - False - user-trash - - + - True + False True - end 0 - + + View on Yahoo! Auctions True True True - Rename - - - - True - False - gtk-edit - - + - True + False True 1 - + True - True - True - Update + False + True + True + expand - + True - False - view-refresh + True + True + Remove + + + + True + False + user-trash + + + + True + True + end + 0 + + + + + True + True + True + Rename + + + + True + False + gtk-edit + + + + + True + True + 1 + + + + + True + True + True + Update + + + + True + False + view-refresh + + + + + True + True + 1 + + + + + True + True + True + Favourite + + + True + False + emblem-favorite + + + + + True + True + 3 + - True + False True - 1 - - - - - True - True - True - Favourite - - - True - False - emblem-favorite - - - - - True - True - 3 + 2 False True + end + 1 + + + + + True + False + Last updated: 12:34:56 + center + True + + + False + True + end 2 - False + True True - 4 + 2