mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-28 10:32:22 -04:00
RsAutoUpdatePage
- Changed the timer of RsAutoUpdatePage to a single-shot timer. The update can take longer than the given timer interval. Changed status service: - send status when the peer connects (new monitor) - send status to all online peers only when user changed it (not in every timer tick) MessengerWindow: - remove load and save of custom state string in settings p3ChatService::sendCustomState - send empty custom state string too git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3307 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f7282edf33
commit
e3e4c97369
15 changed files with 145 additions and 133 deletions
|
@ -250,8 +250,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
|
|||
/** StatusBar section ********/
|
||||
/* initialize combobox in status bar */
|
||||
statusComboBox = new QComboBox(statusBar());
|
||||
initializeStatusObject(statusComboBox);
|
||||
connect(statusComboBox, SIGNAL(activated(int)), this, SLOT(statusChangedComboBox(int)));
|
||||
initializeStatusObject(statusComboBox, true);
|
||||
|
||||
QWidget *widget = new QWidget();
|
||||
QHBoxLayout *hbox = new QHBoxLayout();
|
||||
|
@ -295,7 +294,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
|
|||
/* Creates a tray icon with a context menu and adds it to the system's * notification area. */
|
||||
createTrayIcon();
|
||||
|
||||
loadOwnStatus(); // hack; placed in constructor to preempt sendstatus, so status loaded from file
|
||||
loadOwnStatus();
|
||||
|
||||
/* Set focus to the current page */
|
||||
ui.stackPages->currentWidget()->setFocus();
|
||||
|
@ -356,8 +355,7 @@ void MainWindow::createTrayIcon()
|
|||
trayMenu->addAction(QIcon(IMAGE_RETROSHARE), tr("Show/Hide"), this, SLOT(toggleVisibilitycontextmenu()));
|
||||
|
||||
QMenu *pStatusMenu = trayMenu->addMenu(tr("Status"));
|
||||
initializeStatusObject(pStatusMenu);
|
||||
connect(pStatusMenu, SIGNAL(triggered (QAction*)), this, SLOT(statusChanged(QAction*)));
|
||||
initializeStatusObject(pStatusMenu, true);
|
||||
|
||||
trayMenu->addSeparator();
|
||||
trayMenu->addAction(_messengerwindowAct);
|
||||
|
@ -830,27 +828,6 @@ void MainWindow::setStyle()
|
|||
|
||||
}
|
||||
|
||||
/* get own status */
|
||||
static int getOwnStatus()
|
||||
{
|
||||
std::string ownId = rsPeers->getOwnId();
|
||||
|
||||
StatusInfo si;
|
||||
std::list<StatusInfo> statusList;
|
||||
std::list<StatusInfo>::iterator it;
|
||||
|
||||
if (!rsStatus->getStatus(statusList)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (it = statusList.begin(); it != statusList.end(); it++){
|
||||
if (it->id == ownId)
|
||||
return it->status;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* set status object to status value */
|
||||
static void setStatusObject(QObject *pObject, int nStatus)
|
||||
{
|
||||
|
@ -888,10 +865,12 @@ void MainWindow::loadOwnStatus()
|
|||
{
|
||||
m_bStatusLoadDone = true;
|
||||
|
||||
int nStatus = getOwnStatus();
|
||||
|
||||
for (std::set <QObject*>::iterator it = m_apStatusObjects.begin(); it != m_apStatusObjects.end(); it++) {
|
||||
setStatusObject(*it, nStatus);
|
||||
StatusInfo statusInfo;
|
||||
if (rsStatus->getOwnStatus(statusInfo)) {
|
||||
/* send status to all added objects */
|
||||
for (std::set <QObject*>::iterator it = m_apStatusObjects.begin(); it != m_apStatusObjects.end(); it++) {
|
||||
setStatusObject(*it, statusInfo.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -899,8 +878,7 @@ void MainWindow::checkAndSetIdle(int idleTime)
|
|||
{
|
||||
if ((idleTime >= (int) maxTimeBeforeIdle) && !isIdle) {
|
||||
setIdle(true);
|
||||
}else
|
||||
if((idleTime < (int) maxTimeBeforeIdle) && isIdle) {
|
||||
} else if ((idleTime < (int) maxTimeBeforeIdle) && isIdle) {
|
||||
setIdle(false);
|
||||
}
|
||||
|
||||
|
@ -910,13 +888,18 @@ void MainWindow::checkAndSetIdle(int idleTime)
|
|||
void MainWindow::setIdle(bool idle)
|
||||
{
|
||||
isIdle = idle;
|
||||
setStatus(NULL, getOwnStatus());
|
||||
|
||||
StatusInfo statusInfo;
|
||||
if (rsStatus->getOwnStatus(statusInfo)) {
|
||||
setStatus(NULL, statusInfo.status);
|
||||
}
|
||||
}
|
||||
|
||||
/* add and initialize status object */
|
||||
void MainWindow::initializeStatusObject(QObject *pObject)
|
||||
void MainWindow::initializeStatusObject(QObject *pObject, bool bConnect)
|
||||
{
|
||||
if (m_apStatusObjects.find(pObject) != m_apStatusObjects.end()) {
|
||||
/* already added */
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -944,6 +927,10 @@ void MainWindow::initializeStatusObject(QObject *pObject)
|
|||
pAction->setCheckable(true);
|
||||
pMenu->addAction(pAction);
|
||||
pGroup->addAction(pAction);
|
||||
|
||||
if (bConnect) {
|
||||
connect(pMenu, SIGNAL(triggered (QAction*)), this, SLOT(statusChangedMenu(QAction*)));
|
||||
}
|
||||
} else {
|
||||
/* initialize combobox */
|
||||
QComboBox *pComboBox = dynamic_cast<QComboBox*>(pObject);
|
||||
|
@ -951,15 +938,19 @@ void MainWindow::initializeStatusObject(QObject *pObject)
|
|||
pComboBox->addItem(QIcon(":/images/im-user.png"), tr("Online"), RS_STATUS_ONLINE);
|
||||
pComboBox->addItem(QIcon(":/images/im-user-busy.png"), tr("Busy"), RS_STATUS_BUSY);
|
||||
pComboBox->addItem(QIcon(":/images/im-user-away.png"), tr("Away"), RS_STATUS_AWAY);
|
||||
|
||||
if (bConnect) {
|
||||
connect(pComboBox, SIGNAL(activated(int)), this, SLOT(statusChangedComboBox(int)));
|
||||
}
|
||||
}
|
||||
/* add more objects here */
|
||||
}
|
||||
|
||||
if (m_bStatusLoadDone) {
|
||||
/* loadOwnStatus done, set own status directly */
|
||||
int nStatus = getOwnStatus();
|
||||
if (nStatus != -1) {
|
||||
setStatusObject(pObject, nStatus);
|
||||
StatusInfo statusInfo;
|
||||
if (rsStatus->getOwnStatus(statusInfo)) {
|
||||
setStatusObject(pObject, statusInfo.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -968,29 +959,20 @@ void MainWindow::initializeStatusObject(QObject *pObject)
|
|||
void MainWindow::removeStatusObject(QObject *pObject)
|
||||
{
|
||||
m_apStatusObjects.erase(pObject);
|
||||
|
||||
/* disconnect all signals between the object and MainWindow */
|
||||
disconnect(pObject, NULL, this, NULL);
|
||||
}
|
||||
|
||||
/** Save own status Online,Away,Busy **/
|
||||
void MainWindow::setStatus(QObject *pObject, int nStatus)
|
||||
{
|
||||
RsPeerDetails detail;
|
||||
std::string ownId = rsPeers->getOwnId();
|
||||
|
||||
if (!rsPeers->getPeerDetails(ownId, detail)) {
|
||||
return;
|
||||
}
|
||||
|
||||
StatusInfo si;
|
||||
|
||||
if (isIdle && nStatus == (int) RS_STATUS_ONLINE) {
|
||||
/* set idle state only when I am in online state */
|
||||
/* set idle only when I am online */
|
||||
nStatus = RS_STATUS_INACTIVE;
|
||||
}
|
||||
|
||||
si.id = ownId;
|
||||
si.status = nStatus;
|
||||
|
||||
rsStatus->sendStatus(si);
|
||||
rsStatus->sendStatus("", nStatus);
|
||||
|
||||
/* set status in all status objects, but the calling one */
|
||||
for (std::set <QObject*>::iterator it = m_apStatusObjects.begin(); it != m_apStatusObjects.end(); it++) {
|
||||
|
@ -1001,7 +983,7 @@ void MainWindow::setStatus(QObject *pObject, int nStatus)
|
|||
}
|
||||
|
||||
/* new status from context menu */
|
||||
void MainWindow::statusChanged(QAction *pAction)
|
||||
void MainWindow::statusChangedMenu(QAction *pAction)
|
||||
{
|
||||
if (pAction == NULL) {
|
||||
return;
|
||||
|
@ -1017,5 +999,6 @@ void MainWindow::statusChangedComboBox(int index)
|
|||
return;
|
||||
}
|
||||
|
||||
setStatus(statusComboBox, statusComboBox->itemData(index, Qt::UserRole).toInt());
|
||||
/* no object known */
|
||||
setStatus(NULL, statusComboBox->itemData(index, Qt::UserRole).toInt());
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ public:
|
|||
static void installGroupChatNotifier();
|
||||
|
||||
/* initialize widget with status informations, status constant stored in data or in Qt::UserRole */
|
||||
void initializeStatusObject(QObject *pObject);
|
||||
void initializeStatusObject(QObject *pObject, bool bConnect);
|
||||
void removeStatusObject(QObject *pObject);
|
||||
void setStatus(QObject *pObject, int nStatus);
|
||||
|
||||
|
@ -181,7 +181,7 @@ private slots:
|
|||
void showMess();
|
||||
void showSettings();
|
||||
void setStyle();
|
||||
void statusChanged(QAction *pAction);
|
||||
void statusChangedMenu(QAction *pAction);
|
||||
void statusChangedComboBox(int index);
|
||||
|
||||
/** Called when user attempts to quit via quit button*/
|
||||
|
|
|
@ -163,16 +163,16 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
|
|||
connect(ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
|
||||
|
||||
connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage()));
|
||||
connect(ui.statuscomboBox, SIGNAL(activated(int)), this, SLOT(statusChanged(int)));
|
||||
connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
|
||||
|
||||
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateMessengerDisplay()));
|
||||
connect(NotifyQt::getInstance(), SIGNAL(ownAvatarChanged()), this, SLOT(updateAvatar()));
|
||||
connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage()));
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer = new QTimer(this);
|
||||
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateMessengerDisplay()));
|
||||
timer->start(1000); /* one second */
|
||||
timer->setInterval(1000); /* one second */
|
||||
timer->setSingleShot(true);
|
||||
|
||||
/* to hide the header */
|
||||
ui.messengertreeWidget->header()->hide();
|
||||
|
@ -208,7 +208,7 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
|
|||
|
||||
MainWindow *pMainWindow = MainWindow::getInstance();
|
||||
if (pMainWindow) {
|
||||
pMainWindow->initializeStatusObject(ui.statuscomboBox);
|
||||
pMainWindow->initializeStatusObject(ui.statuscomboBox, true);
|
||||
}
|
||||
insertPeers();
|
||||
updateAvatar();
|
||||
|
@ -383,18 +383,19 @@ void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point )
|
|||
|
||||
void MessengerWindow::updateMessengerDisplay()
|
||||
{
|
||||
if(RsAutoUpdatePage::eventsLocked())
|
||||
return ;
|
||||
if (RsAutoUpdatePage::eventsLocked() == false) {
|
||||
// add self nick and Avatar to Friends.
|
||||
RsPeerDetails pd ;
|
||||
RsPeerDetails pd;
|
||||
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),pd)) {
|
||||
|
||||
QString titleStr("<span style=\"font-size:14pt; font-weight:500;"
|
||||
"color:#FFFFFF;\">%1</span>");
|
||||
ui.nicklabel->setText(titleStr.arg(QString::fromStdString(pd.name) + tr(" - ") + QString::fromStdString(pd.location))) ;
|
||||
QString titleStr("<span style=\"font-size:14pt; font-weight:500;"
|
||||
"color:#FFFFFF;\">%1</span>");
|
||||
ui.nicklabel->setText(titleStr.arg(QString::fromStdString(pd.name) + tr(" - ") + QString::fromStdString(pd.location)));
|
||||
}
|
||||
|
||||
insertPeers();
|
||||
}
|
||||
|
||||
timer->start();
|
||||
}
|
||||
|
||||
/* get the list of peers from the RsIface. */
|
||||
|
@ -1008,21 +1009,7 @@ void MessengerWindow::loadmystatusmessage()
|
|||
/** Save own status message */
|
||||
void MessengerWindow::savestatusmessage()
|
||||
{
|
||||
Settings->setValueToGroup("Profile", "StatusMessage",ui.messagelineEdit->text());
|
||||
|
||||
rsMsgs->setCustomStateString(ui.messagelineEdit->text().toStdString());
|
||||
}
|
||||
|
||||
void MessengerWindow::statusChanged(int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MainWindow *pMainWindow = MainWindow::getInstance();
|
||||
if (pMainWindow) {
|
||||
pMainWindow->setStatus(ui.statuscomboBox, ui.statuscomboBox->itemData(index, Qt::UserRole).toInt());
|
||||
}
|
||||
rsMsgs->setCustomStateString(ui.messagelineEdit->text().toStdString());
|
||||
}
|
||||
|
||||
void MessengerWindow::on_actionSort_Peers_Descending_Order_activated()
|
||||
|
|
|
@ -88,7 +88,6 @@ private slots:
|
|||
|
||||
void changeAvatarClicked();
|
||||
|
||||
void statusChanged(int index);
|
||||
void savestatusmessage();
|
||||
|
||||
void on_actionSort_Peers_Descending_Order_activated();
|
||||
|
@ -110,6 +109,7 @@ private:
|
|||
|
||||
/* Worker Functions */
|
||||
/* (1) Update Display */
|
||||
QTimer *timer;
|
||||
|
||||
/* (2) Utility Fns */
|
||||
QTreeWidgetItem *getCurrentPeer();
|
||||
|
|
|
@ -1578,8 +1578,7 @@ void PeersDialog::on_actionCreate_New_Channel_activated()
|
|||
/** Loads own personal status */
|
||||
void PeersDialog::loadmypersonalstatus()
|
||||
{
|
||||
|
||||
ui.mypersonalstatuslabel->setText(QString::fromStdString(rsMsgs->getCustomStateString()));
|
||||
ui.mypersonalstatuslabel->setText(QString::fromStdString(rsMsgs->getCustomStateString()));
|
||||
}
|
||||
|
||||
void PeersDialog::statusmessage()
|
||||
|
|
|
@ -9,10 +9,12 @@ RsAutoUpdatePage::RsAutoUpdatePage(int ms_update_period,QWidget *parent)
|
|||
: MainPage(parent)
|
||||
{
|
||||
_timer = new QTimer ;
|
||||
_timer->setInterval(ms_update_period);
|
||||
_timer->setSingleShot(true);
|
||||
|
||||
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(timerUpdate())) ;
|
||||
|
||||
_timer->start(ms_update_period) ;
|
||||
_timer->start() ;
|
||||
}
|
||||
|
||||
void RsAutoUpdatePage::showEvent(QShowEvent *event)
|
||||
|
@ -26,11 +28,12 @@ void RsAutoUpdatePage::timerUpdate()
|
|||
{
|
||||
// only update when the widget is visible.
|
||||
//
|
||||
if(_locked || !isVisible())
|
||||
return ;
|
||||
|
||||
updateDisplay();
|
||||
update() ; // Qt flush
|
||||
if(_locked == false && isVisible()) {
|
||||
updateDisplay();
|
||||
update() ; // Qt flush
|
||||
}
|
||||
|
||||
_timer->start() ;
|
||||
}
|
||||
|
||||
void RsAutoUpdatePage::lockAllEvents() { _locked = true ; }
|
||||
|
|
|
@ -52,27 +52,19 @@ StatusMessage::~StatusMessage()
|
|||
{
|
||||
}
|
||||
|
||||
void StatusMessage::closeEvent (QCloseEvent * event)
|
||||
{
|
||||
QDialog::closeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
/** Saves the changes on this page */
|
||||
void StatusMessage::save()
|
||||
{
|
||||
Settings->setValueToGroup("Profile", "StatusMessage",ui.txt_StatusMessage->text());
|
||||
rsMsgs->setCustomStateString(ui.txt_StatusMessage->text().toStdString());
|
||||
|
||||
rsMsgs->setCustomStateString(ui.txt_StatusMessage->text().toStdString());
|
||||
|
||||
close();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
/** Loads the settings for this page */
|
||||
void StatusMessage::load()
|
||||
{
|
||||
ui.txt_StatusMessage->setText(QString::fromStdString(rsMsgs->getCustomStateString()));
|
||||
ui.txt_StatusMessage->setText(QString::fromStdString(rsMsgs->getCustomStateString()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,23 +31,19 @@ class StatusMessage : public QDialog
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
/** Default constructor */
|
||||
StatusMessage(QWidget *parent = 0, Qt::WFlags flags = 0);
|
||||
/** Default destructor */
|
||||
~StatusMessage();
|
||||
|
||||
protected:
|
||||
void closeEvent (QCloseEvent * event);
|
||||
|
||||
private slots:
|
||||
|
||||
/** Saves the changes on this page */
|
||||
void save();
|
||||
/** Loads the settings for this page */
|
||||
void load();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
/** Qt Designer generated object */
|
||||
Ui::StatusMessage ui;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue