2026-06-17 22:44:27 +02:00
|
|
|
#include "accountsetupdialoglauncher.h"
|
|
|
|
|
#include <QDebug>
|
2026-07-05 10:45:44 +02:00
|
|
|
#include "services/accountservice.h"
|
2026-06-17 22:44:27 +02:00
|
|
|
|
|
|
|
|
AccountSetupDialogLauncher::AccountSetupDialogLauncher(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccountSetupDialogLauncher::launchSetupDialog()
|
|
|
|
|
{
|
|
|
|
|
emit accountSetupStarted();
|
|
|
|
|
qDebug() << "[AccountSetupDialogLauncher] Dialog would launch here (Fase 3)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccountSetupDialogLauncher::setupAccountManually(const Account &account)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "[AccountSetupDialogLauncher] Setting up account:" << account.email();
|
|
|
|
|
|
2026-08-17 15:34:49 +02:00
|
|
|
// Save to database and retain the generated id for the synchronizer/event.
|
|
|
|
|
const qint64 id = AccountDao::insert(account);
|
|
|
|
|
if (id < 0) {
|
2026-06-17 22:44:27 +02:00
|
|
|
qWarning() << "[AccountSetupDialogLauncher] Failed to save account to DB";
|
|
|
|
|
emit accountSetupFailed("Failed to save account");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-08-17 15:34:49 +02:00
|
|
|
Account storedAccount = account;
|
|
|
|
|
storedAccount.setId(static_cast<int>(id));
|
2026-06-17 22:44:27 +02:00
|
|
|
|
|
|
|
|
// Initialize synchronizer
|
2026-08-17 15:34:49 +02:00
|
|
|
initializeSynchronizer(storedAccount);
|
2026-06-17 22:44:27 +02:00
|
|
|
|
|
|
|
|
// Publish event
|
|
|
|
|
WinoMail::Events::AccountAddedEvent event;
|
2026-08-17 15:34:49 +02:00
|
|
|
event.account = storedAccount;
|
2026-06-17 22:44:27 +02:00
|
|
|
EVENT_BUS.publish(event);
|
|
|
|
|
|
|
|
|
|
qDebug() << "[AccountSetupDialogLauncher] Account created successfully:" << account.email();
|
2026-08-17 15:34:49 +02:00
|
|
|
emit accountSetupCompleted(storedAccount);
|
2026-06-17 22:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccountSetupDialogLauncher::initializeSynchronizer(const Account &account)
|
|
|
|
|
{
|
|
|
|
|
QString accountId = QString::number(account.id());
|
|
|
|
|
|
|
|
|
|
// Determine provider type from Account's access token or type
|
|
|
|
|
QString providerType;
|
|
|
|
|
switch (account.type()) {
|
|
|
|
|
case AccountType::Gmail:
|
|
|
|
|
providerType = "gmail";
|
|
|
|
|
break;
|
|
|
|
|
case AccountType::Outlook:
|
|
|
|
|
providerType = "outlook";
|
|
|
|
|
break;
|
|
|
|
|
case AccountType::IMAP:
|
|
|
|
|
providerType = "imap";
|
|
|
|
|
break;
|
2026-07-05 10:45:44 +02:00
|
|
|
case AccountType::POP3:
|
|
|
|
|
providerType = "pop3";
|
|
|
|
|
break;
|
2026-06-17 22:44:27 +02:00
|
|
|
default:
|
|
|
|
|
providerType = "imap";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Synchronizer *sync = SynchronizerProvider::instance().createSynchronizer(accountId, providerType);
|
|
|
|
|
if (sync) {
|
|
|
|
|
sync->initialize(account);
|
|
|
|
|
qDebug() << "[AccountSetupDialogLauncher] Synchronizer initialized for account:" << accountId;
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "[AccountSetupDialogLauncher] Could not create synchronizer for:" << providerType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "accountsetupdialoglauncher.moc"
|