aboutsummaryrefslogtreecommitdiffstats
path: root/src/settingsdialog.cpp
diff options
context:
space:
mode:
authorConfuSomu2023-08-24 18:43:15 -0400
committerConfuSomu2023-08-24 19:35:58 -0400
commit9c60bc8ce4a0990c228d2cd746791b88c41532b8 (patch)
treef6e7d56422f95f8202980a87866f0d798c199f47 /src/settingsdialog.cpp
parente625d3fcca7c735ed98570bc1acbcaa840541e61 (diff)
downloadActorViewer-9c60bc8ce4a0990c228d2cd746791b88c41532b8.tar
ActorViewer-9c60bc8ce4a0990c228d2cd746791b88c41532b8.tar.gz
ActorViewer-9c60bc8ce4a0990c228d2cd746791b88c41532b8.zip
Implement basic Mastodon API support
Implement support for OAuth 2.0 code entry, which is then used to retrieve a token that is stored in the application's settings. Authentification allowed the implementation of a basic "get post from URL" feature mostly made for testing.
Diffstat (limited to 'src/settingsdialog.cpp')
-rw-r--r--src/settingsdialog.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp
index 213859a..051091f 100644
--- a/src/settingsdialog.cpp
+++ b/src/settingsdialog.cpp
@@ -1,6 +1,14 @@
#include "settingsdialog.h"
+#include "src/net/instance.h"
+#include "src/settings_interface.h"
+
#include <QPushButton>
#include <QDialogButtonBox>
+#include <QDesktopServices>
+#include <QUrl>
+#include <QMessageBox>
+#include <QInputDialog>
+#include <qnamespace.h>
SettingsDialog::SettingsDialog(QWidget* parent)
: QDialog(parent, Qt::Dialog), ui(new Ui::SettingsDialog)
@@ -64,7 +72,24 @@ void SettingsDialog::on_instanceActionsLabel_linkActivated(const QString& link)
ui->instanceAddressLineEdit->setText(instance_address);
update_ui_in_progress = false;
} else if (link == "action:request-token") {
- // TODO: open browser with token request URL
+ Instance* instance = Instance::create_instance((AppSettingsTypes::InstanceType)ui->instanceTypeComboBox->currentIndex());
+
+ QString url = instance->oauth2_step1();
+ if (not QDesktopServices::openUrl(url))
+ QMessageBox::information(this, tr("Navigate to this URL"), tr("Please open the following URL in your browser: %1").arg(1));
+
+ Instance::OAuth2Step2 step2 = {.ok = false};
+ while (not step2.ok) {
+ bool ok;
+ QString code = QInputDialog::getText(this, tr("Enter authorization code"), tr("Enter the code given during the authentification flow:"), QLineEdit::Normal, "", &ok);
+
+ if (code.isEmpty()) return; // User canceled
+ if (ok) step2 = instance->oauth2_step2(code);
+ }
+
+ // Do not set update_ui_in_progress as we want the new text to be seen as new text by settings_interface (through on_tokenLineEdit_editingFinished())
+ ui->tokenLineEdit->setText(step2.token);
+ on_tokenLineEdit_editingFinished(); // Make sure that the change has been noticed as sometimes it isn't
}
}