2011-12-04 22:03:54 +00:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Christopher Evi-Parker
|
|
|
|
*
|
|
|
|
* 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 "CreateLobbyDialog.h"
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
2012-10-10 10:51:53 +00:00
|
|
|
#include <QPushButton>
|
2011-12-04 22:03:54 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
2014-03-17 20:56:06 +00:00
|
|
|
#include <retroshare/rstypes.h>
|
2011-12-04 22:03:54 +00:00
|
|
|
|
|
|
|
#include "gui/common/PeerDefs.h"
|
2012-01-17 20:36:36 +00:00
|
|
|
#include "ChatDialog.h"
|
2015-03-06 21:13:23 +00:00
|
|
|
#include "gui/ChatLobbyWidget.h"
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2015-04-17 21:36:22 +00:00
|
|
|
CreateLobbyDialog::CreateLobbyDialog(const std::set<RsPeerId>& peer_list, int privacyLevel, QWidget *parent) :
|
2012-11-06 23:26:47 +00:00
|
|
|
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
2011-12-04 22:03:54 +00:00
|
|
|
{
|
|
|
|
ui = new Ui::CreateLobbyDialog() ;
|
2012-01-17 20:36:36 +00:00
|
|
|
ui->setupUi(this);
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2016-08-24 03:28:57 +02:00
|
|
|
ui->headerFrame->setHeaderImage(QPixmap(":/icons/png/chat-lobbies.png"));
|
2017-01-18 10:31:50 +01:00
|
|
|
ui->headerFrame->setHeaderText(tr("Create Chat Room"));
|
2012-08-24 10:49:08 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
RsGxsId default_identity ;
|
|
|
|
rsMsgs->getDefaultIdentityForChatLobby(default_identity) ;
|
2011-12-26 22:43:54 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
ui->idChooser_CB->loadIds(IDCHOOSER_ID_REQUIRED, default_identity);
|
|
|
|
|
2015-08-31 23:38:50 +02:00
|
|
|
#if QT_VERSION >= 0x040700
|
2017-01-18 10:31:50 +01:00
|
|
|
ui->lobbyName_LE->setPlaceholderText(tr("Put a sensible chat room name here"));
|
2015-08-31 23:38:50 +02:00
|
|
|
ui->lobbyTopic_LE->setPlaceholderText(tr("Set a descriptive topic here"));
|
|
|
|
#endif
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2012-10-10 10:51:53 +00:00
|
|
|
connect( ui->buttonBox, SIGNAL(accepted()), this, SLOT(createLobby()));
|
|
|
|
connect( ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
2012-01-17 20:36:36 +00:00
|
|
|
connect( ui->lobbyName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) );
|
2012-03-16 22:47:49 +00:00
|
|
|
connect( ui->lobbyTopic_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) );
|
2015-08-27 23:09:31 -04:00
|
|
|
connect( ui->idChooser_CB, SIGNAL( currentIndexChanged ( int ) ), this, SLOT( checkTextFields( ) ) );
|
|
|
|
connect( ui->pgp_signed_CB, SIGNAL( toggled ( bool ) ), this, SLOT( checkTextFields( ) ) );
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2012-01-27 00:32:17 +00:00
|
|
|
/* initialize key share list */
|
|
|
|
ui->keyShareList->setHeaderText(tr("Contacts:"));
|
|
|
|
ui->keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK);
|
2012-11-24 14:48:31 +00:00
|
|
|
ui->keyShareList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL);
|
2012-01-27 00:32:17 +00:00
|
|
|
ui->keyShareList->start();
|
2014-03-17 20:56:06 +00:00
|
|
|
ui->keyShareList->setSelectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(peer_list, false);
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2012-01-30 23:20:42 +00:00
|
|
|
if (privacyLevel) {
|
2015-03-06 21:13:23 +00:00
|
|
|
ui->security_CB->setCurrentIndex((privacyLevel == CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC) ? 0 : 1);
|
2012-01-30 23:20:42 +00:00
|
|
|
}
|
|
|
|
|
2012-01-27 00:32:17 +00:00
|
|
|
checkTextFields();
|
2012-08-27 21:48:00 +00:00
|
|
|
|
|
|
|
ui->lobbyName_LE->setFocus();
|
2011-12-04 22:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateLobbyDialog::~CreateLobbyDialog()
|
|
|
|
{
|
2012-01-17 20:36:36 +00:00
|
|
|
delete ui;
|
2011-12-04 22:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateLobbyDialog::changeEvent(QEvent *e)
|
|
|
|
{
|
2012-01-17 20:36:36 +00:00
|
|
|
QDialog::changeEvent(e);
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::LanguageChange:
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-12-04 22:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateLobbyDialog::checkTextFields()
|
|
|
|
{
|
2015-03-06 21:13:23 +00:00
|
|
|
RsGxsId id ;
|
|
|
|
|
|
|
|
switch(ui->idChooser_CB->getChosenId(id))
|
|
|
|
{
|
|
|
|
case GxsIdChooser::NoId:
|
|
|
|
case GxsIdChooser::None: ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false) ;
|
|
|
|
break ;
|
|
|
|
default:
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true) ;
|
|
|
|
break ;
|
|
|
|
}
|
2015-08-27 23:09:31 -04:00
|
|
|
|
2018-07-15 16:37:33 +02:00
|
|
|
RsIdentityDetails idd;
|
2015-08-27 23:09:31 -04:00
|
|
|
|
|
|
|
rsIdentity->getIdDetails(id,idd) ;
|
|
|
|
|
2015-11-19 21:14:32 -05:00
|
|
|
if( (!(idd.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN)) && ui->pgp_signed_CB->isChecked())
|
2015-08-27 23:09:31 -04:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false) ;
|
2011-12-04 22:03:54 +00:00
|
|
|
}
|
2012-01-17 20:36:36 +00:00
|
|
|
|
2011-12-04 22:03:54 +00:00
|
|
|
void CreateLobbyDialog::createLobby()
|
|
|
|
{
|
2015-04-17 21:36:22 +00:00
|
|
|
std::set<RsPeerId> shareList;
|
2014-03-17 20:56:06 +00:00
|
|
|
ui->keyShareList->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(shareList, false);
|
2012-01-27 00:32:17 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
// if (shareList.empty()) {
|
|
|
|
// QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend"), QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
// return;
|
|
|
|
// }
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
// create chat lobby !!
|
|
|
|
std::string lobby_name = ui->lobbyName_LE->text().toUtf8().constData() ;
|
|
|
|
std::string lobby_topic = ui->lobbyTopic_LE->text().toUtf8().constData() ;
|
2012-01-06 22:17:08 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
// set nick name !
|
|
|
|
RsGxsId gxs_id ;
|
|
|
|
switch(ui->idChooser_CB->getChosenId(gxs_id))
|
|
|
|
{
|
|
|
|
case GxsIdChooser::NoId:
|
|
|
|
case GxsIdChooser::None:
|
|
|
|
return ;
|
2015-08-26 23:35:36 -04:00
|
|
|
default: break ;
|
2015-03-06 21:13:23 +00:00
|
|
|
}
|
|
|
|
// add to group
|
2012-01-06 22:17:08 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
ChatLobbyFlags lobby_flags ;
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
if(ui->security_CB->currentIndex() == 0)
|
|
|
|
lobby_flags |= RS_CHAT_LOBBY_FLAGS_PUBLIC ;
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2015-08-26 23:35:36 -04:00
|
|
|
if(ui->pgp_signed_CB->isChecked())
|
|
|
|
lobby_flags |= RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ;
|
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name,gxs_id, lobby_topic, shareList, lobby_flags);
|
2011-12-26 22:43:54 +00:00
|
|
|
|
2017-01-18 10:31:50 +01:00
|
|
|
std::cerr << "gui: Created chat room " << std::hex << id << std::dec << std::endl ;
|
2011-12-26 22:43:54 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
// open chat window !!
|
2014-12-29 21:41:05 +00:00
|
|
|
ChatDialog::chatFriend(ChatId(id)) ;
|
2011-12-04 22:03:54 +00:00
|
|
|
|
2015-03-06 21:13:23 +00:00
|
|
|
close();
|
2011-12-04 22:03:54 +00:00
|
|
|
}
|