mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-13 16:45:49 -04:00
added RsAutoUpdatePage and converted PeersDialog and Transfers Dialog to this, to reduce CPU usage.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.4.x@1834 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2fd09506bc
commit
47076a3615
8 changed files with 83 additions and 24 deletions
|
@ -145,6 +145,7 @@ HEADERS += rshare.h \
|
||||||
gui/HelpDialog.h \
|
gui/HelpDialog.h \
|
||||||
gui/LogoBar.h \
|
gui/LogoBar.h \
|
||||||
gui/xprogressbar.h \
|
gui/xprogressbar.h \
|
||||||
|
gui/RsAutoUpdatePage.h \
|
||||||
gui/plugins/PluginInterface.h \
|
gui/plugins/PluginInterface.h \
|
||||||
gui/im_history/IMHistoryKeeper.h \
|
gui/im_history/IMHistoryKeeper.h \
|
||||||
gui/im_history/IMHistoryReader.h \
|
gui/im_history/IMHistoryReader.h \
|
||||||
|
@ -359,6 +360,7 @@ SOURCES += main.cpp \
|
||||||
gui/StatisticDialog.cpp \
|
gui/StatisticDialog.cpp \
|
||||||
gui/MessagesDialog.cpp \
|
gui/MessagesDialog.cpp \
|
||||||
gui/MessagesPopupDialog.cpp \
|
gui/MessagesPopupDialog.cpp \
|
||||||
|
gui/RsAutoUpdatePage.cpp \
|
||||||
gui/im_history/IMHistoryKeeper.cpp \
|
gui/im_history/IMHistoryKeeper.cpp \
|
||||||
gui/im_history/IMHistoryReader.cpp \
|
gui/im_history/IMHistoryReader.cpp \
|
||||||
gui/im_history/IMHistoryItem.cpp \
|
gui/im_history/IMHistoryItem.cpp \
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "msgs/ChanMsgDialog.h"
|
#include "msgs/ChanMsgDialog.h"
|
||||||
#include "connect/ConfCertDialog.h"
|
#include "connect/ConfCertDialog.h"
|
||||||
#include "profile/ProfileView.h"
|
#include "profile/ProfileView.h"
|
||||||
|
#include "RsAutoUpdatePage.h"
|
||||||
|
|
||||||
|
|
||||||
#include "gui/Preferences/rsharesettings.h"
|
#include "gui/Preferences/rsharesettings.h"
|
||||||
|
@ -82,7 +83,7 @@
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
PeersDialog::PeersDialog(QWidget *parent)
|
PeersDialog::PeersDialog(QWidget *parent)
|
||||||
: MainPage(parent),
|
: RsAutoUpdatePage(1000,parent),
|
||||||
historyKeeper(Rshare::dataDirectory() + "/his1.xml")
|
historyKeeper(Rshare::dataDirectory() + "/his1.xml")
|
||||||
{
|
{
|
||||||
/* Invoke the Qt Designer generated object setup routine */
|
/* Invoke the Qt Designer generated object setup routine */
|
||||||
|
@ -221,14 +222,14 @@ void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point )
|
||||||
contextMnu.exec( mevent->globalPos() );
|
contextMnu.exec( mevent->globalPos() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PeersDialog::updateDisplay()
|
||||||
|
{
|
||||||
|
insertPeers() ;
|
||||||
|
}
|
||||||
|
|
||||||
/* get the list of peers from the RsIface. */
|
/* get the list of peers from the RsIface. */
|
||||||
void PeersDialog::insertPeers()
|
void PeersDialog::insertPeers()
|
||||||
{
|
{
|
||||||
if(!isVisible())
|
|
||||||
return ;
|
|
||||||
|
|
||||||
std::list<std::string> peers;
|
std::list<std::string> peers;
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
#include "chat/PopupChatDialog.h"
|
#include "chat/PopupChatDialog.h"
|
||||||
|
|
||||||
#include "mainpage.h"
|
#include "RsAutoUpdatePage.h"
|
||||||
#include "ui_PeersDialog.h"
|
#include "ui_PeersDialog.h"
|
||||||
|
|
||||||
#include "im_history/IMHistoryKeeper.h"
|
#include "im_history/IMHistoryKeeper.h"
|
||||||
|
@ -37,7 +37,7 @@ class QTextEdit;
|
||||||
class QTextCharFormat;
|
class QTextCharFormat;
|
||||||
class ChatDialog;
|
class ChatDialog;
|
||||||
|
|
||||||
class PeersDialog : public MainPage
|
class PeersDialog : public RsAutoUpdatePage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ public:
|
||||||
void loadEmoticonsgroupchat();
|
void loadEmoticonsgroupchat();
|
||||||
// void setChatDialog(ChatDialog *cd);
|
// void setChatDialog(ChatDialog *cd);
|
||||||
|
|
||||||
|
virtual void updateDisplay() ;
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void insertPeers();
|
void insertPeers();
|
||||||
|
|
31
retroshare-gui/src/gui/RsAutoUpdatePage.cpp
Normal file
31
retroshare-gui/src/gui/RsAutoUpdatePage.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <QTimer>
|
||||||
|
#include "RsAutoUpdatePage.h"
|
||||||
|
|
||||||
|
RsAutoUpdatePage::RsAutoUpdatePage(int ms_update_period,QWidget *parent)
|
||||||
|
: MainPage(parent)
|
||||||
|
{
|
||||||
|
_timer = new QTimer ;
|
||||||
|
|
||||||
|
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(timerUpdate())) ;
|
||||||
|
|
||||||
|
_timer->start(ms_update_period) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsAutoUpdatePage::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
std::cout << "In show event !!" << std::endl ;
|
||||||
|
updateDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsAutoUpdatePage::timerUpdate()
|
||||||
|
{
|
||||||
|
// only update when the widget is visible.
|
||||||
|
//
|
||||||
|
if(!isVisible())
|
||||||
|
return ;
|
||||||
|
|
||||||
|
updateDisplay() ;
|
||||||
|
update() ; // Qt flush
|
||||||
|
}
|
||||||
|
|
33
retroshare-gui/src/gui/RsAutoUpdatePage.h
Normal file
33
retroshare-gui/src/gui/RsAutoUpdatePage.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QWidget>
|
||||||
|
#include "mainpage.h"
|
||||||
|
|
||||||
|
// This class implement a basic RS functionality which is that widgets displayign info
|
||||||
|
// should update regularly. They also should update only when visible, to save CPU time.
|
||||||
|
//
|
||||||
|
// Using this class simply needs to derive your widget from RsAutoUpdatePage
|
||||||
|
// and oveload the update() function with the actual code that updates the
|
||||||
|
// widget.
|
||||||
|
//
|
||||||
|
class QTimer ;
|
||||||
|
|
||||||
|
class RsAutoUpdatePage: public MainPage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
RsAutoUpdatePage(int ms_update_period = 1000,QWidget *parent=NULL) ;
|
||||||
|
|
||||||
|
virtual void updateDisplay() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void showEvent(QShowEvent *e) ;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void timerUpdate() ;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer *_timer ;
|
||||||
|
};
|
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
TransfersDialog::TransfersDialog(QWidget *parent)
|
TransfersDialog::TransfersDialog(QWidget *parent)
|
||||||
: MainPage(parent)
|
: RsAutoUpdatePage(1000,parent)
|
||||||
{
|
{
|
||||||
/* Invoke the Qt Designer generated object setup routine */
|
/* Invoke the Qt Designer generated object setup routine */
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
@ -381,12 +381,13 @@ void TransfersDialog::editItem(int row, int column, QVariant data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TransfersDialog::updateDisplay()
|
||||||
|
{
|
||||||
|
insertTransfers();
|
||||||
|
}
|
||||||
/* get the list of Transfers from the RsIface. **/
|
/* get the list of Transfers from the RsIface. **/
|
||||||
void TransfersDialog::insertTransfers()
|
void TransfersDialog::insertTransfers()
|
||||||
{
|
{
|
||||||
if(!isVisible())
|
|
||||||
return ;
|
|
||||||
|
|
||||||
QString symbol, name, sources, status, coreId;
|
QString symbol, name, sources, status, coreId;
|
||||||
qlonglong fileSize, completed, remaining;
|
qlonglong fileSize, completed, remaining;
|
||||||
double progress, dlspeed;
|
double progress, dlspeed;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "mainpage.h"
|
#include "RsAutoUpdatePage.h"
|
||||||
#include "ui_TransfersDialog.h"
|
#include "ui_TransfersDialog.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class DLListDelegate;
|
||||||
class ULListDelegate;
|
class ULListDelegate;
|
||||||
class QStandardItemModel;
|
class QStandardItemModel;
|
||||||
|
|
||||||
class TransfersDialog : public MainPage
|
class TransfersDialog : public RsAutoUpdatePage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ class TransfersDialog : public MainPage
|
||||||
|
|
||||||
virtual void keyPressEvent(QKeyEvent *) ;
|
virtual void keyPressEvent(QKeyEvent *) ;
|
||||||
|
|
||||||
|
virtual void updateDisplay() ;
|
||||||
public slots:
|
public slots:
|
||||||
void insertTransfers();
|
void insertTransfers();
|
||||||
|
|
||||||
|
|
|
@ -165,17 +165,6 @@ void NotifyQt::UpdateGUI()
|
||||||
|
|
||||||
// std::cerr << "Got update signal t=" << lastTs << std::endl ;
|
// std::cerr << "Got update signal t=" << lastTs << std::endl ;
|
||||||
|
|
||||||
if (time(NULL) > lastTs) // always update, every 1 sec.
|
|
||||||
{
|
|
||||||
emit transfersChanged();
|
|
||||||
emit friendsChanged() ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time(NULL) > lastTs + 5) // update every 5 seconds. I don't know what to do with these.
|
|
||||||
{
|
|
||||||
// displayChannels();
|
|
||||||
}
|
|
||||||
|
|
||||||
lastTs = time(NULL) ;
|
lastTs = time(NULL) ;
|
||||||
|
|
||||||
static bool already_updated = false ; // these only update once at start because they may already have been set before
|
static bool already_updated = false ; // these only update once at start because they may already have been set before
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue