added a friend recommendation menu entry in Home drop menu, and created the dialog to create/send the recommendations

This commit is contained in:
csoler 2017-01-22 21:06:11 +01:00
parent dc43611dd4
commit 214fbc7957
6 changed files with 232 additions and 1 deletions

View File

@ -25,6 +25,7 @@
#include "gui/notifyqt.h"
#include "gui/msgs/MessageComposer.h"
#include "gui/connect/ConnectFriendWizard.h"
#include "gui/connect/FriendRecommendDialog.h"
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
#include <QUrlQuery>
@ -60,10 +61,14 @@ HomePage::HomePage(QWidget *parent) :
QAction *SendAction = new QAction(QIcon(),tr("Send via Email"), this);
connect(SendAction, SIGNAL(triggered()), this, SLOT(runEmailClient()));
QAction *RecAction = new QAction(QIcon(),tr("Recommend friends to each others"), this);
connect(RecAction, SIGNAL(triggered()), this, SLOT(recommendFriends()));
QMenu *menu = new QMenu();
menu->addAction(CopyAction);
menu->addAction(SaveAction);
menu->addAction(SendAction);
menu->addAction(RecAction);
ui->shareButton->setMenu(menu);
@ -109,6 +114,11 @@ static void sendMail(QString sAddress, QString sSubject, QString sBody)
QDesktopServices::openUrl (url);
}
void HomePage::recommendFriends()
{
FriendRecommendDialog::showIt() ;
}
void HomePage::runEmailClient()
{
sendMail("", tr("RetroShare Invite"), ui->userCertEdit->toPlainText());

View File

@ -53,7 +53,8 @@ private slots:
void runEmailClient();
void copyCert();
void saveCert();
void addFriend();
void recommendFriends();
void addFriend();
private:
Ui::HomePage *ui;

View File

@ -0,0 +1,77 @@
#include <QMessageBox>
#include "FriendRecommendDialog.h"
#include "gui/msgs/MessageComposer.h"
FriendRecommendDialog::FriendRecommendDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::FriendRecommendDialog)
{
ui->setupUi(this) ;
}
FriendRecommendDialog::~FriendRecommendDialog()
{
}
void FriendRecommendDialog::load()
{
ui->frec_recommendList->setHeaderText(tr("Recommend friends"));
ui->frec_recommendList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui->frec_recommendList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL);
ui->frec_recommendList->start();
ui->frec_toList->setHeaderText(tr("To"));
ui->frec_toList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui->frec_toList->start();
ui->frec_messageEdit->setText(MessageComposer::recommendMessage());
}
void FriendRecommendDialog::showIt()
{
FriendRecommendDialog *dialog = instance();
dialog->load();
dialog->show();
dialog->raise();
dialog->activateWindow();
}
FriendRecommendDialog *FriendRecommendDialog::instance()
{
static FriendRecommendDialog *d = NULL ;
if(d == NULL)
d = new FriendRecommendDialog(NULL);
return d;
}
void FriendRecommendDialog::accept()
{
std::set<RsPeerId> recommendIds;
ui->frec_recommendList->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(recommendIds, false);
if (recommendIds.empty()) {
QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend for recommendation."), QMessageBox::Ok, QMessageBox::Ok);
return ;
}
std::set<RsPeerId> toIds;
ui->frec_toList->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(toIds, false);
if (toIds.empty()) {
QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend as recipient."), QMessageBox::Ok, QMessageBox::Ok);
return ;
}
std::set<RsPeerId>::iterator toId;
for (toId = toIds.begin(); toId != toIds.end(); ++toId) {
MessageComposer::recommendFriend(recommendIds, *toId, ui->frec_messageEdit->toHtml(), true);
}
QDialog::accept() ;
QMessageBox::information(NULL,tr("Recommendation messages sent!"),tr("A recommendation message was sent to each of the chosen friends!")) ;
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <QDialog>
#include "ui_FriendRecommendDialog.h"
class FriendRecommendDialog: public QDialog
{
public:
FriendRecommendDialog(QWidget *parent) ;
virtual ~FriendRecommendDialog() ;
static void showIt();
private:
static FriendRecommendDialog *instance();
virtual void accept() ;
void load();
Ui::FriendRecommendDialog *ui;
};

View File

@ -0,0 +1,118 @@
<?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>1398</width>
<height>774</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="FriendSelectionWidget" name="frec_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="frec_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="frec_label">
<property name="text">
<string>Message:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="frec_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>
<zorder>buttonBox</zorder>
<zorder>frec_label</zorder>
<zorder>frec_messageEdit</zorder>
<zorder>layoutWidget</zorder>
<zorder>frec_recommendList</zorder>
</widget>
<customwidgets>
<customwidget>
<class>FriendSelectionWidget</class>
<extends>QWidget</extends>
<header>gui/common/FriendSelectionWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FriendRecommendDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FriendRecommendDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -425,6 +425,7 @@ HEADERS += rshare.h \
gui/chat/ChatLobbyUserNotify.h \
gui/connect/ConfCertDialog.h \
gui/connect/PGPKeyDialog.h \
gui/connect/FriendRecommendDialog.h \
gui/msgs/MessageInterface.h \
gui/msgs/MessageComposer.h \
gui/msgs/MessageWindow.h \
@ -616,6 +617,7 @@ FORMS += gui/StartDialog.ui \
gui/connect/PGPKeyDialog.ui \
gui/connect/ConnectFriendWizard.ui \
gui/connect/ConnectProgressDialog.ui \
gui/connect/FriendRecommendDialog.ui \
gui/msgs/MessageComposer.ui \
gui/msgs/MessageWindow.ui\
gui/msgs/MessageWidget.ui\
@ -903,6 +905,7 @@ SOURCES += main.cpp \
gui/feeds/NewsFeedUserNotify.cpp \
gui/connect/ConnectFriendWizard.cpp \
gui/connect/ConnectProgressDialog.cpp \
gui/connect/FriendRecommendDialog.cpp \
gui/groups/CreateGroup.cpp \
gui/GetStartedDialog.cpp \
gui/statistics/BandwidthGraphWindow.cpp \