Skip to content

Commit

Permalink
Current version of Psi+ is 1.5.2053
Browse files Browse the repository at this point in the history
It is based on:
* psi: b8bf8dae
* plugins: 347230b
* psimedia: 478567e
* resources: fc4cfc1
  • Loading branch information
tehnick committed Oct 6, 2024
1 parent f6107fd commit 874f300
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 28 deletions.
10 changes: 7 additions & 3 deletions src/accountregdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ AccountRegDlg::~AccountRegDlg() { delete client_; }
void AccountRegDlg::done(int r)
{
if (ui_.busy->isActive()) {
int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the registration?"),
QMessageBox::Yes | QMessageBox::No);
if (n != 0)
auto btn
= QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the registration?"),
QMessageBox::Yes | QMessageBox::No);
if (btn != QMessageBox::Yes) {
return;
}
}
client_->close();
QDialog::done(r);
Expand Down Expand Up @@ -157,9 +159,11 @@ void AccountRegDlg::serverListReceived(const QStringList &list)
{
ui_.busy->stop();
unblock();
ui_.le_server->blockSignals(true);
ui_.le_server->clear();
ui_.le_server->addItems(list);
ui_.le_server->showPopup();
ui_.le_server->blockSignals(false);
}

void AccountRegDlg::serverListError(const QString &e)
Expand Down
78 changes: 54 additions & 24 deletions src/serverlistquerier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@

#include "serverlistquerier.h"

#ifdef XML_SERVER_LIST
#include <QDomDocument>
#include <QDomElement>
#include <QDomNodeList>
#else
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#endif
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
Expand All @@ -39,7 +45,7 @@
ServerListQuerier::ServerListQuerier(QObject *parent) : QObject(parent), redirectCount_(0)
{
http_ = new QNetworkAccessManager(this);
url_ = QUrl("https://xmpp.net/directory.php");
url_ = QUrl("https://data.xmpp.net/providers/v2/providers-A.json");
}

void ServerListQuerier::getList()
Expand Down Expand Up @@ -75,35 +81,59 @@ void ServerListQuerier::get_finished()
servers.push_back(jid);
}
}
#else
QStringList servers;
QString contents = QString::fromUtf8(reply->readAll());
int index = 0;
QRegularExpression re("data-original-title=\"([^\"]+)\"");
QRegularExpressionMatch match;
while ((index = contents.indexOf(re, index + 1, &match)) != -1) {
servers.append(match.captured(1));
}
#endif
emit listReceived(servers);
} else if (reply->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) {
if (redirectCount_ >= SERVERLIST_MAX_REDIRECT) {
emit error(tr("Maximum redirect count reached"));
return;
}
#else

url_ = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).value<QUrl>().resolved(url_);
if (url_.isValid()) {
QNetworkReply *newReply = http_->get(QNetworkRequest(url_));
connect(newReply, SIGNAL(finished()), SLOT(get_finished()));
++redirectCount_;
} else {
emit error(tr("Invalid redirect URL %1").arg(url_.toString()));
return;
if (auto r = parseJson(reply->readAll()); r) {
emit listReceived(*r);
}
#endif
} else {
emit error(tr("Unexpected HTTP status code: %1").arg(status));
}
}
reply->deleteLater();
}

std::optional<QStringList> ServerListQuerier::parseJson(const QByteArray &data)
{
QStringList jidList;
bool parsingErrorOccurred = false;

QJsonDocument jsonDoc = QJsonDocument::fromJson(data);
if (!jsonDoc.isArray()) {
emit error(tr("Failed to parse json."));
return {};
}

QJsonArray jsonArray = jsonDoc.array();

for (const QJsonValue &providerValue : jsonArray) {
if (!providerValue.isObject()) {
parsingErrorOccurred = true;
continue; // Skip if the item is not a valid object
}

QJsonObject providerObj = providerValue.toObject();
auto jidIt = providerObj.find("jid");

if (jidIt == providerObj.end() || !jidIt->isString()) {
parsingErrorOccurred = true;
continue; // Skip if "jid" is not found or is not a string
}

QString jid = jidIt->toString();
if (!jid.isEmpty()) {
jidList.append(jid);
} else {
parsingErrorOccurred = true; // Handle empty jid case
}
}

// Emit an error if the list is empty and there was a parsing error
if (jidList.isEmpty() && parsingErrorOccurred) {
emit error(tr("Failed to parse any valid server JIDs from %1.").arg(url_.toDisplayString()));
}

return jidList;
}
3 changes: 3 additions & 0 deletions src/serverlistquerier.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class ServerListQuerier : public QObject {
protected slots:
void get_finished();

private:
std::optional<QStringList> parseJson(const QByteArray &providers);

private:
QNetworkAccessManager *http_;
QUrl url_;
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.2052 (2024-09-30, 31774cb5)
1.5.2053 (2024-10-06, b8bf8dae)

0 comments on commit 874f300

Please sign in to comment.