mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 14:43:08 +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",
|
||||
"ownerId": "SupertajnehasloxDDDDD",
|
||||
"title": "1"
|
||||
},
|
||||
"5": {
|
||||
"blogId": "5",
|
||||
"ownerId": "6",
|
||||
"title": "6"
|
||||
},
|
||||
"6": {
|
||||
"blogId": "6",
|
||||
"ownerId": "7",
|
||||
"title": "5"
|
||||
},
|
||||
"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"
|
||||
"": {
|
||||
"blogId": "",
|
||||
"items": [
|
||||
{
|
||||
"content": "",
|
||||
"datetime": "01:05:33 Wed Apr 6 2022",
|
||||
"title": "Title"
|
||||
},
|
||||
{
|
||||
"content": "notempty",
|
||||
"datetime": "01:05:44 Wed Apr 6 2022",
|
||||
"title": "anotherTitle"
|
||||
}
|
||||
],
|
||||
"ownerId": "1",
|
||||
"title": ""
|
||||
}
|
||||
}
|
||||
|
||||
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">
|
||||
<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>
|
||||
</RCC>
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
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,
|
||||
0x3c,
|
||||
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,
|
||||
// :/i18n/lab1_pl_PL.qm
|
||||
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": {
|
||||
"id": "1",
|
||||
"mail": "1",
|
||||
"password": "SupertajnehasloxDDDDD"
|
||||
},
|
||||
"2": {
|
||||
"id": "2",
|
||||
"mail": "",
|
||||
"password": ""
|
||||
},
|
||||
"5": {
|
||||
"email": "5",
|
||||
"email": "",
|
||||
"password": "",
|
||||
"userId": "5"
|
||||
},
|
||||
"6": {
|
||||
"email": "5",
|
||||
"password": "",
|
||||
"userId": "6"
|
||||
},
|
||||
"7": {
|
||||
"email": "5",
|
||||
"password": "5",
|
||||
"userId": "7"
|
||||
},
|
||||
"SupertajnehasloxDDDDD": {
|
||||
"email": "1",
|
||||
"password": "1",
|
||||
"userId": "SupertajnehasloxDDDDD"
|
||||
"userId": "1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
|
||||
blogEntry::blogEntry(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
@ -30,10 +31,16 @@ void blogEntry::setUserId(const QString &userId)
|
||||
ui -> ownerID -> setText("Owner ID: " + userId);
|
||||
}
|
||||
|
||||
void blogEntry::setBlogId(const QString &blogId)
|
||||
{
|
||||
this->blogId = blogId;
|
||||
}
|
||||
|
||||
|
||||
QJsonObject blogEntry::readJsonFile(const QString title)
|
||||
{
|
||||
QFile file(title);
|
||||
file.open( QIODevice::ReadOnly);
|
||||
file.open( QIODevice::ReadWrite);
|
||||
QByteArray bytes = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||
@ -59,18 +66,18 @@ void blogEntry::saveEntry()
|
||||
|
||||
ui -> textEdit -> setReadOnly(true);
|
||||
ui -> lineEdit -> setReadOnly(true);
|
||||
QJsonObject blogEntry;
|
||||
blogEntry["content"] = ui -> textEdit -> toPlainText();
|
||||
QJsonObject blogsFile = readJsonFile("blogs.json");
|
||||
QJsonObject blogEntryJson = blogsFile[blogId].toObject();
|
||||
QJsonObject entry;
|
||||
entry["title"] = ui -> lineEdit -> text();
|
||||
QString Time = QTime::currentTime().toString();
|
||||
QString Date = QDate::currentDate().toString();
|
||||
blogEntry["datetime"] = Time + " " + Date;
|
||||
blogEntry["title"] = ui -> lineEdit -> text();
|
||||
QJsonObject blogsFile = readJsonFile("blogs.json");
|
||||
QJsonObject blogEntryJson;
|
||||
blogEntryJson["title"] = ui -> lineEdit -> text();
|
||||
blogEntryJson["datetime"] = Time + " " + Date;
|
||||
blogEntryJson["content"] = ui -> textEdit -> toPlainText();
|
||||
blogsFile.insert(ui -> lineEdit -> text(), blogEntryJson);
|
||||
entry["datetime"] = Time + " " + Date;
|
||||
entry["content"] = ui -> textEdit -> toPlainText();
|
||||
QJsonArray items = blogEntryJson["items"].toArray();
|
||||
items.append(entry);
|
||||
blogEntryJson.insert("items", items);
|
||||
blogsFile.insert(blogId, blogEntryJson);
|
||||
saveJsonFile(blogsFile, "blogs.json");
|
||||
|
||||
}
|
||||
|
||||
@ -18,15 +18,18 @@ public:
|
||||
explicit blogEntry(QWidget *parent = nullptr);
|
||||
~blogEntry();
|
||||
void setUserId(const QString &userId);
|
||||
void setBlogId(const QString &blogId);
|
||||
|
||||
private slots:
|
||||
void on_saveEntry_clicked();
|
||||
void saveEntry();
|
||||
QJsonObject readJsonFile(const QString title);
|
||||
void saveJsonFile(QJsonObject &users, const QString name) const;
|
||||
|
||||
private:
|
||||
Ui::blogEntry *ui;
|
||||
QString userId;
|
||||
QString blogId;
|
||||
};
|
||||
|
||||
#endif // BLOGENTRY_H
|
||||
|
||||
@ -31,7 +31,7 @@ void blogsView::setBlogId(const QString &blogId)
|
||||
QJsonObject blogsView::readJsonFile(const QString title)
|
||||
{
|
||||
QFile file(title);
|
||||
file.open( QIODevice::ReadOnly);
|
||||
file.open(QIODevice::ReadWrite);
|
||||
QByteArray bytes = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||
@ -61,6 +61,7 @@ void blogsView::createNewBlogEntry()
|
||||
qDebug() << "blogsView id: " << userId;
|
||||
blogEntry *e = new blogEntry();
|
||||
e -> setUserId(userId);
|
||||
e -> setBlogId(blogId);
|
||||
ui -> blogsLayout -> addWidget(e);
|
||||
}
|
||||
|
||||
|
||||
@ -66,15 +66,15 @@ void login::loginUser(QJsonObject &users, QJsonObject &blogs)
|
||||
}
|
||||
}
|
||||
qDebug() << "Current blog id: " << currentBlogId;
|
||||
loginSuccessful(id, "temp");
|
||||
loginSuccessful(id, currentBlogId);
|
||||
}else wrongPassword();
|
||||
}
|
||||
}else thisIDDoesNotExist();
|
||||
}
|
||||
|
||||
QJsonObject login::readUserJsonFile(const QString &filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
file.open( QIODevice::ReadOnly);
|
||||
file.open(QIODevice::ReadWrite);
|
||||
QByteArray bytes = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QTextStream>
|
||||
#include <QJsonArray>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) // class definition, constructor
|
||||
: QMainWindow(parent) // calls qmainwindow parent constructor we have,
|
||||
@ -24,8 +25,9 @@ MainWindow::~MainWindow()
|
||||
|
||||
QJsonObject MainWindow::readJsonFile(const QString title)
|
||||
{
|
||||
|
||||
QFile file(title);
|
||||
file.open( QIODevice::ReadOnly);
|
||||
file.open(QIODevice::ReadWrite);
|
||||
QByteArray bytes = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||
@ -34,6 +36,7 @@ QJsonObject MainWindow::readJsonFile(const QString title)
|
||||
|
||||
void MainWindow::saveJsonFile(QJsonObject &users, const QString name) const
|
||||
{
|
||||
|
||||
QFile jsonFile(name);
|
||||
QJsonDocument document;
|
||||
document.setObject( users );
|
||||
@ -99,6 +102,8 @@ void MainWindow::saveRegisteredUser(QJsonObject &users, QJsonObject &blogs) cons
|
||||
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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user