Task done

This commit is contained in:
2025-09-27 23:01:24 +02:00
parent 6c5579809d
commit 6fb3ffb680
8 changed files with 95 additions and 19 deletions

View File

@@ -9,10 +9,12 @@ class Program
{
static int Main()
{
var serviceProvider = SetupServices();
var application = Adw.Application.New("org.piper.feladat1", Gio.ApplicationFlags.FlagsNone);
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.Show();
};

View File

@@ -1,5 +1,7 @@
using Adw;
using GLib;
using Logic;
using Models;
namespace Feladat1.UI.MainWindow;
@@ -22,8 +24,18 @@ public class MainWindow
private PasswordEntryRow passwordField;
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");
Window = builder.GetObject(windowId) as Window;
@@ -58,6 +70,24 @@ public class MainWindow
{
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)
{
@@ -68,7 +98,7 @@ public class MainWindow
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;
}
@@ -79,7 +109,22 @@ public class MainWindow
{
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;
}
}
}
}

View File

@@ -3,8 +3,8 @@
<object class="AdwWindow" id="main_window">
<property name="width-request">300</property>
<property name="height-request">300</property>
<property name="default-width">500</property>
<property name="default-height">600</property>
<property name="default-width">400</property>
<property name="default-height">400</property>
<property name="content">
<object class="AdwToolbarView">
<child type="top">
@@ -23,6 +23,7 @@
<child>
<object class="AdwViewStackPage">
<property name="name">save</property>
<property name="icon-name">document-save-as-symbolic</property>
<property name="title">Save</property>
<property name="child">
<object class="AdwPreferencesPage">
@@ -63,9 +64,32 @@
<object class="AdwViewStackPage">
<property name="name">load</property>
<property name="title">Load</property>
<property name="icon-name">document-open-symbolic</property>
<property name="child">
<object class="AdwStatusPage">
<property name="title">Load</property>
<object class="AdwPreferencesPage">
<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>
</property>
</object>