Enabled distant chat system.

Added system to collect and create chat invites from pgp keys.
Finished the GUI (some layouts need fixing, especially the link creation window).
Still needed: QoS on generic turtle data items. Will need a new item class for any anyway.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6433 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-06-16 14:39:44 +00:00
parent 94b78a8444
commit 69bf523c7a
18 changed files with 485 additions and 377 deletions

View file

@ -36,145 +36,23 @@ CreateMsgLinkDialog::CreateMsgLinkDialog()
setAttribute(Qt::WA_DeleteOnClose, false);
_info_GB->layout()->addWidget( _gpg_selection = new FriendSelectionWidget(this) ) ;
QObject::connect(_link_type_CB,SIGNAL(currentIndexChanged(int)),this,SLOT(update())) ;
layout()->addWidget( _gpg_selection = new FriendSelectionWidget(this) ) ;
QObject::connect(_create_link_PB,SIGNAL(clicked()),this,SLOT(createLink())) ;
QObject::connect(_create_new_PB,SIGNAL(toggled(bool)),this,SLOT(toggleCreateLink(bool))) ;
QObject::connect(_existing_links_LW,SIGNAL(currentRowChanged(int)),this,SLOT(updateCurrentRow(int))) ;
QObject::connect(_copy_to_clipboard_PB,SIGNAL(clicked()),this,SLOT(copyLinkToClipboard())) ;
_gpg_selection->setModus(FriendSelectionWidget::MODUS_SINGLE) ;
_gpg_selection->setShowType(FriendSelectionWidget::SHOW_NON_FRIEND_GPG | FriendSelectionWidget::SHOW_GPG) ;
_gpg_selection->setHeaderText(QObject::tr("Select who can contact you:")) ;
_gpg_selection->start() ;
toggleCreateLink(false) ;
layout()->update() ;
update() ;
updateCurrentRow(-1) ;
}
void CreateMsgLinkDialog::copyLinkToClipboard()
void CreateMsgLinkDialog::createNewChatLink()
{
QList<QListWidgetItem*> selected = _existing_links_LW->selectedItems() ;
QList<RetroShareLink> links ;
for(QList<QListWidgetItem*>::const_iterator it(selected.begin());it!=selected.end();++it)
{
QUrl text = (*it)->data(Qt::UserRole).toUrl() ;
RetroShareLink link(text) ;
links.push_back(link) ;
}
if(!links.empty())
RSLinkClipboard::copyLinks(links) ;
}
void CreateMsgLinkDialog::updateCurrentRow(int r)
{
if(r < 0)
{
_current_link_type_LE->setText("") ;
_current_link_dst_LE->setText("") ;
_current_link_date_DE->setDateTime(QDateTime::fromTime_t(0)) ;
return ;
}
QUrl text = _existing_links_LW->item(r)->data(Qt::UserRole).toUrl() ;
std::cerr << "Parsing link : " << text.toString().toStdString() << std::endl;
RetroShareLink link(text) ;
RsPeerDetails detail ;
rsPeers->getPeerDetails(link.GPGId().toStdString(),detail) ;
if( link.type() == RetroShareLink::TYPE_PRIVATE_CHAT )
{
_current_link_type_LE->setText( tr("Private chat invite") ) ;
_usable_LB->setText(tr("Usable only by :")) ;
}
else
{
_current_link_type_LE->setText( tr("Public message invite") ) ;
_usable_LB->setText(tr("Usable to contact :")) ;
}
_current_link_dst_LE->setText(QString::fromStdString(detail.name)+" ("+link.GPGId()+")") ;
_current_link_date_DE->setDateTime(QDateTime::fromTime_t(link.timeStamp())) ;
}
void CreateMsgLinkDialog::toggleCreateLink(bool b)
{
_new_link_F->setHidden(!b) ;
}
void CreateMsgLinkDialog::update()
{
if(_link_type_CB->currentIndex() == 0)
{
QString s ;
s += "A private chat invite allows a specific peer to contact you using encrypted private chat. You need to select a destination peer from your PGP keyring before creating the link. The link contains the encryption code and your PGP signature, so that the peer can authenticate you." ;
_info_TB->setHtml(s) ;
_gpg_selection->setHidden(false) ;
}
else
{
QString s ;
s += "A public message link allows any peer in the nearby network to send a private message to you. The message is encrypted and only you can read it." ;
_info_TB->setHtml(s) ;
_gpg_selection->setHidden(true) ;
}
std::vector<DistantChatInviteInfo> invites ;
rsMsgs->getDistantChatInviteList(invites) ;
_existing_links_LW->clear() ;
for(uint32_t i=0;i<invites.size();++i)
{
RetroShareLink link ;
if(!link.createPrivateChatInvite(invites[i].time_of_validity,QString::fromStdString(invites[i].destination_pgp_id),QString::fromStdString(invites[i].encrypted_radix64_string))) {
std::cerr << "Cannot create link." << std::endl;
continue;
}
RsPeerDetails detail ;
rsPeers->getPeerDetails(link.GPGId().toStdString(),detail) ;
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole,tr("Private chat invite to ")+QString::fromStdString(detail.name)+" ("+QString::fromStdString(invites[i].destination_pgp_id)+")") ;
item->setData(Qt::UserRole,link.toString()) ;
_existing_links_LW->insertItem(0,item) ;
}
std::vector<DistantOfflineMessengingInvite> invites2 ;
rsMsgs->getDistantOfflineMessengingInvites(invites2) ;
for(uint32_t i=0;i<invites2.size();++i)
{
RetroShareLink link ;
if(!link.createPublicMsgInvite(invites2[i].time_of_validity,QString::fromStdString(invites2[i].issuer_pgp_id),QString::fromStdString(invites2[i].hash)))
std::cerr << "Cannot create link." << std::endl;
else
{
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole,tr("Public message link")) ;
item->setData(Qt::UserRole,link.toString()) ;
_existing_links_LW->insertItem(0,item) ;
}
}
std::cerr << "In static method..." << std::endl;
CreateMsgLinkDialog dialog ;
dialog.exec() ;
}
time_t CreateMsgLinkDialog::computeValidityDuration() const
@ -203,8 +81,6 @@ void CreateMsgLinkDialog::createLink()
{
std::cerr << "Creating link!" << std::endl;
if(_link_type_CB->currentIndex() == 0)
{
time_t validity_duration = computeValidityDuration() ;
FriendSelectionWidget::IdType type ;
std::string current_pgp_id = _gpg_selection->selectedId(type) ;
@ -226,10 +102,11 @@ void CreateMsgLinkDialog::createLink()
if(!res)
QMessageBox::critical(NULL,tr("Private chat invite creation failed"),tr("The creation of the chat invite failed")) ;
else
QMessageBox::information(NULL,tr("Private chat invite created"),tr("Your new chat invite has been copied to clipboard. You can now paste it as a Retroshare link.")) ;
}
else
{
QMessageBox::information(NULL,tr("Private chat invite created"),tr("Your new chat invite has been created. You can now copy/paste it as a Retroshare link.")) ;
#ifdef TO_REMOVE
/* OLD CODE TO CREATE A MSG LINK */
time_t validity_duration = computeValidityDuration() ;
std::string hash;
std::string issuer_pgp_id = rsPeers->getGPGOwnId() ;
@ -253,8 +130,6 @@ void CreateMsgLinkDialog::createLink()
QMessageBox::critical(NULL,tr("Messenging invite creation failed"),tr("The creation of the messenging invite failed")) ;
else
QMessageBox::information(NULL,tr("Messenging invite created"),tr("Your new messenging chat invite has been copied to clipboard. You can now paste it as a Retroshare link.")) ;
}
QTimer::singleShot(100,this,SLOT(update())) ;
#endif
}

View file

@ -30,16 +30,15 @@ class CreateMsgLinkDialog : public QDialog, public Ui::CreateMsgLinkDialog
Q_OBJECT
public:
static void createNewChatLink() ;
protected:
CreateMsgLinkDialog();
virtual ~CreateMsgLinkDialog() {}
private slots:
/* actions to take.... */
void createLink();
void update() ;
void toggleCreateLink(bool) ;
void updateCurrentRow(int) ;
void copyLinkToClipboard() ;
private:
time_t computeValidityDuration() const ;

View file

@ -7,94 +7,13 @@
<x>0</x>
<y>0</y>
<width>590</width>
<height>388</height>
<height>179</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Create distant chat invite</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QListWidget" name="_existing_links_LW">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Valid until:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="_usable_LB">
<property name="text">
<string>Usable by:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QDateTimeEdit" name="_current_link_date_DE"/>
</item>
<item>
<widget class="QLineEdit" name="_current_link_type_LE"/>
</item>
<item>
<widget class="QLineEdit" name="_current_link_dst_LE"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="_copy_to_clipboard_PB">
<property name="text">
<string>Copy to clipboard</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="_create_new_PB">
<property name="text">
<string>Create new</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="_new_link_F">
<property name="frameShape">
@ -105,113 +24,99 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Invite type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="_link_type_CB">
<item>
<property name="text">
<string>Private chat</string>
</property>
</item>
<item>
<property name="text">
<string>Public message</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Validity time :</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="_validity_time_SB">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="_validity_time_CB">
<item>
<property name="text">
<string>hour</string>
</property>
</item>
<item>
<property name="text">
<string>day</string>
</property>
</item>
<item>
<property name="text">
<string>week</string>
</property>
</item>
<item>
<property name="text">
<string>month</string>
</property>
</item>
<item>
<property name="text">
<string>year</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="_create_link_PB">
<property name="text">
<string>Create!</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="_info_GB">
<property name="title">
<string>Information</string>
<widget class="QLabel" name="label_3">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;To create a private chat invite for a non-friend person, select his key below and a validity time for your invite, then press &amp;quot;Create&amp;quot;. The invite will contain the information required to open a tunnel to chat with you. &lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;The invite is encrypted, and does not reveal your identity. Only the selected peer can decrypt the link, and use it to contact you.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextBrowser" name="_info_TB"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Invite type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="_link_type_CB">
<item>
<property name="text">
<string>Private chat</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Validity time :</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="_validity_time_SB">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="_validity_time_CB">
<item>
<property name="text">
<string>hour</string>
</property>
</item>
<item>
<property name="text">
<string>day</string>
</property>
</item>
<item>
<property name="text">
<string>week</string>
</property>
</item>
<item>
<property name="text">
<string>month</string>
</property>
</item>
<item>
<property name="text">
<string>year</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="_create_link_PB">
<property name="text">
<string>Create!</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>

View file

@ -231,10 +231,6 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint /*point*/ )
contextMnu->addAction(QIcon(IMAGE_PEERDETAILS), tr("Peer details..."), this, SLOT(peerdetails()));
contextMnu->addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink()));
contextMnu->addSeparator() ;
#ifdef ENABLE_DISTANT_CHAT_AND_MSGS
contextMnu->addAction(QIcon(IMAGE_COPYLINK), tr("Create a distant chat invitation..."), this, SLOT(createChatLink()));
contextMnu->addSeparator() ;
#endif
contextMnu->addAction(QIcon(IMAGE_CLEAN_UNUSED), tr("Remove unused keys..."), this, SLOT(removeUnusedKeys()));
contextMnu->exec(QCursor::pos());
@ -334,19 +330,6 @@ void NetworkDialog::makeFriend()
ConfCertDialog::showIt(getCurrentNeighbour()->text(COLUMN_PEERID).toStdString(), ConfCertDialog::PageTrust);
}
void NetworkDialog::createChatLink()
{
std::string pgp_id = getCurrentNeighbour()->text(COLUMN_PEERID).toStdString() ;
std::cerr << "Creating chat link for pgp id " << pgp_id << std::endl;
std::string hash,estr ;
rsMsgs->createDistantChatInvite(pgp_id,time(NULL)+3600,estr) ;
std::cerr << "Created invite:" << std::endl;
std::cerr << " estr = " << estr << std::endl;
}
/** Shows Peer Information/Auth Dialog */
void NetworkDialog::peerdetails()
{

View file

@ -69,7 +69,6 @@ private slots:
void removeUnusedKeys() ;
void makeFriend() ;
void denyFriend() ;
void createChatLink() ;
void deleteCert() ;
void peerdetails();
void copyLink();

View file

@ -1226,7 +1226,7 @@ static void processList(const QStringList &list, const QString &textSingular, co
std::string hash ;
uint32_t error_code ;
if(!rsMsgs->initiateDistantChatConnexion(link._encrypted_chat_info.toStdString(),hash,error_code))
if(!rsMsgs->initiateDistantChatConnexion(link._encrypted_chat_info.toStdString(),link._time_stamp,hash,error_code))
{
QString error_msg ;
switch(error_code)

View file

@ -217,6 +217,15 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
return;
}
std::string distant_chat_pgp_id ;
uint32_t distant_peer_status ;
if(rsMsgs->getDistantChatStatus(peerId,distant_peer_status,distant_chat_pgp_id))
{
getChat(peerId,RS_CHAT_OPEN | RS_CHAT_FOCUS); // use own flags
return ;
}
ChatLobbyId lid;
if (rsMsgs->isLobbyId(peerId, lid)) {
getChat(peerId, RS_CHAT_OPEN | RS_CHAT_FOCUS);

View file

@ -38,6 +38,7 @@
#include "gui/RetroShareLink.h"
#include "gui/CreateMsgLinkDialog.h"
#include "gui/settings/rsharesettings.h"
#include "gui/settings/rsettingswin.h"
#include "gui/settings/RsharePeerSettings.h"
#include "gui/im_history/ImHistoryBrowser.h"
#include "gui/common/StatusDefs.h"
@ -549,9 +550,9 @@ void ChatWidget::contextMenu(QPoint point)
QAction *action = contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste RetroShare Link"), this, SLOT(pasteLink()));
action->setDisabled(RSLinkClipboard::empty());
contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste my certificate link"), this, SLOT(pasteOwnCertificateLink()));
#ifdef ENABLE_DISTANT_CHAT_AND_MSGS
contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste/Create private chat or Message link..."), this, SLOT(pasteCreateMsgLink()));
#endif
//#ifdef ENABLE_DISTANT_CHAT_AND_MSGS
// contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste/Create private chat or Message link..."), this, SLOT(pasteCreateMsgLink()));
//#endif
contextMnu->exec(QCursor::pos());
delete(contextMnu);
@ -559,10 +560,7 @@ void ChatWidget::contextMenu(QPoint point)
void ChatWidget::pasteCreateMsgLink()
{
CreateMsgLinkDialog dialog ;
dialog.exec() ;
ui->chatTextEdit->insertHtml(RSLinkClipboard::toHtml());
RSettingsWin::showYourself(this, RSettingsWin::Chat);
}
void ChatWidget::contextMenuTextBrowser(QPoint point)

View file

@ -95,7 +95,7 @@ void PopupDistantChatDialog::updateDisplay()
_status_label->setPixmap(QPixmap(IMAGE_YEL_LED)) ;
_status_label->setToolTip(QObject::tr("Secured tunnel established!")) ;
break ;
case RS_DISTANT_CHAT_STATUS_CAN_TALK: std::cerr << "Tunnel is ok and works. You can talk!" << std::endl;
case RS_DISTANT_CHAT_STATUS_CAN_TALK: std::cerr << "Tunnel is ok and data is transmitted." << std::endl;
_status_label->setPixmap(QPixmap(IMAGE_GRN_LED)) ;
_status_label->setToolTip(QObject::tr("Secured tunnel is working")) ;
break ;

View file

@ -340,7 +340,7 @@ void FriendSelectionWidget::fillList()
gpgItem = new RSTreeWidgetItem(mCompareRole, IDTYPE_GPG);
QString name = QString::fromUtf8(detail.name.c_str());
gpgItem->setText(COLUMN_NAME, name);
gpgItem->setText(COLUMN_NAME, name + " ("+QString::fromStdString(*gpgIt)+")");
sslIds.clear();
rsPeers->getAssociatedSSLIds(*gpgIt, sslIds);

View file

@ -20,11 +20,18 @@
****************************************************************/
#include <QFontDialog>
#include <QMenu>
#include <QMessageBox>
#include <time.h>
#include <retroshare/rsnotify.h>
#include <retroshare/rsmsgs.h>
#include <retroshare/rspeers.h>
#include "ChatPage.h"
#include <gui/RetroShareLink.h>
#include <gui/CreateMsgLinkDialog.h>
#include "gui/chat/ChatStyle.h"
#include "gui/chat/ChatDialog.h"
#include "gui/notifyqt.h"
#include "rsharesettings.h"
@ -32,6 +39,10 @@
#include <retroshare/rsmsgs.h>
#define VARIANT_STANDARD "Standard"
#define IMAGE_CHAT_CREATE ":/images/add_24x24.png"
#define IMAGE_CHAT_OPEN ":/images/typing.png"
#define IMAGE_CHAT_DELETE ":/images/deletemail24.png"
#define IMAGE_CHAT_COPY ":/images/copyrslink.png"
static QString loadStyleInfo(ChatStyle::enumStyleType type, QListWidget *listWidget, QComboBox *comboBox, QString &styleVariant)
{
@ -94,12 +105,147 @@ ChatPage::ChatPage(QWidget * parent, Qt::WFlags flags)
ui.minimumContrast->hide();
#endif
connect(ui._personal_invites_LW, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(personalInvites_customPopupMenu(QPoint)));
connect(ui._collected_contacts_LW, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(collectedContacts_customPopupMenu(QPoint)));
/* Hide platform specific features */
#ifdef Q_WS_WIN
#endif
}
void ChatPage::collectedContacts_customPopupMenu(QPoint p)
{
// items: chat with this person, copy to clipboard, delete
std::cerr << "In custom popup menu" << std::endl;
QListWidgetItem *item = ui._collected_contacts_LW->itemAt(p) ;
if(item == NULL)
return ;
QList<QListWidgetItem*> selected = ui._collected_contacts_LW->selectedItems() ;
QMenu contextMnu( this );
if(selected.size() == 1)
contextMnu.addAction( QIcon(IMAGE_CHAT_OPEN), tr("Open secured chat tunnel"), this, SLOT(collectedInvite_openDistantChat()) ) ;
contextMnu.addAction( QIcon(IMAGE_CHAT_DELETE), tr("Delete this invite"), this, SLOT(collectedInvite_delete()) ) ;
contextMnu.exec(QCursor::pos());
}
void ChatPage::collectedInvite_openDistantChat()
{
QList<QListWidgetItem*> selected = ui._collected_contacts_LW->selectedItems() ;
std::string hash = (*selected.begin())->data(Qt::UserRole).toString().toStdString() ;
std::cerr << "Openning secured chat tunnel for hash " << hash << ". Please wait..." << std::endl;
uint32_t error_code ;
if(!rsMsgs->initiateDistantChatConnexion(hash,error_code))
QMessageBox::critical(NULL,tr("Can't open distant chat"),tr("Cannot open distant chat. Error code=")+QString::number(error_code)) ;
else
ChatDialog::chatFriend(hash);
}
void ChatPage::collectedInvite_delete()
{
QList<QListWidgetItem*> selected = ui._collected_contacts_LW->selectedItems() ;
for(QList<QListWidgetItem*>::const_iterator it(selected.begin());it!=selected.end();++it)
{
std::string hash = (*it)->data(Qt::UserRole).toString().toStdString() ;
std::cerr << "Removing chat invite for hash " << hash << std::endl;
if(!rsMsgs->removeDistantChatInvite(hash))
QMessageBox::critical(NULL,tr("Can't open distant chat"),tr("Cannot remove distant chat invite.")) ;
}
load() ;
}
void ChatPage::personalInvites_customPopupMenu(QPoint p)
{
// items: create invite, copy to clipboard, delete
std::cerr << "In custom popup menu" << std::endl;
QList<QListWidgetItem*> selected = ui._personal_invites_LW->selectedItems() ;
QMenu contextMnu( this );
contextMnu.addAction( QIcon(IMAGE_CHAT_CREATE), tr("Create a chat invitation"), this, SLOT(personalInvites_create()) ) ;
if(!selected.empty())
{
contextMnu.addAction( QIcon(IMAGE_CHAT_COPY), tr("Copy link to clipboard"), this, SLOT(personalInvites_copyLink()) ) ;
contextMnu.addAction( QIcon(IMAGE_CHAT_DELETE), tr("Delete this invite"), this, SLOT(personalInvites_delete()) ) ;
}
contextMnu.exec(QCursor::pos());
}
void ChatPage::personalInvites_copyLink()
{
QList<QListWidgetItem*> selected = ui._personal_invites_LW->selectedItems() ;
QList<RetroShareLink> links ;
std::vector<DistantChatInviteInfo> invites ;
rsMsgs->getDistantChatInviteList(invites) ;
for(QList<QListWidgetItem*>::const_iterator it(selected.begin());it!=selected.end();++it)
{
std::string hash = (*it)->data(Qt::UserRole).toString().toStdString() ;
bool found = false ;
for(uint32_t i=0;i<invites.size();++i)
if(invites[i].hash == hash)
{
RetroShareLink link ;
if(!link.createPrivateChatInvite(invites[i].time_of_validity,QString::fromStdString(invites[i].destination_pgp_id),QString::fromStdString(invites[i].encrypted_radix64_string)))
{
std::cerr << "Cannot create link." << std::endl;
continue;
}
links.push_back(link) ;
break ;
}
}
if(!links.empty())
RSLinkClipboard::copyLinks(links) ;
}
void ChatPage::personalInvites_delete()
{
QList<QListWidgetItem*> selected = ui._personal_invites_LW->selectedItems() ;
QList<RetroShareLink> links ;
for(QList<QListWidgetItem*>::const_iterator it(selected.begin());it!=selected.end();++it)
{
std::string hash = (*it)->data(Qt::UserRole).toString().toStdString() ;
rsMsgs->removeDistantChatInvite(hash) ;
}
load() ;
}
void ChatPage::personalInvites_create()
{
// Call the link creation box
CreateMsgLinkDialog::createNewChatLink() ;
// Now update the page
//
load() ;
}
/** Saves the changes on this page */
bool
ChatPage::save(QString &/*errmsg*/)
@ -229,6 +375,37 @@ ChatPage::load()
uint chatLobbyFlags = Settings->getChatLobbyFlags();
ui.chatLobby_Blink->setChecked(chatLobbyFlags & RS_CHATLOBBY_BLINK);
// load personal invites
//
std::vector<DistantChatInviteInfo> invites ;
rsMsgs->getDistantChatInviteList(invites) ;
ui._personal_invites_LW->clear() ;
ui._collected_contacts_LW->clear() ;
for(uint32_t i=0;i<invites.size();++i)
{
RsPeerDetails detail ;
rsPeers->getPeerDetails(invites[i].destination_pgp_id,detail) ;
if(invites[i].encrypted_radix64_string.empty())
{
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole,tr("Private chat invite from ")+QString::fromStdString(detail.name)+" ("+QString::fromStdString(invites[i].destination_pgp_id)+", " + QString::fromStdString(detail.name) + ", valid until " + QDateTime::fromTime_t(invites[i].time_of_validity).toString() + ")") ;
item->setData(Qt::UserRole,QString::fromStdString(invites[i].hash)) ;
ui._collected_contacts_LW->insertItem(0,item) ;
}
else
{
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole,tr("Private chat invite to ")+QString::fromStdString(detail.name)+" ("+QString::fromStdString(invites[i].destination_pgp_id)+", " + QString::fromStdString(detail.name) + ", valid until " + QDateTime::fromTime_t(invites[i].time_of_validity).toString() + ")") ;
item->setData(Qt::UserRole,QString::fromStdString(invites[i].hash)) ;
ui._personal_invites_LW->insertItem(0,item) ;
}
}
}
void ChatPage::on_pushButtonChangeChatFont_clicked()

View file

@ -52,6 +52,16 @@ class ChatPage : public ConfigPage
void on_privateList_currentRowChanged(int currentRow);
void on_historyList_currentRowChanged(int currentRow);
void personalInvites_customPopupMenu(QPoint) ;
void collectedContacts_customPopupMenu(QPoint) ;
void personalInvites_copyLink() ;
void personalInvites_delete() ;
void personalInvites_create() ;
void collectedInvite_openDistantChat() ;
void collectedInvite_delete() ;
private:
void setPreviewMessages(QString &stylePath, QString styleVariant, QTextBrowser *textBrowser);
void fillPreview(QListWidget *listWidget, QComboBox *comboBox, QTextBrowser *textBrowser);

View file

@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>444</width>
<height>390</height>
<width>646</width>
<height>544</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="general">
<attribute name="title">
@ -317,6 +317,67 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Distant chat</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;Retroshare allows you to anonymously chat to nearby people beyond your friends in the network, using encrypted tunnels. In your personal invites list you keep chat links for people to contact you. In the &amp;quot;collected contacts&amp;quot; list, you keep such chat links that people sent you to contact them.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Your personnal invites</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QListWidget" name="_personal_invites_LW">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Collected contacts</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QListWidget" name="_collected_contacts_LW">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="history">
<attribute name="title">
<string>History</string>