This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

#5629 Complete activation support for activation dialog

  • Loading branch information...
nlyan committed Sep 30, 2016
1 parent 60a4e62 commit 0f95c6e941c9a8b545f3903e4e1842c229d60fe7
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
- <string>Dialog</string>
+ <string>Activate Synergy</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@@ -51,17 +51,11 @@
<item row="0" column="1">
<widget class="QLineEdit" name="m_pLineEditEmail">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="minimumSize">
- <size>
- <width>200</width>
- <height>20</height>
- </size>
- </property>
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
@@ -77,17 +71,11 @@
<item row="1" column="1">
<widget class="QLineEdit" name="m_pLineEditPassword">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="minimumSize">
- <size>
- <width>200</width>
- <height>20</height>
- </size>
- </property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
@@ -120,13 +108,19 @@
</item>
<item>
<widget class="QTextEdit" name="m_pTextEditSerialKey">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
- <height>156</height>
+ <height>165</height>
</rect>
</property>
<property name="windowTitle">
@@ -1,23 +1,166 @@
#include "ActivationDialog.h"
#include "ui_ActivationDialog.h"
#include "CancelActivationDialog.h"
+#include "AppConfig.h"
+#include "WebClient.h"
+#include "EditionType.h"
+#include "ActivationNotifier.h"
+#include "MainWindow.h"
+#include "QUtility.h"
+#include "SubscriptionManager.h"
-ActivationDialog::ActivationDialog(QWidget *parent) :
+#include <QMessageBox>
+#include <QThread>
+#include <iostream>
+
+ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig) :
QDialog(parent),
- ui(new Ui::ActivationDialog)
+ ui(new Ui::ActivationDialog),
+ m_appConfig (&appConfig)
{
ui->setupUi(this);
+
+ ui->m_pLineEditEmail->setText(appConfig.activateEmail());
+ ui->m_pTextEditSerialKey->setText(appConfig.serialKey());
+
+ if (!appConfig.serialKey().isEmpty()) {
+ ui->m_pRadioButtonActivate->setAutoExclusive(false);
+ ui->m_pRadioButtonSubscription->setAutoExclusive(false);
+ ui->m_pRadioButtonActivate->setChecked(false);
+ ui->m_pRadioButtonSubscription->setChecked(true);
+ ui->m_pRadioButtonActivate->setAutoExclusive(true);
+ ui->m_pRadioButtonSubscription->setAutoExclusive(true);
+ ui->m_pTextEditSerialKey->setFocus();
+ ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
+ } else {
+ if (ui->m_pLineEditEmail->text().isEmpty()) {
+ ui->m_pLineEditEmail->setFocus();
+ } else {
+ ui->m_pLineEditPassword->setFocus();
+ }
+ }
}
ActivationDialog::~ActivationDialog()
{
delete ui;
}
+void ActivationDialog::notifyActivation(QString identity)
+{
+ ActivationNotifier* notifier = new ActivationNotifier();
+ notifier->setIdentity(identity);
+
+ QThread* thread = new QThread();
+ connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
+ connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
+ connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+
+ notifier->moveToThread(thread);
+ thread->start();
+
+ QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
+}
+
void ActivationDialog::reject()
{
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
+ notifyActivation("skip:unknown");
QDialog::reject();
}
}
+
+void ActivationDialog::on_m_pRadioButtonSubscription_toggled(bool checked)
+{
+ if (checked) {
+ ui->m_pLineEditEmail->setEnabled(false);
+ ui->m_pLineEditPassword->setEnabled(false);
+ ui->m_pTextEditSerialKey->setEnabled(true);
+ ui->m_pTextEditSerialKey->setFocus();
+ }
+}
+
+void ActivationDialog::on_m_pRadioButtonActivate_toggled(bool checked)
+{
+ if (checked) {
+ ui->m_pLineEditEmail->setEnabled(true);
+ ui->m_pLineEditPassword->setEnabled(true);
+ ui->m_pTextEditSerialKey->setEnabled(false);
+ if (ui->m_pLineEditEmail->text().isEmpty()) {
+ ui->m_pLineEditEmail->setFocus();
+ } else {
+ ui->m_pLineEditPassword->setFocus();
+ }
+ }
+}
+
+void ActivationDialog::accept()
+{
+ QMessageBox message;
+ QString error;
+ int edition = Unregistered;
+
+ try {
+ if (ui->m_pRadioButtonActivate->isChecked()) {
+ WebClient webClient;
+ QString email = ui->m_pLineEditEmail->text();
+ QString password = ui->m_pLineEditPassword->text();
+
+ if (!webClient.setEmail (email, error)) {
+ message.critical (this, "Invalid Email Address", tr("%1").arg(error));
+ return;
+ }
+ else if (!webClient.setPassword (password, error)) {
+ message.critical (this, "Invalid Password", tr("%1").arg(error));
+ return;
+ }
+ else if (!webClient.getEdition (edition, error)) {
+ message.critical (this, "Activation Error",
+ tr("An error occurred while trying to activate Synergy. "
+ "The Symless server returned the following error:\n\n%1").arg(error));
+ return;
+ }
+
+ m_appConfig->setActivateEmail (email);
+ m_appConfig->clearSerialKey();
+ ui->m_pTextEditSerialKey->clear();
+ notifyActivation ("login:" + m_appConfig->activateEmail());
+ }
+ else {
+ QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
+
+ if (!m_appConfig->setSerialKey (serialKey, error)) {
+ message.critical (this, "Invalid Serial Key", tr("%1").arg(error));
+ return;
+ }
+
+ SubscriptionManager subscriptionManager (this, *m_appConfig, edition);
+ if (!subscriptionManager.activateSerial (serialKey)) {
+ return;
+ }
+ m_appConfig->setActivateEmail("");
+ notifyActivation ("serial:" + m_appConfig->serialKey());
+ }
+ }
+ catch (std::exception& e) {
+ message.critical (this, "Unknown Error",
+ tr("An error occurred while trying to activate Synergy. "
+ "Please contact the helpdesk, and provide the "
+ "following details.\n\n%1").arg(e.what()));
+ return;
+ }
+
+ m_appConfig->setEdition(edition);
+ m_appConfig->saveSettings();
+
+ message.information (this, "Activated!",
+ tr("Thanks for activating %1!").arg
+ (getEditionName (edition)));
+ MainWindow& mainWindow = dynamic_cast<MainWindow&>(*this->parent());
+ mainWindow.setEdition(edition);
+ mainWindow.updateLocalFingerprint();
+ mainWindow.settings().sync();
+
+ QDialog::accept();
+}
@@ -7,19 +7,30 @@ namespace Ui {
class ActivationDialog;
}
+class AppConfig;
+
class ActivationDialog : public QDialog
{
Q_OBJECT
public:
- explicit ActivationDialog(QWidget *parent = 0);
+ explicit ActivationDialog(QWidget *parent, AppConfig& appConfig);
~ActivationDialog();
public slots:
void reject();
+ void accept();
+
+protected:
+ void notifyActivation (QString identity);
private:
Ui::ActivationDialog *ui;
+ AppConfig* m_appConfig;
+
+private slots:
+ void on_m_pRadioButtonSubscription_toggled(bool checked);
+ void on_m_pRadioButtonActivate_toggled(bool checked);
};
#endif // ACTIVATIONDIALOG_H
Oops, something went wrong.

0 comments on commit 0f95c6e

Please sign in to comment.