/src/MEGASync/gui/OverQuotaDialog.cpp

https://github.com/meganz/MEGAsync · C++ · 131 lines · 120 code · 11 blank · 0 comment · 18 complexity · efa610bc7363624c5c860daeee71a586 MD5 · raw file

  1. #include "OverQuotaDialog.h"
  2. #include "ui_OverQuotaDialog.h"
  3. #include "mega/types.h"
  4. #include "Utilities.h"
  5. #include <QtConcurrent/QtConcurrent>
  6. #include <QDesktopServices>
  7. OverQuotaDialog::OverQuotaDialog(OverQuotaDialogType type, QWidget *parent) :
  8. QDialog(parent),
  9. ui(new Ui::OverquotaFullDialog)
  10. {
  11. ui->setupUi(this);
  12. ui->labelTitle->setWordWrap(false);
  13. setAttribute(Qt::WA_QuitOnClose, false);
  14. #ifndef __APPLE__
  15. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  16. #endif
  17. connect(ui->buttonDismiss, &QPushButton::clicked, this, &QDialog::reject);
  18. connect(ui->buttonUpgrade, &QPushButton::clicked, this, &OverQuotaDialog::onUpgradeClicked);
  19. connect(ui->labelTitle, &CustomLabel::labelSizeChange, this, &OverQuotaDialog::onTitleLengthChanged);
  20. configureDialog(type);
  21. }
  22. OverQuotaDialog::~OverQuotaDialog()
  23. {
  24. delete ui;
  25. }
  26. std::unique_ptr<OverQuotaDialog> OverQuotaDialog::createDialog(OverQuotaDialogType type)
  27. {
  28. return mega::make_unique<OverQuotaDialog>(type);
  29. }
  30. void OverQuotaDialog::configureDialog(OverQuotaDialogType type)
  31. {
  32. const auto styleLabelAperture{QString::fromUtf8("<p style=\"line-height: 20px;\">")};
  33. const auto styleLabelClosure{QString::fromUtf8("</p>")};
  34. const auto storageFullTitle{tr("Storage full")};
  35. const auto transferQuotaDepletedTitle{tr("Depleted transfer quota")};
  36. if(type == OverQuotaDialogType::STORAGE_SYNCS)
  37. {
  38. setWindowTitle(storageFullTitle);
  39. ui->labelTitle->setText(tr("Syncs are temporarily disabled."));
  40. ui->labelMessage->setText(styleLabelAperture + tr("You have exceeded the available storage space for your account."
  41. " You can add syncs but they will remain disabled until there is enough space"
  42. " on your account.")
  43. + styleLabelClosure);
  44. ui->buttonUpgrade->setText(tr("Buy more space"));
  45. ui->stackedWidgetBigIcons->setCurrentWidget(ui->pageStorageFull);
  46. }
  47. else if(type == OverQuotaDialogType::STORAGE_UPLOAD)
  48. {
  49. setWindowTitle(storageFullTitle);
  50. ui->labelTitle->setText(tr("Uploads are temporarily disabled."));
  51. ui->labelMessage->setText(styleLabelAperture + tr("You have exceeded the available storage space for your account."
  52. " You can add uploads but transfers will remain queued until there is enough space"
  53. " on your account.")
  54. + styleLabelClosure);
  55. ui->buttonUpgrade->setText(tr("Buy more space"));
  56. ui->stackedWidgetBigIcons->setCurrentWidget(ui->pageStorageFull);
  57. }
  58. else if(type == OverQuotaDialogType::BANDWITH_SYNC)
  59. {
  60. setWindowTitle(transferQuotaDepletedTitle);
  61. ui->labelTitle->setText(tr("Syncs are temporarily disabled."));
  62. ui->labelMessage->setText(styleLabelAperture + tr("You have exceeded the available transfer quota for your account."
  63. " You can add syncs but they will remain disable until there is enough bandwidth"
  64. " on your account.")
  65. + styleLabelClosure);
  66. ui->buttonUpgrade->setText(tr("Upgrade Account"));
  67. ui->stackedWidgetBigIcons->setCurrentWidget(ui->pageBandwidthFull);
  68. }
  69. else if(type == OverQuotaDialogType::BANDWIDTH_IMPORT_LINK)
  70. {
  71. setWindowTitle(transferQuotaDepletedTitle);
  72. ui->labelTitle->setText(tr("Importing links is temporarily disabled."));
  73. ui->labelMessage->setText(styleLabelAperture + tr("You have exceeded the available transfer quota for your account."
  74. " You can import links but transfers will remain queued until there is enough bandwidth"
  75. " on your account.")
  76. + styleLabelClosure);
  77. ui->buttonUpgrade->setText(tr("Upgrade Account"));
  78. ui->stackedWidgetBigIcons->setCurrentWidget(ui->pageBandwidthFull);
  79. }
  80. else if(type == OverQuotaDialogType::BANDWIDTH_DOWNLOAD)
  81. {
  82. setWindowTitle(transferQuotaDepletedTitle);
  83. ui->labelTitle->setText(tr("Downloads are temporarily disabled."));
  84. ui->labelMessage->setText(styleLabelAperture + tr("You have exceeded the available transfer quota for your account."
  85. " You can add downloads but transfers will remain queued until there is enough bandwidth"
  86. " on your account.")
  87. + styleLabelClosure);
  88. ui->buttonUpgrade->setText(tr("Upgrade Account"));
  89. ui->stackedWidgetBigIcons->setCurrentWidget(ui->pageBandwidthFull);
  90. }
  91. else if(type == OverQuotaDialogType::BANDWIDTH_STREAM)
  92. {
  93. setWindowTitle(transferQuotaDepletedTitle);
  94. ui->labelTitle->setText(tr("Streams are temporarily disabled."));
  95. ui->labelMessage->setText(styleLabelAperture + tr("You have exceeded the available transfer quota for your account."
  96. " You can add streams but transfers will remain queued until there is enough bandwidth"
  97. " on your account.")
  98. + styleLabelClosure);
  99. ui->buttonUpgrade->setText(tr("Upgrade Account"));
  100. ui->stackedWidgetBigIcons->setCurrentWidget(ui->pageBandwidthFull);
  101. }
  102. }
  103. void OverQuotaDialog::onUpgradeClicked()
  104. {
  105. auto url{QString::fromUtf8("mega://#pro")};
  106. Utilities::getPROurlWithParameters(url);
  107. QtConcurrent::run(QDesktopServices::openUrl, QUrl(url));
  108. QDialog::accept();
  109. }
  110. void OverQuotaDialog::onTitleLengthChanged()
  111. {
  112. int sizeLimitToWrap = ui->widgetHeader->width() - ui->buttonWarning->width() - ui->widgetHeader->layout()->spacing();
  113. #ifndef Q_OS_MACOS
  114. sizeLimitToWrap -= ui->widgetHeader->layout()->contentsMargins().left() + ui->widgetHeader->layout()->contentsMargins().right();
  115. #endif
  116. if(ui->labelTitle->width() >= sizeLimitToWrap)
  117. {
  118. ui->labelTitle->setWordWrap(true);
  119. }
  120. }