mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(toxme): Add save toxme info
This commit is contained in:
parent
41c5d4bf14
commit
204fe1d3de
|
@ -39,7 +39,7 @@ QByteArray Toxme::makeJsonRequest(QString url, QString json, QNetworkReply::Netw
|
|||
netman.setProxy(Settings::getInstance().getProxy());
|
||||
QNetworkRequest request{url};
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
QNetworkReply* reply = netman.post(request,json.toUtf8());
|
||||
QNetworkReply* reply = netman.post(request, json.toUtf8());
|
||||
|
||||
while (!reply->isFinished())
|
||||
{
|
||||
|
@ -239,7 +239,7 @@ QString Toxme::createAddress(ExecCode &code, QString server, ToxId id, QString a
|
|||
qDebug() << response;
|
||||
|
||||
code = extractError(response);
|
||||
if ((code != Registered && code != Updated) || error != QNetworkReply::NoError)
|
||||
if ((code != Ok && code != Updated) || error != QNetworkReply::NoError)
|
||||
return QString();
|
||||
|
||||
return getPass(response, code);
|
||||
|
@ -276,7 +276,7 @@ QString Toxme::getPass(QString json, ExecCode &code) {
|
|||
return json;
|
||||
}
|
||||
|
||||
int Toxme::deleteAddress(QString server, ToxId id)
|
||||
Toxme::ExecCode Toxme::deleteAddress(QString server, ToxId id)
|
||||
{
|
||||
const QString payload{"{\"public_key\":\""+id.toString().left(64)+"\","
|
||||
"\"timestamp\":"+QString().setNum(time(0))+"}"};
|
||||
|
@ -285,6 +285,7 @@ int Toxme::deleteAddress(QString server, ToxId id)
|
|||
if (!server.contains("://"))
|
||||
server = "https://" + server;
|
||||
|
||||
qDebug() << payload;
|
||||
QString pubkeyUrl = server + "/pk";
|
||||
QString apiUrl = server + "/api";
|
||||
QNetworkReply::NetworkError error = QNetworkReply::NoError;
|
||||
|
|
|
@ -38,7 +38,7 @@ class Toxme
|
|||
public:
|
||||
enum ExecCode {
|
||||
ExecError = -50,
|
||||
Registered = 0,
|
||||
Ok = 0,
|
||||
Updated = 1,
|
||||
ServerError = 2,
|
||||
IncorrectResponse = 3,
|
||||
|
@ -54,7 +54,7 @@ public:
|
|||
static QString createAddress(ExecCode &code, QString server, ToxId id, QString address,
|
||||
bool keepPrivate=true, QString bio=QString());
|
||||
/// Deletes the address associated with your current Tox ID
|
||||
static int deleteAddress(QString server, ToxId id);
|
||||
static ExecCode deleteAddress(QString server, ToxId id);
|
||||
/// Return string of the corresponding error code
|
||||
static QString getErrorMessage(int errorCode);
|
||||
|
||||
|
|
|
@ -359,6 +359,13 @@ void Settings::loadPersonal(Profile* profile)
|
|||
}
|
||||
ps.endArray();
|
||||
ps.endGroup();
|
||||
|
||||
ps.beginGroup("Toxme");
|
||||
toxmeInfo = ps.value("info", "").toString();
|
||||
toxmeBio = ps.value("bio", "").toString();
|
||||
toxmePriv = ps.value("priv", false).toBool();
|
||||
toxmePass = ps.value("pass", "").toString();
|
||||
ps.endGroup();
|
||||
}
|
||||
|
||||
void Settings::saveGlobal()
|
||||
|
@ -555,6 +562,13 @@ void Settings::savePersonal(QString profileName, QString password)
|
|||
ps.setValue("enableLogging", enableLogging);
|
||||
ps.endGroup();
|
||||
|
||||
ps.beginGroup("Toxme");
|
||||
ps.setValue("info", toxmeInfo);
|
||||
ps.setValue("bio", toxmeBio);
|
||||
ps.setValue("priv", toxmePriv);
|
||||
ps.setValue("pass", toxmePass);
|
||||
ps.endGroup();
|
||||
|
||||
ps.save();
|
||||
}
|
||||
|
||||
|
@ -838,6 +852,72 @@ void Settings::setTranslation(QString newValue)
|
|||
translation = newValue;
|
||||
}
|
||||
|
||||
void Settings::deleteToxme()
|
||||
{
|
||||
setToxmeInfo("");
|
||||
setToxmeBio("");
|
||||
setToxmePriv("");
|
||||
setToxmePass("");
|
||||
}
|
||||
|
||||
void Settings::setToxme(QString name, QString server, QString bio, bool priv, QString pass)
|
||||
{
|
||||
setToxmeInfo(name + "@" + server);
|
||||
setToxmeBio(bio);
|
||||
setToxmePriv(priv);
|
||||
if (!pass.isEmpty())
|
||||
setToxmePass(pass);
|
||||
}
|
||||
|
||||
QString Settings::getToxmeInfo() const
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
return toxmeInfo;
|
||||
}
|
||||
|
||||
void Settings::setToxmeInfo(QString info)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
if (info.split("@").size() == 2)
|
||||
toxmeInfo = info;
|
||||
}
|
||||
|
||||
QString Settings::getToxmeBio() const
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
return toxmeBio;
|
||||
}
|
||||
|
||||
void Settings::setToxmeBio(QString bio)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
toxmeBio = bio;
|
||||
}
|
||||
|
||||
bool Settings::getToxmePriv() const
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
return toxmePriv;
|
||||
}
|
||||
|
||||
void Settings::setToxmePriv(bool priv)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
toxmePriv = priv;
|
||||
}
|
||||
|
||||
QString Settings::getToxmePass() const
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
return toxmePass;
|
||||
}
|
||||
|
||||
void Settings::setToxmePass(QString pass)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
toxmePass = pass;
|
||||
}
|
||||
|
||||
bool Settings::getForceTCP() const
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
|
|
@ -108,6 +108,21 @@ public:
|
|||
QString getTranslation() const;
|
||||
void setTranslation(QString newValue);
|
||||
|
||||
// Toxme
|
||||
void deleteToxme();
|
||||
void setToxme(QString name, QString server, QString bio, bool priv, QString pass = "");
|
||||
QString getToxmeInfo() const;
|
||||
void setToxmeInfo(QString info);
|
||||
|
||||
QString getToxmeBio() const;
|
||||
void setToxmeBio(QString bio);
|
||||
|
||||
bool getToxmePriv() const;
|
||||
void setToxmePriv(bool priv);
|
||||
|
||||
QString getToxmePass() const;
|
||||
void setToxmePass(QString pass);
|
||||
|
||||
void setAutoSaveEnabled(bool newValue);
|
||||
bool getAutoSaveEnabled() const;
|
||||
|
||||
|
@ -359,6 +374,12 @@ private:
|
|||
QString currentProfile;
|
||||
uint32_t currentProfileId;
|
||||
|
||||
// Toxme Info
|
||||
QString toxmeInfo; // name@server
|
||||
QString toxmeBio;
|
||||
bool toxmePriv;
|
||||
QString toxmePass;
|
||||
|
||||
bool enableLogging;
|
||||
|
||||
int autoAwayTime;
|
||||
|
|
|
@ -81,9 +81,15 @@ 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");
|
||||
|
||||
/* Toxme section init */
|
||||
bodyUI->toxmeServersList->addItem("toxme.io");
|
||||
bodyUI->toxmeServersList->addItem("toxme.io");
|
||||
QString toxmeInfo = Settings::getInstance().getToxmeInfo();
|
||||
if (toxmeInfo.isEmpty()) // User not registered
|
||||
showRegisterToxme();
|
||||
else
|
||||
showExistenToxme();
|
||||
|
||||
bodyUI->qrLabel->setWordWrap(true);
|
||||
|
||||
|
@ -115,7 +121,8 @@ 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(bodyUI->toxmeRegisterButton, &QPushButton::clicked, this, &ProfileForm::onRegisterButtonClicked);
|
||||
connect(bodyUI->toxmeUpdateButton, &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); });
|
||||
|
@ -422,6 +429,39 @@ void ProfileForm::retranslateUi()
|
|||
toxId->setToolTip(tr("This bunch of characters tells other Tox clients how to contact you.\nShare it with your friends to communicate."));
|
||||
}
|
||||
|
||||
void ProfileForm::showRegisterToxme()
|
||||
{
|
||||
bodyUI->toxmeUsername->setText("");
|
||||
bodyUI->toxmeBio->setText("");
|
||||
bodyUI->toxmePrivacy->setChecked(false);
|
||||
|
||||
bodyUI->toxmeRegisterButton->show();
|
||||
bodyUI->toxmeUpdateButton->hide();
|
||||
bodyUI->toxmePassword->hide();
|
||||
bodyUI->toxmePasswordLabel->hide();
|
||||
}
|
||||
|
||||
void ProfileForm::showExistenToxme()
|
||||
{
|
||||
QStringList info = Settings::getInstance().getToxmeInfo().split("@");
|
||||
bodyUI->toxmeUsername->setText(info[0]);
|
||||
bodyUI->toxmeServersList->addItem(info[1]);
|
||||
|
||||
QString bio = Settings::getInstance().getToxmeBio();
|
||||
bodyUI->toxmeBio->setText(bio);
|
||||
|
||||
bool priv = Settings::getInstance().getToxmePriv();
|
||||
bodyUI->toxmePrivacy->setChecked(priv);
|
||||
|
||||
QString pass = Settings::getInstance().getToxmePass();
|
||||
bodyUI->toxmePassword->setText(pass);
|
||||
bodyUI->toxmePassword->show();
|
||||
bodyUI->toxmePasswordLabel->show();
|
||||
|
||||
bodyUI->toxmeRegisterButton->hide();
|
||||
bodyUI->toxmeUpdateButton->show();
|
||||
}
|
||||
|
||||
void ProfileForm::onRegisterButtonClicked()
|
||||
{
|
||||
QString name = bodyUI->toxmeUsername->text();
|
||||
|
@ -458,6 +498,7 @@ void ProfileForm::onRegisterButtonClicked()
|
|||
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"));
|
||||
|
|
|
@ -83,6 +83,7 @@ private slots:
|
|||
void onRegisterButtonClicked();
|
||||
|
||||
private:
|
||||
void showExistenToxme();
|
||||
void retranslateUi();
|
||||
void prFileLabelUpdate();
|
||||
|
||||
|
@ -98,6 +99,7 @@ private:
|
|||
bool hasCheck = false;
|
||||
QRWidget *qr;
|
||||
ClickableTE* toxId;
|
||||
void showRegisterToxme();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>536</width>
|
||||
<height>802</height>
|
||||
<height>844</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,1">
|
||||
|
@ -86,109 +86,6 @@
|
|||
</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="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>
|
||||
<property name="autoDefault">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</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="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<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>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="dnsUsername">
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="bio"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignTop">
|
||||
<widget class="QGroupBox" name="toxGroup">
|
||||
<property name="title">
|
||||
|
@ -256,6 +153,123 @@ Share it with your friends to communicate.</string>
|
|||
</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="0" column="0">
|
||||
<widget class="QLabel" name="toxmeUsernameLabel">
|
||||
<property name="text">
|
||||
<string>Username</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="toxmeUsername">
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="toxmeBioLabel">
|
||||
<property name="text">
|
||||
<string>Biography</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="toxmeBio"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="toxmeServerLabel">
|
||||
<property name="text">
|
||||
<string>Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="toxmeServersList">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="toxmePrivacy">
|
||||
<property name="text">
|
||||
<string>Hide my name from the public list</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QPushButton" name="toxmeRegisterButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Register</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="toxmePasswordLabel">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Your password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QLineEdit" name="toxmePassword">
|
||||
<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="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QPushButton" name="toxmeUpdateButton">
|
||||
<property name="text">
|
||||
<string>Update</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignTop">
|
||||
<widget class="QGroupBox" name="profilesGroup">
|
||||
<property name="title">
|
||||
|
@ -429,12 +443,12 @@ Profile does not contain your history.</string>
|
|||
<tabstop>scrollArea</tabstop>
|
||||
<tabstop>userName</tabstop>
|
||||
<tabstop>statusMessage</tabstop>
|
||||
<tabstop>dnsUsername</tabstop>
|
||||
<tabstop>bio</tabstop>
|
||||
<tabstop>serversList</tabstop>
|
||||
<tabstop>privacy</tabstop>
|
||||
<tabstop>registerButton</tabstop>
|
||||
<tabstop>password</tabstop>
|
||||
<tabstop>toxmeUsername</tabstop>
|
||||
<tabstop>toxmeBio</tabstop>
|
||||
<tabstop>toxmeServersList</tabstop>
|
||||
<tabstop>toxmePrivacy</tabstop>
|
||||
<tabstop>toxmeRegisterButton</tabstop>
|
||||
<tabstop>toxmePassword</tabstop>
|
||||
<tabstop>toxId</tabstop>
|
||||
<tabstop>saveQr</tabstop>
|
||||
<tabstop>copyQr</tabstop>
|
||||
|
|
Loading…
Reference in New Issue
Block a user