#include "mainwindow.h" // Notepad class header file that was generated by the wizard #include "ui_mainwindow.h"// UI header file that was generated by the uic tool #include "login.h" #include "universalFunctions.h" #include #include #include #include #include #include #include MainWindow::MainWindow(QWidget *parent) // class definition, constructor : QMainWindow(parent) // calls qmainwindow parent constructor we have, // base class for the MainWindow class: , ui(new Ui::MainWindow) // create ui class and assign to ui member // creates the UI class instance and assigns it to the ui member: { ui->setupUi(this); // setup user interface defineConnections(); } void MainWindow::defineConnections() const { connect(ui -> loginButton, &QPushButton::clicked, this, &MainWindow::goToLogin); connect(ui -> pushButton, &QPushButton::clicked, this, &MainWindow::saveRegisteredUser); connect(ui -> actionExit, &QAction::triggered, this, &MainWindow::exit); connect(ui -> actionLogin, &QAction::triggered, this, &MainWindow::goToLogin); } void MainWindow::exit() { QApplication::quit(); } MainWindow::~MainWindow() { delete ui; // in the destructor, we delete the ui } void MainWindow::saveRegisteredUser() const { QJsonObject blogs = readJsonFile("blogs.json"); QJsonObject users = readJsonFile("user.json"); QString id = ui->inputId->text(); if(id == "") { outputMessageBox("THIS ID IS EMPTY!"); return; } if(users.find(id) == users.end()) { QString mail = ui->inputMail->text(); QString password = ui->inputPassword->text(); qDebug() << mail << " " << password; QJsonObject user; user["userId"] = id; user["email"] = mail; user["password"]=password; users.insert(id, user); /* userId - unique user id - text obtained from the user during user registration email - e-mail address of the user password - password provided by the user */ QJsonObject blog; QString blogTitle = ui -> inputBlogTitle->text(); QString blogId = ui -> inputBlogID->text(); if(blogs.find(blogId) == blogs.end()) { blog["ownerId"] = id; blog["title"] = blogTitle; blog["blogId"] = blogId; QJsonArray items; blog["items"] = items; blogs.insert(blogId, blog); saveJsonFile(blogs, "blogs.json"); saveJsonFile(users, "user.json"); }else outputMessageBox("THIS BLOG ID IS ALREADY TAKEN!"); }else outputMessageBox("THIS ID IS ALREADY TAKEN!"); } void MainWindow::goToLogin() { login *l = new login(); l -> show(); hide(); } void MainWindow::test() { qDebug() << "pls work"; }