Commit f1b267ed authored by Vincent's avatar Vincent 💩

Added documentation comments and did fine-tuned the UI

parent 6630059f
......@@ -76,6 +76,7 @@
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.SaveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.btnLogout = new System.Windows.Forms.Button();
this.FormTabs.SuspendLayout();
this.ComputerTab.SuspendLayout();
this.panel4.SuspendLayout();
......@@ -183,10 +184,10 @@
this.ReadAllRadio.Checked = true;
this.ReadAllRadio.Location = new System.Drawing.Point(3, 3);
this.ReadAllRadio.Name = "ReadAllRadio";
this.ReadAllRadio.Size = new System.Drawing.Size(61, 17);
this.ReadAllRadio.Size = new System.Drawing.Size(36, 17);
this.ReadAllRadio.TabIndex = 21;
this.ReadAllRadio.TabStop = true;
this.ReadAllRadio.Text = "All New";
this.ReadAllRadio.Text = "All";
this.ReadAllRadio.UseVisualStyleBackColor = true;
//
// ReadSelectRadio
......@@ -472,6 +473,7 @@
//
// AccountPanel
//
this.AccountPanel.Controls.Add(this.btnLogout);
this.AccountPanel.Controls.Add(this.LabelAccountComputerCount);
this.AccountPanel.Controls.Add(this.StaticLabelAccountComputerCount);
this.AccountPanel.Controls.Add(this.LabelAccountSince);
......@@ -484,7 +486,7 @@
this.AccountPanel.Controls.Add(this.StaticLabelAccountEmail);
this.AccountPanel.Location = new System.Drawing.Point(256, 3);
this.AccountPanel.Name = "AccountPanel";
this.AccountPanel.Size = new System.Drawing.Size(236, 139);
this.AccountPanel.Size = new System.Drawing.Size(236, 155);
this.AccountPanel.TabIndex = 1;
this.AccountPanel.TabStop = false;
this.AccountPanel.Text = "Account";
......@@ -502,7 +504,7 @@
// StaticLabelAccountComputerCount
//
this.StaticLabelAccountComputerCount.AutoSize = true;
this.StaticLabelAccountComputerCount.Location = new System.Drawing.Point(6, 103);
this.StaticLabelAccountComputerCount.Location = new System.Drawing.Point(7, 103);
this.StaticLabelAccountComputerCount.Name = "StaticLabelAccountComputerCount";
this.StaticLabelAccountComputerCount.Size = new System.Drawing.Size(83, 13);
this.StaticLabelAccountComputerCount.TabIndex = 9;
......@@ -556,7 +558,7 @@
// StaticLabelAccountDiveCount
//
this.StaticLabelAccountDiveCount.AutoSize = true;
this.StaticLabelAccountDiveCount.Location = new System.Drawing.Point(6, 83);
this.StaticLabelAccountDiveCount.Location = new System.Drawing.Point(7, 83);
this.StaticLabelAccountDiveCount.Name = "StaticLabelAccountDiveCount";
this.StaticLabelAccountDiveCount.Size = new System.Drawing.Size(59, 13);
this.StaticLabelAccountDiveCount.TabIndex = 2;
......@@ -634,6 +636,16 @@
//
this.SaveFileDialog.Filter = "JSON Files (*.json)|*.json";
//
// btnLogout
//
this.btnLogout.Location = new System.Drawing.Point(10, 119);
this.btnLogout.Name = "btnLogout";
this.btnLogout.Size = new System.Drawing.Size(75, 23);
this.btnLogout.TabIndex = 11;
this.btnLogout.Text = "Logout";
this.btnLogout.UseVisualStyleBackColor = true;
this.btnLogout.Click += new System.EventHandler(this.btnLogout_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
......@@ -723,6 +735,7 @@
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.CheckBox CheckboxReadSinceLast;
private System.Windows.Forms.Button btnLogout;
}
}
......@@ -32,8 +32,7 @@ namespace divecomputer_test {
Session.WebAppSession.OnError += (sender, err) => {
AuthErrLabel.Text = err.GetException().Message;
};
}
private void Form1_Load(object sender, EventArgs e) {
......@@ -47,6 +46,7 @@ namespace divecomputer_test {
SaveFileText.Text = Session.Destination ?? "";
LoadTarget();
CheckboxReadSinceLast.Enabled = Session.Target == TargetType.DiveLog;
Session.TrackChanges();
}
......@@ -108,13 +108,19 @@ namespace divecomputer_test {
}
public void SetAccountDetails(UserData data) {
AccountPanel.Visible = true;
LoginPanel.Visible = false;
LabelAccountEmail.Text = data.Email;
LabelAccountName.Text = data.Name;
LabelAccountDiveCount.Text = data.DiveCount.ToString();
LabelAccountSince.Text = data.Inserted.ToString("yyyy-MM-dd hh:mm:ss");
LabelAccountComputerCount.Text = data.ComputerCount.ToString();
AccountPanel.Visible = data != null;
LoginPanel.Visible = data == null;
if(data != null) {
LogRadio.Checked = true;
LabelAccountEmail.Text = data.Email;
LabelAccountName.Text = data.Name;
LabelAccountDiveCount.Text = data.DiveCount.ToString();
LabelAccountSince.Text = data.Inserted.ToString("yyyy-MM-dd hh:mm:ss");
LabelAccountComputerCount.Text = data.ComputerCount.ToString();
} else {
FileRadio.Checked = true;
}
}
private void LogLevelSelector_SelectedValueChanged(object sender, EventArgs e) {
......@@ -337,7 +343,12 @@ namespace divecomputer_test {
} else {
Session.Target = TargetType.None;
}
CheckboxReadSinceLast.Enabled = Session.Target == TargetType.DiveLog;
Session.Save();
}
private void btnLogout_Click(object sender, EventArgs e) {
Session.WebAppSession.Logout();
}
}
}
\ No newline at end of file
......@@ -72,19 +72,57 @@ namespace DiveLogUploader.Readers {
public delegate void StateChangeHandle(object source, StateChangedEventArgs args);
public delegate void ErrorHandle(object source, ErrorEventArgs args);
public class DiveReader : IDisposable {
/// <summary>
/// Wrapper class for reading in with libdivecomputer
/// It uses a background worker for the reading
/// </summary>
public class DiveReader : IDisposable {
public const dc_loglevel_t DefaultLogLevel = dc_loglevel_t.DC_LOGLEVEL_ERROR;
/// <summary>
/// Event called when the progress changed
/// </summary>
public event ProgressHandle OnProgress;
/// <summary>
/// Event called upon receiving the device info
/// </summary>
public event DeviceInfoHandle OnDeviceInfo;
/// <summary>
/// Event called upon receiving clock information from the device
/// </summary>
public event ClockInfoHandle OnDeviceClock;
/// <summary>
/// Event called on receiving a dive from the computer. The dive will be already parsed.
/// </summary>
public event DiveHandle OnDive;
/// <summary>
/// Event called upon after reading and parsing has been completed
/// </summary>
public event CompleteHandle OnComplete;
/// <summary>
/// Event called upon receiving a log message from libdivecomputer.
/// </summary>
public event LogMessageHandle OnLogMessage;
/// <summary>
/// Event called when the state of the reader changes. eg. Started, Waiting for device, Reading and Completed.
/// </summary>
public event StateChangeHandle OnStateChange;
/// <summary>
/// Event called when an error has occurred.
/// </summary>
public event ErrorHandle OnError;
/// <summary>
/// Which log type of messages to receive on the LogMessage event
/// </summary>
public dc_loglevel_t Loglevel = DefaultLogLevel;
/// <summary>
/// Serial port to read from
/// </summary>
public string SerialPort;
/// <summary>
/// DeviceDescriptor of the device to read.
/// </summary>
public Descriptor DeviceDescriptor;
protected BackgroundWorker worker = new BackgroundWorker();
......@@ -108,6 +146,9 @@ namespace DiveLogUploader.Readers {
return ctx;
}
/// <summary>
/// Starts reading
/// </summary>
public void Start() {
if(worker.IsBusy) {
throw new Exception("Dive Reader is already busy");
......@@ -190,9 +231,7 @@ namespace DiveLogUploader.Readers {
}
}
public void Dispose() {
}
public void Dispose() {}
}
......
......@@ -16,7 +16,7 @@ namespace LibDiveComputer {
public string SerialPort;
public string Computer;
public string Destination;
public TargetType Target;
public TargetType Target = TargetType.File;
[JsonIgnore]
public WebApplicationSession WebAppSession { get; private set; }
......
......@@ -106,7 +106,14 @@ namespace DiveLogUploader {
}
}
private UserData Data;
private UserData _data;
public UserData Data {
get { return _data; }
set {
_data = value;
OnData?.Invoke(this, new DataEventArgs { Data = Data });
}
}
public bool IsLoggedIn {
get { return Token != null; }
......@@ -122,6 +129,11 @@ namespace DiveLogUploader {
await GetData();
}
public void Logout() {
Token = null;
Data = null;
}
public async Task Login(string email, string password) {
var d = JToken.FromObject(new {
email = email,
......@@ -166,7 +178,6 @@ namespace DiveLogUploader {
}
Data = result;
OnData?.Invoke(this, new DataEventArgs { Data = result });
} catch(WebserviceError err) {
HandleError(err);
}
......
......@@ -8,12 +8,27 @@ using LibDiveComputer;
using System.Windows.Forms;
namespace DiveLogUploader.Writers {
/// <summary>
/// Dive writer which proxies between an other writer.
/// Let the user select from the given dives and writes them to the target
/// </summary>
public class SelectDiveWriter : IDiveWriter, IDisposable {
/// <summary>
/// Dives currently accumulated
/// </summary>
public List<Dive> Dives = new List<Dive>();
/// <summary>
/// Form used to select the dives
/// </summary>
public DiveSelectorForm Selector;
protected IDiveWriter Target;
protected Form BaseForm;
/// <summary>
/// </summary>
/// <param name="target">Target writer to write the dives to after selection</param>
/// <param name="baseForm">BaseForm used as a reference point for invoking the UI thread</param>
public SelectDiveWriter(IDiveWriter target, Form baseForm = null) {
Target = target;
BaseForm = baseForm;
......@@ -29,10 +44,16 @@ namespace DiveLogUploader.Writers {
};
}
/// <summary>
/// Complete called when the target writer is completed
/// </summary>
public event OnCompleteHandler OnComplete {
add { Target.OnComplete += value; }
remove { Target.OnComplete -= value; }
}
/// <summary>
/// Progress of the target writer
/// </summary>
public event OnProgresHandler OnProgres {
add { Target.OnProgres += value; }
remove { Target.OnProgres -= value; }
......@@ -47,11 +68,17 @@ namespace DiveLogUploader.Writers {
Target.Dispose();
}
/// <summary>
/// Done adding dives. Passes the dives to the selector and shows it.
/// </summary>
public void End() {
Selector.SetDives(Dives);
ShowSelector();
}
/// <summary>
/// Shows the selector form
/// </summary>
public void ShowSelector() {
if (BaseForm != null && BaseForm.InvokeRequired) {
BaseForm.Invoke(new Action(() => { ShowSelector(); }));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment