2011-12-04 17:03:54 -05: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 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"
|
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
|
|
|
|
2013-08-15 12:20:14 -04:00
|
|
|
ui->headerFrame->setHeaderImage(QPixmap(":/images/chat_64.png"));
|
2012-08-24 06:49:08 -04:00
|
|
|
ui->headerFrame->setHeaderText(tr("Create Chat Lobby"));
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
//#if QT_VERSION >= 0x040700
|
|
|
|
// ui->lobbyName_LE->setPlaceholderText(tr("Put a sensible lobby name here")) ;
|
|
|
|
// ui->nickName_LE->setPlaceholderText(tr("Your nickname for this lobby (Change default name in options->chat)")) ;
|
|
|
|
//#endif
|
|
|
|
// ui->nickName_LE->setText(QString::fromUtf8(default_nick.c_str())) ;
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2012-10-10 06:51:53 -04:00
|
|
|
connect( ui->buttonBox, SIGNAL(accepted()), this, SLOT(createLobby()));
|
|
|
|
connect( ui->buttonBox, SIGNAL(rejected()), 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:
|
|
|
|
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
|
|
|
|
|
|
|
RsIdentityDetails(idd) ;
|
|
|
|
|
|
|
|
rsIdentity->getIdDetails(id,idd) ;
|
|
|
|
|
|
|
|
if( (!idd.mPgpKnown) && ui->pgp_signed_CB->isChecked())
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->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
|
|
|
|
2015-07-12 18:00:10 -04:00
|
|
|
std::cerr << "gui: Created chat lobby " << 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
|
|
|
}
|