Compare commits

..

3 commits

Author SHA1 Message Date
8d447109ad
smol objects for settings and listings 2020-09-01 20:41:29 +10:00
0529bd6c93
a working custom add dialogue! 2020-09-01 19:58:35 +10:00
9c5d067635
new build and release scripts 2020-09-01 19:01:36 +10:00
9 changed files with 324 additions and 205 deletions

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
poop/
BuypeebApp.exe
ui.glade~
*.glade~
bin/
obj/
out/

34
AddItemDialogue.cs Normal file
View file

@ -0,0 +1,34 @@
using System;
using Gtk;
using UI = Gtk.Builder.ObjectAttribute;
namespace Buypeeb {
class AddItemDialogue : Dialog {
private Entry EntryURL;
private Entry EntryName;
public AddItemDialogue() : this(new Builder("add.glade")) { }
private AddItemDialogue(Builder builder) : base(builder.GetObject("DialogueAdd").Handle) {
this.Title = "Add item";
builder.Autoconnect(this);
this.EntryURL = (Entry)builder.GetObject("EntryAddURL");
this.EntryName = (Entry)builder.GetObject("EntryAddName");
DeleteEvent += Window_Shutdown;
}
private void Window_Shutdown(object sender, DeleteEventArgs args) {
Application.Quit();
}
public string GetURL() {
return this.EntryURL.Text;
}
public string GetName() {
return this.EntryName.Text;
}
}
}

41
Listing.cs Normal file
View 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}";
}
}
}

View file

@ -17,8 +17,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Gtk;
using UI = Gtk.Builder.ObjectAttribute;
namespace Buypeeb {
enum ItemColumns {
@ -32,13 +33,20 @@ namespace Buypeeb {
class MainWindow : Window {
private ListStore Items;
private Settings Settings;
public MainWindow() : this(new Builder("ui.glade")) { }
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,12 +78,28 @@ namespace Buypeeb {
return (accepted == ResponseType.Ok, response);
}
private void UpdateItems() {
}
// button handlers
private void ButtonAddClicked(object sender, EventArgs a) {
Console.WriteLine("ButtonAddClicked");
var EntryResponse = EntryDialogue();
Console.WriteLine(EntryResponse.response);
// Console.WriteLine("ButtonAddClicked");
AddItemDialogue aid = new AddItemDialogue();
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);
}
else {
Console.WriteLine("{0} is an invalid url", url);
}
}
private void ButtonUpdateAllClicked(object sender, EventArgs a) {

14
Settings.cs Normal file
View 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();
}
}
}

View file

@ -1,2 +1,2 @@
#!/bin/sh
mcs -pkg:gtk-sharp-3.0 -resource:ui.glade *.cs
dotnet build -o out/debug/

2
release.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
dotnet publish -c Release -r linux-x64 --output ./out/release/linux/ -p:PublishSingleFile=true -p:PublishTrimmed=true

157
ui/add.glade Normal file
View file

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkDialog" id="DialogueAdd">
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="default_width">320</property>
<property name="type_hint">dialog</property>
<property name="gravity">center</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="margin_start">5</property>
<property name="margin_end">5</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="margin_bottom">5</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="ButtonAddCancel">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ButtonAddOK">
<property name="label" translatable="yes">OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Add item</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.5"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Enter the URL of the item you want to add.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="EntryAddURL">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_top">5</property>
<property name="margin_bottom">10</property>
<property name="activates_default">True</property>
<property name="placeholder_text" translatable="yes">URL</property>
<property name="input_purpose">url</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">You may also enter a custom name below.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="EntryAddName">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_top">5</property>
<property name="activates_default">True</property>
<property name="placeholder_text" translatable="yes">Name (optional)</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">ButtonAddCancel</action-widget>
<action-widget response="-5">ButtonAddOK</action-widget>
</action-widgets>
<child type="titlebar">
<placeholder/>
</child>
</object>
</interface>

View file

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<requires lib="gtk+" version="3.22" />
<object class="GtkListStore" id="ListItems">
<columns>
<!-- column-name Name -->
<column type="gchararray"/>
<column type="gchararray" />
<!-- column-name PriceYen -->
<column type="gchararray"/>
<column type="gchararray" />
<!-- column-name PriceAUD -->
<column type="gchararray"/>
<column type="gchararray" />
<!-- column-name Ending -->
<column type="gchararray"/>
<column type="gchararray" />
<!-- column-name id -->
<column type="gchararray"/>
<column type="gchararray" />
</columns>
<data>
<row>
@ -55,8 +55,8 @@
<property name="label" translatable="yes">Add new</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-add</property>
<signal name="clicked" handler="ButtonAddClicked" swapped="no"/>
<accelerator key="n" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<signal name="clicked" handler="ButtonAddClicked" swapped="no" />
<accelerator key="n" signal="clicked" modifiers="GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -71,8 +71,8 @@
<property name="label" translatable="yes">Update all</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-refresh</property>
<signal name="clicked" handler="ButtonUpdateAllClicked" swapped="no"/>
<accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<signal name="clicked" handler="ButtonUpdateAllClicked" swapped="no" />
<accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -97,7 +97,7 @@
<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"/>
<accelerator key="z" signal="clicked" modifiers="GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -112,7 +112,7 @@
<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"/>
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -137,7 +137,7 @@
<property name="label" translatable="yes">Clear ended</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-clear</property>
<signal name="clicked" handler="ButtonClearEndedClicked" swapped="no"/>
<signal name="clicked" handler="ButtonClearEndedClicked" swapped="no" />
</object>
<packing>
<property name="expand">False</property>
@ -152,7 +152,7 @@
<property name="label" translatable="yes">Clear all</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-delete</property>
<signal name="clicked" handler="ButtonClearAllClicked" swapped="no"/>
<signal name="clicked" handler="ButtonClearAllClicked" swapped="no" />
</object>
<packing>
<property name="expand">False</property>
@ -177,7 +177,7 @@
<property name="label" translatable="yes">Open</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-open</property>
<accelerator key="o" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="o" signal="clicked" modifiers="GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -192,8 +192,8 @@
<property name="label" translatable="yes">Save</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-save</property>
<signal name="clicked" handler="ButtonSaveClicked" swapped="no"/>
<accelerator key="s" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<signal name="clicked" handler="ButtonSaveClicked" swapped="no" />
<accelerator key="s" signal="clicked" modifiers="GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -208,7 +208,7 @@
<property name="label" translatable="yes">Export as...</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-save-as</property>
<accelerator key="e" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
<accelerator key="e" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -233,7 +233,7 @@
<property name="label" translatable="yes">Help</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-help</property>
<accelerator key="slash" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="slash" signal="clicked" modifiers="GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -248,7 +248,7 @@
<property name="label" translatable="yes">Settings</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-preferences</property>
<accelerator key="comma" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="comma" signal="clicked" modifiers="GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -263,8 +263,8 @@
<property name="label" translatable="yes">Quit</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-quit</property>
<signal name="clicked" handler="ButtonQuitClicked" swapped="no"/>
<accelerator key="q" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<signal name="clicked" handler="ButtonQuitClicked" swapped="no" />
<accelerator key="q" signal="clicked" modifiers="GDK_CONTROL_MASK" />
</object>
<packing>
<property name="expand">False</property>
@ -296,7 +296,7 @@
<property name="activate_on_single_click">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<signal name="changed" handler="tveItemsSelectionChanged" swapped="no"/>
<signal name="changed" handler="tveItemsSelectionChanged" swapped="no" />
</object>
</child>
<child>
@ -308,7 +308,7 @@
<property name="expand">True</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText"/>
<object class="GtkCellRendererText" />
<attributes>
<attribute name="text">0</attribute>
</attributes>
@ -320,7 +320,7 @@
<property name="resizable">True</property>
<property name="title" translatable="yes">Price (¥)</property>
<child>
<object class="GtkCellRendererText"/>
<object class="GtkCellRendererText" />
<attributes>
<attribute name="text">1</attribute>
</attributes>
@ -332,7 +332,7 @@
<property name="resizable">True</property>
<property name="title" translatable="yes">Price (AUD)</property>
<child>
<object class="GtkCellRendererText"/>
<object class="GtkCellRendererText" />
<attributes>
<attribute name="text">2</attribute>
</attributes>
@ -345,7 +345,7 @@
<property name="title" translatable="yes">Ending at</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText"/>
<object class="GtkCellRendererText" />
<attributes>
<attribute name="text">3</attribute>
</attributes>
@ -385,8 +385,8 @@
<property name="max_width_chars">40</property>
<property name="lines">3</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
<attribute name="weight" value="bold" />
<attribute name="scale" value="2" />
</attributes>
</object>
<packing>
@ -548,23 +548,6 @@
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
@ -614,19 +597,22 @@
</packing>
</child>
<child>
<placeholder/>
<placeholder />
</child>
<child>
<placeholder/>
<placeholder />
</child>
<child>
<placeholder/>
<placeholder />
</child>
<child>
<placeholder/>
<placeholder />
</child>
<child>
<placeholder/>
<placeholder />
</child>
<child>
<placeholder />
</child>
</object>
<packing>
@ -661,7 +647,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="ButtonViewBuyeeClicked" swapped="no"/>
<signal name="clicked" handler="ButtonViewBuyeeClicked" swapped="no" />
</object>
<packing>
<property name="expand">False</property>
@ -675,7 +661,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="ButtonViewYahooClicked" swapped="no"/>
<signal name="clicked" handler="ButtonViewYahooClicked" swapped="no" />
</object>
<packing>
<property name="expand">False</property>
@ -696,7 +682,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Remove</property>
<signal name="clicked" handler="ButtonSelectedRemoveClicked" swapped="no"/>
<signal name="clicked" handler="ButtonSelectedRemoveClicked" swapped="no" />
<child>
<object class="GtkImage" id="image4">
<property name="visible">True</property>
@ -718,7 +704,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Rename</property>
<signal name="clicked" handler="ButtonSelectedRenameClicked" swapped="no"/>
<signal name="clicked" handler="ButtonSelectedRenameClicked" swapped="no" />
<child>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
@ -843,147 +829,7 @@
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
<object class="GtkDialog">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Add item</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.5"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Enter the URL of the item you want to add.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">URL</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">You can also enter a custom name to use instead of the default.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkCheckButton">
<property name="label" translatable="yes">Favourite</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</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="titlebar">
<placeholder/>
<placeholder />
</child>
</object>
</interface>