Added multi friend recommendation dialog.

You can start it from the tools menu in FriendsDialog.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4913 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-02-09 19:18:15 +00:00
parent 12767d8fe9
commit 3b314e3a69
11 changed files with 336 additions and 25 deletions

View file

@ -0,0 +1,90 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2012, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QMessageBox>
#include "FriendRecommendDialog.h"
#include "ui_FriendRecommendDialog.h"
#include "msgs/MessageComposer.h"
#include "settings/rsharesettings.h"
void FriendRecommendDialog::showYourself(QWidget *parent)
{
FriendRecommendDialog *dlg = new FriendRecommendDialog(parent);
dlg->show();
}
FriendRecommendDialog::FriendRecommendDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::FriendRecommendDialog)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true);
Settings->loadWidgetInformation(this);
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(sendMsg()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
ui->recommendList->setHeaderText(tr("Recommend friends"));
ui->recommendList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui->recommendList->start();
ui->toList->setHeaderText(tr("To"));
ui->toList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui->toList->start();
ui->messageEdit->setText(MessageComposer::recommendMessage());
}
FriendRecommendDialog::~FriendRecommendDialog()
{
Settings->saveWidgetInformation(this);
delete ui;
}
void FriendRecommendDialog::sendMsg()
{
std::list<std::string> recommendIds;
ui->recommendList->selectedSslIds(recommendIds, false);
if (recommendIds.empty()) {
QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend for recommendation."), QMessageBox::Ok, QMessageBox::Ok);
return;
}
std::list<std::string> toIds;
ui->toList->selectedSslIds(toIds, false);
if (toIds.empty()) {
QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend as recipient."), QMessageBox::Ok, QMessageBox::Ok);
return;
}
std::list<std::string>::iterator toId;
for (toId = toIds.begin(); toId != toIds.end(); toId++) {
MessageComposer::recommendFriend(recommendIds, *toId, ui->messageEdit->toHtml(), true);
}
done(Accepted);
}

View file

@ -0,0 +1,49 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2012, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef FRIENDRECOMMENDDIALOG_H
#define FRIENDRECOMMENDDIALOG_H
#include <QDialog>
namespace Ui {
class FriendRecommendDialog;
}
class FriendRecommendDialog : public QDialog
{
Q_OBJECT
public:
~FriendRecommendDialog();
static void showYourself(QWidget *parent = 0);
private slots:
void sendMsg();
private:
FriendRecommendDialog(QWidget *parent = 0);
Ui::FriendRecommendDialog *ui;
};
#endif // FRIENDRECOMMENDDIALOG_H

View file

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FriendRecommendDialog</class>
<widget class="QDialog" name="FriendRecommendDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<height>362</height>
</rect>
</property>
<property name="windowTitle">
<string>Friend Recommendations</string>
</property>
<property name="windowIcon">
<iconset resource="images.qrc">
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="FriendSelectionWidget" name="recommendList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="FriendSelectionWidget" name="toList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Message:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="messageEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FriendSelectionWidget</class>
<extends>QWidget</extends>
<header>gui/common/FriendSelectionWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -56,6 +56,7 @@
#include "settings/rsharesettings.h"
#include "util/misc.h"
#include "chat/CreateLobbyDialog.h"
#include "FriendRecommendDialog.h"
#include "FriendsDialog.h"
@ -88,6 +89,7 @@ FriendsDialog::FriendsDialog(QWidget *parent)
connect( ui.addfileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile()));
connect( ui.actionAdd_Friend, SIGNAL(triggered()), this, SLOT(addFriend()));
connect( ui.actionCreate_new_Chat_lobby, SIGNAL(triggered()), this, SLOT(createChatLobby()));
connect( ui.actionFriendRecommendations, SIGNAL(triggered()), this, SLOT(recommendFriends()));
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatar->setOwnId();
@ -159,6 +161,7 @@ FriendsDialog::FriendsDialog(QWidget *parent)
menu->addAction(ui.actionAdd_Friend);
menu->addAction(ui.actionAdd_Group);
menu->addAction(ui.actionCreate_new_Chat_lobby);
menu->addAction(ui.actionFriendRecommendations);
menu->addSeparator();
menu->addAction(ui.actionCreate_New_Forum);
@ -830,6 +833,11 @@ void FriendsDialog::createChatLobby()
CreateLobbyDialog(friends).exec();
}
void FriendsDialog::recommendFriends()
{
FriendRecommendDialog::showYourself();
}
/*static*/ ChatTabWidget *FriendsDialog::getTabWidget()
{
return instance ? instance->ui.tabWidget : NULL;

View file

@ -113,6 +113,7 @@ private slots:
void newsFeedChanged(int count);
void createChatLobby();
void recommendFriends();
signals:
void notifyGroupChat(const QString&,const QString&) ;

View file

@ -1442,6 +1442,11 @@ background: white;}</string>
<string>Create new Chat lobby</string>
</property>
</action>
<action name="actionFriendRecommendations">
<property name="text">
<string>Friend Recommendations</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View file

@ -346,7 +346,7 @@ void MessageComposer::processSettings(bool bLoad)
Settings->endGroup();
}
/*static*/ void MessageComposer::msgFriend(std::string id, bool group)
/*static*/ void MessageComposer::msgFriend(const std::string &id, bool group)
{
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
@ -382,13 +382,16 @@ void MessageComposer::processSettings(bool bLoad)
/* window will destroy itself! */
}
static QString buildRecommendHtml(std::list<std::string> &sslIds)
static QString buildRecommendHtml(const std::list<std::string> &sslIds, const std::string &excludeId = "")
{
QString text;
/* process ssl ids */
std::list <std::string>::iterator sslIt;
std::list <std::string>::const_iterator sslIt;
for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) {
if (*sslIt == excludeId) {
continue;
}
RetroShareLink link;
if (link.createCertificate(*sslIt)) {
text += link.toHtml() + "<br>";
@ -398,7 +401,12 @@ static QString buildRecommendHtml(std::list<std::string> &sslIds)
return text;
}
void MessageComposer::recommendFriend(std::list <std::string> &sslIds)
QString MessageComposer::recommendMessage()
{
return tr("I recommend a good friend of me, you can trust him too when you trust me. <br> Copy friend link and paste to Friends list");
}
void MessageComposer::recommendFriend(const std::list <std::string> &sslIds, const std::string &to, const QString &msg, bool autoSend)
{
// std::cerr << "MessageComposer::recommendFriend()" << std::endl;
@ -406,21 +414,40 @@ void MessageComposer::recommendFriend(std::list <std::string> &sslIds)
return;
}
QString recommendHtml = buildRecommendHtml(sslIds, to);
if (recommendHtml.isEmpty()) {
return;
}
/* create a message */
MessageComposer *pMsgDialog = MessageComposer::newMsg();
pMsgDialog->insertTitleText(tr("Friend Recommendation(s)"));
QString sMsgText = tr("I recommend a good friend of me, you can trust him too when you trust me. <br> Copy friend link and paste to Friends list");
if (!to.empty()) {
pMsgDialog->addRecipient(TO, to, false);
}
QString sMsgText = msg.isEmpty() ? recommendMessage() : msg;
sMsgText += "<br><br>";
sMsgText += buildRecommendHtml(sslIds);
sMsgText += recommendHtml;
pMsgDialog->insertMsgText(sMsgText);
std::list <std::string>::iterator peerIt;
std::list <std::string>::const_iterator peerIt;
for (peerIt = sslIds.begin(); peerIt != sslIds.end(); peerIt++) {
if (*peerIt == to) {
continue;
}
pMsgDialog->addRecipient(CC, *peerIt, false);
}
if (autoSend) {
if (pMsgDialog->sendMessage_internal(false)) {
pMsgDialog->close();
return;
}
}
pMsgDialog->show();
/* window will destroy itself! */
@ -917,7 +944,7 @@ MessageComposer *MessageComposer::forwardMsg(const std::string &msgId)
return msgComposer;
}
void MessageComposer::insertTitleText(const QString &title, enumMessageType type)
void MessageComposer::insertTitleText(const QString &title, enumMessageType type)
{
QString titleText;
@ -944,7 +971,7 @@ void MessageComposer::insertTitleText(const QString &title, enumMessageType typ
ui.titleEdit->setText(misc::removeNewLine(titleText));
}
void MessageComposer::insertPastedText(QString msg)
void MessageComposer::insertPastedText(QString msg)
{
msg.replace("\n", "\n<BR>> ");
@ -959,7 +986,7 @@ void MessageComposer::insertPastedText(QString msg)
ui.msgText->document()->setModified(true);
}
void MessageComposer::insertForwardPastedText(QString msg)
void MessageComposer::insertForwardPastedText(QString msg)
{
msg.replace("\n", "\n<BR>> ");
@ -974,7 +1001,7 @@ void MessageComposer::insertForwardPastedText(QString msg)
ui.msgText->document()->setModified(true);
}
void MessageComposer::insertMsgText(const QString &msg)
void MessageComposer::insertMsgText(const QString &msg)
{
ui.msgText->setText(msg);
@ -987,14 +1014,14 @@ void MessageComposer::insertMsgText(const QString &msg)
ui.msgText->document()->setModified(true);
}
void MessageComposer::insertHtmlText(const QString &msg)
void MessageComposer::insertHtmlText(const QString &msg)
{
ui.msgText->setHtml("<a href='" + msg + "'> " + msg + "</a>");
ui.msgText->document()->setModified(true);
}
void MessageComposer::sendMessage()
void MessageComposer::sendMessage()
{
if (sendMessage_internal(false)) {
close();

View file

@ -47,8 +47,9 @@ public:
MessageComposer(QWidget *parent = 0, Qt::WFlags flags = 0);
~MessageComposer();
static void msgFriend(std::string id, bool group);
static void recommendFriend(std::list <std::string> &sslIds);
static void msgFriend(const std::string &id, bool group);
static QString recommendMessage();
static void recommendFriend(const std::list <std::string> &sslIds, const std::string &to = "", const QString &msg = "", bool autoSend = false);
static MessageComposer *newMsg(const std::string &msgId = "");
static MessageComposer *replyMsg(const std::string &msgId, bool all);