diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 6236d935d..35ce75395 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -325,6 +325,7 @@ HEADERS += rshare.h \ gui/common/GroupTreeWidget.h \ gui/common/RSTreeView.h \ gui/common/AvatarWidget.h \ + gui/common/FriendList.h \ gui/style/RSStyle.h \ gui/style/StyleDialog.h \ gui/MessagesDialog.h \ @@ -443,6 +444,7 @@ FORMS += gui/StartDialog.ui \ gui/groups/CreateGroup.ui \ gui/common/GroupTreeWidget.ui \ gui/common/AvatarWidget.ui \ + gui/common/FriendList.ui \ gui/style/StyleDialog.ui \ gui/dht/DhtWindow.ui \ gui/GetStartedDialog.ui @@ -544,6 +546,7 @@ SOURCES += main.cpp \ gui/common/GroupTreeWidget.cpp \ gui/common/RSTreeView.cpp \ gui/common/AvatarWidget.cpp \ + gui/common/FriendList.cpp \ gui/style/RSStyle.cpp \ gui/style/StyleDialog.cpp \ gui/settings/configpage.cpp \ diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index e012ca325..61a367782 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -19,105 +19,54 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "common/vmessagebox.h" -#include "common/StatusDefs.h" -#include "common/GroupDefs.h" -#include "common/Emoticons.h" -#include - -#include "retroshare/rsinit.h" -#include "FriendsDialog.h" -#include -#include -#include -#include -#include -#include -#include "settings/rsharesettings.h" -#include "notifyqt.h" - -#include "chat/PopupChatDialog.h" -#include "msgs/MessageComposer.h" -#include "connect/ConfCertDialog.h" -#ifdef UNFINISHED -#include "unfinished/profile/ProfileView.h" -#endif -#include "profile/ProfileWidget.h" -#include "profile/StatusMessage.h" - -#include "connect/ConnectFriendWizard.h" -#include "forums/CreateForum.h" -#include "channels/CreateChannel.h" -#include "groups/CreateGroup.h" -#include "feeds/AttachFileItem.h" -#include "im_history/ImHistoryBrowser.h" -#include "common/RSTreeWidgetItem.h" -#include "gui/common/AvatarDefs.h" - -#include "RetroShareLink.h" - -#include "MainWindow.h" -#include "NewsFeed.h" -#include "util/misc.h" - #include #include #include #include +#include +#include +#include +#include +#include #include -/* Images for context menu icons */ -#define IMAGE_DENYFRIEND ":/images/denied16.png" -#define IMAGE_REMOVEFRIEND ":/images/removefriend16.png" -#define IMAGE_EXPORTFRIEND ":/images/exportpeers_16x16.png" -#define IMAGE_ADDFRIEND ":/images/user/add_user16.png" -#define IMAGE_FRIENDINFO ":/images/peerdetails_16x16.png" -#define IMAGE_CHAT ":/images/chat.png" -#define IMAGE_MSG ":/images/mail_new.png" -#define IMAGE_CONNECT ":/images/connect_friend.png" -#define IMAGE_COPYLINK ":/images/copyrslink.png" -/* Images for Status icons */ -#define IMAGE_AVAILABLE ":/images/user/identityavaiblecyan24.png" -#define IMAGE_CONNECT2 ":/images/reload24.png" -#define IMAGE_PASTELINK ":/images/pasterslink.png" -#define IMAGE_GROUP16 ":/images/user/group16.png" -#define IMAGE_GROUP24 ":/images/user/group24.png" -#define IMAGE_EDIT ":/images/edit_16.png" -#define IMAGE_REMOVE ":/images/delete.png" -#define IMAGE_EXPAND ":/images/edit_add24.png" -#define IMAGE_COLLAPSE ":/images/edit_remove24.png" +#include "retroshare/rsinit.h" +#include "retroshare/rsnotify.h" +#include "retroshare/rspeers.h" +#include + +#include "channels/CreateChannel.h" +#include "chat/PopupChatDialog.h" +#include "common/Emoticons.h" +#include "common/vmessagebox.h" +#include "connect/ConfCertDialog.h" +#include "connect/ConnectFriendWizard.h" +#include "feeds/AttachFileItem.h" +#include "forums/CreateForum.h" +#include "gui/common/AvatarDefs.h" +#include "gui/mainpagestack.h" +#include "groups/CreateGroup.h" +#include "im_history/ImHistoryBrowser.h" +#include "MainWindow.h" +#include "NewsFeed.h" +#include "notifyqt.h" +#include "profile/ProfileWidget.h" +#include "profile/StatusMessage.h" +#include "RetroShareLink.h" +#include "settings/rsharesettings.h" +#include "util/misc.h" + +#include "FriendsDialog.h" + +/* Images for Newsfeed icons */ #define IMAGE_NEWSFEED "" #define IMAGE_NEWSFEED_NEW ":/images/message-state-new.png" -#define COLUMN_COUNT 2 -#define COLUMN_NAME 0 -#define COLUMN_STATE 1 - -#define COLUMN_DATA 0 // column for storing the userdata id - -#define ROLE_SORT Qt::UserRole -#define ROLE_ID Qt::UserRole + 1 -#define ROLE_STANDARD Qt::UserRole + 2 - -#define TYPE_GPG 0 -#define TYPE_SSL 1 -#define TYPE_GROUP 2 - /****** * #define FRIENDS_DEBUG 1 *****/ - /** Constructor */ FriendsDialog::FriendsDialog(QWidget *parent) : RsAutoUpdatePage(1500,parent) @@ -126,29 +75,25 @@ FriendsDialog::FriendsDialog(QWidget *parent) ui.setupUi(this); last_status_send_time = 0 ; - groupsHasChanged = false; - correctColumnStatusSize = false; - - m_compareRole = new RSTreeWidgetItemCompareRole; - m_compareRole->setRole(COLUMN_NAME, ROLE_SORT); - m_compareRole->setRole(COLUMN_STATE, ROLE_SORT); - - connect( ui.peertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( peertreeWidgetCostumPopupMenu( QPoint ) ) ); - connect( ui.peertreeWidget, SIGNAL( itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *))); - connect( ui.peertreeWidget->header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(peerSortIndicatorChanged(int,Qt::SortOrder))); - connect( ui.mypersonalstatuslabel, SIGNAL(clicked()), SLOT(statusmessage())); connect( ui.actionSet_your_Avatar, SIGNAL(triggered()), this, SLOT(getAvatar())); connect( ui.actionSet_your_Personal_Message, SIGNAL(triggered()), this, SLOT(statusmessage())); connect( ui.addfileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile())); - connect(ui.actionAdd_Friend, SIGNAL(triggered()), this, SLOT(addFriend())); - connect(ui.action_Hide_Offline_Friends, SIGNAL(triggered()), this, SLOT(insertPeers())); - connect(ui.action_Hide_Status_Column, SIGNAL(triggered()), this, SLOT(setStateColumn())); - connect(ui.action_Sort_by_State, SIGNAL(triggered()), this, SLOT(setStateColumn())); - connect(ui.actionSort_Peers_Ascending_Order, SIGNAL(triggered()), this, SLOT(sortPeersAscendingOrder())); - connect(ui.actionSort_Peers_Descending_Order, SIGNAL(triggered()), this, SLOT(sortPeersDescendingOrder())); + + connect(ui.action_Hide_Offline_Friends, SIGNAL(toggled(bool)), ui.friendList, SLOT(setHideUnconnected(bool))); + connect(ui.action_Hide_Status_Column, SIGNAL(toggled(bool)), ui.friendList, SLOT(setHideStatusColumn(bool))); + connect(ui.action_Hide_Status_Column, SIGNAL(toggled(bool)), ui.friendList, SLOT(setHideHeader(bool))); + connect(ui.action_Hide_Status_Column, SIGNAL(toggled(bool)), ui.action_Hide_State, SLOT(setEnabled(bool))); + connect(ui.action_Hide_Avatar_Column, SIGNAL(toggled(bool)), ui.friendList, SLOT(setHideAvatarColumn(bool))); + connect(ui.action_Hide_State, SIGNAL(toggled(bool)), ui.friendList, SLOT(setHideState(bool))); + + connect(ui.action_Sort_by_State, SIGNAL(toggled(bool)), ui.friendList, SLOT(setSortByState(bool))); + connect(ui.actionSort_Peers_Ascending_Order, SIGNAL(triggered()), ui.friendList, SLOT(sortPeersAscendingOrder())); + connect(ui.actionSort_Peers_Descending_Order, SIGNAL(triggered()), ui.friendList, SLOT(sortPeersDescendingOrder())); + + connect(ui.friendList, SIGNAL(peerSortColumnChanged(bool)), this, SLOT(peerSortColumnChanged(bool))); ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatar->setOwnId(); @@ -165,16 +110,6 @@ FriendsDialog::FriendsDialog(QWidget *parent) connect(newsFeed, SIGNAL(newsFeedChanged(int)), this, SLOT(newsFeedChanged(int))); - ui.peertreeWidget->setColumnWidth(COLUMN_NAME, 150); - ui.peertreeWidget->sortItems(COLUMN_NAME, Qt::AscendingOrder); - - // set header text aligment - QTreeWidgetItem * headerItem = ui.peertreeWidget->headerItem(); - headerItem->setTextAlignment(COLUMN_NAME, Qt::AlignHCenter | Qt::AlignVCenter); - headerItem->setTextAlignment(COLUMN_STATE, Qt::AlignLeft | Qt::AlignVCenter); - - wasStatusColumnHidden = ui.peertreeWidget->isColumnHidden(COLUMN_STATE); - connect(ui.Sendbtn, SIGNAL(clicked()), this, SLOT(sendMsg())); connect(ui.emoticonBtn, SIGNAL(clicked()), this, SLOT(smileyWidgetgroupchat())); @@ -245,18 +180,9 @@ FriendsDialog::FriendsDialog(QWidget *parent) displayMenu(); // load settings + RsAutoUpdatePage::lockAllEvents(); processSettings(true); - - /* Set header sizes for the fixed columns and resize modes, must be set after processSettings */ - QHeaderView *header = ui.peertreeWidget->header(); - header->setStretchLastSection(true); - ui.peertreeWidget->setColumnWidth(COLUMN_STATE, 20); // small enough - header->setResizeMode(COLUMN_STATE, QHeaderView::Stretch); - - // 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); - connect(Shortcut, SIGNAL(activated()), this, SLOT( removefriend ())); + RsAutoUpdatePage::unlockAllEvents(); ui.lineEdit->installEventFilter(this); @@ -278,22 +204,17 @@ FriendsDialog::~FriendsDialog () { // save settings processSettings(false); - - delete(m_compareRole); } void FriendsDialog::processSettings(bool bLoad) { - QHeaderView *header = ui.peertreeWidget->header (); - Settings->beginGroup(QString("FriendsDialog")); if (bLoad) { // load settings // state of peer tree - header->restoreState(Settings->value("PeerTree").toByteArray()); - wasStatusColumnHidden = ui.peertreeWidget->isColumnHidden(COLUMN_STATE); + ui.friendList->restoreHeaderState(Settings->value("PeerTree").toByteArray()); // state of hideUnconnected ui.action_Hide_Offline_Friends->setChecked(Settings->value("hideUnconnected", false).toBool()); @@ -304,30 +225,25 @@ void FriendsDialog::processSettings(bool bLoad) // state of hideStatusColumn ui.action_Hide_Status_Column->setChecked(Settings->value("hideStatusColumn", false).toBool()); + // state of hideAvatar + ui.action_Hide_Avatar_Column->setChecked(Settings->value("hideAvatar", true).toBool()); + // state of splitter ui.splitter->restoreState(Settings->value("Splitter").toByteArray()); ui.splitter_2->restoreState(Settings->value("GroupChatSplitter").toByteArray()); // open groups - openGroups.clear(); int arrayIndex = Settings->beginReadArray("Groups"); for (int index = 0; index < arrayIndex; index++) { Settings->setArrayIndex(index); - openGroups.push_back(Settings->value("open").toString().toStdString()); + ui.friendList->addGroupToExpand(Settings->value("open").toString().toStdString()); } Settings->endArray(); - - if (ui.peertreeWidget->isColumnHidden(COLUMN_STATE) && header->sectionSize(COLUMN_STATE) < 100) { - // Workaround - correctColumnStatusSize = true; - } - - setStateColumn(); } else { // save settings // state of peer tree - Settings->setValue("PeerTree", header->saveState()); + Settings->setValue("PeerTree", ui.friendList->saveHeaderState()); // state of hideUnconnected Settings->setValue("hideUnconnected", ui.action_Hide_Offline_Friends->isChecked()); @@ -338,6 +254,9 @@ void FriendsDialog::processSettings(bool bLoad) // state of hideStatusColumn Settings->setValue("hideStatusColumn", ui.action_Hide_Status_Column->isChecked()); + // state of hideAvatar + Settings->setValue("hideAvatar", ui.action_Hide_Avatar_Column->isChecked()); + // state of splitter Settings->setValue("Splitter", ui.splitter->saveState()); Settings->setValue("GroupChatSplitter", ui.splitter_2->saveState()); @@ -345,13 +264,11 @@ void FriendsDialog::processSettings(bool bLoad) // open groups Settings->beginWriteArray("Groups"); int arrayIndex = 0; - int itemCount = ui.peertreeWidget->topLevelItemCount(); - for (int index = 0; index < itemCount; index++) { - QTreeWidgetItem *item = ui.peertreeWidget->topLevelItem(index); - if (item->type() == TYPE_GROUP && item->isExpanded()) { - Settings->setArrayIndex(arrayIndex++); - Settings->setValue("open", item->data(COLUMN_DATA, ROLE_ID).toString()); - } + std::set expandedPeers; + ui.friendList->getExpandedGroups(expandedPeers); + foreach (std::string groupId, expandedPeers) { + Settings->setArrayIndex(arrayIndex++); + Settings->setValue("open", QString::fromStdString(groupId)); } Settings->endArray(); } @@ -389,971 +306,13 @@ void FriendsDialog::contextMenu(QPoint /*point*/) delete(contextMnu); } -void FriendsDialog::peertreeWidgetCostumPopupMenu( QPoint /*point*/ ) -{ - QTreeWidgetItem *c = getCurrentPeer(); - - QMenu contextMnu( this ); - QAction *action; - - QWidget *widget = new QWidget(&contextMnu); - widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}"); - - // create menu header - QHBoxLayout *hbox = new QHBoxLayout(); - hbox->setMargin(0); - hbox->setSpacing(6); - - iconLabel = new QLabel( this ); - iconLabel->setPixmap(QPixmap(":/images/user/friends24.png")); - iconLabel->setMaximumSize( iconLabel->frameSize().height() + 24, 24 ); - hbox->addWidget(iconLabel); - - textLabel = new QLabel("RetroShare", widget ); - - hbox->addWidget(textLabel); - - spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - hbox->addItem(spacerItem); - - widget->setLayout( hbox ); - - QWidgetAction *widgetAction = new QWidgetAction(this); - widgetAction->setDefaultWidget(widget); - - contextMnu.addAction( widgetAction); - - // create menu entries - if (c) { - int type = c->type(); - - // define header - switch (type) { - case TYPE_GROUP: - //this is a GPG key - textLabel->setText("" + tr("Group") + ""); - break; - case TYPE_GPG: - //this is a GPG key - textLabel->setText("" + tr("Friend") + ""); - break; - case TYPE_SSL: - //this is a SSL key - textLabel->setText("" + tr("Location") + ""); - break; - } - - switch (type) { - case TYPE_GROUP: - { - bool standard = c->data(COLUMN_DATA, ROLE_STANDARD).toBool(); - - contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Group"), this, SLOT(msgfriend())); - contextMnu.addAction(QIcon(IMAGE_ADDFRIEND), tr("Add Friend"), this, SLOT(addFriend())); - - contextMnu.addSeparator(); - - action = contextMnu.addAction(QIcon(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup())); - action->setDisabled(standard); - - action = contextMnu.addAction(QIcon(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup())); - action->setDisabled(standard); - } - break; - case TYPE_GPG: - case TYPE_SSL: - { - contextMnu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy())); - contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Friend"), this, SLOT(msgfriend())); - - contextMnu.addSeparator(); - - contextMnu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Friend Details"), this, SLOT(configurefriend())); -// contextMnu.addAction(QIcon(IMAGE_PEERINFO), tr("Profile View"), this, SLOT(viewprofile())); -// action = contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Export Friend"), this, SLOT(exportfriend())); - - if (type == TYPE_GPG) { - contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Recommend this Friend to..."), this, SLOT(recommendfriend())); - } - - contextMnu.addAction(QIcon(IMAGE_CONNECT), tr("Connect To Friend"), this, SLOT(connectfriend())); - - if (type == TYPE_GPG) { - contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink())); - } - - action = contextMnu.addAction(QIcon(IMAGE_PASTELINK), tr("Paste Friend Link"), this, SLOT(pastePerson())); - if (RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) { - action->setDisabled(true); - } - - if (type == TYPE_GPG) { - contextMnu.addAction(QIcon(IMAGE_DENYFRIEND), tr("Deny Friend"), this, SLOT(removefriend())); - } else { - //this is a SSL key - contextMnu.addAction(QIcon(IMAGE_REMOVEFRIEND), tr("Remove Friend Location"), this, SLOT(removefriend())); - } - - if (type == TYPE_GPG) { - QMenu* groupsMenu = NULL; - QMenu* addToGroupMenu = NULL; - QMenu* moveToGroupMenu = NULL; - - std::list groupInfoList; - rsPeers->getGroupInfoList(groupInfoList); - - GroupDefs::sortByName(groupInfoList); - - std::string gpgId = c->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - - QTreeWidgetItem *parent = c->parent(); - - 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) { - if (addToGroupMenu == NULL) { - addToGroupMenu = new QMenu(tr("Add to group"), &contextMnu); - } - QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu); - addToGroupAction->setData(QString::fromStdString(groupIt->id)); - connect(addToGroupAction, SIGNAL(triggered()), this, SLOT(addToGroup())); - addToGroupMenu->addAction(addToGroupAction); - } - - if (moveToGroupMenu == NULL) { - moveToGroupMenu = new QMenu(tr("Move to group"), &contextMnu); - } - QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu); - moveToGroupAction->setData(QString::fromStdString(groupIt->id)); - connect(moveToGroupAction, SIGNAL(triggered()), this, SLOT(moveToGroup())); - moveToGroupMenu->addAction(moveToGroupAction); - } else { - foundGroup = true; - } - } - - if (addToGroupMenu || moveToGroupMenu || foundGroup) { - groupsMenu = contextMnu.addMenu(QIcon(IMAGE_GROUP16), tr("Groups")); - - if (addToGroupMenu) { - groupsMenu->addMenu(addToGroupMenu); - } - - if (moveToGroupMenu) { - groupsMenu->addMenu(moveToGroupMenu); - } - - if (foundGroup) { - // add remove from group - if (parent && parent->type() == TYPE_GROUP) { - QAction *removeFromGroup = groupsMenu->addAction(tr("Remove from group")); - removeFromGroup->setData(parent->data(COLUMN_DATA, ROLE_ID)); - 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())); - } - } - } - } - } - } else { - action = contextMnu.addAction(QIcon(IMAGE_PASTELINK), tr("Paste Friend Link"), this, SLOT(pastePerson())); - if (RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) { - action->setDisabled(true); - } - } - - contextMnu.addSeparator(); - - contextMnu.addAction(QIcon(IMAGE_EXPAND), tr("Expand all"), ui.peertreeWidget, SLOT(expandAll())); - contextMnu.addAction(QIcon(IMAGE_COLLAPSE), tr("Collapse all"), ui.peertreeWidget, SLOT(collapseAll())); - - contextMnu.exec(QCursor::pos()); -} - -// replaced by shortcut -//void FriendsDialog::keyPressEvent(QKeyEvent *e) -//{ -// if(e->key() == Qt::Key_Delete) -// { -// removefriend() ; -// e->accept() ; -// } -// else -// MainPage::keyPressEvent(e) ; -//} - void FriendsDialog::updateDisplay() { - insertPeers() ; -} - -/* get the list of peers from the RsIface. */ -void FriendsDialog::insertPeers() -{ -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::insertPeers() called." << std::endl; -#endif - - std::list gpgFriends; - std::list::iterator gpgIt; - - std::list statusInfo; - rsStatus->getStatusList(statusInfo); - - if (!rsPeers) { - /* not ready yet! */ - std::cerr << "FriendsDialog::insertPeers() not ready yet : rsPeers unintialized." << std::endl; - return; - } - - bool hideUnconnected = ui.action_Hide_Offline_Friends->isChecked(); - bool useStatusColumn = !ui.action_Hide_Status_Column->isChecked(); - bool showState = !ui.action_Hide_State->isChecked(); - - // get ids of existing private chat messages - std::list privateChatIds; - rsMsgs->getPrivateChatQueueIds(true, privateChatIds); - - // get existing groups - std::list groupInfoList; - std::list::iterator groupIt; - rsPeers->getGroupInfoList(groupInfoList); - - rsPeers->getGPGAcceptedList(gpgFriends); - - //add own gpg id, if we have more than on location (ssl client) - std::list ownSslContacts; - std::string ownId = rsPeers->getGPGOwnId(); - rsPeers->getAssociatedSSLIds(ownId, ownSslContacts); - if (ownSslContacts.size() > 0) { - gpgFriends.push_back(ownId); - } - - /* get a link to the table */ - QTreeWidget *peertreeWidget = ui.peertreeWidget; - - // remove items don't exist anymore - QTreeWidgetItemIterator itemIterator(peertreeWidget); - QTreeWidgetItem *item; - while ((item = *itemIterator) != NULL) { - itemIterator++; - switch (item->type()) { - case TYPE_GPG: - { - QTreeWidgetItem *parent = item->parent(); - std::string gpg_widget_id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - - // remove items that are not friends anymore - if (std::find(gpgFriends.begin(), gpgFriends.end(), gpg_widget_id) == gpgFriends.end()) { - if (parent) { - delete(parent->takeChild(parent->indexOfChild(item))); - } else { - delete(peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(item))); - } - break; - } - - if (groupsHasChanged) { - if (parent) { - if (parent->type() == TYPE_GROUP) { - std::string groupId = parent->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - - // the parent is a group, check if the gpg id is assigned to the group - for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); groupIt++) { - if (groupIt->id == groupId) { - if (std::find(groupIt->peerIds.begin(), groupIt->peerIds.end(), gpg_widget_id) == groupIt->peerIds.end()) { - delete(parent->takeChild(parent->indexOfChild(item))); - } - break; - } - } - } - } else { - // gpg item without group, check if the gpg id is assigned to the group - for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); groupIt++) { - if (std::find(groupIt->peerIds.begin(), groupIt->peerIds.end(), gpg_widget_id) != groupIt->peerIds.end()) { - delete(peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(item))); - break; - } - } - } - } - } - break; - case TYPE_GROUP: - { - if (groupsHasChanged) { - // remove deleted groups - std::string groupId = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); groupIt++) { - if (groupIt->id == groupId) { - break; - } - } - if (groupIt == groupInfoList.end() || groupIt->peerIds.size() == 0) { - if (item->parent()) { - delete(item->parent()->takeChild(item->parent()->indexOfChild(item))); - } else { - delete(peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(item))); - } - } - } - } - break; - } - } - - std::list fillGpgIds; - - // start with groups - groupIt = groupInfoList.begin(); - while (true) { - QTreeWidgetItem *groupItem = NULL; - RsGroupInfo *groupInfo = NULL; - int onlineCount = 0; - int availableCount = 0; - if (groupIt != groupInfoList.end()) { - groupInfo = &(*groupIt); - - if ((groupInfo->flag & RS_GROUP_FLAG_STANDARD) && groupInfo->peerIds.size() == 0) { - // don't show empty standard groups - groupIt++; - continue; - } - - // search existing group item - int itemCount = peertreeWidget->topLevelItemCount(); - for (int index = 0; index < itemCount; index++) { - QTreeWidgetItem *groupItemLoop = peertreeWidget->topLevelItem(index); - if (groupItemLoop->type() == TYPE_GROUP && groupItemLoop->data(COLUMN_DATA, ROLE_ID).toString().toStdString() == groupInfo->id) { - groupItem = groupItemLoop; - break; - } - } - - if (groupItem == NULL) { - // add group item - groupItem = new RSTreeWidgetItem(m_compareRole, TYPE_GROUP); - - /* Add item to the list. Add here, because for setHidden the item must be added */ - peertreeWidget->addTopLevelItem(groupItem); - - groupItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); - groupItem->setSizeHint(COLUMN_NAME, QSize(26, 26)); - groupItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter); - groupItem->setIcon(COLUMN_NAME, QIcon(IMAGE_GROUP24)); - groupItem->setForeground(COLUMN_NAME, QBrush(QColor(123, 123, 123))); - - /* used to find back the item */ - groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id)); - groupItem->setData(COLUMN_DATA, ROLE_STANDARD, (groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? true : false); - - if (openGroups.size()) { - if (std::find(openGroups.begin(), openGroups.end(), groupInfo->id) != openGroups.end()) { - groupItem->setExpanded(true); - } - } - } else { - // remove all gpg items that are not more assigned - int childCount = groupItem->childCount(); - int childIndex = 0; - while (childIndex < childCount) { - QTreeWidgetItem *gpgItemLoop = groupItem->child(childIndex); - if (gpgItemLoop->type() == TYPE_GPG) { - if (std::find(groupInfo->peerIds.begin(), groupInfo->peerIds.end(), gpgItemLoop->data(COLUMN_DATA, ROLE_ID).toString().toStdString()) == groupInfo->peerIds.end()) { - delete(groupItem->takeChild(groupItem->indexOfChild(gpgItemLoop))); - childCount = groupItem->childCount(); - continue; - } - } - childIndex++; - } - } - - // name is set after calculation of online/offline items - } - - // iterate through gpg friends - for (gpgIt = gpgFriends.begin(); gpgIt != gpgFriends.end(); gpgIt++) { - std::string gpgId = *gpgIt; - - if (groupInfo) { - // we fill a group, check if gpg id is assigned - if (std::find(groupInfo->peerIds.begin(), groupInfo->peerIds.end(), gpgId) == groupInfo->peerIds.end()) { - continue; - } - } else { - // we fill the not assigned gpg ids - if (std::find(fillGpgIds.begin(), fillGpgIds.end(), gpgId) != fillGpgIds.end()) { - continue; - } - } - - // add equal too, its no problem - fillGpgIds.push_back(gpgId); - - //add the gpg friends -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::insertPeers() inserting gpg_id : " << gpgId << std::endl; -#endif - - /* make a widget per friend */ - QTreeWidgetItem *gpgItem = NULL; - QTreeWidgetItem *gpgItemLoop = NULL; - - // search existing gpg item - int itemCount = groupItem ? groupItem->childCount() : peertreeWidget->topLevelItemCount(); - for (int index = 0; index < itemCount; index++) { - gpgItemLoop = groupItem ? groupItem->child(index) : peertreeWidget->topLevelItem(index); - if (gpgItemLoop->type() == TYPE_GPG && gpgItemLoop->data(COLUMN_DATA, ROLE_ID).toString().toStdString() == gpgId) { - gpgItem = gpgItemLoop; - break; - } - } - - RsPeerDetails detail; - if ((!rsPeers->getPeerDetails(gpgId, detail) || !detail.accept_connection) && detail.gpg_id != ownId) { - // don't accept anymore connection, remove from the view - if (gpgItem) { - if (groupItem) { - delete(groupItem->takeChild(groupItem->indexOfChild(gpgItem))); - } else { - delete (peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpgItem))); - } - } - continue; - } - - if (gpgItem == NULL) { - // create gpg item and add it to tree - gpgItem = new RSTreeWidgetItem(m_compareRole, TYPE_GPG); //set type to 0 for custom popup menu - - /* Add gpg item to the list. Add here, because for setHidden the item must be added */ - if (groupItem) { - groupItem->addChild(gpgItem); - } else { - peertreeWidget->addTopLevelItem(gpgItem); - } - - gpgItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); - gpgItem->setSizeHint(COLUMN_NAME, QSize(26, 26)); - gpgItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter); - - /* not displayed, used to find back the item */ - gpgItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.id)); - } - - availableCount++; - - QString gpgItemText = QString::fromUtf8(detail.name.c_str()); - - // remove items that are not friends anymore - int childCount = gpgItem->childCount(); - int childIndex = 0; - while (childIndex < childCount) { - std::string ssl_id = gpgItem->child(childIndex)->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - if (!rsPeers->isFriend(ssl_id)) { - delete (gpgItem->takeChild(childIndex)); - // count again - childCount = gpgItem->childCount(); - } else { - childIndex++; - } - } - - // update the childs (ssl certs) - bool gpg_connected = false; - bool gpg_online = false; - bool gpg_hasPrivateChat = false; - int bestPeerState = 0; // for gpg item - unsigned int bestRSState = 0; // for gpg item - std::list sslContacts; - - rsPeers->getAssociatedSSLIds(detail.gpg_id, sslContacts); - for (std::list::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); sslIt++) { - QTreeWidgetItem *sslItem = NULL; - std::string sslId = *sslIt; - - //find the corresponding sslItem child item of the gpg item - bool newChild = true; - childCount = gpgItem->childCount(); - for (int childIndex = 0; childIndex < childCount; childIndex++) { - // we assume, that only ssl items are child of the gpg item, so we don't need to test the type - if (gpgItem->child(childIndex)->data(COLUMN_DATA, ROLE_ID).toString().toStdString() == sslId) { - sslItem = gpgItem->child(childIndex); - newChild = false; - break; - } - } - - RsPeerDetails sslDetail; - if (!rsPeers->getPeerDetails(sslId, sslDetail) || !rsPeers->isFriend(sslId)) { -#ifdef FRIENDS_DEBUG - std::cerr << "Removing widget from the view : id : " << sslId << std::endl; -#endif - //child has disappeared, remove it from the gpg_item - if (sslItem) { - gpgItem->removeChild(sslItem); - } - continue; - } - - if (newChild) { - sslItem = new RSTreeWidgetItem(m_compareRole, TYPE_SSL); //set type to 1 for custom popup menu - -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::insertPeers() inserting sslItem." << std::endl; -#endif - - /* Add ssl child to the list. Add here, because for setHidden the item must be added */ - gpgItem->addChild(sslItem); - } - - /* not displayed, used to find back the item */ - sslItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(sslDetail.id)); - - QString sText; - QString customStateString; - if (sslDetail.state & RS_PEER_STATE_CONNECTED) { - customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(sslDetail.id).c_str()); - } - sText = QString::fromUtf8(sslDetail.location.c_str()); - if (customStateString.isEmpty() == false) { - sText += " - " + customStateString; - } - - QString connectStateString = StatusDefs::connectStateString(sslDetail); - if (useStatusColumn) { - sslItem->setText(COLUMN_STATE, connectStateString); - } else if (showState && connectStateString.isEmpty() == false) { - sText += " [" + StatusDefs::connectStateString(sslDetail) + "]"; - } - sslItem->setText( COLUMN_NAME, sText); - - if (useStatusColumn == false && showState == false) { - /* Show the state as tooltip */ - sslItem->setToolTip(COLUMN_NAME, connectStateString); - } else { - sslItem->setToolTip(COLUMN_NAME, ""); - } - - // sort location - sslItem->setData(COLUMN_STATE, ROLE_SORT, sText); - - /* change color and icon */ - QIcon sslIcon; - QFont sslFont; - QColor sslColor; - if (sslDetail.state & RS_PEER_STATE_CONNECTED) { - // get the status info for this ssl id - int peerState = 0; - int rsState = 0; - std::list::iterator it; - for(it = statusInfo.begin(); it != statusInfo.end(); it++) { - if(it->id == sslId){ - rsState = it->status; - switch (rsState) { - case RS_STATUS_INACTIVE: - peerState = PEER_STATE_INACTIVE; - break; - - case RS_STATUS_ONLINE: - peerState = PEER_STATE_ONLINE; - break; - - case RS_STATUS_AWAY: - peerState = PEER_STATE_AWAY; - break; - - case RS_STATUS_BUSY: - peerState = PEER_STATE_BUSY; - break; - } - - /* find the best ssl contact for the gpg item */ - if (bestPeerState == 0 || peerState < bestPeerState) { - /* first ssl contact or higher state */ - bestPeerState = peerState; - bestRSState = rsState; - } else if (peerState == bestPeerState) { - /* equal state ... use first */ - } - break; - } - } - - sslItem->setHidden(false); - gpg_connected = true; - - sslIcon = QIcon(":/images/connect_established.png"); - - if (rsState == 0) { - sslFont.setBold(true); - sslColor = Qt::darkBlue; - } else { - sslFont = StatusDefs::font(rsState); - sslColor = StatusDefs::textColor(rsState); - } - } else if (sslDetail.state & RS_PEER_STATE_ONLINE) { - sslItem->setHidden(hideUnconnected); - gpg_online = true; - - if (sslDetail.connectState) { - sslIcon = QIcon(":/images/connect_creating.png"); - } else { - sslIcon = QIcon(":/images/connect_no.png"); - } - - sslFont.setBold(true); - sslColor = Qt::black; - } else { - sslItem->setHidden(hideUnconnected); - if (sslDetail.connectState) { - sslIcon = QIcon(":/images/connect_creating.png"); - } else { - sslIcon = QIcon(":/images/connect_no.png"); - } - - sslFont.setBold(false); - sslColor = Qt::black; - } - - if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) { - // private chat is available - sslIcon = QIcon(":/images/chat.png"); - gpg_hasPrivateChat = true; - } - sslItem -> setIcon(COLUMN_NAME, sslIcon); - - for (int i = 0; i < COLUMN_COUNT; i++) { - sslItem -> setTextColor(i, sslColor); - sslItem -> setFont(i, sslFont); - } - } - - QIcon gpgIcon; - if (gpg_connected) { - gpgItem->setHidden(false); - - onlineCount++; - - if (bestPeerState == 0) { - // show as online - bestPeerState = PEER_STATE_ONLINE; - bestRSState = RS_STATUS_ONLINE; - } - - QColor textColor = StatusDefs::textColor(bestRSState); - QFont font = StatusDefs::font(bestRSState); - for(int i = 0; i < COLUMN_COUNT; i++) { - gpgItem->setTextColor(i, textColor); - gpgItem->setFont(i, font); - } - - gpgIcon = QIcon(StatusDefs::imageUser(bestRSState)); - - if (useStatusColumn) { - gpgItem->setText(COLUMN_STATE, StatusDefs::name(bestRSState)); - } else if (showState) { - gpgItemText += " [" + StatusDefs::name(bestRSState) + "]"; - } - -// gpgItem->setToolTip(COLUMN_NAME, StatusDefs::tooltip(bestRSState)); - } else if (gpg_online) { - if (useStatusColumn) { - gpgItem->setText(COLUMN_STATE, tr("Available")); - } else if (showState) { - gpgItemText += " [" + tr("Available") + "]"; - } - - bestPeerState = PEER_STATE_AVAILABLE; - onlineCount++; - gpgItem->setHidden(hideUnconnected); - gpgIcon = QIcon(IMAGE_AVAILABLE); - - QFont font; - font.setBold(true); - for(int i = 0; i < COLUMN_COUNT; i++) { - gpgItem->setTextColor(i,(Qt::black)); - gpgItem->setFont(i,font); - } - } else { - if (useStatusColumn) { - gpgItem->setText(COLUMN_STATE, StatusDefs::name(RS_STATUS_OFFLINE)); - } else if (showState) { - gpgItemText += " [" + StatusDefs::name(RS_STATUS_OFFLINE) + "]"; - } - - bestPeerState = PEER_STATE_OFFLINE; - gpgItem->setHidden(hideUnconnected); - gpgIcon = QIcon(StatusDefs::imageUser(RS_STATUS_OFFLINE)); - - QColor textColor = StatusDefs::textColor(RS_STATUS_OFFLINE); - QFont font = StatusDefs::font(RS_STATUS_OFFLINE); - for(int i = 0; i < COLUMN_COUNT; i++) { - gpgItem->setTextColor(i, textColor); - gpgItem->setFont(i, font); - } - } - - if (gpg_hasPrivateChat) { - gpgIcon = QIcon(":/images/chat.png"); - } - - gpgItem->setText(COLUMN_NAME, gpgItemText); - gpgItem->setData(COLUMN_NAME, ROLE_SORT, "2 " + gpgItemText); - gpgItem->setData(COLUMN_STATE, ROLE_SORT, "2 " + BuildStateSortString(true, gpgItemText, bestPeerState)); - gpgItem->setIcon(COLUMN_NAME, gpgIcon); - } - - if (groupInfo && groupItem) { - if ((groupInfo->flag & RS_GROUP_FLAG_STANDARD) && groupItem->childCount() == 0) { - // there are some dead id's assigned - groupItem->setHidden(true); - } else { - QString groupName = GroupDefs::name(*groupInfo); - groupItem->setText(COLUMN_NAME, QString("%1 (%2/%3)").arg(groupName).arg(onlineCount).arg(availableCount)); - // show first the standard groups, than the user groups - groupItem->setData(COLUMN_NAME, ROLE_SORT, ((groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? "0 " : "1 ") + groupName); - } - } - - if (groupIt != groupInfoList.end()) { - groupIt++; - } else { - // all done - break; - } - } - - QTreeWidgetItem *c = getCurrentPeer(); - if (c && c->isHidden()) { - // active item is hidden, deselect it - ui.peertreeWidget->setCurrentItem(NULL); - } - - groupsHasChanged = false; - openGroups.clear(); -} - -/* Utility Fns */ -std::string getPeerRsCertId(QTreeWidgetItem *i) -{ - std::string id = i -> data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - return id; -} - -/** Open a QFileDialog to browse for export a file. */ -void FriendsDialog::exportfriend() -{ - QTreeWidgetItem *c = getCurrentPeer(); - -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::exportfriend()" << std::endl; -#endif - if (!c) - { -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::exportfriend() None Selected -- sorry" << std::endl; -#endif - return; - } - - std::string id = getPeerRsCertId(c); - - if (misc::getSaveFileName(this, RshareSettings::LASTDIR_CERT, tr("Save Certificate"), tr("Certificates (*.pqi)"), fileName)) - { -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::exportfriend() Saving to: " << fileName.toStdString() << std::endl; -#endif - if (rsPeers) - { - rsPeers->saveCertificateToFile(id, fileName.toUtf8().constData()); - } - } - -} - -void FriendsDialog::chatfriendproxy() -{ - chatfriend(getCurrentPeer()); -} - -void FriendsDialog::chatfriend(QTreeWidgetItem *pPeer) -{ - if (pPeer == NULL) { - return; - } - - std::string id = pPeer->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - PopupChatDialog::chatFriend(id); -} - -void FriendsDialog::msgfriend() -{ - QTreeWidgetItem *peer = getCurrentPeer(); - - if (!peer) - return; - - std::string id = peer->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - MessageComposer::msgFriend(id, (peer->type() == TYPE_GROUP)); -} - -void FriendsDialog::recommendfriend() -{ - QTreeWidgetItem *peer = getCurrentPeer(); - - if (!peer) - return; - - std::list ids; - ids.push_back(peer->data(COLUMN_DATA, ROLE_ID).toString().toStdString()); - MessageComposer::recommendFriend(ids); -} - -void FriendsDialog::pastePerson() -{ - RSLinkClipboard::process(RetroShareLink::TYPE_PERSON); -} - -void FriendsDialog::copyLink() -{ - QTreeWidgetItem *c = getCurrentPeer(); - - if (c == NULL) { - return; - } - - QList urls; - RetroShareLink link; - if (link.createPerson(c->data(COLUMN_DATA, ROLE_ID).toString().toStdString())) { - urls.push_back(link); - } - - RSLinkClipboard::copyLinks(urls); -} - -QTreeWidgetItem *FriendsDialog::getCurrentPeer() -{ - /* get the current, and extract the Id */ - - /* get a link to the table */ - QTreeWidget *peerWidget = ui.peertreeWidget; - QTreeWidgetItem *item = peerWidget -> currentItem(); - if (!item) - { -#ifdef FRIENDS_DEBUG - std::cerr << "Invalid Current Item" << std::endl; -#endif - return NULL; - } - -#ifdef FRIENDS_DEBUG - /* Display the columns of this item. */ - std::ostringstream out; - out << "CurrentPeerItem: " << std::endl; - - for(int i = 1; i < COLUMN_COUNT; i++) - { - QString txt = item -> text(i); - out << "\t" << i << ":" << txt.toStdString() << std::endl; - } - std::cerr << out.str(); -#endif - return item; -} - -/* So from the Peers Dialog we can call the following control Functions: - * (1) Remove Current. FriendRemove(id) - * (2) Allow/DisAllow. FriendStatus(id, accept) - * (2) Connect. FriendConnectAttempt(id, accept) - * (3) Set Address. FriendSetAddress(id, str, port) - * (4) Set Trust. FriendTrustSignature(id, bool) - * (5) Configure (GUI Only) -> 3/4 - * - * All of these rely on the finding of the current Id. - */ - - -void FriendsDialog::removefriend() -{ - QTreeWidgetItem *c = getCurrentPeer(); -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::removefriend()" << std::endl; -#endif - if (!c) - { -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::removefriend() None Selected -- sorry" << std::endl; -#endif - return; - } - - if (rsPeers) - { - if ((QMessageBox::question(this, "RetroShare",tr("Do you want to remove this Friend?"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes) - { - rsPeers->removeFriend(getPeerRsCertId(c)); - emit friendsUpdated() ; - } - return; - } -} - -void FriendsDialog::connectfriend() -{ - QTreeWidgetItem *c = getCurrentPeer(); -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::connectfriend()" << std::endl; -#endif - if (!c) - { -#ifdef FRIENDS_DEBUG - std::cerr << "FriendsDialog::connectfriend() Noone Selected -- sorry" << std::endl; -#endif - return; - } - - if (rsPeers) - { - if (c->type() == TYPE_GPG) { - int childCount = c->childCount(); - for (int childIndex = 0; childIndex < childCount; childIndex++) { - QTreeWidgetItem *item = c->child(childIndex); - if (item->type() == TYPE_SSL) { - rsPeers->connectAttempt(getPeerRsCertId(item)); - item->setIcon(COLUMN_NAME,(QIcon(IMAGE_CONNECT2))); - } - } - } else { - //this is a SSL key - rsPeers->connectAttempt(getPeerRsCertId(c)); - c->setIcon(COLUMN_NAME,(QIcon(IMAGE_CONNECT2))); - } - } -} - -/* GUI stuff -> don't do anything directly with Control */ -void FriendsDialog::configurefriend() -{ - ConfCertDialog::showIt(getPeerRsCertId(getCurrentPeer()), ConfCertDialog::PageDetails); } void FriendsDialog::addFriend() { - std::string groupId; - - QTreeWidgetItem *c = getCurrentPeer(); - if (c && c->type() == TYPE_GROUP) { - groupId = c->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - } + std::string groupId = ui.friendList->getSelectedGroupId(); ConnectFriendWizard connwiz (this); @@ -1753,29 +712,6 @@ void FriendsDialog::addSmileys() ui.lineEdit->textCursor().insertText(qobject_cast(sender())->toolTip().split("|").first()); } -#ifdef UNFINISHED -/* GUI stuff -> don't do anything directly with Control */ -void FriendsDialog::viewprofile() -{ - /* display Dialog */ - - QTreeWidgetItem *c = getCurrentPeer(); - - -// static ProfileView *profileview = new ProfileView(); - - - if (!c) - return; - - /* set the Id */ - std::string id = getPeerRsCertId(c); - - profileview -> setPeerId(id); - profileview -> show(); -} -#endif - void FriendsDialog::getAvatar() { QByteArray ba; @@ -2017,55 +953,13 @@ void FriendsDialog::displayMenu() displaymenu->addAction(ui.actionSort_Peers_Ascending_Order); displaymenu->addAction(ui.action_Hide_Offline_Friends); displaymenu->addAction(ui.action_Sort_by_State); + displaymenu->addAction(ui.action_Hide_Avatar_Column); displaymenu->addAction(ui.action_Hide_Status_Column); displaymenu->addAction(ui.action_Hide_State); ui.displayButton->setMenu(displaymenu); } -void FriendsDialog::setStateColumn() -{ - if (ui.action_Hide_Status_Column->isChecked()) { - ui.peertreeWidget->setColumnHidden(COLUMN_STATE, true); - ui.peertreeWidget->setHeaderHidden(true); - ui.action_Hide_State->setEnabled(true); - wasStatusColumnHidden = true; - } else { - ui.peertreeWidget->setColumnHidden(COLUMN_STATE, false); - ui.peertreeWidget->setHeaderHidden(false); - ui.action_Hide_State->setEnabled(false); - if (correctColumnStatusSize) { - correctColumnStatusSize = false; - ui.peertreeWidget->header()->resizeSection(COLUMN_STATE, 100); - } - if (wasStatusColumnHidden) { - ui.peertreeWidget->header()->resizeSection(COLUMN_NAME, ui.peertreeWidget->header()->sectionSize(COLUMN_NAME) - ui.peertreeWidget->header()->sectionSize(COLUMN_STATE)); - } - wasStatusColumnHidden = false; - } - - if(ui.action_Sort_by_State->isChecked()) { - ui.peertreeWidget->sortByColumn(COLUMN_STATE); - } else { - ui.peertreeWidget->sortByColumn(COLUMN_NAME); - } -} - -void FriendsDialog::sortPeersAscendingOrder() -{ - ui.peertreeWidget->sortByColumn(ui.peertreeWidget->sortColumn(), Qt::AscendingOrder); -} - -void FriendsDialog::sortPeersDescendingOrder() -{ - ui.peertreeWidget->sortByColumn(ui.peertreeWidget->sortColumn(), Qt::DescendingOrder); -} - -void FriendsDialog::peerSortIndicatorChanged(int column, Qt::SortOrder) -{ - ui.action_Sort_by_State->setChecked(column == COLUMN_STATE); -} - void FriendsDialog::on_actionMessageHistory_triggered() { ImHistoryBrowser imBrowser("", ui.lineEdit, this); @@ -2078,128 +972,6 @@ void FriendsDialog::on_actionAdd_Group_activated() createGrpDialog.exec(); } -void FriendsDialog::addToGroup() -{ - QTreeWidgetItem *c = getCurrentPeer(); - if (c == NULL) { - return; - } - - if (c->type() != TYPE_GPG) { - // wrong type - return; - } - - std::string groupId = qobject_cast(sender())->data().toString().toStdString(); - std::string gpgId = c->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - - if (gpgId.empty() || groupId.empty()) { - return; - } - - // add to group - rsPeers->assignPeerToGroup(groupId, gpgId, true); -} - -void FriendsDialog::moveToGroup() -{ - QTreeWidgetItem *c = getCurrentPeer(); - if (c == NULL) { - return; - } - - if (c->type() != TYPE_GPG) { - // wrong type - return; - } - - std::string groupId = qobject_cast(sender())->data().toString().toStdString(); - std::string gpgId = c->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - - if (gpgId.empty() || groupId.empty()) { - return; - } - - // remove from all groups - rsPeers->assignPeerToGroup("", gpgId, false); - - // add to group - rsPeers->assignPeerToGroup(groupId, gpgId, true); -} - -void FriendsDialog::removeFromGroup() -{ - QTreeWidgetItem *c = getCurrentPeer(); - if (c == NULL) { - return; - } - - if (c->type() != TYPE_GPG) { - // wrong type - return; - } - - std::string groupId = qobject_cast(sender())->data().toString().toStdString(); - std::string gpgId = c->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - - if (gpgId.empty()) { - return; - } - - // remove from (all) group(s) - rsPeers->assignPeerToGroup(groupId, gpgId, false); -} - -void FriendsDialog::editGroup() -{ - QTreeWidgetItem *c = getCurrentPeer(); - if (c == NULL) { - return; - } - - if (c->type() != TYPE_GROUP) { - // wrong type - return; - } - - std::string groupId = c->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - - if (groupId.empty()) { - return; - } - - CreateGroup editGrpDialog (groupId, this); - editGrpDialog.exec(); -} - -void FriendsDialog::removeGroup() -{ - QTreeWidgetItem *c = getCurrentPeer(); - if (c == NULL) { - return; - } - - if (c->type() != TYPE_GROUP) { - // wrong type - return; - } - - std::string groupId = c->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - - if (groupId.empty()) { - return; - } - - rsPeers->removeGroup(groupId); -} - -void FriendsDialog::groupsChanged(int type) -{ - Q_UNUSED(type); - - groupsHasChanged = true; -} - void FriendsDialog::newsFeedChanged(int count) { if (count) { @@ -2212,3 +984,8 @@ void FriendsDialog::newsFeedChanged(int count) ui.peertabWidget->tabBar()->setTabIcon(newsFeedTabIndex, QIcon(IMAGE_NEWSFEED)); } } + +void FriendsDialog::peerSortColumnChanged(bool sortedByState) +{ + ui.action_Sort_by_State->setChecked(sortedByState); +} diff --git a/retroshare-gui/src/gui/FriendsDialog.h b/retroshare-gui/src/gui/FriendsDialog.h index ba0dd9bde..0d1d8a03c 100644 --- a/retroshare-gui/src/gui/FriendsDialog.h +++ b/retroshare-gui/src/gui/FriendsDialog.h @@ -27,16 +27,6 @@ #include "mainpage.h" -// states for sorting (equal values are possible) -// used in BuildSortString - state + name -#define PEER_STATE_ONLINE 1 -#define PEER_STATE_BUSY 2 -#define PEER_STATE_AWAY 3 -#define PEER_STATE_AVAILABLE 4 -#define PEER_STATE_INACTIVE 5 -#define PEER_STATE_OFFLINE 6 - -#define BuildStateSortString(bEnabled,sName,nState) bEnabled ? (QString ("%1").arg(nState) + " " + sName) : sName #ifndef MINIMAL_RSGUI #include "ui_FriendsDialog.h" @@ -47,9 +37,8 @@ class QTextEdit; class QTextCharFormat; class ChatDialog; class AttachFileItem; -class RSTreeWidgetItemCompareRole; -class FriendsDialog : public RsAutoUpdatePage +class FriendsDialog : public RsAutoUpdatePage { Q_OBJECT @@ -59,15 +48,10 @@ public: /** Default Destructor */ ~FriendsDialog (); - // void setChatDialog(ChatDialog *cd); - virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage - // replaced by shortcut - // virtual void keyPressEvent(QKeyEvent *) ; public slots: - void insertPeers(); void publicChatChanged(int type); // void toggleSendItem( QTreeWidgetItem *item, int col ); @@ -83,8 +67,6 @@ public slots: // called by notifyQt when another peer is typing (in group chant and private chat) void updatePeerStatusString(const QString& peer_id,const QString& status_string,bool is_private_chat) ; - void groupsChanged(int type); - protected: virtual void dragEnterEvent(QDragEnterEvent *event); virtual void dropEvent(QDropEvent *event); @@ -99,39 +81,12 @@ private slots: void on_actionDelete_Chat_History_triggered(); void on_actionMessageHistory_triggered(); - /** Create the context popup menu and it's submenus */ - void peertreeWidgetCostumPopupMenu( QPoint point ); - void updateStatusString(const QString& peer_id, const QString& statusString) ; // called when a peer is typing in group chat void updateStatusTyping() ; // called each time a key is hit //void updatePeerStatusString(const QString& peer_id,const QString& chat_status) ; - /** Export friend in Friends Dialog */ - void exportfriend(); - /** Remove friend */ - void removefriend(); - /** start a chat with a friend **/ void addFriend(); - void chatfriend(QTreeWidgetItem* ); - void chatfriendproxy(); - void msgfriend(); - void recommendfriend(); - void pastePerson(); - void copyLink(); - void addToGroup(); - void moveToGroup(); - void removeFromGroup(); - void editGroup(); - void removeGroup(); - - void configurefriend(); -#ifdef UNFINISHED - void viewprofile(); -#endif - - /** RsServer Friend Calls */ - void connectfriend(); void setColor(); void insertSendList(); @@ -158,15 +113,11 @@ private slots: void setCurrentFileName(const QString &fileName); - void setStateColumn(); - void sortPeersAscendingOrder(); - void sortPeersDescendingOrder(); - void peerSortIndicatorChanged(int,Qt::SortOrder); - void newsFeedChanged(int count); + void peerSortColumnChanged(bool sortedByState); + signals: - void friendsUpdated() ; void notifyGroupChat(const QString&,const QString&) ; private: @@ -176,26 +127,11 @@ private: void colorChanged(const QColor &c); void fontChanged(const QFont &font); - class QLabel *iconLabel, *textLabel; - class QWidget *widget; - class QWidgetAction *widgetAction; - class QSpacerItem *spacerItem; - - RSTreeWidgetItemCompareRole *m_compareRole; - void displayMenu(); ///play the sound when recv a message void playsound(); QString fileName; - bool groupsHasChanged; - std::list openGroups; - - /* Worker Functions */ - /* (1) Update Display */ - - /* (2) Utility Fns */ - QTreeWidgetItem *getCurrentPeer(); ChatStyle style; @@ -207,8 +143,6 @@ private: int newsFeedTabIndex; QColor newsFeedTabColor; QString newsFeedText; - bool wasStatusColumnHidden; - bool correctColumnStatusSize; /** Qt Designer generated object */ Ui::FriendsDialog ui; diff --git a/retroshare-gui/src/gui/FriendsDialog.ui b/retroshare-gui/src/gui/FriendsDialog.ui index 305dc7c3e..1024325f6 100644 --- a/retroshare-gui/src/gui/FriendsDialog.ui +++ b/retroshare-gui/src/gui/FriendsDialog.ui @@ -653,7 +653,10 @@ p, li { white-space: pre-wrap; } - + + + b{} + 0 @@ -666,73 +669,6 @@ p, li { white-space: pre-wrap; } 0 - - - 16777215 - 16777215 - - - - - Arial - 9 - PreferAntialias - true - - - - Qt::CustomContextMenu - - - false - - - QTreeWidget#peertreeWidget{border: 1px solid #CCCCCC; -background: white;} - - - false - - - - 24 - 24 - - - - 1 - - - 20 - - - true - - - true - - - true - - - false - - - false - - - 200 - - - - Friends - - - - - Status - - @@ -1463,6 +1399,30 @@ background: white;} Save Chat History + + + + :/images/user/add_group22.png:/images/user/add_group22.png + + + Add a new Group + + + Add a new Group + + + + + + :/images/edit-clear-history.png:/images/edit-clear-history.png + + + Delete Chat History + + + Deletes all stored and displayed chat history + + true @@ -1494,20 +1454,11 @@ background: white;} true - - Hide State - - - - - - :/images/user/add_group22.png:/images/user/add_group22.png + + false - Add a new Group - - - Add a new Group + Hide State @@ -1534,16 +1485,15 @@ background: white;} Sort Ascending Order - - - - :/images/edit-clear-history.png:/images/edit-clear-history.png + + + true - Delete Chat History + Hide Avatar Column - Deletes all stored and displayed chat history + Hide Avatar Column @@ -1560,6 +1510,13 @@ background: white;}
gui/common/RSTabWidget.h
1 + + FriendList + QWidget +
gui/common/FriendList.h
+ 1 +
+ diff --git a/retroshare-gui/src/gui/MessengerWindow.cpp b/retroshare-gui/src/gui/MessengerWindow.cpp index 23feee547..0c8761d66 100644 --- a/retroshare-gui/src/gui/MessengerWindow.cpp +++ b/retroshare-gui/src/gui/MessengerWindow.cpp @@ -27,7 +27,6 @@ #include "common/vmessagebox.h" #include "common/StatusDefs.h" -#include #include #include #include @@ -39,49 +38,21 @@ #ifndef MINIMAL_RSGUI #include "MainWindow.h" -#include "chat/PopupChatDialog.h" -#include "msgs/MessageComposer.h" #include "ShareManager.h" #include "notifyqt.h" #include "connect/ConnectFriendWizard.h" #endif // MINIMAL_RSGUI -#include "FriendsDialog.h" -#include "connect/ConfCertDialog.h" #include "util/PixmapMerging.h" #include "LogoBar.h" #include "util/Widget.h" #include "util/misc.h" #include "settings/rsharesettings.h" -#include "common/RSTreeWidgetItem.h" -#include "common/AvatarDefs.h" - -#include "RetroShareLink.h" #include #include #include #include -/* Images for context menu icons */ -#define IMAGE_REMOVEFRIEND ":/images/removefriend16.png" -#define IMAGE_EXPIORTFRIEND ":/images/exportpeers_16x16.png" -#define IMAGE_CHAT ":/images/chat.png" -#define IMAGE_MSG ":/images/message-mail.png" -#define IMAGE_CONNECT ":/images/connect_friend.png" -#define IMAGE_PEERINFO ":/images/peerdetails_16x16.png" -#define IMAGE_AVAIBLE ":/images/user/identityavaiblecyan24.png" -#define IMAGE_CONNECT2 ":/images/reload24.png" -#define IMAGE_PASTELINK ":/images/pasterslink.png" - -#define COLUMN_COUNT 3 -#define COLUMN_NAME 0 -#define COLUMN_STATE 1 -#define COLUMN_INFO 2 - -#define COLUMN_DATA 0 // column for storing the userdata id - -#define ROLE_SORT Qt::UserRole -#define ROLE_ID Qt::UserRole + 1 /****** * #define MSG_DEBUG 1 @@ -129,68 +100,51 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags) setAttribute (Qt::WA_QuitOnClose, true); #endif // MINIMAL_RSGUI - m_compareRole = new RSTreeWidgetItemCompareRole; - m_compareRole->setRole(COLUMN_NAME, ROLE_SORT); - ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatar->setOwnId(); - connect( ui.messengertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messengertreeWidgetCostumPopupMenu( QPoint ) ) ); #ifndef MINIMAL_RSGUI - connect( ui.messengertreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *))); - connect( ui.shareButton, SIGNAL(clicked()), SLOT(openShareManager())); connect( ui.addIMAccountButton, SIGNAL(clicked( bool ) ), this , SLOT( addFriend() ) ); #endif // MINIMAL_RSGUI - connect( ui.actionHide_Offline_Friends, SIGNAL(triggered()), this, SLOT(insertPeers())); - connect( ui.actionSort_by_State, SIGNAL(triggered()), this, SLOT(insertPeers())); + connect(ui.actionHide_Offline_Friends, SIGNAL(toggled(bool)), ui.friendList, SLOT(setHideUnconnected(bool))); + connect(ui.actionSort_by_State, SIGNAL(toggled(bool)), ui.friendList, SLOT(setSortByState(bool))); + connect(ui.actionRoot_is_decorated, SIGNAL(toggled(bool)), ui.friendList, SLOT(setRootIsDecorated(bool))); connect(ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage())); connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged())); #ifndef MINIMAL_RSGUI - connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateMessengerDisplay())); connect(NotifyQt::getInstance(), SIGNAL(ownAvatarChanged()), this, SLOT(updateAvatar())); connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage())); connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int))); #endif // MINIMAL_RSGUI - timer = new QTimer(this); - timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateMessengerDisplay())); - timer->setInterval(1000); /* one second */ - timer->setSingleShot(true); - - /* to hide the header */ - ui.messengertreeWidget->header()->hide(); - - /* Set header resize modes and initial section sizes */ - ui.messengertreeWidget->setColumnCount(COLUMN_COUNT); - ui.messengertreeWidget->setColumnHidden ( COLUMN_INFO, true); - ui.messengertreeWidget->sortItems( COLUMN_NAME, Qt::AscendingOrder ); - - QHeaderView * _header = ui.messengertreeWidget->header () ; - _header->setResizeMode (COLUMN_NAME, QHeaderView::Stretch); - _header->setResizeMode (COLUMN_STATE, QHeaderView::Custom); - _header->setStretchLastSection(false); - - _header->resizeSection ( COLUMN_NAME, 200 ); - _header->resizeSection ( COLUMN_STATE, 42 ); + if (expandedPeers != NULL) { + for (std::set::iterator peerIt = expandedPeers->begin(); peerIt != expandedPeers->end(); peerIt++) { + ui.friendList->addPeerToExpand(*peerIt); + } + delete expandedPeers; + expandedPeers = NULL; + } //LogoBar - _rsLogoBarmessenger = NULL; _rsLogoBarmessenger = new LogoBar(ui.logoframe); Widget::createLayout(ui.logoframe)->addWidget(_rsLogoBarmessenger); ui.messagelineEdit->setMinimumWidth(20); - itemFont = QFont("ARIAL", 10); - itemFont.setBold(true); - displayMenu(); // load settings + RsAutoUpdatePage::lockAllEvents(); processSettings(true); + ui.friendList->setHideHeader(true); + ui.friendList->setHideStatusColumn(true); + ui.friendList->setHideGroups(true); + ui.friendList->setBigName(true); + RsAutoUpdatePage::unlockAllEvents(); // add self nick RsPeerDetails pd; @@ -219,12 +173,8 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags) loadmystatusmessage(); #endif // MINIMAL_RSGUI - insertPeers(); - ui.clearButton->hide(); - updateMessengerDisplay(); - /* Hide platform specific features */ #ifdef Q_WS_WIN #endif @@ -242,22 +192,18 @@ MessengerWindow::~MessengerWindow () } #endif // MINIMAL_RSGUI - delete(m_compareRole); - _instance = NULL; } void MessengerWindow::processSettings(bool bLoad) { - QHeaderView *header = ui.messengertreeWidget->header (); - Settings->beginGroup(_name); if (bLoad) { // load settings // state of messenger tree - header->restoreState(Settings->value("MessengerTree").toByteArray()); + ui.friendList->restoreHeaderState(Settings->value("MessengerTree").toByteArray()); // state of actionHide_Offline_Friends ui.actionHide_Offline_Friends->setChecked(Settings->value("hideOfflineFriends", false).toBool()); @@ -266,13 +212,14 @@ void MessengerWindow::processSettings(bool bLoad) ui.actionSort_by_State->setChecked(Settings->value("sortByState", false).toBool()); // state of actionRoot_is_decorated - ui.actionRoot_is_decorated->setChecked(Settings->value("rootIsDecorated", true).toBool()); - on_actionRoot_is_decorated_activated(); + bool decorated = Settings->value("rootIsDecorated", true).toBool(); + ui.actionRoot_is_decorated->setChecked(decorated); + ui.friendList->setRootIsDecorated(decorated); } else { // save settings // state of messenger tree - Settings->setValue("MessengerTree", header->saveState()); + Settings->setValue("MessengerTree", ui.friendList->saveHeaderState()); // state of actionSort_by_State Settings->setValue("sortByState", ui.actionSort_by_State->isChecked()); @@ -287,571 +234,6 @@ void MessengerWindow::processSettings(bool bLoad) Settings->endGroup(); } -void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint /*point*/ ) -{ - QTreeWidgetItem *c = getCurrentPeer(); - - QMenu contextMnu( this ); - - QAction* expandAll = new QAction(tr( "Expand all" ), &contextMnu ); - connect( expandAll , SIGNAL( triggered() ), ui.messengertreeWidget, SLOT (expandAll()) ); - - QAction* collapseAll = new QAction(tr( "Collapse all" ), &contextMnu ); - connect( collapseAll , SIGNAL( triggered() ), ui.messengertreeWidget, SLOT(collapseAll()) ); - -#ifndef MINIMAL_RSGUI - QAction* chatAct = new QAction(QIcon(IMAGE_CHAT), tr( "Chat" ), &contextMnu ); - if (c) { - connect( chatAct , SIGNAL( triggered() ), this, SLOT( chatfriendproxy() ) ); - } else { - chatAct->setDisabled(true); - } - - QAction* sendMessageAct = new QAction(QIcon(IMAGE_MSG), tr( "Message Friend" ), &contextMnu ); - if (c) { - connect( sendMessageAct , SIGNAL( triggered() ), this, SLOT( sendMessage() ) ); - } else { - sendMessageAct->setDisabled(true); - } -#endif // MINIMAL_RSGUI - - QAction* connectfriendAct = new QAction(QIcon(IMAGE_CONNECT), tr( "Connect To Friend" ), &contextMnu ); - if (c) { - connect( connectfriendAct , SIGNAL( triggered() ), this, SLOT( connectfriend() ) ); - } else { - connectfriendAct->setDisabled(true); - } - -#ifndef MINIMAL_RSGUI - QAction* configurefriendAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Peer Details" ), &contextMnu ); - if (c) { - connect( configurefriendAct , SIGNAL( triggered() ), this, SLOT( configurefriend() ) ); - } else { - configurefriendAct->setDisabled(true); - } - - QAction* recommendfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Recomend this Friend to..." ), &contextMnu ); - if (c && c->type() == 0) { - connect( recommendfriendAct , SIGNAL( triggered() ), this, SLOT( recommendfriend() ) ); - } else { - recommendfriendAct->setDisabled(true); - } - - QAction* pastePersonAct = new QAction(QIcon(IMAGE_PASTELINK), tr( "Paste RetroShare Link" ), &contextMnu ); - if(!RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) { - connect( pastePersonAct , SIGNAL( triggered() ), this, SLOT( pastePerson() ) ); - } else { - pastePersonAct->setDisabled(true); - } - - //QAction* profileviewAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Profile View" ), &contextMnu ); - //connect( profileviewAct , SIGNAL( triggered() ), this, SLOT( viewprofile() ) ); - - QAction* exportfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Export Friend" ), &contextMnu ); - if (c) { - connect( exportfriendAct , SIGNAL( triggered() ), this, SLOT( exportfriend() ) ); - } else { - exportfriendAct->setDisabled(true); - } - - QAction* removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Deny Friend" ), &contextMnu ); - if (c) { - if (c->type() == 1) { - //this is a SSL key - removefriendAct->setText(tr( "Remove Friend Location")); - } - connect( removefriendAct , SIGNAL( triggered() ), this, SLOT( removefriend() ) ); - } else { - removefriendAct->setDisabled(true); - } -#endif // MINIMAL_RSGUI - - QWidget *widget = new QWidget(); - widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}"); - - QHBoxLayout *hbox = new QHBoxLayout(&contextMnu); - hbox->setMargin(0); - hbox->setSpacing(6); - - QLabel *iconLabel = new QLabel(&contextMnu); - iconLabel->setPixmap(QPixmap(":/images/user/friends24.png")); - iconLabel->setMaximumSize( iconLabel->frameSize().height() + 24, 24 ); - hbox->addWidget(iconLabel); - - QLabel *textLabel; - textLabel = new QLabel( tr("RetroShare instance"), widget ); - if (c && c->type() == 0) { - //this is a GPG key - textLabel->setText(tr("GPG Key")); - } - - hbox->addWidget(textLabel); - - QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - hbox->addItem(spacerItem); - - widget->setLayout( hbox ); - - QWidgetAction *widgetAction = new QWidgetAction(this); - widgetAction->setDefaultWidget(widget); - - contextMnu.addAction( widgetAction); -#ifndef MINIMAL_RSGUI - contextMnu.addAction( chatAct); - contextMnu.addAction( sendMessageAct); - contextMnu.addAction( configurefriendAct); - //contextMnu.addAction( profileviewAct); - contextMnu.addAction( recommendfriendAct); -#endif // MINIMAL_RSGUI - contextMnu.addAction( connectfriendAct); -#ifndef MINIMAL_RSGUI - contextMnu.addAction(pastePersonAct); - contextMnu.addAction( removefriendAct); -#endif // MINIMAL_RSGUI - //contextMnu.addAction( exportfriendAct); - contextMnu.addSeparator(); - contextMnu.addAction( expandAll); - contextMnu.addAction( collapseAll); - contextMnu.exec(QCursor::pos()); -} - -void MessengerWindow::updateMessengerDisplay() -{ - if (RsAutoUpdatePage::eventsLocked() == false) { - insertPeers(); - } - - timer->start(); -} - -/* get the list of peers from the RsIface. */ -void MessengerWindow::insertPeers() -{ - std::list gpgFriends; - std::list::iterator it; - std::list statusInfo; -#ifndef MINIMAL_RSGUI - rsStatus->getStatusList(statusInfo); -#endif // MINIMAL_RSGUI - - if (!rsPeers) { - /* not ready yet! */ - std::cerr << "FriendsDialog::insertPeers() not ready yet : rsPeers unintialized." << std::endl; - return; - } - - std::list privateChatIds; -#ifndef MINIMAL_RSGUI - rsMsgs->getPrivateChatQueueIds(true, privateChatIds); -#endif // MINIMAL_RSGUI - - rsPeers->getGPGAcceptedList(gpgFriends); - - std::string sOwnId = rsPeers->getGPGOwnId(); - - //add own gpg id, if we have more than on location (ssl client) - std::list ownSslContacts; - rsPeers->getAssociatedSSLIds(sOwnId, ownSslContacts); - if (ownSslContacts.size() > 0) { - gpgFriends.push_back(sOwnId); - } - - /* get a link to the table */ - QTreeWidget *peertreeWidget = ui.messengertreeWidget; - - bool sortState = ui.actionSort_by_State->isChecked(); - bool hideOfflineFriends = ui.actionHide_Offline_Friends->isChecked(); - - //remove items that are not fiends anymore - int itemCount = peertreeWidget->topLevelItemCount(); - int index = 0; - while (index < itemCount) { - std::string gpg_widget_id = peertreeWidget->topLevelItem(index)->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - if (std::find(gpgFriends.begin(), gpgFriends.end(), gpg_widget_id) == gpgFriends.end()) { - delete (peertreeWidget->takeTopLevelItem(index)); - // count again - itemCount = peertreeWidget->topLevelItemCount(); - } else { - index++; - } - } - - //add the gpg friends - for(it = gpgFriends.begin(); it != gpgFriends.end(); it++) { - /* make a widget per friend */ - QTreeWidgetItem *gpg_item = NULL; - QTreeWidgetItem *gpg_item_loop = NULL; - QString gpgid = QString::fromStdString(*it); - itemCount = peertreeWidget->topLevelItemCount(); - for (int nIndex = 0; nIndex < itemCount; nIndex++) { - gpg_item_loop = peertreeWidget->topLevelItem(nIndex); - if (gpg_item_loop->data(COLUMN_DATA, ROLE_ID).toString() == gpgid) { - gpg_item = gpg_item_loop; - break; - } - } - - RsPeerDetails detail; - if ((!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection) - && detail.gpg_id != sOwnId) { - //don't accept anymore connection, remove from the view - delete (peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item))); - continue; - } - - if (gpg_item == NULL) { - gpg_item = new RSTreeWidgetItem(m_compareRole, 0); //set type to 0 for custom popup menu - gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); - } - - gpg_item -> setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter ); - gpg_item -> setSizeHint(COLUMN_NAME, QSize( 40,40 ) ); - - /* not displayed, used to find back the item */ - gpg_item -> setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.id)); - - //remove items that are not friends anymore - int childCount = gpg_item->childCount(); - int childIndex = 0; - while (childIndex < childCount) { - std::string ssl_id = gpg_item->child(childIndex)->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - if (!rsPeers->isFriend(ssl_id)) { - delete (gpg_item->takeChild(childIndex)); - // count again - childCount = gpg_item->childCount(); - } else { - childIndex++; - } - } - - //update the childs (ssl certs) - bool gpg_connected = false; - bool gpg_online = false; - bool gpg_hasPrivateChat = false; - std::list sslContacts; - std::map sslLocations; - std::map sslCustomStateStrings; - - rsPeers->getAssociatedSSLIds(detail.gpg_id, sslContacts); - for(std::list::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); sslIt++) { - QTreeWidgetItem *sslItem = NULL; - - //find the corresponding sslItem child item of the gpg item - bool newChild = true; - childCount = gpg_item->childCount(); - for (int childIndex = 0; childIndex < childCount; childIndex++) { - if (gpg_item->child(childIndex)->data(COLUMN_DATA, ROLE_ID).toString().toStdString() == *sslIt) { - sslItem = gpg_item->child(childIndex); - newChild = false; - break; - } - } - - RsPeerDetails sslDetail; - if (!rsPeers->getPeerDetails(*sslIt, sslDetail) || !rsPeers->isFriend(*sslIt)) { - std::cerr << "Removing widget from the view : id : " << *sslIt << std::endl; - if (sslItem) { - //child has disappeared, remove it from the gpg_item - gpg_item->removeChild(sslItem); - } - continue; - } - - if (sslItem == NULL) { - sslItem = new RSTreeWidgetItem(m_compareRole, 1); //set type to 1 for custom popup menu - } - - /* not displayed, used to find back the item */ - sslItem -> setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(sslDetail.id)); - - /* store location */ - sslLocations[sslDetail.id] = sslDetail.location; - - QString sCustomString; -#ifndef MINIMAL_RSGUI - if (sslDetail.state & RS_PEER_STATE_CONNECTED) { - sCustomString = QString::fromUtf8(rsMsgs->getCustomStateString(sslDetail.id).c_str()); - } -#endif // MINIMAL_RSGUI - if (sCustomString.isEmpty()) { - sslItem -> setText( COLUMN_NAME, QString::fromUtf8(sslDetail.location.c_str()) + " " + StatusDefs::connectStateString(sslDetail)); - sslItem -> setToolTip( COLUMN_NAME, tr("location") + " : " + QString::fromUtf8(sslDetail.location.c_str())); - } else { - sslItem -> setText( COLUMN_NAME, QString::fromUtf8(sslDetail.location.c_str()) + " " + StatusDefs::connectStateString(sslDetail)); - sslItem -> setToolTip( COLUMN_NAME, tr("location") + " : " + QString::fromUtf8(sslDetail.location.c_str()) + " - " + sCustomString); - - /* store custom state string */ - sslCustomStateStrings[sslDetail.id] = sCustomString; - } - - QIcon sslIcon; - QFont sslFont; - QColor sslColor; - if (sslDetail.state & RS_PEER_STATE_CONNECTED) { - sslItem->setHidden(false); - gpg_connected = true; - -#ifdef MINIMAL_RSGUI -// to show the gpg as online, remove it with MINIMAL_RSGUI - QFont font1; - font1.setBold(true); - - gpg_item->setToolTip(COLUMN_NAME, StatusDefs::tooltip(RS_STATUS_ONLINE)); - gpg_item->setData(COLUMN_NAME, ROLE_SORT, BuildStateSortString(sortState, gpg_item->text(COLUMN_NAME), PEER_STATE_ONLINE)); - - QColor textColor = StatusDefs::textColor(RS_STATUS_ONLINE); - QFont font = StatusDefs::font(RS_STATUS_ONLINE); - for(int i = 0; i < COLUMN_COUNT; i++) { - gpg_item -> setTextColor(i, textColor); - gpg_item -> setFont(i, font); - } -#endif // MINIMAL_RSGUI - - /* change color and icon */ - sslIcon = QIcon(":/images/connect_established.png"); - sslFont.setBold(true); - sslColor = Qt::darkBlue; - } else if (sslDetail.state & RS_PEER_STATE_ONLINE) { - sslItem->setHidden(hideOfflineFriends); - gpg_online = true; - - if (sslDetail.connectState) { - sslIcon = QIcon(":/images/connect_creating.png"); - } else { - sslIcon = QIcon(":/images/connect_no.png"); - } - - sslFont.setBold(true); - sslColor = Qt::black; - } else { - sslItem->setHidden(hideOfflineFriends); - if (sslDetail.connectState) { - sslIcon = QIcon(":/images/connect_creating.png"); - } else { - sslIcon = QIcon(":/images/connect_no.png"); - } - - sslFont.setBold(false); - sslColor = Qt::black; - } - - if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) { - // private chat is available - sslIcon = QIcon(":/images/chat.png"); - gpg_hasPrivateChat = true; - } - sslItem -> setIcon(COLUMN_NAME, sslIcon); - - for (int i = 0; i < COLUMN_COUNT; i++) { - sslItem -> setTextColor(i, sslColor); - sslItem -> setFont(i, sslFont); - } - -#ifdef PEERS_DEBUG - std::cerr << "FriendsDialog::insertPeers() inserting sslItem." << std::endl; -#endif - /* add sl child to the list. If item is already in the list, it won't be duplicated thanks to Qt */ - gpg_item->addChild(sslItem); - if (newChild) { - gpg_item->setExpanded(true); - } - } - - int i = 0; - QIcon gpgIcon; - - if (gpg_connected) { - gpg_item->setHidden(false); - -#ifdef MINIMAL_RSGUI - gpgIcon = QIcon(StatusDefs::imageIM(RS_STATUS_ONLINE)); -#else - int bestPeerState = 0; // for gpg item - std::string bestSslId; // for gpg item - unsigned int bestRSState = 0; // for gpg item - - std::list::iterator it = statusInfo.begin(); - for(; it != statusInfo.end() ; it++){ - - // don't forget the kids - std::list::iterator cont_it = sslContacts.begin(); - for(; cont_it != sslContacts.end(); cont_it++){ - - if((it->id == *cont_it) && (rsPeers->isOnline(*cont_it))) { - - int peerState = 0; - - gpg_item -> setText(COLUMN_STATE, StatusDefs::name(it->status)); - - QPixmap avatar; - AvatarDefs::getAvatarFromSslId(it->id, avatar); - QIcon avatar_icon(avatar); - gpg_item->setIcon(COLUMN_STATE, avatar_icon); - - switch (it->status) { - case RS_STATUS_INACTIVE: - peerState = PEER_STATE_INACTIVE; - break; - - case RS_STATUS_ONLINE: - peerState = PEER_STATE_ONLINE; - break; - - case RS_STATUS_AWAY: - peerState = PEER_STATE_AWAY; - break; - - case RS_STATUS_BUSY: - peerState = PEER_STATE_BUSY; - break; - } - - /* find the best ssl contact for the gpg item */ - if (bestPeerState == 0) { - /* first ssl contact */ - bestPeerState = peerState; - bestSslId = *cont_it; - bestRSState = it->status; - } else if (peerState < bestPeerState) { - /* higher state */ - bestPeerState = peerState; - bestSslId = *cont_it; - bestRSState = it->status; - } else if (peerState == bestPeerState) { - /* equal state */ - - /* use the ssl id with existing custom state string */ - std::map::iterator it1 = sslCustomStateStrings.find(bestSslId); - std::map::iterator it2 = sslCustomStateStrings.find(*cont_it); - - if (it1 == sslCustomStateStrings.end()) { - if (it2 == sslCustomStateStrings.end()) { - /* both with no custom state string ... use first */ - } else { - /* second with a custom state string ... use second */ - bestPeerState = peerState; - bestSslId = *cont_it; - } - } else { - /* use first */ - } - } - } - } - } - - if (bestPeerState == 0) { - // show as online - bestPeerState = PEER_STATE_ONLINE; - bestRSState = RS_STATUS_ONLINE; - } - - QColor textColor = StatusDefs::textColor(bestRSState); - QFont font = StatusDefs::font(bestRSState); - for(i = 0; i < COLUMN_COUNT; i++) { - gpg_item -> setTextColor(i, textColor); - gpg_item -> setFont(i, font); - } - - gpgIcon = QIcon(StatusDefs::imageIM(bestRSState)); - - gpg_item->setText(COLUMN_NAME, QString::fromUtf8(detail.name.c_str())); - gpg_item -> setToolTip(COLUMN_NAME, StatusDefs::tooltip(bestRSState)); - - std::map::iterator customStateString = sslCustomStateStrings.find(bestSslId); - if (customStateString == sslCustomStateStrings.end()) { -// std::map::iterator location = sslLocations.find(bestSslId); -// if (location == sslLocations.end()) { -// /* show only the name */ -// gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name)); -// } else { -// /* show the name with location */ -// gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name) + "\n" + QString::fromStdString(location->second)); -// } - - /* use state string for location */ - QString stateString; - stateString = StatusDefs::name(bestRSState); - - if (stateString.isEmpty()) { - /* show only the name */ - gpg_item->setText(COLUMN_NAME, QString::fromUtf8(detail.name.c_str())); - } else { - /* show the name with location */ - gpg_item->setText(COLUMN_NAME, QString::fromUtf8(detail.name.c_str()) + "\n" + stateString); - } - } else { - /* show the name with custom state string */ - gpg_item->setText(COLUMN_NAME, QString::fromUtf8(detail.name.c_str()) + "\n" + customStateString->second); - } - - gpg_item->setData(COLUMN_NAME, ROLE_SORT, BuildStateSortString(sortState, gpg_item->text(COLUMN_NAME), bestPeerState)); - -#endif // MINIMAL_RSGUI - } else if (gpg_online) { - gpg_item->setHidden(hideOfflineFriends); - gpg_item->setText(COLUMN_NAME, QString::fromUtf8(detail.name.c_str())); - gpgIcon = QIcon(IMAGE_AVAIBLE); - gpg_item->setData(COLUMN_NAME, ROLE_SORT, BuildStateSortString(sortState, gpg_item->text(COLUMN_NAME), PEER_STATE_AVAILABLE)); - QFont font; - font.setBold(true); - for(i = 0; i < COLUMN_COUNT; i++) { - gpg_item -> setTextColor(i,(Qt::black)); - gpg_item -> setFont(i,font); - } - } else { - gpg_item->setHidden(hideOfflineFriends); - gpg_item->setText(COLUMN_NAME, QString::fromUtf8(detail.name.c_str())); - gpgIcon = QIcon(StatusDefs::imageIM(RS_STATUS_OFFLINE)); - gpg_item->setData(COLUMN_NAME, ROLE_SORT, BuildStateSortString(sortState, gpg_item->text(COLUMN_NAME), PEER_STATE_OFFLINE)); - - QColor textColor = StatusDefs::textColor(RS_STATUS_OFFLINE); - QFont font = StatusDefs::font(RS_STATUS_OFFLINE); - for(i = 0; i < COLUMN_COUNT; i++) { - gpg_item -> setTextColor(i, textColor); - gpg_item -> setFont(i, font); - } - } - - if (gpg_hasPrivateChat) { - gpgIcon = QIcon(":/images/chat.png"); - } - - gpg_item -> setIcon(COLUMN_NAME, gpgIcon); - - /* add gpg item to the list. If item is already in the list, it won't be duplicated thanks to Qt */ - peertreeWidget->addTopLevelItem(gpg_item); - - if (expandedPeers && expandedPeers->find(detail.gpg_id) != expandedPeers->end()) { - /* we have information about expanded peers and the peer was expanded */ - gpg_item->setExpanded(true); - } - } - - if (ui.filterPatternLineEdit->text().isEmpty() == false) { - FilterItems(); - } - - if (expandedPeers) { - /* we don't need the informations anymore */ - delete(expandedPeers); - expandedPeers = NULL; - } - - QTreeWidgetItem *c = getCurrentPeer(); - if (c && c->isHidden()) { - // active item is hidden, deselect it - ui.messengertreeWidget->setCurrentItem(NULL); - } -} - -/* Utility Fns */ -std::string getPeersRsCertId(QTreeWidgetItem *i) -{ - std::string id = i -> data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - return id; -} - #ifndef MINIMAL_RSGUI /** Add a Friend ShortCut */ void MessengerWindow::addFriend() @@ -860,183 +242,10 @@ void MessengerWindow::addFriend() connwiz.exec (); } - -/** Open a QFileDialog to browse for export a file. */ -void MessengerWindow::exportfriend() -{ - QTreeWidgetItem *c = getCurrentPeer(); - -#ifdef PEERS_DEBUG - std::cerr << "FriendsDialog::exportfriend()" << std::endl; #endif - if (!c) - { -#ifdef PEERS_DEBUG - std::cerr << "FriendsDialog::exportfriend() None Selected -- sorry" << std::endl; -#endif - return; - } - - std::string id = getPeersRsCertId(c); - QString fileName = QFileDialog::getSaveFileName(this, tr("Save Certificate"), "", - tr("Certificates (*.pqi)")); - - std::string file = fileName.toStdString(); - if (file != "") - { -#ifdef PEERS_DEBUG - std::cerr << "FriendsDialog::exportfriend() Saving to: " << file << std::endl; - std::cerr << std::endl; -#endif - if (rsPeers) - { - rsPeers->saveCertificateToFile(id, file); - } - } - -} - -void MessengerWindow::chatfriendproxy() -{ - chatfriend(getCurrentPeer()); -} - -void MessengerWindow::chatfriend(QTreeWidgetItem *pPeer) -{ - if (pPeer == NULL) { - return; - } - - std::string id = pPeer->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - PopupChatDialog::chatFriend(id); -} -#endif // MINIMAL_RSGUI - -QTreeWidgetItem *MessengerWindow::getCurrentPeer() -{ - /* get the current, and extract the Id */ - - /* get a link to the table */ - QTreeWidget *peerWidget = ui.messengertreeWidget; - QTreeWidgetItem *item = peerWidget -> currentItem(); - if (!item) - { -#ifdef PEERS_DEBUG - std::cerr << "Invalid Current Item" << std::endl; -#endif - return NULL; - } - -#ifdef PEERS_DEBUG - /* Display the columns of this item. */ - std::ostringstream out; - out << "CurrentPeerItem: " << std::endl; - - for(int i = 1; i < 6; i++) - { - QString txt = item -> text(i); - out << "\t" << i << ":" << txt.toStdString() << std::endl; - } - std::cerr << out.str(); -#endif - return item; -} - -/* So from the Peers Dialog we can call the following control Functions: - * (1) Remove Current. FriendRemove(id) - * (2) Allow/DisAllow. FriendStatus(id, accept) - * (2) Connect. FriendConnectAttempt(id, accept) - * (3) Set Address. FriendSetAddress(id, str, port) - * (4) Set Trust. FriendTrustSignature(id, bool) - * (5) Configure (GUI Only) -> 3/4 - * - * All of these rely on the finding of the current Id. - */ - -#ifndef MINIMAL_RSGUI -void MessengerWindow::removefriend() -{ - QTreeWidgetItem *c = getCurrentPeer(); -#ifdef PEERS_DEBUG - std::cerr << "FriendsDialog::removefriend()" << std::endl; -#endif - if (!c) - { -#ifdef PEERS_DEBUG - std::cerr << "FriendsDialog::removefriend() Noone Selected -- sorry" << std::endl; -#endif - return; - } - - if (rsPeers) - { - rsPeers->removeFriend(getPeersRsCertId(c)); - emit friendsUpdated() ; - } -} -#endif // MINIMAL_RSGUI - -void MessengerWindow::connectfriend() -{ - QTreeWidgetItem *c = getCurrentPeer(); -#ifdef PEERS_DEBUG - std::cerr << "FriendsDialog::connectfriend()" << std::endl; -#endif - if (!c) - { -#ifdef PEERS_DEBUG - std::cerr << "FriendsDialog::connectfriend() Noone Selected -- sorry" << std::endl; -#endif - return; - } - - if (rsPeers) - { - if (c->type() == 0) { - int childCount = c->childCount(); - for (int childIndex = 0; childIndex < childCount; childIndex++) { - QTreeWidgetItem *item = c->child(childIndex); - if (item->type() == 1) { - rsPeers->connectAttempt(getPeersRsCertId(item)); - item->setIcon(COLUMN_NAME,(QIcon(IMAGE_CONNECT2))); - } - } - } else { - //this is a SSL key - rsPeers->connectAttempt(getPeersRsCertId(c)); - c->setIcon(COLUMN_NAME,(QIcon(IMAGE_CONNECT2))); - } - } -} - -#ifndef MINIMAL_RSGUI -/* GUI stuff -> don't do anything directly with Control */ -void MessengerWindow::configurefriend() -{ - ConfCertDialog::showIt(getPeersRsCertId(getCurrentPeer()), ConfCertDialog::PageDetails); -} - -void MessengerWindow::recommendfriend() -{ - QTreeWidgetItem *peer = getCurrentPeer(); - - if (!peer) - return; - - std::list ids; - ids.push_back(peer->data(COLUMN_DATA, ROLE_ID).toString().toStdString()); - MessageComposer::recommendFriend(ids); -} - -void MessengerWindow::pastePerson() -{ - RSLinkClipboard::process(RetroShareLink::TYPE_PERSON); -} -#endif // MINIMAL_RSGUI //============================================================================ - void MessengerWindow::closeEvent (QCloseEvent * /*event*/) { /* save the expanded peers */ @@ -1046,13 +255,7 @@ void MessengerWindow::closeEvent (QCloseEvent * /*event*/) expandedPeers->clear(); } - for (int nIndex = 0; nIndex < ui.messengertreeWidget->topLevelItemCount(); nIndex++) { - QTreeWidgetItem *item = ui.messengertreeWidget->topLevelItem(nIndex); - if (item->isExpanded()) { - expandedPeers->insert(expandedPeers->end(), item->data(COLUMN_DATA, ROLE_ID).toString().toStdString()); - } - } - + ui.friendList->getExpandedPeers(*expandedPeers); } LogoBar & MessengerWindow::getLogoBar() const { @@ -1066,17 +269,6 @@ void MessengerWindow::openShareManager() ShareManager::showYourself(); } -void MessengerWindow::sendMessage() -{ - QTreeWidgetItem *peer = getCurrentPeer(); - - if (!peer) - return; - - std::string id = peer->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); - MessageComposer::msgFriend(id, false); -} - /** Loads own personal status message */ void MessengerWindow::loadmystatusmessage() { @@ -1104,21 +296,6 @@ void MessengerWindow::updateOwnStatus(const QString &peer_id, int status) #endif // MINIMAL_RSGUI -void MessengerWindow::on_actionSort_Peers_Descending_Order_activated() -{ - ui.messengertreeWidget->sortItems ( COLUMN_NAME, Qt::DescendingOrder ); -} - -void MessengerWindow::on_actionSort_Peers_Ascending_Order_activated() -{ - ui.messengertreeWidget->sortItems ( COLUMN_NAME, Qt::AscendingOrder ); -} - -void MessengerWindow::on_actionRoot_is_decorated_activated() -{ - ui.messengertreeWidget->setRootIsDecorated(ui.actionRoot_is_decorated->isChecked()); -} - void MessengerWindow::displayMenu() { QMenu *lookmenu = new QMenu(); @@ -1149,48 +326,5 @@ void MessengerWindow::filterRegExpChanged() ui.clearButton->show(); } - FilterItems(); -} - -void MessengerWindow::FilterItems() -{ - QString sPattern = ui.filterPatternLineEdit->text(); - - int nCount = ui.messengertreeWidget->topLevelItemCount (); - for (int nIndex = 0; nIndex < nCount; nIndex++) { - FilterItem(ui.messengertreeWidget->topLevelItem(nIndex), sPattern); - } - - QTreeWidgetItem *c = getCurrentPeer(); - if (c && c->isHidden()) { - // active item is hidden, deselect it - ui.messengertreeWidget->setCurrentItem(NULL); - } -} - -bool MessengerWindow::FilterItem(QTreeWidgetItem *pItem, QString &sPattern) -{ - bool bVisible = true; - - if (sPattern.isEmpty() == false) { - if (pItem->text(0).contains(sPattern, Qt::CaseInsensitive) == false) { - bVisible = false; - } - } - - int nVisibleChildCount = 0; - int nCount = pItem->childCount(); - for (int nIndex = 0; nIndex < nCount; nIndex++) { - if (FilterItem(pItem->child(nIndex), sPattern)) { - nVisibleChildCount++; - } - } - - if (bVisible || nVisibleChildCount) { - pItem->setHidden(false); - } else { - pItem->setHidden(true); - } - - return (bVisible || nVisibleChildCount); + ui.friendList->filterItems(text); } diff --git a/retroshare-gui/src/gui/MessengerWindow.h b/retroshare-gui/src/gui/MessengerWindow.h index 9ab8986b1..3823d7b32 100644 --- a/retroshare-gui/src/gui/MessengerWindow.h +++ b/retroshare-gui/src/gui/MessengerWindow.h @@ -27,23 +27,17 @@ #include class LogoBar; -class FriendsDialog; -class PopupChatDialog; -class RSTreeWidgetItemCompareRole; class MessengerWindow : public RWindow { Q_OBJECT - public: - QPixmap picture; - +public: static void showYourself (); static MessengerWindow* getInstance(); static void releaseInstance(); public slots: - void updateMessengerDisplay() ; #ifndef MINIMAL_RSGUI void loadmystatusmessage(); #endif // MINIMAL_RSGUI @@ -59,30 +53,9 @@ protected: void closeEvent (QCloseEvent * event); private slots: - /** Create the context popup menu and it's submenus */ - void messengertreeWidgetCostumPopupMenu( QPoint point ); - #ifndef MINIMAL_RSGUI /** Add a new friend */ void addFriend(); - /** Export friend */ - void exportfriend(); - /** Remove friend */ - void removefriend(); -#endif // MINIMAL_RSGUI - /** start to connect to a friend **/ - void connectfriend(); -#ifndef MINIMAL_RSGUI - /** start a chat with a friend **/ - void chatfriend(QTreeWidgetItem *pPeer); - void chatfriendproxy(); - /** start Messages Composer **/ - void sendMessage(); - /** show peers details for each friend **/ - void configurefriend(); - - void recommendfriend(); - void pastePerson(); /** Open Shared Manager **/ void openShareManager(); @@ -92,15 +65,10 @@ private slots: void savestatusmessage(); #endif // MINIMAL_RSGUI - void on_actionSort_Peers_Descending_Order_activated(); - void on_actionSort_Peers_Ascending_Order_activated(); - void on_actionRoot_is_decorated_activated(); - void filterRegExpChanged(); void clearFilter(); signals: - void friendsUpdated() ; private: static MessengerWindow *_instance; @@ -109,26 +77,11 @@ private: void displayMenu(); - /* Worker Functions */ - /* (1) Update Display */ - QTimer *timer; - - /* (2) Utility Fns */ - QTreeWidgetItem *getCurrentPeer(); - void insertPeers(); - - void FilterItems(); - bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern); - - QTreeView *messengertreeWidget; LogoBar * _rsLogoBarmessenger; - QFont itemFont; QString m_nickName; - RSTreeWidgetItemCompareRole *m_compareRole; - /** Qt Designer generated object */ Ui::MessengerWindow ui; }; diff --git a/retroshare-gui/src/gui/MessengerWindow.ui b/retroshare-gui/src/gui/MessengerWindow.ui index 93c1bd1c9..196d65f02 100644 --- a/retroshare-gui/src/gui/MessengerWindow.ui +++ b/retroshare-gui/src/gui/MessengerWindow.ui @@ -355,33 +355,13 @@ stop:0 #FEFEFE, stop:1 #E8E8E8);
- - - Qt::CustomContextMenu + + + + 0 + 0 + - - QTreeWidget#messengertreeWidget{ -border: 1px solid #CCCCCC; -} - - - - 38 - 38 - - - - 22 - - - true - - - 0 - - - false - @@ -458,6 +438,12 @@ border: 1px solid #CCCCCC;
gui/common/AvatarWidget.h
1 + + FriendList + QWidget +
gui/common/FriendList.h
+ 1 +