fixed a few GUI bits for non anonymous chat lobbies

This commit is contained in:
csoler 2015-08-27 22:37:01 -04:00
parent 040b4fb949
commit 6d01461c66
4 changed files with 126 additions and 36 deletions

View File

@ -22,18 +22,21 @@
#include "retroshare/rsnotify.h" #include "retroshare/rsnotify.h"
#include "retroshare/rsidentity.h" #include "retroshare/rsidentity.h"
//#define CHAT_LOBBY_GUI_DEBUG 1
#define COLUMN_NAME 0 #define COLUMN_NAME 0
#define COLUMN_USER_COUNT 1 #define COLUMN_USER_COUNT 1
#define COLUMN_TOPIC 2 #define COLUMN_TOPIC 2
#define COLUMN_SUBSCRIBED 3 #define COLUMN_SUBSCRIBED 3
#define COLUMN_COUNT 4 #define COLUMN_COUNT 4
#define COLUMN_DATA 0 #define COLUMN_DATA 0
#define ROLE_SORT Qt::UserRole
#define ROLE_ID Qt::UserRole + 1 #define ROLE_SORT Qt::UserRole
#define ROLE_SUBSCRIBED Qt::UserRole + 2 #define ROLE_ID Qt::UserRole + 1
#define ROLE_PRIVACYLEVEL Qt::UserRole + 3 #define ROLE_SUBSCRIBED Qt::UserRole + 2
#define ROLE_PRIVACYLEVEL Qt::UserRole + 3
#define ROLE_AUTOSUBSCRIBE Qt::UserRole + 4 #define ROLE_AUTOSUBSCRIBE Qt::UserRole + 4
#define ROLE_FLAGS Qt::UserRole + 5
#define TYPE_FOLDER 0 #define TYPE_FOLDER 0
@ -129,10 +132,12 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WindowFlags flags)
ui.lobbyTreeWidget->setColumnHidden(COLUMN_SUBSCRIBED,true) ; ui.lobbyTreeWidget->setColumnHidden(COLUMN_SUBSCRIBED,true) ;
ui.lobbyTreeWidget->setSortingEnabled(true) ; ui.lobbyTreeWidget->setSortingEnabled(true) ;
float fact = QFontMetricsF(font()).height()/14.0f;
ui.lobbyTreeWidget->adjustSize(); ui.lobbyTreeWidget->adjustSize();
ui.lobbyTreeWidget->setColumnWidth(COLUMN_NAME,100); ui.lobbyTreeWidget->setColumnWidth(COLUMN_NAME,100*fact);
ui.lobbyTreeWidget->setColumnWidth(COLUMN_USER_COUNT, 50); ui.lobbyTreeWidget->setColumnWidth(COLUMN_USER_COUNT, 50*fact);
ui.lobbyTreeWidget->setColumnWidth(COLUMN_TOPIC, 50); ui.lobbyTreeWidget->setColumnWidth(COLUMN_TOPIC, 50*fact);
/** Setup the actions for the header context menu */ /** Setup the actions for the header context menu */
showUserCountAct= new QAction(headerItem->text(COLUMN_USER_COUNT),this); showUserCountAct= new QAction(headerItem->text(COLUMN_USER_COUNT),this);
@ -150,7 +155,7 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WindowFlags flags)
ui.splitter->setStretchFactor(1, 1); ui.splitter->setStretchFactor(1, 1);
QList<int> sizes; QList<int> sizes;
sizes << 200 << width(); // Qt calculates the right sizes sizes << 200*fact << width(); // Qt calculates the right sizes
ui.splitter->setSizes(sizes); ui.splitter->setSizes(sizes);
lobbyChanged(); lobbyChanged();
@ -222,6 +227,25 @@ void ChatLobbyWidget::updateNotify(ChatLobbyId id, unsigned int count)
} }
} }
static bool trimAnonIds(std::list<RsGxsId>& lst)
{
// trim down identities that are unsigned, because the lobby requires it.
bool removed = false ;
RsIdentityDetails idd ;
for(std::list<RsGxsId>::iterator it = lst.begin();it!=lst.end();)
if(!rsIdentity->getIdDetails(*it,idd) || !idd.mPgpLinked)
{
it = lst.erase(it) ;
removed= true ;
}
else
++it ;
return removed ;
}
void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint) void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint)
{ {
std::cerr << "Creating customPopupMennu" << std::endl; std::cerr << "Creating customPopupMennu" << std::endl;
@ -244,10 +268,19 @@ void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint)
else else
{ {
QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem(); QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem();
uint32_t item_flags = item->data(COLUMN_DATA,ROLE_ID).toUInt() ;
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
ChatLobbyFlags flags(item->data(COLUMN_DATA, ROLE_FLAGS).toUInt());
bool removed = false ;
if(flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED)
removed = trimAnonIds(own_identities) ;
if(own_identities.empty()) if(own_identities.empty())
{ {
if(removed)
contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Create a non anonymous identity and enter this lobby"), this, SLOT(createIdentityAndSubscribe()));
else
contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Create an identity and enter this lobby"), this, SLOT(createIdentityAndSubscribe())); contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Create an identity and enter this lobby"), this, SLOT(createIdentityAndSubscribe()));
} }
else if(own_identities.size() == 1) else if(own_identities.size() == 1)
@ -300,7 +333,7 @@ void ChatLobbyWidget::lobbyChanged()
updateDisplay(); updateDisplay();
} }
static void updateItem(QTreeWidget *treeWidget, QTreeWidgetItem *item, ChatLobbyId id, const std::string &name, const std::string &topic, int count, bool subscribed, bool autoSubscribe) static void updateItem(QTreeWidget *treeWidget, QTreeWidgetItem *item, ChatLobbyId id, const std::string &name, const std::string &topic, int count, bool subscribed, bool autoSubscribe,ChatLobbyFlags lobby_flags)
{ {
item->setText(COLUMN_NAME, QString::fromUtf8(name.c_str())); item->setText(COLUMN_NAME, QString::fromUtf8(name.c_str()));
item->setData(COLUMN_NAME, ROLE_SORT, QString::fromUtf8(name.c_str())); item->setData(COLUMN_NAME, ROLE_SORT, QString::fromUtf8(name.c_str()));
@ -323,9 +356,11 @@ static void updateItem(QTreeWidget *treeWidget, QTreeWidgetItem *item, ChatLobby
item->setData(COLUMN_DATA, ROLE_ID, (qulonglong)id); item->setData(COLUMN_DATA, ROLE_ID, (qulonglong)id);
item->setData(COLUMN_DATA, ROLE_SUBSCRIBED, subscribed); item->setData(COLUMN_DATA, ROLE_SUBSCRIBED, subscribed);
item->setData(COLUMN_DATA, ROLE_FLAGS, lobby_flags.toUInt32());
item->setData(COLUMN_DATA, ROLE_AUTOSUBSCRIBE, autoSubscribe); item->setData(COLUMN_DATA, ROLE_AUTOSUBSCRIBE, autoSubscribe);
QColor color = treeWidget->palette().color(QPalette::Active, QPalette::Text); QColor color = treeWidget->palette().color(QPalette::Active, QPalette::Text);
if (!subscribed) { if (!subscribed) {
// Average between Base and Text colors // Average between Base and Text colors
QColor color2 = treeWidget->palette().color(QPalette::Active, QPalette::Base); QColor color2 = treeWidget->palette().color(QPalette::Active, QPalette::Base);
@ -335,10 +370,15 @@ static void updateItem(QTreeWidget *treeWidget, QTreeWidgetItem *item, ChatLobby
for (int column = 0; column < COLUMN_COUNT; ++column) { for (int column = 0; column < COLUMN_COUNT; ++column) {
item->setTextColor(column, color); item->setTextColor(column, color);
} }
item->setToolTip(0,QObject::tr("Subject:")+" "+item->text(COLUMN_TOPIC)+"\n" QString tooltipstr = QObject::tr("Subject:")+" "+item->text(COLUMN_TOPIC)+"\n"
+QObject::tr("Participants:")+" "+QString::number(count)+"\n" +QObject::tr("Participants:")+" "+QString::number(count)+"\n"
+QObject::tr("Auto Subscribe:")+" "+(autoSubscribe? QObject::tr("enabled"): QObject::tr("disabled"))+"\n" +QObject::tr("Auto Subscribe:")+" "+(autoSubscribe? QObject::tr("enabled"): QObject::tr("disabled"))+"\n"
+QObject::tr("Id:")+" "+QString::number(id,16)) ; +QObject::tr("Id:")+" "+QString::number(id,16) ;
if(lobby_flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED)
tooltipstr += QObject::tr("\nSecurity: no anonymous ids") ;
item->setToolTip(0,tooltipstr) ;
} }
void ChatLobbyWidget::addChatPage(ChatLobbyDialog *d) void ChatLobbyWidget::addChatPage(ChatLobbyDialog *d)
@ -380,7 +420,6 @@ void ChatLobbyWidget::setCurrentChatPage(ChatLobbyDialog *d)
} }
} }
//#define CHAT_LOBBY_GUI_DEBUG
void ChatLobbyWidget::updateDisplay() void ChatLobbyWidget::updateDisplay()
{ {
#ifdef CHAT_LOBBY_GUI_DEBUG #ifdef CHAT_LOBBY_GUI_DEBUG
@ -521,12 +560,15 @@ void ChatLobbyWidget::updateDisplay()
} }
} }
ChatLobbyFlags lobby_flags = lobby.lobby_flags ;
QIcon icon; QIcon icon;
if (item == NULL) if (item == NULL)
{ {
item = new RSTreeWidgetItem(compareRole, TYPE_LOBBY); item = new RSTreeWidgetItem(compareRole, TYPE_LOBBY);
icon = (lobby.lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC) ? QIcon(IMAGE_PUBLIC) : QIcon(IMAGE_PRIVATE); icon = (lobby.lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC) ? QIcon(IMAGE_PUBLIC) : QIcon(IMAGE_PRIVATE);
lobby_item->addChild(item); lobby_item->addChild(item);
} }
else else
{ {
@ -554,7 +596,7 @@ void ChatLobbyWidget::updateDisplay()
} }
} }
updateItem(ui.lobbyTreeWidget, item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed, autoSubscribe); updateItem(ui.lobbyTreeWidget, item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed, autoSubscribe,lobby_flags);
} }
// time_t now = time(NULL) ; // time_t now = time(NULL) ;
@ -589,7 +631,11 @@ void ChatLobbyWidget::updateDisplay()
} }
QIcon icon; QIcon icon;
if (item == NULL) {
ChatLobbyFlags lobby_flags = lobby.lobby_flags ;
if (item == NULL)
{
item = new RSTreeWidgetItem(compareRole, TYPE_LOBBY); item = new RSTreeWidgetItem(compareRole, TYPE_LOBBY);
icon = (lobby.lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC) ? QIcon(IMAGE_PUBLIC) : QIcon(IMAGE_PRIVATE); icon = (lobby.lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC) ? QIcon(IMAGE_PUBLIC) : QIcon(IMAGE_PRIVATE);
itemParent->addChild(item); itemParent->addChild(item);
@ -605,7 +651,7 @@ void ChatLobbyWidget::updateDisplay()
bool autoSubscribe = rsMsgs->getLobbyAutoSubscribe(lobby.lobby_id); bool autoSubscribe = rsMsgs->getLobbyAutoSubscribe(lobby.lobby_id);
updateItem(ui.lobbyTreeWidget, item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.gxs_ids.size(), true, autoSubscribe); updateItem(ui.lobbyTreeWidget, item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.gxs_ids.size(), true, autoSubscribe,lobby_flags);
} }
publicSubLobbyItem->setHidden(publicSubLobbyItem->childCount()==0); publicSubLobbyItem->setHidden(publicSubLobbyItem->childCount()==0);
privateSubLobbyItem->setHidden(privateSubLobbyItem->childCount()==0); privateSubLobbyItem->setHidden(privateSubLobbyItem->childCount()==0);
@ -647,9 +693,14 @@ void ChatLobbyWidget::createIdentityAndSubscribe()
return ; return ;
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong(); ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
ChatLobbyFlags flags(item->data(COLUMN_DATA, ROLE_FLAGS).toUInt());
IdEditDialog dlg(this); IdEditDialog dlg(this);
dlg.setupNewId(false); dlg.setupNewId(false);
if(flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED) //
dlg.enforceNoAnonIds() ;
dlg.exec(); dlg.exec();
// fetch new id // fetch new id
std::list<RsGxsId> own_ids; std::list<RsGxsId> own_ids;
@ -711,6 +762,7 @@ void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item)
} }
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong(); ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
ChatLobbyFlags flags ( item->data(COLUMN_DATA, ROLE_FLAGS).toUInt());
RsGxsId gxs_id ; RsGxsId gxs_id ;
std::list<RsGxsId> own_ids; std::list<RsGxsId> own_ids;
@ -726,6 +778,9 @@ void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item)
{ {
IdEditDialog dlg(this); IdEditDialog dlg(this);
dlg.setupNewId(false); dlg.setupNewId(false);
if(flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED) //
dlg.enforceNoAnonIds() ;
dlg.exec(); dlg.exec();
// fetch new id // fetch new id
if(!rsIdentity->getOwnIds(own_ids) || own_ids.empty()) if(!rsIdentity->getOwnIds(own_ids) || own_ids.empty())
@ -733,8 +788,20 @@ void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item)
gxs_id = own_ids.front(); gxs_id = own_ids.front();
} }
else else
{
rsMsgs->getDefaultIdentityForChatLobby(gxs_id); rsMsgs->getDefaultIdentityForChatLobby(gxs_id);
RsIdentityDetails idd ;
if(!rsIdentity->getIdDetails(gxs_id,idd))
return ;
if(flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED)
{
QMessageBox::warning(NULL,tr("Default identity is anonymous"),tr("You cannot join this lobby with your default identity, since it is anonymous and the lobby forbids it.")) ;
return ;
}
}
if(rsMsgs->joinVisibleChatLobby(id,gxs_id)) if(rsMsgs->joinVisibleChatLobby(id,gxs_id))
ChatDialog::chatFriend(ChatId(id),true) ; ChatDialog::chatFriend(ChatId(id),true) ;
} }
@ -763,18 +830,25 @@ void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
std::list<RsGxsId> my_ids ; std::list<RsGxsId> my_ids ;
rsIdentity->getOwnIds(my_ids) ; rsIdentity->getOwnIds(my_ids) ;
trimAnonIds(my_ids) ;
for(std::vector<VisibleChatLobbyRecord>::const_iterator it(lobbies.begin());it!=lobbies.end();++it) for(std::vector<VisibleChatLobbyRecord>::const_iterator it(lobbies.begin());it!=lobbies.end();++it)
if( (*it).lobby_id == id) if( (*it).lobby_id == id)
{ {
ui.lobbyname_lineEdit->setText( RsHtml::plainText(it->lobby_name) ); ui.lobbyname_lineEdit->setText( RsHtml::plainText(it->lobby_name) );
ui.lobbyid_lineEdit->setText( QString::number((*it).lobby_id,16) ); ui.lobbyid_lineEdit->setText( QString::number((*it).lobby_id,16) );
ui.lobbytopic_lineEdit->setText( RsHtml::plainText(it->lobby_topic) ); ui.lobbytopic_lineEdit->setText( RsHtml::plainText(it->lobby_topic) );
ui.lobbytype_lineEdit->setText( (( (*it).lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC)?tr("Public"):tr("Private")) ); ui.lobbytype_lineEdit->setText( (( (*it).lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC)?tr("Public"):tr("Private")) );
ui.lobbysec_lineEdit->setText( (( (*it).lobby_flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED)?tr("No anonymous IDs"):tr("Anonymous ids accepted")) );
ui.lobbypeers_lineEdit->setText( QString::number((*it).total_number_of_peers) ); ui.lobbypeers_lineEdit->setText( QString::number((*it).total_number_of_peers) );
QString text = tr("You're not subscribed to this lobby; Double click-it to enter and chat.") ; QString text = tr("You're not subscribed to this lobby; Double click-it to enter and chat.") ;
if(my_ids.empty()) if(my_ids.empty())
text += "\n\n"+tr("You will need to create an identity in order to join chat lobbies.") ; if( (*it).lobby_flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED)
text += "\n\n"+tr("You will need to create a non anonymous identity in order to join this chat lobby.") ;
else
text += "\n\n"+tr("You will need to create an identity in order to join chat lobbies.") ;
ui.lobbyInfoLabel->setText(text); ui.lobbyInfoLabel->setText(text);
return ; return ;
@ -785,6 +859,7 @@ void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
ui.lobbytopic_lineEdit->clear(); ui.lobbytopic_lineEdit->clear();
ui.lobbytype_lineEdit->clear(); ui.lobbytype_lineEdit->clear();
ui.lobbypeers_lineEdit->clear(); ui.lobbypeers_lineEdit->clear();
ui.lobbysec_lineEdit->clear();
QString text = tr("No lobby selected. \nSelect lobbies at left to show details.\nDouble click lobbies to enter and chat.") ; QString text = tr("No lobby selected. \nSelect lobbies at left to show details.\nDouble click lobbies to enter and chat.") ;
ui.lobbyInfoLabel->setText(text) ; ui.lobbyInfoLabel->setText(text) ;

View File

@ -6,21 +6,12 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>643</width> <width>803</width>
<height>426</height> <height>517</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin"> <property name="margin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -99,7 +90,7 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QWidget" name=""> <widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QFrame" name="toolBarFrame"> <widget class="QFrame" name="toolBarFrame">
@ -201,9 +192,6 @@
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QGroupBox" name="lobbyinfo_groupBox"> <widget class="QGroupBox" name="lobbyinfo_groupBox">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="title"> <property name="title">
<string>Selected lobby info</string> <string>Selected lobby info</string>
</property> </property>
@ -264,6 +252,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Security:</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="font"> <property name="font">
@ -336,6 +337,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="lobbysec_lineEdit">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="lobbypeers_lineEdit"> <widget class="QLabel" name="lobbypeers_lineEdit">
<property name="sizePolicy"> <property name="sizePolicy">

View File

@ -207,7 +207,13 @@ void IdEditDialog::setupExistingId(const RsGxsGroupId &keyId)
groupIds.push_back(keyId); groupIds.push_back(keyId);
uint32_t token; uint32_t token;
mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDEDITDIALOG_LOADID); mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDEDITDIALOG_LOADID);
}
void IdEditDialog::enforceNoAnonIds()
{
ui->radioButton_GpgId->setChecked(true);
ui->radioButton_GpgId->setEnabled(false);
} }
void IdEditDialog::loadExistingId(uint32_t token) void IdEditDialog::loadExistingId(uint32_t token)

View File

@ -47,6 +47,7 @@ public:
void setupNewId(bool pseudo); void setupNewId(bool pseudo);
void setupExistingId(const RsGxsGroupId &keyId); void setupExistingId(const RsGxsGroupId &keyId);
void enforceNoAnonIds() ;
RsGxsGroupId groupId() { return mGroupId; } RsGxsGroupId groupId() { return mGroupId; }