2015-11-10 04:56:22 +08:00
|
|
|
#include "aboutuser.h"
|
|
|
|
#include "ui_aboutuser.h"
|
|
|
|
#include "src/persistence/settings.h"
|
|
|
|
|
2015-11-13 05:30:54 +08:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
2015-11-13 05:46:43 +08:00
|
|
|
AboutUser::AboutUser(ToxId &toxId, QWidget *parent) :
|
2015-11-10 04:56:22 +08:00
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::AboutUser)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AboutUser::onAcceptedClicked);
|
2015-11-13 05:30:54 +08:00
|
|
|
connect(ui->autoaccept, &QCheckBox::clicked, this, &AboutUser::onAutoAcceptClicked);
|
2015-11-13 05:46:43 +08:00
|
|
|
connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutUser::onSelectDirClicked);
|
|
|
|
|
|
|
|
this->toxId = toxId;
|
|
|
|
QString dir = Settings::getInstance().getAutoAcceptDir(this->toxId);
|
|
|
|
ui->autoaccept->setChecked(!dir.isEmpty());
|
|
|
|
ui->selectSaveDir->setEnabled(ui->autoaccept->isChecked());
|
2015-11-10 04:56:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AboutUser::setFriend(Friend *f)
|
|
|
|
{
|
|
|
|
this->setWindowTitle(f->getDisplayedName());
|
|
|
|
ui->userName->setText(f->getDisplayedName());
|
|
|
|
ui->publicKey->setText(QString(f->getToxId().toString()));
|
|
|
|
ui->note->setPlainText(Settings::getInstance().getContactNote(f->getToxId()));
|
2015-11-13 05:46:43 +08:00
|
|
|
|
2015-11-13 05:13:37 +08:00
|
|
|
QPixmap avatar = Settings::getInstance().getSavedAvatar(f->getToxId().toString());
|
|
|
|
ui->statusMessage->setText(f->getStatusMessage());
|
|
|
|
if(!avatar.isNull()) {
|
|
|
|
ui->avatar->setPixmap(avatar);
|
|
|
|
} else {
|
2015-11-13 05:30:54 +08:00
|
|
|
ui->avatar->setPixmap(QPixmap(":/img/contact_dark.svg"));
|
2015-11-13 05:13:37 +08:00
|
|
|
}
|
2015-11-13 05:30:54 +08:00
|
|
|
|
2015-11-10 04:56:22 +08:00
|
|
|
}
|
|
|
|
|
2015-11-13 05:30:54 +08:00
|
|
|
void AboutUser::onAutoAcceptClicked()
|
|
|
|
{
|
|
|
|
QString dir;
|
|
|
|
if (!ui->autoaccept->isChecked())
|
|
|
|
{
|
|
|
|
dir = QDir::homePath();
|
|
|
|
ui->autoaccept->setChecked(false);
|
|
|
|
Settings::getInstance().setAutoAcceptDir(this->toxId, "");
|
2015-11-13 05:46:43 +08:00
|
|
|
ui->selectSaveDir->setText("Auto accept for this contact is disabled");
|
2015-11-13 05:30:54 +08:00
|
|
|
}
|
|
|
|
else if (ui->autoaccept->isChecked())
|
|
|
|
{
|
|
|
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose an auto accept directory",
|
|
|
|
"popup title"), dir);
|
|
|
|
ui->autoaccept->setChecked(true);
|
|
|
|
Settings::getInstance().setAutoAcceptDir(this->toxId, dir);
|
2015-11-13 05:46:43 +08:00
|
|
|
ui->selectSaveDir->setText(Settings::getInstance().getAutoAcceptDir(this->toxId));
|
2015-11-13 05:30:54 +08:00
|
|
|
}
|
|
|
|
Settings::getInstance().saveGlobal();
|
2015-11-13 05:46:43 +08:00
|
|
|
ui->selectSaveDir->setEnabled(ui->autoaccept->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AboutUser::onSelectDirClicked()
|
|
|
|
{
|
|
|
|
QString dir;
|
|
|
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose an auto accept directory",
|
|
|
|
"popup title"), dir);
|
|
|
|
ui->autoaccept->setChecked(true);
|
|
|
|
Settings::getInstance().setAutoAcceptDir(this->toxId, dir);
|
|
|
|
Settings::getInstance().saveGlobal();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief AboutUser::onAcceptedClicked When users clicks the bottom OK button,
|
|
|
|
* save all settings
|
|
|
|
*/
|
|
|
|
void AboutUser::onAcceptedClicked()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setContactNote(ui->publicKey->text(), ui->note->toPlainText());
|
|
|
|
Settings::getInstance().saveGlobal();
|
2015-11-13 05:30:54 +08:00
|
|
|
}
|
|
|
|
|
2015-11-10 04:56:22 +08:00
|
|
|
AboutUser::~AboutUser()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|