Merge pull request #1615 from csoler/v0.6-FriendList

V0.6 friend list
This commit is contained in:
csoler 2019-08-26 19:07:11 +02:00 committed by GitHub
commit c28c193b7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 3272 additions and 86 deletions

View file

@ -18,12 +18,15 @@
* *
*******************************************************************************/
#include <QBuffer>
#include <rshare.h>
#include <retroshare/rsstatus.h>
#include <retroshare/rspeers.h>
#include <retroshare/rsmsgs.h>
#include "gui/notifyqt.h"
#include "util/misc.h"
#include "gui/common/AvatarDefs.h"
#include "gui/common/AvatarDialog.h"
@ -85,19 +88,33 @@ void AvatarWidget::mouseReleaseEvent(QMouseEvent */*event*/)
if (!mFlag.isOwnId) {
return;
}
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Choose avatar"), AvatarDialog::RS_AVATAR_DEFAULT_IMAGE_W,AvatarDialog::RS_AVATAR_DEFAULT_IMAGE_H);
AvatarDialog dialog(this);
if (img.isNull())
return;
QPixmap avatar;
AvatarDefs::getOwnAvatar(avatar, "");
setPixmap(img);
dialog.setAvatar(avatar);
if (dialog.exec() == QDialog::Accepted) {
QByteArray newAvatar;
dialog.getAvatar(newAvatar);
QByteArray data;
QBuffer buffer(&data);
rsMsgs->setOwnAvatarData((unsigned char *)(newAvatar.data()), newAvatar.size()) ; // last char 0 included.
}
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG"); // writes image into a in PNG format
rsMsgs->setOwnAvatarData((unsigned char *)(data.data()), data.size()) ; // last char 0 included.
// AvatarDialog dialog(this);
//
// QPixmap avatar;
// AvatarDefs::getOwnAvatar(avatar, "");
//
// dialog.setAvatar(avatar);
// if (dialog.exec() == QDialog::Accepted) {
// QByteArray newAvatar;
// dialog.getAvatar(newAvatar);
//
// rsMsgs->setOwnAvatarData((unsigned char *)(newAvatar.data()), newAvatar.size()) ; // last char 0 included.
// }
}
void AvatarWidget::setFrameType(FrameType type)

View file

@ -126,8 +126,7 @@ FriendList::FriendList(QWidget *parent) :
#ifdef RS_DIRECT_CHAT
connect(ui->peerTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *)));
#else
connect( ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
this, SLOT(expandItem(QTreeWidgetItem *)) );
connect( ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(expandItem(QTreeWidgetItem *)) );
#endif
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged()));
@ -1014,6 +1013,7 @@ void FriendList::insertPeers()
if (rsState == 0) {
sslFont.setBold(true);
sslColor = mTextColorStatus[RS_STATUS_ONLINE];
} else {
sslFont = StatusDefs::font(rsState);
sslColor = mTextColorStatus[rsState];
@ -1965,7 +1965,7 @@ bool FriendList::exportFriendlist(QString &fileName)
/**
* @brief helper function to show a message box
*/
void showXMLParsingError()
static void showXMLParsingError()
{
// show error to user
QMessageBox mbox;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,227 @@
/*******************************************************************************
* retroshare-gui/src/gui/msgs/RsFriendListModel.h *
* *
* Copyright 2019 by Cyril Soler <csoler@users.sourceforge.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#pragma once
#include <QModelIndex>
#include <QColor>
#include "retroshare/rsstatus.h"
#include "retroshare/rsmsgs.h"
#include "retroshare/rspeers.h"
typedef uint32_t ForumModelIndex;
// This class is the item model used by Qt to display the information
class RsFriendListModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit RsFriendListModel(QObject *parent = NULL);
~RsFriendListModel(){}
class RsNodeDetails: public RsPeerDetails {};// in the near future, there will be a specific class for Profile/Node details in replacement of RsPeerDetails
class RsProfileDetails: public RsPeerDetails {};
struct HierarchicalGroupInformation
{
RsGroupInfo group_info;
std::vector<uint32_t> child_profile_indices; // index in the array of hierarchical profiles
};
struct HierarchicalProfileInformation
{
RsProfileDetails profile_info;
std::vector<uint32_t> child_node_indices; // indices of nodes in the array of nodes.
};
struct HierarchicalNodeInformation
{
HierarchicalNodeInformation() : last_update_ts(0) {}
rstime_t last_update_ts;
RsNodeDetails node_info;
};
enum Columns {
COLUMN_THREAD_NAME = 0x00,
COLUMN_THREAD_LAST_CONTACT = 0x01,
COLUMN_THREAD_IP = 0x02,
COLUMN_THREAD_ID = 0x03,
COLUMN_THREAD_NB_COLUMNS = 0x04
};
enum Roles{ SortRole = Qt::UserRole+1,
StatusRole = Qt::UserRole+2,
UnreadRole = Qt::UserRole+3,
FilterRole = Qt::UserRole+4,
OnlineRole = Qt::UserRole+5,
TypeRole = Qt::UserRole+6
};
enum FilterType{ FILTER_TYPE_NONE = 0x00,
FILTER_TYPE_ID = 0x01,
FILTER_TYPE_NAME = 0x02
};
enum EntryType{ ENTRY_TYPE_UNKNOWN = 0x00,
ENTRY_TYPE_GROUP = 0x01,
ENTRY_TYPE_PROFILE = 0x02,
ENTRY_TYPE_NODE = 0x03
};
// This structure encodes the position of a node in the hierarchy. The type tells which of the index fields are valid.
struct EntryIndex
{
public:
EntryIndex();
EntryType type; // type of the entry (group,profile,location)
// Indices w.r.t. parent. The set of indices entirely determines the position of the entry in the hierarchy.
// An index of 0xff means "undefined"
uint16_t group_index; // index of the group in mGroups tab
uint16_t profile_index; // index of the child profile in its own group if group_index < 0xff, or in the mProfiles tab otherwise.
uint16_t node_index; // index of the child node in its own profile
EntryIndex parent() const;
EntryIndex child(int row,const std::vector<EntryIndex>& top_level) const;
uint32_t parentRow(uint32_t nb_groups) const;
};
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
QModelIndex getIndexOfGroup(const RsNodeGroupId& mid) const;
static const QString FilterString ;
// This method will asynchroneously update the data
void setDisplayGroups(bool b);
bool getDisplayGroups() const { return mDisplayGroups; }
void setDisplayStatusString(bool b);
bool getDisplayStatusString() const { return mDisplayStatusString; }
EntryType getType(const QModelIndex&) const;
bool getGroupData (const QModelIndex&,RsGroupInfo &) const;
bool getProfileData(const QModelIndex&,RsProfileDetails&) const;
bool getNodeData (const QModelIndex&,RsNodeDetails &) const;
void setFilter(FilterType filter_type, const QStringList& strings) ;
// Overloaded methods from QAbstractItemModel
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& child) const override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
void clear() ;
/* Color definitions (for standard see qss.default) */
QColor mTextColorGroup;
QColor mTextColorStatus[RS_STATUS_COUNT];
private:
const HierarchicalGroupInformation *getGroupInfo (const EntryIndex&) const;
const HierarchicalProfileInformation *getProfileInfo(const EntryIndex&)const;
const HierarchicalNodeInformation *getNodeInfo(const EntryIndex&) const;
void checkNode(HierarchicalNodeInformation& node);
bool getPeerOnlineStatus(const EntryIndex& e) const;
std::map<RsPgpId,uint32_t>::const_iterator checkProfileIndex(const RsPgpId& pgp_id,
std::map<RsPgpId,uint32_t>& pgp_indices,
std::vector<HierarchicalProfileInformation>& mProfiles,
bool create);
QVariant sizeHintRole (const EntryIndex& e, int col) const;
QVariant displayRole (const EntryIndex& e, int col) const;
QVariant decorationRole(const EntryIndex& e, int col) const;
QVariant toolTipRole (const EntryIndex& e, int col) const;
QVariant statusRole (const EntryIndex& e, int col) const;
QVariant sortRole (const EntryIndex& e, int col) const;
QVariant fontRole (const EntryIndex& e, int col) const;
QVariant textColorRole (const EntryIndex& e, int col) const;
QVariant onlineRole (const EntryIndex& e, int col) const;
QVariant filterRole (const EntryIndex& e, int col) const;
/*!
* \brief debug_dump
* Dumps the hierarchy of posts in the terminal, to allow checking whether the internal representation is correct.
*/
public slots:
void checkInternalData(bool force);
void debug_dump() const;
signals:
void dataLoaded(); // emitted after the messages have been set. Can be used to updated the UI.
void friendListChanged(); // emitted after the messages have been set. Can be used to updated the UI.
void dataAboutToLoad();
private:
void updateInternalData();
bool passesFilter(const EntryIndex &e, int column) const;
void preMods() ;
void postMods() ;
void *getParentRef(void *ref,int& row) const;
void *getChildRef(void *ref,int row) const;
int getChildrenCount(void *ref) const;
template<uint8_t> static bool convertIndexToInternalId(const EntryIndex& e,quintptr& ref);
template<uint8_t> static bool convertInternalIdToIndex(quintptr ref, EntryIndex& e);
uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings);
QStringList mFilterStrings;
FilterType mFilterType;
bool mDisplayGroups ;
bool mDisplayStatusString ;
rstime_t mLastInternalDataUpdate;
rstime_t mLastNodeUpdate;;
// The 3 vectors below store thehierarchical information for groups, profiles and locations,
// meaning which is the child/parent of which. The actual group/profile/node data are also stored in the
// structure.
mutable std::vector<HierarchicalGroupInformation> mGroups;
mutable std::vector<HierarchicalProfileInformation> mProfiles;
mutable std::vector<HierarchicalNodeInformation> mLocations;
// The top level list contains all nodes to display, which type depends on the option to display groups or not.
// Idices in the list may be profile indices or group indices. In the former case the profile child index refers to
// the inde in the mProfiles tab, whereas in the the later case, the child index refers to the index of the profile in the
// group it belows to.
std::vector<EntryIndex> mTopLevel;
};

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,156 @@
/*******************************************************************************
* gui/common/NewFriendList.h *
* *
* Copyright (C) 2011, Retroshare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#pragma once
#include <set>
#include <QWidget>
#include <QTreeView>
#include "FriendListModel.h"
#include "RsAutoUpdatePage.h"
#include "retroshare/rsstatus.h"
namespace Ui {
class NewFriendList;
}
class RSTreeWidgetItemCompareRole;
class QTreeWidgetItem;
class QToolButton;
class FriendListSortFilterProxyModel;
class NewFriendList: public RsAutoUpdatePage
{
Q_OBJECT
Q_PROPERTY(QColor textColorGroup READ textColorGroup WRITE setTextColorGroup)
Q_PROPERTY(QColor textColorStatusOffline READ textColorStatusOffline WRITE setTextColorStatusOffline)
Q_PROPERTY(QColor textColorStatusAway READ textColorStatusAway WRITE setTextColorStatusAway)
Q_PROPERTY(QColor textColorStatusBusy READ textColorStatusBusy WRITE setTextColorStatusBusy)
Q_PROPERTY(QColor textColorStatusOnline READ textColorStatusOnline WRITE setTextColorStatusOnline)
Q_PROPERTY(QColor textColorStatusInactive READ textColorStatusInactive WRITE setTextColorStatusInactive)
public:
explicit NewFriendList(QWidget *parent = 0);
~NewFriendList();
// Add a tool button to the tool area
void addToolButton(QToolButton *toolButton);
void processSettings(bool load);
void setColumnVisible(int col,bool visible);
bool isColumnVisible(int col) const;
std::string getSelectedGroupId() const;
void updateDisplay() override;
QColor textColorGroup() const { return mModel->mTextColorGroup; }
QColor textColorStatusOffline() const { return mModel->mTextColorStatus[RS_STATUS_OFFLINE ]; }
QColor textColorStatusAway() const { return mModel->mTextColorStatus[RS_STATUS_AWAY ]; }
QColor textColorStatusBusy() const { return mModel->mTextColorStatus[RS_STATUS_BUSY ]; }
QColor textColorStatusOnline() const { return mModel->mTextColorStatus[RS_STATUS_ONLINE ]; }
QColor textColorStatusInactive() const { return mModel->mTextColorStatus[RS_STATUS_INACTIVE]; }
void setTextColorGroup(QColor color) { mModel->mTextColorGroup = color; }
void setTextColorStatusOffline(QColor color) { mModel->mTextColorStatus[RS_STATUS_OFFLINE ] = color; }
void setTextColorStatusAway(QColor color) { mModel->mTextColorStatus[RS_STATUS_AWAY ] = color; }
void setTextColorStatusBusy(QColor color) { mModel->mTextColorStatus[RS_STATUS_BUSY ] = color; }
void setTextColorStatusOnline(QColor color) { mModel->mTextColorStatus[RS_STATUS_ONLINE ] = color; }
void setTextColorStatusInactive(QColor color) { mModel->mTextColorStatus[RS_STATUS_INACTIVE] = color; }
public slots:
void filterItems(const QString &text);
void toggleSortByState(bool sort);
void forceUpdateDisplay();
void toggleColumnVisible();
void setShowGroups(bool show);
void setShowUnconnected(bool hidden);
void setShowState(bool show);
void headerContextMenuRequested(QPoint);
private slots:
void sortColumn(int col,Qt::SortOrder so);
protected:
void changeEvent(QEvent *e);
private:
Ui::NewFriendList *ui;
RsFriendListModel *mModel;
QAction *mActionSortByState;
void expandGroup(const RsNodeGroupId& gid);
void recursRestoreExpandedItems(const QModelIndex& index, const QString& parent_path, const std::set<QString>& exp, const std::set<QString> &sel);
void recursSaveExpandedItems(const QModelIndex& index,const QString& parent_path,std::set<QString>& exp, std::set<QString>& sel);
void saveExpandedPathsAndSelection(std::set<QString>& expanded_indexes, std::set<QString>& selected_indexes);
void restoreExpandedPathsAndSelection(const std::set<QString>& expanded_indexes, const std::set<QString>& selected_indexes);
void checkInternalData(bool force);
QModelIndex getCurrentSourceIndex() const;
bool getCurrentNode(RsFriendListModel::RsNodeDetails& prof) const;
bool getCurrentGroup(RsGroupInfo& prof) const;
bool getCurrentProfile(RsFriendListModel::RsProfileDetails& prof) const;
// Settings for peer list display
bool mShowState;
std::set<RsNodeGroupId> openGroups;
std::set<RsPgpId> openPeers;
bool getOrCreateGroup(const std::string& name, uint flag, RsNodeGroupId& id);
bool getGroupIdByName(const std::string& name, RsNodeGroupId& id);
bool importExportFriendlistFileDialog(QString &fileName, bool import);
bool exportFriendlist(QString &fileName);
bool importFriendlist(QString &fileName, bool &errorPeers, bool &errorGroups);
FriendListSortFilterProxyModel *mProxyModel ;
private slots:
void peerTreeWidgetCustomPopupMenu();
void pastePerson();
void connectNode();
void configureNode();
void configureProfile();
void chatNode();
void copyFullCertificate();
void addFriend();
void msgNode();
void msgGroup();
void msgProfile();
void recommendNode();
void removeNode();
void removeProfile();
void createNewGroup() ;
void addToGroup();
void moveToGroup();
void removeFromGroup();
void editGroup();
void removeGroup();
void exportFriendlistClicked();
void importFriendlistClicked();
};

View file

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewFriendList</class>
<widget class="QWidget" name="NewFriendList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>475</width>
<height>292</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="titleBarFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="LineEditClear" name="filterLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTreeView" name="peerTreeWidget">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
<action name="actionShowOfflineFriends">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Offline Friends</string>
</property>
<property name="toolTip">
<string>Show Offline Friends</string>
</property>
</action>
<action name="actionShowState">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Status</string>
</property>
<property name="toolTip">
<string>Show status</string>
</property>
</action>
<action name="actionShowGroups">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Groups</string>
</property>
<property name="toolTip">
<string>Show groups</string>
</property>
</action>
<action name="actionExportFriendlist">
<property name="text">
<string>export friendlist</string>
</property>
<property name="toolTip">
<string>export your friendlist including groups</string>
</property>
</action>
<action name="actionImportFriendlist">
<property name="text">
<string>import friendlist</string>
</property>
<property name="toolTip">
<string>import your friendlist including groups</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View file

@ -243,7 +243,7 @@ QString StatusDefs::connectStateWithoutTransportTypeString(RsPeerDetails &detail
return stateString;
}
QString StatusDefs::connectStateIpString(RsPeerDetails &details)
QString StatusDefs::connectStateIpString(const RsPeerDetails &details)
{
QString stateString = QString("");

View file

@ -40,7 +40,7 @@ public:
static QString peerStateString(int peerState);
static QString connectStateString(RsPeerDetails &details);
static QString connectStateWithoutTransportTypeString(RsPeerDetails &details);
static QString connectStateIpString(RsPeerDetails &details);
static QString connectStateIpString(const RsPeerDetails &details);
};
#endif