2020-08-31 14:02:41 +00:00
|
|
|
/*
|
|
|
|
buypeeb - a program to track yahoo jp auctions of peebus.
|
|
|
|
Copyright (C) 2020 lynnesbian
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-08-28 16:04:37 +00:00
|
|
|
using System;
|
2020-09-01 10:41:29 +00:00
|
|
|
using System.Collections.Generic;
|
2020-09-03 13:47:36 +00:00
|
|
|
using System.IO;
|
2020-09-01 09:58:35 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2020-09-03 13:47:36 +00:00
|
|
|
using System.Text.Json;
|
2020-09-03 05:23:23 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-09-03 16:08:31 +00:00
|
|
|
using System.Net;
|
2020-09-04 07:23:32 +00:00
|
|
|
using System.Diagnostics;
|
2020-08-28 16:04:37 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
namespace Buypeeb {
|
2020-09-03 05:23:23 +00:00
|
|
|
public struct ItemColumns {
|
2020-09-03 06:34:42 +00:00
|
|
|
public const int Name = 0;
|
|
|
|
public const int PriceYen = 1;
|
|
|
|
public const int PriceAUD = 2;
|
|
|
|
public const int Ending = 3;
|
|
|
|
public const int Id = 4;
|
2020-08-31 14:20:56 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 16:04:37 +00:00
|
|
|
class MainWindow : Window {
|
2020-08-31 14:20:56 +00:00
|
|
|
|
2020-09-03 13:47:36 +00:00
|
|
|
private string location;
|
2020-09-03 16:09:19 +00:00
|
|
|
// private Queue<string> statuses;
|
2020-09-03 13:47:36 +00:00
|
|
|
|
2020-09-02 03:21:32 +00:00
|
|
|
private ListStore items;
|
|
|
|
private Settings settings;
|
2020-09-03 06:02:56 +00:00
|
|
|
private TreeView itemTreeView;
|
2020-09-03 13:47:36 +00:00
|
|
|
private Label statusLabel;
|
2020-09-04 07:23:32 +00:00
|
|
|
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
|
2020-09-04 10:48:47 +00:00
|
|
|
// when that is done, you can use the cache array to replace everything from here...
|
|
|
|
|
|
|
|
private Box selectionViewBox;
|
|
|
|
private Label endingLabel;
|
|
|
|
|
|
|
|
// ...to here.
|
2020-08-31 14:20:56 +00:00
|
|
|
|
2020-09-04 09:17:59 +00:00
|
|
|
static SemaphoreSlim taskLimit = new SemaphoreSlim(4);
|
2020-09-03 05:23:23 +00:00
|
|
|
|
2020-09-04 09:17:59 +00:00
|
|
|
private YahooAuctionsItem selectedItem {
|
2020-09-04 07:23:32 +00:00
|
|
|
get {
|
2020-09-04 09:17:59 +00:00
|
|
|
if (this.itemTreeView.Selection.CountSelectedRows() == 0) {
|
|
|
|
// avoids incurring the wrath of Gtk-CRITICAL **
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-04 07:23:32 +00:00
|
|
|
this.itemTreeView.Selection.GetSelected(out TreeIter iter);
|
2020-09-04 09:13:16 +00:00
|
|
|
return (YahooAuctionsItem)this.itemTreeView.Model.GetValue(iter, 0);
|
2020-09-04 07:23:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 09:58:35 +00:00
|
|
|
public MainWindow() : this(new Builder("main.glade")) { }
|
2020-08-28 16:04:37 +00:00
|
|
|
|
|
|
|
private MainWindow(Builder builder) : base(builder.GetObject("wndMain").Handle) {
|
2020-09-03 13:47:36 +00:00
|
|
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
|
|
|
|
// C:\Users\Beebus\AppData\Roaming\Lynnear Software\buypeeb
|
|
|
|
this.location = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%APPDATA%"), "Lynnear Software", "buypeeb");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// ~/.config/Lynnear Software/buypeeb
|
|
|
|
this.location = System.IO.Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".config", "Lynnear Software", "buypeeb");
|
|
|
|
}
|
|
|
|
|
|
|
|
string userdata = System.IO.Path.Combine(location, "userdata.json");
|
|
|
|
if (File.Exists(userdata)) {
|
|
|
|
try {
|
|
|
|
string j = File.ReadAllText(userdata);
|
|
|
|
this.settings = JsonSerializer.Deserialize<Settings>(j);
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
// ???
|
|
|
|
Console.WriteLine("oops");
|
|
|
|
Application.Quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.settings = new Settings();
|
|
|
|
}
|
|
|
|
this.SaveSettings();
|
2020-08-31 14:20:56 +00:00
|
|
|
this.Title = "Buypeeb";
|
2020-09-03 05:23:23 +00:00
|
|
|
|
2020-09-04 07:23:32 +00:00
|
|
|
this.builder = builder;
|
2020-08-28 16:04:37 +00:00
|
|
|
builder.Autoconnect(this);
|
2020-09-03 06:02:56 +00:00
|
|
|
|
2020-09-03 13:47:36 +00:00
|
|
|
this.statusLabel = (Label)builder.GetObject("LabelStatus");
|
2020-09-04 10:48:47 +00:00
|
|
|
this.selectionViewBox = (Box)builder.GetObject("SelectionViewBox");
|
|
|
|
this.endingLabel = (Label)builder.GetObject("LabelSelectedEnding");
|
2020-09-03 13:47:36 +00:00
|
|
|
|
2020-09-03 06:02:56 +00:00
|
|
|
// bind treeview columns to watchlist instead of needing to manually sync its liststore
|
|
|
|
this.itemTreeView = (TreeView)builder.GetObject("TreeViewItems");
|
2020-09-04 09:13:16 +00:00
|
|
|
this.items = new ListStore(typeof(YahooAuctionsItem));
|
2020-09-02 03:21:32 +00:00
|
|
|
this.RenderList();
|
2020-09-03 05:23:23 +00:00
|
|
|
|
2020-09-03 06:02:56 +00:00
|
|
|
this.itemTreeView.Model = this.items;
|
2020-09-03 16:08:31 +00:00
|
|
|
TreeCellDataFunc[] funcs = {
|
|
|
|
new TreeCellDataFunc(this.RenderColumnName),
|
|
|
|
new TreeCellDataFunc(this.RenderColumnPriceYen),
|
|
|
|
new TreeCellDataFunc(this.RenderColumnPriceAUD),
|
|
|
|
new TreeCellDataFunc(this.RenderColumnEnding)
|
|
|
|
};
|
|
|
|
|
2020-09-03 06:34:42 +00:00
|
|
|
for (int i = 0; i < this.itemTreeView.Columns.Length; i++) {
|
|
|
|
var c = this.itemTreeView.Columns[i];
|
|
|
|
|
2020-09-03 16:08:31 +00:00
|
|
|
c.SetCellDataFunc(c.Cells[0], funcs[i]);
|
2020-09-03 06:34:42 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 16:08:31 +00:00
|
|
|
this.UpdateItems();
|
2020-09-04 10:48:47 +00:00
|
|
|
GLib.Timeout.Add(1000, new GLib.TimeoutHandler(UpdateSelectionEndTime));
|
2020-09-03 06:02:56 +00:00
|
|
|
|
2020-09-04 09:17:59 +00:00
|
|
|
DeleteEvent += WindowShutdown;
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 09:17:59 +00:00
|
|
|
private void WindowShutdown(object sender, DeleteEventArgs args) {
|
2020-09-03 14:38:41 +00:00
|
|
|
SaveSettings();
|
2020-08-28 16:04:37 +00:00
|
|
|
Application.Quit();
|
|
|
|
}
|
|
|
|
|
2020-09-01 10:41:29 +00:00
|
|
|
// general behaviour
|
2020-08-28 16:58:14 +00:00
|
|
|
|
2020-09-03 13:47:36 +00:00
|
|
|
private void SetStatus(string status) {
|
|
|
|
this.statusLabel.Text = status ?? "Buypeeb";
|
|
|
|
}
|
|
|
|
|
2020-09-03 16:09:19 +00:00
|
|
|
private (TreePath path, TreeIter iter) GetRow(string id) {
|
|
|
|
// TODO: surely there's a better way to do this
|
|
|
|
TreeIter iter;
|
|
|
|
this.itemTreeView.Model.GetIterFirst(out iter);
|
|
|
|
|
|
|
|
for (int i = 0; i < this.itemTreeView.Model.IterNChildren(); i++) {
|
2020-09-04 09:13:16 +00:00
|
|
|
var x = (YahooAuctionsItem)this.itemTreeView.Model.GetValue(iter, 0);
|
2020-09-03 16:09:19 +00:00
|
|
|
if (x.id == id) {
|
|
|
|
return (this.itemTreeView.Model.GetPath(iter), iter);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.itemTreeView.Model.IterNext(ref iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLine($"Couldn't find {id}!");
|
|
|
|
return (null, iter);
|
|
|
|
}
|
|
|
|
|
2020-09-03 13:47:36 +00:00
|
|
|
private void SaveSettings() {
|
|
|
|
string j = JsonSerializer.Serialize(this.settings);
|
2020-09-03 14:17:28 +00:00
|
|
|
string p = System.IO.Path.Combine(this.location, "userdata.json");
|
2020-09-03 13:47:36 +00:00
|
|
|
Console.WriteLine(j);
|
2020-09-03 14:19:13 +00:00
|
|
|
if (!Directory.Exists(this.location)) {
|
|
|
|
Directory.CreateDirectory(this.location);
|
|
|
|
}
|
2020-09-03 14:17:28 +00:00
|
|
|
if (!File.Exists(p)) {
|
|
|
|
File.CreateText(p);
|
|
|
|
}
|
2020-09-03 13:47:36 +00:00
|
|
|
File.WriteAllText(System.IO.Path.Combine(this.location, "userdata.json"), j);
|
|
|
|
}
|
|
|
|
|
2020-09-03 05:23:23 +00:00
|
|
|
private void UpdateThread(string id) {
|
|
|
|
var item = this.settings.watchlist[id];
|
|
|
|
Console.WriteLine($"Updating {id}...");
|
2020-09-03 13:47:36 +00:00
|
|
|
// set item.ready to false to show that it's still being updated
|
|
|
|
// this changes a few behaviours, such as displaying the price as "..." instead of whatever's currently stored
|
2020-09-03 05:23:23 +00:00
|
|
|
item.ready = false;
|
2020-09-03 16:09:19 +00:00
|
|
|
|
2020-09-03 05:23:23 +00:00
|
|
|
Gtk.Application.Invoke(delegate {
|
2020-09-03 16:09:19 +00:00
|
|
|
// TODO: find a way to not have to do this. i think we need to avoid actually modifying the items outside of the main thread :/
|
|
|
|
var pathAndIter = this.GetRow(id);
|
|
|
|
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
|
2020-09-03 05:23:23 +00:00
|
|
|
});
|
2020-09-03 16:09:19 +00:00
|
|
|
|
|
|
|
using (WebClient client = new WebClient()) {
|
|
|
|
// TODO: download should have timeout
|
2020-09-04 10:48:47 +00:00
|
|
|
item.Update(client.DownloadString(item.url));
|
|
|
|
// item.Update(File.ReadAllText("yahoo.html"));
|
2020-09-03 16:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Gtk.Application.Invoke(delegate {
|
|
|
|
var pathAndIter = this.GetRow(id);
|
|
|
|
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
|
2020-09-04 09:17:59 +00:00
|
|
|
if (item == this.selectedItem) {
|
2020-09-04 07:23:32 +00:00
|
|
|
// if the user has this item selected and it just became ready, enable the selection box
|
2020-09-04 10:48:47 +00:00
|
|
|
this.selectionViewBox.Sensitive = true;
|
2020-09-04 07:23:32 +00:00
|
|
|
}
|
2020-09-03 16:09:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
item.ready = true;
|
|
|
|
Console.WriteLine($"{id} updated.");
|
2020-09-03 05:23:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 10:16:42 +00:00
|
|
|
private void UpdateItem(string id, bool force = false) {
|
2020-09-03 13:47:36 +00:00
|
|
|
// 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
|
2020-09-04 10:16:42 +00:00
|
|
|
if (this.settings.watchlist[id].updatedRecently && !force) {
|
|
|
|
// the item has been updated recently, and force is not true
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-04 09:17:59 +00:00
|
|
|
taskLimit.Wait();
|
2020-09-03 05:23:23 +00:00
|
|
|
var t = Task.Factory.StartNew(() => {
|
|
|
|
this.UpdateThread(id);
|
2020-09-04 09:17:59 +00:00
|
|
|
}).ContinueWith(task => { taskLimit.Release(); });
|
2020-09-03 05:23:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateItems() {
|
2020-09-04 10:48:47 +00:00
|
|
|
this.selectionViewBox.Sensitive = false;
|
2020-09-04 07:23:32 +00:00
|
|
|
|
2020-09-03 05:23:23 +00:00
|
|
|
var t = Task.Factory.StartNew(() => {
|
|
|
|
foreach (var item in this.settings.watchlist) {
|
|
|
|
this.UpdateItem(item.Key);
|
|
|
|
}
|
|
|
|
});
|
2020-09-04 07:23:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateSelectionView() {
|
|
|
|
// get the currently selected item
|
2020-09-04 09:17:59 +00:00
|
|
|
var item = this.selectedItem;
|
2020-09-04 07:23:32 +00:00
|
|
|
var infobox = (Box)this.builder.GetObject("SelectionInfoBox");
|
|
|
|
|
|
|
|
if (item == null) {
|
2020-09-04 10:48:47 +00:00
|
|
|
this.selectionViewBox.Sensitive = false;
|
2020-09-04 07:23:32 +00:00
|
|
|
infobox.Visible = false;
|
|
|
|
var l = (Label)this.builder.GetObject("LabelSelectedName");
|
|
|
|
l.Text = "buypeeb";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-04 10:48:47 +00:00
|
|
|
this.selectionViewBox.Sensitive = item.ready;
|
2020-09-04 07:23:32 +00:00
|
|
|
infobox.Visible = true;
|
|
|
|
|
|
|
|
var info = new Dictionary<string, string>();
|
|
|
|
info.Add("Name", item.name);
|
2020-09-04 09:17:59 +00:00
|
|
|
info.Add("YahooName", item.originalName);
|
2020-09-04 07:23:32 +00:00
|
|
|
info.Add("Price", item.PriceJPY());
|
|
|
|
info.Add("PriceAUD", item.PriceAUD());
|
2020-09-04 10:48:47 +00:00
|
|
|
info.Add("Ending", "...");
|
2020-09-04 07:23:32 +00:00
|
|
|
info.Add("Bids", $"{item.bids}");
|
2020-09-04 09:17:59 +00:00
|
|
|
info.Add("BuyItNow", item.winPrice == 0 ? "No" : $"¥{item.PriceJPY(true)} (${item.PriceAUD(true)})");
|
|
|
|
info.Add("AutoExtension", item.autoExtension ? "Yes" : "No");
|
2020-09-04 07:23:32 +00:00
|
|
|
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);
|
|
|
|
}
|
2020-09-03 05:23:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 09:10:55 +00:00
|
|
|
private MessageDialog OkCancelDialogue(string message) {
|
|
|
|
var md = new MessageDialog(
|
|
|
|
parent_window: this,
|
|
|
|
flags: DialogFlags.DestroyWithParent | DialogFlags.Modal,
|
|
|
|
type: MessageType.Question,
|
|
|
|
bt: ButtonsType.OkCancel,
|
|
|
|
format: message
|
|
|
|
);
|
|
|
|
md.KeepAbove = true;
|
|
|
|
md.Resizable = false;
|
|
|
|
md.FocusOnMap = true;
|
|
|
|
md.Title = "buypeeb";
|
|
|
|
|
|
|
|
return md;
|
|
|
|
}
|
|
|
|
|
2020-09-03 13:47:36 +00:00
|
|
|
// show a simple entry dialogue that allows the user to enter text and either cancel or submit it
|
2020-09-04 08:06:45 +00:00
|
|
|
private (Boolean accepted, string response) EntryDialogue(string title = "Buypeeb", string message = "Hi there!", string prefill = null) {
|
|
|
|
Dialog ed = new Dialog(title, null, DialogFlags.DestroyWithParent | DialogFlags.Modal, "Cancel", ResponseType.Cancel, "OK", ResponseType.Ok);
|
2020-08-31 14:34:31 +00:00
|
|
|
ed.DefaultResponse = ResponseType.Ok;
|
2020-09-04 08:06:45 +00:00
|
|
|
ed.KeepAbove = true;
|
2020-08-28 16:58:14 +00:00
|
|
|
|
|
|
|
Label edLabel = new Label(message);
|
|
|
|
Entry edEntry = new Entry();
|
2020-09-04 08:06:45 +00:00
|
|
|
if (!String.IsNullOrWhiteSpace(prefill)) {
|
|
|
|
edEntry.Text = prefill;
|
|
|
|
}
|
2020-08-31 14:34:31 +00:00
|
|
|
edEntry.ActivatesDefault = true;
|
2020-08-28 16:58:14 +00:00
|
|
|
|
|
|
|
ed.ContentArea.PackStart(edLabel, true, true, 2);
|
|
|
|
edLabel.Show();
|
|
|
|
ed.ContentArea.PackStart(edEntry, true, true, 10);
|
|
|
|
edEntry.Show();
|
|
|
|
|
2020-09-04 08:06:45 +00:00
|
|
|
ed.ContentArea.MarginBottom = 5;
|
|
|
|
ed.ContentArea.MarginTop = 5;
|
|
|
|
ed.ContentArea.MarginStart = 5;
|
|
|
|
ed.ContentArea.MarginEnd = 5;
|
2020-09-04 09:20:14 +00:00
|
|
|
ed.MarginBottom = 5;
|
2020-09-04 08:06:45 +00:00
|
|
|
|
2020-08-28 16:58:14 +00:00
|
|
|
ResponseType accepted = (ResponseType)ed.Run();
|
|
|
|
string response = edEntry.Text;
|
2020-09-01 07:12:17 +00:00
|
|
|
ed.Dispose();
|
2020-08-28 16:58:14 +00:00
|
|
|
return (accepted == ResponseType.Ok, response);
|
|
|
|
}
|
|
|
|
|
2020-09-02 03:21:32 +00:00
|
|
|
private void RenderList() {
|
|
|
|
this.items.Clear();
|
2020-09-03 06:02:56 +00:00
|
|
|
foreach (var item in this.settings.watchlist) {
|
|
|
|
items.AppendValues(item.Value);
|
2020-09-02 03:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 07:23:32 +00:00
|
|
|
// event handlers
|
2020-08-28 16:04:37 +00:00
|
|
|
|
|
|
|
private void ButtonAddClicked(object sender, EventArgs a) {
|
2020-09-01 09:58:35 +00:00
|
|
|
// Console.WriteLine("ButtonAddClicked");
|
|
|
|
AddItemDialogue aid = new AddItemDialogue();
|
2020-09-04 08:06:45 +00:00
|
|
|
aid.Title = "Buypeeb";
|
2020-09-01 09:58:35 +00:00
|
|
|
ResponseType accepted = (ResponseType)aid.Run();
|
|
|
|
string url = aid.GetURL();
|
|
|
|
string name = aid.GetName();
|
|
|
|
aid.Dispose();
|
|
|
|
|
|
|
|
// vry simpl url validation for simpol creachers
|
|
|
|
Regex rx = new Regex(@"^http.+yahoo.+");
|
|
|
|
if (rx.IsMatch(url)) {
|
|
|
|
Console.WriteLine("{0} will be added", url);
|
2020-09-04 07:23:32 +00:00
|
|
|
this.UpdateItem(this.settings.Watch(url, name).id);
|
2020-09-02 03:21:32 +00:00
|
|
|
this.RenderList();
|
2020-09-01 09:58:35 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Console.WriteLine("{0} is an invalid url", url);
|
|
|
|
}
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonUpdateAllClicked(object sender, EventArgs a) {
|
2020-09-03 05:23:23 +00:00
|
|
|
this.UpdateItems();
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonClearEndedClicked(object sender, EventArgs a) {
|
|
|
|
Console.WriteLine("ButtonClearEndedClicked");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonClearAllClicked(object sender, EventArgs a) {
|
|
|
|
Console.WriteLine("ButtonClearAllClicked");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonSaveClicked(object sender, EventArgs a) {
|
2020-09-03 14:38:41 +00:00
|
|
|
this.SaveSettings();
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonQuitClicked(object sender, EventArgs a) {
|
2020-09-04 09:10:55 +00:00
|
|
|
var md = this.OkCancelDialogue("Are you sure you want to quit?");
|
2020-09-04 08:06:45 +00:00
|
|
|
|
2020-08-28 16:04:37 +00:00
|
|
|
ResponseType response = (ResponseType)md.Run();
|
2020-09-01 07:12:17 +00:00
|
|
|
md.Dispose();
|
2020-08-28 16:04:37 +00:00
|
|
|
if (response == ResponseType.Ok) {
|
2020-09-03 14:38:41 +00:00
|
|
|
this.SaveSettings();
|
2020-08-28 16:04:37 +00:00
|
|
|
Application.Quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 07:23:32 +00:00
|
|
|
private void TreeViewItemsSelectionChanged(object sender, EventArgs a) {
|
|
|
|
this.UpdateSelectionView();
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonViewBuyeeClicked(object sender, EventArgs a) {
|
2020-09-04 09:17:59 +00:00
|
|
|
this.OpenUrl(this.selectedItem.buyeeUrl);
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonViewYahooClicked(object sender, EventArgs a) {
|
2020-09-04 09:17:59 +00:00
|
|
|
this.OpenUrl(this.selectedItem.url);
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonSelectedRemoveClicked(object sender, EventArgs a) {
|
2020-09-04 09:17:59 +00:00
|
|
|
var item = this.selectedItem;
|
2020-09-04 08:06:45 +00:00
|
|
|
|
2020-09-04 09:10:55 +00:00
|
|
|
var md = this.OkCancelDialogue($"Are you sure you want to remove the item \"{item.name}\"?"); // TODO: this looks bad being all on one line
|
2020-09-04 08:06:45 +00:00
|
|
|
|
|
|
|
ResponseType response = (ResponseType)md.Run();
|
|
|
|
md.Dispose();
|
|
|
|
if (response == ResponseType.Ok) {
|
|
|
|
this.settings.watchlist.Remove(item.id);
|
|
|
|
this.RenderList();
|
|
|
|
}
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonSelectedRenameClicked(object sender, EventArgs a) {
|
2020-09-04 09:17:59 +00:00
|
|
|
var item = this.selectedItem;
|
2020-09-04 08:06:45 +00:00
|
|
|
(bool accepted, string response) = this.EntryDialogue("Rename item", $"Enter a new name for the item \"{item.name}\".", item.name);
|
|
|
|
if (accepted) {
|
|
|
|
item.name = response;
|
|
|
|
this.UpdateSelectionView();
|
|
|
|
}
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 07:23:32 +00:00
|
|
|
private void ButtonSelectedUpdateClicked(object sender, EventArgs args) {
|
2020-09-04 10:48:47 +00:00
|
|
|
this.selectionViewBox.Sensitive = false;
|
2020-09-04 09:17:59 +00:00
|
|
|
this.UpdateItem(this.selectedItem.id);
|
2020-09-04 07:23:32 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 06:02:56 +00:00
|
|
|
// column renderers
|
|
|
|
|
|
|
|
private void RenderColumnName(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
2020-09-04 09:13:16 +00:00
|
|
|
YahooAuctionsItem item = (YahooAuctionsItem)model.GetValue(iter, 0);
|
2020-09-03 06:02:56 +00:00
|
|
|
(cell as Gtk.CellRendererText).Text = item.name ?? "Loading...";
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RenderColumnPriceYen(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
2020-09-04 09:13:16 +00:00
|
|
|
YahooAuctionsItem item = (YahooAuctionsItem)model.GetValue(iter, 0);
|
2020-09-03 16:09:19 +00:00
|
|
|
(cell as Gtk.CellRendererText).Text = item.ready ? item.PriceJPY() : "...";
|
2020-09-03 06:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void RenderColumnPriceAUD(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
2020-09-04 09:13:16 +00:00
|
|
|
YahooAuctionsItem item = (YahooAuctionsItem)model.GetValue(iter, 0);
|
2020-09-03 16:09:19 +00:00
|
|
|
(cell as Gtk.CellRendererText).Text = item.ready ? item.PriceAUD() : "...";
|
2020-09-03 06:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void RenderColumnEnding(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
2020-09-04 09:13:16 +00:00
|
|
|
YahooAuctionsItem item = (YahooAuctionsItem)model.GetValue(iter, 0);
|
2020-09-04 10:16:42 +00:00
|
|
|
string ending = "";
|
|
|
|
if (item.ready) {
|
|
|
|
var now = DateTime.Now;
|
|
|
|
var end = item.endDate.ToLocalTime();
|
|
|
|
// TODO: should we show the year if the auction ends next year? 0uo
|
|
|
|
if (end.DayOfYear != now.DayOfYear) {
|
|
|
|
// the auction isn't ending today, so we should show the day it's ending on for clarity
|
|
|
|
ending += end.ToString("MMM d ");
|
|
|
|
}
|
|
|
|
ending += end.ToString("HH:mm");
|
|
|
|
if (this.settings.displaySecondsInList) {
|
|
|
|
// add the seconds on to the end
|
|
|
|
ending += end.ToString(":ss");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(cell as Gtk.CellRendererText).Text = item.ready ? ending : "...";
|
2020-09-03 06:02:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 10:48:47 +00:00
|
|
|
// timers
|
|
|
|
|
|
|
|
private bool UpdateSelectionEndTime() {
|
|
|
|
if (!this.selectionViewBox.IsSensitive) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var item = this.selectedItem;
|
|
|
|
if (!item.ready) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
string ending = "";
|
|
|
|
if (item.available) {
|
|
|
|
var now = DateTime.Now;
|
|
|
|
var end = item.endDate.ToLocalTime();
|
|
|
|
var span = end.Subtract(now);
|
|
|
|
|
|
|
|
if (span.Days > 0) {
|
|
|
|
ending += span.ToString("dd' days, '"); // will format twelve days as "12 days, "
|
|
|
|
}
|
|
|
|
// timespan objects don't contain definitions for the time or date separators, so the colons need to be escaped
|
|
|
|
// `HH` doesn't exist, but `hh` behaves identically
|
|
|
|
// see https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings
|
|
|
|
ending += span.ToString(@"hh\:mm\:ss");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ending = "Auction has ended";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.endingLabel.Text = ending;
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-28 16:04:37 +00:00
|
|
|
}
|
|
|
|
}
|