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

View File

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

View File

@ -19,6 +19,7 @@
#include "EditionType.h" #include "EditionType.h"
#include "AppConfig.h" #include "AppConfig.h"
#include <ctime> #include <ctime>
#include <QThread>
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) : SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
m_AppConfig(appConfig) { m_AppConfig(appConfig) {
@ -30,6 +31,28 @@ SubscriptionManager::setSerialKey(QString serialKeyString)
SerialKey serialKey (serialKeyString.toStdString()); SerialKey serialKey (serialKeyString.toStdString());
if (serialKey.isValid (::time(0)) && (serialKey != m_serialKey)) { if (serialKey.isValid (::time(0)) && (serialKey != m_serialKey)) {
m_AppConfig->setSerialKey (serialKeyString); m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (serialKey); 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 <QObject>
#include <SerialKey.h> #include <SerialKey.h>
#include <ActivationNotifier.h>
class AppConfig; class AppConfig;
@ -29,6 +30,10 @@ class SubscriptionManager: public QObject
public: public:
SubscriptionManager (AppConfig* appConfig); SubscriptionManager (AppConfig* appConfig);
void setSerialKey (QString serialKey); void setSerialKey (QString serialKey);
void notifySkip ();
private:
void notifyActivation (QString identity);
private: private:
AppConfig* m_AppConfig; AppConfig* m_AppConfig;
@ -36,4 +41,5 @@ private:
signals: signals:
void serialKeyChanged (SerialKey); void serialKeyChanged (SerialKey);
void editionChanged (Edition);
}; };

View File

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