userregister.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "userregister.h"
  2. #include "jsondeploy.h"
  3. #include <qmessagebox.h>
  4. #include <QTimer>
  5. UserRegister::UserRegister(QWidget *parent)
  6. : QDialog(parent), m_isNetReplayCome(-1)
  7. {
  8. ui.setupUi(this);
  9. JsonDeploy::init();
  10. int status = JsonDeploy::getKeyValueFromNumSets(SOFT_STATUS);
  11. m_regeisterStatus = status;
  12. if (0 == status)
  13. {
  14. ui.status->setText(tr("Free Trial"));
  15. }
  16. else if (1 == status)
  17. {
  18. ui.status->setText(tr("Registered Version"));
  19. }
  20. else if (2 == status)
  21. {
  22. ui.status->setText(tr("License Expired"));
  23. }
  24. else if (3 == status)
  25. {
  26. ui.status->setText(tr("License Error"));
  27. }
  28. QString mac = JsonDeploy::getKeyValueFromSets("mac");
  29. ui.machineId->setText(mac);
  30. QString softKey = JsonDeploy::getKeyValueFromSets(SOFT_KEY);
  31. if (!softKey.isEmpty() && softKey != "0")
  32. {
  33. ui.licenceKey->setText(softKey);
  34. }
  35. }
  36. UserRegister::~UserRegister()
  37. {
  38. JsonDeploy::close();
  39. }
  40. //服务器返回而来的注册验证消息
  41. void UserRegister::slot_registerReplay(int code)
  42. {
  43. if (code == 1)
  44. {
  45. //如果是正版,给出正版提示。
  46. ui.status->setText(tr("Registered Version"));
  47. m_regeisterStatus = 1;
  48. }
  49. else
  50. {
  51. }
  52. m_isNetReplayCome = code;
  53. }
  54. void UserRegister::slot_register()
  55. {
  56. if (m_regeisterStatus == 1)
  57. {
  58. QMessageBox::warning(this, tr("Licence Key"), tr("It is already a registered version."));
  59. return;
  60. }
  61. if (ui.licenceKey->text().isEmpty())
  62. {
  63. QMessageBox::warning(this, tr("Licence Key"), tr("Please scanning the donation, Write your email address in the message area.\nYou will get the registration code!"));
  64. }
  65. else
  66. {
  67. QString key = ui.licenceKey->text();
  68. if (key.size() != 12)
  69. {
  70. QMessageBox::warning(this, tr("Licence Key"), tr("Please enter the correct registration code!"));
  71. return;
  72. }
  73. emit signSendRegisterKey(key);
  74. //QMessageBox::information(this, tr("Licence Key"), tr("Processing succeeded. We will process your registration code in the background. It may take 1-3 days."));
  75. QString oldKey = JsonDeploy::getKeyValueFromSets(SOFT_KEY);
  76. if (oldKey.isEmpty() || oldKey == "0" || oldKey != key)
  77. {
  78. JsonDeploy::updataKeyValueFromSets(SOFT_KEY, key);
  79. }
  80. QEventLoop loop(this);
  81. QTimer::singleShot(5000, &loop, SLOT(quit()));//创建单次定时器,槽函数为事件循环的退出函数
  82. loop.exec(QEventLoop::ExcludeUserInputEvents);
  83. //表示来了消息
  84. if (m_isNetReplayCome != -1)
  85. {
  86. if (m_isNetReplayCome == 1)
  87. {
  88. QMessageBox::information(this, tr("Licence Key"), tr("Congratulations on your successful registration."));
  89. }
  90. else
  91. {
  92. QMessageBox::information(this, tr("Licence Key"), tr("Registration failed. Please try again later."));
  93. }
  94. }
  95. else
  96. {
  97. QMessageBox::information(this, tr("Licence Key"), tr("Registration failed. Please try again later."));
  98. }
  99. }
  100. }