2018-12-25 21:34:59 +01:00
/*******************************************************************************
* gui / ChatLobbyWidget . cpp *
* *
* Copyright ( C ) 2012 Retroshare Team < 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/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2018-01-05 14:45:29 +01:00
2012-01-07 19:52:58 +00:00
# include "ChatLobbyWidget.h"
2018-01-05 14:45:29 +01:00
2012-01-12 00:13:25 +00:00
# include "notifyqt.h"
# include "chat/ChatLobbyDialog.h"
2014-12-12 23:50:35 +00:00
# include "chat/ChatLobbyUserNotify.h"
2018-01-05 14:45:29 +01:00
# include "chat/ChatTabWidget.h"
# include "chat/CreateLobbyDialog.h"
# include "common/RSTreeWidgetItem.h"
2020-05-16 19:43:27 +02:00
# include "common/RSElidedItemDelegate.h"
2018-02-04 17:51:26 +01:00
# include "gui/RetroShareLink.h"
2015-03-06 21:13:23 +00:00
# include "gui/gxs/GxsIdDetails.h"
2015-05-17 10:13:32 +00:00
# include "gui/Identity/IdEditDialog.h"
2018-01-05 14:45:29 +01:00
# include "gui/settings/rsharesettings.h"
# include "util/HandleRichText.h"
# include "util/QtVersion.h"
2020-08-15 22:17:52 +02:00
# include "gui/common/FilesDefs.h"
2012-01-07 19:52:58 +00:00
2012-01-12 00:13:25 +00:00
# include "retroshare/rsmsgs.h"
# include "retroshare/rspeers.h"
# include "retroshare/rsnotify.h"
2015-03-06 21:13:23 +00:00
# include "retroshare/rsidentity.h"
2012-01-12 00:13:25 +00:00
2018-01-05 14:45:29 +01:00
# include <QGridLayout>
# include <QMenu>
# include <QMessageBox>
# include <QTextBrowser>
# include <QTimer>
# include <QTreeWidget>
# include <algorithm>
# include <time.h>
2015-08-27 22:37:01 -04:00
//#define CHAT_LOBBY_GUI_DEBUG 1
2012-01-12 00:13:25 +00:00
# define COLUMN_NAME 0
# define COLUMN_USER_COUNT 1
2012-03-16 22:47:49 +00:00
# define COLUMN_TOPIC 2
2019-01-12 14:44:46 +01:00
# define COLUMN_COUNT 3
2012-01-12 00:13:25 +00:00
# define COLUMN_DATA 0
2015-08-27 22:37:01 -04:00
# define ROLE_SORT Qt::UserRole
# define ROLE_ID Qt::UserRole + 1
# define ROLE_SUBSCRIBED Qt::UserRole + 2
# define ROLE_PRIVACYLEVEL Qt::UserRole + 3
2013-06-29 16:15:33 +00:00
# define ROLE_AUTOSUBSCRIBE Qt::UserRole + 4
2015-08-27 22:37:01 -04:00
# define ROLE_FLAGS Qt::UserRole + 5
2013-06-29 16:15:33 +00:00
2012-01-12 00:13:25 +00:00
# define TYPE_FOLDER 0
# define TYPE_LOBBY 1
2013-09-05 00:57:48 +00:00
# define IMAGE_CREATE ""
2019-10-14 19:56:47 +02:00
# define IMAGE_PUBLIC ": / icons / png / chats.png"
# define IMAGE_PRIVATE ": / icons / png / chats-private.png"
2019-12-04 21:49:59 +01:00
# define IMAGE_SIGNED ": / icons / png / chats-signed.png"
2019-11-23 00:25:52 +01:00
# define IMAGE_SUBSCRIBE ": / icons / png / enter.png"
# define IMAGE_UNSUBSCRIBE ": / icons / png / leave2.png"
2013-09-05 00:57:48 +00:00
# define IMAGE_PEER_ENTERING ":images / user / add_user24.png"
# define IMAGE_PEER_LEAVING ":images / user / remove_user24.png"
2019-12-04 21:49:59 +01:00
# define IMAGE_TYPING ":icons / png / typing.png"
2013-12-26 21:44:02 +00:00
# define IMAGE_MESSAGE ":images / chat.png"
2013-09-05 00:57:48 +00:00
# define IMAGE_AUTOSUBSCRIBE ":images / accepted16.png"
2019-11-23 00:25:52 +01:00
# define IMAGE_COPYRSLINK ": / icons / png / copy.png"
2012-01-12 00:13:25 +00:00
2013-10-18 21:10:33 +00:00
ChatLobbyWidget : : ChatLobbyWidget ( QWidget * parent , Qt : : WindowFlags flags )
2014-05-10 02:38:47 +00:00
: RsAutoUpdatePage ( 5000 , parent , flags )
2012-01-07 19:52:58 +00:00
{
2014-05-10 02:38:47 +00:00
ui . setupUi ( this ) ;
2012-01-12 00:13:25 +00:00
2014-05-10 02:38:47 +00:00
m_bProcessSettings = false ;
2015-04-17 21:36:22 +00:00
myChatLobbyUserNotify = NULL ;
2018-01-05 14:45:29 +01:00
myInviteYesButton = NULL ;
myInviteIdChooser = NULL ;
2013-09-19 19:22:17 +00:00
2014-05-10 02:38:47 +00:00
QObject : : connect ( NotifyQt : : getInstance ( ) , SIGNAL ( lobbyListChanged ( ) ) , SLOT ( lobbyChanged ( ) ) ) ;
2016-02-14 11:53:27 +01:00
QObject : : connect ( NotifyQt : : getInstance ( ) , SIGNAL ( chatLobbyEvent ( qulonglong , int , const RsGxsId & , const QString & ) ) , this , SLOT ( displayChatLobbyEvent ( qulonglong , int , const RsGxsId & , const QString & ) ) ) ;
2014-05-10 02:38:47 +00:00
QObject : : connect ( NotifyQt : : getInstance ( ) , SIGNAL ( chatLobbyInviteReceived ( ) ) , this , SLOT ( readChatLobbyInvites ( ) ) ) ;
2012-01-12 00:13:25 +00:00
2014-05-10 02:38:47 +00:00
QObject : : connect ( ui . lobbyTreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( lobbyTreeWidgetCustomPopupMenu ( QPoint ) ) ) ;
QObject : : connect ( ui . lobbyTreeWidget , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) ) ;
QObject : : connect ( ui . lobbyTreeWidget , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( updateCurrentLobby ( ) ) ) ;
2012-01-18 20:02:19 +00:00
2014-05-10 02:38:47 +00:00
QObject : : connect ( ui . filterLineEdit , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( filterItems ( QString ) ) ) ;
QObject : : connect ( ui . filterLineEdit , SIGNAL ( filterChanged ( int ) ) , this , SLOT ( filterColumnChanged ( int ) ) ) ;
2016-01-27 20:27:44 +01:00
QObject : : connect ( ui . createLobbyToolButton , SIGNAL ( clicked ( ) ) , this , SLOT ( createChatLobby ( ) ) ) ;
2012-01-12 00:13:25 +00:00
compareRole = new RSTreeWidgetItemCompareRole ;
compareRole - > setRole ( COLUMN_NAME , ROLE_SORT ) ;
2014-05-10 02:38:47 +00:00
ui . lobbyTreeWidget - > setColumnCount ( COLUMN_COUNT ) ;
ui . lobbyTreeWidget - > sortItems ( COLUMN_NAME , Qt : : AscendingOrder ) ;
2012-01-12 00:13:25 +00:00
2014-05-10 02:38:47 +00:00
ui . lobbyTreeWidget - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2013-03-17 15:03:21 +00:00
2014-05-10 02:38:47 +00:00
QTreeWidgetItem * headerItem = ui . lobbyTreeWidget - > headerItem ( ) ;
2012-01-12 00:13:25 +00:00
headerItem - > setText ( COLUMN_NAME , tr ( " Name " ) ) ;
headerItem - > setText ( COLUMN_USER_COUNT , tr ( " Count " ) ) ;
2012-03-16 22:47:49 +00:00
headerItem - > setText ( COLUMN_TOPIC , tr ( " Topic " ) ) ;
2012-01-12 00:13:25 +00:00
headerItem - > setTextAlignment ( COLUMN_NAME , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
2013-09-02 00:08:38 +00:00
headerItem - > setTextAlignment ( COLUMN_TOPIC , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
2012-01-12 00:13:25 +00:00
headerItem - > setTextAlignment ( COLUMN_USER_COUNT , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
2014-05-10 02:38:47 +00:00
QHeaderView * header = ui . lobbyTreeWidget - > header ( ) ;
2015-06-26 08:14:09 +00:00
QHeaderView_setSectionResizeModeColumn ( header , COLUMN_NAME , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( header , COLUMN_USER_COUNT , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( header , COLUMN_TOPIC , QHeaderView : : Interactive ) ;
2012-01-12 00:13:25 +00:00
2013-10-11 20:46:25 +00:00
privateSubLobbyItem = new RSTreeWidgetItem ( compareRole , TYPE_FOLDER ) ;
2017-01-22 18:52:30 +01:00
privateSubLobbyItem - > setText ( COLUMN_NAME , tr ( " Private Subscribed chat rooms " ) ) ;
2014-05-10 02:38:47 +00:00
privateSubLobbyItem - > setData ( COLUMN_NAME , ROLE_SORT , " 1 " ) ;
// privateLobbyItem->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE));
2015-03-06 21:13:23 +00:00
privateSubLobbyItem - > setData ( COLUMN_DATA , ROLE_PRIVACYLEVEL , CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE ) ;
2014-05-10 02:38:47 +00:00
ui . lobbyTreeWidget - > insertTopLevelItem ( 0 , privateSubLobbyItem ) ;
publicSubLobbyItem = new RSTreeWidgetItem ( compareRole , TYPE_FOLDER ) ;
2017-01-22 18:52:30 +01:00
publicSubLobbyItem - > setText ( COLUMN_NAME , tr ( " Public Subscribed chat rooms " ) ) ;
2014-05-10 02:38:47 +00:00
publicSubLobbyItem - > setData ( COLUMN_NAME , ROLE_SORT , " 2 " ) ;
// publicLobbyItem->setIcon(COLUMN_NAME, QIcon(IMAGE_PUBLIC));
2015-03-06 21:13:23 +00:00
publicSubLobbyItem - > setData ( COLUMN_DATA , ROLE_PRIVACYLEVEL , CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC ) ;
2014-05-10 02:38:47 +00:00
ui . lobbyTreeWidget - > insertTopLevelItem ( 1 , publicSubLobbyItem ) ;
2013-10-11 20:46:25 +00:00
2012-01-12 00:13:25 +00:00
privateLobbyItem = new RSTreeWidgetItem ( compareRole , TYPE_FOLDER ) ;
2017-01-22 18:52:30 +01:00
privateLobbyItem - > setText ( COLUMN_NAME , tr ( " Private chat rooms " ) ) ;
2014-05-10 02:38:47 +00:00
privateLobbyItem - > setData ( COLUMN_NAME , ROLE_SORT , " 3 " ) ;
// privateLobbyItem->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE));
2015-03-06 21:13:23 +00:00
privateLobbyItem - > setData ( COLUMN_DATA , ROLE_PRIVACYLEVEL , CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE ) ;
2014-05-10 02:38:47 +00:00
ui . lobbyTreeWidget - > insertTopLevelItem ( 2 , privateLobbyItem ) ;
2012-01-12 00:13:25 +00:00
publicLobbyItem = new RSTreeWidgetItem ( compareRole , TYPE_FOLDER ) ;
2017-01-22 18:52:30 +01:00
publicLobbyItem - > setText ( COLUMN_NAME , tr ( " Public chat rooms " ) ) ;
2014-05-10 02:38:47 +00:00
publicLobbyItem - > setData ( COLUMN_NAME , ROLE_SORT , " 4 " ) ;
// publicLobbyItem->setIcon(COLUMN_NAME, QIcon(IMAGE_PUBLIC));
2015-03-06 21:13:23 +00:00
publicLobbyItem - > setData ( COLUMN_DATA , ROLE_PRIVACYLEVEL , CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC ) ;
2014-05-10 02:38:47 +00:00
ui . lobbyTreeWidget - > insertTopLevelItem ( 3 , publicLobbyItem ) ;
ui . lobbyTreeWidget - > expandAll ( ) ;
ui . lobbyTreeWidget - > setColumnHidden ( COLUMN_NAME , false ) ;
ui . lobbyTreeWidget - > setColumnHidden ( COLUMN_USER_COUNT , true ) ;
ui . lobbyTreeWidget - > setColumnHidden ( COLUMN_TOPIC , true ) ;
ui . lobbyTreeWidget - > setSortingEnabled ( true ) ;
2020-05-16 19:43:27 +02:00
ui . lobbyTreeWidget - > setItemDelegateForColumn ( COLUMN_NAME , new RSElidedItemDelegate ( ) ) ;
2014-05-10 02:38:47 +00:00
2015-08-27 22:37:01 -04:00
float fact = QFontMetricsF ( font ( ) ) . height ( ) / 14.0f ;
2014-05-10 02:38:47 +00:00
ui . lobbyTreeWidget - > adjustSize ( ) ;
2015-08-27 22:37:01 -04:00
ui . lobbyTreeWidget - > setColumnWidth ( COLUMN_NAME , 100 * fact ) ;
ui . lobbyTreeWidget - > setColumnWidth ( COLUMN_USER_COUNT , 50 * fact ) ;
ui . lobbyTreeWidget - > setColumnWidth ( COLUMN_TOPIC , 50 * fact ) ;
2014-05-10 02:38:47 +00:00
/** Setup the actions for the header context menu */
showUserCountAct = new QAction ( headerItem - > text ( COLUMN_USER_COUNT ) , this ) ;
2015-06-12 08:27:26 +00:00
showUserCountAct - > setCheckable ( true ) ; showUserCountAct - > setToolTip ( tr ( " Show " ) + " " + showUserCountAct - > text ( ) + " " + tr ( " column " ) ) ;
2013-09-19 19:22:17 +00:00
connect ( showUserCountAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowUserCountColumn ( bool ) ) ) ;
showTopicAct = new QAction ( headerItem - > text ( COLUMN_TOPIC ) , this ) ;
2015-06-12 08:27:26 +00:00
showTopicAct - > setCheckable ( true ) ; showTopicAct - > setToolTip ( tr ( " Show " ) + " " + showTopicAct - > text ( ) + " " + tr ( " column " ) ) ;
2013-09-19 19:22:17 +00:00
connect ( showTopicAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowTopicColumn ( bool ) ) ) ;
2013-03-19 20:49:24 +00:00
2013-03-19 22:34:30 +00:00
// Set initial size of the splitter
2014-12-13 23:32:23 +00:00
ui . splitter - > setStretchFactor ( 0 , 0 ) ;
ui . splitter - > setStretchFactor ( 1 , 1 ) ;
2013-03-19 22:34:30 +00:00
QList < int > sizes ;
2015-08-27 22:37:01 -04:00
sizes < < 200 * fact < < width ( ) ; // Qt calculates the right sizes
2014-05-10 02:38:47 +00:00
ui . splitter - > setSizes ( sizes ) ;
2013-03-19 22:34:30 +00:00
2012-01-12 00:13:25 +00:00
lobbyChanged ( ) ;
2013-02-24 22:44:14 +00:00
showBlankPage ( 0 ) ;
2014-05-10 02:38:47 +00:00
/* add filter actions */
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " Name " ) , COLUMN_NAME , tr ( " Search Name " ) ) ;
ui . filterLineEdit - > setCurrentFilter ( COLUMN_NAME ) ;
// load settings
processSettings ( true ) ;
2015-06-30 16:44:58 +00:00
int S = QFontMetricsF ( font ( ) ) . height ( ) ;
QString help_str = tr ( " \
2017-01-18 10:15:07 +01:00
< h1 > < img width = \ " %1 \" src= \" :/icons/help_64.png \" > Chat Rooms</h1> \
< p > Chat rooms work pretty much like IRC . \
2014-05-10 02:38:47 +00:00
They allow you to talk anonymously with tons of people without the need to make friends . < / p > \
2017-01-21 21:38:10 +01:00
< p > A chat room can be public ( your friends see it ) or private ( your friends can ' t see it , unless you \
2020-02-22 01:26:20 +01:00
invite them with < img src = \ " :/icons/png/add.png \" width=%2/>). \
2017-01-21 21:38:10 +01:00
Once you have been invited to a private room , you will be able to see it when your friends \
2014-05-10 02:38:47 +00:00
are using it . < / p > \
< p > The list at left shows \
chat lobbies your friends are participating in . You can either \
2013-07-19 18:36:09 +00:00
< ul > \
2017-01-18 10:15:07 +01:00
< li > Right click to create a new chat room < / li > \
2017-01-21 21:38:10 +01:00
< li > Double click a chat room to enter , chat , and show it to your friends < / li > \
2014-05-10 02:38:47 +00:00
< / ul > \
2017-01-18 10:15:07 +01:00
Note : For the chat rooms to work properly , your computer needs be on time . So check your system clock ! \
2014-05-10 02:38:47 +00:00
< / p > \
"
2015-06-30 16:44:58 +00:00
) . arg ( QString : : number ( 2 * S ) ) . arg ( QString : : number ( S ) ) ;
2017-02-25 23:52:57 +01:00
registerHelpButton ( ui . helpButton , help_str , " ChatLobbyDialog " ) ;
2019-10-14 19:56:47 +02:00
ui . lobbyTreeWidget - > setIconSize ( QSize ( S * 1.5 , S * 1.5 ) ) ;
2012-01-07 19:52:58 +00:00
}
2012-01-12 00:13:25 +00:00
2012-01-07 19:52:58 +00:00
ChatLobbyWidget : : ~ ChatLobbyWidget ( )
{
2013-09-19 19:22:17 +00:00
// save settings
processSettings ( false ) ;
2012-06-09 14:14:04 +00:00
if ( compareRole ) {
delete ( compareRole ) ;
}
2012-01-12 00:13:25 +00:00
}
2020-01-26 23:19:20 +01:00
UserNotify * ChatLobbyWidget : : createUserNotify ( QObject * parent )
2014-12-12 23:50:35 +00:00
{
2020-01-26 23:19:20 +01:00
myChatLobbyUserNotify = new ChatLobbyUserNotify ( parent ) ;
connect ( myChatLobbyUserNotify , SIGNAL ( countChanged ( ChatLobbyId , unsigned int ) ) , this , SLOT ( updateNotify ( ChatLobbyId , unsigned int ) ) ) ;
2015-04-17 21:36:22 +00:00
return myChatLobbyUserNotify ;
}
void ChatLobbyWidget : : updateNotify ( ChatLobbyId id , unsigned int count )
{
ChatLobbyDialog * dialog = NULL ;
dialog = _lobby_infos [ id ] . dialog ;
if ( ! dialog ) return ;
QToolButton * notifyButton = dialog - > getChatWidget ( ) - > getNotifyButton ( ) ;
if ( ! notifyButton ) return ;
dialog - > getChatWidget ( ) - > setNotify ( myChatLobbyUserNotify ) ;
if ( count > 0 ) {
notifyButton - > setVisible ( true ) ;
2016-08-06 17:52:12 +02:00
//notifyButton->setIcon(_lobby_infos[id].default_icon);
2015-04-17 21:36:22 +00:00
notifyButton - > setToolTip ( QString ( " (%1) " ) . arg ( count ) ) ;
} else {
notifyButton - > setVisible ( false ) ;
}
2014-12-12 23:50:35 +00:00
}
2015-08-27 22:37:01 -04:00
static bool trimAnonIds ( std : : list < RsGxsId > & lst )
{
// trim down identities that are unsigned, because the lobby requires it.
bool removed = false ;
RsIdentityDetails idd ;
for ( std : : list < RsGxsId > : : iterator it = lst . begin ( ) ; it ! = lst . end ( ) ; )
2015-11-19 21:14:32 -05:00
if ( ! rsIdentity - > getIdDetails ( * it , idd ) | | ! ( idd . mFlags & RS_IDENTITY_FLAGS_PGP_LINKED ) )
2015-08-27 22:37:01 -04:00
{
it = lst . erase ( it ) ;
removed = true ;
}
else
+ + it ;
return removed ;
}
2013-02-24 22:44:14 +00:00
void ChatLobbyWidget : : lobbyTreeWidgetCustomPopupMenu ( QPoint )
2012-01-12 00:13:25 +00:00
{
2013-02-24 22:44:14 +00:00
std : : cerr < < " Creating customPopupMennu " < < std : : endl ;
2014-05-10 02:38:47 +00:00
QTreeWidgetItem * item = ui . lobbyTreeWidget - > currentItem ( ) ;
2012-01-30 23:20:42 +00:00
2012-01-12 00:13:25 +00:00
QMenu contextMnu ( this ) ;
2012-01-30 23:20:42 +00:00
if ( item & & item - > type ( ) = = TYPE_FOLDER ) {
2020-08-15 22:17:52 +02:00
QAction * action = contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_CREATE ) , tr ( " Create chat room " ) , this , SLOT ( createChatLobby ( ) ) ) ;
2012-01-30 23:20:42 +00:00
action - > setData ( item - > data ( COLUMN_DATA , ROLE_PRIVACYLEVEL ) . toInt ( ) ) ;
}
2012-01-12 00:13:25 +00:00
2015-03-06 21:13:23 +00:00
if ( item & & item - > type ( ) = = TYPE_LOBBY )
{
2015-04-22 17:33:53 +00:00
std : : list < RsGxsId > own_identities ;
rsIdentity - > getOwnIds ( own_identities ) ;
2015-03-06 21:13:23 +00:00
if ( item - > data ( COLUMN_DATA , ROLE_SUBSCRIBED ) . toBool ( ) )
2020-08-15 22:17:52 +02:00
contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_UNSUBSCRIBE ) , tr ( " Leave this room " ) , this , SLOT ( unsubscribeItem ( ) ) ) ;
2015-03-06 21:13:23 +00:00
else
{
QTreeWidgetItem * item = ui . lobbyTreeWidget - > currentItem ( ) ;
2015-12-05 16:49:00 -05:00
//ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
2015-08-27 22:37:01 -04:00
ChatLobbyFlags flags ( item - > data ( COLUMN_DATA , ROLE_FLAGS ) . toUInt ( ) ) ;
bool removed = false ;
if ( flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED )
removed = trimAnonIds ( own_identities ) ;
2015-05-17 10:13:32 +00:00
if ( own_identities . empty ( ) )
{
2015-08-27 22:37:01 -04:00
if ( removed )
2020-08-15 22:17:52 +02:00
contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_SUBSCRIBE ) , tr ( " Create a non anonymous identity and enter this room " ) , this , SLOT ( createIdentityAndSubscribe ( ) ) ) ;
2015-08-27 22:37:01 -04:00
else
2020-08-15 22:17:52 +02:00
contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_SUBSCRIBE ) , tr ( " Create an identity and enter this chat room " ) , this , SLOT ( createIdentityAndSubscribe ( ) ) ) ;
2015-05-17 10:13:32 +00:00
}
else if ( own_identities . size ( ) = = 1 )
2015-03-06 21:13:23 +00:00
{
2020-08-15 22:17:52 +02:00
QAction * action = contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_SUBSCRIBE ) , tr ( " Enter this chat room " ) , this , SLOT ( subscribeChatLobbyAs ( ) ) ) ;
2015-05-17 10:13:32 +00:00
action - > setData ( QString : : fromStdString ( ( own_identities . front ( ) ) . toStdString ( ) ) ) ;
2015-03-06 21:13:23 +00:00
}
else
{
2020-08-15 22:17:52 +02:00
QMenu * mnu = contextMnu . addMenu ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_SUBSCRIBE ) , tr ( " Enter this chat room as... " ) ) ;
2015-03-06 21:13:23 +00:00
for ( std : : list < RsGxsId > : : const_iterator it = own_identities . begin ( ) ; it ! = own_identities . end ( ) ; + + it )
{
RsIdentityDetails idd ;
rsIdentity - > getIdDetails ( * it , idd ) ;
QPixmap pixmap ;
2019-06-04 11:49:26 +02:00
if ( idd . mAvatar . mSize = = 0 | | ! GxsIdDetails : : loadPixmapFromData ( idd . mAvatar . mData , idd . mAvatar . mSize , pixmap , GxsIdDetails : : SMALL ) )
pixmap = GxsIdDetails : : makeDefaultIcon ( * it , GxsIdDetails : : SMALL ) ;
2015-03-06 21:13:23 +00:00
QAction * action = mnu - > addAction ( QIcon ( pixmap ) , QString ( " %1 (%2) " ) . arg ( QString : : fromUtf8 ( idd . mNickname . c_str ( ) ) , QString : : fromStdString ( ( * it ) . toStdString ( ) ) ) , this , SLOT ( subscribeChatLobbyAs ( ) ) ) ;
action - > setData ( QString : : fromStdString ( ( * it ) . toStdString ( ) ) ) ;
}
}
2015-03-07 14:49:33 +00:00
}
2015-03-06 21:13:23 +00:00
2019-06-15 13:54:34 +02:00
# ifdef TO_BE_REMOVED
// This code is not needed anymore because AutoSubscribe is now automatically handled with chat room subscription.
2015-04-22 17:33:53 +00:00
if ( item - > data ( COLUMN_DATA , ROLE_AUTOSUBSCRIBE ) . toBool ( ) )
contextMnu . addAction ( QIcon ( IMAGE_AUTOSUBSCRIBE ) , tr ( " Remove Auto Subscribe " ) , this , SLOT ( autoSubscribeItem ( ) ) ) ;
else if ( ! own_identities . empty ( ) )
contextMnu . addAction ( QIcon ( IMAGE_SUBSCRIBE ) , tr ( " Add Auto Subscribe " ) , this , SLOT ( autoSubscribeItem ( ) ) ) ;
2019-06-15 13:54:34 +02:00
# endif
2018-02-04 17:51:26 +01:00
2020-08-15 22:17:52 +02:00
contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_COPYRSLINK ) , tr ( " Copy RetroShare Link " ) , this , SLOT ( copyItemLink ( ) ) ) ;
2015-03-06 21:13:23 +00:00
}
2012-01-12 00:13:25 +00:00
2015-03-06 21:13:23 +00:00
contextMnu . addSeparator ( ) ; //-------------------------------------------------------------------
2013-09-19 19:22:17 +00:00
2015-03-06 21:13:23 +00:00
showUserCountAct - > setChecked ( ! ui . lobbyTreeWidget - > isColumnHidden ( COLUMN_USER_COUNT ) ) ;
showTopicAct - > setChecked ( ! ui . lobbyTreeWidget - > isColumnHidden ( COLUMN_TOPIC ) ) ;
2013-09-19 19:22:17 +00:00
2015-03-06 21:13:23 +00:00
QMenu * menu = contextMnu . addMenu ( tr ( " Columns " ) ) ;
menu - > addAction ( showUserCountAct ) ;
menu - > addAction ( showTopicAct ) ;
2013-09-19 19:22:17 +00:00
2015-03-06 21:13:23 +00:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2013-09-19 19:22:17 +00:00
}
2012-01-12 00:13:25 +00:00
void ChatLobbyWidget : : lobbyChanged ( )
{
updateDisplay ( ) ;
}
2015-08-27 22:37:01 -04:00
static void updateItem ( QTreeWidget * treeWidget , QTreeWidgetItem * item , ChatLobbyId id , const std : : string & name , const std : : string & topic , int count , bool subscribed , bool autoSubscribe , ChatLobbyFlags lobby_flags )
2012-01-12 00:13:25 +00:00
{
item - > setText ( COLUMN_NAME , QString : : fromUtf8 ( name . c_str ( ) ) ) ;
item - > setData ( COLUMN_NAME , ROLE_SORT , QString : : fromUtf8 ( name . c_str ( ) ) ) ;
2012-03-16 23:07:28 +00:00
if ( topic . empty ( ) )
{
2012-03-30 23:02:52 +00:00
item - > setText ( COLUMN_TOPIC , qApp - > translate ( " ChatLobbyWidget " , " [No topic provided] " ) ) ;
item - > setData ( COLUMN_TOPIC , ROLE_SORT , qApp - > translate ( " ChatLobbyWidget " , " [No topic provided] " ) ) ;
2012-03-16 23:07:28 +00:00
}
else
{
item - > setText ( COLUMN_TOPIC , QString : : fromUtf8 ( topic . c_str ( ) ) ) ;
item - > setData ( COLUMN_TOPIC , ROLE_SORT , QString : : fromUtf8 ( topic . c_str ( ) ) ) ;
}
2012-03-16 22:47:49 +00:00
2013-09-19 19:22:17 +00:00
//item->setText(COLUMN_USER_COUNT, QString::number(count));
2013-10-11 20:46:25 +00:00
item - > setData ( COLUMN_USER_COUNT , Qt : : EditRole , count ) ;
2013-09-19 19:22:17 +00:00
2012-01-12 11:14:50 +00:00
item - > setData ( COLUMN_DATA , ROLE_ID , ( qulonglong ) id ) ;
2012-01-12 00:13:25 +00:00
item - > setData ( COLUMN_DATA , ROLE_SUBSCRIBED , subscribed ) ;
2015-08-27 22:37:01 -04:00
item - > setData ( COLUMN_DATA , ROLE_FLAGS , lobby_flags . toUInt32 ( ) ) ;
2013-06-29 16:15:33 +00:00
item - > setData ( COLUMN_DATA , ROLE_AUTOSUBSCRIBE , autoSubscribe ) ;
2012-01-12 00:13:25 +00:00
2020-05-16 19:43:27 +02:00
//TODO (Phenom): Add qproperty for these text colors in stylesheets
// As palette is not updated by stylesheet
2013-07-04 20:09:46 +00:00
QColor color = treeWidget - > palette ( ) . color ( QPalette : : Active , QPalette : : Text ) ;
2015-08-27 22:37:01 -04:00
2013-03-02 21:27:38 +00:00
if ( ! subscribed ) {
// Average between Base and Text colors
2013-07-04 20:09:46 +00:00
QColor color2 = treeWidget - > palette ( ) . color ( QPalette : : Active , QPalette : : Base ) ;
2013-03-02 21:27:38 +00:00
color . setRgbF ( ( color2 . redF ( ) + color . redF ( ) ) / 2 , ( color2 . greenF ( ) + color . greenF ( ) ) / 2 , ( color2 . blueF ( ) + color . blueF ( ) ) / 2 ) ;
}
2012-01-12 00:13:25 +00:00
for ( int column = 0 ; column < COLUMN_COUNT ; + + column ) {
2020-05-16 19:43:27 +02:00
item - > setData ( column , Qt : : ForegroundRole , color ) ;
2012-01-12 00:13:25 +00:00
}
2015-08-27 22:37:01 -04:00
QString tooltipstr = QObject : : tr ( " Subject: " ) + " " + item - > text ( COLUMN_TOPIC ) + " \n "
2015-06-12 08:27:26 +00:00
+ QObject : : tr ( " Participants: " ) + " " + QString : : number ( count ) + " \n "
+ QObject : : tr ( " Auto Subscribe: " ) + " " + ( autoSubscribe ? QObject : : tr ( " enabled " ) : QObject : : tr ( " disabled " ) ) + " \n "
2015-08-27 22:37:01 -04:00
+ QObject : : tr ( " Id: " ) + " " + QString : : number ( id , 16 ) ;
if ( lobby_flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED )
2017-03-21 16:41:39 +03:00
{
2015-11-25 10:33:28 +00:00
tooltipstr + = QObject : : tr ( " \n Security: no anonymous IDs " ) ;
2017-03-21 16:41:39 +03:00
QColor foreground = QColor ( 0 , 128 , 0 ) ; // green
for ( int column = 0 ; column < COLUMN_COUNT ; + + column )
2020-05-16 19:43:27 +02:00
item - > setData ( column , Qt : : ForegroundRole , foreground ) ;
2017-03-21 16:41:39 +03:00
}
2015-08-27 22:37:01 -04:00
item - > setToolTip ( 0 , tooltipstr ) ;
2012-01-07 19:52:58 +00:00
}
2013-02-24 22:44:14 +00:00
void ChatLobbyWidget : : addChatPage ( ChatLobbyDialog * d )
{
// check that the page does not already exist.
2013-02-27 22:17:49 +00:00
if ( _lobby_infos . find ( d - > id ( ) ) = = _lobby_infos . end ( ) )
2013-02-24 22:44:14 +00:00
{
2020-04-18 14:49:24 +02:00
connect ( d , SIGNAL ( dialogClose ( ChatDialog * ) ) , this , SLOT ( dialogClose ( ChatDialog * ) ) ) ;
2013-02-24 22:44:14 +00:00
connect ( d , SIGNAL ( typingEventReceived ( ChatLobbyId ) ) , this , SLOT ( updateTypingStatus ( ChatLobbyId ) ) ) ;
2015-04-17 21:36:22 +00:00
connect ( d , SIGNAL ( messageReceived ( bool , ChatLobbyId , QDateTime , QString , QString ) ) , this , SLOT ( updateMessageChanged ( bool , ChatLobbyId , QDateTime , QString , QString ) ) ) ;
2013-02-27 22:17:49 +00:00
connect ( d , SIGNAL ( peerJoined ( ChatLobbyId ) ) , this , SLOT ( updatePeerEntering ( ChatLobbyId ) ) ) ;
connect ( d , SIGNAL ( peerLeft ( ChatLobbyId ) ) , this , SLOT ( updatePeerLeaving ( ChatLobbyId ) ) ) ;
2013-02-24 22:44:14 +00:00
2013-08-26 23:37:13 +00:00
ChatLobbyId id = d - > id ( ) ;
_lobby_infos [ id ] . dialog = d ;
_lobby_infos [ id ] . default_icon = QIcon ( ) ;
2020-04-18 14:49:24 +02:00
_lobby_infos [ id ] . last_typing_event = time ( nullptr ) ;
2013-08-26 23:37:13 +00:00
2020-04-18 14:49:24 +02:00
ChatLobbyInfo linfo ;
if ( rsMsgs - > getChatLobbyInfo ( id , linfo ) )
2020-08-15 22:17:52 +02:00
_lobby_infos [ id ] . default_icon = ( linfo . lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC ) ? FilesDefs : : getIconFromQtResourcePath ( IMAGE_PUBLIC ) : FilesDefs : : getIconFromQtResourcePath ( IMAGE_PRIVATE ) ;
2020-04-18 14:49:24 +02:00
else
std : : cerr < < " (EE) cannot find info for room " < < std : : hex < < id < < std : : dec < < std : : endl ;
}
ui . stackedWidget - > addWidget ( d ) ;
}
void ChatLobbyWidget : : removeChatPage ( ChatLobbyDialog * d )
{
// check that the page already exist.
if ( _lobby_infos . find ( d - > id ( ) ) ! = _lobby_infos . end ( ) )
{
ui . stackedWidget - > removeWidget ( d ) ;
2013-02-24 22:44:14 +00:00
}
}
2020-04-18 14:49:24 +02:00
void ChatLobbyWidget : : dialogClose ( ChatDialog * cd )
{
ChatLobbyDialog * d = dynamic_cast < ChatLobbyDialog * > ( cd ) ;
if ( _lobby_infos . find ( d - > id ( ) ) ! = _lobby_infos . end ( ) )
unsubscribeChatLobby ( d - > id ( ) ) ;
}
2013-02-24 22:44:14 +00:00
void ChatLobbyWidget : : setCurrentChatPage ( ChatLobbyDialog * d )
{
2014-05-10 02:38:47 +00:00
ui . stackedWidget - > setCurrentWidget ( d ) ;
2013-08-27 15:26:11 +00:00
if ( d ) {
QTreeWidgetItem * item = getTreeWidgetItem ( d - > id ( ) ) ;
if ( item ) {
2014-05-10 02:38:47 +00:00
ui . lobbyTreeWidget - > setCurrentItem ( item ) ;
2013-08-27 15:26:11 +00:00
}
}
2013-02-24 22:44:14 +00:00
}
2012-01-07 19:52:58 +00:00
void ChatLobbyWidget : : updateDisplay ( )
{
2012-01-28 13:20:01 +00:00
# ifdef CHAT_LOBBY_GUI_DEBUG
2017-01-21 21:38:10 +01:00
std : : cerr < < " updating chat room display! " < < std : : endl ;
2012-01-28 13:20:01 +00:00
# endif
2012-12-04 21:36:05 +00:00
std : : vector < VisibleChatLobbyRecord > visibleLobbies ;
rsMsgs - > getListOfNearbyChatLobbies ( visibleLobbies ) ;
2012-01-07 19:52:58 +00:00
2015-03-06 21:13:23 +00:00
std : : list < ChatLobbyId > lobbies ;
2012-01-12 00:13:25 +00:00
rsMsgs - > getChatLobbyList ( lobbies ) ;
2012-01-07 21:01:43 +00:00
2012-01-28 13:20:01 +00:00
# ifdef CHAT_LOBBY_GUI_DEBUG
2013-12-26 21:44:02 +00:00
std : : cerr < < " got " < < visibleLobbies . size ( ) < < " visible lobbies " < < std : : endl ;
2012-01-28 13:20:01 +00:00
# endif
2012-01-07 21:37:31 +00:00
2012-01-12 00:13:25 +00:00
// now, do a nice display of lobbies
2012-01-07 19:52:58 +00:00
2014-03-17 20:56:06 +00:00
RsPeerId vpid ;
2015-03-06 21:13:23 +00:00
std : : list < ChatLobbyId > : : const_iterator lobbyIt ;
2012-01-12 00:13:25 +00:00
// remove not existing public lobbies
2013-12-26 21:44:02 +00:00
for ( int p = 0 ; p < 4 ; + + p )
2012-12-04 21:36:05 +00:00
{
2013-12-26 21:44:02 +00:00
QTreeWidgetItem * lobby_item = NULL ;
switch ( p )
{
case 0 : lobby_item = privateSubLobbyItem ; break ;
case 1 : lobby_item = publicSubLobbyItem ; break ;
case 2 : lobby_item = privateLobbyItem ; break ;
default :
case 3 : lobby_item = publicLobbyItem ; break ;
}
//QTreeWidgetItem *lobby_item = (p==0)?publicLobbyItem:privateLobbyItem ;
2012-12-04 21:36:05 +00:00
int childCnt = lobby_item - > childCount ( ) ;
int childIndex = 0 ;
while ( childIndex < childCnt ) {
QTreeWidgetItem * itemLoop = lobby_item - > child ( childIndex ) ;
if ( itemLoop - > type ( ) = = TYPE_LOBBY )
{
// check for visible lobby
2013-12-26 21:44:02 +00:00
//
uint32_t i ;
for ( i = 0 ; i < visibleLobbies . size ( ) ; + + i )
2012-12-04 21:36:05 +00:00
if ( itemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) = = visibleLobbies [ i ] . lobby_id )
2012-01-12 00:13:25 +00:00
break ;
2013-12-26 21:44:02 +00:00
if ( i > = visibleLobbies . size ( ) )
2012-12-04 21:36:05 +00:00
{
// Check for participating lobby with public level
//
for ( lobbyIt = lobbies . begin ( ) ; lobbyIt ! = lobbies . end ( ) ; + + lobbyIt )
2015-03-06 21:13:23 +00:00
if ( itemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) = = * lobbyIt )
2012-12-04 21:36:05 +00:00
break ;
if ( lobbyIt = = lobbies . end ( ) )
{
delete ( lobby_item - > takeChild ( lobby_item - > indexOfChild ( itemLoop ) ) ) ;
childCnt = lobby_item - > childCount ( ) ;
continue ;
}
2012-01-12 00:13:25 +00:00
}
}
2014-10-21 22:33:02 +00:00
+ + childIndex ;
2012-01-12 00:13:25 +00:00
}
}
2012-01-07 21:01:43 +00:00
2012-12-04 21:36:05 +00:00
// Now add visible lobbies
//
2013-12-26 21:44:02 +00:00
for ( uint32_t i = 0 ; i < visibleLobbies . size ( ) ; + + i )
2012-12-04 21:36:05 +00:00
{
const VisibleChatLobbyRecord & lobby = visibleLobbies [ i ] ;
2012-01-07 21:37:31 +00:00
2012-01-23 22:49:47 +00:00
# ifdef CHAT_LOBBY_GUI_DEBUG
2012-12-04 21:36:05 +00:00
std : : cerr < < " adding " < < lobby . lobby_name < < " topic " < < lobby . lobby_topic < < " # " < < std : : hex < < lobby . lobby_id < < std : : dec < < " public " < < lobby . total_number_of_peers < < " peers. Lobby type: " < < lobby . lobby_privacy_level < < std : : endl ;
2012-01-23 22:49:47 +00:00
# endif
2012-01-07 23:03:59 +00:00
2013-10-11 20:46:25 +00:00
2016-01-10 14:22:06 +01:00
bool subscribed = std : : find ( lobbies . begin ( ) , lobbies . end ( ) , lobby . lobby_id ) ! = lobbies . end ( ) ;
2013-10-11 20:46:25 +00:00
2012-01-12 00:13:25 +00:00
QTreeWidgetItem * item = NULL ;
2013-12-26 21:44:02 +00:00
QTreeWidgetItem * lobby_item = NULL ;
2015-03-06 21:13:23 +00:00
QTreeWidgetItem * lobby_other_item = NULL ;
if ( lobby . lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC )
{
if ( subscribed )
{
lobby_item = publicSubLobbyItem ;
lobby_other_item = publicLobbyItem ;
}
else
{
lobby_item = publicLobbyItem ;
lobby_other_item = publicSubLobbyItem ;
}
}
else
{
if ( subscribed )
{
lobby_item = privateSubLobbyItem ;
lobby_other_item = privateLobbyItem ;
}
else
{
lobby_item = privateLobbyItem ;
lobby_other_item = privateSubLobbyItem ;
}
}
2013-12-26 21:44:02 +00:00
//QTreeWidgetItem *lobby_item = (lobby.lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC)?publicLobbyItem:privateLobbyItem ;
2012-12-04 21:36:05 +00:00
// Search existing item
//
2013-12-26 21:44:02 +00:00
int childCnt = lobby_other_item - > childCount ( ) ;
2014-10-21 22:33:02 +00:00
for ( int childIndex = 0 ; childIndex < childCnt ; + + childIndex )
2013-12-26 21:44:02 +00:00
{
QTreeWidgetItem * itemLoop = lobby_other_item - > child ( childIndex ) ;
if ( itemLoop - > type ( ) = = TYPE_LOBBY & & itemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) = = lobby . lobby_id ) {
delete ( lobby_other_item - > takeChild ( lobby_other_item - > indexOfChild ( itemLoop ) ) ) ;
childCnt = lobby_other_item - > childCount ( ) ;
break ;
}
}
childCnt = lobby_item - > childCount ( ) ;
2014-10-21 22:33:02 +00:00
for ( int childIndex = 0 ; childIndex < childCnt ; + + childIndex )
2012-12-04 21:36:05 +00:00
{
QTreeWidgetItem * itemLoop = lobby_item - > child ( childIndex ) ;
2012-01-12 00:13:25 +00:00
if ( itemLoop - > type ( ) = = TYPE_LOBBY & & itemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) = = lobby . lobby_id ) {
item = itemLoop ;
break ;
}
2012-01-07 21:37:31 +00:00
}
2012-01-07 21:01:43 +00:00
2015-08-27 22:37:01 -04:00
ChatLobbyFlags lobby_flags = lobby . lobby_flags ;
2013-09-05 20:12:24 +00:00
QIcon icon ;
2013-12-26 21:44:02 +00:00
if ( item = = NULL )
{
2012-01-12 00:13:25 +00:00
item = new RSTreeWidgetItem ( compareRole , TYPE_LOBBY ) ;
2020-08-15 22:17:52 +02:00
icon = ( lobby . lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC ) ? FilesDefs : : getIconFromQtResourcePath ( IMAGE_PUBLIC ) : FilesDefs : : getIconFromQtResourcePath ( IMAGE_PRIVATE ) ;
2012-12-04 21:36:05 +00:00
lobby_item - > addChild ( item ) ;
2015-08-27 22:37:01 -04:00
2013-12-26 21:44:02 +00:00
}
else
{
2013-09-05 20:12:24 +00:00
if ( item - > data ( COLUMN_DATA , ROLE_SUBSCRIBED ) . toBool ( ) ! = subscribed ) {
// Replace icon
2020-08-15 22:17:52 +02:00
icon = ( lobby . lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC ) ? FilesDefs : : getIconFromQtResourcePath ( IMAGE_PUBLIC ) : FilesDefs : : getIconFromQtResourcePath ( IMAGE_PRIVATE ) ;
2013-09-05 20:12:24 +00:00
}
2012-01-12 00:13:25 +00:00
}
2013-09-05 20:12:24 +00:00
if ( ! icon . isNull ( ) ) {
2014-05-10 02:38:47 +00:00
item - > setIcon ( COLUMN_NAME , subscribed ? icon : icon . pixmap ( ui . lobbyTreeWidget - > iconSize ( ) , QIcon : : Disabled ) ) ;
2012-01-12 00:13:25 +00:00
}
2012-01-07 21:37:31 +00:00
2019-06-15 13:54:34 +02:00
// In the new model (after lobby save to disk) the auto-subscribe flag is used to automatically join lobbies that where
2019-06-15 22:44:59 +02:00
// previously being used when the t software quits.
2019-06-15 13:54:34 +02:00
2013-12-26 21:44:02 +00:00
bool autoSubscribe = rsMsgs - > getLobbyAutoSubscribe ( lobby . lobby_id ) ;
2013-06-29 16:15:33 +00:00
2019-06-15 22:44:59 +02:00
if ( autoSubscribe & & subscribed & & _lobby_infos . find ( lobby . lobby_id ) = = _lobby_infos . end ( ) )
2013-12-26 21:44:02 +00:00
{
2019-06-15 22:44:59 +02:00
ChatDialog * cd = ChatDialog : : getChat ( ChatId ( lobby . lobby_id ) , RS_CHAT_OPEN ) ;
addChatPage ( dynamic_cast < ChatLobbyDialog * > ( cd ) ) ;
2013-12-26 21:44:02 +00:00
}
2013-06-29 16:15:33 +00:00
2015-08-27 22:37:01 -04:00
updateItem ( ui . lobbyTreeWidget , item , lobby . lobby_id , lobby . lobby_name , lobby . lobby_topic , lobby . total_number_of_peers , subscribed , autoSubscribe , lobby_flags ) ;
2012-01-12 00:13:25 +00:00
}
2012-01-07 23:03:59 +00:00
2014-05-10 02:38:47 +00:00
// time_t now = time(NULL) ;
2013-02-27 22:17:49 +00:00
2012-12-04 21:36:05 +00:00
// Now add participating lobbies.
//
for ( lobbyIt = lobbies . begin ( ) ; lobbyIt ! = lobbies . end ( ) ; + + lobbyIt )
2015-03-06 21:13:23 +00:00
{
ChatLobbyInfo lobby ;
rsMsgs - > getChatLobbyInfo ( * lobbyIt , lobby ) ;
2012-01-12 00:13:25 +00:00
2012-01-23 22:49:47 +00:00
# ifdef CHAT_LOBBY_GUI_DEBUG
2012-03-16 22:47:49 +00:00
std : : cerr < < " adding " < < lobby . lobby_name < < " topic " < < lobby . lobby_topic < < " # " < < std : : hex < < lobby . lobby_id < < std : : dec < < " private " < < lobby . nick_names . size ( ) < < " peers. " < < std : : endl ;
2012-01-23 22:49:47 +00:00
# endif
2012-01-12 00:13:25 +00:00
QTreeWidgetItem * itemParent ;
2015-03-06 21:13:23 +00:00
if ( lobby . lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC )
2013-10-11 20:46:25 +00:00
itemParent = publicSubLobbyItem ;
2015-03-06 21:13:23 +00:00
else
2013-10-11 20:46:25 +00:00
itemParent = privateSubLobbyItem ;
2012-01-12 00:13:25 +00:00
QTreeWidgetItem * item = NULL ;
// search existing item
2012-12-04 21:36:05 +00:00
int childCount = itemParent - > childCount ( ) ;
2014-10-21 22:33:02 +00:00
for ( int childIndex = 0 ; childIndex < childCount ; + + childIndex ) {
2012-01-12 00:13:25 +00:00
QTreeWidgetItem * itemLoop = itemParent - > child ( childIndex ) ;
if ( itemLoop - > type ( ) = = TYPE_LOBBY & & itemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) = = lobby . lobby_id ) {
item = itemLoop ;
break ;
}
}
2013-09-05 20:12:24 +00:00
QIcon icon ;
2015-08-27 22:37:01 -04:00
ChatLobbyFlags lobby_flags = lobby . lobby_flags ;
if ( item = = NULL )
{
2015-03-06 21:13:23 +00:00
item = new RSTreeWidgetItem ( compareRole , TYPE_LOBBY ) ;
2020-08-15 22:17:52 +02:00
icon = ( lobby . lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC ) ? FilesDefs : : getIconFromQtResourcePath ( IMAGE_PUBLIC ) : FilesDefs : : getIconFromQtResourcePath ( IMAGE_PRIVATE ) ;
2015-03-06 21:13:23 +00:00
itemParent - > addChild ( item ) ;
} else {
if ( ! item - > data ( COLUMN_DATA , ROLE_SUBSCRIBED ) . toBool ( ) ) {
// Replace icon
2020-08-15 22:17:52 +02:00
icon = ( lobby . lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC ) ? FilesDefs : : getIconFromQtResourcePath ( IMAGE_PUBLIC ) : FilesDefs : : getIconFromQtResourcePath ( IMAGE_PRIVATE ) ;
2015-03-06 21:13:23 +00:00
}
}
2013-09-05 20:12:24 +00:00
if ( ! icon . isNull ( ) ) {
item - > setIcon ( COLUMN_NAME , icon ) ;
2012-01-12 00:13:25 +00:00
}
2014-05-10 02:38:47 +00:00
bool autoSubscribe = rsMsgs - > getLobbyAutoSubscribe ( lobby . lobby_id ) ;
2013-06-29 16:15:33 +00:00
2015-08-27 22:37:01 -04:00
updateItem ( ui . lobbyTreeWidget , item , lobby . lobby_id , lobby . lobby_name , lobby . lobby_topic , lobby . gxs_ids . size ( ) , true , autoSubscribe , lobby_flags ) ;
2019-06-15 13:54:34 +02:00
std : : map < ChatLobbyId , ChatLobbyInfoStruct > : : iterator it = _lobby_infos . find ( lobby . lobby_id ) ;
// look for chat rooms that are subscribed but not displayed as such
if ( it = = _lobby_infos . end ( ) & & rsMsgs - > joinVisibleChatLobby ( lobby . lobby_id , lobby . gxs_id ) )
{
std : : cerr < < " Adding back ChatLobbyDialog for subscribed lobby " < < std : : hex < < lobby . lobby_id < < std : : dec < < std : : endl ;
2019-06-15 22:44:59 +02:00
ChatDialog : : chatFriend ( ChatId ( lobby . lobby_id ) , true ) ;
2019-06-15 13:54:34 +02:00
}
2012-01-07 21:37:31 +00:00
}
2014-05-10 02:38:47 +00:00
publicSubLobbyItem - > setHidden ( publicSubLobbyItem - > childCount ( ) = = 0 ) ;
2017-03-21 15:02:46 +03:00
publicSubLobbyItem - > setText ( COLUMN_NAME , tr ( " Public Subscribed chat rooms " ) + QString ( " ( " ) + QString : : number ( publicSubLobbyItem - > childCount ( ) ) + QString ( " ) " ) ) ;
2014-05-10 02:38:47 +00:00
privateSubLobbyItem - > setHidden ( privateSubLobbyItem - > childCount ( ) = = 0 ) ;
2017-03-21 15:02:46 +03:00
publicLobbyItem - > setText ( COLUMN_NAME , tr ( " Public chat rooms " ) + " ( " + QString : : number ( publicLobbyItem - > childCount ( ) ) + QString ( " ) " ) ) ;
2012-01-07 21:37:31 +00:00
}
2012-01-07 21:01:43 +00:00
2012-01-12 00:13:25 +00:00
void ChatLobbyWidget : : createChatLobby ( )
2012-01-07 21:37:31 +00:00
{
2012-01-30 23:20:42 +00:00
int privacyLevel = 0 ;
QAction * action = qobject_cast < QAction * > ( sender ( ) ) ;
if ( action ) {
privacyLevel = action - > data ( ) . toInt ( ) ;
}
2015-04-17 21:36:22 +00:00
std : : set < RsPeerId > friends ;
2012-01-30 23:20:42 +00:00
CreateLobbyDialog ( friends , privacyLevel ) . exec ( ) ;
2012-01-12 00:13:25 +00:00
}
2013-02-24 22:44:14 +00:00
void ChatLobbyWidget : : showLobby ( QTreeWidgetItem * item )
{
2020-04-18 14:49:24 +02:00
if ( item = = nullptr | | item - > type ( ) ! = TYPE_LOBBY ) {
2013-02-24 22:44:14 +00:00
showBlankPage ( 0 ) ;
return ;
}
ChatLobbyId id = item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) ;
2013-02-27 22:17:49 +00:00
if ( _lobby_infos . find ( id ) = = _lobby_infos . end ( ) )
2013-02-24 22:44:14 +00:00
showBlankPage ( id ) ;
else
2020-04-18 14:49:24 +02:00
{
_lobby_infos [ id ] . dialog - > showDialog ( RS_CHAT_FOCUS ) ;
if ( _lobby_infos [ id ] . dialog - > isWindowed ( ) )
showBlankPage ( id , true ) ;
}
2013-02-24 22:44:14 +00:00
}
2015-04-17 21:36:22 +00:00
2015-05-17 10:13:32 +00:00
// this function is for the case where we don't have any identity yet
void ChatLobbyWidget : : createIdentityAndSubscribe ( )
{
QTreeWidgetItem * item = ui . lobbyTreeWidget - > currentItem ( ) ;
if ( ! item )
return ;
ChatLobbyId id = item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) ;
2015-08-27 22:37:01 -04:00
ChatLobbyFlags flags ( item - > data ( COLUMN_DATA , ROLE_FLAGS ) . toUInt ( ) ) ;
2015-05-17 10:13:32 +00:00
IdEditDialog dlg ( this ) ;
dlg . setupNewId ( false ) ;
2015-08-27 22:37:01 -04:00
if ( flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ) //
dlg . enforceNoAnonIds ( ) ;
2015-05-17 10:13:32 +00:00
dlg . exec ( ) ;
// fetch new id
std : : list < RsGxsId > own_ids ;
if ( ! rsIdentity - > getOwnIds ( own_ids ) | | own_ids . empty ( ) )
return ;
if ( rsMsgs - > joinVisibleChatLobby ( id , own_ids . front ( ) ) )
ChatDialog : : chatFriend ( ChatId ( id ) , true ) ;
}
2015-03-06 21:13:23 +00:00
void ChatLobbyWidget : : subscribeChatLobbyAs ( )
{
QTreeWidgetItem * item = ui . lobbyTreeWidget - > currentItem ( ) ;
if ( ! item )
return ;
ChatLobbyId id = item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) ;
2013-02-24 22:44:14 +00:00
2015-03-06 21:13:23 +00:00
QAction * action = qobject_cast < QAction * > ( QObject : : sender ( ) ) ;
if ( ! action )
return ;
RsGxsId gxs_id ( action - > data ( ) . toString ( ) . toStdString ( ) ) ;
2015-12-05 16:49:00 -05:00
//uint32_t error_code ;
2015-03-06 21:13:23 +00:00
if ( rsMsgs - > joinVisibleChatLobby ( id , gxs_id ) )
ChatDialog : : chatFriend ( ChatId ( id ) , true ) ;
}
2015-04-17 21:36:22 +00:00
2018-02-04 17:51:26 +01:00
bool ChatLobbyWidget : : showLobbyAnchor ( ChatLobbyId id , QString anchor )
2015-04-17 21:36:22 +00:00
{
QTreeWidgetItem * item = getTreeWidgetItem ( id ) ;
2020-04-18 14:49:24 +02:00
if ( item ! = nullptr ) {
2015-04-17 21:36:22 +00:00
if ( item - > type ( ) = = TYPE_LOBBY ) {
if ( _lobby_infos . find ( id ) = = _lobby_infos . end ( ) ) {
showBlankPage ( id ) ;
} else {
2020-04-18 14:49:24 +02:00
_lobby_infos [ id ] . dialog - > showDialog ( RS_CHAT_FOCUS ) ;
if ( _lobby_infos [ id ] . dialog - > isWindowed ( ) )
showBlankPage ( id , true ) ;
_lobby_infos [ id ] . dialog - > getChatWidget ( ) - > scrollToAnchor ( anchor ) ;
2015-04-17 21:36:22 +00:00
}
2018-02-04 17:51:26 +01:00
ui . lobbyTreeWidget - > setCurrentItem ( item ) ;
return true ;
2015-04-17 21:36:22 +00:00
}
}
2018-02-04 17:51:26 +01:00
return false ;
2015-04-17 21:36:22 +00:00
}
2015-03-06 21:13:23 +00:00
void ChatLobbyWidget : : subscribeChatLobbyAtItem ( QTreeWidgetItem * item )
2012-01-12 00:13:25 +00:00
{
2015-03-06 21:13:23 +00:00
if ( item = = NULL | | item - > type ( ) ! = TYPE_LOBBY ) {
return ;
}
2012-01-12 00:13:25 +00:00
2015-03-06 21:13:23 +00:00
ChatLobbyId id = item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) ;
2015-08-27 22:37:01 -04:00
ChatLobbyFlags flags ( item - > data ( COLUMN_DATA , ROLE_FLAGS ) . toUInt ( ) ) ;
2015-03-06 21:13:23 +00:00
RsGxsId gxs_id ;
2015-05-17 10:13:32 +00:00
std : : list < RsGxsId > own_ids ;
// not using rsMsgs->getDefaultIdentityForChatLobby(), to check if we have an identity
// to work around the case when the identity was deleted and is invalid
2015-06-01 08:52:58 +00:00
// (the chatservice does not know if a default identity was deleted)
2015-05-17 10:13:32 +00:00
// only rsIdentity knows the truth at the moment!
if ( ! rsIdentity - > getOwnIds ( own_ids ) )
return ;
// if there is no identity yet, show the dialog to create a new identity
if ( own_ids . empty ( ) )
{
IdEditDialog dlg ( this ) ;
dlg . setupNewId ( false ) ;
2015-08-27 22:37:01 -04:00
if ( flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ) //
dlg . enforceNoAnonIds ( ) ;
2015-05-17 10:13:32 +00:00
dlg . exec ( ) ;
// fetch new id
if ( ! rsIdentity - > getOwnIds ( own_ids ) | | own_ids . empty ( ) )
return ;
gxs_id = own_ids . front ( ) ;
}
else
2015-08-27 22:37:01 -04:00
{
2015-05-17 10:13:32 +00:00
rsMsgs - > getDefaultIdentityForChatLobby ( gxs_id ) ;
2015-08-27 22:37:01 -04:00
RsIdentityDetails idd ;
if ( ! rsIdentity - > getIdDetails ( gxs_id , idd ) )
return ;
2015-12-05 16:49:00 -05:00
if ( ( flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ) & & ! ( idd . mFlags & RS_IDENTITY_FLAGS_PGP_LINKED ) )
2015-08-27 22:37:01 -04:00
{
2017-01-21 21:38:10 +01:00
QMessageBox : : warning ( NULL , tr ( " Default identity is anonymous " ) , tr ( " You cannot join this chat room with your default identity, since it is anonymous and the chat room forbids it. " ) ) ;
2015-08-27 22:37:01 -04:00
return ;
}
}
2015-05-17 10:13:32 +00:00
if ( rsMsgs - > joinVisibleChatLobby ( id , gxs_id ) )
2014-12-29 21:41:05 +00:00
ChatDialog : : chatFriend ( ChatId ( id ) , true ) ;
2012-01-12 00:13:25 +00:00
}
2013-06-29 16:15:33 +00:00
void ChatLobbyWidget : : autoSubscribeLobby ( QTreeWidgetItem * item )
{
2015-01-05 20:00:32 +00:00
if ( item = = NULL | | item - > type ( ) ! = TYPE_LOBBY ) {
2013-06-29 16:15:33 +00:00
return ;
}
ChatLobbyId id = item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) ;
bool isAutoSubscribe = rsMsgs - > getLobbyAutoSubscribe ( id ) ;
rsMsgs - > setLobbyAutoSubscribe ( id , ! isAutoSubscribe ) ;
2017-07-19 13:38:26 +02:00
if ( ! isAutoSubscribe & & ! item - > data ( COLUMN_DATA , ROLE_SUBSCRIBED ) . toBool ( ) )
subscribeChatLobbyAtItem ( item ) ;
2013-06-29 16:15:33 +00:00
}
2020-04-18 14:49:24 +02:00
void ChatLobbyWidget : : showBlankPage ( ChatLobbyId id , bool subscribed /*= false*/ )
2013-02-24 22:44:14 +00:00
{
// show the default blank page.
2014-05-10 02:38:47 +00:00
ui . stackedWidget - > setCurrentWidget ( ui . _lobby_blank_page ) ;
2013-09-24 21:09:49 +00:00
2013-02-24 22:44:14 +00:00
// Update information
std : : vector < VisibleChatLobbyRecord > lobbies ;
2020-04-18 14:49:24 +02:00
rsMsgs - > getListOfNearbyChatLobbies ( lobbies ) ;
std : : list < RsGxsId > my_ids ;
rsIdentity - > getOwnIds ( my_ids ) ;
2015-03-07 14:49:33 +00:00
2020-04-18 14:49:24 +02:00
trimAnonIds ( my_ids ) ;
2013-02-24 22:44:14 +00:00
for ( std : : vector < VisibleChatLobbyRecord > : : const_iterator it ( lobbies . begin ( ) ) ; it ! = lobbies . end ( ) ; + + it )
if ( ( * it ) . lobby_id = = id )
{
2014-05-10 02:38:47 +00:00
ui . lobbyname_lineEdit - > setText ( RsHtml : : plainText ( it - > lobby_name ) ) ;
ui . lobbyid_lineEdit - > setText ( QString : : number ( ( * it ) . lobby_id , 16 ) ) ;
ui . lobbytopic_lineEdit - > setText ( RsHtml : : plainText ( it - > lobby_topic ) ) ;
2015-08-27 22:37:01 -04:00
ui . lobbytype_lineEdit - > setText ( ( ( ( * it ) . lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC ) ? tr ( " Public " ) : tr ( " Private " ) ) ) ;
2015-11-25 10:33:28 +00:00
ui . lobbysec_lineEdit - > setText ( ( ( ( * it ) . lobby_flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ) ? tr ( " No anonymous IDs " ) : tr ( " Anonymous IDs accepted " ) ) ) ;
2014-05-10 02:38:47 +00:00
ui . lobbypeers_lineEdit - > setText ( QString : : number ( ( * it ) . total_number_of_peers ) ) ;
2020-04-18 14:49:24 +02:00
QString text = tr ( " You're subscribed to this chat room; Double click to show window and chat. " ) ;
if ( ! subscribed )
{
text = tr ( " You're not subscribed to this chat room; Double click-it to enter and chat. " ) ;
2015-12-05 16:49:00 -05:00
if ( my_ids . empty ( ) )
{
if ( ( * it ) . lobby_flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED )
2017-01-21 21:38:10 +01:00
text + = " \n \n " + tr ( " You will need to create a non anonymous identity in order to join this chat room. " ) ;
2015-12-05 16:49:00 -05:00
else
2017-02-16 09:53:54 +01:00
text + = " \n \n " + tr ( " You will need to create an identity in order to join chat rooms. " ) ;
2015-12-05 16:49:00 -05:00
}
2020-04-18 14:49:24 +02:00
}
2015-03-07 14:49:33 +00:00
2020-04-18 14:49:24 +02:00
ui . lobbyInfoLabel - > setText ( text ) ;
2013-02-24 22:44:14 +00:00
return ;
}
2013-09-24 21:09:49 +00:00
2014-05-10 02:38:47 +00:00
ui . lobbyname_lineEdit - > clear ( ) ;
ui . lobbyid_lineEdit - > clear ( ) ;
ui . lobbytopic_lineEdit - > clear ( ) ;
ui . lobbytype_lineEdit - > clear ( ) ;
ui . lobbypeers_lineEdit - > clear ( ) ;
2015-08-27 22:37:01 -04:00
ui . lobbysec_lineEdit - > clear ( ) ;
2013-09-23 22:31:52 +00:00
2017-02-16 09:53:54 +01:00
QString text = tr ( " No chat room selected. \n Select chat rooms at left to show details. \n Double click a chat room to enter and chat. " ) ;
2014-12-06 22:09:44 +00:00
ui . lobbyInfoLabel - > setText ( text ) ;
2013-02-24 22:44:14 +00:00
}
2013-09-24 21:09:49 +00:00
2012-01-27 18:51:27 +00:00
void ChatLobbyWidget : : subscribeItem ( )
{
2015-03-06 21:13:23 +00:00
subscribeChatLobbyAtItem ( ui . lobbyTreeWidget - > currentItem ( ) ) ;
2012-01-27 18:51:27 +00:00
}
2013-06-29 16:15:33 +00:00
void ChatLobbyWidget : : autoSubscribeItem ( )
{
2015-03-06 21:13:23 +00:00
autoSubscribeLobby ( ui . lobbyTreeWidget - > currentItem ( ) ) ;
2013-06-29 16:15:33 +00:00
}
2018-02-04 17:51:26 +01:00
void ChatLobbyWidget : : copyItemLink ( )
{
QTreeWidgetItem * item = ui . lobbyTreeWidget - > currentItem ( ) ;
if ( item = = NULL | | item - > type ( ) ! = TYPE_LOBBY ) {
return ;
}
ChatLobbyId id = item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) ;
QString name = item - > text ( COLUMN_NAME ) ;
RetroShareLink link = RetroShareLink : : createChatRoom ( ChatId ( id ) , name ) ;
if ( link . valid ( ) ) {
QList < RetroShareLink > urls ;
urls . push_back ( link ) ;
RSLinkClipboard : : copyLinks ( urls ) ;
}
}
2013-02-24 22:44:14 +00:00
QTreeWidgetItem * ChatLobbyWidget : : getTreeWidgetItem ( ChatLobbyId id )
{
2013-10-11 20:46:25 +00:00
for ( int p = 0 ; p < 4 ; + + p )
2013-02-24 22:44:14 +00:00
{
2013-10-11 20:46:25 +00:00
QTreeWidgetItem * lobby_item = NULL ;
switch ( p ) {
case 0 : lobby_item = privateSubLobbyItem ; break ;
case 1 : lobby_item = publicSubLobbyItem ; break ;
case 2 : lobby_item = privateLobbyItem ; break ;
2015-06-15 17:45:15 +00:00
case 3 : lobby_item = publicLobbyItem ; break ;
2013-10-11 20:46:25 +00:00
default : lobby_item = publicLobbyItem ;
}
//QTreeWidgetItem *lobby_item = (p==0)?publicLobbyItem:privateLobbyItem ;
2013-02-24 22:44:14 +00:00
int childCnt = lobby_item - > childCount ( ) ;
int childIndex = 0 ;
while ( childIndex < childCnt ) {
QTreeWidgetItem * itemLoop = lobby_item - > child ( childIndex ) ;
if ( itemLoop - > type ( ) = = TYPE_LOBBY & & itemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) = = id )
return itemLoop ;
2013-02-24 22:55:58 +00:00
+ + childIndex ;
2013-02-24 22:44:14 +00:00
}
}
return NULL ;
}
void ChatLobbyWidget : : updateTypingStatus ( ChatLobbyId id )
{
QTreeWidgetItem * item = getTreeWidgetItem ( id ) ;
if ( item ! = NULL )
{
2020-08-15 22:17:52 +02:00
item - > setIcon ( COLUMN_NAME , FilesDefs : : getIconFromQtResourcePath ( IMAGE_TYPING ) ) ;
2013-02-27 22:17:49 +00:00
_lobby_infos [ id ] . last_typing_event = time ( NULL ) ;
2013-02-24 22:44:14 +00:00
2013-02-27 22:17:49 +00:00
QTimer : : singleShot ( 5000 , this , SLOT ( resetLobbyTreeIcons ( ) ) ) ;
}
}
void ChatLobbyWidget : : updatePeerLeaving ( ChatLobbyId id )
{
QTreeWidgetItem * item = getTreeWidgetItem ( id ) ;
if ( item ! = NULL )
{
2020-08-15 22:17:52 +02:00
item - > setIcon ( COLUMN_NAME , FilesDefs : : getIconFromQtResourcePath ( IMAGE_PEER_LEAVING ) ) ;
2013-02-27 22:17:49 +00:00
_lobby_infos [ id ] . last_typing_event = time ( NULL ) ;
2013-02-24 22:44:14 +00:00
QTimer : : singleShot ( 5000 , this , SLOT ( resetLobbyTreeIcons ( ) ) ) ;
}
}
2013-02-27 22:17:49 +00:00
void ChatLobbyWidget : : updatePeerEntering ( ChatLobbyId id )
{
QTreeWidgetItem * item = getTreeWidgetItem ( id ) ;
if ( item ! = NULL )
{
2020-08-15 22:17:52 +02:00
item - > setIcon ( COLUMN_NAME , FilesDefs : : getIconFromQtResourcePath ( IMAGE_PEER_ENTERING ) ) ;
2013-02-27 22:17:49 +00:00
_lobby_infos [ id ] . last_typing_event = time ( NULL ) ;
2013-02-24 22:44:14 +00:00
2013-02-27 22:17:49 +00:00
QTimer : : singleShot ( 5000 , this , SLOT ( resetLobbyTreeIcons ( ) ) ) ;
}
}
2013-02-24 22:44:14 +00:00
void ChatLobbyWidget : : resetLobbyTreeIcons ( )
{
time_t now = time ( NULL ) ;
2013-02-27 22:17:49 +00:00
for ( std : : map < ChatLobbyId , ChatLobbyInfoStruct > : : iterator it ( _lobby_infos . begin ( ) ) ; it ! = _lobby_infos . end ( ) ; + + it )
if ( it - > second . last_typing_event + 5 < = now )
2013-02-24 22:44:14 +00:00
{
2013-08-26 23:37:13 +00:00
getTreeWidgetItem ( it - > first ) - > setIcon ( COLUMN_NAME , it - > second . default_icon ) ;
2014-05-10 02:38:47 +00:00
//std::cerr << "Reseted 1 lobby icon." << std::endl;
2013-02-24 22:44:14 +00:00
}
}
2012-01-12 00:13:25 +00:00
void ChatLobbyWidget : : unsubscribeItem ( )
{
2014-05-10 02:38:47 +00:00
QTreeWidgetItem * item = ui . lobbyTreeWidget - > currentItem ( ) ;
2015-01-05 20:00:32 +00:00
if ( item = = NULL | | item - > type ( ) ! = TYPE_LOBBY ) {
2012-01-12 00:13:25 +00:00
return ;
}
const ChatLobbyId id = item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) ;
2013-02-24 22:44:14 +00:00
unsubscribeChatLobby ( id ) ;
}
void ChatLobbyWidget : : unsubscribeChatLobby ( ChatLobbyId id )
{
2017-01-21 21:38:10 +01:00
std : : cerr < < " Unsubscribing from chat room " < < std : : endl ;
2013-02-24 22:44:14 +00:00
// close the tab.
2013-02-27 22:17:49 +00:00
std : : map < ChatLobbyId , ChatLobbyInfoStruct > : : iterator it = _lobby_infos . find ( id ) ;
2013-02-24 22:44:14 +00:00
2013-02-27 22:17:49 +00:00
if ( it ! = _lobby_infos . end ( ) )
2013-02-24 22:44:14 +00:00
{
2015-04-17 21:36:22 +00:00
if ( myChatLobbyUserNotify ) {
myChatLobbyUserNotify - > chatLobbyCleared ( id , " " ) ;
}
2014-05-10 02:38:47 +00:00
ui . stackedWidget - > removeWidget ( it - > second . dialog ) ;
2020-04-18 14:49:24 +02:00
disconnect ( it - > second . dialog , SIGNAL ( dialogClose ( ChatDialog * ) ) , this , SLOT ( dialogClose ( ChatDialog * ) ) ) ;
it - > second . dialog - > leaveLobby ( ) ;
2013-02-27 22:17:49 +00:00
_lobby_infos . erase ( it ) ;
2013-02-24 22:44:14 +00:00
}
2014-05-10 02:38:47 +00:00
2013-02-24 22:44:14 +00:00
// Unsubscribe the chat lobby
2014-12-29 21:41:05 +00:00
ChatDialog : : closeChat ( ChatId ( id ) ) ;
2012-01-12 00:13:25 +00:00
rsMsgs - > unsubscribeChatLobby ( id ) ;
2013-06-29 16:15:33 +00:00
bool isAutoSubscribe = rsMsgs - > getLobbyAutoSubscribe ( id ) ;
2014-05-10 02:38:47 +00:00
if ( isAutoSubscribe ) rsMsgs - > setLobbyAutoSubscribe ( id , ! isAutoSubscribe ) ;
2013-06-29 16:15:33 +00:00
2014-05-10 02:38:47 +00:00
ChatLobbyDialog * cldCW = NULL ;
if ( NULL ! = ( cldCW = dynamic_cast < ChatLobbyDialog * > ( ui . stackedWidget - > currentWidget ( ) ) ) )
{
2013-08-28 21:13:35 +00:00
2014-05-10 02:38:47 +00:00
QTreeWidgetItem * qtwiFound = getTreeWidgetItem ( cldCW - > id ( ) ) ;
if ( qtwiFound ) {
ui . lobbyTreeWidget - > setCurrentItem ( qtwiFound ) ;
}
} else {
ui . lobbyTreeWidget - > clearSelection ( ) ;
2013-08-28 21:13:35 +00:00
2014-05-10 02:38:47 +00:00
}
2012-01-12 00:13:25 +00:00
}
2013-02-24 22:44:14 +00:00
void ChatLobbyWidget : : updateCurrentLobby ( )
2012-01-12 00:13:25 +00:00
{
2014-05-10 02:38:47 +00:00
QList < QTreeWidgetItem * > items = ui . lobbyTreeWidget - > selectedItems ( ) ;
2013-02-24 22:44:14 +00:00
if ( items . empty ( ) )
showLobby ( 0 ) ;
else
2013-02-27 22:17:49 +00:00
{
2013-08-26 23:37:13 +00:00
QTreeWidgetItem * item = items . front ( ) ;
showLobby ( item ) ;
2013-02-28 21:47:37 +00:00
2013-08-26 23:37:13 +00:00
ChatLobbyId id = item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) ;
2013-02-28 21:47:37 +00:00
2013-08-26 23:37:13 +00:00
if ( _lobby_infos . find ( id ) ! = _lobby_infos . end ( ) ) {
2013-10-11 20:46:25 +00:00
int iPrivacyLevel = item - > parent ( ) - > data ( COLUMN_DATA , ROLE_PRIVACYLEVEL ) . toInt ( ) ;
2020-08-15 22:17:52 +02:00
QIcon icon = ( iPrivacyLevel = = CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC ) ? FilesDefs : : getIconFromQtResourcePath ( IMAGE_PUBLIC ) : FilesDefs : : getIconFromQtResourcePath ( IMAGE_PRIVATE ) ;
2013-08-26 23:37:13 +00:00
_lobby_infos [ id ] . default_icon = icon ;
item - > setIcon ( COLUMN_NAME , icon ) ;
}
2013-02-27 22:17:49 +00:00
}
2014-05-10 02:38:47 +00:00
if ( ui . filterLineEdit - > text ( ) . isEmpty ( ) = = false ) {
filterItems ( ui . filterLineEdit - > text ( ) ) ;
2013-09-02 00:08:38 +00:00
}
2013-02-27 22:17:49 +00:00
}
2015-04-17 21:36:22 +00:00
void ChatLobbyWidget : : updateMessageChanged ( bool incoming , ChatLobbyId id , QDateTime time , QString senderName , QString msg )
2013-02-27 22:17:49 +00:00
{
2014-05-10 02:38:47 +00:00
QTreeWidgetItem * current_item = ui . lobbyTreeWidget - > currentItem ( ) ;
2015-04-17 21:36:22 +00:00
bool bIsCurrentItem = ( current_item ! = NULL & & current_item - > data ( COLUMN_DATA , ROLE_ID ) . toULongLong ( ) = = id ) ;
if ( myChatLobbyUserNotify ) {
if ( incoming ) myChatLobbyUserNotify - > chatLobbyNewMessage ( id , time , senderName , msg ) ;
}
2013-03-03 21:41:56 +00:00
// Don't show anything for current lobby.
//
2015-04-17 21:36:22 +00:00
if ( bIsCurrentItem )
2013-03-03 21:41:56 +00:00
return ;
2020-08-15 22:17:52 +02:00
_lobby_infos [ id ] . default_icon = FilesDefs : : getIconFromQtResourcePath ( IMAGE_MESSAGE ) ;
2013-02-27 22:17:49 +00:00
QTreeWidgetItem * item = getTreeWidgetItem ( id ) ;
2013-03-01 20:51:40 +00:00
if ( item = = NULL )
return ;
2013-08-26 23:37:13 +00:00
item - > setIcon ( COLUMN_NAME , _lobby_infos [ id ] . default_icon ) ;
2012-01-12 00:13:25 +00:00
}
2013-02-24 22:44:14 +00:00
void ChatLobbyWidget : : itemDoubleClicked ( QTreeWidgetItem * item , int /*column*/ )
2013-02-22 21:42:27 +00:00
{
2015-03-06 21:13:23 +00:00
subscribeChatLobbyAtItem ( item ) ;
2013-02-22 21:42:27 +00:00
}
2016-02-14 11:53:27 +01:00
void ChatLobbyWidget : : displayChatLobbyEvent ( qulonglong lobby_id , int event_type , const RsGxsId & gxs_id , const QString & str )
2012-01-12 00:13:25 +00:00
{
2014-12-29 21:41:05 +00:00
if ( ChatLobbyDialog * cld = dynamic_cast < ChatLobbyDialog * > ( ChatDialog : : getExistingChat ( ChatId ( lobby_id ) ) ) ) {
2016-02-14 11:53:27 +01:00
cld - > displayLobbyEvent ( event_type , gxs_id , str ) ;
2014-12-29 21:41:05 +00:00
}
2012-01-07 19:52:58 +00:00
}
2012-01-12 00:13:25 +00:00
void ChatLobbyWidget : : readChatLobbyInvites ( )
{
2015-03-06 21:13:23 +00:00
std : : list < ChatLobbyInvite > invites ;
rsMsgs - > getPendingChatLobbyInvites ( invites ) ;
2012-01-12 00:13:25 +00:00
2015-03-06 21:13:23 +00:00
RsGxsId default_id ;
rsMsgs - > getDefaultIdentityForChatLobby ( default_id ) ;
2012-01-12 00:13:25 +00:00
2018-01-03 15:01:04 +01:00
std : : list < ChatLobbyId > subscribed_lobbies ;
rsMsgs - > getChatLobbyList ( subscribed_lobbies ) ;
2018-01-05 14:45:29 +01:00
for ( std : : list < ChatLobbyInvite > : : const_iterator it ( invites . begin ( ) ) ; it ! = invites . end ( ) ; + + it )
{
2018-01-03 15:01:04 +01:00
// first check if the lobby is already subscribed. If so, just ignore the request.
bool found = false ;
for ( auto it2 ( subscribed_lobbies . begin ( ) ) ; it2 ! = subscribed_lobbies . end ( ) & & ! found ; + + it2 )
found = found | | ( * it2 = = ( * it ) . lobby_id ) ;
if ( found )
continue ;
2017-01-21 21:38:10 +01:00
QMessageBox mb ( QObject : : tr ( " Join chat room " ) ,
tr ( " %1 invites you to chat room named %2 " ) . arg ( QString : : fromUtf8 ( rsPeers - > getPeerName ( ( * it ) . peer_id ) . c_str ( ) ) ) . arg ( RsHtml : : plainText ( it - > lobby_name ) ) ,
2015-03-06 21:13:23 +00:00
QMessageBox : : Question , QMessageBox : : Yes , QMessageBox : : No , 0 ) ;
2012-01-07 19:52:58 +00:00
2016-08-06 13:49:39 +02:00
2018-01-05 14:45:29 +01:00
QLabel * label ;
GxsIdChooser * idchooser = new GxsIdChooser ;
2015-03-06 21:13:23 +00:00
2018-01-03 14:05:13 +01:00
if ( ( * it ) . lobby_flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED )
{
idchooser - > loadIds ( IDCHOOSER_ID_REQUIRED | IDCHOOSER_NON_ANONYMOUS , default_id ) ;
label = new QLabel ( tr ( " Choose a non anonymous identity for this chat room: " ) ) ;
}
else
{
idchooser - > loadIds ( IDCHOOSER_ID_REQUIRED , default_id ) ;
label = new QLabel ( tr ( " Choose an identity for this chat room: " ) ) ;
}
2018-01-05 14:45:29 +01:00
myInviteYesButton = mb . button ( QMessageBox : : Yes ) ;
myInviteIdChooser = idchooser ;
connect ( idchooser , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( idChooserCurrentIndexChanged ( int ) ) ) ;
idChooserCurrentIndexChanged ( 0 ) ;
QGridLayout * layout = qobject_cast < QGridLayout * > ( mb . layout ( ) ) ;
if ( layout ) {
layout - > addWidget ( label , layout - > rowCount ( ) , 0 , 1 , layout - > columnCount ( ) , Qt : : AlignHCenter ) ;
layout - > addWidget ( idchooser , layout - > rowCount ( ) , 0 , 1 , layout - > columnCount ( ) , Qt : : AlignRight ) ;
} else {
//Not QGridLayout so add at end
mb . layout ( ) - > addWidget ( label ) ;
mb . layout ( ) - > addWidget ( idchooser ) ;
}
2016-08-06 13:49:39 +02:00
2018-01-05 14:45:29 +01:00
int res = mb . exec ( ) ;
myInviteYesButton = NULL ;
myInviteIdChooser = NULL ;
2015-03-06 21:13:23 +00:00
if ( res = = QMessageBox : : No )
{
rsMsgs - > denyLobbyInvite ( ( * it ) . lobby_id ) ;
continue ;
}
RsGxsId chosen_id ;
idchooser - > getChosenId ( chosen_id ) ;
if ( chosen_id . isNull ( ) )
{
rsMsgs - > denyLobbyInvite ( ( * it ) . lobby_id ) ;
continue ;
}
2016-01-10 14:22:06 +01:00
if ( rsMsgs - > acceptLobbyInvite ( ( * it ) . lobby_id , chosen_id ) )
2015-03-06 21:13:23 +00:00
ChatDialog : : chatFriend ( ChatId ( ( * it ) . lobby_id ) , true ) ;
else
2017-01-21 21:38:10 +01:00
std : : cerr < < " Can't join chat room with id 0x " < < std : : hex < < ( * it ) . lobby_id < < std : : dec < < std : : endl ;
2015-03-06 21:13:23 +00:00
}
2018-01-05 14:45:29 +01:00
myInviteYesButton = NULL ;
myInviteIdChooser = NULL ;
}
void ChatLobbyWidget : : idChooserCurrentIndexChanged ( int /*index*/ )
{
if ( myInviteYesButton & & myInviteIdChooser )
{
RsGxsId chosen_id ;
switch ( myInviteIdChooser - > getChosenId ( chosen_id ) )
{
case GxsIdChooser : : KnowId :
case GxsIdChooser : : UnKnowId :
myInviteYesButton - > setEnabled ( true ) ;
break ;
case GxsIdChooser : : NoId :
case GxsIdChooser : : None :
default : ;
myInviteYesButton - > setEnabled ( false ) ;
}
}
2012-01-12 00:13:25 +00:00
}
2013-09-02 00:08:38 +00:00
void ChatLobbyWidget : : filterColumnChanged ( int )
{
2014-05-10 02:38:47 +00:00
filterItems ( ui . filterLineEdit - > text ( ) ) ;
2013-09-02 00:08:38 +00:00
}
void ChatLobbyWidget : : filterItems ( const QString & text )
{
2014-05-10 02:38:47 +00:00
int filterColumn = ui . filterLineEdit - > currentFilter ( ) ;
2013-09-02 00:08:38 +00:00
2014-05-10 02:38:47 +00:00
int count = ui . lobbyTreeWidget - > topLevelItemCount ( ) ;
2014-10-21 22:33:02 +00:00
for ( int index = 0 ; index < count ; + + index ) {
2014-05-10 02:38:47 +00:00
filterItem ( ui . lobbyTreeWidget - > topLevelItem ( index ) , text , filterColumn ) ;
}
2013-09-02 00:08:38 +00:00
}
bool ChatLobbyWidget : : filterItem ( QTreeWidgetItem * item , const QString & text , int filterColumn )
{
bool visible = true ;
if ( text . isEmpty ( ) = = false ) {
if ( item - > text ( filterColumn ) . contains ( text , Qt : : CaseInsensitive ) = = false ) {
visible = false ;
}
}
int visibleChildCount = 0 ;
int count = item - > childCount ( ) ;
2014-10-21 22:33:02 +00:00
for ( int index = 0 ; index < count ; + + index ) {
2013-09-02 00:08:38 +00:00
if ( filterItem ( item - > child ( index ) , text , filterColumn ) ) {
2014-10-21 22:33:02 +00:00
+ + visibleChildCount ;
2013-09-02 00:08:38 +00:00
}
}
if ( visible | | visibleChildCount ) {
item - > setHidden ( false ) ;
} else {
item - > setHidden ( true ) ;
}
return ( visible | | visibleChildCount ) ;
}
2013-09-19 19:22:17 +00:00
void ChatLobbyWidget : : processSettings ( bool bLoad )
{
2014-05-10 02:38:47 +00:00
m_bProcessSettings = true ;
2013-09-19 19:22:17 +00:00
2014-05-10 02:38:47 +00:00
QHeaderView * Header = ui . lobbyTreeWidget - > header ( ) ;
2013-09-19 19:22:17 +00:00
2014-05-10 02:38:47 +00:00
Settings - > beginGroup ( QString ( " ChatLobbyWidget " ) ) ;
2013-09-19 19:22:17 +00:00
if ( bLoad ) {
// load settings
2017-01-24 17:51:57 +03:00
ui . splitter - > restoreState ( Settings - > value ( " splitter " ) . toByteArray ( ) ) ;
2014-05-10 02:38:47 +00:00
// state of the lists
Header - > restoreState ( Settings - > value ( " lobbyList " ) . toByteArray ( ) ) ;
2013-09-19 19:22:17 +00:00
2014-05-10 02:38:47 +00:00
setShowUserCountColumn ( Settings - > value ( " showUserCountColumn " , ! ui . lobbyTreeWidget - > isColumnHidden ( COLUMN_USER_COUNT ) ) . toBool ( ) ) ;
setShowTopicColumn ( Settings - > value ( " showTopicColumn " , ! ui . lobbyTreeWidget - > isColumnHidden ( COLUMN_TOPIC ) ) . toBool ( ) ) ;
} else {
// save settings
2017-01-24 17:51:57 +03:00
Settings - > setValue ( " splitter " , ui . splitter - > saveState ( ) ) ;
2014-05-10 02:38:47 +00:00
// state of the lists
Settings - > setValue ( " lobbyList " , Header - > saveState ( ) ) ;
2013-09-19 19:22:17 +00:00
2014-05-10 02:38:47 +00:00
Settings - > setValue ( " showUserCountColumn " , ! ui . lobbyTreeWidget - > isColumnHidden ( COLUMN_USER_COUNT ) ) ;
Settings - > setValue ( " showTopicColumn " , ! ui . lobbyTreeWidget - > isColumnHidden ( COLUMN_TOPIC ) ) ;
}
2013-09-19 19:22:17 +00:00
2014-05-10 02:38:47 +00:00
Settings - > endGroup ( ) ;
2013-09-19 19:22:17 +00:00
m_bProcessSettings = false ;
}
void ChatLobbyWidget : : setShowUserCountColumn ( bool show )
{
2014-05-10 02:38:47 +00:00
if ( ui . lobbyTreeWidget - > isColumnHidden ( COLUMN_USER_COUNT ) = = show ) {
ui . lobbyTreeWidget - > setColumnHidden ( COLUMN_USER_COUNT , ! show ) ;
}
ui . lobbyTreeWidget - > header ( ) - > setVisible ( getNumColVisible ( ) > 1 ) ;
2013-09-19 19:22:17 +00:00
}
void ChatLobbyWidget : : setShowTopicColumn ( bool show )
{
2014-05-10 02:38:47 +00:00
if ( ui . lobbyTreeWidget - > isColumnHidden ( COLUMN_TOPIC ) = = show ) {
ui . lobbyTreeWidget - > setColumnHidden ( COLUMN_TOPIC , ! show ) ;
}
ui . lobbyTreeWidget - > header ( ) - > setVisible ( getNumColVisible ( ) > 1 ) ;
2013-09-19 19:22:17 +00:00
}
2013-10-11 20:46:25 +00:00
int ChatLobbyWidget : : getNumColVisible ( )
{
2014-05-10 02:38:47 +00:00
int iNumColVis = 0 ;
for ( int iColumn = 0 ; iColumn < COLUMN_COUNT ; + + iColumn ) {
if ( ! ui . lobbyTreeWidget - > isColumnHidden ( iColumn ) ) {
+ + iNumColVis ;
}
}
2013-10-11 20:46:25 +00:00
return iNumColVis ;
2013-09-19 19:22:17 +00:00
}