2018-12-25 15:34:59 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/RsAutoUpdatePage.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (c) 2009 Retroshare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2009-11-17 07:45:06 -05:00
|
|
|
#include <QTimer>
|
2020-08-18 08:43:45 -04:00
|
|
|
|
|
|
|
#include <retroshare-gui/RsAutoUpdatePage.h>
|
2009-11-17 07:45:06 -05:00
|
|
|
|
2010-04-19 17:50:03 -04:00
|
|
|
bool RsAutoUpdatePage::_locked = false ;
|
|
|
|
|
2012-02-17 05:03:38 -05:00
|
|
|
RsAutoUpdatePage::RsAutoUpdatePage(int ms_update_period, QWidget *parent, Qt::WindowFlags flags)
|
|
|
|
: MainPage(parent, flags)
|
2009-11-17 07:45:06 -05:00
|
|
|
{
|
2013-06-21 20:05:02 -04:00
|
|
|
mUpdateWhenInvisible = false;
|
|
|
|
|
2009-11-17 07:45:06 -05:00
|
|
|
_timer = new QTimer ;
|
2010-07-20 15:45:07 -04:00
|
|
|
_timer->setInterval(ms_update_period);
|
|
|
|
_timer->setSingleShot(true);
|
2009-11-17 07:45:06 -05:00
|
|
|
|
|
|
|
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(timerUpdate())) ;
|
|
|
|
|
2010-07-20 15:45:07 -04:00
|
|
|
_timer->start() ;
|
2009-11-17 07:45:06 -05:00
|
|
|
}
|
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
RsAutoUpdatePage::~RsAutoUpdatePage()
|
|
|
|
{
|
|
|
|
if(_timer != NULL)
|
|
|
|
delete _timer ;
|
|
|
|
|
|
|
|
_timer = NULL ;
|
|
|
|
}
|
|
|
|
|
2013-05-21 08:55:03 -04:00
|
|
|
void RsAutoUpdatePage::securedUpdateDisplay()
|
|
|
|
{
|
2013-06-21 20:05:02 -04:00
|
|
|
if(_locked == false && (mUpdateWhenInvisible || isVisible())) {
|
2013-05-21 08:55:03 -04:00
|
|
|
updateDisplay();
|
|
|
|
update() ; // Qt flush
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 10:06:29 -04:00
|
|
|
void RsAutoUpdatePage::showEvent(QShowEvent */*event*/)
|
2009-11-17 07:45:06 -05:00
|
|
|
{
|
2013-06-21 20:05:02 -04:00
|
|
|
//std::cout << "RsAutoUpdatePage::showEvent() In show event !!" << std::endl ;
|
|
|
|
if(!_locked && !mUpdateWhenInvisible)
|
2010-04-19 17:50:03 -04:00
|
|
|
updateDisplay();
|
2009-11-17 07:45:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RsAutoUpdatePage::timerUpdate()
|
|
|
|
{
|
|
|
|
// only update when the widget is visible.
|
|
|
|
//
|
2013-05-21 08:55:03 -04:00
|
|
|
securedUpdateDisplay() ;
|
2010-07-20 15:45:07 -04:00
|
|
|
_timer->start() ;
|
2009-11-17 07:45:06 -05:00
|
|
|
}
|
|
|
|
|
2010-04-19 17:50:03 -04:00
|
|
|
void RsAutoUpdatePage::lockAllEvents() { _locked = true ; }
|
|
|
|
void RsAutoUpdatePage::unlockAllEvents() { _locked = false ; }
|
|
|
|
bool RsAutoUpdatePage::eventsLocked() { return _locked ; }
|
2013-05-21 08:55:03 -04:00
|
|
|
|