mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(toxme): Add ToxMe registration
Add some features in Toxme class and new section in profile form
This commit is contained in:
parent
dde56c99ec
commit
cb8bf134d2
|
@ -334,3 +334,39 @@ QString Toxme::getErrorMessage(int errorCode)
|
||||||
return QObject::tr("Unknown error (%1)").arg(errorCode);
|
return QObject::tr("Unknown error (%1)").arg(errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Toxme::getErrorMessage(int errorCode)
|
||||||
|
{
|
||||||
|
switch (errorCode) {
|
||||||
|
case -1:
|
||||||
|
return "You must send POST requests to /api";
|
||||||
|
case -2:
|
||||||
|
return "Please try again using a HTTPS connection";
|
||||||
|
case -3:
|
||||||
|
return "I was unable to read your encrypted payload";
|
||||||
|
case -4:
|
||||||
|
return "You're making too many requests. Wait an hour and try again";
|
||||||
|
case -25:
|
||||||
|
return "This name is already in use";
|
||||||
|
case -26:
|
||||||
|
return "This Tox ID is already registered under another name";
|
||||||
|
case -27:
|
||||||
|
return "Please don't use a space in your name";
|
||||||
|
case -28:
|
||||||
|
return "Password incorrect";
|
||||||
|
case -29:
|
||||||
|
return "You can't use this name";
|
||||||
|
case -30:
|
||||||
|
return "Name not found";
|
||||||
|
case -31:
|
||||||
|
return "Tox ID not sent";
|
||||||
|
case -41:
|
||||||
|
return "Lookup failed because the other server replied with invalid data";
|
||||||
|
case -42:
|
||||||
|
return "That user does not exist";
|
||||||
|
case -43:
|
||||||
|
return "Internal lookup error. Please file a bug";
|
||||||
|
default:
|
||||||
|
return "Unknow error" + errorCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <src/net/toxme.h>
|
||||||
|
|
||||||
ProfileForm::ProfileForm(QWidget *parent) :
|
ProfileForm::ProfileForm(QWidget *parent) :
|
||||||
QWidget{parent}, qr{nullptr}
|
QWidget{parent}, qr{nullptr}
|
||||||
|
@ -80,6 +81,9 @@ ProfileForm::ProfileForm(QWidget *parent) :
|
||||||
QVBoxLayout *toxIdGroup = qobject_cast<QVBoxLayout*>(bodyUI->toxGroup->layout());
|
QVBoxLayout *toxIdGroup = qobject_cast<QVBoxLayout*>(bodyUI->toxGroup->layout());
|
||||||
delete toxIdGroup->replaceWidget(bodyUI->toxId, toxId); // Original toxId is in heap, delete it
|
delete toxIdGroup->replaceWidget(bodyUI->toxId, toxId); // Original toxId is in heap, delete it
|
||||||
bodyUI->toxId->hide();
|
bodyUI->toxId->hide();
|
||||||
|
bodyUI->password->hide();
|
||||||
|
bodyUI->passwordLabel->hide();
|
||||||
|
bodyUI->serversList->addItem("toxme.io");
|
||||||
|
|
||||||
bodyUI->qrLabel->setWordWrap(true);
|
bodyUI->qrLabel->setWordWrap(true);
|
||||||
|
|
||||||
|
@ -111,6 +115,7 @@ ProfileForm::ProfileForm(QWidget *parent) :
|
||||||
connect(bodyUI->changePassButton, &QPushButton::clicked, this, &ProfileForm::onChangePassClicked);
|
connect(bodyUI->changePassButton, &QPushButton::clicked, this, &ProfileForm::onChangePassClicked);
|
||||||
connect(bodyUI->saveQr, &QPushButton::clicked, this, &ProfileForm::onSaveQrClicked);
|
connect(bodyUI->saveQr, &QPushButton::clicked, this, &ProfileForm::onSaveQrClicked);
|
||||||
connect(bodyUI->copyQr, &QPushButton::clicked, this, &ProfileForm::onCopyQrClicked);
|
connect(bodyUI->copyQr, &QPushButton::clicked, this, &ProfileForm::onCopyQrClicked);
|
||||||
|
connect(bodyUI->registerButton, &QPushButton::clicked, this, &ProfileForm::onRegisterButtonClicked);
|
||||||
|
|
||||||
connect(core, &Core::usernameSet, this, [=](const QString& val) { bodyUI->userName->setText(val); });
|
connect(core, &Core::usernameSet, this, [=](const QString& val) { bodyUI->userName->setText(val); });
|
||||||
connect(core, &Core::statusMessageSet, this, [=](const QString& val) { bodyUI->statusMessage->setText(val); });
|
connect(core, &Core::statusMessageSet, this, [=](const QString& val) { bodyUI->statusMessage->setText(val); });
|
||||||
|
@ -416,3 +421,46 @@ void ProfileForm::retranslateUi()
|
||||||
// We have to add the toxId tooltip here and not in the .ui or Qt won't know how to translate it dynamically
|
// We have to add the toxId tooltip here and not in the .ui or Qt won't know how to translate it dynamically
|
||||||
toxId->setToolTip(tr("This bunch of characters tells other Tox clients how to contact you.\nShare it with your friends to communicate."));
|
toxId->setToolTip(tr("This bunch of characters tells other Tox clients how to contact you.\nShare it with your friends to communicate."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProfileForm::onRegisterButtonClicked()
|
||||||
|
{
|
||||||
|
QString name = bodyUI->toxmeUsername->text();
|
||||||
|
if (name.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
bodyUI->toxmeRegisterButton->setEnabled(false);
|
||||||
|
bodyUI->toxmeUpdateButton->setEnabled(false);
|
||||||
|
bodyUI->toxmeRegisterButton->setText(tr("Register (processing)"));
|
||||||
|
bodyUI->toxmeUpdateButton->setText(tr("Update (processing)"));
|
||||||
|
|
||||||
|
QString id = toxId->text();
|
||||||
|
QString bio = bodyUI->toxmeBio->text();
|
||||||
|
QString server = bodyUI->toxmeServersList->currentText();
|
||||||
|
bool privacy = bodyUI->toxmePrivacy->isChecked();
|
||||||
|
if (name.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Toxme::ExecCode code = Toxme::ExecCode::Ok;
|
||||||
|
QString response = Toxme::createAddress(code, server, id, name, privacy, bio);
|
||||||
|
|
||||||
|
switch (code) {
|
||||||
|
case Toxme::Updated:
|
||||||
|
QMessageBox::information(this, tr("Done!"), tr("Account %1@%2 updated successfully").arg(name, server), "Ok");
|
||||||
|
Settings::getInstance().setToxme(name, server, bio, privacy);
|
||||||
|
showExistenToxme();
|
||||||
|
break;
|
||||||
|
case Toxme::Ok:
|
||||||
|
QMessageBox::information(this, tr("Done!"), tr("Successfully added %1@%2 to the database. Save your password").arg(name, server), "Ok");
|
||||||
|
Settings::getInstance().setToxme(name, server, bio, privacy, response);
|
||||||
|
showExistenToxme();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
QString errorMessage = Toxme::getErrorMessage(code);
|
||||||
|
QMessageBox::warning(this, tr("Toxme error"), errorMessage, "Ok");
|
||||||
|
}
|
||||||
|
|
||||||
|
bodyUI->toxmeRegisterButton->setEnabled(true);
|
||||||
|
bodyUI->toxmeUpdateButton->setEnabled(true);
|
||||||
|
bodyUI->toxmeRegisterButton->setText(tr("Register"));
|
||||||
|
bodyUI->toxmeUpdateButton->setText(tr("Update"));
|
||||||
|
}
|
||||||
|
|
|
@ -81,6 +81,8 @@ private slots:
|
||||||
void onAvatarClicked();
|
void onAvatarClicked();
|
||||||
void showProfilePictureContextMenu(const QPoint &point);
|
void showProfilePictureContextMenu(const QPoint &point);
|
||||||
|
|
||||||
|
void onRegisterButtonClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void prFileLabelUpdate();
|
void prFileLabelUpdate();
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>442</width>
|
<width>584</width>
|
||||||
<height>659</height>
|
<height>659</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -39,11 +39,11 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>585</width>
|
<width>542</width>
|
||||||
<height>625</height>
|
<height>792</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,1">
|
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,1">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>9</number>
|
<number>9</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -86,6 +86,90 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="horizontalGroupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Toxme register</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="bioLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Biography</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="bio"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="dnsUsername"/>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="1">
|
||||||
|
<widget class="QLineEdit" name="password">
|
||||||
|
<property name="frame">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
|
<widget class="QLabel" name="passwordLabel">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Your password</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QCheckBox" name="privacy">
|
||||||
|
<property name="text">
|
||||||
|
<string>Hide my name from the public list</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QPushButton" name="registerButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Register</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="dnsUsernameLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Username</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QComboBox" name="serversList">
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>-1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="serverLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Server</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item alignment="Qt::AlignTop">
|
<item alignment="Qt::AlignTop">
|
||||||
<widget class="QGroupBox" name="toxGroup">
|
<widget class="QGroupBox" name="toxGroup">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -104,7 +188,11 @@ Share it with your friends to communicate.</string>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="toxId"/>
|
<widget class="QLineEdit" name="toxId">
|
||||||
|
<property name="frame">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QFrame" name="verticalFrame">
|
<widget class="QFrame" name="verticalFrame">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user