From fbf52cf864fe5b74e2c16223e6b2ba6afee8c1db Mon Sep 17 00:00:00 2001 From: niansa Date: Tue, 18 Aug 2020 18:49:59 +0200 Subject: [PATCH] Added basic postView --- QCommsy.pro | 3 +- info.ui | 16 +++++++ libcommsy.hpp | 16 +++---- libcommsyauth.hpp | 2 +- login.ui | 2 +- main.cpp | 60 +++++++++++++++++-------- postView.ui | 109 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 179 insertions(+), 29 deletions(-) create mode 100644 postView.ui diff --git a/QCommsy.pro b/QCommsy.pro index fd4aa17..cf06f30 100644 --- a/QCommsy.pro +++ b/QCommsy.pro @@ -27,7 +27,8 @@ FORMS += \ info.ui \ login.ui \ offline.ui \ - overview.ui + overview.ui \ + postView.ui LIBS += -lcurlpp -lcurl LIBS += -lfuse diff --git a/info.ui b/info.ui index e324507..65207a8 100644 --- a/info.ui +++ b/info.ui @@ -51,6 +51,22 @@ + + + + + 8 + true + + + + + + + Qt::AlignCenter + + + diff --git a/libcommsy.hpp b/libcommsy.hpp index 85a929e..d57e329 100644 --- a/libcommsy.hpp +++ b/libcommsy.hpp @@ -21,13 +21,13 @@ using json = nlohmann::json; #include -class invalidSIDError : public std::exception {}; -class invalidRoomError : public std::exception {}; -class invalidPostError : public std::exception {}; -class connectionFailError : public std::exception {}; -class parsingNoSuchIDError : public std::exception {}; -class parsingNoSuchTagError : public std::exception {}; -class descDownloadError : public std::exception {}; +class invalidSIDError {}; +class invalidRoomError {}; +class invalidPostError {}; +class connectionFailError {}; +class parsingNoSuchIDError {}; +class parsingNoSuchTagError {}; +class descDownloadError {}; static std::string server_url; @@ -118,7 +118,6 @@ GumboNode *gumbo_search_by_id(GumboNode* node, std::string searchword, GumboTag } // If no nodes were found, panic() throw parsingNoSuchIDError(); - return new GumboNode; } void gumbo_search_by_tag(std::vector &elemvect, GumboNode* node, GumboTag searchedtag) { @@ -207,7 +206,6 @@ std::string gumbo_find_text_by_tag(GumboNode *node, GumboTag searchtag) { } throw parsingNoSuchTagError(); - return ""; } diff --git a/libcommsyauth.hpp b/libcommsyauth.hpp index bc36393..a2e0f53 100644 --- a/libcommsyauth.hpp +++ b/libcommsyauth.hpp @@ -12,7 +12,7 @@ #define libCommsyAuth_NAME "libcommsyauth" #define libCommsyAuth_VERSION "0.2-alpha" -class authFailureError : public std::exception {}; +class authFailureError {}; class libCommsyAuth : public QObject { diff --git a/login.ui b/login.ui index 331cd37..bd47ff6 100644 --- a/login.ui +++ b/login.ui @@ -72,7 +72,7 @@ Qt::ImhDigitsOnly - 6505986 + 7 diff --git a/main.cpp b/main.cpp index ebeab59..9ec132c 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,7 @@ #include "ui_login.h" #include "ui_failure.h" #include "ui_offline.h" - +#include "ui_postView.h" #include "libcommsy.hpp" #include "libcommsyauth.hpp" @@ -23,7 +23,7 @@ #define QCommsy_NAME "QCommsy" #define QCommsy_VERSION "0.2-alpha" -QSettings *settings; +static QSettings *settings; class _UILoader { @@ -32,6 +32,10 @@ class _UILoader { bool cacheInvalidate = true; public: + _UILoader () { + auther = new libCommsyAuth(); + } + void reconnect() { // Destroy old connector if (connector != nullptr) { @@ -54,6 +58,7 @@ public: void failureWindow(QMainWindow *w); void loginWindow(QMainWindow *w, const QString& failure = ""); void infoWindow(QMainWindow *w); + void postViewWindow(QMainWindow *w, commsyPost *thispost, const QString& description); void offlineWindow(QMainWindow *w); }; @@ -68,13 +73,12 @@ void _UILoader::infoWindow(QMainWindow *w) { thisui->versionInfo->setText( "App frontend: " QCommsy_NAME " version " QCommsy_VERSION "
" "Authentication backend: " libCommsyAuth_NAME " version " libCommsyAuth_VERSION "
" - "Scrapping backend: " libCommsy_NAME " version " libCommsy_VERSION + "Scrapping backend: " libCommsy_NAME " version " libCommsy_VERSION "
" ); + thisui->buildDateInfo->setText(__DATE__ " " __TIME__); // Add button handlers - w->connect(thisui->backButton, &QPushButton::pressed, [this, w] () { - loginWindow(w); - }); + w->connect(thisui->backButton, &QPushButton::pressed, [this, w] () { loginWindow(w); }); } void _UILoader::failureWindow(QMainWindow *w) { @@ -99,7 +103,6 @@ void _UILoader::failureWindow(QMainWindow *w) { void _UILoader::offlineWindow(QMainWindow *w) { Ui::offlineWindow *thisui = new Ui::offlineWindow; - QString reason; // Show initial UI thisui->setupUi(w); @@ -108,12 +111,25 @@ void _UILoader::offlineWindow(QMainWindow *w) { w->connect(thisui->logoutButton, &QPushButton::pressed, [this, w] () { logout(); loginWindow(w); }); } +void _UILoader::postViewWindow(QMainWindow *w, commsyPost *thispost, const QString& description) { + Ui::postViewWindow *thisui = new Ui::postViewWindow; + + // Show initial UI + thisui->setupUi(w); + w->show(); + + // Update informations + thisui->titleText->setText(QString::fromStdString(thispost->name)); + thisui->metaText->setText(QString::fromStdString(thispost->meta)); + thisui->descriptionText->setText(description); + + // Add button handlers + w->connect(thisui->backButton, &QPushButton::pressed, [this, w] () { loginWindow(w); }); +} + void _UILoader::loginWindow(QMainWindow *w, const QString& failure) { Ui::loginWindow *thisui = new Ui::loginWindow; - // Create new auther - auther = new libCommsyAuth(); - // Check if logged in already if (settings->contains("server_sid")) { return overviewWindow(w); @@ -127,7 +143,10 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) { bool restoreForm = settings->value("server_save", false).toBool(); if (restoreForm) { thisui->saveBox->setCheckState(Qt::Checked); - //... TODO + thisui->adressLine->setText(settings->value("server_url", thisui->adressLine->text()).toString()); + thisui->roomLine->setText(settings->value("server_room", "").toString()); + thisui->usernameLine->setText(settings->value("server_username", "").toString()); + thisui->passwordLine->setText(settings->value("server_password", "").toString()); } // Set failure text @@ -148,16 +167,16 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) { } }); - w->connect(auther, &libCommsyAuth::connectionDone, [this, thisui, w] (QNetworkReply *netReply) { // Finished test connection + w->connect(auther, &libCommsyAuth::connectionDone, [this, thisui] (QNetworkReply *netReply) { // Finished test connection auther->sendAuth(auther->getAuthUrl(netReply), thisui->usernameLine->text(), thisui->passwordLine->text()); }); - w->connect(auther, &libCommsyAuth::connectionNotfound, [this, thisui, w] (QNetworkReply *) { // "server not found" during test connection + w->connect(auther, &libCommsyAuth::connectionNotfound, [thisui] (QNetworkReply *) { // "server not found" during test connection thisui->failureText->setText("Der angegebene Server existiert nicht"); }); // Add button handlers - w->connect(thisui->loginButton, &QPushButton::pressed, [this, thisui, w] () { + w->connect(thisui->loginButton, &QPushButton::pressed, [this, thisui] () { // Check input lines if (thisui->adressLine->text().isEmpty() or thisui->usernameLine->text().isEmpty() or thisui->roomLine->text().isEmpty() or thisui->passwordLine->text().isEmpty()) { return; @@ -169,9 +188,14 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) { } // Save basic server credentials - settings->setValue("server_save", thisui->saveBox->checkState() == Qt::Checked); + bool saveAllData = thisui->saveBox->checkState() == Qt::Checked; + settings->setValue("server_save", saveAllData); settings->setValue("server_url", thisui->adressLine->text()); settings->setValue("server_room", thisui->roomLine->text()); + if (saveAllData) { + settings->setValue("server_username", thisui->usernameLine->text()); + settings->setValue("server_password", thisui->passwordLine->text()); + } // Connect auther->connectionInit(thisui->adressLine->text()); @@ -214,8 +238,10 @@ void _UILoader::overviewWindow(QMainWindow *w, bool catchInvalidRoomError) { } // Add button handlers - w->connect(thisui->postList, &QListWidget::activated, [this, thisui] (QModelIndex index) { - QDesktopServices::openUrl(QUrl(settings->value("server_url").toString() + QString::fromStdString(connector->getPost(index.row())->url))); + w->connect(thisui->postList, &QListWidget::activated, [this, w] (QModelIndex index) { + //QDesktopServices::openUrl(QUrl(settings->value("server_url").toString() + QString::fromStdString(connector->getPost(index.row())->url))); + auto postID = static_cast(index.row()); + postViewWindow(w, connector->getPost(postID), QString::fromStdString(*connector->getDescription(postID))); }); w->connect(thisui->logoutButton, &QPushButton::pressed, [this, w] () { logout(); loginWindow(w); }); diff --git a/postView.ui b/postView.ui new file mode 100644 index 0000000..fa18d8d --- /dev/null +++ b/postView.ui @@ -0,0 +1,109 @@ + + + postViewWindow + + + + 0 + 0 + 323 + 489 + + + + QCommsy + + + true + + + + + + + true + + + + + 0 + 0 + 303 + 438 + + + + + + + + 16 + + + + Title + + + true + + + + + + + + true + + + + Meta + + + true + + + + + + + Qt::Horizontal + + + + + + + description + + + true + + + + + + + + + + x Dateien + + + + + + + + + + + Zurück + + + + + + + + +