Task done
This commit is contained in:
@@ -9,10 +9,12 @@ class Program
|
|||||||
{
|
{
|
||||||
static int Main()
|
static int Main()
|
||||||
{
|
{
|
||||||
|
var serviceProvider = SetupServices();
|
||||||
var application = Adw.Application.New("org.piper.feladat1", Gio.ApplicationFlags.FlagsNone);
|
var application = Adw.Application.New("org.piper.feladat1", Gio.ApplicationFlags.FlagsNone);
|
||||||
application.OnActivate += (sender, args) =>
|
application.OnActivate += (sender, args) =>
|
||||||
{
|
{
|
||||||
var window = new MainWindow().Window;
|
var userService = serviceProvider.GetService<IUserService>();
|
||||||
|
var window = new MainWindow(userService).Window;
|
||||||
window.Application = (Adw.Application)sender;
|
window.Application = (Adw.Application)sender;
|
||||||
window.Show();
|
window.Show();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Adw;
|
using Adw;
|
||||||
|
using GLib;
|
||||||
using Logic;
|
using Logic;
|
||||||
|
using Models;
|
||||||
|
|
||||||
namespace Feladat1.UI.MainWindow;
|
namespace Feladat1.UI.MainWindow;
|
||||||
|
|
||||||
@@ -22,8 +24,18 @@ public class MainWindow
|
|||||||
private PasswordEntryRow passwordField;
|
private PasswordEntryRow passwordField;
|
||||||
private const string passwordFieldId = "password";
|
private const string passwordFieldId = "password";
|
||||||
|
|
||||||
public MainWindow()
|
private EntryRow emailLabel;
|
||||||
|
private const string emailLabelId = "emailLabel";
|
||||||
|
|
||||||
|
private EntryRow usernameLabel;
|
||||||
|
private const string usernameLabelId = "usernameLabel";
|
||||||
|
|
||||||
|
private PasswordEntryRow passwordLabel;
|
||||||
|
private const string passwordLabelId = "passwordLabel";
|
||||||
|
|
||||||
|
public MainWindow(IUserService userService)
|
||||||
{
|
{
|
||||||
|
this.userService = userService;
|
||||||
var builder = new Gtk.Builder("Feladat1.UI.MainWindow.MainWindow.ui.xml");
|
var builder = new Gtk.Builder("Feladat1.UI.MainWindow.MainWindow.ui.xml");
|
||||||
|
|
||||||
Window = builder.GetObject(windowId) as Window;
|
Window = builder.GetObject(windowId) as Window;
|
||||||
@@ -58,6 +70,24 @@ public class MainWindow
|
|||||||
{
|
{
|
||||||
throw new NullReferenceException(passwordFieldId);
|
throw new NullReferenceException(passwordFieldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emailLabel = builder.GetObject(emailLabelId) as EntryRow;
|
||||||
|
if (emailLabel == null)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException(emailLabelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
usernameLabel = builder.GetObject(usernameLabelId) as EntryRow;
|
||||||
|
if (usernameLabel == null)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException(usernameLabelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
passwordLabel = builder.GetObject(passwordLabelId) as PasswordEntryRow;
|
||||||
|
if (passwordLabel == null)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException(passwordLabelId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (NullReferenceException e)
|
catch (NullReferenceException e)
|
||||||
{
|
{
|
||||||
@@ -68,7 +98,7 @@ public class MainWindow
|
|||||||
|
|
||||||
private bool ValidateFields()
|
private bool ValidateFields()
|
||||||
{
|
{
|
||||||
if (userNameField.Text_ != null && emailField.Text_ != null && passwordField.Text_ != null)
|
if (userNameField.Text_ != string.Empty && emailField.Text_ != string.Empty && passwordField.Text_ != string.Empty)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -79,7 +109,22 @@ public class MainWindow
|
|||||||
{
|
{
|
||||||
if (ValidateFields())
|
if (ValidateFields())
|
||||||
{
|
{
|
||||||
userService.Create(userNameField.GetText(), emailField.GetText(), passwordField.GetText());
|
int returnCode = userService.Create(userNameField.GetText(), emailField.GetText(), passwordField.GetText());
|
||||||
|
if (returnCode == 0)
|
||||||
|
{
|
||||||
|
ToastOverlay overlay = new ToastOverlay();
|
||||||
|
overlay.SetParent(Window);
|
||||||
|
|
||||||
|
Toast toast = new Toast();
|
||||||
|
toast.SetButtonLabel("New user exported successfully");
|
||||||
|
|
||||||
|
overlay.AddToast(toast);
|
||||||
|
|
||||||
|
User user = userService.Read();
|
||||||
|
emailLabel.Text_ = user.Email;
|
||||||
|
usernameLabel.Text_ = user.Username;
|
||||||
|
passwordLabel.Text_ = user.Password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
<object class="AdwWindow" id="main_window">
|
<object class="AdwWindow" id="main_window">
|
||||||
<property name="width-request">300</property>
|
<property name="width-request">300</property>
|
||||||
<property name="height-request">300</property>
|
<property name="height-request">300</property>
|
||||||
<property name="default-width">500</property>
|
<property name="default-width">400</property>
|
||||||
<property name="default-height">600</property>
|
<property name="default-height">400</property>
|
||||||
<property name="content">
|
<property name="content">
|
||||||
<object class="AdwToolbarView">
|
<object class="AdwToolbarView">
|
||||||
<child type="top">
|
<child type="top">
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
<child>
|
<child>
|
||||||
<object class="AdwViewStackPage">
|
<object class="AdwViewStackPage">
|
||||||
<property name="name">save</property>
|
<property name="name">save</property>
|
||||||
|
<property name="icon-name">document-save-as-symbolic</property>
|
||||||
<property name="title">Save</property>
|
<property name="title">Save</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="AdwPreferencesPage">
|
<object class="AdwPreferencesPage">
|
||||||
@@ -63,9 +64,32 @@
|
|||||||
<object class="AdwViewStackPage">
|
<object class="AdwViewStackPage">
|
||||||
<property name="name">load</property>
|
<property name="name">load</property>
|
||||||
<property name="title">Load</property>
|
<property name="title">Load</property>
|
||||||
|
<property name="icon-name">document-open-symbolic</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="AdwStatusPage">
|
<object class="AdwPreferencesPage">
|
||||||
<property name="title">Load</property>
|
<child>
|
||||||
|
<object class="AdwPreferencesGroup">
|
||||||
|
<child>
|
||||||
|
<object class="AdwEntryRow" id="emailLabel">
|
||||||
|
<property name="title">Email</property>
|
||||||
|
<property name="editable">False</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="AdwEntryRow" id="usernameLabel">
|
||||||
|
<property name="title">Felhasználónév</property>
|
||||||
|
<property name="editable">False</property>
|
||||||
|
<property name="activatable">False</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="AdwPasswordEntryRow" id="passwordLabel">
|
||||||
|
<property name="title">Jelszó</property>
|
||||||
|
<property name="editable">False</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</property>
|
</property>
|
||||||
</object>
|
</object>
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ namespace Logic;
|
|||||||
|
|
||||||
public interface IUserService
|
public interface IUserService
|
||||||
{
|
{
|
||||||
public void Create(string username, string email, string password);
|
public int Create(string username, string email, string password);
|
||||||
public User? Read();
|
public User? Read();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,19 @@ namespace Logic;
|
|||||||
public class UserService : IUserService
|
public class UserService : IUserService
|
||||||
{
|
{
|
||||||
private IRepository repository;
|
private IRepository repository;
|
||||||
|
|
||||||
|
public UserService(IRepository repository)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
public User? Read()
|
public User? Read()
|
||||||
{
|
{
|
||||||
return repository.Read();
|
return repository.Read();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Create(string username, string email, string password)
|
public int Create(string username, string email, string password)
|
||||||
{
|
{
|
||||||
repository.Write(new User(username, email, password));
|
return repository.Write(new User(username, email, password));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,7 @@ public class User
|
|||||||
{
|
{
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public string Email { get; }
|
public string Email { get; }
|
||||||
|
public string Password { get; set; }
|
||||||
private string password;
|
|
||||||
public string Password
|
|
||||||
{
|
|
||||||
set => password = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User(string username, string email, string password)
|
public User(string username, string email, string password)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ namespace Repository;
|
|||||||
public interface IRepository
|
public interface IRepository
|
||||||
{
|
{
|
||||||
public User? Read();
|
public User? Read();
|
||||||
public void Write(User item);
|
public int Write(User item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,24 +32,28 @@ public class JsonRepository : IRepository
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(User item)
|
public int Write(User item)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string json = JsonSerializer.Serialize(item);
|
string json = JsonSerializer.Serialize(item);
|
||||||
File.WriteAllText(_fileName, json);
|
File.WriteAllText(_fileName, json);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
catch (JsonException e)
|
catch (JsonException e)
|
||||||
{
|
{
|
||||||
WriteToStdErr($"JSON error: {e.Message}");
|
WriteToStdErr($"JSON error: {e.Message}");
|
||||||
|
return e.GetHashCode();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
WriteToStdErr($"File I/O error: {e.Message}");
|
WriteToStdErr($"File I/O error: {e.Message}");
|
||||||
|
return e.GetHashCode();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
WriteToStdErr($"Unexpected error: {e.Message}");
|
WriteToStdErr($"Unexpected error: {e.Message}");
|
||||||
|
return e.GetHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user