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 <time.h>
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>
2012-05-11 20:40:53 -04:00
# include <QTextStream>
# include <QTextCodec>
# include <QTimer>
2012-10-24 09:22:14 -04:00
# include <QMessageBox>
2013-08-25 16:41:50 -04:00
# include <QTextDocumentFragment>
2008-11-24 09:07:26 -05:00
2011-10-20 17:34:44 -04:00
# 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 "common/Emoticons.h"
2012-03-22 05:01:17 -04:00
# include "common/PeerDefs.h"
2012-08-05 16:12:55 -04:00
# include "chat/ChatUserNotify.h"
2010-09-19 20:10:51 -04:00
# include "connect/ConnectFriendWizard.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"
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-05-11 20:40:53 -04:00
# include "util/HandleRichText.h"
2012-11-15 16:35:37 -05:00
# include "util/DateTime.h"
2011-10-20 17:34:44 -04:00
# include "FriendsDialog.h"
2013-02-22 16:42:27 -05:00
# include "NetworkView.h"
# include "NetworkDialog.h"
2014-05-07 19:45:53 -04:00
# include "gui/Identity/IdDialog.h"
# include "gui/Circles/CirclesDialog.h"
2010-05-05 07:47:29 -04:00
2011-10-20 17:34:44 -04:00
/* Images for Newsfeed icons */
2014-05-09 22:38:47 -04:00
//#define IMAGE_NEWSFEED ""
//#define IMAGE_NEWSFEED_NEW ":/images/message-state-new.png"
2014-05-07 19:45:53 -04:00
# define IMAGE_NETWORK2 ": / images / logo / logo_16.png"
2013-02-22 16:42:27 -05:00
# define IMAGE_PEERS ": / images / groupchat.png"
2014-05-07 19:45:53 -04:00
# define IMAGE_IDENTITY ": / images / identity / identities_32.png"
# define IMAGE_CIRCLES ": / images / circles / circles_32.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 ;
2012-04-12 19:00:39 -04:00
inChatCharFormatChanged = false ;
2007-11-14 22:18:48 -05:00
2012-08-26 16:31:10 -04:00
connect ( ui . mypersonalstatusLabel , SIGNAL ( clicked ( ) ) , SLOT ( statusmessage ( ) ) ) ;
2010-09-04 10:23:30 -04:00
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 ( ) ) ) ;
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 ) ;
2014-05-11 09:59:14 -04:00
//ui.tabWidget->addTab(idDialog = new IdDialog(),QIcon(IMAGE_IDENTITY), tr("Identities"));
//ui.tabWidget->addTab(circlesDialog = new CirclesDialog(),QIcon(IMAGE_CIRCLES), tr("Circles"));
2013-02-22 16:42:27 -05:00
ui . tabWidget - > addTab ( networkView = new NetworkView ( ) , QIcon ( IMAGE_NETWORK2 ) , tr ( " Local network " ) ) ;
2013-07-16 16:00:46 -04:00
ui . tabWidget - > addTab ( networkDialog = new NetworkDialog ( ) , QIcon ( IMAGE_PEERS ) , tr ( " Keyring " ) ) ;
2013-02-22 16:42:27 -05:00
//ui.tabWidget->addTab(new ProfileWidget(), tr("Profile"));
//newsFeed = new NewsFeed();
//int newsFeedTabIndex = ui.tabWidget->insertTab(0, newsFeed, tr("News Feed"));
//ui.tabWidget->setCurrentIndex(newsFeedTabIndex);
2012-01-18 15:02:19 -05:00
ui . tabWidget - > hideCloseButton ( 0 ) ;
ui . tabWidget - > hideCloseButton ( 1 ) ;
ui . tabWidget - > hideCloseButton ( 2 ) ;
ui . tabWidget - > hideCloseButton ( 3 ) ;
2014-05-07 19:45:53 -04:00
ui . tabWidget - > hideCloseButton ( 4 ) ;
2010-11-10 07:24:36 -05:00
/* get the current text and text color of the tab bar */
2013-02-22 16:42:27 -05:00
//newsFeedTabColor = ui.tabWidget->tabBar()->tabTextColor(newsFeedTabIndex);
//newsFeedText = ui.tabWidget->tabBar()->tabText(newsFeedTabIndex);
2010-11-10 07:24:36 -05:00
2013-02-22 16:42:27 -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
2012-08-22 04:19:46 -04:00
connect ( ui . msgText , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenuMsgText ( QPoint ) ) ) ;
2010-09-04 10:23:30 -04:00
connect ( ui . lineEdit , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
2012-04-12 19:00:39 -04:00
// reset text and color after removing all characters from the QTextEdit and after calling QTextEdit::clear
connect ( ui . lineEdit , SIGNAL ( currentCharFormatChanged ( QTextCharFormat ) ) , this , SLOT ( chatCharFormatChanged ( ) ) ) ;
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 ( ) ) ) ;
2012-02-11 16:41:41 -05:00
connect ( ui . fontsButton , SIGNAL ( clicked ( ) ) , this , SLOT ( chooseFont ( ) ) ) ;
connect ( ui . colorChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( chooseColor ( ) ) ) ;
2013-08-25 16:41:50 -04:00
connect ( ui . attachPictureButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraPicture ( ) ) ) ;
2010-09-04 10:23:30 -04:00
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
2012-02-11 16:41:41 -05:00
colorChanged ( ) ;
fontChanged ( ) ;
setColorAndFont ( ) ;
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
2013-07-22 08:34:05 -04:00
setChatInfo ( tr ( " Retroshare broadcast chat: messages are sent to all connected friends. " ) , QString : : fromUtf8 ( " blue " ) ) ;
2010-09-04 10:23:30 -04:00
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 ;
2014-03-17 16:56:06 -04:00
rsHistory - > getMessages ( RsPeerId ( ) , historyMsgs , messageCount ) ;
2011-09-29 05:20:09 -04:00
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 * menu = new QMenu ( ) ;
2012-02-11 16:41:41 -05:00
menu - > addAction ( ui . actionClear_Chat_History ) ;
menu - > addAction ( ui . actionDelete_Chat_History ) ;
menu - > addAction ( ui . actionSave_History ) ;
menu - > addAction ( ui . actionMessageHistory ) ;
ui . menuButton - > setMenu ( menu ) ;
2013-07-16 18:33:45 -04:00
// menu = new QMenu();
// menu->addAction(ui.actionAdd_Friend);
// menu->addAction(ui.actionAdd_Group);
// menu->addAction(ui.actionCreate_new_Chat_lobby);
//
// menu->addSeparator();
// menu->addAction(ui.actionSet_your_Avatar);
// menu->addAction(ui.actionSet_your_Personal_Message);
//
// ui.menutoolButton->setMenu(menu);
2010-09-04 10:23:30 -04:00
2014-04-29 07:52:13 -04:00
QToolButton * addFriendButton = new QToolButton ( this ) ;
addFriendButton - > setIcon ( QIcon ( " :/images/user/add_user24.png " ) ) ;
addFriendButton - > setToolTip ( tr ( " Add Friend " ) ) ;
connect ( addFriendButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addFriend ( ) ) ) ;
ui . friendList - > addToolButton ( addFriendButton ) ;
2010-09-04 10:23:30 -04:00
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 ( ) ;
// 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 ) ;
2013-09-10 18:04:39 -04:00
ui . friendList - > setShowIPColumn ( false ) ;
2011-11-11 20:26:26 -05:00
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 ) ) {
2012-08-26 16:31:10 -04:00
ui . nicknameLabel - > setText ( PeerDefs : : nameWithLocation ( pd ) ) ;
2010-09-04 10:23:30 -04:00
}
2013-09-08 11:08:36 -04:00
QString hlp_str = tr (
" <h1><img width= \" 32 \" src= \" :/images/64px_help.png \" > Friends</h1> \
< p > The Friends tab shows . . . your friends : the list of persons you have accepted to connect to . \
< / p > \
< p > You can group friends together to allow a finer level of information access , for instance to only allow \
some friends to see some files . < / p > \
< p > On the right , you will find 3 useful tabs : \
< ul > \
< li > Broadcast sends messages to all connected friends at once < / li > \
< li > Local Network shows the network around you , including friends of your friends < / li > \
< li > Keyring contains keys you collected , mostly forwarded to you by your friends < / li > \
< / ul > < / p > \
" ) ;
2013-07-19 08:18:58 -04:00
registerHelpButton ( ui . helpButton , hlp_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
2013-08-25 16:41:50 -04:00
# if QT_VERSION < 0x040700
// embedded images are not supported before QT 4.7.0
2013-08-26 03:24:37 -04:00
ui . attachPictureButton - > setVisible ( false ) ;
2013-08-25 16:41:50 -04:00
# endif
2008-11-24 09:07:26 -05:00
}
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
}
2013-02-23 09:29:36 -05:00
void FriendsDialog : : activatePage ( FriendsDialog : : Page page )
{
switch ( page )
{
2014-05-07 19:45:53 -04:00
case FriendsDialog : : IdTab : ui . tabWidget - > setCurrentWidget ( idDialog ) ;
break ;
case FriendsDialog : : CirclesTab : ui . tabWidget - > setCurrentWidget ( circlesDialog ) ;
break ;
2013-02-23 09:29:36 -05:00
case FriendsDialog : : NetworkTab : ui . tabWidget - > setCurrentWidget ( networkDialog ) ;
break ;
case FriendsDialog : : BroadcastTab : ui . tabWidget - > setCurrentWidget ( networkDialog ) ;
break ;
case FriendsDialog : : NetworkViewTab : ui . tabWidget - > setCurrentWidget ( networkView ) ;
break ;
}
}
2012-08-05 16:12:55 -04:00
UserNotify * FriendsDialog : : getUserNotify ( QObject * parent )
{
return new ChatUserNotify ( parent ) ;
}
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
}
2012-09-07 17:28:25 -04:00
void FriendsDialog : : contextMenuMsgText ( QPoint point )
2012-08-22 04:19:46 -04:00
{
2012-09-26 13:52:58 -04:00
QMatrix matrix ;
matrix . translate ( ui . msgText - > horizontalScrollBar ( ) - > value ( ) , ui . msgText - > verticalScrollBar ( ) - > value ( ) ) ;
QMenu * contextMnu = ui . msgText - > createStandardContextMenu ( matrix . map ( point ) ) ;
2012-08-22 04:19:46 -04:00
contextMnu - > addSeparator ( ) ;
contextMnu - > addAction ( ui . actionClear_Chat_History ) ;
2012-09-26 13:52:58 -04:00
contextMnu - > exec ( ui . msgText - > viewport ( ) - > mapToGlobal ( point ) ) ;
2012-08-22 04:19:46 -04:00
delete ( contextMnu ) ;
}
2012-09-07 17:28:25 -04:00
void FriendsDialog : : contextMenu ( QPoint point )
2010-03-17 11:34:36 -04:00
{
2012-09-07 17:28:25 -04:00
QMenu * contextMnu = ui . lineEdit - > createStandardContextMenu ( point ) ;
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
}
2012-04-12 19:00:39 -04:00
void FriendsDialog : : chatCharFormatChanged ( )
{
if ( inChatCharFormatChanged ) {
return ;
}
inChatCharFormatChanged = true ;
// Reset font and color before inserting a character if edit box is empty
// (color info disappears when the user deletes all text)
if ( ui . lineEdit - > toPlainText ( ) . isEmpty ( ) ) {
setColorAndFont ( ) ;
}
inChatCharFormatChanged = false ;
}
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 ( ) ;
}
2013-01-22 19:22:17 -05: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
2014-03-17 16:56:06 -04:00
QString status = QString : : fromUtf8 ( rsPeers - > getPeerName ( RsPeerId ( peer_id . toStdString ( ) ) ) . c_str ( ) ) + " " + tr ( status_string . toLatin1 ( ) ) ;
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
{
2012-05-11 20:40:53 -04:00
unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_OPTIMIZE ;
2010-09-04 10:23:30 -04:00
// embed smileys ?
2011-09-29 05:20:09 -04:00
if ( Settings - > valueFromGroup ( " Chat " , " Emoteicons_GroupChat " , true ) . toBool ( ) ) {
2012-05-11 20:40:53 -04:00
formatTextFlag | = RSHTML_FORMATTEXT_EMBED_SMILEYS ;
2010-09-04 10:23:30 -04:00
}
2012-09-21 17:23:14 -04:00
// Always fix colors
formatTextFlag | = RSHTML_FORMATTEXT_FIX_COLORS ;
qreal desiredContrast = Settings - > valueFromGroup ( " Chat " , " MinimumContrast " , 4.5 ) . toDouble ( ) ;
QColor backgroundColor = ui . groupChatTab - > palette ( ) . base ( ) . color ( ) ;
// Remove font name, size, bold, italics?
if ( ! Settings - > valueFromGroup ( " Chat " , " EnableCustomFonts " , true ) . toBool ( ) ) {
formatTextFlag | = RSHTML_FORMATTEXT_REMOVE_FONT_FAMILY ;
}
if ( ! Settings - > valueFromGroup ( " Chat " , " EnableCustomFontSize " , true ) . toBool ( ) ) {
formatTextFlag | = RSHTML_FORMATTEXT_REMOVE_FONT_SIZE ;
}
if ( ! Settings - > valueFromGroup ( " Chat " , " EnableBold " , true ) . toBool ( ) ) {
formatTextFlag | = RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT ;
}
if ( ! Settings - > valueFromGroup ( " Chat " , " EnableItalics " , true ) . toBool ( ) ) {
formatTextFlag | = RSHTML_FORMATTEXT_REMOVE_FONT_STYLE ;
}
2010-09-04 10:23:30 -04:00
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-05-11 20:40:53 -04:00
2012-09-21 17:23:14 -04:00
QString formattedMessage = RsHtml ( ) . formatText ( ui . msgText - > document ( ) , message , formatTextFlag , backgroundColor , desiredContrast ) ;
2012-05-11 20:40:53 -04:00
QString formatMsg = style . formatMessage ( type , name , incoming ? recvTime : sendTime , formattedMessage ) ;
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 ( ) ) ;
2013-10-03 17:41:34 -04:00
QString msg = QString : : fromUtf8 ( it - > msg . c_str ( ) ) ;
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 ) ;
2013-10-03 17:41:34 -04:00
std : : string message = text . toUtf8 ( ) . constData ( ) ;
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
/* 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;
2013-01-22 19:22:17 -05:00
QList < QTreeWidgetItem * > items ;
2008-07-10 06:34:49 -04:00
for ( it = peers . begin ( ) ; it ! = peers . end ( ) ; it + + )
{
RsPeerDetails details ;
if ( ! rsPeers - > getPeerDetails ( * it , details ) )
{
continue ; /* BAD */
}
2013-01-22 19:22:17 -05:00
/* make a widget per friend */
QTreeWidgetItem * item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
2008-07-10 06:34:49 -04:00
/* add all the labels */
/* (0) Person */
2014-07-04 14:50:27 -04:00
item - > setText ( 0 , QString : : fromUtf8 ( details . name . c_str ( ) ) ) ;
2008-07-10 06:34:49 -04:00
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 ) ;
}
2013-01-22 19:22:17 -05:00
/* remove old items */
2008-07-10 06:34:49 -04:00
//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
//============================================================================
2012-02-11 16:41:41 -05:00
void FriendsDialog : : chooseColor ( )
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 ) ;
2012-02-11 16:41:41 -05:00
colorChanged ( ) ;
setColorAndFont ( ) ;
2010-10-07 20:07:44 -04:00
}
}
2009-07-13 15:58:11 -04:00
2012-02-11 16:41:41 -05:00
void FriendsDialog : : colorChanged ( )
2010-10-07 20:07:44 -04:00
{
QPixmap pxm ( 16 , 16 ) ;
2012-02-11 16:41:41 -05:00
pxm . fill ( mCurrentColor ) ;
2010-10-07 20:07:44 -04:00
ui . colorChatButton - > setIcon ( pxm ) ;
2008-07-10 06:34:49 -04:00
}
2012-02-11 16:41:41 -05:00
void FriendsDialog : : chooseFont ( )
2008-07-10 06:34:49 -04:00
{
bool ok ;
2012-02-11 16:41:41 -05:00
QFont font = QFontDialog : : getFont ( & ok , mCurrentFont , this ) ;
2010-10-07 20:07:44 -04:00
if ( ok ) {
2012-02-11 16:41:41 -05:00
mCurrentFont = font ;
fontChanged ( ) ;
setFont ( ) ;
2010-10-07 20:07:44 -04:00
}
2008-07-10 06:34:49 -04:00
}
2012-02-11 16:41:41 -05:00
void FriendsDialog : : fontChanged ( )
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 ( ) ) ;
2008-07-10 06:34:49 -04:00
}
2012-02-11 16:41:41 -05:00
void FriendsDialog : : setColorAndFont ( )
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 ( ) ) ;
2012-02-11 16:41:41 -05:00
2010-10-07 20:07:44 -04:00
ui . lineEdit - > setFont ( mCurrentFont ) ;
ui . lineEdit - > setTextColor ( mCurrentColor ) ;
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
2012-02-11 16:41:41 -05:00
void FriendsDialog : : setFont ( )
{
setColorAndFont ( ) ;
Settings - > setChatScreenFont ( mCurrentFont . toString ( ) ) ;
}
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 ;
}
2012-11-15 16:35:37 -05:00
ui . msgText - > append ( " <font color='grey'> " + DateTime : : formatTime ( QTime : : currentTime ( ) ) + " </font> - <font color=' " + color . name ( ) + " '><i> " + info + " </i></font> " ) ;
2008-11-24 09:07:26 -05:00
}
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 ( ) ;
2014-03-17 16:56:06 -04:00
rsHistory - > clear ( RsPeerId ( ) ) ;
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
}
}
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
{
2012-08-26 16:31:10 -04: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 ) ) {
2012-11-11 16:17:00 -05:00
ui . hashBox - > addAttachments ( files , TransferRequestFlags ( 0u ) ) ; // no anonymous routing, because it is for friends only!
2010-12-02 19:54:40 -05:00
}
2010-01-31 17:29:30 -05:00
}
2013-08-25 16:41:50 -04:00
void FriendsDialog : : addExtraPicture ( )
{
// select a picture file
QString file ;
2014-01-28 16:38:11 -05:00
if ( misc : : getOpenFileName ( window ( ) , RshareSettings : : LASTDIR_IMAGES , tr ( " Load Picture File " ) , " Pictures (*.png *.xpm *.jpg *.jpeg) " , file ) ) {
2013-08-25 16:41:50 -04:00
QString encodedImage ;
if ( RsHtml : : makeEmbeddedImage ( file , encodedImage , 640 * 480 ) ) {
QTextDocumentFragment fragment = QTextDocumentFragment : : fromHtml ( encodedImage ) ;
ui . lineEdit - > textCursor ( ) . insertFragment ( fragment ) ;
}
}
}
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 ;
2012-11-11 16:17:00 -05:00
2014-03-17 16:56:06 -04:00
if ( ! link . createExtraFile ( hashedFile . filename , hashedFile . size , QString : : fromStdString ( hashedFile . hash . toStdString ( ) ) , QString : : fromStdString ( rsPeers - > getOwnId ( ) . toStdString ( ) ) ) )
2011-12-07 08:08:12 -05:00
continue ;
2013-01-22 19:22:17 -05:00
2011-12-07 08:08:12 -05:00
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
2013-08-25 16:24:47 -04:00
ui . lineEdit - > insertHtml ( mesgString ) ;
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
{
2014-03-17 16:56:06 -04:00
ImHistoryBrowser imBrowser ( RsPeerId ( ) , ui . lineEdit , this ) ;
2010-09-01 10:15:50 -04:00
imBrowser . exec ( ) ;
}
2010-09-21 12:11:19 -04:00
2012-03-30 19:02:52 -04:00
/*static*/ bool FriendsDialog : : isGroupChatActive ( )
{
FriendsDialog * friendsDialog = dynamic_cast < FriendsDialog * > ( MainWindow : : getPage ( MainWindow : : Friends ) ) ;
if ( ! friendsDialog ) {
return false ;
}
if ( friendsDialog - > ui . tabWidget - > currentWidget ( ) = = friendsDialog - > ui . groupChatTab ) {
return true ;
}
return false ;
}
/*static*/ void FriendsDialog : : groupChatActivate ( )
{
FriendsDialog * friendsDialog = dynamic_cast < FriendsDialog * > ( MainWindow : : getPage ( MainWindow : : Friends ) ) ;
if ( ! friendsDialog ) {
return ;
}
MainWindow : : showWindow ( MainWindow : : Friends ) ;
friendsDialog - > ui . tabWidget - > setCurrentWidget ( friendsDialog - > ui . groupChatTab ) ;
friendsDialog - > ui . lineEdit - > setFocus ( ) ;
}