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>
|
|
|
|
|
|
|
|
#include "gui/common/PeerDefs.h"
|
2012-01-17 15:36:36 -05:00
|
|
|
#include "ChatDialog.h"
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2012-01-30 18:20:42 -05:00
|
|
|
CreateLobbyDialog::CreateLobbyDialog(const std::list<std::string>& peer_list, int privacyLevel, QWidget *parent, Qt::WFlags flags) :
|
2012-01-26 19:32:17 -05:00
|
|
|
QDialog(parent, flags)
|
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
|
|
|
|
2012-08-24 06:49:08 -04:00
|
|
|
ui->headerFrame->setHeaderImage(QPixmap(":/images/user/agt_forum64.png"));
|
|
|
|
ui->headerFrame->setHeaderText(tr("Create Chat Lobby"));
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
std::string default_nick ;
|
|
|
|
rsMsgs->getDefaultNickNameForChatLobby(default_nick) ;
|
2011-12-26 17:43:54 -05:00
|
|
|
|
2011-12-27 16:06:43 -05:00
|
|
|
#if QT_VERSION >= 0x040700
|
2012-01-17 15:36:36 -05:00
|
|
|
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)")) ;
|
2011-12-27 16:06:43 -05:00
|
|
|
#endif
|
2012-02-03 08:29:16 -05:00
|
|
|
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( ) ) );
|
2012-01-17 15:36:36 -05:00
|
|
|
connect( ui->nickName_LE, SIGNAL( textChanged ( QString ) ), 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);
|
|
|
|
ui->keyShareList->start();
|
|
|
|
ui->keyShareList->setSelectedSslIds(peer_list, false);
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2012-01-30 18:20:42 -05:00
|
|
|
if (privacyLevel) {
|
|
|
|
ui->security_CB->setCurrentIndex((privacyLevel == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC) ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
if(ui->lobbyName_LE->text() == "" || ui->nickName_LE->text() == "")
|
2012-10-10 06:51:53 -04:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false) ;
|
2011-12-04 17:03:54 -05:00
|
|
|
else
|
2012-10-10 06:51:53 -04:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true) ;
|
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()
|
|
|
|
{
|
2012-01-26 19:32:17 -05:00
|
|
|
std::list<std::string> shareList;
|
|
|
|
ui->keyShareList->selectedSslIds(shareList, false);
|
|
|
|
|
2012-03-16 18:47:49 -04: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
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
// create chat lobby !!
|
|
|
|
std::string lobby_name = ui->lobbyName_LE->text().toUtf8().constData() ;
|
2012-03-16 18:47:49 -04:00
|
|
|
std::string lobby_topic = ui->lobbyTopic_LE->text().toUtf8().constData() ;
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
// add to group
|
2012-01-06 17:17:08 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
int lobby_privacy_type = (ui->security_CB->currentIndex() == 0)?RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC:RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE ;
|
2012-01-06 17:17:08 -05:00
|
|
|
|
2012-03-16 18:47:49 -04:00
|
|
|
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, lobby_topic, shareList, lobby_privacy_type);
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
std::cerr << "gui: Created chat lobby " << std::hex << id << std::endl ;
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
// set nick name !
|
2011-12-26 17:43:54 -05:00
|
|
|
|
2012-02-03 08:29:16 -05:00
|
|
|
rsMsgs->setNickNameForChatLobby(id,ui->nickName_LE->text().toUtf8().constData()) ;
|
2011-12-26 17:43:54 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
// open chat window !!
|
|
|
|
std::string vpid ;
|
|
|
|
|
|
|
|
if(rsMsgs->getVirtualPeerId(id,vpid))
|
|
|
|
ChatDialog::chatFriend(vpid) ;
|
2011-12-04 17:03:54 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
close();
|
2011-12-04 17:03:54 -05:00
|
|
|
}
|