diff --git a/QCommsy.pro b/QCommsy.pro index 246d72b..b7d4ef1 100644 --- a/QCommsy.pro +++ b/QCommsy.pro @@ -32,8 +32,10 @@ FORMS += \ overview.ui \ postView.ui -LIBS += -lcurlpp -lcurl -LIBS += -lgumbo +LIBS += -lcurlpp -lcurl \ + -lgumbo + +DEFINES += GIT_CURRENT_SHA1="\\\"$(shell git -C \""$$_PRO_FILE_PWD_"\" describe)\\\"" # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/main.cpp b/main.cpp index 1f81445..6b02c58 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -121,6 +122,8 @@ void _UILoader::infoWindow() { "App frontend: " QCommsy_NAME " version " QCommsy_VERSION "
" "Authentication backend: " libCommsyAuth_NAME " version " libCommsyAuth_VERSION "
" "Scrapping backend: " libCommsy_NAME " version " libCommsy_VERSION "
" + "Git version: " GIT_CURRENT_SHA1 "
" + "Build ID: " + QString::number(std::hash{}(__DATE__ __TIME__)) + "
" ); thisui->buildDateInfo->setText( "Build date:\n" diff --git a/ui_loader.hpp b/ui_loader.hpp new file mode 100644 index 0000000..18ce955 --- /dev/null +++ b/ui_loader.hpp @@ -0,0 +1,70 @@ +class _UILoader { + libCommsy *connector = nullptr; + libCommsyAuth *auther = nullptr; + bool cacheInvalidate = true; + +public: + void failureWindow(); + void overviewWindow(bool catchInvalidRoomError = true); + void loginWindow(const QString& failure = ""); + void infoWindow(); + void postViewWindow(commsyPost *thispost, QString description); + void offlineWindow(); + + _UILoader () { + auther = new libCommsyAuth(); + } + + void reconnect() { + // Destroy old connector + if (connector != nullptr) { + if (not cacheInvalidate) { + return; + } + delete connector; + connector = nullptr; + } + cacheInvalidate = false; + // Connect to commsy + connector = new libCommsy(settings->value("server_url").toString().toStdString(), settings->value("server_sid").toString().toStdString(), settings->value("server_room").toString().toStdString()); + } + + void logout() { + settings->remove("server_sid"); + } + + void downloadAndOpenFile(QNetworkRequest mNetReq, const QString& filename) { + auto mNetMan = new QNetworkAccessManager(); + + // Set SID in request so we're authenticated TODO: think about a cleaner way + mNetReq.setRawHeader("Cookie", "SID=" + settings->value("server_sid").toString().toUtf8()); + + // Connect to downloading + w->connect(mNetMan, &QNetworkAccessManager::finished, [this, mNetMan, filename] (QNetworkReply *mNetReply) { + // Save and open downloaded file + { + // Initialise + QString destPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + '/' + filename; + QFile destFile(destPath); + + // Write downloaded data to file + if (!destFile.open(QIODevice::WriteOnly)) { + return failureWindow(); + } + destFile.write(mNetReply->readAll()); + destFile.close(); + + // Open file in some application + //QDesktopServices::openUrl(destPath); + QDesktopServices::openUrl(QUrl::fromLocalFile(destPath)); + } + + // Clean up + mNetMan->deleteLater(); + }); + + // Start download + mNetMan->get(mNetReq); + } + +};