Commit aa90e1ae authored by Anthony Léonard's avatar Anthony Léonard

Implement Ring usernames (Ethereum)

Change-Id: I9faeae5ad0bb2983876f53a3e5efe32d5c24ce9b
parent 7c7e95f7
......@@ -22,6 +22,7 @@
#include <QSortFilterProxyModel>
#include <QFileDialog>
#include <QPushButton>
#include <QMessageBox>
#include "codecmodel.h"
#include "protocolmodel.h"
......@@ -106,7 +107,19 @@ AccountDetails::setAccount(Account* currentAccount) {
if (currentAccount_ == nullptr)
return;
ui->lrcfg_username->setReadOnly(currentAccount_->protocol() == Account::Protocol::RING);
if (currentAccount_->protocol() == Account::Protocol::RING) {
if (currentAccount_->registeredName().isEmpty() ){ // If our user isn't registered on the blockhain
ui->lrcfg_registeredName->clear();
ui->lrcfg_registeredName->setReadOnly(false);
ui->registerButton->setText(tr("Register on blockchain"));
ui->registerButton->show();
ui->registerButton->setEnabled(true);
} else {
ui->lrcfg_registeredName->setText(currentAccount_->registeredName());
ui->lrcfg_registeredName->setReadOnly(true);
ui->registerButton->hide();
}
}
codecModel_ = currentAccount->codecModel();
ui->audioCodecView->setModel(codecModel_->audioCodecs());
......@@ -368,3 +381,54 @@ void AccountDetails::on_devicesStackedWidget_currentChanged(int pageNum)
if (pageNum != ui->devicesStackedWidget->indexOf(ui->passwordAskingPage))
ui->passwordArchiveEdit->clear();
}
void AccountDetails::on_registerButton_clicked()
{
ui->registerButton->setEnabled(false);
ui->registerButton->setText(tr("Registering... It may take some time"));
bool regSuccess = currentAccount_->registerName(ui->lrcfg_password->text(), ui->lrcfg_registeredName->text());
if (!regSuccess) {
QMessageBox::warning(this, "Username not registered", "Username registration failed, try again later.");
ui->registerButton->setEnabled(true);
ui->registerButton->setText(tr("Register on blockchain"));
return;
}
connect(currentAccount_, SIGNAL(nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)),
this, SLOT(handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)));
}
void AccountDetails::handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name)
{
disconnect(currentAccount_, SIGNAL(nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)),
this, SLOT(handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)));
switch(status) {
case NameDirectory::RegisterNameStatus::ALREADY_TAKEN:
QMessageBox::warning(this, "Username not registered", "This username is already taken, try another one.");
ui->registerButton->setEnabled(true);
ui->registerButton->setText(tr("Register on blockchain"));
break;
case NameDirectory::RegisterNameStatus::INVALID_NAME:
QMessageBox::warning(this, "Username not registered", "This username is invalid, try another one.");
ui->registerButton->setEnabled(true);
ui->registerButton->setText(tr("Register on blockchain"));
break;
case NameDirectory::RegisterNameStatus::WRONG_PASSWORD:
QMessageBox::warning(this, "Username not registered", "Wrong password, try again.");
ui->registerButton->setEnabled(true);
ui->registerButton->setText(tr("Register on blockchain"));
break;
case NameDirectory::RegisterNameStatus::NETWORK_ERROR:
QMessageBox::warning(this, "Username not registered", "Network error. Try again later.");
ui->registerButton->setEnabled(true);
ui->registerButton->setText(tr("Register on blockchain"));
break;
case NameDirectory::RegisterNameStatus::SUCCESS:
ui->lrcfg_registeredName->setReadOnly(true);
ui->registerButton->hide();
QMessageBox::information(this, "Username registered", name + " is registered, you can now share this name.");
break;
}
}
......@@ -58,6 +58,7 @@ private slots:
void on_exportEndedOkButton_clicked();
void on_cancelAddButton_clicked();
void on_devicesStackedWidget_currentChanged(int arg1);
void on_registerButton_clicked();
private slots:
void onCertButtonClicked();
......@@ -65,6 +66,7 @@ private slots:
void audioCodecSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
void videoCodecSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
void exportOnRingEnded(Account::ExportOnRingStatus state, const QString& pin);
void handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name);
private:
Ui::AccountDetails* ui;
......@@ -75,4 +77,3 @@ private:
void stopRingtone();
};
This diff is collapsed.
......@@ -186,6 +186,9 @@ CallWidget::CallWidget(QWidget* parent) :
ui->smartList->clearSelection();
});
connect(&NameDirectory::instance(), SIGNAL(registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
this, SLOT(contactLineEdit_registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)));
} catch (const std::exception& e) {
qDebug() << "INIT ERROR" << e.what();
}
......@@ -662,16 +665,32 @@ CallWidget::historicButtonClicked(bool checked)
}
void
CallWidget::on_ringContactLineEdit_returnPressed()
CallWidget::searchContactLineEditEntry(const URI &uri)
{
auto cm = PhoneDirectoryModel::instance().getNumber(ui->ringContactLineEdit->text());
time_t currentTime;
::time(&currentTime);
cm->setLastUsed(currentTime);
auto cm = PhoneDirectoryModel::instance().getNumber(uri);
// if its a new CM, bring it to the top
if (cm->lastUsed() == 0)
cm->setLastUsed(QDateTime::currentDateTime().toTime_t());
// select cm
RecentModel::instance().selectionModel()->setCurrentIndex(RecentModel::instance().getIndex(cm),
QItemSelectionModel::ClearAndSelect);
ui->ringContactLineEdit->clear();
}
void
CallWidget::on_ringContactLineEdit_returnPressed()
{
auto contactLineText = ui->ringContactLineEdit->text();
URI uri_passed = URI(contactLineText);
if (!contactLineText.isNull() && contactLineText.length() > 0){
QModelIndex index = RecentModel::instance().getIndex(cm);
RecentModel::instance().selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
NameDirectory::instance().lookupName(nullptr, QString(), uri_passed);
} else {
searchContactLineEditEntry(uri_passed);
}
}
void
......@@ -832,3 +851,39 @@ CallWidget::on_shareButton_clicked()
{
Utils::InvokeMailto(tr("Contact me on Ring"), tr("My RingId is : ") + ui->ringIdLabel->text());
}
void
CallWidget::contactLineEdit_registeredNameFound(const Account* account,NameDirectory::LookupStatus status,
const QString& address,const QString& name)
{
URI uri = URI(ui->ringContactLineEdit->text());
QString username_to_lookup = uri.userinfo();
if (username_to_lookup.compare(name) != 0){
return;
}
switch (status)
{
case NameDirectory::LookupStatus::SUCCESS:
{
uri = URI("ring:" + address);
qDebug() << uri;
searchContactLineEditEntry(uri);
break;
}
case NameDirectory::LookupStatus::INVALID_NAME:
{
qDebug() << "Invalid Ring username";
break;
}
case NameDirectory::LookupStatus::ERROR:
case NameDirectory::LookupStatus::NOT_FOUND:
default:
{
qDebug() << "Could not resolve Ring username";
break;
}
}
}
......@@ -94,6 +94,7 @@ private slots:
void slotAccountMessageReceived(const QMap<QString,QString> message,ContactMethod* cm,Media::Media::Direction dir);
void onIncomingMessage(::Media::TextRecording* t, ContactMethod* cm);
void callChangedSlot();
void contactLineEdit_registeredNameFound(const Account* account,NameDirectory::LookupStatus status,const QString& address,const QString& name);
private:
Ui::CallWidget* ui;
......@@ -126,5 +127,6 @@ private:
void slidePage(QWidget* widget, bool toRight = false);
void callStateToView(Call* value);
void setupQRCode();
void searchContactLineEditEntry(const URI &uri);
};
......@@ -288,7 +288,8 @@ QWidget#messagingPage{
QPushButton#wizardButton, QPushButton#playButton, QPushButton#clearHistoryButton, QPushButton#doTransferButton,
QPushButton#checkUpdateButton, QPushButton#photoButton, QPushButton#takePhotoButton, QPushButton#importButton,
QPushButton#existingPushButton, QPushButton#newAccountButton, QPushButton#previousButton, QPushButton#exportButton,
QPushButton#cancelAddButton, QPushButton#exportOnRingButton, QPushButton#addDeviceButton, QPushButton#exportEndedOkButton{
QPushButton#cancelAddButton, QPushButton#exportOnRingButton, QPushButton#addDeviceButton, QPushButton#exportEndedOkButton,
QPushButton#errorPushButton, QPushButton#registerButton{
background-color: #3AC0D2;
border: 0px;
color: white;
......@@ -300,7 +301,8 @@ QPushButton#doTransferButton:hover, QPushButton#photoButton:hover,
QPushButton#takePhotoButton:hover, QPushButton#importButton:hover,
QPushButton#existingPushButton:hover, QPushButton#newAccountButton:hover, QPushButton#previousButton:hover,
QPushButton#exportButton:hover, QPushButton#cancelAddButton:hover, QPushButton#exportOnRingButton:hover,
QPushButton#addDeviceButton:hover, QPushButton#exportEndedOkButton:hover{
QPushButton#addDeviceButton:hover, QPushButton#exportEndedOkButton:hover, QPushButton#errorPushButton:hover,
QPushButton#registerButton:hover{
background-color: #4dc6d6;
}
......@@ -309,7 +311,8 @@ QPushButton#doTransferButton:pressed, QPushButton#photoButton:pressed,
QPushButton#takePhotoButton:pressed, QPushButton#importButton:pressed,
QPushButton#existingPushButton:pressed, QPushButton#newAccountButton:pressed, QPushButton#previousButton:pressed,
QPushButton#exportButton:pressed, QPushButton#cancelAddButton:pressed, QPushButton#exportOnRingButton:pressed,
QPushButton#addDeviceButton:pressed, QPushButton#exportEndedOkButton:pressed{
QPushButton#addDeviceButton:pressed, QPushButton#exportEndedOkButton:pressed, QPushButton#errorPushButton:pressed,
QPushButton#registerButton:pressed{
background-color: #34acbd;
}
......@@ -500,7 +503,7 @@ QSpinBox::up-button{
QLineEdit#lrcfg_alias, QLineEdit#lrcfg_hostname, QLineEdit#lrcfg_password, QLineEdit#lrcfg_proxy,
QLineEdit#lrcfg_mailbox, QLineEdit#lrcfg_tlsPassword, QLineEdit#lrcfg_tlsServerName,
QLineEdit#lrcfg_turnServerRealm, QLineEdit#lrcfg_turnServerUsername, QLineEdit#lrcfg_turnServerPassword,
QLineEdit#lrcfg_turnServer, QLineEdit#lrcfg_publishedAddress, QLineEdit#lrcfg_username{
QLineEdit#lrcfg_turnServer, QLineEdit#lrcfg_publishedAddress, QLineEdit#lrcfg_registeredName{
background: transparent;
border-radius: 0px;
border-style: solid;
......@@ -524,7 +527,7 @@ QLineEdit#lrcfg_alias:focus, QLineEdit#lrcfg_hostname:focus, QLineEdit#lrcfg_pas
QLineEdit#lrcfg_proxy:focus, QLineEdit#lrcfg_mailbox:focus, QLineEdit#lrcfg_tlsPassword:focus,
QLineEdit#lrcfg_tlsServerName:focus, QLineEdit#lrcfg_turnServerRealm:focus, QLineEdit#lrcfg_turnServerUsername:focus,
QLineEdit#lrcfg_turnServerPassword:focus, QLineEdit#lrcfg_turnServer:focus, QLineEdit#lrcfg_publishedAddress:focus,
QLineEdit#lrcfg_username:focus{
QLineEdit#lrcfg_registeredName:focus{
border-color: #3AC0D2;
}
......
......@@ -20,6 +20,7 @@
#include "ui_wizarddialog.h"
#include <QMovie>
#include <QMessageBox>
#include "accountmodel.h"
#include "account.h"
......@@ -33,7 +34,8 @@ WizardDialog::WizardDialog(WizardMode wizardMode, Account* toBeMigrated, QWidget
QDialog(parent),
ui(new Ui::WizardDialog),
account_(toBeMigrated),
wizardMode_(wizardMode)
wizardMode_(wizardMode),
nameLookupTimer_(this)
{
ui->setupUi(this);
......@@ -64,10 +66,18 @@ WizardDialog::WizardDialog(WizardMode wizardMode, Account* toBeMigrated, QWidget
ui->pinEdit->hide();
ui->label->setText(tr("Your account needs to be migrated. Choose a password."));
}
ui->searchingStateLabel->clear();
connect(&NameDirectory::instance(), SIGNAL(registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
this, SLOT(handle_registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)));
nameLookupTimer_.setSingleShot(true);
connect(&nameLookupTimer_, QTimer::timeout, this, WizardDialog::timeoutNameLookupTimer);
}
WizardDialog::~WizardDialog()
{
disconnect(&NameDirectory::instance(), SIGNAL(registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
this, SLOT(handle_registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)));
delete ui;
}
......@@ -131,8 +141,16 @@ WizardDialog::endSetup(Account::RegistrationState state)
switch (state) {
case Account::RegistrationState::READY:
{
account_->performAction(Account::EditAction::RELOAD);
QDialog::accept();
if (ui->signUpCheckbox->isChecked()) { // If the user wants to register its name on the blockchain
bool regSuccess = account_->registerName(ui->passwordEdit->text(), ui->usernameEdit->text());
if (!regSuccess) usernameFailedRegistration();
else
connect(account_, SIGNAL(nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)),
this, SLOT(handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)));
} else {
account_->performAction(Account::EditAction::RELOAD);
QDialog::accept();
}
break;
}
case Account::RegistrationState::UNREGISTERED:
......@@ -152,6 +170,12 @@ WizardDialog::closeEvent(QCloseEvent* event)
QDialog::closeEvent(event);
}
void
WizardDialog::usernameFailedRegistration()
{
QMessageBox::warning(this, "Username not registered", "Your account has been created, but we could not register your username. Try again from the settings menu.");
}
void
WizardDialog::on_avatarButton_clicked()
{
......@@ -186,7 +210,10 @@ WizardDialog::changePage(bool existingAccount)
ui->ringLogo->setHidden(existingAccount);
ui->label->setHidden(existingAccount);
ui->usernameEdit->setHidden(existingAccount);
ui->signUpCheckbox->setHidden(existingAccount);
ui->signUpCheckbox->setChecked(!existingAccount);
ui->confirmPasswordEdit->setHidden(existingAccount);
ui->searchingStateLabel->setHidden(existingAccount);
ui->pinEdit->setVisible(existingAccount);
}
......@@ -209,3 +236,65 @@ WizardDialog::on_passwordEdit_textChanged(const QString& arg1)
ui->confirmPasswordEdit->setText(ui->passwordEdit->text());
}
}
void
WizardDialog::on_usernameEdit_textChanged(const QString &arg1)
{
Q_UNUSED(arg1)
if(ui->signUpCheckbox->isChecked() && !arg1.isEmpty()) {
ui->searchingStateLabel->setText(tr("Searching..."));
nameLookupTimer_.start(1500);
} else {
ui->searchingStateLabel->clear();
nameLookupTimer_.stop();
}
}
void
WizardDialog::timeoutNameLookupTimer()
{
if(ui->signUpCheckbox->isChecked() && !ui->usernameEdit->text().isEmpty()) {
NameDirectory::instance().lookupName(nullptr, QString(), ui->usernameEdit->text());
} else {
ui->searchingStateLabel->clear();
}
}
void
WizardDialog::handle_registeredNameFound (const Account* account, NameDirectory::LookupStatus status, const QString& address, const QString& name)
{
Q_UNUSED(account)
Q_UNUSED(address)
Q_UNUSED(name)
#pragma push_macro("ERROR")
#undef ERROR
switch(status) {
case NameDirectory::LookupStatus::SUCCESS:
ui->searchingStateLabel->setText(tr("Username not available."));
break;
case NameDirectory::LookupStatus::NOT_FOUND:
ui->searchingStateLabel->setText(tr("Username is available."));
break;
case NameDirectory::LookupStatus::INVALID_NAME:
ui->searchingStateLabel->setText(tr("Username is invalid."));
break;
case NameDirectory::LookupStatus::ERROR:
ui->searchingStateLabel->setText(tr("Network error."));
break;
}
#pragma pop_macro("ERROR")
}
void
WizardDialog::handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name)
{
Q_UNUSED(name)
disconnect(account_, SIGNAL(nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)),
this, SLOT(handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus,QString)));
if(status != NameDirectory::RegisterNameStatus::SUCCESS) {
usernameFailedRegistration();
}
account_->performAction(Account::EditAction::RELOAD);
QDialog::accept();
}
......@@ -58,14 +58,19 @@ private slots:
private slots:
void endSetup(Account::RegistrationState state);
void on_usernameEdit_textChanged(const QString& arg1);
void handle_registeredNameFound(const Account *account, NameDirectory::LookupStatus status, const QString& address, const QString& name);
void handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name);
void timeoutNameLookupTimer();
private:
Ui::WizardDialog* ui;
Account* account_;
WizardMode wizardMode_;
QMovie* movie_;
QTimer nameLookupTimer_;
void setup();
void changePage(bool existingAccount);
void usernameFailedRegistration();
};
......@@ -214,32 +214,75 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="usernameEdit">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="placeholderText">
<string>Choose your username</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="searchingStateLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Searching...</string>
</property>
</widget>
</item>
</layout>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QLineEdit" name="usernameEdit">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
<widget class="QCheckBox" name="signUpCheckbox">
<property name="toolTip">
<string>Register your username on the Ring. This will reserve the username so that only you can use it. Your friends will be able to call you with your usename instead of using your RingID.</string>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="placeholderText">
<string>Choose your username</string>
<property name="text">
<string>Register name publicly (experimental)</string>
</property>
<property name="clearButtonEnabled">
<property name="checked">
<bool>true</bool>
</property>
</widget>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment