Advertisement
Guest User

More work with timer

a guest
Apr 4th, 2020
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. diff --git a/src/mucjoindlg.cpp b/src/mucjoindlg.cpp
  2. index cf07d78c..479e396b 100644
  3. --- a/src/mucjoindlg.cpp
  4. +++ b/src/mucjoindlg.cpp
  5. @@ -35,6 +35,7 @@
  6.  
  7.  static const int     nickConflictCode = 409;
  8.  static const QString additionalSymbol = "_";
  9. +static const int     timeout          = 30000;
  10.  
  11.  MUCJoinDlg::MUCJoinDlg(PsiCon *psi, PsiAccount *pa) : QDialog(nullptr), nickAlreadyCompleted_(false)
  12.  {
  13. @@ -53,6 +54,10 @@ MUCJoinDlg::MUCJoinDlg(PsiCon *psi, PsiAccount *pa) : QDialog(nullptr), nickAlre
  14.      ui_.ck_history->hide();
  15.      joinButton_ = ui_.buttonBox->addButton(tr("&Join"), QDialogButtonBox::AcceptRole);
  16.      joinButton_->setDefault(true);
  17. +    timer_ = new QTimer(this);
  18. +    timer_->setInterval(timeout);
  19. +    connect(timer_, &QTimer::timeout, this,
  20. +            [this]() { error(404, tr("No response from server for %1 seconds").arg(timeout / 1000)); });
  21.  
  22.      reason_ = PsiAccount::MucCustomJoin;
  23.  
  24. @@ -269,6 +274,7 @@ void MUCJoinDlg::doJoin(PsiAccount::MucJoinReason r)
  25.      account_->dialogRegister(this, jid_);
  26.  
  27.      setWidgetsEnabled(false);
  28. +    timer_->start();
  29.      ui_.busy->start();
  30.  }
  31.  
  32. @@ -283,6 +289,8 @@ void MUCJoinDlg::setWidgetsEnabled(bool enabled)
  33.  void MUCJoinDlg::joined()
  34.  {
  35.      controller_->recentGCAdd(jid_.full());
  36. +    if (timer_->isActive())
  37. +        timer_->stop();
  38.      ui_.busy->stop();
  39.  
  40.      nickAlreadyCompleted_ = false;
  41. @@ -293,6 +301,8 @@ void MUCJoinDlg::joined()
  42.  
  43.  void MUCJoinDlg::error(int error, const QString &str)
  44.  {
  45. +    if (timer_->isActive())
  46. +        timer_->stop();
  47.      ui_.busy->stop();
  48.      setWidgetsEnabled(true);
  49.  
  50. diff --git a/src/mucjoindlg.h b/src/mucjoindlg.h
  51. index 90fe7c7f..52a89ecc 100644
  52. --- a/src/mucjoindlg.h
  53. +++ b/src/mucjoindlg.h
  54. @@ -25,6 +25,7 @@
  55.  #include "xmpp_jid.h"
  56.  
  57.  #include <QDialog>
  58. +#include <QTimer>
  59.  
  60.  class PsiCon;
  61.  class QString;
  62. @@ -67,6 +68,7 @@ private:
  63.      QPushButton *             joinButton_;
  64.      XMPP::Jid                 jid_;
  65.      PsiAccount::MucJoinReason reason_;
  66. +    QTimer *                  timer_;
  67.      bool                      nickAlreadyCompleted_;
  68.  
  69.      void disableWidgets();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement