2011-11-27 16:04:10 -05:00
/****************************************************************
*
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2011 , csoler
*
* 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 <QMessageBox>
2012-01-28 10:11:58 -05:00
# include <QInputDialog>
2012-11-14 09:39:08 -05:00
# include <QMenu>
2011-11-27 16:04:10 -05:00
# include "ChatLobbyDialog.h"
2013-02-22 16:42:27 -05:00
# include "gui/ChatLobbyWidget.h"
2012-01-18 15:02:19 -05:00
# include "ChatTabWidget.h"
2012-01-17 15:36:36 -05:00
# include "gui/settings/rsharesettings.h"
# include "gui/settings/RsharePeerSettings.h"
2012-03-30 19:02:52 -04:00
# include "gui/MainWindow.h"
2012-01-18 15:02:19 -05:00
# include "gui/FriendsDialog.h"
2012-05-11 16:53:27 -04:00
# include <gui/common/html.h>
2012-11-14 09:39:08 -05:00
# include "gui/common/RSTreeWidgetItem.h"
2013-02-22 16:42:27 -05:00
# include "gui/common/FriendSelectionDialog.h"
2013-07-01 16:35:07 -04:00
# include "util/HandleRichText.h"
2012-01-17 15:36:36 -05:00
# include <retroshare/rsnotify.h>
# include <time.h>
2011-11-27 16:04:10 -05:00
2012-11-15 19:53:13 -05:00
# define COLUMN_ICON 0
# define COLUMN_NAME 1
2013-08-24 11:07:31 -04:00
# define COLUMN_ACTIVITY 2
# define COLUMN_COUNT 3
2012-11-15 19:53:13 -05:00
2011-11-27 16:04:10 -05:00
/** Default constructor */
2013-10-18 17:10:33 -04:00
ChatLobbyDialog : : ChatLobbyDialog ( const ChatLobbyId & lid , QWidget * parent , Qt : : WindowFlags flags )
2012-01-17 15:36:36 -05:00
: ChatDialog ( parent , flags ) , lobbyId ( lid )
2011-11-27 16:04:10 -05:00
{
2012-01-17 15:36:36 -05:00
/* Invoke Qt Designer generated QObject setup routine */
ui . setupUi ( this ) ;
connect ( ui . participantsFrameButton , SIGNAL ( toggled ( bool ) ) , this , SLOT ( showParticipantsFrame ( bool ) ) ) ;
2012-01-28 10:11:58 -05:00
connect ( ui . actionChangeNickname , SIGNAL ( triggered ( ) ) , this , SLOT ( changeNickname ( ) ) ) ;
2013-03-19 17:37:38 -04:00
connect ( ui . participantsList , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( participantsTreeWidgetCustomPopupMenu ( QPoint ) ) ) ;
2012-11-15 19:53:13 -05:00
connect ( ui . participantsList , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( participantsTreeWidgetDoubleClicked ( QTreeWidgetItem * , int ) ) ) ;
2012-11-14 09:39:08 -05:00
2012-11-15 19:53:13 -05:00
ui . participantsList - > setColumnCount ( COLUMN_COUNT ) ;
ui . participantsList - > setColumnWidth ( COLUMN_ICON , 20 ) ;
2013-08-24 11:07:31 -04:00
ui . participantsList - > setColumnHidden ( COLUMN_ACTIVITY , true ) ;
2012-02-09 16:24:51 -05:00
2012-11-14 09:39:08 -05:00
muteAct = new QAction ( QIcon ( ) , tr ( " Mute participant " ) , this ) ;
connect ( muteAct , SIGNAL ( triggered ( ) ) , this , SLOT ( changePartipationState ( ) ) ) ;
2013-02-22 16:42:27 -05:00
// Add a button to invite friends.
//
2013-10-04 08:13:09 -04:00
inviteFriendsButton = new QToolButton ;
2013-02-22 16:42:27 -05:00
inviteFriendsButton - > setMinimumSize ( QSize ( 28 , 28 ) ) ;
inviteFriendsButton - > setMaximumSize ( QSize ( 28 , 28 ) ) ;
inviteFriendsButton - > setText ( QString ( ) ) ;
2013-10-04 08:13:09 -04:00
inviteFriendsButton - > setAutoRaise ( true ) ;
2013-02-22 16:42:27 -05:00
inviteFriendsButton - > setToolTip ( tr ( " Invite friends to this lobby " ) ) ;
2013-02-24 17:44:14 -05:00
{
2013-02-22 16:42:27 -05:00
QIcon icon ;
icon . addPixmap ( QPixmap ( " :/images/edit_add24.png " ) ) ;
inviteFriendsButton - > setIcon ( icon ) ;
inviteFriendsButton - > setIconSize ( QSize ( 22 , 22 ) ) ;
2013-02-24 17:44:14 -05:00
}
2013-02-22 16:42:27 -05:00
connect ( inviteFriendsButton , SIGNAL ( clicked ( ) ) , this , SLOT ( inviteFriends ( ) ) ) ;
2013-04-23 18:43:19 -04:00
getChatWidget ( ) - > addChatBarWidget ( inviteFriendsButton ) ;
2013-02-24 17:44:14 -05:00
2013-10-04 08:13:09 -04:00
unsubscribeButton = new QToolButton ;
2013-02-24 17:44:14 -05:00
unsubscribeButton - > setMinimumSize ( QSize ( 28 , 28 ) ) ;
unsubscribeButton - > setMaximumSize ( QSize ( 28 , 28 ) ) ;
unsubscribeButton - > setText ( QString ( ) ) ;
2013-10-04 08:13:09 -04:00
unsubscribeButton - > setAutoRaise ( true ) ;
2013-02-24 17:44:14 -05:00
unsubscribeButton - > setToolTip ( tr ( " Leave this lobby (Unsubscribe) " ) ) ;
{
QIcon icon ;
2013-08-15 12:20:14 -04:00
icon . addPixmap ( QPixmap ( " :/images/exit_32.png " ) ) ;
2013-02-24 17:44:14 -05:00
unsubscribeButton - > setIcon ( icon ) ;
unsubscribeButton - > setIconSize ( QSize ( 22 , 22 ) ) ;
}
connect ( unsubscribeButton , SIGNAL ( clicked ( ) ) , this , SLOT ( leaveLobby ( ) ) ) ;
2013-04-23 18:43:19 -04:00
getChatWidget ( ) - > addChatBarWidget ( unsubscribeButton ) ;
2013-02-22 16:42:27 -05:00
}
2013-02-24 17:44:14 -05:00
void ChatLobbyDialog : : leaveLobby ( )
{
emit lobbyLeave ( id ( ) ) ;
}
2013-02-22 16:42:27 -05:00
void ChatLobbyDialog : : inviteFriends ( )
{
std : : cerr < < " Inviting friends " < < std : : endl ;
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > ids = FriendSelectionDialog : : selectFriends_SSL ( NULL , tr ( " Invite friends " ) , tr ( " Select friends to invite: " ) ) ;
2013-02-22 16:42:27 -05:00
std : : cerr < < " Inviting these friends: " < < std : : endl ;
ChatLobbyId lobby_id ;
if ( ! rsMsgs - > isLobbyId ( getPeerId ( ) , lobby_id ) )
return ;
2014-03-17 16:56:06 -04:00
for ( std : : list < RsPeerId > : : const_iterator it ( ids . begin ( ) ) ; it ! = ids . end ( ) ; + + it )
2013-02-22 16:42:27 -05:00
{
std : : cerr < < " " < < * it < < std : : endl ;
rsMsgs - > invitePeerToLobby ( lobby_id , * it ) ;
}
2012-11-14 09:39:08 -05:00
}
2013-03-19 17:37:38 -04:00
void ChatLobbyDialog : : participantsTreeWidgetCustomPopupMenu ( QPoint )
2012-11-14 09:39:08 -05:00
{
2012-11-15 19:53:13 -05:00
QList < QTreeWidgetItem * > selectedItems = ui . participantsList - > selectedItems ( ) ;
2012-11-14 09:39:08 -05:00
QMenu contextMnu ( this ) ;
contextMnu . addAction ( muteAct ) ;
muteAct - > setCheckable ( true ) ;
2012-11-15 19:53:13 -05:00
muteAct - > setEnabled ( false ) ;
2013-03-19 17:37:38 -04:00
muteAct - > setChecked ( false ) ;
2012-11-15 19:53:13 -05:00
if ( selectedItems . size ( ) ) {
2013-08-24 11:07:31 -04:00
std : : string nickName ;
rsMsgs - > getNickNameForChatLobby ( lobbyId , nickName ) ;
if ( selectedItems . count ( ) > 1 | | ( selectedItems . at ( 0 ) - > text ( COLUMN_NAME ) . toStdString ( ) ! = nickName ) )
{
2012-11-15 19:53:13 -05:00
muteAct - > setEnabled ( true ) ;
QList < QTreeWidgetItem * > : : iterator item ;
for ( item = selectedItems . begin ( ) ; item ! = selectedItems . end ( ) ; + + item ) {
if ( isParticipantMuted ( ( * item ) - > text ( COLUMN_NAME ) ) ) {
muteAct - > setChecked ( true ) ;
break ;
}
}
2012-11-14 09:39:08 -05:00
}
2013-08-24 11:07:31 -04:00
}
2012-11-14 09:39:08 -05:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2012-01-17 15:36:36 -05:00
}
2014-03-17 16:56:06 -04:00
void ChatLobbyDialog : : init ( const RsPeerId & peerId , const QString & title )
2012-01-17 15:36:36 -05:00
{
2012-03-20 19:05:17 -04:00
std : : list < ChatLobbyInfo > lobbies ;
rsMsgs - > getChatLobbyList ( lobbies ) ;
std : : list < ChatLobbyInfo > : : const_iterator lobbyIt ;
for ( lobbyIt = lobbies . begin ( ) ; lobbyIt ! = lobbies . end ( ) ; + + lobbyIt ) {
2014-03-17 16:56:06 -04:00
RsPeerId vpid ;
2012-03-20 19:05:17 -04:00
if ( rsMsgs - > getVirtualPeerId ( lobbyIt - > lobby_id , vpid ) ) {
if ( vpid = = peerId ) {
2013-07-01 16:35:07 -04:00
QString msg = tr ( " Welcome to lobby %1 " ) . arg ( RsHtml : : plainText ( lobbyIt - > lobby_name ) ) ;
2013-06-30 09:58:17 -04:00
_lobby_name = QString : : fromUtf8 ( lobbyIt - > lobby_name . c_str ( ) ) ;
2012-03-20 19:05:17 -04:00
if ( ! lobbyIt - > lobby_topic . empty ( ) ) {
2013-07-01 16:35:07 -04:00
msg + = " \n " + tr ( " Topic: %1 " ) . arg ( RsHtml : : plainText ( lobbyIt - > lobby_topic ) ) ;
2012-03-20 19:05:17 -04:00
}
ui . chatWidget - > setWelcomeMessage ( msg ) ;
break ;
}
}
}
2012-01-17 19:32:15 -05:00
ChatDialog : : init ( peerId , title ) ;
std : : string nickName ;
rsMsgs - > getNickNameForChatLobby ( lobbyId , nickName ) ;
ui . chatWidget - > setName ( QString : : fromUtf8 ( nickName . c_str ( ) ) ) ;
2012-01-17 15:36:36 -05:00
2012-01-28 10:11:58 -05:00
ui . chatWidget - > addToolsAction ( ui . actionChangeNickname ) ;
2012-11-11 16:17:00 -05:00
ui . chatWidget - > setDefaultExtraFileFlags ( RS_FILE_REQ_ANONYMOUS_ROUTING ) ;
2012-01-28 10:11:58 -05:00
2012-01-17 15:36:36 -05:00
lastUpdateListTime = 0 ;
/* Hide or show the participants frames */
showParticipantsFrame ( PeerSettings - > getShowParticipantsFrame ( peerId ) ) ;
// add to window
2013-02-22 16:42:27 -05:00
2013-02-24 17:44:14 -05:00
dynamic_cast < ChatLobbyWidget * > ( MainWindow : : getPage ( MainWindow : : ChatLobby ) ) - > addChatPage ( this ) ;
2012-01-17 15:36:36 -05:00
2012-05-05 10:22:21 -04:00
/** List of muted Participants */
mutedParticipants = new QStringList ;
2012-01-17 15:36:36 -05:00
// load settings
processSettings ( true ) ;
2011-11-27 16:04:10 -05:00
}
/** Destructor. */
ChatLobbyDialog : : ~ ChatLobbyDialog ( )
{
// announce leaving of lobby
2012-01-11 19:13:25 -05:00
2012-01-06 17:17:08 -05:00
// check that the lobby still exists.
2012-01-11 19:13:25 -05:00
ChatLobbyId lid ;
2012-01-17 15:36:36 -05:00
if ( rsMsgs - > isLobbyId ( getPeerId ( ) , lid ) ) {
rsMsgs - > unsubscribeChatLobby ( lobbyId ) ;
2012-01-11 19:13:25 -05:00
}
2012-01-17 15:36:36 -05:00
// save settings
processSettings ( false ) ;
2012-01-11 19:13:25 -05:00
}
2012-01-06 17:17:08 -05:00
2012-01-17 15:36:36 -05:00
ChatWidget * ChatLobbyDialog : : getChatWidget ( )
2012-01-11 19:13:25 -05:00
{
2012-01-17 15:36:36 -05:00
return ui . chatWidget ;
}
2012-10-27 11:59:12 -04:00
bool ChatLobbyDialog : : notifyBlink ( )
{
return ( Settings - > getChatLobbyFlags ( ) & RS_CHATLOBBY_BLINK ) ;
}
2012-01-17 15:36:36 -05:00
void ChatLobbyDialog : : processSettings ( bool load )
{
Settings - > beginGroup ( QString ( " ChatLobbyDialog " ) ) ;
if ( load ) {
// load settings
} else {
// save settings
2012-01-11 19:13:25 -05:00
}
2012-01-17 15:36:36 -05:00
Settings - > endGroup ( ) ;
2011-12-26 17:43:54 -05:00
}
2012-05-06 18:19:59 -04:00
/**
* Change your Nickname
*
* - send a Message to all Members = > later : send hidden message to clients , so they can actualize there mutedParticipants list
*/
2012-01-28 10:11:58 -05:00
void ChatLobbyDialog : : setNickname ( const QString & nickname )
2011-11-27 16:04:10 -05:00
{
2012-01-28 10:11:58 -05:00
rsMsgs - > setNickNameForChatLobby ( lobbyId , nickname . toUtf8 ( ) . constData ( ) ) ;
2012-05-23 18:33:45 -04:00
// get new nick name
std : : string newNickname ;
if ( rsMsgs - > getNickNameForChatLobby ( lobbyId , newNickname ) ) {
ui . chatWidget - > setName ( QString : : fromUtf8 ( newNickname . c_str ( ) ) ) ;
}
2012-01-28 10:11:58 -05:00
}
2012-05-06 18:19:59 -04:00
/**
* Dialog : Change your Nickname in the ChatLobby
*/
2012-01-28 10:11:58 -05:00
void ChatLobbyDialog : : changeNickname ( )
{
QInputDialog dialog ;
dialog . setWindowTitle ( tr ( " Change nick name " ) ) ;
dialog . setLabelText ( tr ( " Please enter your new nick name " ) ) ;
std : : string nickName ;
rsMsgs - > getNickNameForChatLobby ( lobbyId , nickName ) ;
dialog . setTextValue ( QString : : fromUtf8 ( nickName . c_str ( ) ) ) ;
2012-05-23 18:33:45 -04:00
if ( dialog . exec ( ) = = QDialog : : Accepted & & ! dialog . textValue ( ) . isEmpty ( ) ) {
2012-01-28 10:11:58 -05:00
setNickname ( dialog . textValue ( ) ) ;
}
2011-11-27 16:04:10 -05:00
}
2012-05-05 10:22:21 -04:00
/**
* We get a new Message from a chat participant
*
* - Ignore Messages from muted chat participants
*/
2011-12-28 04:15:28 -05:00
void ChatLobbyDialog : : addIncomingChatMsg ( const ChatInfo & info )
{
QDateTime sendTime = QDateTime : : fromTime_t ( info . sendTime ) ;
QDateTime recvTime = QDateTime : : fromTime_t ( info . recvTime ) ;
2013-10-03 17:41:34 -04:00
QString message = QString : : fromUtf8 ( info . msg . c_str ( ) ) ;
2012-01-11 19:13:25 -05:00
QString name = QString : : fromUtf8 ( info . peer_nickname . c_str ( ) ) ;
2014-03-17 16:56:06 -04:00
QString rsid = QString : : fromUtf8 ( info . rsid . toStdString ( ) . c_str ( ) ) ;
2011-12-28 04:15:28 -05:00
2013-10-17 14:45:59 -04:00
//std::cerr << "message from rsid " << info.rsid.c_str() << std::endl;
2012-05-06 18:19:59 -04:00
2013-03-19 17:37:38 -04:00
if ( ! isParticipantMuted ( name ) ) {
2014-01-01 19:56:46 -05:00
ui . chatWidget - > addChatMsg ( true , name , sendTime , recvTime , message , ChatWidget : : MSGTYPE_NORMAL ) ;
2013-03-19 17:37:38 -04:00
emit messageReceived ( id ( ) ) ;
}
2012-05-05 10:22:21 -04:00
2012-07-30 09:27:40 -04:00
// This is a trick to translate HTML into text.
QTextEdit editor ;
editor . setHtml ( message ) ;
QString notifyMsg = name + " : " + editor . toPlainText ( ) ;
if ( notifyMsg . length ( ) > 30 )
MainWindow : : displayLobbySystrayMsg ( tr ( " Lobby chat " ) + " : " + _lobby_name , notifyMsg . left ( 30 ) + QString ( " ... " ) ) ;
else
MainWindow : : displayLobbySystrayMsg ( tr ( " Lobby chat " ) + " : " + _lobby_name , notifyMsg ) ;
2011-12-29 09:19:53 -05:00
// also update peer list.
2012-01-17 15:36:36 -05:00
time_t now = time ( NULL ) ;
2011-12-29 09:19:53 -05:00
2013-08-24 11:07:31 -04:00
QList < QTreeWidgetItem * > qlFoundParticipants = ui . participantsList - > findItems ( name , Qt : : MatchExactly , COLUMN_NAME ) ;
if ( qlFoundParticipants . count ( ) ! = 0 ) qlFoundParticipants . at ( 0 ) - > setText ( COLUMN_ACTIVITY , QString : : number ( now ) ) ;
2012-01-17 15:36:36 -05:00
if ( now > lastUpdateListTime ) {
lastUpdateListTime = now ;
updateParticipantsList ( ) ;
2011-12-29 09:19:53 -05:00
}
}
2012-05-05 10:22:21 -04:00
/**
2012-11-14 09:39:08 -05:00
* Regenerate the QTreeWidget participant list of a Chat Lobby
2012-05-05 10:22:21 -04:00
*
2013-03-19 17:37:38 -04:00
* Show yellow icon for muted Participants
2012-05-05 10:22:21 -04:00
*/
2012-01-17 15:36:36 -05:00
void ChatLobbyDialog : : updateParticipantsList ( )
2011-12-29 09:19:53 -05:00
{
2013-08-24 11:07:31 -04:00
std : : list < ChatLobbyInfo > lInfos ;
rsMsgs - > getChatLobbyList ( lInfos ) ;
2012-11-15 19:53:13 -05:00
2013-08-24 11:07:31 -04:00
std : : list < ChatLobbyInfo > : : const_iterator it ( lInfos . begin ( ) ) ;
2012-11-15 19:53:13 -05:00
2013-08-24 11:07:31 -04:00
// Set it to the current ChatLobby
2014-01-28 02:57:58 -05:00
for ( ; it ! = lInfos . end ( ) & & ( * it ) . lobby_id ! = lobbyId ; + + it ) ;
2011-12-29 09:19:53 -05:00
2013-08-24 11:07:31 -04:00
if ( it ! = lInfos . end ( ) ) {
ChatLobbyInfo cliInfo = ( * it ) ;
2013-08-25 16:13:51 -04:00
QList < QTreeWidgetItem * > qlOldParticipants = ui . participantsList - > findItems ( " * " , Qt : : MatchWildcard , COLUMN_NAME ) ;
2013-08-24 11:07:31 -04:00
foreach ( QTreeWidgetItem * qtwiCur , qlOldParticipants ) {
QString qsOldParticipant = qtwiCur - > text ( COLUMN_NAME ) ;
2013-08-25 16:13:51 -04:00
QByteArray qbaPart = qsOldParticipant . toUtf8 ( ) ;
std : : string strTemp = std : : string ( qbaPart . begin ( ) , qbaPart . end ( ) ) ;
2013-08-24 11:07:31 -04:00
2013-08-25 16:13:51 -04:00
std : : map < std : : string , time_t > : : iterator itFound ( cliInfo . nick_names . find ( strTemp ) ) ;
2013-08-24 11:07:31 -04:00
if ( itFound = = cliInfo . nick_names . end ( ) )
{
//Old Participant go out, remove it
2013-08-25 16:13:51 -04:00
int index = ui . participantsList - > indexOfTopLevelItem ( qtwiCur ) ;
delete ui . participantsList - > takeTopLevelItem ( index ) ;
2013-08-24 11:07:31 -04:00
}
}
2011-12-29 09:19:53 -05:00
2012-05-24 15:26:43 -04:00
2011-12-29 09:19:53 -05:00
2012-01-14 16:09:04 -05:00
for ( std : : map < std : : string , time_t > : : const_iterator it2 ( ( * it ) . nick_names . begin ( ) ) ; it2 ! = ( * it ) . nick_names . end ( ) ; + + it2 ) {
2012-05-05 10:22:21 -04:00
QString participant = QString : : fromUtf8 ( ( it2 - > first ) . c_str ( ) ) ;
2013-08-24 11:07:31 -04:00
QList < QTreeWidgetItem * > qlFoundParticipants = ui . participantsList - > findItems ( participant , Qt : : MatchExactly , COLUMN_NAME ) ;
QTreeWidgetItem * widgetitem ;
2012-05-05 10:22:21 -04:00
2013-08-24 11:07:31 -04:00
if ( qlFoundParticipants . count ( ) = = 0 )
{
2012-05-05 10:22:21 -04:00
// TE: Add Wigdet to participantsList with Checkbox, to mute Participant
2013-08-24 11:07:31 -04:00
widgetitem = new RSTreeWidgetItem ;
widgetitem - > setText ( COLUMN_NAME , participant ) ;
widgetitem - > setText ( COLUMN_ACTIVITY , QString : : number ( time ( NULL ) ) ) ;
ui . participantsList - > addTopLevelItem ( widgetitem ) ;
} else { widgetitem = qlFoundParticipants . at ( 0 ) ; }
2012-05-05 10:22:21 -04:00
if ( isParticipantMuted ( participant ) ) {
2013-08-24 11:07:31 -04:00
widgetitem - > setIcon ( COLUMN_ICON , QIcon ( " :/images/redled.png " ) ) ;
widgetitem - > setTextColor ( COLUMN_NAME , QColor ( 255 , 0 , 0 ) ) ;
2012-05-05 10:22:21 -04:00
} else {
2012-11-15 19:53:13 -05:00
widgetitem - > setIcon ( COLUMN_ICON , QIcon ( " :/images/greenled.png " ) ) ;
2013-08-24 11:07:31 -04:00
widgetitem - > setTextColor ( COLUMN_NAME , ui . participantsList - > palette ( ) . color ( QPalette : : Active , QPalette : : Text ) ) ;
2012-05-05 10:22:21 -04:00
}
2012-11-15 19:53:13 -05:00
2013-08-24 11:07:31 -04:00
time_t tLastAct = widgetitem - > text ( COLUMN_ACTIVITY ) . toInt ( ) ;
time_t now = time ( NULL ) ;
2014-05-29 11:19:19 -04:00
if ( tLastAct < now - 60 * 30 )
widgetitem - > setIcon ( COLUMN_ICON , QIcon ( isParticipantMuted ( participant ) ? " :/images/ledoff1.png " : " :/images/grayled.png " ) ) ;
2012-11-14 09:39:08 -05:00
2013-08-24 11:07:31 -04:00
std : : string nickName ;
rsMsgs - > getNickNameForChatLobby ( lobbyId , nickName ) ;
if ( participant . toStdString ( ) = = nickName ) widgetitem - > setIcon ( COLUMN_ICON , QIcon ( " :/images/yellowled.png " ) ) ;
QTime qtLastAct = QTime ( 0 , 0 , 0 ) . addSecs ( now - tLastAct ) ;
widgetitem - > setToolTip ( COLUMN_NAME , tr ( " Right click to mute/unmute participants<br/>Double click to address this person<br/> " )
+ tr ( " This participant is not active since: " )
+ qtLastAct . toString ( )
+ tr ( " seconds " )
) ;
2012-01-11 19:13:25 -05:00
}
}
2012-05-24 15:26:43 -04:00
ui . participantsList - > setSortingEnabled ( true ) ;
2012-11-15 19:53:13 -05:00
ui . participantsList - > sortItems ( COLUMN_NAME , Qt : : AscendingOrder ) ;
2011-12-28 04:15:28 -05:00
}
2012-05-05 10:22:21 -04:00
/**
2012-11-14 09:39:08 -05:00
* Called when a Participant in QTree get Clicked / Changed
2012-05-05 10:22:21 -04:00
*
* Check if the Checkbox altered and Mute User
*
2012-05-06 18:19:59 -04:00
* @ todo auf rsid
*
2012-11-14 09:39:08 -05:00
* @ param QTreeWidgetItem Participant to check
2012-05-05 10:22:21 -04:00
*/
2012-11-14 09:39:08 -05:00
void ChatLobbyDialog : : changePartipationState ( )
2012-05-05 10:22:21 -04:00
{
2012-11-15 19:53:13 -05:00
QList < QTreeWidgetItem * > selectedItems = ui . participantsList - > selectedItems ( ) ;
if ( selectedItems . size ( ) = = 0 ) {
2012-11-14 09:39:08 -05:00
return ;
2012-11-15 19:53:13 -05:00
}
2012-11-14 09:39:08 -05:00
2012-11-15 19:53:13 -05:00
QList < QTreeWidgetItem * > : : iterator item ;
for ( item = selectedItems . begin ( ) ; item ! = selectedItems . end ( ) ; + + item ) {
QString nickname = ( * item ) - > text ( COLUMN_NAME ) ;
2012-05-05 10:22:21 -04:00
2012-11-15 19:53:13 -05:00
std : : cerr < < " check Partipation status for ' " < < nickname . toUtf8 ( ) . constData ( ) < < std : : endl ;
if ( muteAct - > isChecked ( ) ) {
muteParticipant ( nickname ) ;
} else {
unMuteParticipant ( nickname ) ;
}
}
mutedParticipants - > removeDuplicates ( ) ;
updateParticipantsList ( ) ;
}
void ChatLobbyDialog : : participantsTreeWidgetDoubleClicked ( QTreeWidgetItem * item , int column )
{
if ( ! item ) {
return ;
}
2013-02-22 16:42:27 -05:00
if ( column = = COLUMN_NAME )
{
2013-07-01 16:35:07 -04:00
getChatWidget ( ) - > pasteText ( " @ " + RsHtml : : plainText ( item - > text ( COLUMN_NAME ) ) ) ;
2013-02-22 16:42:27 -05:00
return ;
2012-05-05 10:22:21 -04:00
}
2012-11-15 19:53:13 -05:00
2013-02-22 16:42:27 -05:00
// if (column == COLUMN_ICON) {
// return;
// }
//
// QString nickname = item->text(COLUMN_NAME);
// if (isParticipantMuted(nickname)) {
// unMuteParticipant(nickname);
// } else {
// muteParticipant(nickname);
// }
//
// mutedParticipants->removeDuplicates();
//
// updateParticipantsList();
2012-05-05 10:22:21 -04:00
}
2012-05-11 16:53:27 -04:00
void ChatLobbyDialog : : muteParticipant ( const QString & nickname ) {
std : : cerr < < " Mute " < < std : : endl ;
2013-08-24 11:07:31 -04:00
std : : string myNickName ;
rsMsgs - > getNickNameForChatLobby ( lobbyId , myNickName ) ;
if ( nickname . toStdString ( ) ! = myNickName )
2012-05-11 16:53:27 -04:00
mutedParticipants - > append ( nickname ) ;
}
void ChatLobbyDialog : : unMuteParticipant ( const QString & nickname ) {
std : : cerr < < " UnMute " < < std : : endl ;
mutedParticipants - > removeAll ( nickname ) ;
}
/**
* Is this nickName already known in the lobby
*/
bool ChatLobbyDialog : : isNicknameInLobby ( const QString & nickname ) {
std : : list < ChatLobbyInfo > linfos ;
rsMsgs - > getChatLobbyList ( linfos ) ;
std : : list < ChatLobbyInfo > : : const_iterator it ( linfos . begin ( ) ) ;
// Set it to the current ChatLobby
2014-01-28 02:57:58 -05:00
for ( ; it ! = linfos . end ( ) & & ( * it ) . lobby_id ! = lobbyId ; + + it ) ;
2012-05-11 16:53:27 -04:00
if ( it ! = linfos . end ( ) ) {
for ( std : : map < std : : string , time_t > : : const_iterator it2 ( ( * it ) . nick_names . begin ( ) ) ; it2 ! = ( * it ) . nick_names . end ( ) ; + + it2 ) {
QString participant = QString : : fromUtf8 ( ( it2 - > first ) . c_str ( ) ) ;
if ( participant = = nickname ) {
return true ;
}
}
}
return false ;
}
2012-05-05 10:22:21 -04:00
/**
* Should Messages from this Nickname be muted ?
*
2012-05-06 18:19:59 -04:00
* At the moment it is not possible to 100 % know which peer sendet the message , and only
* the nickname is available . So this couldn ' t work for 100 % . So , for example , if a peer
* change his name to the name of a other peer , we couldn ' t block him . A real implementation
* will be possible if we transfer a temporary Session ID from the sending Retroshare client
* version 0.6
*
2012-05-05 10:22:21 -04:00
* @ param QString nickname to check
*/
2012-05-11 16:53:27 -04:00
bool ChatLobbyDialog : : isParticipantMuted ( const QString & participant )
2012-05-05 10:22:21 -04:00
{
2012-05-11 16:53:27 -04:00
// nickname in Mute list
return mutedParticipants - > contains ( participant ) ;
2012-05-05 10:22:21 -04:00
}
2012-01-11 19:13:25 -05:00
void ChatLobbyDialog : : displayLobbyEvent ( int event_type , const QString & nickname , const QString & str )
2012-01-06 17:17:08 -05:00
{
2013-08-24 11:07:31 -04:00
QString qsParticipant = " " ;
2012-01-17 15:36:36 -05:00
switch ( event_type ) {
case RS_CHAT_LOBBY_EVENT_PEER_LEFT :
2013-08-24 11:07:31 -04:00
qsParticipant = str ;
2014-01-01 19:56:46 -05:00
ui . chatWidget - > addChatMsg ( true , tr ( " Lobby management " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( ) , tr ( " %1 has left the lobby. " ) . arg ( RsHtml : : plainText ( str ) ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
2013-02-27 17:17:49 -05:00
emit peerLeft ( id ( ) ) ;
2012-01-17 15:36:36 -05:00
break ;
case RS_CHAT_LOBBY_EVENT_PEER_JOINED :
2013-08-24 11:07:31 -04:00
qsParticipant = str ;
2014-01-01 19:56:46 -05:00
ui . chatWidget - > addChatMsg ( true , tr ( " Lobby management " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( ) , tr ( " %1 joined the lobby. " ) . arg ( RsHtml : : plainText ( str ) ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
2013-02-27 17:17:49 -05:00
emit peerJoined ( id ( ) ) ;
2012-01-17 15:36:36 -05:00
break ;
case RS_CHAT_LOBBY_EVENT_PEER_STATUS :
2013-08-24 11:07:31 -04:00
qsParticipant = nickname ;
2013-07-01 16:35:07 -04:00
ui . chatWidget - > updateStatusString ( RsHtml : : plainText ( nickname ) + " %1 " , RsHtml : : plainText ( str ) ) ;
2013-03-19 17:37:38 -04:00
if ( ! isParticipantMuted ( nickname ) ) {
emit typingEventReceived ( id ( ) ) ;
}
2012-01-17 15:36:36 -05:00
break ;
2012-05-06 18:19:59 -04:00
case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME :
2013-08-24 11:07:31 -04:00
qsParticipant = str ;
2014-01-01 19:56:46 -05:00
ui . chatWidget - > addChatMsg ( true , tr ( " Lobby management " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( ) , tr ( " %1 changed his name to: %2 " ) . arg ( RsHtml : : plainText ( nickname ) , RsHtml : : plainText ( str ) ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
2012-05-11 16:53:27 -04:00
// TODO if a user was muted and changed his name, update mute list, but only, when the muted peer, dont change his name to a other peer in your chat lobby
if ( isParticipantMuted ( nickname ) & & ! isNicknameInLobby ( str ) ) {
muteParticipant ( str ) ;
}
2012-05-06 18:19:59 -04:00
break ;
2012-01-23 17:49:47 -05:00
case RS_CHAT_LOBBY_EVENT_KEEP_ALIVE :
2012-02-12 15:45:42 -05:00
//std::cerr << "Received keep alive packet from " << nickname.toStdString() << " in lobby " << getPeerId() << std::endl;
2012-01-23 17:49:47 -05:00
break ;
2012-01-17 15:36:36 -05:00
default :
std : : cerr < < " ChatLobbyDialog::displayLobbyEvent() Unhandled lobby event type " < < event_type < < std : : endl ;
2012-01-06 17:17:08 -05:00
}
2013-08-24 11:07:31 -04:00
if ( qsParticipant ! = " " ) {
QList < QTreeWidgetItem * > qlFoundParticipants = ui . participantsList - > findItems ( str , Qt : : MatchExactly , COLUMN_NAME ) ;
if ( qlFoundParticipants . count ( ) ! = 0 ) qlFoundParticipants . at ( 0 ) - > setText ( COLUMN_ACTIVITY , QString : : number ( time ( NULL ) ) ) ;
}
2012-01-23 16:10:34 -05:00
updateParticipantsList ( ) ;
2012-01-06 17:17:08 -05:00
}
2012-01-11 19:13:25 -05:00
bool ChatLobbyDialog : : canClose ( )
{
// check that the lobby still exists.
ChatLobbyId lid ;
2012-01-17 15:36:36 -05:00
if ( ! rsMsgs - > isLobbyId ( getPeerId ( ) , lid ) ) {
2012-01-11 19:13:25 -05:00
return true ;
}
2012-01-17 15:36:36 -05:00
if ( QMessageBox : : Yes = = QMessageBox : : question ( this , tr ( " Unsubscribe to lobby " ) , tr ( " Do you want to unsubscribe to this chat lobby? " ) , QMessageBox : : Yes | QMessageBox : : No ) ) {
2012-01-11 19:13:25 -05:00
return true ;
}
return false ;
}
2012-01-17 15:36:36 -05:00
void ChatLobbyDialog : : showDialog ( uint chatflags )
{
2013-02-24 17:44:14 -05:00
if ( chatflags & RS_CHAT_FOCUS )
{
2013-02-22 16:42:27 -05:00
MainWindow : : showWindow ( MainWindow : : ChatLobby ) ;
2013-02-24 17:44:14 -05:00
dynamic_cast < ChatLobbyWidget * > ( MainWindow : : getPage ( MainWindow : : ChatLobby ) ) - > setCurrentChatPage ( this ) ;
2012-01-17 15:36:36 -05:00
}
}
void ChatLobbyDialog : : showParticipantsFrame ( bool show )
{
ui . participantsFrame - > setVisible ( show ) ;
ui . participantsFrameButton - > setChecked ( show ) ;
if ( show ) {
ui . participantsFrameButton - > setToolTip ( tr ( " Hide Participants " ) ) ;
ui . participantsFrameButton - > setIcon ( QIcon ( " :images/hide_toolbox_frame.png " ) ) ;
} else {
ui . participantsFrameButton - > setToolTip ( tr ( " Show Participants " ) ) ;
ui . participantsFrameButton - > setIcon ( QIcon ( " :images/show_toolbox_frame.png " ) ) ;
}
PeerSettings - > setShowParticipantsFrame ( getPeerId ( ) , show ) ;
}