smol objects for settings and listings
This commit is contained in:
parent
0529bd6c93
commit
8d447109ad
3 changed files with 68 additions and 1 deletions
41
Listing.cs
Normal file
41
Listing.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Buypeeb {
|
||||
class Listing {
|
||||
public string url;
|
||||
public string id;
|
||||
public string name;
|
||||
public int price;
|
||||
public int win_price;
|
||||
public string original_name;
|
||||
public bool favourite;
|
||||
// start_date, end_date
|
||||
public int bids;
|
||||
public bool auto_extension;
|
||||
|
||||
public Listing(string url, string id, string name) {
|
||||
this.url = url;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
// use fake values for now
|
||||
var rnd = new Random();
|
||||
this.price = rnd.Next(100, 5000);
|
||||
this.bids = rnd.Next(0, 15);
|
||||
this.name = "testing";
|
||||
this.original_name = "testing";
|
||||
}
|
||||
|
||||
public string PriceAUD() {
|
||||
double aud = this.price / 75.0;
|
||||
return $"${aud:f2}";
|
||||
}
|
||||
|
||||
public string PriceJPY() {
|
||||
return $"¥{this.price}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using Gtk;
|
||||
|
||||
|
@ -32,13 +33,20 @@ namespace Buypeeb {
|
|||
class MainWindow : Window {
|
||||
|
||||
private ListStore Items;
|
||||
private Settings Settings;
|
||||
|
||||
public MainWindow() : this(new Builder("main.glade")) { }
|
||||
|
||||
private MainWindow(Builder builder) : base(builder.GetObject("wndMain").Handle) {
|
||||
this.Settings = new Settings();
|
||||
this.Title = "Buypeeb";
|
||||
builder.Autoconnect(this);
|
||||
this.Items = (ListStore)builder.GetObject("ListItems");
|
||||
this.Items.Clear();
|
||||
foreach (KeyValuePair<string, Listing> entry in Settings.watchlist) {
|
||||
string[] values = new[] { entry.Value.name, entry.Value.PriceJPY(), entry.Value.PriceAUD(), "whenever", entry.Value.id };
|
||||
this.Items.AppendValues(values);
|
||||
}
|
||||
foreach (object[] row in this.Items) {
|
||||
Console.WriteLine(row[(int)ItemColumns.Name]);
|
||||
}
|
||||
|
@ -49,7 +57,7 @@ namespace Buypeeb {
|
|||
Application.Quit();
|
||||
}
|
||||
|
||||
// convenience functions
|
||||
// general behaviour
|
||||
|
||||
private (Boolean accepted, string response) EntryDialogue(string title = "Buypeeb", string message = "Hi there!") {
|
||||
Dialog ed = new Dialog(title, null, Gtk.DialogFlags.DestroyWithParent, "Cancel", ResponseType.Cancel, "OK", ResponseType.Ok);
|
||||
|
@ -70,6 +78,10 @@ namespace Buypeeb {
|
|||
return (accepted == ResponseType.Ok, response);
|
||||
}
|
||||
|
||||
private void UpdateItems() {
|
||||
|
||||
}
|
||||
|
||||
// button handlers
|
||||
|
||||
private void ButtonAddClicked(object sender, EventArgs a) {
|
||||
|
|
14
Settings.cs
Normal file
14
Settings.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Buypeeb {
|
||||
class Settings {
|
||||
public Dictionary<string, Listing> watchlist;
|
||||
|
||||
public Settings() {
|
||||
this.watchlist = new Dictionary<string, Listing>();
|
||||
string id = "k12345";
|
||||
this.watchlist.Add(id, new Listing("https://yahoo.jp", id, "my thingy"));
|
||||
this.watchlist[id].Update();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue