2010-05-14 07:48:20 -04:00
/****************************************************************
2007-11-14 22:18:48 -05:00
* RetroShare is distributed under the following license :
*
2011-05-17 13:27:47 -04:00
* Copyright ( C ) 2006 - 2011 RetroShare Team
2007-11-14 22:18:48 -05:00
*
* 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
2009-07-13 15:58:11 -04:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2007-11-14 22:18:48 -05:00
* Boston , MA 02110 - 1301 , USA .
2008-11-24 09:07:26 -05:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-14 22:18:48 -05:00
2011-10-20 17:34:44 -04:00
# include <sstream>
# include <time.h>
# include <sys/stat.h>
# include <algorithm>
2010-07-23 14:52:58 -04:00
# include <QColorDialog>
# include <QDropEvent>
2011-10-20 17:34:44 -04:00
# include <QFontDialog>
# include <QMenu>
# include <QScrollBar>
2008-11-24 09:07:26 -05:00
2010-09-04 10:23:30 -04:00
# include "retroshare/rsinit.h"
2011-10-20 17:34:44 -04:00
# include "retroshare/rsnotify.h"
# include "retroshare/rspeers.h"
2011-09-29 05:20:09 -04:00
# include <retroshare/rshistory.h>
2008-01-25 03:49:40 -05:00
2011-10-20 17:34:44 -04:00
# include "channels/CreateChannel.h"
# include "common/Emoticons.h"
# include "common/vmessagebox.h"
2012-01-17 15:36:36 -05:00
# include "chat/ChatDialog.h"
2007-11-14 22:18:48 -05:00
# include "connect/ConfCertDialog.h"
2010-09-19 20:10:51 -04:00
# include "connect/ConnectFriendWizard.h"
# include "forums/CreateForum.h"
2011-10-20 17:34:44 -04:00
# include "gui/common/AvatarDefs.h"
# include "gui/mainpagestack.h"
2010-09-21 12:11:19 -04:00
# include "groups/CreateGroup.h"
2010-09-19 20:10:51 -04:00
# include "im_history/ImHistoryBrowser.h"
2010-05-02 20:09:55 -04:00
# include "MainWindow.h"
2010-08-12 12:00:21 -04:00
# include "NewsFeed.h"
2012-01-07 14:52:58 -05:00
# include "ChatLobbyWidget.h"
2011-10-20 17:34:44 -04:00
# include "notifyqt.h"
# include "profile/ProfileWidget.h"
# include "profile/StatusMessage.h"
# include "RetroShareLink.h"
# include "settings/rsharesettings.h"
2010-12-02 19:54:40 -05:00
# include "util/misc.h"
2012-01-12 11:24:36 -05:00
# include "chat/CreateLobbyDialog.h"
2010-05-02 20:09:55 -04:00
2011-10-20 17:34:44 -04:00
# include "FriendsDialog.h"
2010-05-05 07:47:29 -04:00
2011-10-20 17:34:44 -04:00
/* Images for Newsfeed icons */
2010-11-10 07:24:36 -05:00
# define IMAGE_NEWSFEED ""
# define IMAGE_NEWSFEED_NEW ": / images / message-state-new.png"
2008-11-24 09:07:26 -05:00
2008-07-09 05:53:47 -04:00
/******
2011-05-24 19:35:11 -04:00
* # define FRIENDS_DEBUG 1
2008-07-09 05:53:47 -04:00
* * * * */
2012-01-18 15:02:19 -05:00
static FriendsDialog * instance = NULL ;
2008-11-24 09:07:26 -05:00
/** Constructor */
2011-05-17 13:27:47 -04:00
FriendsDialog : : FriendsDialog ( QWidget * parent )
2010-09-04 10:23:30 -04:00
: RsAutoUpdatePage ( 1500 , parent )
2008-11-24 09:07:26 -05:00
{
2010-09-04 10:23:30 -04:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2009-09-30 18:30:57 -04:00
2012-01-18 15:02:19 -05:00
if ( instance = = NULL ) {
instance = this ;
}
2010-09-04 10:23:30 -04:00
last_status_send_time = 0 ;
2007-11-14 22:18:48 -05:00
2010-09-04 10:23:30 -04:00
connect ( ui . mypersonalstatuslabel , SIGNAL ( clicked ( ) ) , SLOT ( statusmessage ( ) ) ) ;
connect ( ui . actionSet_your_Avatar , SIGNAL ( triggered ( ) ) , this , SLOT ( getAvatar ( ) ) ) ;
connect ( ui . actionSet_your_Personal_Message , SIGNAL ( triggered ( ) ) , this , SLOT ( statusmessage ( ) ) ) ;
connect ( ui . addfileButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
2012-01-12 11:24:36 -05:00
connect ( ui . actionAdd_Friend , SIGNAL ( triggered ( ) ) , this , SLOT ( addFriend ( ) ) ) ;
connect ( ui . actionCreate_new_Chat_lobby , SIGNAL ( triggered ( ) ) , this , SLOT ( createChatLobby ( ) ) ) ;
2011-10-20 17:34:44 -04:00
2011-09-05 17:19:07 -04:00
ui . avatar - > setFrameType ( AvatarWidget : : STATUS_FRAME ) ;
ui . avatar - > setOwnId ( ) ;
2012-01-18 15:02:19 -05:00
ui . tabWidget - > setTabPosition ( QTabWidget : : North ) ;
ui . tabWidget - > addTab ( new ChatLobbyWidget ( ) , tr ( " Chat lobbies " ) ) ;
ui . tabWidget - > addTab ( new ProfileWidget ( ) , tr ( " Profile " ) ) ;
2012-01-25 16:45:23 -05:00
newsFeed = new NewsFeed ( ) ;
int newsFeedTabIndex = ui . tabWidget - > addTab ( newsFeed , tr ( " News Feed " ) ) ;
2012-01-18 15:02:19 -05:00
ui . tabWidget - > hideCloseButton ( 0 ) ;
ui . tabWidget - > hideCloseButton ( 1 ) ;
ui . tabWidget - > hideCloseButton ( 2 ) ;
ui . tabWidget - > hideCloseButton ( 3 ) ;
2010-11-10 07:24:36 -05:00
/* get the current text and text color of the tab bar */
2012-01-18 15:02:19 -05:00
newsFeedTabColor = ui . tabWidget - > tabBar ( ) - > tabTextColor ( newsFeedTabIndex ) ;
newsFeedText = ui . tabWidget - > tabBar ( ) - > tabText ( newsFeedTabIndex ) ;
2010-11-10 07:24:36 -05:00
connect ( newsFeed , SIGNAL ( newsFeedChanged ( int ) ) , this , SLOT ( newsFeedChanged ( int ) ) ) ;
2009-09-25 21:10:25 -04:00
2010-09-04 10:23:30 -04:00
connect ( ui . Sendbtn , SIGNAL ( clicked ( ) ) , this , SLOT ( sendMsg ( ) ) ) ;
connect ( ui . emoticonBtn , SIGNAL ( clicked ( ) ) , this , SLOT ( smileyWidgetgroupchat ( ) ) ) ;
2008-07-10 06:34:49 -04:00
2010-09-04 10:23:30 -04:00
connect ( ui . lineEdit , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
2010-03-17 11:34:36 -04:00
2010-09-04 10:23:30 -04:00
connect ( ui . textboldChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textunderlineChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textitalicChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . fontsButton , SIGNAL ( clicked ( ) ) , this , SLOT ( getFont ( ) ) ) ;
connect ( ui . colorChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setColor ( ) ) ) ;
connect ( ui . actionSave_History , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSaveAs ( ) ) ) ;
2009-07-13 15:58:11 -04:00
2011-12-07 08:08:12 -05:00
connect ( ui . hashBox , SIGNAL ( fileHashingFinished ( QList < HashedFile > ) ) , this , SLOT ( fileHashingFinished ( QList < HashedFile > ) ) ) ;
2010-09-04 10:23:30 -04:00
ui . fontsButton - > setIcon ( QIcon ( QString ( " :/images/fonts.png " ) ) ) ;
2009-07-13 15:58:11 -04:00
2010-10-07 20:07:44 -04:00
mCurrentColor = Qt : : black ;
2010-09-10 14:38:46 -04:00
mCurrentFont . fromString ( Settings - > getChatScreenFont ( ) ) ;
2010-10-07 20:07:44 -04:00
colorChanged ( mCurrentColor ) ;
fontChanged ( mCurrentFont ) ;
2010-09-04 10:23:30 -04:00
2010-09-07 11:49:31 -04:00
style . setStyleFromSettings ( ChatStyle : : TYPE_PUBLIC ) ;
2010-09-04 10:23:30 -04:00
setChatInfo ( tr ( " Welcome to RetroShare's group chat. " ) , QString : : fromUtf8 ( " blue " ) ) ;
2011-09-29 05:20:09 -04:00
if ( rsHistory - > getEnable ( true ) ) {
2010-11-06 20:22:46 -04:00
int messageCount = Settings - > getPublicChatHistoryCount ( ) ;
if ( messageCount > 0 ) {
2011-09-29 05:20:09 -04:00
std : : list < HistoryMsg > historyMsgs ;
rsHistory - > getMessages ( " " , historyMsgs , messageCount ) ;
std : : list < HistoryMsg > : : iterator it ;
for ( it = historyMsgs . begin ( ) ; it ! = historyMsgs . end ( ) ; it + + ) {
addChatMsg ( it - > incoming , true , QString : : fromUtf8 ( it - > peerName . c_str ( ) ) , QDateTime : : fromTime_t ( it - > sendTime ) , QDateTime : : fromTime_t ( it - > recvTime ) , QString : : fromUtf8 ( it - > message . c_str ( ) ) ) ;
2010-11-06 20:22:46 -04:00
}
2010-09-04 10:23:30 -04:00
}
}
QMenu * grpchatmenu = new QMenu ( ) ;
2011-02-08 16:59:17 -05:00
grpchatmenu - > addAction ( ui . actionClear_Chat_History ) ;
grpchatmenu - > addAction ( ui . actionDelete_Chat_History ) ;
2010-09-04 10:23:30 -04:00
grpchatmenu - > addAction ( ui . actionSave_History ) ;
grpchatmenu - > addAction ( ui . actionMessageHistory ) ;
ui . menuButton - > setMenu ( grpchatmenu ) ;
QMenu * menu = new QMenu ( ) ;
menu - > addAction ( ui . actionAdd_Friend ) ;
2010-09-21 12:11:19 -04:00
menu - > addAction ( ui . actionAdd_Group ) ;
2012-01-12 11:24:36 -05:00
menu - > addAction ( ui . actionCreate_new_Chat_lobby ) ;
2010-09-21 12:11:19 -04:00
2010-09-04 10:23:30 -04:00
menu - > addSeparator ( ) ;
menu - > addAction ( ui . actionCreate_New_Forum ) ;
# ifndef RS_RELEASE_VERSION
menu - > addAction ( ui . actionCreate_New_Channel ) ;
# endif
menu - > addAction ( ui . actionSet_your_Avatar ) ;
menu - > addAction ( ui . actionSet_your_Personal_Message ) ;
2009-07-13 15:58:11 -04:00
2010-09-04 10:23:30 -04:00
ui . menupushButton - > setMenu ( menu ) ;
setAcceptDrops ( true ) ;
ui . lineEdit - > setAcceptDrops ( false ) ;
2011-12-07 08:08:12 -05:00
ui . hashBox - > setDropWidget ( this ) ;
ui . hashBox - > setAutoHide ( true ) ;
2010-09-04 10:23:30 -04:00
2011-08-15 19:42:07 -04:00
/* Set initial size the splitter */
QList < int > sizes ;
sizes < < height ( ) < < 100 ; // Qt calculates the right sizes
ui . splitter_2 - > setSizes ( sizes ) ;
2010-09-04 10:23:30 -04:00
loadmypersonalstatus ( ) ;
2011-11-11 20:26:26 -05:00
ui . displayButton - > setMenu ( ui . friendList - > createDisplayMenu ( ) ) ;
2010-09-04 10:23:30 -04:00
// load settings
2011-10-20 17:34:44 -04:00
RsAutoUpdatePage : : lockAllEvents ( ) ;
2011-11-11 20:26:26 -05:00
ui . friendList - > setShowStatusColumn ( true ) ;
ui . friendList - > setShowLastContactColumn ( false ) ;
ui . friendList - > setShowAvatarColumn ( false ) ;
ui . friendList - > setRootIsDecorated ( true ) ;
ui . friendList - > setShowGroups ( true ) ;
2010-09-04 10:23:30 -04:00
processSettings ( true ) ;
2011-10-20 17:34:44 -04:00
RsAutoUpdatePage : : unlockAllEvents ( ) ;
2010-09-04 10:23:30 -04:00
ui . lineEdit - > installEventFilter ( this ) ;
// add self nick and Avatar to Friends.
RsPeerDetails pd ;
if ( rsPeers - > getPeerDetails ( rsPeers - > getOwnId ( ) , pd ) ) {
QString titleStr ( " <span style= \" font-size:16pt; font-weight:500; "
" color:#32cd32; \" >%1</span> " ) ;
2011-07-17 19:07:29 -04:00
ui . nicklabel - > setText ( titleStr . arg ( QString : : fromUtf8 ( pd . name . c_str ( ) ) + " ( " + tr ( " me " ) + " ) " + QString : : fromUtf8 ( pd . location . c_str ( ) ) ) ) ;
2010-09-04 10:23:30 -04:00
}
/* Hide platform specific features */
2008-11-24 09:07:26 -05:00
# ifdef Q_WS_WIN
# endif
}
2007-11-14 22:18:48 -05:00
2011-05-17 13:27:47 -04:00
FriendsDialog : : ~ FriendsDialog ( )
2010-05-11 16:02:52 -04:00
{
2010-06-08 17:38:36 -04:00
// save settings
processSettings ( false ) ;
2012-01-18 15:02:19 -05:00
if ( this = = instance ) {
instance = NULL ;
}
2010-05-11 16:02:52 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : processSettings ( bool bLoad )
2010-06-08 17:38:36 -04:00
{
2011-05-17 13:27:47 -04:00
Settings - > beginGroup ( QString ( " FriendsDialog " ) ) ;
2010-06-08 17:38:36 -04:00
if ( bLoad ) {
// load settings
// state of splitter
ui . splitter - > restoreState ( Settings - > value ( " Splitter " ) . toByteArray ( ) ) ;
2010-08-27 20:30:18 -04:00
ui . splitter_2 - > restoreState ( Settings - > value ( " GroupChatSplitter " ) . toByteArray ( ) ) ;
2010-06-08 17:38:36 -04:00
} else {
// save settings
// state of splitter
Settings - > setValue ( " Splitter " , ui . splitter - > saveState ( ) ) ;
2010-08-27 20:30:18 -04:00
Settings - > setValue ( " GroupChatSplitter " , ui . splitter_2 - > saveState ( ) ) ;
2010-06-08 17:38:36 -04:00
}
2011-11-11 20:26:26 -05:00
ui . friendList - > processSettings ( bLoad ) ;
2010-06-08 17:38:36 -04:00
Settings - > endGroup ( ) ;
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : showEvent ( QShowEvent * event )
2010-09-04 10:23:30 -04:00
{
static bool first = true ;
if ( first ) {
// Workaround: now the scroll position is correct calculated
first = false ;
QScrollBar * scrollbar = ui . msgText - > verticalScrollBar ( ) ;
scrollbar - > setValue ( scrollbar - > maximum ( ) ) ;
}
2010-09-10 16:43:11 -04:00
RsAutoUpdatePage : : showEvent ( event ) ;
2010-09-04 10:23:30 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : pasteLink ( )
2010-03-17 11:34:36 -04:00
{
2010-10-07 20:07:44 -04:00
ui . lineEdit - > insertHtml ( RSLinkClipboard : : toHtml ( ) ) ;
2010-03-17 11:34:36 -04:00
}
2011-08-12 10:06:29 -04:00
void FriendsDialog : : contextMenu ( QPoint /*point*/ )
2010-03-17 11:34:36 -04:00
{
2010-11-21 16:12:35 -05:00
QMenu * contextMnu = ui . lineEdit - > createStandardContextMenu ( ) ;
2010-03-17 11:34:36 -04:00
2010-11-21 16:12:35 -05:00
contextMnu - > addSeparator ( ) ;
QAction * action = contextMnu - > addAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste RetroShare Link " ) , this , SLOT ( pasteLink ( ) ) ) ;
action - > setDisabled ( RSLinkClipboard : : empty ( ) ) ;
2010-03-17 11:34:36 -04:00
2010-11-21 16:12:35 -05:00
contextMnu - > exec ( QCursor : : pos ( ) ) ;
delete ( contextMnu ) ;
2010-03-17 11:34:36 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : updateDisplay ( )
2009-11-17 07:45:06 -05:00
{
2007-11-14 22:18:48 -05:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : addFriend ( )
2010-09-29 15:30:59 -04:00
{
2011-10-20 17:34:44 -04:00
std : : string groupId = ui . friendList - > getSelectedGroupId ( ) ;
2010-09-29 15:30:59 -04:00
ConnectFriendWizard connwiz ( this ) ;
if ( groupId . empty ( ) = = false ) {
connwiz . setGroup ( groupId ) ;
}
connwiz . exec ( ) ;
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : resetStatusBar ( )
2009-09-30 18:30:57 -04:00
{
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
2011-05-17 13:27:47 -04:00
std : : cerr < < " FriendsDialog: reseting status bar. " < < std : : endl ;
2011-05-24 19:35:11 -04:00
# endif
2009-09-30 18:30:57 -04:00
ui . statusStringLabel - > setText ( QString ( " " ) ) ;
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : updateStatusTyping ( )
2009-09-30 18:30:57 -04:00
{
2010-08-30 14:33:19 -04:00
if ( time ( NULL ) - last_status_send_time > 5 ) // limit 'peer is typing' packets to at most every 10 sec
{
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
2011-05-17 13:27:47 -04:00
std : : cerr < < " FriendsDialog: sending group chat typing info. " < < std : : endl ;
2010-08-30 14:33:19 -04:00
# endif
2009-09-30 18:30:57 -04:00
2010-08-30 14:33:19 -04:00
# ifdef ONLY_FOR_LINGUIST
tr ( " is typing... " ) ;
# endif
rsMsgs - > sendGroupChatStatusString ( " is typing... " ) ;
last_status_send_time = time ( NULL ) ;
}
2009-09-30 18:30:57 -04:00
}
2010-08-30 14:33:19 -04:00
2009-09-30 18:30:57 -04:00
// Called by libretroshare through notifyQt to display the peer's status
//
2011-05-17 13:27:47 -04:00
void FriendsDialog : : updateStatusString ( const QString & peer_id , const QString & status_string )
2009-09-30 18:30:57 -04:00
{
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
2011-05-17 13:27:47 -04:00
std : : cerr < < " FriendsDialog: received group chat typing info. updating gui. " < < std : : endl ;
2010-08-30 14:33:19 -04:00
# endif
2009-09-30 18:30:57 -04:00
2011-07-17 19:07:29 -04:00
QString status = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id . toStdString ( ) ) . c_str ( ) ) + " " + tr ( status_string . toAscii ( ) ) ;
2010-08-30 14:33:19 -04:00
ui . statusStringLabel - > setText ( status ) ; // displays info for 5 secs.
2009-09-30 18:30:57 -04:00
2010-08-30 14:33:19 -04:00
QTimer : : singleShot ( 5000 , this , SLOT ( resetStatusBar ( ) ) ) ;
2009-09-30 18:30:57 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : updatePeerStatusString ( const QString & peer_id , const QString & status_string , bool is_private_chat )
2009-05-05 15:15:32 -04:00
{
2012-01-17 15:36:36 -05:00
if ( ! is_private_chat ) {
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
2010-08-30 14:33:19 -04:00
std : : cerr < < " Updating public chat msg from peer " < < rsPeers - > getPeerName ( peer_id . toStdString ( ) ) < < " : " < < status_string . toStdString ( ) < < std : : endl ;
# endif
2009-09-30 18:30:57 -04:00
2010-08-30 14:33:19 -04:00
updateStatusString ( peer_id , status_string ) ;
}
2009-05-05 15:15:32 -04:00
}
2007-11-14 22:18:48 -05:00
2011-05-17 13:27:47 -04:00
void FriendsDialog : : publicChatChanged ( int type )
2010-09-01 13:56:15 -04:00
{
if ( type = = NOTIFY_TYPE_ADD ) {
insertChat ( ) ;
}
}
2011-09-29 05:20:09 -04:00
void FriendsDialog : : addChatMsg ( bool incoming , bool history , const QString & name , const QDateTime & sendTime , const QDateTime & recvTime , const QString & message )
2010-09-04 10:23:30 -04:00
{
unsigned int formatFlag = CHAT_FORMATMSG_EMBED_LINKS ;
// embed smileys ?
2011-09-29 05:20:09 -04:00
if ( Settings - > valueFromGroup ( " Chat " , " Emoteicons_GroupChat " , true ) . toBool ( ) ) {
2010-09-04 10:23:30 -04:00
formatFlag | = CHAT_FORMATMSG_EMBED_SMILEYS ;
}
ChatStyle : : enumFormatMessage type ;
if ( incoming ) {
if ( history ) {
type = ChatStyle : : FORMATMSG_HINCOMING ;
} else {
type = ChatStyle : : FORMATMSG_INCOMING ;
}
} else {
if ( history ) {
type = ChatStyle : : FORMATMSG_HOUTGOING ;
} else {
type = ChatStyle : : FORMATMSG_OUTGOING ;
}
}
2012-01-30 19:06:24 -05:00
// Remove <p>'s from older RetroShare versions before 31.01.2012 (can be removed later)
QString optimizedMessage = message ;
RsHtml : : optimizeHtml ( optimizedMessage ) ;
QString formatMsg = style . formatMessage ( type , name , incoming ? recvTime : sendTime , optimizedMessage , formatFlag ) ;
2010-09-04 10:23:30 -04:00
ui . msgText - > append ( formatMsg ) ;
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : insertChat ( )
2008-07-10 06:34:49 -04:00
{
2010-08-31 13:13:52 -04:00
std : : list < ChatInfo > newchat ;
2010-09-01 13:56:15 -04:00
if ( ! rsMsgs - > getPublicChatQueue ( newchat ) )
2010-08-31 13:13:52 -04:00
{
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
2010-08-31 13:13:52 -04:00
std : : cerr < < " no chat available. " < < std : : endl ;
# endif
return ;
}
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
2010-08-31 13:13:52 -04:00
std : : cerr < < " got new chat. " < < std : : endl ;
# endif
std : : list < ChatInfo > : : iterator it ;
2008-07-10 06:34:49 -04:00
2010-08-31 13:13:52 -04:00
/* add in lines at the bottom */
for ( it = newchat . begin ( ) ; it ! = newchat . end ( ) ; it + + )
{
/* are they private? */
if ( it - > chatflags & RS_CHAT_PRIVATE )
{
2010-09-01 13:56:15 -04:00
/* this should not happen */
2010-08-31 13:13:52 -04:00
continue ;
}
2008-07-10 06:34:49 -04:00
2010-09-04 10:23:30 -04:00
QDateTime sendTime = QDateTime : : fromTime_t ( it - > sendTime ) ;
2010-10-03 06:08:58 -04:00
QDateTime recvTime = QDateTime : : fromTime_t ( it - > recvTime ) ;
2011-07-17 19:07:29 -04:00
QString name = QString : : fromUtf8 ( rsPeers - > getPeerName ( it - > rsid ) . c_str ( ) ) ;
2010-09-04 10:23:30 -04:00
QString msg = QString : : fromStdWString ( it - > msg ) ;
2008-07-10 06:34:49 -04:00
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
std : : cerr < < " FriendsDialog::insertChat(): " < < msg . toStdString ( ) < < std : : endl ;
2010-09-04 10:23:30 -04:00
# endif
2008-07-10 06:34:49 -04:00
2010-09-04 10:23:30 -04:00
bool incoming = false ;
2010-02-07 07:36:37 -05:00
2010-08-31 13:13:52 -04:00
// notify with a systray icon msg
if ( it - > rsid ! = rsPeers - > getOwnId ( ) )
{
2010-09-04 10:23:30 -04:00
incoming = true ;
2010-08-31 13:13:52 -04:00
// This is a trick to translate HTML into text.
2010-09-04 10:23:30 -04:00
QTextEdit editor ;
editor . setHtml ( msg ) ;
QString notifyMsg = name + " : " + editor . toPlainText ( ) ;
2010-08-31 13:13:52 -04:00
if ( notifyMsg . length ( ) > 30 )
2010-11-02 17:11:11 -04:00
emit notifyGroupChat ( tr ( " New group chat " ) , notifyMsg . left ( 30 ) + QString ( " ... " ) ) ;
2010-08-31 13:13:52 -04:00
else
2010-11-02 17:11:11 -04:00
emit notifyGroupChat ( tr ( " New group chat " ) , notifyMsg ) ;
2010-08-31 13:13:52 -04:00
}
2010-02-07 07:36:37 -05:00
2011-09-29 05:20:09 -04:00
addChatMsg ( incoming , false , name , sendTime , recvTime , msg ) ;
2010-08-31 13:13:52 -04:00
}
2008-07-10 06:34:49 -04:00
}
2011-05-17 13:27:47 -04:00
bool FriendsDialog : : eventFilter ( QObject * obj , QEvent * event )
2008-07-10 06:34:49 -04:00
{
2010-09-04 10:23:30 -04:00
if ( obj = = ui . lineEdit ) {
if ( event - > type ( ) = = QEvent : : KeyPress ) {
updateStatusTyping ( ) ;
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( event ) ;
if ( keyEvent & & ( keyEvent - > key ( ) = = Qt : : Key_Enter | | keyEvent - > key ( ) = = Qt : : Key_Return ) ) {
// Enter pressed
if ( Settings - > getChatSendMessageWithCtrlReturn ( ) ) {
if ( keyEvent - > modifiers ( ) & Qt : : ControlModifier ) {
// send message with Ctrl+Enter
sendMsg ( ) ;
return true ; // eat event
}
} else {
if ( keyEvent - > modifiers ( ) & Qt : : ControlModifier ) {
// insert return
ui . lineEdit - > textCursor ( ) . insertText ( " \n " ) ;
} else {
// send message with Enter
sendMsg ( ) ;
}
return true ; // eat event
}
}
}
}
// pass the event on to the parent class
return RsAutoUpdatePage : : eventFilter ( obj , event ) ;
2008-07-10 06:34:49 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : sendMsg ( )
2008-07-10 06:34:49 -04:00
{
QTextEdit * lineWidget = ui . lineEdit ;
2010-09-04 10:23:30 -04:00
if ( lineWidget - > toPlainText ( ) . isEmpty ( ) ) {
// nothing to send
return ;
}
2008-07-10 06:34:49 -04:00
2011-09-29 05:20:09 -04:00
QString text ;
RsHtml : : optimizeHtml ( lineWidget , text ) ;
std : : wstring message = text . toStdWString ( ) ;
2009-07-13 15:58:11 -04:00
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
std : : string msg ( message . begin ( ) , message . end ( ) ) ;
2011-05-17 13:27:47 -04:00
std : : cerr < < " FriendsDialog::sendMsg(): " < < msg < < std : : endl ;
2010-09-01 13:56:15 -04:00
# endif
2008-07-10 06:34:49 -04:00
2010-09-01 13:56:15 -04:00
rsMsgs - > sendPublicChat ( message ) ;
ui . lineEdit - > clear ( ) ;
2010-10-07 20:07:44 -04:00
// workaround for Qt bug - http://bugreports.qt.nokia.com/browse/QTBUG-2533
// QTextEdit::clear() does not reset the CharFormat if document contains hyperlinks that have been accessed.
ui . lineEdit - > setCurrentCharFormat ( QTextCharFormat ( ) ) ;
2010-09-01 13:56:15 -04:00
setFont ( ) ;
2008-07-10 06:34:49 -04:00
2010-09-01 13:56:15 -04:00
/* redraw send list */
insertSendList ( ) ;
2008-07-10 06:34:49 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : insertSendList ( )
2008-07-10 06:34:49 -04:00
{
2010-05-12 16:10:22 -04:00
# ifdef false
2008-07-10 06:34:49 -04:00
std : : list < std : : string > peers ;
std : : list < std : : string > : : iterator it ;
if ( ! rsPeers )
{
/* not ready yet! */
return ;
}
rsPeers - > getOnlineList ( peers ) ;
/* get a link to the table */
//QTreeWidget *sendWidget = ui.msgSendList;
QList < QTreeWidgetItem * > items ;
for ( it = peers . begin ( ) ; it ! = peers . end ( ) ; it + + )
{
RsPeerDetails details ;
if ( ! rsPeers - > getPeerDetails ( * it , details ) )
{
continue ; /* BAD */
}
/* make a widget per friend */
QTreeWidgetItem * item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
/* add all the labels */
/* (0) Person */
item - > setText ( 0 , QString : : fromStdString ( details . name ) ) ;
item - > setFlags ( Qt : : ItemIsUserCheckable | Qt : : ItemIsEnabled ) ;
//item -> setFlags(Qt::ItemIsUserCheckable);
item - > setCheckState ( 0 , Qt : : Checked ) ;
if ( rsicontrol - > IsInChat ( * it ) )
{
item - > setCheckState ( 0 , Qt : : Checked ) ;
}
else
{
item - > setCheckState ( 0 , Qt : : Unchecked ) ;
}
/* disable for the moment */
item - > setFlags ( Qt : : ItemIsUserCheckable ) ;
item - > setCheckState ( 0 , Qt : : Checked ) ;
/* add to the list */
items . append ( item ) ;
}
/* remove old items */
//sendWidget->clear();
//sendWidget->setColumnCount(1);
/* add the items in! */
//sendWidget->insertTopLevelItems(0, items);
//sendWidget->update(); /* update display */
2010-05-12 16:10:22 -04:00
# endif
2008-07-10 06:34:49 -04:00
}
/* to toggle the state */
2011-05-17 13:27:47 -04:00
//void FriendsDialog::toggleSendItem( QTreeWidgetItem *item, int col )
2010-09-24 07:38:46 -04:00
//{
2011-05-24 19:35:11 -04:00
//#ifdef FRIENDS_DEBUG
2010-09-24 07:38:46 -04:00
// std::cerr << "ToggleSendItem()" << std::endl;
2011-05-24 19:35:11 -04:00
//#endif
2010-09-24 07:38:46 -04:00
//
// /* extract id */
// std::string id = (item -> text(4)).toStdString();
//
// /* get state */
// bool inChat = (Qt::Checked == item -> checkState(0)); /* alway column 0 */
//
// /* call control fns */
//
// rsicontrol -> SetInChat(id, inChat);
// return;
//}
2008-07-10 06:34:49 -04:00
2009-03-12 13:57:30 -04:00
//============================================================================
2011-05-17 13:27:47 -04:00
void FriendsDialog : : setColor ( )
2008-07-10 06:34:49 -04:00
{
2010-10-07 20:07:44 -04:00
bool ok ;
QRgb color = QColorDialog : : getRgba ( ui . lineEdit - > textColor ( ) . rgba ( ) , & ok , this ) ;
if ( ok ) {
mCurrentColor = QColor ( color ) ;
colorChanged ( mCurrentColor ) ;
}
setFont ( ) ;
}
2009-07-13 15:58:11 -04:00
2011-05-17 13:27:47 -04:00
void FriendsDialog : : colorChanged ( const QColor & c )
2010-10-07 20:07:44 -04:00
{
QPixmap pxm ( 16 , 16 ) ;
2011-08-12 10:06:29 -04:00
pxm . fill ( c ) ;
2010-10-07 20:07:44 -04:00
ui . colorChatButton - > setIcon ( pxm ) ;
2008-07-10 06:34:49 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : getFont ( )
2008-07-10 06:34:49 -04:00
{
bool ok ;
mCurrentFont = QFontDialog : : getFont ( & ok , mCurrentFont , this ) ;
2010-10-07 20:07:44 -04:00
if ( ok ) {
fontChanged ( mCurrentFont ) ;
}
2008-07-10 06:34:49 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : fontChanged ( const QFont & font )
2008-07-10 06:34:49 -04:00
{
2010-10-07 20:07:44 -04:00
mCurrentFont = font ;
2008-07-10 06:34:49 -04:00
2010-10-07 20:07:44 -04:00
ui . textboldChatButton - > setChecked ( mCurrentFont . bold ( ) ) ;
ui . textunderlineChatButton - > setChecked ( mCurrentFont . underline ( ) ) ;
ui . textitalicChatButton - > setChecked ( mCurrentFont . italic ( ) ) ;
2009-07-13 15:58:11 -04:00
2010-10-07 20:07:44 -04:00
setFont ( ) ;
2008-07-10 06:34:49 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : setFont ( )
2008-11-24 09:07:26 -05:00
{
2010-10-07 20:07:44 -04:00
mCurrentFont . setBold ( ui . textboldChatButton - > isChecked ( ) ) ;
mCurrentFont . setUnderline ( ui . textunderlineChatButton - > isChecked ( ) ) ;
mCurrentFont . setItalic ( ui . textitalicChatButton - > isChecked ( ) ) ;
ui . lineEdit - > setFont ( mCurrentFont ) ;
ui . lineEdit - > setTextColor ( mCurrentColor ) ;
Settings - > setChatScreenFont ( mCurrentFont . toString ( ) ) ;
2009-07-13 15:58:11 -04:00
2010-10-07 20:07:44 -04:00
ui . lineEdit - > setFocus ( ) ;
}
2008-07-10 06:34:49 -04:00
2008-11-24 09:07:26 -05:00
// Update Chat Info information
2011-05-17 13:27:47 -04:00
void FriendsDialog : : setChatInfo ( QString info , QColor color )
2008-11-24 09:07:26 -05:00
{
static unsigned int nbLines = 0 ;
+ + nbLines ;
// Check log size, clear it if too big
if ( nbLines > 200 ) {
ui . msgText - > clear ( ) ;
nbLines = 1 ;
}
ui . msgText - > append ( QString : : fromUtf8 ( " <font color='grey'> " ) + QTime : : currentTime ( ) . toString ( QString : : fromUtf8 ( " hh:mm:ss " ) ) + QString : : fromUtf8 ( " </font> - <font color=' " ) + color . name ( ) + QString : : fromUtf8 ( " '><i> " ) + info + QString : : fromUtf8 ( " </i></font> " ) ) ;
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : on_actionClear_Chat_History_triggered ( )
2008-11-24 09:07:26 -05:00
{
2010-09-04 10:23:30 -04:00
ui . msgText - > clear ( ) ;
2008-11-24 09:07:26 -05:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : on_actionDelete_Chat_History_triggered ( )
2011-02-08 16:59:17 -05:00
{
2011-02-27 16:47:49 -05:00
if ( ( QMessageBox : : question ( this , " RetroShare " , tr ( " Do you really want to physically delete the history? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes ) {
on_actionClear_Chat_History_triggered ( ) ;
2011-09-29 05:20:09 -04:00
rsHistory - > clear ( " " ) ;
2011-02-27 16:47:49 -05:00
}
2011-02-08 16:59:17 -05:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : smileyWidgetgroupchat ( )
2009-07-13 15:58:11 -04:00
{
2010-09-14 13:47:11 -04:00
Emoticons : : showSmileyWidget ( this , ui . emoticonBtn , SLOT ( addSmileys ( ) ) , true ) ;
2008-11-24 09:07:26 -05:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : addSmileys ( )
2008-07-10 06:34:49 -04:00
{
2010-09-04 10:23:30 -04:00
ui . lineEdit - > textCursor ( ) . insertText ( qobject_cast < QPushButton * > ( sender ( ) ) - > toolTip ( ) . split ( " | " ) . first ( ) ) ;
2008-07-10 06:34:49 -04:00
}
2007-11-14 22:18:48 -05:00
2011-05-17 13:27:47 -04:00
void FriendsDialog : : getAvatar ( )
2009-09-02 18:42:31 -04:00
{
2011-08-12 16:27:05 -04:00
QByteArray ba ;
if ( misc : : getOpenAvatarPicture ( this , ba ) )
2009-09-02 18:42:31 -04:00
{
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
2011-08-12 16:27:05 -04:00
std : : cerr < < " Avatar image size = " < < ba . size ( ) < < std : : endl ;
2011-05-24 19:35:11 -04:00
# endif
2009-09-02 18:42:31 -04:00
2011-08-12 16:27:05 -04:00
rsMsgs - > setOwnAvatarData ( ( unsigned char * ) ( ba . data ( ) ) , ba . size ( ) ) ; // last char 0 included.
2009-09-02 18:42:31 -04:00
}
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : on_actionCreate_New_Forum_activated ( )
2010-01-16 20:36:50 -05:00
{
2010-05-02 20:09:55 -04:00
MainWindow : : activatePage ( MainWindow : : Forums ) ;
CreateForum cf ( this ) ;
cf . exec ( ) ;
2010-01-16 20:36:50 -05:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : on_actionCreate_New_Channel_activated ( )
2010-01-16 20:36:50 -05:00
{
2010-05-02 20:09:55 -04:00
# ifndef RS_RELEASE_VERSION
MainWindow : : activatePage ( MainWindow : : Channels ) ;
2010-05-02 07:41:23 -04:00
2010-05-02 20:09:55 -04:00
CreateChannel cf ( this ) ;
cf . exec ( ) ;
# endif
2010-01-16 20:36:50 -05:00
}
2010-05-02 20:09:55 -04:00
2009-09-29 18:52:46 -04:00
/** Loads own personal status */
2011-05-17 13:27:47 -04:00
void FriendsDialog : : loadmypersonalstatus ( )
2009-09-29 18:52:46 -04:00
{
2010-11-24 14:25:53 -05:00
ui . mypersonalstatuslabel - > setText ( QString : : fromUtf8 ( rsMsgs - > getCustomStateString ( ) . c_str ( ) ) ) ;
2009-09-29 18:52:46 -04:00
}
2009-10-08 15:08:44 -04:00
2011-05-17 13:27:47 -04:00
void FriendsDialog : : statusmessage ( )
2009-10-08 15:08:44 -04:00
{
2010-05-02 20:09:55 -04:00
StatusMessage statusmsgdialog ( this ) ;
statusmsgdialog . exec ( ) ;
2009-10-08 15:08:44 -04:00
}
2010-01-31 17:29:30 -05:00
2011-05-17 13:27:47 -04:00
void FriendsDialog : : addExtraFile ( )
2010-01-31 17:29:30 -05:00
{
2011-12-07 08:08:12 -05:00
QStringList files ;
if ( misc : : getOpenFileNames ( this , RshareSettings : : LASTDIR_EXTRAFILE , tr ( " Add Extra File " ) , " " , files ) ) {
ui . hashBox - > addAttachments ( files ) ;
2010-12-02 19:54:40 -05:00
}
2010-01-31 17:29:30 -05:00
}
2011-12-07 08:08:12 -05:00
void FriendsDialog : : fileHashingFinished ( QList < HashedFile > hashedFiles )
2010-09-01 13:56:15 -04:00
{
2011-05-17 13:27:47 -04:00
std : : cerr < < " FriendsDialog::fileHashingFinished() started. " < < std : : endl ;
2010-03-17 11:34:36 -04:00
2011-12-07 08:08:12 -05:00
QString mesgString ;
2010-01-31 17:29:30 -05:00
2011-12-07 08:08:12 -05:00
QList < HashedFile > : : iterator it ;
for ( it = hashedFiles . begin ( ) ; it ! = hashedFiles . end ( ) ; + + it ) {
HashedFile & hashedFile = * it ;
RetroShareLink link ;
if ( ! link . createFile ( hashedFile . filename , hashedFile . size , QString : : fromStdString ( hashedFile . hash ) ) ) {
continue ;
}
mesgString + = link . toHtmlSize ( ) ;
if ( it ! = hashedFiles . end ( ) ) {
mesgString + = " <BR> " ;
}
2011-05-04 06:22:49 -04:00
}
2010-01-31 17:29:30 -05:00
2011-05-24 19:35:11 -04:00
# ifdef FRIENDS_DEBUG
std : : cerr < < " FriendsDialog::fileHashingFinished mesgString : " < < mesgString . toStdString ( ) < < std : : endl ;
2010-09-01 13:56:15 -04:00
# endif
2010-01-31 17:29:30 -05:00
2011-12-07 08:08:12 -05:00
if ( ! mesgString . isEmpty ( ) ) {
/* convert to real html document */
QTextBrowser textBrowser ;
textBrowser . setHtml ( mesgString ) ;
std : : wstring msg = textBrowser . toHtml ( ) . toStdWString ( ) ;
2010-01-31 17:29:30 -05:00
2011-12-07 08:08:12 -05:00
rsMsgs - > sendPublicChat ( msg ) ;
setFont ( ) ;
2010-09-17 17:54:25 -04:00
}
2010-01-31 17:29:30 -05:00
}
2010-04-27 18:08:38 -04:00
2011-05-17 13:27:47 -04:00
bool FriendsDialog : : fileSave ( )
2010-04-27 18:08:38 -04:00
{
if ( fileName . isEmpty ( ) )
return fileSaveAs ( ) ;
QFile file ( fileName ) ;
if ( ! file . open ( QFile : : WriteOnly ) )
return false ;
QTextStream ts ( & file ) ;
ts . setCodec ( QTextCodec : : codecForName ( " UTF-8 " ) ) ;
ts < < ui . msgText - > document ( ) - > toPlainText ( ) ;
ui . msgText - > document ( ) - > setModified ( false ) ;
return true ;
}
2011-05-17 13:27:47 -04:00
bool FriendsDialog : : fileSaveAs ( )
2010-04-27 18:08:38 -04:00
{
2010-12-02 19:54:40 -05:00
QString fn ;
if ( misc : : getSaveFileName ( this , RshareSettings : : LASTDIR_HISTORY , tr ( " Save as... " ) , tr ( " Text File (*.txt );;All Files (*) " ) , fn ) ) {
setCurrentFileName ( fn ) ;
return fileSave ( ) ;
}
return false ;
2010-04-27 18:08:38 -04:00
}
2011-05-17 13:27:47 -04:00
void FriendsDialog : : setCurrentFileName ( const QString & fileName )
2010-04-27 18:08:38 -04:00
{
this - > fileName = fileName ;
ui . msgText - > document ( ) - > setModified ( false ) ;
setWindowModified ( false ) ;
2010-05-02 07:41:23 -04:00
}
2010-05-05 07:47:29 -04:00
2011-05-17 13:27:47 -04:00
void FriendsDialog : : on_actionMessageHistory_triggered ( )
2010-09-01 10:15:50 -04:00
{
2011-09-29 05:20:09 -04:00
ImHistoryBrowser imBrowser ( " " , ui . lineEdit , this ) ;
2010-09-01 10:15:50 -04:00
imBrowser . exec ( ) ;
}
2010-09-21 12:11:19 -04:00
2011-05-17 13:27:47 -04:00
void FriendsDialog : : on_actionAdd_Group_activated ( )
2010-09-21 12:11:19 -04:00
{
2010-09-22 18:37:57 -04:00
CreateGroup createGrpDialog ( " " , this ) ;
2010-09-21 12:11:19 -04:00
createGrpDialog . exec ( ) ;
}
2010-09-22 18:37:57 -04:00
2011-05-17 13:27:47 -04:00
void FriendsDialog : : newsFeedChanged ( int count )
2010-11-10 07:24:36 -05:00
{
2012-01-25 16:45:23 -05:00
int newsFeedTabIndex = ui . tabWidget - > indexOf ( newsFeed ) ;
if ( newsFeedTabIndex < 0 ) {
return ;
}
2010-11-10 07:24:36 -05:00
if ( count ) {
2012-01-18 15:02:19 -05:00
ui . tabWidget - > tabBar ( ) - > setTabText ( newsFeedTabIndex , QString ( " %1 (%2) " ) . arg ( newsFeedText ) . arg ( count ) ) ;
ui . tabWidget - > tabBar ( ) - > setTabTextColor ( newsFeedTabIndex , Qt : : blue ) ;
ui . tabWidget - > tabBar ( ) - > setTabIcon ( newsFeedTabIndex , QIcon ( IMAGE_NEWSFEED_NEW ) ) ;
2010-11-10 07:24:36 -05:00
} else {
2012-01-18 15:02:19 -05:00
ui . tabWidget - > tabBar ( ) - > setTabText ( newsFeedTabIndex , newsFeedText ) ;
ui . tabWidget - > tabBar ( ) - > setTabTextColor ( newsFeedTabIndex , newsFeedTabColor ) ;
ui . tabWidget - > tabBar ( ) - > setTabIcon ( newsFeedTabIndex , QIcon ( IMAGE_NEWSFEED ) ) ;
2010-11-10 07:24:36 -05:00
}
}
2012-01-11 19:13:25 -05:00
2012-01-12 11:24:36 -05:00
void FriendsDialog : : createChatLobby ( )
{
std : : list < std : : string > friends ;
CreateLobbyDialog ( friends ) . exec ( ) ;
2012-01-17 15:36:36 -05:00
}
2012-01-18 15:02:19 -05:00
/*static*/ ChatTabWidget * FriendsDialog : : getTabWidget ( )
{
return instance ? instance - > ui . tabWidget : NULL ;
}