removed friendsChanged() and NOTIFY_LIST_FRIENDS

This commit is contained in:
csoler 2025-06-11 20:50:38 +02:00
parent 2edb3afc81
commit df02d745d8
14 changed files with 91 additions and 215 deletions

View file

@ -118,7 +118,7 @@ FriendServerControl::FriendServerControl(QWidget *parent)
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
{
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
}, mEventHandlerId_peer, RsEventType::PEER_CONNECTION );
}, mEventHandlerId_peer, RsEventType::PEER_STATE );
}
void FriendServerControl::onAutoAddFriends(bool b)

View file

@ -30,9 +30,10 @@
#include <QtDebug>
#include <QMenuBar>
#include <retroshare/rsplugin.h>
#include <retroshare/rsconfig.h>
#include <util/argstream.h>
#include "retroshare/rsplugin.h"
#include "retroshare/rsconfig.h"
#include "util/argstream.h"
#include "util/qtthreadsutils.h"
#if defined(Q_OS_DARWIN)
#include "gui/common/MacDockIconHandler.h"
@ -340,10 +341,27 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
createNotifyIcons();
/* calculate friend count */
/* intialize friend count */
updateFriends();
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateFriends()));
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateFriends()));
// connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateFriends()));
// connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateFriends()));
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
if(!fe)
return;
updateFriends();
}
, this );
}, mEventHandlerId, RsEventType::FRIEND_LIST );
loadOwnStatus();

View file

@ -25,6 +25,8 @@
#include <QSystemTrayIcon>
#include <set>
#include "retroshare/rsevents.h"
#include "gui/common/rwindow.h"
#include "gui/common/RSComboBox.h"
#include "util/FontSizeHandler.h"
@ -375,6 +377,8 @@ private:
FontSizeHandler mFontSizeHandler;
Ui::MainWindow *ui ;
RsEventsHandlerId_t mEventHandlerId;
};
#endif

View file

@ -76,7 +76,7 @@ static NewsFeed* instance = nullptr;
NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed),
mEventTypes({
RsEventType::AUTHSSL_CONNECTION_AUTENTICATION,
RsEventType::PEER_CONNECTION ,
RsEventType::FRIEND_LIST ,
RsEventType::GXS_CIRCLES ,
RsEventType::GXS_CHANNELS ,
RsEventType::GXS_FORUMS ,
@ -197,7 +197,7 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
if(event->mType == RsEventType::AUTHSSL_CONNECTION_AUTENTICATION && (flags & RS_FEED_TYPE_SECURITY))
handleSecurityEvent(event);
if(event->mType == RsEventType::PEER_CONNECTION && (flags & RS_FEED_TYPE_PEER))
if(event->mType == RsEventType::FRIEND_LIST && (flags & RS_FEED_TYPE_PEER))
handleConnectionEvent(event);
if(event->mType == RsEventType::GXS_CIRCLES && (flags & RS_FEED_TYPE_CIRCLE))
@ -428,7 +428,7 @@ void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event)
void NewsFeed::handleConnectionEvent(std::shared_ptr<const RsEvent> event)
{
const RsConnectionEvent *pe = dynamic_cast<const RsConnectionEvent*>(event.get());
const RsFriendListEvent *pe = dynamic_cast<const RsFriendListEvent*>(event.get());
if(!pe) return;
auto& e(*pe);
@ -437,18 +437,18 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr<const RsEvent> event)
std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl;
#endif
switch(e.mConnectionInfoCode)
switch(e.mEventCode)
{
case RsConnectionEventCode::PEER_CONNECTED:
case RsFriendListEventCode::NODE_CONNECTED:
addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true);
NotifyQt::getInstance()->addToaster(RS_POPUP_CONNECT, e.mSslId.toStdString().c_str(), "", "");
break;
case RsConnectionEventCode::PEER_DISCONNECTED: // not handled yet
case RsFriendListEventCode::NODE_DISCONNECTED: // not handled yet
break;
case RsConnectionEventCode::PEER_TIME_SHIFT:
case RsFriendListEventCode::NODE_TIME_SHIFT:
addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_OFFSET, false),false);
break;
case RsConnectionEventCode::PEER_REPORTS_WRONG_IP:
case RsFriendListEventCode::NODE_REPORTS_WRONG_IP:
addFeedItemIfUnique(new SecurityIpItem(
this, e.mSslId, e.mOwnLocator.toString(),
e.mReportedLocator.toString(),

View file

@ -134,7 +134,7 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent)
RsQThreadUtils::postToObject( [this,event]() { handleEvent_main_thread(event); }) ;}, mEventHandlerId_identities, RsEventType::GXS_IDENTITY );
mEventHandlerId_peers = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) {
RsQThreadUtils::postToObject( [this,event]() { handleEvent_main_thread(event); }) ;}, mEventHandlerId_peers, RsEventType::PEER_CONNECTION );
RsQThreadUtils::postToObject( [this,event]() { handleEvent_main_thread(event); }) ;}, mEventHandlerId_peers, RsEventType::FRIEND_LIST );
mFontSizeHandler.registerFontSize(ui->friendList);
}
@ -149,13 +149,13 @@ void FriendSelectionWidget::handleEvent_main_thread(std::shared_ptr<const RsEven
update(); // Qt flush
return;
}
const RsConnectionEvent *fp = dynamic_cast<const RsConnectionEvent*>(event.get());
const RsFriendListEvent *fp = dynamic_cast<const RsFriendListEvent*>(event.get());
if(fp)
switch(fp->mConnectionInfoCode)
switch(fp->mEventCode)
{
case RsConnectionEventCode::PEER_REMOVED:
case RsConnectionEventCode::PEER_ADDED:
case RsFriendListEventCode::NODE_REMOVED:
case RsFriendListEventCode::NODE_ADDED:
updateDisplay(true);
update(); // Qt flush
break;

View file

@ -199,8 +199,8 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par
mEventHandlerId_gssp=0; // forces initialization
mEventHandlerId_pssc=0; // forces initialization
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_pssc, RsEventType::PEER_STATE_CHANGED );
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::PEER_CONNECTION );
// rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_pssc, RsEventType::PEER_STATE_CHANGED );
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::FRIEND_LIST );
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_gssp, RsEventType::GOSSIP_DISCOVERY );
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(QString)), this, SLOT(forceUpdateDisplay()));

View file

@ -968,190 +968,6 @@ void ConnectFriendWizard::openCert()
}
}
#ifdef TO_BE_REMOVED
//========================== CertificatePage =================================
void ConnectFriendWizard::loadFriendCert()
{
QString fileName ;
if(!misc::getOpenFileName(this, RshareSettings::LASTDIR_CERT, tr("Select Certificate"), tr("RetroShare Certificate (*.rsc );;All Files (*)"),fileName))
return ;
if (!fileName.isNull()) {
ui->friendFileNameEdit->setText(fileName);
}
}
void ConnectFriendWizard::generateCertificateCalled()
{
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << " generateCertificateCalled" << std::endl;
#endif
std::string cert = rsPeers->GetRetroshareInvite();
if (cert.empty()) {
QMessageBox::information(this, "RetroShare", tr("Sorry, create certificate failed"), QMessageBox::Ok, QMessageBox::Ok);
return;
}
QString qdir = QFileDialog::getSaveFileName(this, tr("Please choose a filename"), QDir::homePath(), tr("RetroShare Certificate (*.rsc );;All Files (*)"));
//Todo: move save to file to p3Peers::SaveCertificateToFile
if (qdir.isEmpty() == false) {
QFile CertFile(qdir);
if (CertFile.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) {
if (CertFile.write(QByteArray(cert.c_str())) > 0) {
QMessageBox::information(this, "RetroShare", tr("Certificate file successfully created"), QMessageBox::Ok, QMessageBox::Ok);
} else {
QMessageBox::information(this, "RetroShare", tr("Sorry, certificate file creation failed"), QMessageBox::Ok, QMessageBox::Ok);
}
CertFile.close();
} else {
QMessageBox::information(this, "RetroShare", tr("Sorry, certificate file creation failed"), QMessageBox::Ok, QMessageBox::Ok);
}
}
}
//============================= FofPage ======================================
void ConnectFriendWizard::updatePeersList(int index)
{
ui->selectedPeersTW->clearContents();
ui->selectedPeersTW->setRowCount(0);
RsPgpId ownId = rsPeers->getGPGOwnId();
int row = 0;
_id_boxes.clear();
// We have to use this trick because signers are given by their names instead of their ids. That's a cause
// for some confusion when two peers have the same name.
//
std::list<RsPgpId> gpg_ids;
rsPeers->getGPGAllList(gpg_ids);
for (std::list<RsPgpId>::const_iterator it(gpg_ids.begin()); it != gpg_ids.end(); ++it) {
if (*it == ownId) {
// its me
continue;
}
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << "examining peer " << *it << " (name=" << rsPeers->getPeerName(*it);
#endif
RsPeerDetails details ;
if (!rsPeers->getGPGDetails(*it,details)) {
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << " no details." << std::endl ;
#endif
continue;
}
// determine common friends
std::list<RsPgpId> common_friends;
for (std::list<RsPgpId>::const_iterator it2(details.gpgSigners.begin()); it2 != details.gpgSigners.end(); ++it2) {
if(rsPeers->isGPGAccepted(*it2)) {
common_friends.push_back(*it2);
}
}
bool show = false;
switch(index) {
case 0: // "All unsigned friends of my friends"
show = !details.ownsign;
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << "case 0: ownsign=" << details.ownsign << ", show=" << show << std::endl;
#endif
break ;
case 1: // "Unsigned peers who already signed my certificate"
show = details.hasSignedMe && !(details.state & RS_PEER_STATE_FRIEND);
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << "case 1, ownsign=" << details.ownsign << ", is_authed_me=" << details.hasSignedMe << ", show=" << show << std::endl;
#endif
break ;
case 2: // "Peers shown as denied"
show = details.ownsign && !(details.state & RS_PEER_STATE_FRIEND);
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << "case 2, ownsign=" << details.ownsign << ", state_friend=" << (details.state & RS_PEER_STATE_FRIEND) << ", show=" << show << std::endl;
#endif
break ;
}
if (show) {
ui->selectedPeersTW->insertRow(row);
QCheckBox *cb = new QCheckBox;
cb->setChecked(true);
_id_boxes[cb] = details.id;
_gpg_id_boxes[cb] = details.gpg_id;
ui->selectedPeersTW->setCellWidget(row, 0, cb);
ui->selectedPeersTW->setItem(row, 1, new QTableWidgetItem(QString::fromUtf8(details.name.c_str())));
QComboBox *qcb = new QComboBox;
if (common_friends.empty()) {
qcb->addItem(tr("*** None ***"));
} else {
for (std::list<RsPgpId>::const_iterator it2(common_friends.begin()); it2 != common_friends.end(); ++it2) {
qcb->addItem(QString::fromStdString( (*it2).toStdString()));
}
}
ui->selectedPeersTW->setCellWidget(row, 2, qcb);
ui->selectedPeersTW->setItem(row, 3, new QTableWidgetItem(QString::fromStdString(details.id.toStdString())));
++row;
}
}
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << "FofPage::updatePeersList() finished iterating over peers" << std::endl;
#endif
if (row>0) {
ui->selectedPeersTW->resizeColumnsToContents();
ui->makeFriendButton->setEnabled(true);
} else {
ui->makeFriendButton->setEnabled(false);
}
}
void ConnectFriendWizard::signAllSelectedUsers()
{
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << "making lots of friends !!" << std::endl;
#endif
for (std::map<QCheckBox*, RsPeerId>::const_iterator it(_id_boxes.begin()); it != _id_boxes.end(); ++it) {
if (it->first->isChecked()) {
#ifdef FRIEND_WIZARD_DEBUG
std::cerr << "Making friend with " << it->second << std::endl ;
#endif
//rsPeers->AuthCertificate(it->second, "");
rsPeers->addFriend(it->second, _gpg_id_boxes[it->first]);
}
}
ui->FofPage->setComplete(true);
ui->userSelectionCB->setEnabled(false);
ui->selectedPeersTW->setEnabled(false);
ui->makeFriendButton->setEnabled(false);
NotifyQt::getInstance()->notifyListChange(NOTIFY_LIST_NEIGHBOURS,0);
NotifyQt::getInstance()->notifyListChange(NOTIFY_LIST_FRIENDS,0);
}
//============================= RsidPage =====================================
//============================ Emailpage =====================================
#endif
//========================= ErrorMessagePage =================================
//========================== ConclusionPage ==================================

View file

@ -28,6 +28,7 @@
#include "gui/common/StatusDefs.h"
#include "gui/common/FilesDefs.h"
#include "gui/common/AvatarDefs.h"
#include "util/qtthreadsutils.h"
#include "util/DateTime.h"
#include "gui/notifyqt.h"
@ -58,7 +59,23 @@ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId,
connect( chatButton, SIGNAL( clicked() ), this, SLOT( openChat() ) );
connect( sendmsgButton, SIGNAL( clicked() ), this, SLOT( sendMsg() ) );
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
//connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
if(!fe)
return;
updateItem();
}
, this );
}, mEventHandlerId, RsEventType::FRIEND_LIST );
avatar->setId(ChatId(mPeerId));// TODO: remove unnecesary converstation

View file

@ -66,6 +66,7 @@ private:
RsPeerId mPeerId;
uint32_t mType;
bool mIsHome;
RsEventsHandlerId_t mEventHandlerId ;
};
#endif

View file

@ -33,6 +33,7 @@
#include "gui/connect/ConnectFriendWizard.h"
#include "gui/common/AvatarDefs.h"
#include "util/DateTime.h"
#include "util/qtthreadsutils.h"
#include "gui/notifyqt.h"
@ -72,7 +73,23 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g
connect( peerDetailsButton, SIGNAL(clicked()), this, SLOT(peerDetails()));
connect( friendRequesttoolButton, SIGNAL(clicked()), this, SLOT(friendRequest()));
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
//connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
if(!fe)
return;
updateItem();
}
, this );
}, mEventHandlerId, RsEventType::FRIEND_LIST );
avatar->setId(ChatId(mSslId));

View file

@ -67,6 +67,8 @@ private:
std::string mIP;
uint32_t mType;
bool mIsHome;
RsEventsHandlerId_t mEventHandlerId;
};
#endif

View file

@ -540,12 +540,14 @@ void NotifyQt::notifyListChange(int list, int type)
#endif
emit neighboursChanged();
break;
#ifdef TO_REMOVE
case NOTIFY_LIST_FRIENDS:
#ifdef NOTIFY_DEBUG
std::cerr << "received friends changed" << std::endl ;
#endif
emit friendsChanged() ;
break;
#endif
case NOTIFY_LIST_DIRLIST_LOCAL:
#ifdef NOTIFY_DEBUG
std::cerr << "received files changed" << std::endl ;
@ -644,9 +646,11 @@ void NotifyQt::notifyListPreChange(int list, int /*type*/)
{
case NOTIFY_LIST_NEIGHBOURS:
break;
#ifdef TO_REMOVE
case NOTIFY_LIST_FRIENDS:
emit friendsChanged() ;
break;
#endif
case NOTIFY_LIST_DIRLIST_FRIENDS:
emit filesPreModChanged(false) ; /* remote */
break ;

View file

@ -108,7 +108,7 @@ class NotifyQt: public QObject, public NotifyClient
void filesPreModChanged(bool) const ;
void filesPostModChanged(bool) const ;
// void transfersChanged() const ;
void friendsChanged() const ;
// void friendsChanged() const ;
void lobbyListChanged() const ;
void chatLobbyEvent(qulonglong,int,const RsGxsId&,const QString&) ;
void neighboursChanged() const ;

View file

@ -1045,12 +1045,9 @@ unfinishedtranslations {
}
messenger {
SOURCES += gui/MessengerWindow.cpp \
gui/common/FriendList.cpp
HEADERS += gui/MessengerWindow.h \
gui/common/FriendList.h
FORMS += gui/MessengerWindow.ui \
gui/common/FriendList.ui
SOURCES += gui/MessengerWindow.cpp
HEADERS += gui/MessengerWindow.h
FORMS += gui/MessengerWindow.ui
DEFiNES += MESSENGER_WINDOW
}