mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 11:54:22 -04:00
fixed initialization of UI in NewFriendList
This commit is contained in:
parent
5e118e0e27
commit
7ccb05b77a
4 changed files with 126 additions and 110 deletions
|
@ -1965,7 +1965,7 @@ bool FriendList::exportFriendlist(QString &fileName)
|
||||||
/**
|
/**
|
||||||
* @brief helper function to show a message box
|
* @brief helper function to show a message box
|
||||||
*/
|
*/
|
||||||
void showXMLParsingError()
|
static void showXMLParsingError()
|
||||||
{
|
{
|
||||||
// show error to user
|
// show error to user
|
||||||
QMessageBox mbox;
|
QMessageBox mbox;
|
||||||
|
|
|
@ -658,3 +658,54 @@ RsFriendListModel::EntryType RsFriendListModel::getType(const QModelIndex& i) co
|
||||||
|
|
||||||
return e.type;
|
return e.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsFriendListModel::updateInternalData()
|
||||||
|
{
|
||||||
|
preMods();
|
||||||
|
|
||||||
|
mGroups.clear();
|
||||||
|
mLocations.clear();
|
||||||
|
mProfiles.clear();
|
||||||
|
|
||||||
|
// groups
|
||||||
|
|
||||||
|
std::list<RsGroupInfo> groupInfoList;
|
||||||
|
rsPeers->getGroupInfoList(groupInfoList) ;
|
||||||
|
|
||||||
|
for(auto it(groupInfoList.begin());it!=groupInfoList.end();++it)
|
||||||
|
mGroups.push_back(*it);
|
||||||
|
|
||||||
|
// profiles
|
||||||
|
|
||||||
|
std::list<RsPgpId> gpg_ids;
|
||||||
|
rsPeers->getGPGAcceptedList(gpg_ids);
|
||||||
|
|
||||||
|
for(auto it(gpg_ids.begin());it!=gpg_ids.end();++it)
|
||||||
|
{
|
||||||
|
RsProfileDetails det;
|
||||||
|
|
||||||
|
if(!rsPeers->getGPGDetails(*it,det))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mProfiles.push_back(det);
|
||||||
|
}
|
||||||
|
|
||||||
|
// locations
|
||||||
|
|
||||||
|
std::list<RsPeerId> peer_ids;
|
||||||
|
rsPeers->getFriendList(peer_ids);
|
||||||
|
|
||||||
|
for(auto it(peer_ids.begin());it!=peer_ids.end();++it)
|
||||||
|
{
|
||||||
|
RsNodeDetails det;
|
||||||
|
|
||||||
|
if(!rsPeers->getPeerDetails(*it,det))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mLocations.push_back(det);
|
||||||
|
}
|
||||||
|
|
||||||
|
postMods();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
|
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTreeWidgetItem>
|
|
||||||
#include <QWidgetAction>
|
#include <QWidgetAction>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
@ -110,6 +109,7 @@ Q_DECLARE_METATYPE(ElidedLabel*)
|
||||||
|
|
||||||
NewFriendList::NewFriendList(QWidget *parent) :
|
NewFriendList::NewFriendList(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
|
ui(new Ui::NewFriendList()),
|
||||||
// mCompareRole(new RSTreeWidgetItemCompareRole),
|
// mCompareRole(new RSTreeWidgetItemCompareRole),
|
||||||
mShowGroups(true),
|
mShowGroups(true),
|
||||||
mShowState(false),
|
mShowState(false),
|
||||||
|
@ -119,12 +119,9 @@ NewFriendList::NewFriendList(QWidget *parent) :
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu()));
|
connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu()));
|
||||||
connect(ui->peerTreeWidget, SIGNAL(itemExpanded(QTreeWidgetItem *)), this, SLOT(expandItem(QTreeWidgetItem *)));
|
//connect(ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(expandItem(QTreeWidgetItem *)) );
|
||||||
connect(ui->peerTreeWidget, SIGNAL(itemCollapsed(QTreeWidgetItem *)), this, SLOT(collapseItem(QTreeWidgetItem *)));
|
|
||||||
connect(ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(expandItem(QTreeWidgetItem *)) );
|
|
||||||
|
|
||||||
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged()));
|
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged()));
|
||||||
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(insertPeers()));
|
|
||||||
|
|
||||||
connect(ui->actionHideOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setHideUnconnected(bool)));
|
connect(ui->actionHideOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setHideUnconnected(bool)));
|
||||||
connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool)));
|
connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool)));
|
||||||
|
@ -137,9 +134,12 @@ NewFriendList::NewFriendList(QWidget *parent) :
|
||||||
ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
|
ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
|
||||||
ui->filterLineEdit->showFilterIcon();
|
ui->filterLineEdit->showFilterIcon();
|
||||||
|
|
||||||
|
|
||||||
mModel = new RsFriendListModel();
|
mModel = new RsFriendListModel();
|
||||||
ui->peerTreeWidget->setModel(mModel);
|
ui->peerTreeWidget->setModel(mModel);
|
||||||
|
|
||||||
|
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), mModel, SLOT(updateInternalData()));
|
||||||
|
|
||||||
/* Add filter actions */
|
/* Add filter actions */
|
||||||
// QTreeWidgetItem *headerItem = ui->peerTreeWidget->headerItem();
|
// QTreeWidgetItem *headerItem = ui->peerTreeWidget->headerItem();
|
||||||
// QString headerText = headerItem->text(COLUMN_NAME);
|
// QString headerText = headerItem->text(COLUMN_NAME);
|
||||||
|
@ -163,9 +163,6 @@ NewFriendList::NewFriendList(QWidget *parent) :
|
||||||
/* Initialize tree */
|
/* Initialize tree */
|
||||||
// ui->peerTreeWidget->enableColumnCustomize(true);
|
// ui->peerTreeWidget->enableColumnCustomize(true);
|
||||||
// ui->peerTreeWidget->setColumnCustomizable(COLUMN_NAME, false);
|
// ui->peerTreeWidget->setColumnCustomizable(COLUMN_NAME, false);
|
||||||
connect(ui->peerTreeWidget, SIGNAL(columnVisibleChanged(int,bool)), this, SLOT(peerTreeColumnVisibleChanged(int,bool)));
|
|
||||||
connect(ui->peerTreeWidget, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(peerTreeItemCollapsedExpanded(QTreeWidgetItem*)));
|
|
||||||
connect(ui->peerTreeWidget, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(peerTreeItemCollapsedExpanded(QTreeWidgetItem*)));
|
|
||||||
|
|
||||||
QFontMetricsF fontMetrics(ui->peerTreeWidget->font());
|
QFontMetricsF fontMetrics(ui->peerTreeWidget->font());
|
||||||
|
|
||||||
|
@ -270,7 +267,6 @@ void NewFriendList::changeEvent(QEvent *e)
|
||||||
QWidget::changeEvent(e);
|
QWidget::changeEvent(e);
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::StyleChange:
|
case QEvent::StyleChange:
|
||||||
insertPeers();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// remove compiler warnings
|
// remove compiler warnings
|
||||||
|
@ -278,12 +274,6 @@ void NewFriendList::changeEvent(QEvent *e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Utility Fns */
|
|
||||||
inline std::string getRsId(QTreeWidgetItem *item)
|
|
||||||
{
|
|
||||||
return item->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the context popup menu and its submenus,
|
* Creates the context popup menu and its submenus,
|
||||||
* then shows it at the current cursor position.
|
* then shows it at the current cursor position.
|
||||||
|
@ -363,12 +353,6 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu()
|
||||||
|
|
||||||
case RsFriendListModel::ENTRY_TYPE_PROFILE:
|
case RsFriendListModel::ENTRY_TYPE_PROFILE:
|
||||||
{
|
{
|
||||||
#ifdef RS_DIRECT_CHAT
|
|
||||||
contextMenu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy()));
|
|
||||||
contextMenu.addAction(QIcon(IMAGE_MSG), tr("Send message"), this, SLOT(msgProfile()));
|
|
||||||
contextMenu.addSeparator();
|
|
||||||
#endif // RS_DIRECT_CHAT
|
|
||||||
|
|
||||||
contextMenu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Profile details"), this, SLOT(configureProfile()));
|
contextMenu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Profile details"), this, SLOT(configureProfile()));
|
||||||
contextMenu.addAction(QIcon(IMAGE_DENYFRIEND), tr("Deny connections"), this, SLOT(removefriend()));
|
contextMenu.addAction(QIcon(IMAGE_DENYFRIEND), tr("Deny connections"), this, SLOT(removefriend()));
|
||||||
|
|
||||||
|
@ -448,7 +432,7 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu()
|
||||||
case RsFriendListModel::ENTRY_TYPE_NODE:
|
case RsFriendListModel::ENTRY_TYPE_NODE:
|
||||||
{
|
{
|
||||||
#ifdef RS_DIRECT_CHAT
|
#ifdef RS_DIRECT_CHAT
|
||||||
contextMenu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy()));
|
contextMenu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatNode()));
|
||||||
contextMenu.addAction(QIcon(IMAGE_MSG), tr("Send message to this node"), this, SLOT(msgNode()));
|
contextMenu.addAction(QIcon(IMAGE_MSG), tr("Send message to this node"), this, SLOT(msgNode()));
|
||||||
contextMenu.addSeparator();
|
contextMenu.addSeparator();
|
||||||
#endif // RS_DIRECT_CHAT
|
#endif // RS_DIRECT_CHAT
|
||||||
|
@ -497,7 +481,6 @@ void NewFriendList::createNewGroup()
|
||||||
void NewFriendList::groupsChanged()
|
void NewFriendList::groupsChanged()
|
||||||
{
|
{
|
||||||
groupsHasChanged = true;
|
groupsHasChanged = true;
|
||||||
insertPeers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay)
|
static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay)
|
||||||
|
@ -519,37 +502,37 @@ static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay)
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getNameWidget(QTreeWidget *treeWidget, QTreeWidgetItem *item, ElidedLabel *&nameLabel, ElidedLabel *&textLabel)
|
// static void getNameWidget(QTreeWidget *treeWidget, QTreeWidgetItem *item, ElidedLabel *&nameLabel, ElidedLabel *&textLabel)
|
||||||
{
|
// {
|
||||||
QWidget *widget = treeWidget->itemWidget(item, NewFriendList::COLUMN_NAME);
|
// QWidget *widget = treeWidget->itemWidget(item, NewFriendList::COLUMN_NAME);
|
||||||
|
//
|
||||||
if (!widget) {
|
// if (!widget) {
|
||||||
widget = new QWidget;
|
// widget = new QWidget;
|
||||||
widget->setAttribute(Qt::WA_TranslucentBackground);
|
// widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
nameLabel = new ElidedLabel(widget);
|
// nameLabel = new ElidedLabel(widget);
|
||||||
textLabel = new ElidedLabel(widget);
|
// textLabel = new ElidedLabel(widget);
|
||||||
|
//
|
||||||
widget->setProperty("nameLabel", qVariantFromValue(nameLabel));
|
// widget->setProperty("nameLabel", qVariantFromValue(nameLabel));
|
||||||
widget->setProperty("textLabel", qVariantFromValue(textLabel));
|
// widget->setProperty("textLabel", qVariantFromValue(textLabel));
|
||||||
|
//
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
// QVBoxLayout *layout = new QVBoxLayout;
|
||||||
layout->setSpacing(0);
|
// layout->setSpacing(0);
|
||||||
layout->setContentsMargins(3, 0, 0, 0);
|
// layout->setContentsMargins(3, 0, 0, 0);
|
||||||
|
//
|
||||||
nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
// nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
||||||
textLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
// textLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
||||||
|
//
|
||||||
layout->addWidget(nameLabel);
|
// layout->addWidget(nameLabel);
|
||||||
layout->addWidget(textLabel);
|
// layout->addWidget(textLabel);
|
||||||
|
//
|
||||||
widget->setLayout(layout);
|
// widget->setLayout(layout);
|
||||||
|
//
|
||||||
treeWidget->setItemWidget(item, NewFriendList::COLUMN_NAME, widget);
|
// treeWidget->setItemWidget(item, NewFriendList::COLUMN_NAME, widget);
|
||||||
} else {
|
// } else {
|
||||||
nameLabel = widget->property("nameLabel").value<ElidedLabel*>();
|
// nameLabel = widget->property("nameLabel").value<ElidedLabel*>();
|
||||||
textLabel = widget->property("textLabel").value<ElidedLabel*>();
|
// textLabel = widget->property("textLabel").value<ElidedLabel*>();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list with all groupIds that are expanded
|
* Returns a list with all groupIds that are expanded
|
||||||
|
@ -583,32 +566,32 @@ bool NewFriendList::getExpandedPeers(std::set<RsPgpId> &peers) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewFriendList::collapseItem(QTreeWidgetItem *item)
|
// void NewFriendList::collapseItem(QTreeWidgetItem *item)
|
||||||
{
|
// {
|
||||||
switch (item->type())
|
// switch (item->type())
|
||||||
{
|
// {
|
||||||
case TYPE_GROUP:
|
// case TYPE_GROUP:
|
||||||
openGroups.erase(RsNodeGroupId(getRsId(item))) ;
|
// openGroups.erase(RsNodeGroupId(getRsId(item))) ;
|
||||||
break;
|
// break;
|
||||||
case TYPE_GPG:
|
// case TYPE_GPG:
|
||||||
openPeers.erase(RsPgpId(getRsId(item))) ;
|
// openPeers.erase(RsPgpId(getRsId(item))) ;
|
||||||
default:
|
// default:
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
void NewFriendList::expandItem(QTreeWidgetItem *item)
|
// void NewFriendList::expandItem(QTreeWidgetItem *item)
|
||||||
{
|
// {
|
||||||
switch (item->type())
|
// switch (item->type())
|
||||||
{
|
// {
|
||||||
case TYPE_GROUP:
|
// case TYPE_GROUP:
|
||||||
openGroups.insert(RsNodeGroupId(getRsId(item))) ;
|
// openGroups.insert(RsNodeGroupId(getRsId(item))) ;
|
||||||
break;
|
// break;
|
||||||
case TYPE_GPG:
|
// case TYPE_GPG:
|
||||||
openPeers.insert(RsPgpId(getRsId(item))) ;
|
// openPeers.insert(RsPgpId(getRsId(item))) ;
|
||||||
default:
|
// default:
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
void NewFriendList::addFriend()
|
void NewFriendList::addFriend()
|
||||||
{
|
{
|
||||||
|
@ -649,6 +632,15 @@ void NewFriendList::msgNode()
|
||||||
|
|
||||||
MessageComposer::msgFriend(det.id);
|
MessageComposer::msgFriend(det.id);
|
||||||
}
|
}
|
||||||
|
void NewFriendList::chatNode()
|
||||||
|
{
|
||||||
|
RsFriendListModel::RsNodeDetails det;
|
||||||
|
|
||||||
|
if(!getCurrentNode(det))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ChatDialog::chatFriend(ChatId(det.id));
|
||||||
|
}
|
||||||
|
|
||||||
void NewFriendList::recommendNode()
|
void NewFriendList::recommendNode()
|
||||||
{
|
{
|
||||||
|
@ -1091,7 +1083,7 @@ bool NewFriendList::exportFriendlist(QString &fileName)
|
||||||
/**
|
/**
|
||||||
* @brief helper function to show a message box
|
* @brief helper function to show a message box
|
||||||
*/
|
*/
|
||||||
void showXMLParsingError()
|
static void showXMLParsingError()
|
||||||
{
|
{
|
||||||
// show error to user
|
// show error to user
|
||||||
QMessageBox mbox;
|
QMessageBox mbox;
|
||||||
|
@ -1287,14 +1279,12 @@ void NewFriendList::setHideUnconnected(bool hidden)
|
||||||
{
|
{
|
||||||
if (mHideUnconnected != hidden) {
|
if (mHideUnconnected != hidden) {
|
||||||
mHideUnconnected = hidden;
|
mHideUnconnected = hidden;
|
||||||
insertPeers();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewFriendList::setColumnVisible(Column column, bool visible)
|
void NewFriendList::setColumnVisible(Column column, bool visible)
|
||||||
{
|
{
|
||||||
ui->peerTreeWidget->setColumnHidden(column, !visible);
|
ui->peerTreeWidget->setColumnHidden(column, !visible);
|
||||||
peerTreeColumnVisibleChanged(column, visible);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewFriendList::sortByColumn(Column column, Qt::SortOrder sortOrder)
|
void NewFriendList::sortByColumn(Column column, Qt::SortOrder sortOrder)
|
||||||
|
@ -1302,29 +1292,10 @@ void NewFriendList::sortByColumn(Column column, Qt::SortOrder sortOrder)
|
||||||
ui->peerTreeWidget->sortByColumn(column, sortOrder);
|
ui->peerTreeWidget->sortByColumn(column, sortOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewFriendList::peerTreeColumnVisibleChanged(int /*column*/, bool visible)
|
|
||||||
{
|
|
||||||
if (visible) {
|
|
||||||
insertPeers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewFriendList::peerTreeItemCollapsedExpanded(QTreeWidgetItem *item)
|
|
||||||
{
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item->type() == TYPE_GPG) {
|
|
||||||
insertPeers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewFriendList::setShowState(bool show)
|
void NewFriendList::setShowState(bool show)
|
||||||
{
|
{
|
||||||
if (mShowState != show) {
|
if (mShowState != show) {
|
||||||
mShowState = show;
|
mShowState = show;
|
||||||
insertPeers();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,10 +95,6 @@ public slots:
|
||||||
void setShowState(bool show);
|
void setShowState(bool show);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void peerTreeColumnVisibleChanged(int column, bool visible);
|
|
||||||
void peerTreeItemCollapsedExpanded(QTreeWidgetItem *item);
|
|
||||||
void collapseItem(QTreeWidgetItem *item);
|
|
||||||
void expandItem(QTreeWidgetItem *item);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
|
@ -139,7 +135,6 @@ private:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void groupsChanged();
|
void groupsChanged();
|
||||||
void insertPeers();
|
|
||||||
void peerTreeWidgetCustomPopupMenu();
|
void peerTreeWidgetCustomPopupMenu();
|
||||||
void updateMenu();
|
void updateMenu();
|
||||||
|
|
||||||
|
@ -148,8 +143,7 @@ private slots:
|
||||||
void connectNode();
|
void connectNode();
|
||||||
void configureNode();
|
void configureNode();
|
||||||
void configureProfile();
|
void configureProfile();
|
||||||
void chatfriend(QTreeWidgetItem *item);
|
void chatNode();
|
||||||
void chatfriendproxy();
|
|
||||||
void copyFullCertificate();
|
void copyFullCertificate();
|
||||||
void addFriend();
|
void addFriend();
|
||||||
void msgNode();
|
void msgNode();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue