added update every 5 mins to account for changes when sleeping

This commit is contained in:
csoler 2019-08-20 21:27:59 +02:00
parent 6a62227dba
commit a75a4945ec
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 29 additions and 28 deletions

View File

@ -46,6 +46,7 @@
std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
const QString RsFriendListModel::FilterString("filtered");
const uint32_t MAX_INTERNAL_DATA_UPDATE_DELAY = 300 ; // re-update the internal data every 5 mins. Should properly cover sleep/wake-up changes.
static const uint32_t NODE_DETAILS_UPDATE_DELAY = 5; // update each node every 5 secs.
@ -694,8 +695,19 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const
}
}
// This function makes sure that the internal data gets updated. They are situations where the otification system cannot
// send the information about changes, such as when the computer is put on sleep.
void RsFriendListModel::checkInternalData()
{
if(mLastInternalDataUpdate + MAX_INTERNAL_DATA_UPDATE_DELAY < time(NULL))
updateInternalData();
}
const RsFriendListModel::HierarchicalGroupInformation *RsFriendListModel::getGroupInfo(const EntryIndex& e) const
{
const_cast<RsFriendListModel*>(this)->checkInternalData();
if(e.group_index >= mGroups.size())
return NULL ;
else
@ -704,6 +716,8 @@ const RsFriendListModel::HierarchicalGroupInformation *RsFriendListModel::getGro
const RsFriendListModel::HierarchicalProfileInformation *RsFriendListModel::getProfileInfo(const EntryIndex& e) const
{
const_cast<RsFriendListModel*>(this)->checkInternalData();
// First look into the relevant group, then for the correct profile in this group.
if(e.type != ENTRY_TYPE_PROFILE)
@ -724,6 +738,8 @@ const RsFriendListModel::HierarchicalProfileInformation *RsFriendListModel::getP
const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getNodeInfo(const EntryIndex& e) const
{
const_cast<RsFriendListModel*>(this)->checkInternalData();
if(e.type != ENTRY_TYPE_NODE)
return NULL ;
@ -771,19 +787,6 @@ bool RsFriendListModel::getPeerOnlineStatus(const EntryIndex& e) const
return (noded && (noded->node_info.state & RS_PEER_STATE_CONNECTED));
}
QVariant RsFriendListModel::userRole(const EntryIndex& fmpe,int col) const
{
// switch(col)
// {
// case COLUMN_THREAD_AUTHOR: return QVariant(QString::fromStdString(fmpe.srcId.toStdString()));
// case COLUMN_THREAD_MSGID: return QVariant(QString::fromStdString(fmpe.msgId));
// default:
// return QVariant();
// }
return QVariant();
}
QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) const
{
if(col > 0)
@ -1084,6 +1087,8 @@ void RsFriendListModel::updateInternalData()
endInsertRows();
postMods();
mLastInternalDataUpdate = time(NULL);
}

View File

@ -149,7 +149,7 @@ public:
private:
const HierarchicalGroupInformation *getGroupInfo (const EntryIndex&) const;
const HierarchicalProfileInformation *getProfileInfo(const EntryIndex&) const;
const HierarchicalProfileInformation *getProfileInfo(const EntryIndex&)const;
const HierarchicalNodeInformation *getNodeInfo(const EntryIndex&) const;
bool getPeerOnlineStatus(const EntryIndex& e) const;
@ -162,7 +162,6 @@ private:
QVariant displayRole (const EntryIndex& e, int col) const;
QVariant decorationRole(const EntryIndex& e, int col) const;
QVariant toolTipRole (const EntryIndex& e, int col) const;
QVariant userRole (const EntryIndex& e, int col) const;
QVariant statusRole (const EntryIndex& e, int col) const;
QVariant sortRole (const EntryIndex& e, int col) const;
QVariant fontRole (const EntryIndex& e, int col) const;
@ -186,6 +185,7 @@ signals:
private:
bool passesFilter(const EntryIndex &e, int column) const;
void checkInternalData();
void preMods() ;
void postMods() ;
@ -204,6 +204,7 @@ private:
bool mDisplayGroups ;
bool mDisplayStatusString ;
rstime_t mLastInternalDataUpdate;
// The 3 vectors below store thehierarchical information for groups, profiles and locations,
// meaning which is the child/parent of which. The actual group/profile/node data are also stored in the

View File

@ -178,7 +178,7 @@ NewFriendList::NewFriendList(QWidget *parent) : QWidget(parent), ui(new Ui::NewF
ui->filterLineEdit->addFilter(QIcon(), headerText, RsFriendListModel::COLUMN_THREAD_NAME, QString("%1 %2").arg(tr("Search"), headerText));
ui->filterLineEdit->addFilter(QIcon(), tr("ID"), RsFriendListModel::COLUMN_THREAD_ID, tr("Search ID"));
mActionSortByState = new QAction(tr("Display online friends on top"), this);
mActionSortByState = new QAction(tr("Online friends on top"), this);
mActionSortByState->setCheckable(true);
//setting default filter by column as subject
@ -191,10 +191,7 @@ NewFriendList::NewFriendList(QWidget *parent) : QWidget(parent), ui(new Ui::NewF
// workaround for Qt bug, should be solved in next Qt release 4.7.0
// http://bugreports.qt.nokia.com/browse/QTBUG-8270
QShortcut *Shortcut = new QShortcut(QKeySequence(Qt::Key_Delete), ui->peerTreeWidget, 0, 0, Qt::WidgetShortcut);
/* Initialize tree */
// ui->peerTreeWidget->enableColumnCustomize(true);
// ui->peerTreeWidget->setColumnCustomizable(COLUMN_NAME, false);
connect(Shortcut, SIGNAL(activated()), this, SLOT(removefriend()));
QFontMetricsF fontMetrics(ui->peerTreeWidget->font());
@ -216,7 +213,6 @@ NewFriendList::NewFriendList(QWidget *parent) : QWidget(parent), ui(new Ui::NewF
QHeaderView *h = ui->peerTreeWidget->header();
h->setContextMenuPolicy(Qt::CustomContextMenu);
connect(Shortcut, SIGNAL(activated()), this, SLOT(removefriend()));
connect(ui->peerTreeWidget->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder)));
connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(toggleSortByState(bool)));
connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu()));
@ -227,7 +223,6 @@ NewFriendList::NewFriendList(QWidget *parent) : QWidget(parent), ui(new Ui::NewF
connect(ui->actionShowOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setShowUnconnected(bool)));
connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool)));
connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool)));
connect(ui->actionExportFriendlist, SIGNAL(triggered()), this, SLOT(exportFriendlistClicked()));
connect(ui->actionImportFriendlist, SIGNAL(triggered()), this, SLOT(importFriendlistClicked()));
@ -317,9 +312,8 @@ void NewFriendList::headerContextMenuRequested(QPoint p)
void NewFriendList::addToolButton(QToolButton *toolButton)
{
if (!toolButton) {
if (!toolButton)
return;
}
/* Initialize button */
toolButton->setAutoRaise(true);
@ -334,9 +328,8 @@ void NewFriendList::processSettings(bool load)
{
// state of peer tree
if (load) {
// load settings
if (load) // load settings
{
// states
setShowUnconnected(!Settings->value("hideUnconnected", mProxyModel->showOfflineNodes()).toBool());
setShowState(Settings->value("showState", mModel->getDisplayStatusString()).toBool());
@ -366,7 +359,9 @@ void NewFriendList::processSettings(bool load)
std::cerr << "(EE) Cannot find group info for openned group \"" << gids << "\"" << std::endl;
}
Settings->endArray();
} else {
}
else
{
// save settings
// states