comunicwatcher/whoamidialog.cpp

46 lines
963 B
C++

#include <QMessageBox>
#include "accounthelper.h"
#include "whoamidialog.h"
#include "ui_whoamidialog.h"
WhoAmIDialog::WhoAmIDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::WhoAmIDialog)
{
ui->setupUi(this);
AccountHelper::GetUserID([this](int id) {
this->onGotUserId(id);
});
connect(&mUserHelper, &UserHelper::onGotUserInfo, this, &WhoAmIDialog::getUserCallback);
}
WhoAmIDialog::~WhoAmIDialog()
{
delete ui;
}
void WhoAmIDialog::getUserCallback(const User &u)
{
if(!u.isValid()) {
QMessageBox::warning(this, tr("Error"), tr("Could not get user information!"));
return;
}
this->ui->user_name->setText(u.fullName());
}
void WhoAmIDialog::onGotUserId(int userID)
{
if(userID < 1) {
QMessageBox::warning(this, tr("Error"), tr("Could not get your id!"));
return;
}
this->ui->user_id->setText(QString::number(userID));
mUserHelper.getUserInfo(userID);
}