Fix Save Network Friends Headers Size

This commit is contained in:
Phenom 2020-11-12 18:47:50 +01:00
parent 4a7906376f
commit f8d7bd5d74

View file

@ -171,7 +171,7 @@ private:
bool m_showOfflineNodes; bool m_showOfflineNodes;
}; };
NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent),*/ ui(new Ui::NewFriendList()) NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,parent),*/ ui(new Ui::NewFriendList())
{ {
ui->setupUi(this); ui->setupUi(this);
@ -259,7 +259,7 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent)
} }
void NewFriendList::handleEvent(std::shared_ptr<const RsEvent> e) void NewFriendList::handleEvent(std::shared_ptr<const RsEvent> /*e*/)
{ {
// /!\ The function we're in is called from a different thread. It's very important // /!\ The function we're in is called from a different thread. It's very important
// to use this trick in order to avoid data races. // to use this trick in order to avoid data races.
@ -294,7 +294,7 @@ void NewFriendList::sortColumn(int col,Qt::SortOrder so)
restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes); restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes);
} }
void NewFriendList::headerContextMenuRequested(QPoint p) void NewFriendList::headerContextMenuRequested(QPoint /*p*/)
{ {
QMenu displayMenu(tr("Show Items"), this); QMenu displayMenu(tr("Show Items"), this);
@ -463,6 +463,7 @@ void NewFriendList::processSettings(bool load)
setColumnVisible(RsFriendListModel::COLUMN_THREAD_IP,Settings->value("showIP", isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)).toBool()); setColumnVisible(RsFriendListModel::COLUMN_THREAD_IP,Settings->value("showIP", isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)).toBool());
setColumnVisible(RsFriendListModel::COLUMN_THREAD_ID,Settings->value("showID", isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)).toBool()); setColumnVisible(RsFriendListModel::COLUMN_THREAD_ID,Settings->value("showID", isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)).toBool());
setColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT,Settings->value("showLastContact", isColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT)).toBool()); setColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT,Settings->value("showLastContact", isColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT)).toBool());
ui->peerTreeWidget->header()->restoreState(Settings->value("headers").toByteArray());
// sort // sort
toggleSortByState(Settings->value("sortByState", mProxyModel->sortByState()).toBool()); toggleSortByState(Settings->value("sortByState", mProxyModel->sortByState()).toBool());
@ -488,6 +489,7 @@ void NewFriendList::processSettings(bool load)
Settings->setValue("showIP",isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)); Settings->setValue("showIP",isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP));
Settings->setValue("showID",isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)); Settings->setValue("showID",isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID));
Settings->setValue("showLastContact",isColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT)); Settings->setValue("showLastContact",isColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT));
Settings->setValue("headers",ui->peerTreeWidget->header()->saveState());
// sort // sort
Settings->setValue("sortByState", mProxyModel->sortByState()); Settings->setValue("sortByState", mProxyModel->sortByState());
@ -568,133 +570,141 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu()
//this is a SSL key //this is a SSL key
textLabel->setText("<strong>" + tr("Node") + "</strong>"); textLabel->setText("<strong>" + tr("Node") + "</strong>");
break; break;
default:
textLabel->setText("<strong>" + tr("UNKNOWN TYPE") + "</strong>");
} }
switch (type) switch (type)
{ {
case RsFriendListModel::ENTRY_TYPE_GROUP: case RsFriendListModel::ENTRY_TYPE_GROUP:
{ {
RsGroupInfo group_info ; RsGroupInfo group_info ;
mModel->getGroupData(index,group_info); mModel->getGroupData(index,group_info);
bool standard = group_info.flag & RS_GROUP_FLAG_STANDARD; bool standard = group_info.flag & RS_GROUP_FLAG_STANDARD;
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup())); contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup()));
QAction *action = contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup())); QAction *action = contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup()));
action->setDisabled(standard); action->setDisabled(standard);
} }
break; break;
case RsFriendListModel::ENTRY_TYPE_PROFILE: case RsFriendListModel::ENTRY_TYPE_PROFILE:
{
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_FRIENDINFO), tr("Profile details"), this, SLOT(configureProfile()));
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DENYFRIEND), tr("Deny connections"), this, SLOT(removeProfile()));
RsFriendListModel::RsProfileDetails details;
mModel->getProfileData(index,details);
if(mModel->getDisplayGroups())
{ {
QMenu* addToGroupMenu = NULL; contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_FRIENDINFO), tr("Profile details"), this, SLOT(configureProfile()));
QMenu* moveToGroupMenu = NULL; contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DENYFRIEND), tr("Deny connections"), this, SLOT(removeProfile()));
std::list<RsGroupInfo> groupInfoList; RsFriendListModel::RsProfileDetails details;
rsPeers->getGroupInfoList(groupInfoList); mModel->getProfileData(index,details);
GroupDefs::sortByName(groupInfoList); if(mModel->getDisplayGroups())
{
QMenu* addToGroupMenu = NULL;
QMenu* moveToGroupMenu = NULL;
RsPgpId gpgId ( details.gpg_id ); std::list<RsGroupInfo> groupInfoList;
rsPeers->getGroupInfoList(groupInfoList);
QModelIndex parent = mModel->parent(index); GroupDefs::sortByName(groupInfoList);
bool foundGroup = false; RsPgpId gpgId ( details.gpg_id );
// add action for all groups, except the own group
for (std::list<RsGroupInfo>::iterator groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
if (std::find(groupIt->peerIds.begin(), groupIt->peerIds.end(), gpgId) == groupIt->peerIds.end()) {
if (parent.isValid())
{
if (addToGroupMenu == NULL)
addToGroupMenu = new QMenu(tr("Add to group"), &contextMenu);
QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu); QModelIndex parent = mModel->parent(index);
addToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString()));
connect(addToGroupAction, SIGNAL(triggered()), this, SLOT(addToGroup())); bool foundGroup = false;
addToGroupMenu->addAction(addToGroupAction); // add action for all groups, except the own group
for (std::list<RsGroupInfo>::iterator groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
if (std::find(groupIt->peerIds.begin(), groupIt->peerIds.end(), gpgId) == groupIt->peerIds.end()) {
if (parent.isValid())
{
if (addToGroupMenu == NULL)
addToGroupMenu = new QMenu(tr("Add to group"), &contextMenu);
QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu);
addToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString()));
connect(addToGroupAction, SIGNAL(triggered()), this, SLOT(addToGroup()));
addToGroupMenu->addAction(addToGroupAction);
}
if (moveToGroupMenu == NULL) {
moveToGroupMenu = new QMenu(tr("Move to group"), &contextMenu);
}
QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu);
moveToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString()));
connect(moveToGroupAction, SIGNAL(triggered()), this, SLOT(moveToGroup()));
moveToGroupMenu->addAction(moveToGroupAction);
} else {
foundGroup = true;
}
}
QMenu *groupsMenu = contextMenu.addMenu(FilesDefs::getIconFromQtResourcePath(IMAGE_GROUP16), tr("Groups"));
groupsMenu->addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EXPAND), tr("Create new group"), this, SLOT(createNewGroup()));
if (addToGroupMenu || moveToGroupMenu || foundGroup) {
if (addToGroupMenu) {
groupsMenu->addMenu(addToGroupMenu);
} }
if (moveToGroupMenu == NULL) { if (moveToGroupMenu) {
moveToGroupMenu = new QMenu(tr("Move to group"), &contextMenu); groupsMenu->addMenu(moveToGroupMenu);
}
if (foundGroup)
{
// add remove from group
if (parent.isValid() && mModel->getType(parent) == RsFriendListModel::ENTRY_TYPE_GROUP)
{
RsGroupInfo info ;
mModel->getGroupData(parent,info);
QAction *removeFromGroup = groupsMenu->addAction(tr("Remove from group ")+QString::fromUtf8(info.name.c_str()));
removeFromGroup->setData(parent.sibling(parent.row(),RsFriendListModel::COLUMN_THREAD_ID).data(Qt::DisplayRole));
connect(removeFromGroup, SIGNAL(triggered()), this, SLOT(removeFromGroup()));
}
QAction *removeFromAllGroups = groupsMenu->addAction(tr("Remove from all groups"));
removeFromAllGroups->setData("");
connect(removeFromAllGroups, SIGNAL(triggered()), this, SLOT(removeFromGroup()));
} }
QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu);
moveToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString()));
connect(moveToGroupAction, SIGNAL(triggered()), this, SLOT(moveToGroup()));
moveToGroupMenu->addAction(moveToGroupAction);
} else {
foundGroup = true;
} }
} }
QMenu *groupsMenu = contextMenu.addMenu(FilesDefs::getIconFromQtResourcePath(IMAGE_GROUP16), tr("Groups"));
groupsMenu->addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EXPAND), tr("Create new group"), this, SLOT(createNewGroup()));
if (addToGroupMenu || moveToGroupMenu || foundGroup) {
if (addToGroupMenu) {
groupsMenu->addMenu(addToGroupMenu);
}
if (moveToGroupMenu) {
groupsMenu->addMenu(moveToGroupMenu);
}
if (foundGroup)
{
// add remove from group
if (parent.isValid() && mModel->getType(parent) == RsFriendListModel::ENTRY_TYPE_GROUP)
{
RsGroupInfo info ;
mModel->getGroupData(parent,info);
QAction *removeFromGroup = groupsMenu->addAction(tr("Remove from group ")+QString::fromUtf8(info.name.c_str()));
removeFromGroup->setData(parent.sibling(parent.row(),RsFriendListModel::COLUMN_THREAD_ID).data(Qt::DisplayRole));
connect(removeFromGroup, SIGNAL(triggered()), this, SLOT(removeFromGroup()));
}
QAction *removeFromAllGroups = groupsMenu->addAction(tr("Remove from all groups"));
removeFromAllGroups->setData("");
connect(removeFromAllGroups, SIGNAL(triggered()), this, SLOT(removeFromGroup()));
}
}
} }
}
break ; break ;
case RsFriendListModel::ENTRY_TYPE_NODE: case RsFriendListModel::ENTRY_TYPE_NODE:
{ {
#ifdef RS_DIRECT_CHAT #ifdef RS_DIRECT_CHAT
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_CHAT), tr("Chat"), this, SLOT(chatNode())); contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_CHAT), tr("Chat"), this, SLOT(chatNode()));
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_MSG), tr("Send message to this node"), this, SLOT(msgNode())); contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_MSG), tr("Send message to this node"), this, SLOT(msgNode()));
contextMenu.addSeparator(); contextMenu.addSeparator();
#endif // RS_DIRECT_CHAT #endif // RS_DIRECT_CHAT
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_FRIENDINFO), tr("Node details"), this, SLOT(configureNode())); contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_FRIENDINFO), tr("Node details"), this, SLOT(configureNode()));
if (type == RsFriendListModel::ENTRY_TYPE_PROFILE || type == RsFriendListModel::ENTRY_TYPE_NODE) if (type == RsFriendListModel::ENTRY_TYPE_PROFILE || type == RsFriendListModel::ENTRY_TYPE_NODE)
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EXPORTFRIEND), tr("Recommend this node to..."), this, SLOT(recommendNode())); contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EXPORTFRIEND), tr("Recommend this node to..."), this, SLOT(recommendNode()));
RsFriendListModel::RsNodeDetails details; RsFriendListModel::RsNodeDetails details;
mModel->getNodeData(index,details); mModel->getNodeData(index,details);
if(!rsPeers->isHiddenNode(rsPeers->getOwnId()) || rsPeers->isHiddenNode( details.id )) if(!rsPeers->isHiddenNode(rsPeers->getOwnId()) || rsPeers->isHiddenNode( details.id ))
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_CONNECT), tr("Attempt to connect"), this, SLOT(connectNode())); contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_CONNECT), tr("Attempt to connect"), this, SLOT(connectNode()));
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy certificate link"), this, SLOT(copyFullCertificate())); contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy certificate link"), this, SLOT(copyFullCertificate()));
//this is a SSL key //this is a SSL key
contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REMOVEFRIEND), tr("Remove Friend Node"), this, SLOT(removeNode())); contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REMOVEFRIEND), tr("Remove Friend Node"), this, SLOT(removeNode()));
} }
break;
default:
{
contextMenu.addSection("Report it to Devs!");
}
} }
} }
@ -722,6 +732,7 @@ void NewFriendList::createNewGroup()
createGrpDialog.exec(); createGrpDialog.exec();
} }
#ifdef NOT_USED
static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay) static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay)
{ {
int avatarWidth = avatar.width(); int avatarWidth = avatar.width();
@ -740,6 +751,7 @@ static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay)
icon.addPixmap(pixmap); icon.addPixmap(pixmap);
return icon; return icon;
} }
#endif
void NewFriendList::addFriend() void NewFriendList::addFriend()
{ {
@ -755,37 +767,37 @@ void NewFriendList::addFriend()
} }
void NewFriendList::msgProfile() void NewFriendList::msgProfile()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det)) if(!getCurrentNode(det))
return; return;
MessageComposer::msgFriend(det.id); MessageComposer::msgFriend(det.id);
} }
void NewFriendList::msgGroup() void NewFriendList::msgGroup()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det)) if(!getCurrentNode(det))
return; return;
MessageComposer::msgFriend(det.id); MessageComposer::msgFriend(det.id);
} }
void NewFriendList::msgNode() void NewFriendList::msgNode()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det)) if(!getCurrentNode(det))
return; return;
MessageComposer::msgFriend(det.id); MessageComposer::msgFriend(det.id);
} }
void NewFriendList::chatNode() void NewFriendList::chatNode()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det)) if(!getCurrentNode(det))
return; return;
ChatDialog::chatFriend(ChatId(det.id)); ChatDialog::chatFriend(ChatId(det.id));
} }
@ -794,10 +806,10 @@ void NewFriendList::recommendNode()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det)) if(!getCurrentNode(det))
return; return;
MessageComposer::recommendFriend(std::set<RsPeerId>({ det.id })); MessageComposer::recommendFriend(std::set<RsPeerId>({ det.id }));
} }
void NewFriendList::pastePerson() void NewFriendList::pastePerson()
@ -808,10 +820,10 @@ void NewFriendList::pastePerson()
void NewFriendList::copyFullCertificate() void NewFriendList::copyFullCertificate()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det)) if(!getCurrentNode(det))
return; return;
QList<RetroShareLink> urls; QList<RetroShareLink> urls;
RetroShareLink link = RetroShareLink::createCertificate(det.id); RetroShareLink link = RetroShareLink::createCertificate(det.id);
@ -935,33 +947,33 @@ void NewFriendList::removeItem()
void NewFriendList::removeNode() void NewFriendList::removeNode()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det) || !rsPeers) if(!getCurrentNode(det) || !rsPeers)
return; return;
if ((QMessageBox::question(this, "RetroShare", tr("Do you want to remove this node?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes)) == QMessageBox::Yes) if ((QMessageBox::question(this, "RetroShare", tr("Do you want to remove this node?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes)) == QMessageBox::Yes)
rsPeers->removeFriendLocation(det.id); rsPeers->removeFriendLocation(det.id);
checkInternalData(true); checkInternalData(true);
} }
void NewFriendList::removeProfile() void NewFriendList::removeProfile()
{ {
RsFriendListModel::RsProfileDetails det; RsFriendListModel::RsProfileDetails det;
if(!getCurrentProfile(det) || !rsPeers) if(!getCurrentProfile(det) || !rsPeers)
return; return;
if ((QMessageBox::question(this, "RetroShare", tr("Do you want to remove this Friend?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes)) == QMessageBox::Yes) if ((QMessageBox::question(this, "RetroShare", tr("Do you want to remove this Friend?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes)) == QMessageBox::Yes)
rsPeers->removeFriend(det.gpg_id); rsPeers->removeFriend(det.gpg_id);
checkInternalData(true); checkInternalData(true);
} }
void NewFriendList::connectNode() void NewFriendList::connectNode()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det) || !rsPeers) if(!getCurrentNode(det) || !rsPeers)
return; return;
rsPeers->connectAttempt(det.id); rsPeers->connectAttempt(det.id);
ConnectProgressDialog::showProgress(det.id); ConnectProgressDialog::showProgress(det.id);
@ -972,17 +984,17 @@ void NewFriendList::configureNode()
{ {
RsFriendListModel::RsNodeDetails det; RsFriendListModel::RsNodeDetails det;
if(!getCurrentNode(det)) if(!getCurrentNode(det))
return; return;
ConfCertDialog::showIt(det.id, ConfCertDialog::PageDetails); ConfCertDialog::showIt(det.id, ConfCertDialog::PageDetails);
} }
void NewFriendList::configureProfile() void NewFriendList::configureProfile()
{ {
RsFriendListModel::RsProfileDetails det; RsFriendListModel::RsProfileDetails det;
if(!getCurrentProfile(det)) if(!getCurrentProfile(det))
return; return;
PGPKeyDialog::showIt(det.gpg_id, PGPKeyDialog::PageDetails); PGPKeyDialog::showIt(det.gpg_id, PGPKeyDialog::PageDetails);
} }
@ -1079,11 +1091,11 @@ void NewFriendList::removeGroup()
{ {
RsGroupInfo pinfo; RsGroupInfo pinfo;
if(!getCurrentGroup(pinfo)) if(!getCurrentGroup(pinfo))
return; return;
rsPeers->removeGroup(pinfo.id); rsPeers->removeGroup(pinfo.id);
checkInternalData(true); checkInternalData(true);
} }
void NewFriendList::applyWhileKeepingTree(std::function<void()> predicate) void NewFriendList::applyWhileKeepingTree(std::function<void()> predicate)
@ -1199,7 +1211,7 @@ bool NewFriendList::importExportFriendlistFileDialog(QString &fileName, bool imp
, tr("Select a file for exporting your friendlist to") , tr("Select a file for exporting your friendlist to")
, tr("XML File (*.xml);;All Files (*)") , tr("XML File (*.xml);;All Files (*)")
, fileName, NULL , fileName, NULL
, (QFileDialog::Options)0 , QFileDialog::Options()
); );
} }
if ( res && !fileName.endsWith(".xml",Qt::CaseInsensitive) ) if ( res && !fileName.endsWith(".xml",Qt::CaseInsensitive) )