Merge pull request #57 from csoler/v0.6-SignedLobbies

V0.6 signed lobbies
This commit is contained in:
Cyril Soler 2015-08-28 00:14:24 -04:00
commit a45de1ddb3
9 changed files with 251 additions and 84 deletions

View file

@ -22,18 +22,21 @@
#include "retroshare/rsnotify.h"
#include "retroshare/rsidentity.h"
//#define CHAT_LOBBY_GUI_DEBUG 1
#define COLUMN_NAME 0
#define COLUMN_USER_COUNT 1
#define COLUMN_TOPIC 2
#define COLUMN_SUBSCRIBED 3
#define COLUMN_COUNT 4
#define COLUMN_DATA 0
#define ROLE_SORT Qt::UserRole
#define ROLE_ID Qt::UserRole + 1
#define ROLE_SUBSCRIBED Qt::UserRole + 2
#define ROLE_PRIVACYLEVEL Qt::UserRole + 3
#define ROLE_SORT Qt::UserRole
#define ROLE_ID Qt::UserRole + 1
#define ROLE_SUBSCRIBED Qt::UserRole + 2
#define ROLE_PRIVACYLEVEL Qt::UserRole + 3
#define ROLE_AUTOSUBSCRIBE Qt::UserRole + 4
#define ROLE_FLAGS Qt::UserRole + 5
#define TYPE_FOLDER 0
@ -129,10 +132,12 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WindowFlags flags)
ui.lobbyTreeWidget->setColumnHidden(COLUMN_SUBSCRIBED,true) ;
ui.lobbyTreeWidget->setSortingEnabled(true) ;
float fact = QFontMetricsF(font()).height()/14.0f;
ui.lobbyTreeWidget->adjustSize();
ui.lobbyTreeWidget->setColumnWidth(COLUMN_NAME,100);
ui.lobbyTreeWidget->setColumnWidth(COLUMN_USER_COUNT, 50);
ui.lobbyTreeWidget->setColumnWidth(COLUMN_TOPIC, 50);
ui.lobbyTreeWidget->setColumnWidth(COLUMN_NAME,100*fact);
ui.lobbyTreeWidget->setColumnWidth(COLUMN_USER_COUNT, 50*fact);
ui.lobbyTreeWidget->setColumnWidth(COLUMN_TOPIC, 50*fact);
/** Setup the actions for the header context menu */
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);
QList<int> sizes;
sizes << 200 << width(); // Qt calculates the right sizes
sizes << 200*fact << width(); // Qt calculates the right sizes
ui.splitter->setSizes(sizes);
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)
{
std::cerr << "Creating customPopupMennu" << std::endl;
@ -244,10 +268,19 @@ void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint)
else
{
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(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()));
}
else if(own_identities.size() == 1)
@ -300,7 +333,7 @@ void ChatLobbyWidget::lobbyChanged()
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->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_SUBSCRIBED, subscribed);
item->setData(COLUMN_DATA, ROLE_FLAGS, lobby_flags.toUInt32());
item->setData(COLUMN_DATA, ROLE_AUTOSUBSCRIBE, autoSubscribe);
QColor color = treeWidget->palette().color(QPalette::Active, QPalette::Text);
if (!subscribed) {
// Average between Base and Text colors
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) {
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("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)
@ -380,7 +420,6 @@ void ChatLobbyWidget::setCurrentChatPage(ChatLobbyDialog *d)
}
}
//#define CHAT_LOBBY_GUI_DEBUG
void ChatLobbyWidget::updateDisplay()
{
#ifdef CHAT_LOBBY_GUI_DEBUG
@ -521,12 +560,15 @@ void ChatLobbyWidget::updateDisplay()
}
}
ChatLobbyFlags lobby_flags = lobby.lobby_flags ;
QIcon icon;
if (item == NULL)
{
item = new RSTreeWidgetItem(compareRole, TYPE_LOBBY);
icon = (lobby.lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC) ? QIcon(IMAGE_PUBLIC) : QIcon(IMAGE_PRIVATE);
lobby_item->addChild(item);
}
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) ;
@ -589,7 +631,11 @@ void ChatLobbyWidget::updateDisplay()
}
QIcon icon;
if (item == NULL) {
ChatLobbyFlags lobby_flags = lobby.lobby_flags ;
if (item == NULL)
{
item = new RSTreeWidgetItem(compareRole, TYPE_LOBBY);
icon = (lobby.lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC) ? QIcon(IMAGE_PUBLIC) : QIcon(IMAGE_PRIVATE);
itemParent->addChild(item);
@ -605,7 +651,7 @@ void ChatLobbyWidget::updateDisplay()
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);
privateSubLobbyItem->setHidden(privateSubLobbyItem->childCount()==0);
@ -647,9 +693,14 @@ void ChatLobbyWidget::createIdentityAndSubscribe()
return ;
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
ChatLobbyFlags flags(item->data(COLUMN_DATA, ROLE_FLAGS).toUInt());
IdEditDialog dlg(this);
dlg.setupNewId(false);
if(flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED) //
dlg.enforceNoAnonIds() ;
dlg.exec();
// fetch new id
std::list<RsGxsId> own_ids;
@ -711,6 +762,7 @@ void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item)
}
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
ChatLobbyFlags flags ( item->data(COLUMN_DATA, ROLE_FLAGS).toUInt());
RsGxsId gxs_id ;
std::list<RsGxsId> own_ids;
@ -726,6 +778,9 @@ void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item)
{
IdEditDialog dlg(this);
dlg.setupNewId(false);
if(flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED) //
dlg.enforceNoAnonIds() ;
dlg.exec();
// fetch new id
if(!rsIdentity->getOwnIds(own_ids) || own_ids.empty())
@ -733,7 +788,19 @@ void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item)
gxs_id = own_ids.front();
}
else
{
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))
ChatDialog::chatFriend(ChatId(id),true) ;
@ -763,18 +830,25 @@ void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
std::list<RsGxsId> my_ids ;
rsIdentity->getOwnIds(my_ids) ;
trimAnonIds(my_ids) ;
for(std::vector<VisibleChatLobbyRecord>::const_iterator it(lobbies.begin());it!=lobbies.end();++it)
if( (*it).lobby_id == id)
{
ui.lobbyname_lineEdit->setText( RsHtml::plainText(it->lobby_name) );
ui.lobbyid_lineEdit->setText( QString::number((*it).lobby_id,16) );
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) );
QString text = tr("You're not subscribed to this lobby; Double click-it to enter and chat.") ;
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);
return ;
@ -785,6 +859,7 @@ void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
ui.lobbytopic_lineEdit->clear();
ui.lobbytype_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.") ;
ui.lobbyInfoLabel->setText(text) ;

View file

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

View file

@ -207,7 +207,13 @@ void IdEditDialog::setupExistingId(const RsGxsGroupId &keyId)
groupIds.push_back(keyId);
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)

View file

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

View file

@ -57,7 +57,8 @@ CreateLobbyDialog::CreateLobbyDialog(const std::set<RsPeerId>& peer_list, int pr
connect( ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
connect( ui->lobbyName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) );
connect( ui->lobbyTopic_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) );
connect( ui->idChooser_CB, SIGNAL( currentChanged ( int ) ), this, SLOT( checkTextFields( ) ) );
connect( ui->idChooser_CB, SIGNAL( currentIndexChanged ( int ) ), this, SLOT( checkTextFields( ) ) );
connect( ui->pgp_signed_CB, SIGNAL( toggled ( bool ) ), this, SLOT( checkTextFields( ) ) );
/* initialize key share list */
ui->keyShareList->setHeaderText(tr("Contacts:"));
@ -105,6 +106,13 @@ void CreateLobbyDialog::checkTextFields()
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true) ;
break ;
}
RsIdentityDetails(idd) ;
rsIdentity->getIdDetails(id,idd) ;
if( (!idd.mPgpKnown) && ui->pgp_signed_CB->isChecked())
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false) ;
}
void CreateLobbyDialog::createLobby()
@ -128,6 +136,7 @@ void CreateLobbyDialog::createLobby()
case GxsIdChooser::NoId:
case GxsIdChooser::None:
return ;
default: break ;
}
// add to group
@ -136,6 +145,9 @@ void CreateLobbyDialog::createLobby()
if(ui->security_CB->currentIndex() == 0)
lobby_flags |= RS_CHAT_LOBBY_FLAGS_PUBLIC ;
if(ui->pgp_signed_CB->isChecked())
lobby_flags |= RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ;
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name,gxs_id, lobby_topic, shareList, lobby_flags);
std::cerr << "gui: Created chat lobby " << std::hex << id << std::dec << std::endl ;

View file

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>787</width>
<width>1315</width>
<height>486</height>
</rect>
</property>
@ -86,7 +86,7 @@
<item row="3" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Security policy:</string>
<string>Visibility:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -110,6 +110,29 @@
<item row="2" column="2">
<widget class="GxsIdChooser" name="idChooser_CB"/>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="pgp_signed_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If you check this, only PGP-signed ids can be used to join and talk in this lobby. This limitation prevents anonymous spamming as it becomes possible for at least some people in the lobby to locate the spammer's node.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>require PGP-signed identities</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Security:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>