1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2025-09-04 01:42:44 +00:00

QuickConnect: init

This adds a page in the settings page that allows the user to enter a
quick connect code to allow another device to log in.
This commit is contained in:
Chris Josten 2024-01-02 19:51:27 +01:00
parent 13786f01c9
commit a66434afa8
10 changed files with 242 additions and 3 deletions

View file

@ -209,6 +209,14 @@ signals:
void supportedCommandsChanged();
void onlineChanged();
/**
* @brief Emitted after submitQuickConnectCode succeeded
*/
void quickConnectAccepted();
/**
* @brief Emitted after submitQuickConnectCode failed
*/
void quickConnectRejected();
/**
* @brief onUserDataChanged Emitted when the user data of an item is changed on the server.
@ -233,6 +241,7 @@ public slots:
*/
void setupConnection();
void authenticate(QString username, QString password, bool storeCredentials = false);
void submitQuickConnectCode(const QString &code);
/**
* @brief Logs the user out and clears the session.

View file

@ -256,6 +256,27 @@ public:
}
};
// Specialisation for endpoints that return "true" or "false" as response.
template<typename P>
class HttpLoaderBase<bool, P> : public Loader<bool, P> {
public:
explicit HttpLoaderBase(Jellyfin::ApiClient *apiClient)
: Loader<bool, P> (apiClient) {}
typename Loader<bool, P>::ResultType parseResponse(int statusCode, QByteArray response) {
QString text = QString::fromUtf8(response);
if (text == QStringLiteral("true")) {
return true;
} else if (text == QStringLiteral("false")) {
return false;
} else {
this->stopWithError(QStringLiteral("Could not parse boolean response: %1").arg(text));
return std::nullopt;
}
}
};
/**
* Implementation of Loader that loads Items over HTTP

View file

@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <QSharedPointer>
#include "JellyfinQt/dto/clientcapabilitiesdto.h"
#include "JellyfinQt/loader/http/quickconnect.h"
#include "JellyfinQt/support/jsonconv.h"
#include "JellyfinQt/viewmodel/settings.h"
#include "JellyfinQt/websocket.h"
@ -428,6 +429,26 @@ void ApiClient::authenticate(QString username, QString password, bool storeCrede
setDefaultErrorHandler(rep);
}
void ApiClient::submitQuickConnectCode(const QString &code) {
using QQAuthorizeLoader = Loader::HTTP::AuthorizeLoader;
Loader::AuthorizeParams params;
params.setCode(code);
QQAuthorizeLoader *loader = new QQAuthorizeLoader(this);
loader->setParameters(params);
loader->load();
loader->connect(loader, &QQAuthorizeLoader::error, this, [this, loader](QString message) {
qDebug() << "QQ error: " << message;
emit this->quickConnectRejected();
loader->deleteLater();
});
loader->connect(loader, &QQAuthorizeLoader::ready, this, [this, loader]() {
emit this->quickConnectAccepted();
loader->deleteLater();
});
}
void ApiClient::deleteSession() {
QNetworkReply *rep = post("/Sessions/Logout");
connect(rep, &QNetworkReply::finished, this, [rep, this] {