mirror of
https://gitlab.com/niansa/qcommsy.git
synced 2025-03-06 20:53:33 +01:00
Added basic postView
This commit is contained in:
parent
62f7aa2fb6
commit
fbf52cf864
7 changed files with 179 additions and 29 deletions
|
@ -27,7 +27,8 @@ FORMS += \
|
||||||
info.ui \
|
info.ui \
|
||||||
login.ui \
|
login.ui \
|
||||||
offline.ui \
|
offline.ui \
|
||||||
overview.ui
|
overview.ui \
|
||||||
|
postView.ui
|
||||||
|
|
||||||
LIBS += -lcurlpp -lcurl
|
LIBS += -lcurlpp -lcurl
|
||||||
LIBS += -lfuse
|
LIBS += -lfuse
|
||||||
|
|
16
info.ui
16
info.ui
|
@ -51,6 +51,22 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="buildDateInfo">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>8</pointsize>
|
||||||
|
<italic>true</italic>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="backButton">
|
<widget class="QPushButton" name="backButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
@ -21,13 +21,13 @@ using json = nlohmann::json;
|
||||||
|
|
||||||
#include <gumbo.h>
|
#include <gumbo.h>
|
||||||
|
|
||||||
class invalidSIDError : public std::exception {};
|
class invalidSIDError {};
|
||||||
class invalidRoomError : public std::exception {};
|
class invalidRoomError {};
|
||||||
class invalidPostError : public std::exception {};
|
class invalidPostError {};
|
||||||
class connectionFailError : public std::exception {};
|
class connectionFailError {};
|
||||||
class parsingNoSuchIDError : public std::exception {};
|
class parsingNoSuchIDError {};
|
||||||
class parsingNoSuchTagError : public std::exception {};
|
class parsingNoSuchTagError {};
|
||||||
class descDownloadError : public std::exception {};
|
class descDownloadError {};
|
||||||
|
|
||||||
|
|
||||||
static std::string server_url;
|
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()
|
// If no nodes were found, panic()
|
||||||
throw parsingNoSuchIDError();
|
throw parsingNoSuchIDError();
|
||||||
return new GumboNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gumbo_search_by_tag(std::vector<GumboNode *> &elemvect, GumboNode* node, GumboTag searchedtag) {
|
void gumbo_search_by_tag(std::vector<GumboNode *> &elemvect, GumboNode* node, GumboTag searchedtag) {
|
||||||
|
@ -207,7 +206,6 @@ std::string gumbo_find_text_by_tag(GumboNode *node, GumboTag searchtag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
throw parsingNoSuchTagError();
|
throw parsingNoSuchTagError();
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#define libCommsyAuth_NAME "libcommsyauth"
|
#define libCommsyAuth_NAME "libcommsyauth"
|
||||||
#define libCommsyAuth_VERSION "0.2-alpha"
|
#define libCommsyAuth_VERSION "0.2-alpha"
|
||||||
|
|
||||||
class authFailureError : public std::exception {};
|
class authFailureError {};
|
||||||
|
|
||||||
|
|
||||||
class libCommsyAuth : public QObject {
|
class libCommsyAuth : public QObject {
|
||||||
|
|
2
login.ui
2
login.ui
|
@ -72,7 +72,7 @@
|
||||||
<set>Qt::ImhDigitsOnly</set>
|
<set>Qt::ImhDigitsOnly</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>6505986</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="maxLength">
|
<property name="maxLength">
|
||||||
<number>7</number>
|
<number>7</number>
|
||||||
|
|
60
main.cpp
60
main.cpp
|
@ -3,7 +3,7 @@
|
||||||
#include "ui_login.h"
|
#include "ui_login.h"
|
||||||
#include "ui_failure.h"
|
#include "ui_failure.h"
|
||||||
#include "ui_offline.h"
|
#include "ui_offline.h"
|
||||||
|
#include "ui_postView.h"
|
||||||
#include "libcommsy.hpp"
|
#include "libcommsy.hpp"
|
||||||
#include "libcommsyauth.hpp"
|
#include "libcommsyauth.hpp"
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
#define QCommsy_NAME "QCommsy"
|
#define QCommsy_NAME "QCommsy"
|
||||||
#define QCommsy_VERSION "0.2-alpha"
|
#define QCommsy_VERSION "0.2-alpha"
|
||||||
|
|
||||||
QSettings *settings;
|
static QSettings *settings;
|
||||||
|
|
||||||
|
|
||||||
class _UILoader {
|
class _UILoader {
|
||||||
|
@ -32,6 +32,10 @@ class _UILoader {
|
||||||
bool cacheInvalidate = true;
|
bool cacheInvalidate = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
_UILoader () {
|
||||||
|
auther = new libCommsyAuth();
|
||||||
|
}
|
||||||
|
|
||||||
void reconnect() {
|
void reconnect() {
|
||||||
// Destroy old connector
|
// Destroy old connector
|
||||||
if (connector != nullptr) {
|
if (connector != nullptr) {
|
||||||
|
@ -54,6 +58,7 @@ public:
|
||||||
void failureWindow(QMainWindow *w);
|
void failureWindow(QMainWindow *w);
|
||||||
void loginWindow(QMainWindow *w, const QString& failure = "");
|
void loginWindow(QMainWindow *w, const QString& failure = "");
|
||||||
void infoWindow(QMainWindow *w);
|
void infoWindow(QMainWindow *w);
|
||||||
|
void postViewWindow(QMainWindow *w, commsyPost *thispost, const QString& description);
|
||||||
void offlineWindow(QMainWindow *w);
|
void offlineWindow(QMainWindow *w);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,13 +73,12 @@ void _UILoader::infoWindow(QMainWindow *w) {
|
||||||
thisui->versionInfo->setText(
|
thisui->versionInfo->setText(
|
||||||
"<b>App frontend:</b> " QCommsy_NAME " version " QCommsy_VERSION "<br />"
|
"<b>App frontend:</b> " QCommsy_NAME " version " QCommsy_VERSION "<br />"
|
||||||
"<b>Authentication backend:</b> " libCommsyAuth_NAME " version " libCommsyAuth_VERSION "<br />"
|
"<b>Authentication backend:</b> " libCommsyAuth_NAME " version " libCommsyAuth_VERSION "<br />"
|
||||||
"<b>Scrapping backend:</b> " libCommsy_NAME " version " libCommsy_VERSION
|
"<b>Scrapping backend:</b> " libCommsy_NAME " version " libCommsy_VERSION "<br />"
|
||||||
);
|
);
|
||||||
|
thisui->buildDateInfo->setText(__DATE__ " " __TIME__);
|
||||||
|
|
||||||
// Add button handlers
|
// Add button handlers
|
||||||
w->connect(thisui->backButton, &QPushButton::pressed, [this, w] () {
|
w->connect(thisui->backButton, &QPushButton::pressed, [this, w] () { loginWindow(w); });
|
||||||
loginWindow(w);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _UILoader::failureWindow(QMainWindow *w) {
|
void _UILoader::failureWindow(QMainWindow *w) {
|
||||||
|
@ -99,7 +103,6 @@ void _UILoader::failureWindow(QMainWindow *w) {
|
||||||
|
|
||||||
void _UILoader::offlineWindow(QMainWindow *w) {
|
void _UILoader::offlineWindow(QMainWindow *w) {
|
||||||
Ui::offlineWindow *thisui = new Ui::offlineWindow;
|
Ui::offlineWindow *thisui = new Ui::offlineWindow;
|
||||||
QString reason;
|
|
||||||
|
|
||||||
// Show initial UI
|
// Show initial UI
|
||||||
thisui->setupUi(w);
|
thisui->setupUi(w);
|
||||||
|
@ -108,12 +111,25 @@ void _UILoader::offlineWindow(QMainWindow *w) {
|
||||||
w->connect(thisui->logoutButton, &QPushButton::pressed, [this, w] () { logout(); loginWindow(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) {
|
void _UILoader::loginWindow(QMainWindow *w, const QString& failure) {
|
||||||
Ui::loginWindow *thisui = new Ui::loginWindow;
|
Ui::loginWindow *thisui = new Ui::loginWindow;
|
||||||
|
|
||||||
// Create new auther
|
|
||||||
auther = new libCommsyAuth();
|
|
||||||
|
|
||||||
// Check if logged in already
|
// Check if logged in already
|
||||||
if (settings->contains("server_sid")) {
|
if (settings->contains("server_sid")) {
|
||||||
return overviewWindow(w);
|
return overviewWindow(w);
|
||||||
|
@ -127,7 +143,10 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) {
|
||||||
bool restoreForm = settings->value("server_save", false).toBool();
|
bool restoreForm = settings->value("server_save", false).toBool();
|
||||||
if (restoreForm) {
|
if (restoreForm) {
|
||||||
thisui->saveBox->setCheckState(Qt::Checked);
|
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
|
// 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());
|
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");
|
thisui->failureText->setText("Der angegebene Server existiert nicht");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Add button handlers
|
// Add button handlers
|
||||||
w->connect(thisui->loginButton, &QPushButton::pressed, [this, thisui, w] () {
|
w->connect(thisui->loginButton, &QPushButton::pressed, [this, thisui] () {
|
||||||
// Check input lines
|
// Check input lines
|
||||||
if (thisui->adressLine->text().isEmpty() or thisui->usernameLine->text().isEmpty() or thisui->roomLine->text().isEmpty() or thisui->passwordLine->text().isEmpty()) {
|
if (thisui->adressLine->text().isEmpty() or thisui->usernameLine->text().isEmpty() or thisui->roomLine->text().isEmpty() or thisui->passwordLine->text().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -169,9 +188,14 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save basic server credentials
|
// 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_url", thisui->adressLine->text());
|
||||||
settings->setValue("server_room", thisui->roomLine->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
|
// Connect
|
||||||
auther->connectionInit(thisui->adressLine->text());
|
auther->connectionInit(thisui->adressLine->text());
|
||||||
|
@ -214,8 +238,10 @@ void _UILoader::overviewWindow(QMainWindow *w, bool catchInvalidRoomError) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add button handlers
|
// Add button handlers
|
||||||
w->connect(thisui->postList, &QListWidget::activated, [this, thisui] (QModelIndex index) {
|
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)));
|
//QDesktopServices::openUrl(QUrl(settings->value("server_url").toString() + QString::fromStdString(connector->getPost(index.row())->url)));
|
||||||
|
auto postID = static_cast<unsigned long>(index.row());
|
||||||
|
postViewWindow(w, connector->getPost(postID), QString::fromStdString(*connector->getDescription(postID)));
|
||||||
});
|
});
|
||||||
|
|
||||||
w->connect(thisui->logoutButton, &QPushButton::pressed, [this, w] () { logout(); loginWindow(w); });
|
w->connect(thisui->logoutButton, &QPushButton::pressed, [this, w] () { logout(); loginWindow(w); });
|
||||||
|
|
109
postView.ui
Normal file
109
postView.ui
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>postViewWindow</class>
|
||||||
|
<widget class="QMainWindow" name="postViewWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>323</width>
|
||||||
|
<height>489</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>QCommsy</string>
|
||||||
|
</property>
|
||||||
|
<property name="documentMode">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>303</width>
|
||||||
|
<height>438</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="titleText">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>16</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Title</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="metaText">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<italic>true</italic>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Meta</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="descriptionText">
|
||||||
|
<property name="text">
|
||||||
|
<string>description</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="fileListWidget"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="filesInfo">
|
||||||
|
<property name="text">
|
||||||
|
<string>x Dateien</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="backButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Zurück</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Add table
Reference in a new issue