Compare commits
5 commits
ed759d8945
...
2da88f92f6
Author | SHA1 | Date | |
---|---|---|---|
2da88f92f6 | |||
6ffc144936 | |||
02e81b12b0 | |||
d9a4349a0a | |||
4dd48e75b1 |
5 changed files with 279 additions and 59 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ out/
|
|||
yahoo.html
|
||||
.vs/
|
||||
/buypeeb.sln
|
||||
\#*.glade#
|
||||
|
|
105
MainWindow.cs
105
MainWindow.cs
|
@ -108,6 +108,11 @@ namespace Buypeeb {
|
|||
this.builder = builder;
|
||||
builder.Autoconnect(this);
|
||||
|
||||
var menuButtonFilter = (MenuButton)builder.GetObject("MenuButtonFilter");
|
||||
var menuButtonSort = (MenuButton)builder.GetObject("MenuButtonSort");
|
||||
menuButtonFilter.Child = (Image)builder.GetObject("ImageFilter");
|
||||
menuButtonSort.Child = (Image)builder.GetObject("ImageSort");
|
||||
|
||||
this.selectionViewBox = (Box)builder.GetObject("SelectionViewBox");
|
||||
this.endingLabel = (Label)builder.GetObject("LabelSelectedEnding");
|
||||
this.searchEntry = (SearchEntry)builder.GetObject("FilterSearchEntry");
|
||||
|
@ -335,6 +340,13 @@ namespace Buypeeb {
|
|||
var l = (Label)this.builder.GetObject($"LabelSelected{row.Key}");
|
||||
l.Text = row.Value;
|
||||
}
|
||||
this.UpdateSelectionEndTime();
|
||||
|
||||
var noteBuffer = (TextBuffer)this.builder.GetObject("TextBufferSelectedNotes");
|
||||
noteBuffer.Clear();
|
||||
if (!String.IsNullOrWhiteSpace(item.notes)) {
|
||||
noteBuffer.Text = item.notes;
|
||||
}
|
||||
|
||||
var f = (ToggleButton)this.builder.GetObject("ButtonSelectedFavourite");
|
||||
f.Active = item.favourite;
|
||||
|
@ -407,11 +419,56 @@ namespace Buypeeb {
|
|||
return (accepted == ResponseType.Ok, response);
|
||||
}
|
||||
|
||||
private string GetSortType() {
|
||||
foreach (var name in new List<string> { "NameDescending", "NameAscending", "PriceDescending", "PriceAscending", "EndingDescending", "EndingAscending" }) {
|
||||
var radio = (RadioMenuItem)this.builder.GetObject($"Sort{name}");
|
||||
if (radio.Active) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
return "NameAscending";
|
||||
}
|
||||
|
||||
private void RenderList() {
|
||||
this.items.Clear();
|
||||
foreach (var item in this.settings.watchlist.Values) {
|
||||
items.AppendValues(item);
|
||||
var values = this.settings.watchlist.Values;
|
||||
IOrderedEnumerable<YahooAuctionsItem> sorted;
|
||||
var type = this.GetSortType();
|
||||
if (type == "NameDescending") {
|
||||
sorted = values.OrderByDescending(item => item.name);
|
||||
}
|
||||
else if (type == "NameAscending") {
|
||||
sorted = values.OrderBy(item => item.name);
|
||||
}
|
||||
else if (type == "PriceDescending") {
|
||||
sorted = values.OrderByDescending(item => item.price);
|
||||
}
|
||||
else if (type == "PriceAscending") {
|
||||
sorted = values.OrderBy(item => item.price);
|
||||
}
|
||||
else if (type == "EndingDescending") {
|
||||
sorted = values.OrderByDescending(item => item.endDate);
|
||||
}
|
||||
else {
|
||||
sorted = values.OrderBy(item => item.endDate);
|
||||
}
|
||||
|
||||
if (settings.displayFavouritesAtTopOfList) {
|
||||
foreach (var item in sorted.Where(item => item.favourite)) {
|
||||
items.AppendValues(item);
|
||||
}
|
||||
|
||||
foreach (var item in sorted.Where(item => !item.favourite)) {
|
||||
items.AppendValues(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach (var item in sorted) {
|
||||
items.AppendValues(item);
|
||||
}
|
||||
}
|
||||
|
||||
var m = (TreeModelFilter)this.itemTreeView.Model;
|
||||
m.Refilter();
|
||||
}
|
||||
|
@ -573,6 +630,7 @@ namespace Buypeeb {
|
|||
try {
|
||||
using (var writer = new StreamWriter(sd.Filename))
|
||||
using (var csv = new CsvWriter(writer, System.Globalization.CultureInfo.InvariantCulture)) {
|
||||
|
||||
csv.WriteRecords(this.settings.watchlist);
|
||||
}
|
||||
}
|
||||
|
@ -643,11 +701,46 @@ namespace Buypeeb {
|
|||
ToggleButton s = (ToggleButton)sender;
|
||||
this.selectedItem.favourite = s.Active;
|
||||
|
||||
// i don't know why this is necessary
|
||||
var pathAndIter = this.GetRow(this.selectedItem.id);
|
||||
if (pathAndIter.path != null) {
|
||||
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
|
||||
if (this.settings.displayFavouritesAtTopOfList) {
|
||||
var id = this.selectedItem.id;
|
||||
// re-render the list, to ensure the favourites get pushed to the top
|
||||
this.RenderList();
|
||||
// attempt to reselect the item we were just looking at
|
||||
var pathAndIter = this.GetRow(id);
|
||||
this.itemTreeView.Selection.SelectPath(pathAndIter.path);
|
||||
}
|
||||
else {
|
||||
// i don't know why this is necessary
|
||||
var pathAndIter = this.GetRow(this.selectedItem.id);
|
||||
if (pathAndIter.path != null) {
|
||||
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonSelectedNotesClearClicked(object sender, EventArgs args) {
|
||||
var item = this.selectedItem;
|
||||
var md = this.MsgBox($"Are you sure you want to clear the notes for \"{item.name}\"?");
|
||||
if (md.Run() == (int)ResponseType.Ok) {
|
||||
var noteBuffer = (TextBuffer)this.builder.GetObject("TextBufferSelectedNotes");
|
||||
noteBuffer.Clear();
|
||||
this.selectedItem.notes = null;
|
||||
}
|
||||
md.Dispose();
|
||||
}
|
||||
|
||||
private void TextViewSelectedNotesFocusOut(object sender, FocusOutEventArgs args) {
|
||||
// the "save" button does nothing, however, when you click the save button, you transfer focus to it, firing this event!
|
||||
// how very sneaky
|
||||
var noteBuffer = (TextBuffer)this.builder.GetObject("TextBufferSelectedNotes");
|
||||
if (this.selectedItem != null) {
|
||||
this.selectedItem.notes = String.IsNullOrWhiteSpace(noteBuffer.Text) ? null : noteBuffer.Text;
|
||||
}
|
||||
}
|
||||
|
||||
private void SortMenuClosed(object sender, EventArgs args) {
|
||||
this.RenderList();
|
||||
}
|
||||
|
||||
// timers
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Buypeeb {
|
|||
public int updateIntervalCritical { get; set; } = 60;
|
||||
public int favouriteUpdateIntervalCritical { get; set; } = 30;
|
||||
public bool displaySecondsInList { get; set; } = true;
|
||||
public bool displayFavouritesAtTopOfList { get; set; } = true;
|
||||
|
||||
public Dictionary<string, YahooAuctionsItem> watchlist {
|
||||
get; set;
|
||||
|
|
|
@ -3,15 +3,19 @@ using System.Globalization;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using CsvHelper.Configuration.Attributes;
|
||||
|
||||
namespace Buypeeb {
|
||||
class YahooAuctionsItem {
|
||||
[JsonIgnore]
|
||||
public string url {
|
||||
get {
|
||||
return $"https://page.auctions.yahoo.co.jp/jp/auction/{this.id}";
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public string buyeeUrl {
|
||||
get {
|
||||
return $"https://buyee.jp/item/yahoo/auction/{this.id}";
|
||||
|
@ -23,21 +27,24 @@ namespace Buypeeb {
|
|||
// the id *must* be saved!
|
||||
// i'm also saving the original name to make it easier to tell what the items are in the userdata.json
|
||||
// there's not really a need for it i guess but it's my program and i can do what i want
|
||||
// anything with the attribute [Ignore] won't be put in the CSV, and things with [JsonIgnore] won't be put in userdata.json
|
||||
[Ignore]
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
private int price = 0;
|
||||
public int price = 0;
|
||||
public int winPrice;
|
||||
public string originalName { get; set; }
|
||||
public string notes { get; set; }
|
||||
public bool favourite { get; set; } = false;
|
||||
public DateTime startDate;
|
||||
public DateTime endDate;
|
||||
public DateTime endDate { get; set; }
|
||||
public DateTime lastUpdated;
|
||||
public int bids;
|
||||
public bool autoExtension;
|
||||
public bool ready;
|
||||
public bool available;
|
||||
|
||||
[Ignore, JsonIgnore]
|
||||
public bool updatedRecently {
|
||||
get {
|
||||
var later = this.lastUpdated.AddSeconds(15);
|
||||
|
@ -45,15 +52,21 @@ namespace Buypeeb {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: don't serialise this stuff
|
||||
[JsonIgnore]
|
||||
public string priceJPY { get { return $"¥{this.price}"; } }
|
||||
[JsonIgnore]
|
||||
public string winPriceJPY { get { return $"¥{this.winPrice}"; } }
|
||||
[Ignore, JsonIgnore]
|
||||
public string priceAUD { get { return $"${(this.price / 75.0):f2}"; } }
|
||||
[Ignore, JsonIgnore]
|
||||
public string winPriceAUD { get { return $"${(this.winPrice / 75.0):f2}"; } }
|
||||
[Ignore, JsonIgnore]
|
||||
public bool endingToday { get { return this.endDate.DayOfYear == DateTime.UtcNow.DayOfYear; } }
|
||||
[Ignore, JsonIgnore]
|
||||
public bool hasWinPrice { get { return this.winPrice != 0; } }
|
||||
private bool success { get; set; } // TODO: custom setter that throws an exception if set to false or something idk
|
||||
[Ignore, JsonIgnore]
|
||||
public bool endingSoon { get { return DateTime.Compare(DateTime.UtcNow.AddMinutes(10), this.endDate) > 0; } }
|
||||
private bool success { get; set; } // TODO: custom setter that throws an exception if set to false or something idk
|
||||
|
||||
public YahooAuctionsItem(string id, string name) {
|
||||
this.id = id;
|
||||
|
|
210
ui/main.glade
210
ui/main.glade
|
@ -2,6 +2,87 @@
|
|||
<!-- Generated with glade 3.36.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.22"/>
|
||||
<object class="GtkImage" id="ImageFilter">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">edit-find</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="ImageSort">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">view-sort-ascending</property>
|
||||
</object>
|
||||
<object class="GtkRadioMenuItem" id="SortMenu">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
</object>
|
||||
<object class="GtkMenu" id="menu1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<signal name="selection-done" handler="SortMenuClosed" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="SortNameAscending">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Name, Ascending</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<property name="group">SortMenu</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="SortNameDescending">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Name, Descending</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<property name="group">SortMenu</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="SortPriceAscending">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Price, low to high</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<property name="group">SortMenu</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="SortPriceDescending">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Price, high to low</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<property name="group">SortMenu</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="SortEndingAscending">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Ending soonest</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<property name="group">SortMenu</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="SortEndingDescending">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Ending latest</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<property name="group">SortMenu</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkTextBuffer" id="TextBufferSelectedNotes"/>
|
||||
<object class="GtkPopover" id="popover1">
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -232,48 +313,6 @@
|
|||
<property name="homogeneous">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Undo</property>
|
||||
<property name="label" translatable="yes">Undo</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-undo</property>
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Redo</property>
|
||||
<property name="label" translatable="yes">Redo</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-redo</property>
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorToolItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="ButtonClearEnded">
|
||||
<property name="visible">True</property>
|
||||
|
@ -474,7 +513,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuButton">
|
||||
<object class="GtkMenuButton" id="MenuButtonFilter">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
|
@ -490,6 +529,24 @@
|
|||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="MenuButtonSort">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="popup">menu1</property>
|
||||
<property name="use_popover">False</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -533,7 +590,6 @@
|
|||
<property name="fixed_width">100</property>
|
||||
<property name="title" translatable="yes">Name</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="clickable">True</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
</child>
|
||||
|
@ -979,16 +1035,72 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkExpander">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<child>
|
||||
<object class="GtkTextView">
|
||||
<property name="height_request">100</property>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="wrap_mode">word</property>
|
||||
<property name="buffer">TextBufferSelectedNotes</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_start">3</property>
|
||||
<property name="margin_end">3</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkTextView">
|
||||
<property name="height_request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="wrap_mode">word</property>
|
||||
<property name="buffer">TextBufferSelectedNotes</property>
|
||||
<signal name="focus-out-event" handler="TextViewSelectedNotesFocusOut" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Clear</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="ButtonSelectedNotesClearClicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Save</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="label">
|
||||
|
|
Loading…
Reference in a new issue