diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index eea82fc97..037faa372 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -271,14 +271,17 @@ QModelIndex RsFriendListModel::index(int row, int column, const QModelIndex& par EntryIndex parent_index ; convertInternalIdToIndex(parent.internalId(),parent_index); - +#ifdef DEBUG_MODEL RsDbg() << "Index row=" << row << " col=" << column << " parent=" << parent << std::endl; +#endif quintptr ref; EntryIndex new_index = parent_index.child(row,mTopLevel); convertIndexToInternalId(new_index,ref); +#ifdef DEBUG_MODEL RsDbg() << " returning " << createIndex(row,column,ref) << std::endl; +#endif return createIndex(row,column,ref); } @@ -445,10 +448,12 @@ uint32_t RsFriendListModel::updateFilterStatus(ForumModelIndex i,int column,cons void RsFriendListModel::setFilter(FilterType filter_type, const QStringList& strings) { +#ifdef DEBUG_MODEL std::cerr << "Setting filter to filter_type=" << int(filter_type) << " and strings to " ; foreach(const QString& str,strings) std::cerr << "\"" << str.toStdString() << "\" " ; std::cerr << std::endl; +#endif preMods(); @@ -580,7 +585,9 @@ QVariant RsFriendListModel::onlineRole(const EntryIndex& e, int col) const QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const { +#ifdef DEBUG_MODEL std::cerr << " font role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": " << std::endl; +#endif bool b = onlineRole(e,col).toBool(); @@ -597,7 +604,9 @@ QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const { +#ifdef DEBUG_MODEL std::cerr << " Display role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": " << std::endl; +#endif switch(e.type) { @@ -621,7 +630,9 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const switch(col) { case COLUMN_THREAD_NAME: +#ifdef DEBUG_MODEL std::cerr << group->group_info.name.c_str() << std::endl; +#endif if(!group->child_profile_indices.empty()) return QVariant(QString::fromUtf8(group->group_info.name.c_str())+" (" + QString::number(nb_online) + "/" + QString::number(group->child_profile_indices.size()) + ")"); @@ -733,7 +744,9 @@ const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getNode if(node.last_update_ts + NODE_DETAILS_UPDATE_DELAY < now) { +#ifdef DEBUG_MODEL std::cerr << "Updating ID " << node.node_info.id << std::endl; +#endif RsPeerId id(node.node_info.id); // this avoids zeroing the id field when writing the node data rsPeers->getPeerDetails(id,node.node_info); node.last_update_ts = now; diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 1a6be634a..96de6adea 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -113,16 +113,22 @@ public: FriendListSortFilterProxyModel(const QHeaderView *header,QObject *parent = NULL): QSortFilterProxyModel(parent), m_header(header), m_sortingEnabled(false), - m_hideOfflineNodes(false) {} + m_showOfflineNodes(true) {} bool lessThan(const QModelIndex& left, const QModelIndex& right) const override { + bool online1 = left .data(RsFriendListModel::OnlineRole).toBool(); + bool online2 = right.data(RsFriendListModel::OnlineRole).toBool(); + + if(online1 != online2 && m_sortByState) + return (m_header->sortIndicatorOrder()==Qt::AscendingOrder)?online1:online2 ; // always put online nodes first + return left.data(RsFriendListModel::SortRole) < right.data(RsFriendListModel::SortRole) ; } bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override { - if(m_hideOfflineNodes && !sourceModel()->index(source_row,0,source_parent).data(RsFriendListModel::OnlineRole).toBool()) + if(!m_showOfflineNodes && !sourceModel()->index(source_row,0,source_parent).data(RsFriendListModel::OnlineRole).toBool()) return false; return sourceModel()->index(source_row,0,source_parent).data(RsFriendListModel::FilterRole).toString() == RsFriendListModel::FilterString ; @@ -136,15 +142,15 @@ public: void setSortingEnabled(bool b) { m_sortingEnabled = b ; } void setSortByState(bool b) { m_sortByState = b ; } - void setHideOfflineNodes(bool b) { m_hideOfflineNodes = b ; } + void setShowOfflineNodes(bool b) { m_showOfflineNodes = b ; } - bool hideOfflineNodes() const { return m_hideOfflineNodes ; } + bool showOfflineNodes() const { return m_showOfflineNodes ; } private: const QHeaderView *m_header ; bool m_sortingEnabled; bool m_sortByState; - bool m_hideOfflineNodes; + bool m_showOfflineNodes; }; NewFriendList::NewFriendList(QWidget *parent) : @@ -156,19 +162,6 @@ NewFriendList::NewFriendList(QWidget *parent) : { ui->setupUi(this); - connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu())); - //connect(ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(expandItem(QTreeWidgetItem *)) ); - - connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged())); - - connect(ui->actionHideOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setHideUnconnected(bool))); - connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool))); - connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool))); - connect(ui->actionExportFriendlist, SIGNAL(triggered()), this, SLOT(exportFriendlistClicked())); - connect(ui->actionImportFriendlist, SIGNAL(triggered()), this, SLOT(importFriendlistClicked())); - - connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); - ui->filterLineEdit->setPlaceholderText(tr("Search")) ; ui->filterLineEdit->showFilterIcon(); @@ -184,8 +177,6 @@ NewFriendList::NewFriendList(QWidget *parent) : ui->peerTreeWidget->setModel(mProxyModel); - connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), mModel, SLOT(updateInternalData())); - /* Add filter actions */ QString headerText = mModel->headerData(RsFriendListModel::COLUMN_THREAD_NAME,Qt::Horizontal,Qt::DisplayRole).toString(); ui->filterLineEdit->addFilter(QIcon(), headerText, RsFriendListModel::COLUMN_THREAD_NAME, QString("%1 %2").arg(tr("Search"), headerText)); @@ -193,7 +184,6 @@ NewFriendList::NewFriendList(QWidget *parent) : mActionSortByState = new QAction(tr("Display online friends on top"), this); mActionSortByState->setCheckable(true); - connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(toggleSortByState(bool))); //setting default filter by column as subject ui->filterLineEdit->setCurrentFilter(RsFriendListModel::COLUMN_THREAD_NAME); @@ -202,12 +192,9 @@ NewFriendList::NewFriendList(QWidget *parent) : /* Set sort */ sortByColumn(RsFriendListModel::COLUMN_THREAD_NAME, Qt::AscendingOrder); toggleSortByState(false); - connect(ui->peerTreeWidget->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder))); - - // workaround for Qt bug, should be solved in next Qt release 4.7.0 + // 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())); /* Initialize tree */ // ui->peerTreeWidget->enableColumnCustomize(true); @@ -232,11 +219,27 @@ NewFriendList::NewFriendList(QWidget *parent) : QHeaderView *h = ui->peerTreeWidget->header(); h->setContextMenuPolicy(Qt::CustomContextMenu); - connect(h, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint))); - QTimer *timer = new QTimer; - QObject::connect(timer,SIGNAL(timeout()),mModel,SLOT(debug_dump())); - timer->start(2000); +// QTimer *timer = new QTimer; +// QObject::connect(timer,SIGNAL(timeout()),mModel,SLOT(debug_dump())); +// timer->start(2000); + + connect(Shortcut, SIGNAL(activated()), this, SLOT(removefriend())); + connect(ui->peerTreeWidget->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder))); + connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(toggleSortByState(bool))); + connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), mModel, SLOT(updateInternalData())); + connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu())); + connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged())); + + connect(ui->actionShowOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setShowUnconnected(bool))); + connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool))); + connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool))); + + connect(ui->actionExportFriendlist, SIGNAL(triggered()), this, SLOT(exportFriendlistClicked())); + connect(ui->actionImportFriendlist, SIGNAL(triggered()), this, SLOT(importFriendlistClicked())); + + connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); + connect(h, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint))); } NewFriendList::~NewFriendList() @@ -255,14 +258,39 @@ void NewFriendList::headerContextMenuRequested(QPoint p) { QMenu displayMenu(tr("Show Items"), this); - displayMenu.addAction(ui->actionHideOfflineFriends); + QWidget *widget = new QWidget(&displayMenu); + 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(widget); + hbox->setMargin(0); + hbox->setSpacing(6); + + QLabel *iconLabel = new QLabel(widget); + QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5); + iconLabel->setPixmap(pix); + iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); + hbox->addWidget(iconLabel); + + QLabel *textLabel = new QLabel("Show/hide...", widget); + 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); + displayMenu.addAction(widgetAction); + + displayMenu.addAction(mActionSortByState); + + displayMenu.addAction(ui->actionShowOfflineFriends); displayMenu.addAction(ui->actionShowState); displayMenu.addAction(ui->actionShowGroups); - displayMenu.addAction(ui->actionExportFriendlist); - displayMenu.addAction(ui->actionImportFriendlist); - - ui->actionHideOfflineFriends->setChecked(mProxyModel->hideOfflineNodes()); + ui->actionShowOfflineFriends->setChecked(mProxyModel->showOfflineNodes()); ui->actionShowState->setChecked(mShowState); ui->actionShowGroups->setChecked(mModel->getDisplayGroups()); @@ -320,10 +348,14 @@ void NewFriendList::processSettings(bool load) // restoreState would corrupt the internal sectionCount // states - setHideUnconnected(Settings->value("hideUnconnected", mProxyModel->hideOfflineNodes()).toBool()); + setShowUnconnected(!Settings->value("hideUnconnected", mProxyModel->showOfflineNodes()).toBool()); setShowState(Settings->value("showState", mShowState).toBool()); setShowGroups(Settings->value("showGroups", mModel->getDisplayGroups()).toBool()); + setColumnVisible(RsFriendListModel::COLUMN_THREAD_IP,Settings->value("showIP", isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)).toBool()); + setColumnVisible(RsFriendListModel::COLUMN_THREAD_ID,Settings->value("showID", isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)).toBool()); + setColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT,Settings->value("showLastContact", isColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT)).toBool()); + // sort toggleSortByState(Settings->value("sortByState", isSortByState()).toBool()); @@ -348,10 +380,14 @@ void NewFriendList::processSettings(bool load) // save settings // states - Settings->setValue("hideUnconnected", mProxyModel->hideOfflineNodes()); + Settings->setValue("hideUnconnected", !mProxyModel->showOfflineNodes()); Settings->setValue("showState", mShowState); Settings->setValue("showGroups", mModel->getDisplayGroups()); + 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)); + // sort Settings->setValue("sortByState", isSortByState()); @@ -371,6 +407,7 @@ void NewFriendList::processSettings(bool load) void NewFriendList::toggleSortByState(bool sort) { mProxyModel->setSortByState(sort); + mProxyModel->setFilterRegExp(QRegExp(QString(RsFriendListModel::FilterString))) ;// triggers a re-display. } void NewFriendList::changeEvent(QEvent *e) @@ -410,7 +447,7 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu() iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); hbox->addWidget(iconLabel); - QLabel *textLabel = new QLabel("RetroShare", widget); + QLabel *textLabel = new QLabel("Friend list", widget); hbox->addWidget(textLabel); QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); @@ -421,7 +458,6 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu() QWidgetAction *widgetAction = new QWidgetAction(this); widgetAction->setDefaultWidget(widget); contextMenu.addAction(widgetAction); - contextMenu.addAction(mActionSortByState); // create menu entries if(index.isValid()) @@ -579,6 +615,11 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu() contextMenu.addAction(QIcon(IMAGE_EXPAND), tr("Expand all"), ui->peerTreeWidget, SLOT(expandAll())); contextMenu.addAction(QIcon(IMAGE_COLLAPSE), tr("Collapse all"), ui->peerTreeWidget, SLOT(collapseAll())); + contextMenu.addSeparator(); + + contextMenu.addAction(ui->actionExportFriendlist); + contextMenu.addAction(ui->actionImportFriendlist); + // contextMenu = ui->peerTreeWidget->createStandardContextMenu(contextMenu); contextMenu.exec(QCursor::pos()); @@ -1392,12 +1433,16 @@ bool NewFriendList::getOrCreateGroup(const std::string& name, uint flag, RsNodeG } -void NewFriendList::setHideUnconnected(bool hidden) +void NewFriendList::setShowUnconnected(bool show) { - mProxyModel->setHideOfflineNodes(hidden); + mProxyModel->setShowOfflineNodes(show); mProxyModel->setFilterRegExp(QRegExp(QString(RsFriendListModel::FilterString))) ;// triggers a re-display. } +bool NewFriendList::isColumnVisible(int col) const +{ + return !ui->peerTreeWidget->isColumnHidden(col); +} void NewFriendList::setColumnVisible(int col,bool visible) { ui->peerTreeWidget->setColumnHidden(col, !visible); @@ -1415,6 +1460,8 @@ void NewFriendList::toggleColumnVisible() //emit columnVisibleChanged(column,visible); ui->peerTreeWidget->setColumnHidden(column, !visible); + + processSettings(false); // save settings } void NewFriendList::sortByColumn(int column, Qt::SortOrder sortOrder) diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 0dd8c210b..b488fc860 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -60,6 +60,7 @@ public: void addPeerToExpand(const RsPgpId &gpgId); bool getExpandedPeers(std::set &peers) const; void setColumnVisible(int col,bool visible); + bool isColumnVisible(int col) const; std::string getSelectedGroupId() const; void sortByColumn(int column, Qt::SortOrder sortOrder); @@ -85,7 +86,7 @@ public slots: void toggleColumnVisible(); void setShowGroups(bool show); - void setHideUnconnected(bool hidden); + void setShowUnconnected(bool hidden); void setShowState(bool show); void headerContextMenuRequested(QPoint); diff --git a/retroshare-gui/src/gui/common/NewFriendList.ui b/retroshare-gui/src/gui/common/NewFriendList.ui index 360cc4707..177a8f494 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.ui +++ b/retroshare-gui/src/gui/common/NewFriendList.ui @@ -67,12 +67,15 @@ - + true - Hide Offline Friends + Offline Friends + + + Show Offline Friends @@ -80,10 +83,10 @@ true - Show State + Status - Show State + Show status @@ -91,10 +94,10 @@ true - Show Groups + Groups - Show Groups + Show groups