mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 18:43:07 +02:00
feat: store blog entries
This commit is contained in:
parent
18310ff2c3
commit
04c8866199
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,32 +1,19 @@
|
|||||||
{
|
{
|
||||||
"superId": {
|
"": {
|
||||||
"blogId": "superId",
|
"blogId": "",
|
||||||
"ownerId": "SupertajnehasloxDDDDD",
|
"items": [
|
||||||
"title": "1"
|
{
|
||||||
},
|
"content": "",
|
||||||
"5": {
|
"datetime": "01:05:33 Wed Apr 6 2022",
|
||||||
"blogId": "5",
|
"title": "Title"
|
||||||
"ownerId": "6",
|
},
|
||||||
"title": "6"
|
{
|
||||||
},
|
"content": "notempty",
|
||||||
"6": {
|
"datetime": "01:05:44 Wed Apr 6 2022",
|
||||||
"blogId": "6",
|
"title": "anotherTitle"
|
||||||
"ownerId": "7",
|
}
|
||||||
"title": "5"
|
],
|
||||||
},
|
"ownerId": "1",
|
||||||
"Title": {
|
"title": ""
|
||||||
"content": "",
|
|
||||||
"datetime": "13:25:59 Tue Apr 5 2022",
|
|
||||||
"title": "Title"
|
|
||||||
},
|
|
||||||
"blogtitle3": {
|
|
||||||
"content": "blogtitle3",
|
|
||||||
"datetime": "00:25:37 Tue Apr 5 2022",
|
|
||||||
"title": "blogtitle3"
|
|
||||||
},
|
|
||||||
"title": {
|
|
||||||
"content": "blogentry2",
|
|
||||||
"datetime": "00:24:53 Tue Apr 5 2022",
|
|
||||||
"title": "blogtitle2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE RCC><RCC version="1.0">
|
<!DOCTYPE RCC><RCC version="1.0">
|
||||||
<qresource prefix="i18n">
|
<qresource prefix="i18n">
|
||||||
<file alias="lab1_pl_PL.qm">/home/kuchy/Zlew/niepraca/Studia/Programy/egui_lab1_krzysztof_rudnicki/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/.qm/lab1_pl_PL.qm</file>
|
<file alias="lab1_pl_PL.qm">/home/kuchy/Zlew/Studia/NieNotatki/Projekty/nie_inzynierka/Programowanie/EGUI/egui_lab1_krzysztof_rudnicki/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/.qm/lab1_pl_PL.qm</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
static const unsigned char qt_resource_data[] = {
|
static const unsigned char qt_resource_data[] = {
|
||||||
// /home/kuchy/Zlew/niepraca/Studia/Programy/egui_lab1_krzysztof_rudnicki/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/.qm/lab1_pl_PL.qm
|
// /home/kuchy/Zlew/Studia/NieNotatki/Projekty/nie_inzynierka/Programowanie/EGUI/egui_lab1_krzysztof_rudnicki/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/.qm/lab1_pl_PL.qm
|
||||||
0x0,0x0,0x0,0x29,
|
0x0,0x0,0x0,0x29,
|
||||||
0x3c,
|
0x3c,
|
||||||
0xb8,0x64,0x18,0xca,0xef,0x9c,0x95,0xcd,0x21,0x1c,0xbf,0x60,0xa1,0xbd,0xdd,0xa7,
|
0xb8,0x64,0x18,0xca,0xef,0x9c,0x95,0xcd,0x21,0x1c,0xbf,0x60,0xa1,0xbd,0xdd,0xa7,
|
||||||
@ -39,7 +39,7 @@ static const unsigned char qt_resource_struct[] = {
|
|||||||
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
|
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
|
||||||
// :/i18n/lab1_pl_PL.qm
|
// :/i18n/lab1_pl_PL.qm
|
||||||
0x0,0x0,0x0,0xe,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
|
0x0,0x0,0x0,0xe,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
|
||||||
0x0,0x0,0x1,0x7f,0xf9,0x6f,0xcf,0x46,
|
0x0,0x0,0x1,0x7f,0xc6,0xd1,0xee,0x9c,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -1,37 +1,7 @@
|
|||||||
{
|
{
|
||||||
"": {
|
|
||||||
"id": "",
|
|
||||||
"mail": "",
|
|
||||||
"password": ""
|
|
||||||
},
|
|
||||||
"1": {
|
"1": {
|
||||||
"id": "1",
|
"email": "",
|
||||||
"mail": "1",
|
|
||||||
"password": "SupertajnehasloxDDDDD"
|
|
||||||
},
|
|
||||||
"2": {
|
|
||||||
"id": "2",
|
|
||||||
"mail": "",
|
|
||||||
"password": ""
|
|
||||||
},
|
|
||||||
"5": {
|
|
||||||
"email": "5",
|
|
||||||
"password": "",
|
"password": "",
|
||||||
"userId": "5"
|
"userId": "1"
|
||||||
},
|
|
||||||
"6": {
|
|
||||||
"email": "5",
|
|
||||||
"password": "",
|
|
||||||
"userId": "6"
|
|
||||||
},
|
|
||||||
"7": {
|
|
||||||
"email": "5",
|
|
||||||
"password": "5",
|
|
||||||
"userId": "7"
|
|
||||||
},
|
|
||||||
"SupertajnehasloxDDDDD": {
|
|
||||||
"email": "1",
|
|
||||||
"password": "1",
|
|
||||||
"userId": "SupertajnehasloxDDDDD"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
blogEntry::blogEntry(QWidget *parent) :
|
blogEntry::blogEntry(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
@ -30,10 +31,16 @@ void blogEntry::setUserId(const QString &userId)
|
|||||||
ui -> ownerID -> setText("Owner ID: " + userId);
|
ui -> ownerID -> setText("Owner ID: " + userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void blogEntry::setBlogId(const QString &blogId)
|
||||||
|
{
|
||||||
|
this->blogId = blogId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QJsonObject blogEntry::readJsonFile(const QString title)
|
QJsonObject blogEntry::readJsonFile(const QString title)
|
||||||
{
|
{
|
||||||
QFile file(title);
|
QFile file(title);
|
||||||
file.open( QIODevice::ReadOnly);
|
file.open( QIODevice::ReadWrite);
|
||||||
QByteArray bytes = file.readAll();
|
QByteArray bytes = file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||||
@ -59,18 +66,18 @@ void blogEntry::saveEntry()
|
|||||||
|
|
||||||
ui -> textEdit -> setReadOnly(true);
|
ui -> textEdit -> setReadOnly(true);
|
||||||
ui -> lineEdit -> setReadOnly(true);
|
ui -> lineEdit -> setReadOnly(true);
|
||||||
QJsonObject blogEntry;
|
QJsonObject blogsFile = readJsonFile("blogs.json");
|
||||||
blogEntry["content"] = ui -> textEdit -> toPlainText();
|
QJsonObject blogEntryJson = blogsFile[blogId].toObject();
|
||||||
|
QJsonObject entry;
|
||||||
|
entry["title"] = ui -> lineEdit -> text();
|
||||||
QString Time = QTime::currentTime().toString();
|
QString Time = QTime::currentTime().toString();
|
||||||
QString Date = QDate::currentDate().toString();
|
QString Date = QDate::currentDate().toString();
|
||||||
blogEntry["datetime"] = Time + " " + Date;
|
entry["datetime"] = Time + " " + Date;
|
||||||
blogEntry["title"] = ui -> lineEdit -> text();
|
entry["content"] = ui -> textEdit -> toPlainText();
|
||||||
QJsonObject blogsFile = readJsonFile("blogs.json");
|
QJsonArray items = blogEntryJson["items"].toArray();
|
||||||
QJsonObject blogEntryJson;
|
items.append(entry);
|
||||||
blogEntryJson["title"] = ui -> lineEdit -> text();
|
blogEntryJson.insert("items", items);
|
||||||
blogEntryJson["datetime"] = Time + " " + Date;
|
blogsFile.insert(blogId, blogEntryJson);
|
||||||
blogEntryJson["content"] = ui -> textEdit -> toPlainText();
|
|
||||||
blogsFile.insert(ui -> lineEdit -> text(), blogEntryJson);
|
|
||||||
saveJsonFile(blogsFile, "blogs.json");
|
saveJsonFile(blogsFile, "blogs.json");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,15 +18,18 @@ public:
|
|||||||
explicit blogEntry(QWidget *parent = nullptr);
|
explicit blogEntry(QWidget *parent = nullptr);
|
||||||
~blogEntry();
|
~blogEntry();
|
||||||
void setUserId(const QString &userId);
|
void setUserId(const QString &userId);
|
||||||
|
void setBlogId(const QString &blogId);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_saveEntry_clicked();
|
void on_saveEntry_clicked();
|
||||||
void saveEntry();
|
void saveEntry();
|
||||||
QJsonObject readJsonFile(const QString title);
|
QJsonObject readJsonFile(const QString title);
|
||||||
void saveJsonFile(QJsonObject &users, const QString name) const;
|
void saveJsonFile(QJsonObject &users, const QString name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::blogEntry *ui;
|
Ui::blogEntry *ui;
|
||||||
QString userId;
|
QString userId;
|
||||||
|
QString blogId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLOGENTRY_H
|
#endif // BLOGENTRY_H
|
||||||
|
|||||||
@ -31,7 +31,7 @@ void blogsView::setBlogId(const QString &blogId)
|
|||||||
QJsonObject blogsView::readJsonFile(const QString title)
|
QJsonObject blogsView::readJsonFile(const QString title)
|
||||||
{
|
{
|
||||||
QFile file(title);
|
QFile file(title);
|
||||||
file.open( QIODevice::ReadOnly);
|
file.open(QIODevice::ReadWrite);
|
||||||
QByteArray bytes = file.readAll();
|
QByteArray bytes = file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||||
@ -61,6 +61,7 @@ void blogsView::createNewBlogEntry()
|
|||||||
qDebug() << "blogsView id: " << userId;
|
qDebug() << "blogsView id: " << userId;
|
||||||
blogEntry *e = new blogEntry();
|
blogEntry *e = new blogEntry();
|
||||||
e -> setUserId(userId);
|
e -> setUserId(userId);
|
||||||
|
e -> setBlogId(blogId);
|
||||||
ui -> blogsLayout -> addWidget(e);
|
ui -> blogsLayout -> addWidget(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,15 +66,15 @@ void login::loginUser(QJsonObject &users, QJsonObject &blogs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << "Current blog id: " << currentBlogId;
|
qDebug() << "Current blog id: " << currentBlogId;
|
||||||
loginSuccessful(id, "temp");
|
loginSuccessful(id, currentBlogId);
|
||||||
}else wrongPassword();
|
}else wrongPassword();
|
||||||
}
|
}else thisIDDoesNotExist();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject login::readUserJsonFile(const QString &filename)
|
QJsonObject login::readUserJsonFile(const QString &filename)
|
||||||
{
|
{
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
file.open( QIODevice::ReadOnly);
|
file.open(QIODevice::ReadWrite);
|
||||||
QByteArray bytes = file.readAll();
|
QByteArray bytes = file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) // class definition, constructor
|
MainWindow::MainWindow(QWidget *parent) // class definition, constructor
|
||||||
: QMainWindow(parent) // calls qmainwindow parent constructor we have,
|
: QMainWindow(parent) // calls qmainwindow parent constructor we have,
|
||||||
@ -24,8 +25,9 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
QJsonObject MainWindow::readJsonFile(const QString title)
|
QJsonObject MainWindow::readJsonFile(const QString title)
|
||||||
{
|
{
|
||||||
|
|
||||||
QFile file(title);
|
QFile file(title);
|
||||||
file.open( QIODevice::ReadOnly);
|
file.open(QIODevice::ReadWrite);
|
||||||
QByteArray bytes = file.readAll();
|
QByteArray bytes = file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||||
@ -34,6 +36,7 @@ QJsonObject MainWindow::readJsonFile(const QString title)
|
|||||||
|
|
||||||
void MainWindow::saveJsonFile(QJsonObject &users, const QString name) const
|
void MainWindow::saveJsonFile(QJsonObject &users, const QString name) const
|
||||||
{
|
{
|
||||||
|
|
||||||
QFile jsonFile(name);
|
QFile jsonFile(name);
|
||||||
QJsonDocument document;
|
QJsonDocument document;
|
||||||
document.setObject( users );
|
document.setObject( users );
|
||||||
@ -99,6 +102,8 @@ void MainWindow::saveRegisteredUser(QJsonObject &users, QJsonObject &blogs) cons
|
|||||||
blog["ownerId"] = id;
|
blog["ownerId"] = id;
|
||||||
blog["title"] = blogTitle;
|
blog["title"] = blogTitle;
|
||||||
blog["blogId"] = blogId;
|
blog["blogId"] = blogId;
|
||||||
|
QJsonArray items;
|
||||||
|
blog["items"] = items;
|
||||||
blogs.insert(blogId, blog);
|
blogs.insert(blogId, blog);
|
||||||
saveJsonFile(blogs, "blogs.json");
|
saveJsonFile(blogs, "blogs.json");
|
||||||
saveJsonFile(users, "user.json");
|
saveJsonFile(users, "user.json");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user