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

@ -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>