2018-07-20 13:48:29 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/chat/CreateLobbyDialog.cpp *
|
|
|
|
* *
|
|
|
|
* LibResAPI: API for local socket server *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2010, Christopher Evi-Parker <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2011-12-04 17:03:54 -05:00
|
|
|
|
|
|
|
#include "CreateLobbyDialog.h"
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
2012-10-10 06:51:53 -04:00
|
|
|
#include <QPushButton>
|
2011-12-04 17:03:54 -05:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
2014-03-17 16:56:06 -04:00
|
|
|
#include <retroshare/rstypes.h>
|
2011-12-04 17:03:54 -05:00
|
|
|
|
|
|
|
#include "gui/common/PeerDefs.h"
|
2012-01-17 15:36:36 -05:00
|
|
|
#include "ChatDialog.h"
|
2015-03-06 16:13:23 -05:00
|
|
|
#include "gui/ChatLobbyWidget.h"
|
2020-08-19 10:19:42 -04:00
|
|
|
#include "gui/common/FilesDefs.h"
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2015-04-17 17:36:22 -04:00
|
|
|
CreateLobbyDialog::CreateLobbyDialog(const std::set<RsPeerId>& peer_list, int privacyLevel, QWidget *parent) :
|
2012-11-06 18:26:47 -05:00
|
|
|
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
2011-12-04 17:03:54 -05:00
|
|
|
{
|
|
|
|
ui = new Ui::CreateLobbyDialog() ;
|
2012-01-17 15:36:36 -05:00
|
|
|
ui->setupUi(this);
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2020-08-19 10:19:42 -04:00
|
|
|
ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/chat-lobbies.png"));
|
2019-01-19 16:36:19 -05:00
|
|
|
ui->headerFrame->setHeaderText(tr("Create Chat Room"));
|
|
|
|
|
2015-03-06 16:13:23 -05:00
|
|
|
RsGxsId default_identity ;
|
|
|
|
rsMsgs->getDefaultIdentityForChatLobby(default_identity) ;
|
2011-12-26 17:43:54 -05:00
|
|
|
|
2015-03-06 16:13:23 -05:00
|
|
|
ui->idChooser_CB->loadIds(IDCHOOSER_ID_REQUIRED, default_identity);
|
|
|
|
|
2015-08-31 17:38:50 -04:00
|
|
|
#if QT_VERSION >= 0x040700
|
2017-01-18 04:31:50 -05:00
|
|
|
ui->lobbyName_LE->setPlaceholderText(tr("Put a sensible chat room name here"));
|
2015-08-31 17:38:50 -04:00
|
|
|
ui->lobbyTopic_LE->setPlaceholderText(tr("Set a descriptive topic here"));
|
|
|
|
#endif
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2020-10-12 15:46:06 -04:00
|
|
|
connect( ui->createButton, SIGNAL(clicked()), this, SLOT(createLobby()));
|
|
|
|
connect( ui->cancelButton, SIGNAL(clicked()), this, SLOT(close()));
|
2012-01-17 15:36:36 -05:00
|
|
|
connect( ui->lobbyName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) );
|
2012-03-16 18:47:49 -04: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 17:03:54 -05:00
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
/* initialize key share list */
|
|
|
|
ui->keyShareList->setHeaderText(tr("Contacts:"));
|
|
|
|
ui->keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK);
|
2012-11-24 09:48:31 -05:00
|
|
|
ui->keyShareList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL);
|
2012-01-26 19:32:17 -05:00
|
|
|
ui->keyShareList->start();
|
2014-03-17 16:56:06 -04:00
|
|
|
ui->keyShareList->setSelectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(peer_list, false);
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2012-01-30 18:20:42 -05:00
|
|
|
if (privacyLevel) {
|
2015-03-06 16:13:23 -05:00
|
|
|
ui->security_CB->setCurrentIndex((privacyLevel == CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC) ? 0 : 1);
|
2012-01-30 18:20:42 -05:00
|
|
|
}
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
checkTextFields();
|
2012-08-27 17:48:00 -04:00
|
|
|
|
|
|
|
ui->lobbyName_LE->setFocus();
|
2011-12-04 17:03:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateLobbyDialog::~CreateLobbyDialog()
|
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
delete ui;
|
2011-12-04 17:03:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateLobbyDialog::changeEvent(QEvent *e)
|
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
QDialog::changeEvent(e);
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::LanguageChange:
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-12-04 17:03:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateLobbyDialog::checkTextFields()
|
|
|
|
{
|
2015-03-06 16:13:23 -05:00
|
|
|
RsGxsId id ;
|
|
|
|
|
|
|
|
switch(ui->idChooser_CB->getChosenId(id))
|
|
|
|
{
|
|
|
|
case GxsIdChooser::NoId:
|
2020-10-12 15:46:06 -04:00
|
|
|
case GxsIdChooser::None: ui->createButton->setEnabled(false) ;
|
2015-03-06 16:13:23 -05:00
|
|
|
break ;
|
|
|
|
default:
|
2020-10-12 15:46:06 -04:00
|
|
|
ui->createButton->setEnabled(true) ;
|
2015-03-06 16:13:23 -05:00
|
|
|
break ;
|
|
|
|
}
|
2015-08-27 23:09:31 -04:00
|
|
|
|
2018-07-15 10:37:33 -04: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())
|
2020-10-12 15:46:06 -04:00
|
|
|
ui->createButton->setEnabled(false) ;
|
2011-12-04 17:03:54 -05:00
|
|
|
}
|
2012-01-17 15:36:36 -05:00
|
|
|
|
2011-12-04 17:03:54 -05:00
|
|
|
void CreateLobbyDialog::createLobby()
|
|
|
|
{
|
2015-04-17 17:36:22 -04:00
|
|
|
std::set<RsPeerId> shareList;
|
2014-03-17 16:56:06 -04:00
|
|
|
ui->keyShareList->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(shareList, false);
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2015-03-06 16:13:23 -05:00
|
|
|
// if (shareList.empty()) {
|
|
|
|
// QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend"), QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
// return;
|
|
|
|
// }
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2015-03-06 16:13:23 -05: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 17:17:08 -05:00
|
|
|
|
2015-03-06 16:13:23 -05: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 16:13:23 -05:00
|
|
|
}
|
|
|
|
// add to group
|
2012-01-06 17:17:08 -05:00
|
|
|
|
2015-03-06 16:13:23 -05:00
|
|
|
ChatLobbyFlags lobby_flags ;
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2015-03-06 16:13:23 -05:00
|
|
|
if(ui->security_CB->currentIndex() == 0)
|
|
|
|
lobby_flags |= RS_CHAT_LOBBY_FLAGS_PUBLIC ;
|
2011-12-04 17:03:54 -05: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 16:13:23 -05:00
|
|
|
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name,gxs_id, lobby_topic, shareList, lobby_flags);
|
2011-12-26 17:43:54 -05:00
|
|
|
|
2017-01-18 04:31:50 -05:00
|
|
|
std::cerr << "gui: Created chat room " << std::hex << id << std::dec << std::endl ;
|
2011-12-26 17:43:54 -05:00
|
|
|
|
2015-03-06 16:13:23 -05:00
|
|
|
// open chat window !!
|
2014-12-29 16:41:05 -05:00
|
|
|
ChatDialog::chatFriend(ChatId(id)) ;
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2015-03-06 16:13:23 -05:00
|
|
|
close();
|
2011-12-04 17:03:54 -05:00
|
|
|
}
|