diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index cd5785ff5..94e55ee7e 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -145,6 +145,7 @@ HEADERS += rshare.h \ gui/HelpDialog.h \ gui/LogoBar.h \ gui/xprogressbar.h \ + gui/RsAutoUpdatePage.h \ gui/plugins/PluginInterface.h \ gui/im_history/IMHistoryKeeper.h \ gui/im_history/IMHistoryReader.h \ @@ -359,6 +360,7 @@ SOURCES += main.cpp \ gui/StatisticDialog.cpp \ gui/MessagesDialog.cpp \ gui/MessagesPopupDialog.cpp \ + gui/RsAutoUpdatePage.cpp \ gui/im_history/IMHistoryKeeper.cpp \ gui/im_history/IMHistoryReader.cpp \ gui/im_history/IMHistoryItem.cpp \ diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index ab08a95c5..c576d5166 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -35,6 +35,7 @@ #include "msgs/ChanMsgDialog.h" #include "connect/ConfCertDialog.h" #include "profile/ProfileView.h" +#include "RsAutoUpdatePage.h" #include "gui/Preferences/rsharesettings.h" @@ -82,7 +83,7 @@ /** Constructor */ PeersDialog::PeersDialog(QWidget *parent) - : MainPage(parent), + : RsAutoUpdatePage(1000,parent), historyKeeper(Rshare::dataDirectory() + "/his1.xml") { /* Invoke the Qt Designer generated object setup routine */ @@ -221,14 +222,14 @@ void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point ) contextMnu.exec( mevent->globalPos() ); } - +void PeersDialog::updateDisplay() +{ + insertPeers() ; +} /* get the list of peers from the RsIface. */ void PeersDialog::insertPeers() { - if(!isVisible()) - return ; - std::list peers; std::list::iterator it; diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index 10ebb6177..a0a2f25b9 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -26,7 +26,7 @@ #include "chat/PopupChatDialog.h" -#include "mainpage.h" +#include "RsAutoUpdatePage.h" #include "ui_PeersDialog.h" #include "im_history/IMHistoryKeeper.h" @@ -37,7 +37,7 @@ class QTextEdit; class QTextCharFormat; class ChatDialog; -class PeersDialog : public MainPage +class PeersDialog : public RsAutoUpdatePage { Q_OBJECT @@ -52,6 +52,7 @@ public: void loadEmoticonsgroupchat(); // void setChatDialog(ChatDialog *cd); + virtual void updateDisplay() ; public slots: void insertPeers(); diff --git a/retroshare-gui/src/gui/RsAutoUpdatePage.cpp b/retroshare-gui/src/gui/RsAutoUpdatePage.cpp new file mode 100644 index 000000000..8a03282c4 --- /dev/null +++ b/retroshare-gui/src/gui/RsAutoUpdatePage.cpp @@ -0,0 +1,31 @@ +#include +#include +#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 +} + diff --git a/retroshare-gui/src/gui/RsAutoUpdatePage.h b/retroshare-gui/src/gui/RsAutoUpdatePage.h new file mode 100644 index 000000000..b60447a8c --- /dev/null +++ b/retroshare-gui/src/gui/RsAutoUpdatePage.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#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 ; +}; diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index b590a21d9..43254c36a 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -47,7 +47,7 @@ /** Constructor */ TransfersDialog::TransfersDialog(QWidget *parent) -: MainPage(parent) +: RsAutoUpdatePage(1000,parent) { /* Invoke the Qt Designer generated object setup routine */ 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. **/ void TransfersDialog::insertTransfers() { - if(!isVisible()) - return ; - QString symbol, name, sources, status, coreId; qlonglong fileSize, completed, remaining; double progress, dlspeed; diff --git a/retroshare-gui/src/gui/TransfersDialog.h b/retroshare-gui/src/gui/TransfersDialog.h index a46d7a890..6c77e0d54 100644 --- a/retroshare-gui/src/gui/TransfersDialog.h +++ b/retroshare-gui/src/gui/TransfersDialog.h @@ -29,7 +29,7 @@ #include #include -#include "mainpage.h" +#include "RsAutoUpdatePage.h" #include "ui_TransfersDialog.h" @@ -37,7 +37,7 @@ class DLListDelegate; class ULListDelegate; class QStandardItemModel; -class TransfersDialog : public MainPage +class TransfersDialog : public RsAutoUpdatePage { Q_OBJECT @@ -49,6 +49,7 @@ class TransfersDialog : public MainPage virtual void keyPressEvent(QKeyEvent *) ; + virtual void updateDisplay() ; public slots: void insertTransfers(); diff --git a/retroshare-gui/src/rsiface/notifyqt.cpp b/retroshare-gui/src/rsiface/notifyqt.cpp index 5598940c0..5486bebe1 100644 --- a/retroshare-gui/src/rsiface/notifyqt.cpp +++ b/retroshare-gui/src/rsiface/notifyqt.cpp @@ -165,17 +165,6 @@ void NotifyQt::UpdateGUI() // 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) ; static bool already_updated = false ; // these only update once at start because they may already have been set before