From f8d7bd5d742a263ace61583618d1918f94de520e Mon Sep 17 00:00:00 2001 From: Phenom Date: Thu, 12 Nov 2020 18:47:50 +0100 Subject: [PATCH] Fix Save Network Friends Headers Size --- .../src/gui/common/NewFriendList.cpp | 280 +++++++++--------- 1 file changed, 146 insertions(+), 134 deletions(-) diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 839145a16..723f26e77 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -171,7 +171,7 @@ private: 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); @@ -259,7 +259,7 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) } -void NewFriendList::handleEvent(std::shared_ptr e) +void NewFriendList::handleEvent(std::shared_ptr /*e*/) { // /!\ 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. @@ -294,7 +294,7 @@ void NewFriendList::sortColumn(int col,Qt::SortOrder so) restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes); } -void NewFriendList::headerContextMenuRequested(QPoint p) +void NewFriendList::headerContextMenuRequested(QPoint /*p*/) { 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_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()); + ui->peerTreeWidget->header()->restoreState(Settings->value("headers").toByteArray()); // sort 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("showID",isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)); Settings->setValue("showLastContact",isColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT)); + Settings->setValue("headers",ui->peerTreeWidget->header()->saveState()); // sort Settings->setValue("sortByState", mProxyModel->sortByState()); @@ -568,133 +570,141 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu() //this is a SSL key textLabel->setText("" + tr("Node") + ""); break; + default: + textLabel->setText("" + tr("UNKNOWN TYPE") + ""); } switch (type) { - case RsFriendListModel::ENTRY_TYPE_GROUP: - { - RsGroupInfo group_info ; - mModel->getGroupData(index,group_info); + case RsFriendListModel::ENTRY_TYPE_GROUP: + { + RsGroupInfo 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())); - action->setDisabled(standard); - } + QAction *action = contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup())); + action->setDisabled(standard); + } break; - 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()) + case RsFriendListModel::ENTRY_TYPE_PROFILE: { - QMenu* addToGroupMenu = NULL; - QMenu* moveToGroupMenu = NULL; + contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_FRIENDINFO), tr("Profile details"), this, SLOT(configureProfile())); + contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DENYFRIEND), tr("Deny connections"), this, SLOT(removeProfile())); - std::list groupInfoList; - rsPeers->getGroupInfoList(groupInfoList); + RsFriendListModel::RsProfileDetails details; + mModel->getProfileData(index,details); - GroupDefs::sortByName(groupInfoList); + if(mModel->getDisplayGroups()) + { + QMenu* addToGroupMenu = NULL; + QMenu* moveToGroupMenu = NULL; - RsPgpId gpgId ( details.gpg_id ); + std::list groupInfoList; + rsPeers->getGroupInfoList(groupInfoList); - QModelIndex parent = mModel->parent(index); + GroupDefs::sortByName(groupInfoList); - bool foundGroup = false; - // add action for all groups, except the own group - for (std::list::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); + RsPgpId gpgId ( details.gpg_id ); - 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); + QModelIndex parent = mModel->parent(index); + + bool foundGroup = false; + // add action for all groups, except the own group + for (std::list::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) { - moveToGroupMenu = new QMenu(tr("Move to group"), &contextMenu); + 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())); } - 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 ; - case RsFriendListModel::ENTRY_TYPE_NODE: - { + case RsFriendListModel::ENTRY_TYPE_NODE: + { #ifdef RS_DIRECT_CHAT - 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.addSeparator(); + 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.addSeparator(); #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) - contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EXPORTFRIEND), tr("Recommend this node to..."), this, SLOT(recommendNode())); + 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())); - RsFriendListModel::RsNodeDetails details; - mModel->getNodeData(index,details); + RsFriendListModel::RsNodeDetails details; + mModel->getNodeData(index,details); - if(!rsPeers->isHiddenNode(rsPeers->getOwnId()) || rsPeers->isHiddenNode( details.id )) - contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_CONNECT), tr("Attempt to connect"), this, SLOT(connectNode())); + 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_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 - contextMenu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REMOVEFRIEND), tr("Remove Friend Node"), this, SLOT(removeNode())); + //this is a SSL key + 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(); } +#ifdef NOT_USED static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay) { int avatarWidth = avatar.width(); @@ -740,6 +751,7 @@ static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay) icon.addPixmap(pixmap); return icon; } +#endif void NewFriendList::addFriend() { @@ -755,37 +767,37 @@ void NewFriendList::addFriend() } void NewFriendList::msgProfile() { - RsFriendListModel::RsNodeDetails det; + RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det)) - return; + if(!getCurrentNode(det)) + return; MessageComposer::msgFriend(det.id); } void NewFriendList::msgGroup() { - RsFriendListModel::RsNodeDetails det; + RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det)) - return; + if(!getCurrentNode(det)) + return; MessageComposer::msgFriend(det.id); } void NewFriendList::msgNode() { - RsFriendListModel::RsNodeDetails det; + RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det)) - return; + if(!getCurrentNode(det)) + return; MessageComposer::msgFriend(det.id); } void NewFriendList::chatNode() { - RsFriendListModel::RsNodeDetails det; + RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det)) - return; + if(!getCurrentNode(det)) + return; ChatDialog::chatFriend(ChatId(det.id)); } @@ -794,10 +806,10 @@ void NewFriendList::recommendNode() { RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det)) - return; + if(!getCurrentNode(det)) + return; - MessageComposer::recommendFriend(std::set({ det.id })); + MessageComposer::recommendFriend(std::set({ det.id })); } void NewFriendList::pastePerson() @@ -808,10 +820,10 @@ void NewFriendList::pastePerson() void NewFriendList::copyFullCertificate() { - RsFriendListModel::RsNodeDetails det; + RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det)) - return; + if(!getCurrentNode(det)) + return; QList urls; RetroShareLink link = RetroShareLink::createCertificate(det.id); @@ -935,33 +947,33 @@ void NewFriendList::removeItem() void NewFriendList::removeNode() { - RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det) || !rsPeers) - return; + RsFriendListModel::RsNodeDetails det; + if(!getCurrentNode(det) || !rsPeers) + return; 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); - checkInternalData(true); + checkInternalData(true); } void NewFriendList::removeProfile() { - RsFriendListModel::RsProfileDetails det; - if(!getCurrentProfile(det) || !rsPeers) - return; + RsFriendListModel::RsProfileDetails det; + if(!getCurrentProfile(det) || !rsPeers) + return; 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); - checkInternalData(true); + checkInternalData(true); } void NewFriendList::connectNode() { - RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det) || !rsPeers) - return; + RsFriendListModel::RsNodeDetails det; + if(!getCurrentNode(det) || !rsPeers) + return; rsPeers->connectAttempt(det.id); ConnectProgressDialog::showProgress(det.id); @@ -972,17 +984,17 @@ void NewFriendList::configureNode() { RsFriendListModel::RsNodeDetails det; - if(!getCurrentNode(det)) - return; + if(!getCurrentNode(det)) + return; ConfCertDialog::showIt(det.id, ConfCertDialog::PageDetails); } void NewFriendList::configureProfile() { - RsFriendListModel::RsProfileDetails det; + RsFriendListModel::RsProfileDetails det; - if(!getCurrentProfile(det)) - return; + if(!getCurrentProfile(det)) + return; PGPKeyDialog::showIt(det.gpg_id, PGPKeyDialog::PageDetails); } @@ -1079,11 +1091,11 @@ void NewFriendList::removeGroup() { RsGroupInfo pinfo; - if(!getCurrentGroup(pinfo)) - return; + if(!getCurrentGroup(pinfo)) + return; rsPeers->removeGroup(pinfo.id); - checkInternalData(true); + checkInternalData(true); } void NewFriendList::applyWhileKeepingTree(std::function predicate) @@ -1199,7 +1211,7 @@ bool NewFriendList::importExportFriendlistFileDialog(QString &fileName, bool imp , tr("Select a file for exporting your friendlist to") , tr("XML File (*.xml);;All Files (*)") , fileName, NULL - , (QFileDialog::Options)0 + , QFileDialog::Options() ); } if ( res && !fileName.endsWith(".xml",Qt::CaseInsensitive) )