Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(toxme): Add ToxMe registration
Browse files Browse the repository at this point in the history
Add some features in Toxme class and new section in profile form
  • Loading branch information
Diadlo committed Apr 12, 2016
1 parent dde56c9 commit cb8bf13
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 5 deletions.
36 changes: 36 additions & 0 deletions src/net/toxme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,39 @@ QString Toxme::getErrorMessage(int 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;
}
}
48 changes: 48 additions & 0 deletions src/widget/form/profileform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <QWindow>
#include <QMenu>
#include <QMouseEvent>
#include <src/net/toxme.h>

ProfileForm::ProfileForm(QWidget *parent) :
QWidget{parent}, qr{nullptr}
Expand Down Expand Up @@ -80,6 +81,9 @@ ProfileForm::ProfileForm(QWidget *parent) :
QVBoxLayout *toxIdGroup = qobject_cast<QVBoxLayout*>(bodyUI->toxGroup->layout());
delete toxIdGroup->replaceWidget(bodyUI->toxId, toxId); // Original toxId is in heap, delete it
bodyUI->toxId->hide();
bodyUI->password->hide();
bodyUI->passwordLabel->hide();
bodyUI->serversList->addItem("toxme.io");

bodyUI->qrLabel->setWordWrap(true);

Expand Down Expand Up @@ -111,6 +115,7 @@ ProfileForm::ProfileForm(QWidget *parent) :
connect(bodyUI->changePassButton, &QPushButton::clicked, this, &ProfileForm::onChangePassClicked);
connect(bodyUI->saveQr, &QPushButton::clicked, this, &ProfileForm::onSaveQrClicked);
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::statusMessageSet, this, [=](const QString& val) { bodyUI->statusMessage->setText(val); });
Expand Down Expand Up @@ -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
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"));
}
2 changes: 2 additions & 0 deletions src/widget/form/profileform.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ private slots:
void onAvatarClicked();
void showProfilePictureContextMenu(const QPoint &point);

void onRegisterButtonClicked();

private:
void retranslateUi();
void prFileLabelUpdate();
Expand Down
98 changes: 93 additions & 5 deletions src/widget/form/profileform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>442</width>
<width>584</width>
<height>659</height>
</rect>
</property>
Expand Down Expand Up @@ -39,11 +39,11 @@
<rect>
<x>0</x>
<y>0</y>
<width>585</width>
<height>625</height>
<width>542</width>
<height>792</height>
</rect>
</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">
<number>9</number>
</property>
Expand Down Expand Up @@ -86,6 +86,90 @@
</layout>
</widget>
</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">
<widget class="QGroupBox" name="toxGroup">
<property name="title">
Expand All @@ -104,7 +188,11 @@ Share it with your friends to communicate.</string>
</widget>
</item>
<item>
<widget class="QLineEdit" name="toxId"/>
<widget class="QLineEdit" name="toxId">
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="verticalFrame">
Expand Down

0 comments on commit cb8bf13

Please sign in to comment.