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

@ -224,6 +224,7 @@ HEADERS += rshare.h \
gui/TrustView.h \
gui/MessengerWindow.h \
gui/FriendsDialog.h \
gui/FriendRecommendDialog.h \
gui/RemoteDirModel.h \
gui/RetroShareLink.h \
gui/SearchTreeWidget.h \
@ -405,6 +406,7 @@ FORMS += gui/StartDialog.ui \
gui/HelpDialog.ui \
gui/InfoDialog.ui \
gui/DetailsDialog.ui \
gui/FriendRecommendDialog.ui \
gui/bwgraph/bwgraph.ui \
gui/profile/ProfileWidget.ui \
gui/profile/StatusMessage.ui \
@ -498,6 +500,7 @@ SOURCES += main.cpp \
gui/TrustView.cpp \
gui/MessengerWindow.cpp \
gui/FriendsDialog.cpp \
gui/FriendRecommendDialog.cpp \
gui/RemoteDirModel.cpp \
gui/RsAutoUpdatePage.cpp \
gui/RetroShareLink.cpp \

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);

View File

@ -4959,6 +4959,39 @@ p, li { white-space: pre-wrap; }
<translation>Spalten</translation>
</message>
</context>
<context>
<name>FriendRecommendDialog</name>
<message>
<location filename="../gui/FriendRecommendDialog.ui" line="+14"/>
<source>Friend Recommendations</source>
<translation>Freundempfehlungen</translation>
</message>
<message>
<location line="+37"/>
<source>Message:</source>
<translation>Nachricht:</translation>
</message>
<message>
<location filename="../gui/FriendRecommendDialog.cpp" line="+48"/>
<source>Recommend friends</source>
<translation>Freunde empfehlen</translation>
</message>
<message>
<location line="+4"/>
<source>To</source>
<translation>An</translation>
</message>
<message>
<location line="+20"/>
<source>Please select at least one friend for recommendation.</source>
<translation>Bitte mindestens einen Freund als Empfehlung wählen.</translation>
</message>
<message>
<location line="+8"/>
<source>Please select at least one friend as recipient.</source>
<translation>Bitte mindestens einen Empfänger wählen.</translation>
</message>
</context>
<context>
<name>FriendSelectionWidget</name>
<message>
@ -5147,6 +5180,11 @@ p, li { white-space: pre-wrap; }
<source>Create new Chat lobby</source>
<translation>Neue Chat Lobby erstellen</translation>
</message>
<message>
<location line="+5"/>
<source>Friend Recommendations</source>
<translation>Freundempfehlungen</translation>
</message>
<message>
<source>Hide Offline Friends</source>
<translation type="obsolete">Verstecke offline Freunde</translation>
@ -5168,7 +5206,7 @@ p, li { white-space: pre-wrap; }
<translation type="obsolete">Status ausblenden</translation>
</message>
<message>
<location line="-27"/>
<location line="-32"/>
<location line="+3"/>
<source>Add a new Group</source>
<translation>Neue Gruppe hinzufügen</translation>
@ -5196,7 +5234,7 @@ p, li { white-space: pre-wrap; }
<translation>Löscht den gespeicherten und angezeigten Chat Verlauf</translation>
</message>
<message>
<location filename="../gui/FriendsDialog.cpp" line="+96"/>
<location filename="../gui/FriendsDialog.cpp" line="+98"/>
<source>Chat lobbies</source>
<translation>Chat Lobbies</translation>
</message>
@ -5216,7 +5254,7 @@ p, li { white-space: pre-wrap; }
<translation>Willkommen bei RetroShare&apos;s Gruppenchat.</translation>
</message>
<message>
<location line="+67"/>
<location line="+68"/>
<source>me</source>
<translation>ich</translation>
</message>
@ -7237,7 +7275,7 @@ Bitte gib etwas Speicher frei und drücke OK.</translation>
<name>MessageComposer</name>
<message>
<location filename="../gui/msgs/MessageComposer.ui" line="+17"/>
<location filename="../gui/msgs/MessageComposer.cpp" line="+676"/>
<location filename="../gui/msgs/MessageComposer.cpp" line="+703"/>
<source>Compose</source>
<translation>Verfassen</translation>
</message>
@ -7256,7 +7294,7 @@ Bitte gib etwas Speicher frei und drücke OK.</translation>
<translation type="obsolete">Zurücksetzen</translation>
</message>
<message>
<location filename="../gui/msgs/MessageComposer.cpp" line="-472"/>
<location filename="../gui/msgs/MessageComposer.cpp" line="-499"/>
<source>Send To:</source>
<translation>Senden an:</translation>
</message>
@ -7387,7 +7425,7 @@ Bitte gib etwas Speicher frei und drücke OK.</translation>
<translation>Setzt Schriftart auf Codestil</translation>
</message>
<message>
<location filename="../gui/msgs/MessageComposer.cpp" line="+939"/>
<location filename="../gui/msgs/MessageComposer.cpp" line="+966"/>
<source>To</source>
<translation>An</translation>
</message>
@ -7472,7 +7510,7 @@ Bitte gib etwas Speicher frei und drücke OK.</translation>
<translation>Blockquote hinzufügen</translation>
</message>
<message>
<location filename="../gui/msgs/MessageComposer.cpp" line="-1025"/>
<location filename="../gui/msgs/MessageComposer.cpp" line="-1052"/>
<source>&amp;Left</source>
<translation>&amp;Links</translation>
</message>
@ -7492,7 +7530,7 @@ Bitte gib etwas Speicher frei und drücke OK.</translation>
<translation>&amp;Blocksatz</translation>
</message>
<message>
<location line="+217"/>
<location line="+244"/>
<location line="+1503"/>
<source>Save Message</source>
<translation>Nachricht speichern</translation>
@ -7737,12 +7775,12 @@ Möchtest du die Nachricht speichern ?</translation>
<translation type="obsolete">Datei nicht gefunden oder Dateiname nicht akzeptiert.</translation>
</message>
<message>
<location line="-1665"/>
<location line="-1679"/>
<source>Friend Recommendation(s)</source>
<translation>Freundempfehlung(en)</translation>
</message>
<message>
<location line="+2"/>
<location line="-19"/>
<source>I recommend a good friend of me, you can trust him too when you trust me. &lt;br&gt; Copy friend link and paste to Friends list</source>
<translation>Ich empfehle Dir einen guten Freund von mir. Du kannst ihm vertrauen, wenn Du mir vertraust. &lt;br&gt; Kopiere den Link und füge ihn in der Freundesliste ein</translation>
</message>