diff src/dialog/settings/services.cpp @ 7:07a9095eaeed

Update Refactored some code, moved some around
author Paper <mrpapersonic@gmail.com>
date Thu, 24 Aug 2023 23:11:38 -0400
parents 1d82f6e04d7d
children
line wrap: on
line diff
--- a/src/dialog/settings/services.cpp	Wed Aug 16 00:49:17 2023 -0400
+++ b/src/dialog/settings/services.cpp	Thu Aug 24 23:11:38 2023 -0400
@@ -1,6 +1,6 @@
 #include "settings.h"
 #include "anilist.h"
-#include "window.h"
+#include "session.h"
 #include <QGroupBox>
 #include <QComboBox>
 #include <QPushButton>
@@ -15,8 +15,12 @@
 
 	QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box);
 
-	sync_combo_box = new QComboBox(sync_group_box);
+	QComboBox* sync_combo_box = new QComboBox(sync_group_box);
 	sync_combo_box->addItem(tr("AniList"));
+	connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index){
+		service = static_cast<enum AnimeListServices>(index + 1);
+	});
+	sync_combo_box->setCurrentIndex(service - 1);
 
 	QLabel* sync_note_label = new QLabel(tr("Note: Weeaboo is unable to synchronize multiple services at the same time."), sync_group_box);
 
@@ -43,9 +47,13 @@
 	QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box);
 
 	QWidget* auth_widget = new QWidget(group_box);
-	username_entry = new QLineEdit(QString::fromUtf8(session.config.anilist.username.c_str()), auth_widget);
+	QLineEdit* username_entry = new QLineEdit(username, auth_widget);
+	connect(username_entry, &QLineEdit::editingFinished, this, [this, username_entry]{
+		username = username_entry->text();
+	});
+
 	QPushButton* auth_button = new QPushButton(auth_widget);
-	connect(auth_button, &QPushButton::clicked, this, [this]{
+	connect(auth_button, &QPushButton::clicked, this, []{
 		AniList a;
 		a.Authorize();
 	});
@@ -75,12 +83,14 @@
 }
 
 void SettingsPageServices::SaveInfo() {
-	session.config.anilist.username = username_entry->displayText().toStdString();
-	session.config.service = static_cast<enum AnimeListServices>(sync_combo_box->currentIndex()+1);
+	session.config.anilist.username = username.toStdString();
+	session.config.service = service;
 }
 
 SettingsPageServices::SettingsPageServices(QWidget* parent)
 	: SettingsPage(parent, tr("Services")) {
+	username = QString::fromUtf8(session.config.anilist.username.c_str());
+	service = session.config.service;
 	AddTab(CreateMainPage(), tr("Main"));
 	AddTab(CreateAniListPage(), tr("AniList"));
 }