File indexing completed on 2024-05-05 05:40:57

0001 /***************************************************************************
0002  *   Copyright (C) 2011 by Renaud Guezennec                                *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   Rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #include "connectionretrydialog.h"
0022 #include "ui_connectionretrydialog.h"
0023 
0024 #define DEFAULT_TIMEOUT 11
0025 #define DEFAULT_INTERVAL 1000
0026 
0027 ConnectionRetryDialog::ConnectionRetryDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ConnectionRetryDialog)
0028 {
0029     ui->setupUi(this);
0030     m_timer= new QTimer(this);
0031     m_counter= DEFAULT_TIMEOUT;
0032     m_timeoutValue= DEFAULT_INTERVAL;
0033     m_timer->setInterval(m_timeoutValue);
0034     m_msg= tr("Connection has failed! Connection Retry in %1s.");
0035     ui->m_label->setText(m_msg.arg(m_counter));
0036     connect(m_timer, SIGNAL(timeout()), this, SLOT(decreaseCounter()));
0037     connect(this, SIGNAL(rejected()), m_timer, SLOT(stop()));
0038 }
0039 
0040 ConnectionRetryDialog::~ConnectionRetryDialog()
0041 {
0042     delete ui;
0043     delete m_timer;
0044 }
0045 void ConnectionRetryDialog::resetCounter()
0046 {
0047     m_counter= DEFAULT_TIMEOUT;
0048 }
0049 
0050 void ConnectionRetryDialog::startTimer()
0051 {
0052     m_timer->start();
0053 }
0054 void ConnectionRetryDialog::setTimeOut(int timeout)
0055 {
0056     m_timeoutValue= timeout;
0057     m_timer->setInterval(m_timeoutValue);
0058 }
0059 void ConnectionRetryDialog::decreaseCounter()
0060 {
0061     --m_counter;
0062     ui->m_label->setText(m_msg.arg(m_counter));
0063     if(0 >= m_counter)
0064     {
0065         // emit tryConnection();
0066         accept();
0067         resetCounter();
0068     }
0069 }