#5659 Move activation notification to SubscriptionManager

This commit is contained in:
Andrew Nelless 2016-10-14 12:16:23 +01:00
parent 540882056f
commit 727fc5c220
5 changed files with 34 additions and 27 deletions

View File

@ -31,27 +31,11 @@ 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");
m_subscriptionManager->notifySkip();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
QDialog::reject();
@ -69,10 +53,7 @@ void ActivationDialog::accept()
try {
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
SubscriptionManager subscriptionManager (m_appConfig);
subscriptionManager.setSerialKey (serialKey);
notifyActivation("serial:" + m_appConfig->serialKey());
m_subscriptionManager->setSerialKey(serialKey);
}
catch (std::exception& e) {
message.critical(this, "Unknown Error",

View File

@ -22,9 +22,6 @@ public:
public slots:
void reject();
void accept();
protected:
void notifyActivation (QString identity);
private:
Ui::ActivationDialog *ui;

View File

@ -19,6 +19,7 @@
#include "EditionType.h"
#include "AppConfig.h"
#include <ctime>
#include <QThread>
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
m_AppConfig(appConfig) {
@ -30,6 +31,28 @@ SubscriptionManager::setSerialKey(QString serialKeyString)
SerialKey serialKey (serialKeyString.toStdString());
if (serialKey.isValid (::time(0)) && (serialKey != m_serialKey)) {
m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (serialKey);
}
}
void SubscriptionManager::notifySkip()
{
notifyActivation ("skip:unknown");
}
void SubscriptionManager::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);
}

View File

@ -19,6 +19,7 @@
#include <QObject>
#include <SerialKey.h>
#include <ActivationNotifier.h>
class AppConfig;
@ -29,11 +30,16 @@ class SubscriptionManager: public QObject
public:
SubscriptionManager (AppConfig* appConfig);
void setSerialKey (QString serialKey);
void notifySkip ();
private:
void notifyActivation (QString identity);
private:
AppConfig* m_AppConfig;
SerialKey m_serialKey;
signals:
void serialKeyChanged (SerialKey);
void editionChanged (Edition);
};

View File

@ -35,12 +35,12 @@ public:
bool isExpired(time_t currentTime) const;
bool isTrial() const;
time_t daysLeft(time_t currentTime) const;
Edition edition() const;
Edition edition() const;
private:
std::string decode(const std::string& serial) const;
void parse(std::string plainSerial);
Edition getEdition(std::string editionStr);
Edition getEdition(std::string editionStr);
#ifdef TEST_ENV
private:
@ -60,7 +60,7 @@ private:
unsigned m_userLimit;
unsigned long long m_warnTime;
unsigned long long m_expireTime;
Edition m_edition;
Edition m_edition;
bool m_trial;
bool m_valid;
};