diff --git a/libcommsy.hpp b/libcommsy.hpp index 9bfed51..ce6622e 100644 --- a/libcommsy.hpp +++ b/libcommsy.hpp @@ -321,11 +321,12 @@ struct commsyPost { #define libCommsy_NAME "libcommsy" -#define libCommsy_VERSION "1.0-stable" +#define libCommsy_VERSION "1.1-stable" class libCommsy { public: std::vector posts; unsigned long numposts; + std::string lastID; bool postExists(unsigned long postID) { return postID < numposts; @@ -353,22 +354,18 @@ public: return &thispost->description; } - libCommsy(const std::string& _server_url, const std::string& _server_sid, const std::string& _room) { + libCommsy(const std::string& _server_url, const std::string& _server_sid, const std::string& _room, const std::string start_id = "", const unsigned long max_posts = 0) { // Define required variables server_url = _server_url; server_sid = _server_sid; room = _room; - std::string lastID; + lastID = start_id; std::stringstream httpcontent; GumboOutput *document; long statuscode; numposts = 0; - // Make sure the server_url doesn't end with / - if (*(server_url.end() - 1) == '/') { - server_url.pop_back(); - } - + // Loop until all or max_posts posts are fetched while (1) { // Check connection and download feed try { @@ -422,6 +419,11 @@ public: numposts++; // Get lastID lastID = posts.back().id; + // Check if maximum amount of posts to load was exceeded + if (numposts == max_posts) { + // Stop loading more posts + break; + } } } } diff --git a/libcommsyauth.hpp b/libcommsyauth.hpp index dee80b2..bc36393 100644 --- a/libcommsyauth.hpp +++ b/libcommsyauth.hpp @@ -10,7 +10,7 @@ #include #define libCommsyAuth_NAME "libcommsyauth" -#define libCommsyAuth_VERSION "0.1-alpha" +#define libCommsyAuth_VERSION "0.2-alpha" class authFailureError : public std::exception {}; @@ -21,6 +21,7 @@ class libCommsyAuth : public QObject { public: Q_SIGNALS: void connectionDone(QNetworkReply *r); + void connectionNotfound(QNetworkReply *r); void authDone(QNetworkReply *r); public: @@ -33,6 +34,7 @@ public: mNetManAuth = new QNetworkAccessManager(this); mNetReq = new QNetworkRequest(); connect(mNetManTestconn, &QNetworkAccessManager::finished, this, &libCommsyAuth::connectionDone); + //connect(mNetManTestconn, &QNetworkReply::HostNotFoundError, this, &libCommsyAuth::connectionNotfound); connect(mNetManAuth, &QNetworkAccessManager::finished, this, &libCommsyAuth::authDone); } diff --git a/main.cpp b/main.cpp index f8d1a1b..48673d8 100644 --- a/main.cpp +++ b/main.cpp @@ -21,7 +21,7 @@ #include #define QCommsy_NAME "QCommsy" -#define QCommsy_VERSION "0.1-alpha" +#define QCommsy_VERSION "0.2-alpha" QSettings *settings; @@ -148,8 +148,10 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) { } }); w->connect(auther, &libCommsyAuth::connectionDone, [this, thisui, w] (QNetworkReply *netReply) { - QString authUrl = auther->getAuthUrl(netReply); - auther->sendAuth(authUrl, 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 *) { + thisui->failureText->setText("Der angegebene Server existiert nicht"); }); @@ -160,6 +162,11 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) { return; } + // Make sure the adressLine doesn't end with / + if (thisui->adressLine->text().endsWith("/")) { + thisui->adressLine->backspace(); + } + // Save basic server credentials settings->setValue("server_save", thisui->saveBox->checkState() == Qt::Checked); settings->setValue("server_url", thisui->adressLine->text());