Mercurial > minori
comparison src/services/anilist.cpp @ 36:2743011a6042
*: mass update
formatted all source files, converted ALL instances of setStyleSheet() to
palettes and fonts (stylesheets suck), and I changed the clang-format file because
it wasn't working on my laptop for some reason.
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 21 Sep 2023 15:17:47 -0400 |
parents | cde8f67a7c7d |
children | 619cbd6e69f9 |
comparison
equal
deleted
inserted
replaced
35:329b7921a6be | 36:2743011a6042 |
---|---|
12 #include <QMessageBox> | 12 #include <QMessageBox> |
13 #include <QUrl> | 13 #include <QUrl> |
14 #include <chrono> | 14 #include <chrono> |
15 #include <curl/curl.h> | 15 #include <curl/curl.h> |
16 #include <exception> | 16 #include <exception> |
17 #include <format> | |
18 #define CLIENT_ID "13706" | 17 #define CLIENT_ID "13706" |
19 | 18 |
20 using nlohmann::literals::operator"" _json_pointer; | 19 using nlohmann::literals::operator"" _json_pointer; |
21 | 20 |
22 namespace Services::AniList { | 21 namespace Services::AniList { |
23 | 22 |
24 class Account { | 23 class Account { |
25 public: | 24 public: |
26 std::string Username() const { return session.config.anilist.username; } | 25 std::string Username() const { return session.config.anilist.username; } |
27 void SetUsername(std::string const& username) { | 26 void SetUsername(std::string const& username) { session.config.anilist.username = username; } |
28 session.config.anilist.username = username; | |
29 } | |
30 | 27 |
31 int UserId() const { return session.config.anilist.user_id; } | 28 int UserId() const { return session.config.anilist.user_id; } |
32 void SetUserId(const int id) { session.config.anilist.user_id = id; } | 29 void SetUserId(const int id) { session.config.anilist.user_id = id; } |
33 | 30 |
34 std::string AuthToken() const { return session.config.anilist.auth_token; } | 31 std::string AuthToken() const { return session.config.anilist.auth_token; } |
35 void SetAuthToken(std::string const& auth_token) { | 32 void SetAuthToken(std::string const& auth_token) { session.config.anilist.auth_token = auth_token; } |
36 session.config.anilist.auth_token = auth_token; | |
37 } | |
38 | 33 |
39 bool Authenticated() const { return !AuthToken().empty(); } | 34 bool Authenticated() const { return !AuthToken().empty(); } |
40 }; | 35 }; |
41 | 36 |
42 static Account account; | 37 static Account account; |
66 CURLcode res = curl_easy_perform(curl); | 61 CURLcode res = curl_easy_perform(curl); |
67 curl_slist_free_all(list); | 62 curl_slist_free_all(list); |
68 curl_easy_cleanup(curl); | 63 curl_easy_cleanup(curl); |
69 if (res != CURLE_OK) { | 64 if (res != CURLE_OK) { |
70 QMessageBox box(QMessageBox::Icon::Critical, "", | 65 QMessageBox box(QMessageBox::Icon::Critical, "", |
71 QString("curl_easy_perform(curl) failed!: ") + | 66 QString("curl_easy_perform(curl) failed!: ") + QString(curl_easy_strerror(res))); |
72 QString(curl_easy_strerror(res))); | |
73 box.exec(); | 67 box.exec(); |
74 return ""; | 68 return ""; |
75 } | 69 } |
76 return userdata; | 70 return userdata; |
77 } | 71 } |
315 return account.UserId(); | 309 return account.UserId(); |
316 } | 310 } |
317 | 311 |
318 int AuthorizeUser() { | 312 int AuthorizeUser() { |
319 /* Prompt for PIN */ | 313 /* Prompt for PIN */ |
320 QDesktopServices::openUrl(QUrl("https://anilist.co/api/v2/oauth/authorize?client_id=" CLIENT_ID | 314 QDesktopServices::openUrl( |
321 "&response_type=token")); | 315 QUrl("https://anilist.co/api/v2/oauth/authorize?client_id=" CLIENT_ID "&response_type=token")); |
322 bool ok; | 316 bool ok; |
323 QString token = QInputDialog::getText( | 317 QString token = QInputDialog::getText( |
324 0, "Credentials needed!", | 318 0, "Credentials needed!", "Please enter the code given to you after logging in to AniList:", QLineEdit::Normal, |
325 "Please enter the code given to you after logging in to AniList:", QLineEdit::Normal, "", | 319 "", &ok); |
326 &ok); | |
327 if (ok && !token.isEmpty()) | 320 if (ok && !token.isEmpty()) |
328 account.SetAuthToken(token.toStdString()); | 321 account.SetAuthToken(token.toStdString()); |
329 else // fail | 322 else // fail |
330 return 0; | 323 return 0; |
331 const std::string query = "query {\n" | 324 const std::string query = "query {\n" |