2010-05-14 07:48:20 -04:00
/****************************************************************
2007-11-14 22:18:48 -05:00
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , 2007 crypton
*
* 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
2008-11-24 09:07:26 -05:00
# include <QFile>
2007-11-14 22:18:48 -05:00
# include <QFileInfo>
2010-07-23 14:52:58 -04:00
# include <QShortcut>
# include <QWidgetAction>
# include <QScrollBar>
# include <QDesktopWidget>
# include <QColorDialog>
# include <QFontDialog>
# include <QDropEvent>
2008-11-24 09:07:26 -05:00
# include "common/vmessagebox.h"
2010-01-18 17:44:09 -05:00
# include <gui/mainpagestack.h>
2008-11-24 09:07:26 -05:00
# include "rshare.h"
# include "PeersDialog.h"
2010-08-06 05:40:23 -04:00
# include <retroshare/rsiface.h>
# include <retroshare/rspeers.h>
# include <retroshare/rsstatus.h>
# include <retroshare/rsmsgs.h>
# include <retroshare/rsnotify.h>
2010-05-11 16:02:52 -04:00
# include "settings/rsharesettings.h"
2008-01-25 03:49:40 -05:00
2007-11-14 22:18:48 -05:00
# include "chat/PopupChatDialog.h"
2010-05-23 15:13:41 -04:00
# include "msgs/MessageComposer.h"
2007-11-14 22:18:48 -05:00
# include "connect/ConfCertDialog.h"
2009-01-22 20:58:56 -05:00
# include "profile/ProfileView.h"
2009-09-25 21:10:25 -04:00
# include "profile/ProfileWidget.h"
2009-10-08 15:08:44 -04:00
# include "profile/StatusMessage.h"
2009-09-22 18:47:49 -04:00
# include "gui/connect/ConnectFriendWizard.h"
2010-01-16 20:36:50 -05:00
# include "gui/forums/CreateForum.h"
2010-05-02 07:41:23 -04:00
# include "gui/channels/CreateChannel.h"
2010-07-23 14:52:58 -04:00
# include "gui/feeds/AttachFileItem.h"
2010-07-15 07:25:34 -04:00
# include "RetroShareLink.h"
2008-12-07 09:19:13 -05:00
2010-05-02 20:09:55 -04:00
# include "MainWindow.h"
2010-08-12 12:00:21 -04:00
# include "NewsFeed.h"
2010-05-02 20:09:55 -04:00
2007-11-14 22:18:48 -05:00
# include <sstream>
2010-01-20 17:02:43 -05:00
# include <time.h>
2010-01-31 17:29:30 -05:00
# include <sys/stat.h>
2010-08-25 14:31:56 -04:00
# include <algorithm>
2007-11-14 22:18:48 -05:00
2010-05-05 07:47:29 -04:00
# include <QSound>
2008-11-24 09:07:26 -05:00
/* Images for context menu icons */
2007-11-14 22:18:48 -05:00
# define IMAGE_REMOVEFRIEND ": / images / removefriend16.png"
# define IMAGE_EXPIORTFRIEND ": / images / exportpeers_16x16.png"
2008-04-07 20:31:46 -04:00
# define IMAGE_PEERINFO ": / images / peerdetails_16x16.png"
2007-11-14 22:18:48 -05:00
# define IMAGE_CHAT ": / images / chat.png"
2008-04-03 17:32:45 -04:00
# define IMAGE_MSG ": / images / message-mail.png"
2009-01-22 20:58:56 -05:00
# define IMAGE_CONNECT ": / images / connect_friend.png"
2007-11-14 22:18:48 -05:00
/* Images for Status icons */
2008-07-10 06:34:49 -04:00
# define IMAGE_ONLINE ": / images / user / identity24.png"
2010-06-05 18:42:32 -04:00
# define IMAGE_AWAY ": / images / user / identity24away.png"
# define IMAGE_BUSY ": / images / user / identity24busy.png"
2010-06-05 19:27:08 -04:00
# define IMAGE_INACTIVE ": / images / user / identity24idle.png"
2008-07-11 11:51:49 -04:00
# define IMAGE_OFFLINE ": / images / user / identityoffline24.png"
2008-11-24 09:07:26 -05:00
# define IMAGE_OFFLINE2 ": / images / user / identitylightgrey24.png"
2009-04-29 11:48:01 -04:00
# define IMAGE_AVAIBLE ": / images / user / identityavaiblecyan24.png"
2009-10-15 12:39:21 -04:00
# define IMAGE_UNREACHABLE ": / images / user / identityunreachable24.png"
2009-04-29 11:48:01 -04:00
# define IMAGE_CONNECT2 ": / images / reload24.png"
2010-07-15 07:25:34 -04:00
# define IMAGE_PASTELINK ": / images / pasterslink.png"
2008-11-24 09:07:26 -05:00
2010-06-08 17:38:36 -04:00
# define COLUMN_COUNT 3
# define COLUMN_NAME 0
# define COLUMN_STATE 1
# define COLUMN_INFO 2
2010-06-25 10:19:48 -04:00
# define COLUMN_DATA 0 // column for storing the userdata id
# define ROLE_SORT Qt::UserRole
# define ROLE_ID Qt::UserRole + 1
2010-06-08 17:38:36 -04:00
2008-07-09 05:53:47 -04:00
/******
* # define PEERS_DEBUG 1
* * * * */
2010-06-08 17:38:36 -04:00
// quick and dirty for sorting, better use QTreeView and QSortFilterProxyModel
2010-06-17 13:39:32 -04:00
class MyPeerTreeWidgetItem : public QTreeWidgetItem
2010-06-08 17:38:36 -04:00
{
public :
2010-06-17 13:39:32 -04:00
MyPeerTreeWidgetItem ( QTreeWidget * pWidget , int type ) : QTreeWidgetItem ( type )
2010-06-08 17:38:36 -04:00
{
m_pWidget = pWidget ; // can't access the member "view"
}
bool operator < ( const QTreeWidgetItem & other ) const
{
2010-06-11 19:28:05 -04:00
int role = Qt : : DisplayRole ;
2010-06-08 17:38:36 -04:00
int column = m_pWidget ? m_pWidget - > sortColumn ( ) : 0 ;
2010-06-11 19:28:05 -04:00
switch ( column ) {
case COLUMN_STATE :
// sort by state set in user role
2010-06-25 10:19:48 -04:00
role = ROLE_SORT ;
2010-06-11 19:28:05 -04:00
// no break;
case COLUMN_NAME :
{
const QVariant v1 = data ( column , role ) ;
const QVariant v2 = other . data ( column , role ) ;
return ( v1 . toString ( ) . compare ( v2 . toString ( ) , Qt : : CaseInsensitive ) < 0 ) ;
}
2010-06-08 17:38:36 -04:00
}
// let the standard do the sort
return QTreeWidgetItem : : operator < ( other ) ;
}
private :
QTreeWidget * m_pWidget ; // the member "view" is private
} ;
2008-07-09 05:53:47 -04:00
2008-11-24 09:07:26 -05:00
/** Constructor */
PeersDialog : : PeersDialog ( QWidget * parent )
2010-01-02 16:45:46 -05:00
: RsAutoUpdatePage ( 1500 , parent ) ,
2010-05-12 15:03:30 -04:00
historyKeeper ( Rshare : : dataDirectory ( ) + " /his1.xml " ) ,
smWidget ( 0 )
2008-11-24 09:07:26 -05:00
{
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2009-10-08 15:08:44 -04:00
2009-09-30 18:30:57 -04:00
last_status_send_time = 0 ;
2010-01-18 17:44:09 -05:00
2008-11-24 09:07:26 -05:00
connect ( ui . peertreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( peertreeWidgetCostumPopupMenu ( QPoint ) ) ) ;
2010-04-15 08:02:23 -04:00
connect ( ui . peertreeWidget , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( chatfriend ( QTreeWidgetItem * ) ) ) ;
2007-11-14 22:18:48 -05:00
2009-09-02 18:42:31 -04:00
connect ( ui . avatartoolButton , SIGNAL ( clicked ( ) ) , SLOT ( getAvatar ( ) ) ) ;
2009-10-08 15:08:44 -04:00
connect ( ui . mypersonalstatuslabel , SIGNAL ( clicked ( ) ) , SLOT ( statusmessage ( ) ) ) ;
2010-01-16 20:36:50 -05:00
connect ( ui . actionSet_your_Avatar , SIGNAL ( triggered ( ) ) , this , SLOT ( getAvatar ( ) ) ) ;
connect ( ui . actionSet_your_Personal_Message , SIGNAL ( triggered ( ) ) , this , SLOT ( statusmessage ( ) ) ) ;
2010-01-31 17:29:30 -05:00
connect ( ui . addfileButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
connect ( ui . msgText , SIGNAL ( anchorClicked ( const QUrl & ) ) , SLOT ( anchorClicked ( const QUrl & ) ) ) ;
2010-01-16 20:36:50 -05:00
2010-06-18 17:59:33 -04:00
connect ( ui . action_Hide_Offline_Friends , SIGNAL ( triggered ( ) ) , this , SLOT ( insertPeers ( ) ) ) ;
connect ( ui . action_Hide_Status_Column , SIGNAL ( triggered ( ) ) , this , SLOT ( statusColumn ( ) ) ) ;
2010-01-19 16:43:40 -05:00
2010-01-31 17:29:30 -05:00
ui . peertabWidget - > setTabPosition ( QTabWidget : : North ) ;
2009-09-25 21:10:25 -04:00
ui . peertabWidget - > addTab ( new ProfileWidget ( ) , QString ( tr ( " Profile " ) ) ) ;
2010-08-12 12:02:19 -04:00
ui . peertabWidget - > addTab ( new NewsFeed ( ) , QString ( tr ( " Friends Storm " ) ) ) ;
2009-09-25 21:10:25 -04:00
2010-01-03 08:54:38 -05:00
ui . peertreeWidget - > setColumnCount ( 4 ) ;
2010-01-02 16:45:46 -05:00
ui . peertreeWidget - > setColumnHidden ( 3 , true ) ;
2010-01-13 16:16:18 -05:00
ui . peertreeWidget - > setColumnHidden ( 2 , true ) ;
2010-01-18 17:42:10 -05:00
ui . peertreeWidget - > sortItems ( 0 , Qt : : AscendingOrder ) ;
2009-07-13 15:58:11 -04:00
2010-06-08 17:38:36 -04:00
// set header text aligment
QTreeWidgetItem * headerItem = ui . peertreeWidget - > headerItem ( ) ;
headerItem - > setTextAlignment ( COLUMN_NAME , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( COLUMN_STATE , Qt : : AlignLeft | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( COLUMN_INFO , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
2008-07-12 07:57:09 -04:00
2008-07-10 06:34:49 -04:00
connect ( ui . lineEdit , SIGNAL ( textChanged ( ) ) , this , SLOT ( checkChat ( ) ) ) ;
connect ( ui . Sendbtn , SIGNAL ( clicked ( ) ) , this , SLOT ( sendMsg ( ) ) ) ;
2008-11-24 09:07:26 -05:00
connect ( ui . emoticonBtn , SIGNAL ( clicked ( ) ) , this , SLOT ( smileyWidgetgroupchat ( ) ) ) ;
2008-07-10 06:34:49 -04:00
2010-03-17 11:34:36 -04:00
ui . lineEdit - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui . lineEdit , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
pasteLinkAct = new QAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste retroshare Link " ) , this ) ;
connect ( pasteLinkAct , SIGNAL ( triggered ( ) ) , this , SLOT ( pasteLink ( ) ) ) ;
2009-07-13 15:58:11 -04:00
2008-07-10 06:34:49 -04:00
connect ( ui . msgText , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayInfoChatMenu ( const QPoint & ) ) ) ;
2009-07-13 15:58:11 -04:00
connect ( ui . textboldChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textunderlineChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
2008-07-10 06:34:49 -04:00
connect ( ui . textitalicChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
2009-07-13 15:58:11 -04:00
connect ( ui . fontsButton , SIGNAL ( clicked ( ) ) , this , SLOT ( getFont ( ) ) ) ;
2008-07-10 06:34:49 -04:00
connect ( ui . colorChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setColor ( ) ) ) ;
2010-04-27 18:08:38 -04:00
connect ( ui . actionSave_History , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSaveAs ( ) ) ) ;
2009-07-13 15:58:11 -04:00
2008-07-10 06:34:49 -04:00
ui . fontsButton - > setIcon ( QIcon ( QString ( " :/images/fonts.png " ) ) ) ;
2009-07-13 15:58:11 -04:00
2008-07-10 06:34:49 -04:00
_currentColor = Qt : : black ;
2009-01-22 20:58:56 -05:00
QPixmap pxm ( 16 , 16 ) ;
2008-07-10 06:34:49 -04:00
pxm . fill ( _currentColor ) ;
ui . colorChatButton - > setIcon ( pxm ) ;
2009-07-13 15:58:11 -04:00
2010-05-20 17:53:27 -04:00
Settings - > beginGroup ( QString ( " Chat " ) ) ;
mCurrentFont . fromString ( Settings - > value ( QString : : fromUtf8 ( " ChatScreenFont " ) ) . toString ( ) ) ;
2008-07-10 06:34:49 -04:00
ui . lineEdit - > setFont ( mCurrentFont ) ;
2010-05-20 17:53:27 -04:00
2010-05-18 14:02:51 -04:00
setChatInfo ( tr ( " Welcome to RetroShare's group chat. " ) , QString : : fromUtf8 ( " blue " ) ) ;
2010-05-11 16:02:52 -04:00
2010-05-20 17:53:27 -04:00
if ( Settings - > value ( QString : : fromUtf8 ( " GroupChat_History " ) , true ) . toBool ( ) )
2010-05-03 17:17:36 -04:00
{
2010-05-18 14:02:51 -04:00
QStringList him ;
2010-05-03 17:17:36 -04:00
historyKeeper . getMessages ( him , " " , " THIS " , 8 ) ;
foreach ( QString mess , him )
ui . msgText - > append ( mess ) ;
}
2010-05-20 17:53:27 -04:00
Settings - > endGroup ( ) ;
2009-07-13 15:58:11 -04:00
2010-05-03 17:17:36 -04:00
//setChatInfo(mess, "green");
2009-07-13 15:58:11 -04:00
2008-11-24 09:07:26 -05:00
QMenu * grpchatmenu = new QMenu ( ) ;
2008-07-10 06:34:49 -04:00
grpchatmenu - > addAction ( ui . actionClearChat ) ;
2010-04-27 18:08:38 -04:00
grpchatmenu - > addAction ( ui . actionSave_History ) ;
2010-05-03 17:17:36 -04:00
//grpchatmenu->addAction(ui.actionDisable_Emoticons);
2008-07-10 06:34:49 -04:00
ui . menuButton - > setMenu ( grpchatmenu ) ;
2009-07-13 15:58:11 -04:00
2008-11-24 09:07:26 -05:00
_underline = false ;
2008-07-10 06:34:49 -04:00
QTimer * timer = new QTimer ( this ) ;
timer - > connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( insertChat ( ) ) ) ;
timer - > start ( 500 ) ; /* half a second */
2009-09-22 18:47:49 -04:00
QMenu * menu = new QMenu ( ) ;
2010-01-18 17:44:09 -05:00
menu - > addAction ( ui . actionAdd_Friend ) ;
2010-01-16 20:36:50 -05:00
menu - > addSeparator ( ) ;
menu - > addAction ( ui . actionCreate_New_Forum ) ;
2010-02-06 15:49:24 -05:00
# ifndef RS_RELEASE_VERSION
2010-01-16 20:36:50 -05:00
menu - > addAction ( ui . actionCreate_New_Channel ) ;
2010-02-06 15:49:24 -05:00
# endif
2010-01-16 20:36:50 -05:00
menu - > addAction ( ui . actionSet_your_Avatar ) ;
menu - > addAction ( ui . actionSet_your_Personal_Message ) ;
2009-09-22 18:47:49 -04:00
ui . menupushButton - > setMenu ( menu ) ;
2010-01-16 21:27:32 -05:00
2010-02-07 07:36:37 -05:00
//ui.msgText->setOpenExternalLinks ( false );
//ui.msgText->setOpenLinks ( false );
2010-01-31 17:29:30 -05:00
setAcceptDrops ( true ) ;
ui . lineEdit - > setAcceptDrops ( false ) ;
2009-09-02 18:42:31 -04:00
updateAvatar ( ) ;
2009-09-29 18:52:46 -04:00
loadmypersonalstatus ( ) ;
2010-01-31 17:29:30 -05:00
loadEmoticonsgroupchat ( ) ;
2010-06-18 17:59:33 -04:00
displayMenu ( ) ;
2008-11-24 09:07:26 -05:00
2010-06-08 17:38:36 -04:00
// load settings
processSettings ( true ) ;
2010-05-06 10:39:50 -04:00
// workaround for Qt bug, should be solved in next Qt release 4.7.0
// http://bugreports.qt.nokia.com/browse/QTBUG-8270
QShortcut * Shortcut = new QShortcut ( QKeySequence ( Qt : : Key_Delete ) , ui . peertreeWidget , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( Shortcut , SIGNAL ( activated ( ) ) , this , SLOT ( removefriend ( ) ) ) ;
2008-11-24 09:07:26 -05:00
/* Hide platform specific features */
# ifdef Q_WS_WIN
# endif
}
2007-11-14 22:18:48 -05:00
2010-05-11 16:02:52 -04:00
PeersDialog : : ~ PeersDialog ( )
{
2010-06-08 17:38:36 -04:00
// save settings
processSettings ( false ) ;
2010-05-12 15:03:30 -04:00
delete smWidget ;
2010-05-11 16:02:52 -04:00
}
2010-06-08 17:38:36 -04:00
void PeersDialog : : processSettings ( bool bLoad )
{
QHeaderView * header = ui . peertreeWidget - > header ( ) ;
Settings - > beginGroup ( QString ( " PeersDialog " ) ) ;
if ( bLoad ) {
// load settings
// state of peer tree
header - > restoreState ( Settings - > value ( " PeerTree " ) . toByteArray ( ) ) ;
2010-06-16 15:00:28 -04:00
// state of hideUnconnected
2010-06-18 17:59:33 -04:00
ui . action_Hide_Offline_Friends - > setChecked ( Settings - > value ( " hideUnconnected " , false ) . toBool ( ) ) ;
// state of hideStatusColumn
ui . action_Hide_Status_Column - > setChecked ( Settings - > value ( " hideStatusColumn " , false ) . toBool ( ) ) ;
2010-06-16 15:00:28 -04:00
2010-06-08 17:38:36 -04:00
// 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 peer tree
Settings - > setValue ( " PeerTree " , header - > saveState ( ) ) ;
2010-06-16 15:00:28 -04:00
// state of hideUnconnected
2010-06-18 17:59:33 -04:00
Settings - > setValue ( " hideUnconnected " , ui . action_Hide_Offline_Friends - > isChecked ( ) ) ;
// state of hideStatusColumn
Settings - > setValue ( " hideStatusColumn " , ui . action_Hide_Status_Column - > isChecked ( ) ) ;
2010-06-16 15:00:28 -04:00
2010-06-08 17:38:36 -04:00
// 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
}
Settings - > endGroup ( ) ;
}
2010-03-17 11:34:36 -04:00
void PeersDialog : : pasteLink ( )
{
ui . lineEdit - > insertHtml ( RSLinkClipboard : : toHtml ( ) ) ;
}
void PeersDialog : : contextMenu ( QPoint point )
{
if ( RSLinkClipboard : : empty ( ) )
return ;
QMenu contextMnu ( this ) ;
contextMnu . addAction ( pasteLinkAct ) ;
2010-05-14 16:55:44 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2010-03-17 11:34:36 -04:00
}
2008-11-24 09:07:26 -05:00
void PeersDialog : : peertreeWidgetCostumPopupMenu ( QPoint point )
{
2010-07-15 07:25:34 -04:00
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( ! c ) {
//no peer selected
return ;
}
2008-11-24 09:07:26 -05:00
2010-07-15 07:25:34 -04:00
QMenu contextMnu ( this ) ;
2010-01-18 17:44:40 -05:00
2010-07-15 07:25:34 -04:00
QAction * expandAll = new QAction ( tr ( " Expand all " ) , & contextMnu ) ;
connect ( expandAll , SIGNAL ( triggered ( ) ) , ui . peertreeWidget , SLOT ( expandAll ( ) ) ) ;
2010-01-18 17:44:40 -05:00
2010-07-15 07:25:34 -04:00
QAction * collapseAll = new QAction ( tr ( " Collapse all " ) , & contextMnu ) ;
connect ( collapseAll , SIGNAL ( triggered ( ) ) , ui . peertreeWidget , SLOT ( collapseAll ( ) ) ) ;
2007-11-14 22:18:48 -05:00
2010-07-15 07:25:34 -04:00
QAction * chatAct = new QAction ( QIcon ( IMAGE_CHAT ) , tr ( " Chat " ) , & contextMnu ) ;
connect ( chatAct , SIGNAL ( triggered ( ) ) , this , SLOT ( chatfriendproxy ( ) ) ) ;
2007-11-14 22:18:48 -05:00
2010-07-15 07:25:34 -04:00
QAction * msgAct = new QAction ( QIcon ( IMAGE_MSG ) , tr ( " Message Friend " ) , & contextMnu ) ;
connect ( msgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( msgfriend ( ) ) ) ;
2009-07-13 15:58:11 -04:00
2010-07-15 07:25:34 -04:00
QAction * connectfriendAct = new QAction ( QIcon ( IMAGE_CONNECT ) , tr ( " Connect To Friend " ) , & contextMnu ) ;
connect ( connectfriendAct , SIGNAL ( triggered ( ) ) , this , SLOT ( connectfriend ( ) ) ) ;
2009-01-22 20:58:56 -05:00
2010-07-15 07:25:34 -04:00
QAction * configurefriendAct = new QAction ( QIcon ( IMAGE_PEERINFO ) , tr ( " Peer Details " ) , & contextMnu ) ;
connect ( configurefriendAct , SIGNAL ( triggered ( ) ) , this , SLOT ( configurefriend ( ) ) ) ;
2009-07-13 15:58:11 -04:00
2010-07-15 07:25:34 -04:00
QAction * recommendfriendAct = new QAction ( QIcon ( IMAGE_EXPIORTFRIEND ) , tr ( " Recomend this Friend to... " ) , & contextMnu ) ;
connect ( recommendfriendAct , SIGNAL ( triggered ( ) ) , this , SLOT ( recommendfriend ( ) ) ) ;
2010-07-16 16:12:02 -04:00
QAction * pastePersonAct = new QAction ( QIcon ( IMAGE_PASTELINK ) , tr ( " Paste Person Link " ) , & contextMnu ) ;
2010-07-15 07:25:34 -04:00
if ( ! RSLinkClipboard : : empty ( RetroShareLink : : TYPE_PERSON ) ) {
connect ( pastePersonAct , SIGNAL ( triggered ( ) ) , this , SLOT ( pastePerson ( ) ) ) ;
} else {
pastePersonAct - > setDisabled ( true ) ;
}
QAction * profileviewAct = new QAction ( QIcon ( IMAGE_PEERINFO ) , tr ( " Profile View " ) , & contextMnu ) ;
connect ( profileviewAct , SIGNAL ( triggered ( ) ) , this , SLOT ( viewprofile ( ) ) ) ;
QAction * exportfriendAct = new QAction ( QIcon ( IMAGE_EXPIORTFRIEND ) , tr ( " Export Friend " ) , & contextMnu ) ;
connect ( exportfriendAct , SIGNAL ( triggered ( ) ) , this , SLOT ( exportfriend ( ) ) ) ;
QAction * removefriendAct ;
if ( c - > type ( ) = = 0 ) {
//this is a GPG key
removefriendAct = new QAction ( QIcon ( IMAGE_REMOVEFRIEND ) , tr ( " Deny Friend " ) , & contextMnu ) ;
} else {
removefriendAct = new QAction ( QIcon ( IMAGE_REMOVEFRIEND ) , tr ( " Remove Friend Location " ) , & contextMnu ) ;
}
connect ( removefriendAct , SIGNAL ( triggered ( ) ) , this , SLOT ( removefriend ( ) ) ) ;
2009-07-13 15:58:11 -04:00
2008-11-24 09:07:26 -05:00
2010-07-15 07:25:34 -04:00
QWidget * widget = new QWidget ( & contextMnu ) ;
widget - > setStyleSheet ( " .QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;} " ) ;
2007-11-14 22:18:48 -05:00
2010-07-15 07:25:34 -04:00
QHBoxLayout * hbox = new QHBoxLayout ( ) ;
hbox - > setMargin ( 0 ) ;
hbox - > setSpacing ( 6 ) ;
2009-09-24 17:38:40 -04:00
2010-07-15 07:25:34 -04:00
iconLabel = new QLabel ( this ) ;
iconLabel - > setPixmap ( QPixmap ( " :/images/user/friends24.png " ) ) ;
iconLabel - > setMaximumSize ( iconLabel - > frameSize ( ) . height ( ) + 24 , 24 ) ;
hbox - > addWidget ( iconLabel ) ;
if ( c - > type ( ) = = 0 ) {
//this is a GPG key
textLabel = new QLabel ( tr ( " <strong>GPG Key</strong> " ) , widget ) ;
} else {
textLabel = new QLabel ( tr ( " <strong>RetroShare instance</strong> " ) , widget ) ;
}
hbox - > addWidget ( textLabel ) ;
spacerItem = new QSpacerItem ( 40 , 20 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ;
hbox - > addItem ( spacerItem ) ;
widget - > setLayout ( hbox ) ;
2009-09-24 17:38:40 -04:00
2010-07-15 07:25:34 -04:00
QWidgetAction * widgetAction = new QWidgetAction ( this ) ;
widgetAction - > setDefaultWidget ( widget ) ;
contextMnu . addAction ( widgetAction ) ;
contextMnu . addAction ( chatAct ) ;
contextMnu . addAction ( msgAct ) ;
contextMnu . addAction ( configurefriendAct ) ;
//contextMnu.addAction( profileviewAct);
if ( c - > type ( ) = = 0 ) {
contextMnu . addAction ( recommendfriendAct ) ;
} else {
//this is a SSL key
contextMnu . addAction ( connectfriendAct ) ;
}
contextMnu . addAction ( pastePersonAct ) ;
contextMnu . addAction ( removefriendAct ) ;
//contextMnu.addAction( exportfriendAct);
contextMnu . addSeparator ( ) ;
contextMnu . addAction ( expandAll ) ;
contextMnu . addAction ( collapseAll ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
2008-11-24 09:07:26 -05:00
}
2010-05-06 10:39:50 -04:00
// replaced by shortcut
//void PeersDialog::keyPressEvent(QKeyEvent *e)
//{
// if(e->key() == Qt::Key_Delete)
// {
// removefriend() ;
// e->accept() ;
// }
// else
// MainPage::keyPressEvent(e) ;
//}
2010-01-17 12:58:28 -05:00
2009-11-17 07:45:06 -05:00
void PeersDialog : : updateDisplay ( )
{
2010-01-19 16:43:13 -05:00
// 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> " ) ;
ui . nicklabel - > setText ( titleStr . arg ( QString : : fromStdString ( pd . name ) + tr ( " (me) " ) + QString : : fromStdString ( pd . location ) ) ) ;
}
insertPeers ( ) ;
2009-11-17 07:45:06 -05:00
}
2007-11-14 22:18:48 -05:00
/* get the list of peers from the RsIface. */
void PeersDialog : : insertPeers ( )
{
2010-08-03 08:35:26 -04:00
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog::insertPeers() called. " < < std : : endl ;
# endif
std : : list < std : : string > gpgFriends ;
std : : list < std : : string > : : iterator it ;
std : : list < StatusInfo > statusInfo ;
2010-08-20 14:45:44 -04:00
rsStatus - > getStatusList ( statusInfo ) ;
2010-08-03 08:35:26 -04:00
if ( ! rsPeers ) {
/* not ready yet! */
std : : cerr < < " PeersDialog::insertPeers() not ready yet : rsPeers unintialized. " < < std : : endl ;
return ;
}
bool bHideUnconnected = ui . action_Hide_Offline_Friends - > isChecked ( ) ;
rsPeers - > getGPGAcceptedList ( gpgFriends ) ;
//add own gpg id, if we have more than on location (ssl client)
std : : list < std : : string > ownSslContacts ;
std : : string ownId = rsPeers - > getGPGOwnId ( ) ;
rsPeers - > getSSLChildListOfGPGId ( ownId , ownSslContacts ) ;
if ( ownSslContacts . size ( ) > 0 ) {
gpgFriends . push_back ( ownId ) ;
}
/* get a link to the table */
QTreeWidget * peertreeWidget = ui . peertreeWidget ;
//remove items that are not friends anymore
int itemCount = peertreeWidget - > topLevelItemCount ( ) ;
int index = 0 ;
while ( index < itemCount ) {
std : : string gpg_widget_id = ( peertreeWidget - > topLevelItem ( index ) ) - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
2010-08-25 14:31:56 -04:00
if ( std : : find ( gpgFriends . begin ( ) , gpgFriends . end ( ) , gpg_widget_id ) = = gpgFriends . end ( ) ) {
2010-08-03 08:35:26 -04:00
delete ( peertreeWidget - > takeTopLevelItem ( index ) ) ;
// count again
itemCount = peertreeWidget - > topLevelItemCount ( ) ;
} else {
index + + ;
}
}
//add the gpg friends
for ( it = gpgFriends . begin ( ) ; it ! = gpgFriends . end ( ) ; it + + ) {
2010-02-08 09:06:43 -05:00
# ifdef PEERS_DEBUG
2010-08-03 08:35:26 -04:00
std : : cerr < < " PeersDialog::insertPeers() inserting gpg_id : " < < * it < < std : : endl ;
2010-02-08 09:06:43 -05:00
# endif
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
/* make a widget per friend */
QTreeWidgetItem * gpg_item = NULL ;
QTreeWidgetItem * gpg_item_loop = NULL ;
QString gpgid = QString : : fromStdString ( * it ) ;
itemCount = peertreeWidget - > topLevelItemCount ( ) ;
for ( int nIndex = 0 ; nIndex < itemCount ; nIndex + + ) {
gpg_item_loop = peertreeWidget - > topLevelItem ( nIndex ) ;
if ( gpg_item_loop - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) = = gpgid ) {
gpg_item = gpg_item_loop ;
break ;
}
}
2007-11-14 22:18:48 -05:00
2010-08-03 08:35:26 -04:00
RsPeerDetails detail ;
if ( ( ! rsPeers - > getPeerDetails ( * it , detail ) | | ! detail . accept_connection )
& & detail . gpg_id ! = ownId ) {
//don't accept anymore connection, remove from the view
if ( gpg_item ) {
delete ( peertreeWidget - > takeTopLevelItem ( peertreeWidget - > indexOfTopLevelItem ( gpg_item ) ) ) ;
}
continue ;
2008-01-25 03:49:40 -05:00
}
2010-08-03 08:35:26 -04:00
bool bNew = false ;
if ( gpg_item = = NULL ) {
gpg_item = new MyPeerTreeWidgetItem ( peertreeWidget , 0 ) ; //set type to 0 for custom popup menu
gpg_item - > setChildIndicatorPolicy ( QTreeWidgetItem : : DontShowIndicatorWhenChildless ) ;
bNew = true ;
}
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
gpg_item - > setText ( COLUMN_NAME , QString : : fromStdString ( detail . name ) ) ;
gpg_item - > setSizeHint ( COLUMN_NAME , QSize ( 26 , 26 ) ) ;
2007-11-14 22:18:48 -05:00
2010-08-03 08:35:26 -04:00
gpg_item - > setTextAlignment ( COLUMN_NAME , Qt : : AlignLeft | Qt : : AlignVCenter ) ;
2010-01-13 19:38:36 -05:00
2010-08-03 08:35:26 -04:00
/* not displayed, used to find back the item */
gpg_item - > setData ( COLUMN_DATA , ROLE_ID , QString : : fromStdString ( detail . id ) ) ;
2010-01-02 16:45:46 -05:00
2010-03-06 16:30:18 -05:00
//remove items that are not friends anymore
2010-08-03 08:35:26 -04:00
int childCount = gpg_item - > childCount ( ) ;
int childIndex = 0 ;
while ( childIndex < childCount ) {
std : : string ssl_id = gpg_item - > child ( childIndex ) - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
if ( ! rsPeers - > isFriend ( ssl_id ) ) {
delete ( gpg_item - > takeChild ( childIndex ) ) ;
// count again
childCount = gpg_item - > childCount ( ) ;
2010-01-13 16:25:18 -05:00
} else {
2010-08-03 08:35:26 -04:00
childIndex + + ;
2010-01-13 16:25:18 -05:00
}
}
2010-08-03 08:35:26 -04:00
//update the childs (ssl certs)
bool gpg_connected = false ;
bool gpg_online = false ;
std : : list < std : : string > sslContacts ;
rsPeers - > getSSLChildListOfGPGId ( detail . gpg_id , sslContacts ) ;
for ( std : : list < std : : string > : : iterator sslIt = sslContacts . begin ( ) ; sslIt ! = sslContacts . end ( ) ; sslIt + + ) {
QTreeWidgetItem * sslItem = NULL ;
//find the corresponding sslItem child item of the gpg item
bool newChild = true ;
childCount = gpg_item - > childCount ( ) ;
for ( int childIndex = 0 ; childIndex < childCount ; childIndex + + ) {
if ( gpg_item - > child ( childIndex ) - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) = = * sslIt ) {
sslItem = gpg_item - > child ( childIndex ) ;
newChild = false ;
2010-06-25 10:19:48 -04:00
break ;
}
2010-01-13 16:22:52 -05:00
}
2009-07-13 15:58:11 -04:00
2010-08-03 08:35:26 -04:00
RsPeerDetails sslDetail ;
if ( ! rsPeers - > getPeerDetails ( * sslIt , sslDetail ) | | ! rsPeers - > isFriend ( * sslIt ) ) {
# ifdef PEERS_DEBUG
std : : cerr < < " Removing widget from the view : id : " < < * sslIt < < std : : endl ;
# endif
//child has disappeared, remove it from the gpg_item
if ( sslItem ) {
gpg_item - > removeChild ( sslItem ) ;
2010-05-12 16:10:22 -04:00
}
2010-01-13 16:25:18 -05:00
continue ;
}
2007-11-14 22:18:48 -05:00
2010-08-03 08:35:26 -04:00
if ( newChild ) {
sslItem = new MyPeerTreeWidgetItem ( peertreeWidget , 1 ) ; //set type to 1 for custom popup menu
2010-05-12 16:10:22 -04:00
}
2010-01-13 16:25:18 -05:00
/* not displayed, used to find back the item */
2010-08-03 08:35:26 -04:00
sslItem - > setData ( COLUMN_DATA , ROLE_ID , QString : : fromStdString ( sslDetail . id ) ) ;
2010-01-13 16:16:18 -05:00
2010-08-03 08:35:26 -04:00
QString sText ;
2010-08-06 17:14:25 -04:00
std : : string customStateString ;
if ( sslDetail . state & RS_PEER_STATE_CONNECTED ) {
customStateString = rsMsgs - > getCustomStateString ( sslDetail . id ) ;
}
2010-08-03 08:35:26 -04:00
sText = tr ( " location : " ) + QString : : fromStdString ( sslDetail . location ) ;
if ( customStateString . empty ( ) = = false ) {
sText + = tr ( " - " ) + QString : : fromStdString ( customStateString ) ;
}
sslItem - > setText ( COLUMN_NAME , sText ) ;
sslItem - > setToolTip ( COLUMN_NAME , sText ) ;
2010-05-12 16:10:22 -04:00
2010-08-03 08:35:26 -04:00
/* not displayed, used to find back the item */
sslItem - > setText ( COLUMN_STATE , QString : : fromStdString ( sslDetail . autoconnect ) ) ;
// sort location
sslItem - > setData ( COLUMN_STATE , ROLE_SORT , sText ) ;
/* change color and icon */
int i ;
if ( sslDetail . state & RS_PEER_STATE_CONNECTED ) {
sslItem - > setHidden ( false ) ;
gpg_connected = true ;
sslItem - > setIcon ( COLUMN_NAME , ( QIcon ( " :/images/connect_established.png " ) ) ) ;
sslItem - > setIcon ( COLUMN_STATE , ( QIcon ( " :/images/encrypted32.png " ) ) ) ;
QFont font ;
font . setBold ( true ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
sslItem - > setTextColor ( i , ( Qt : : darkBlue ) ) ;
sslItem - > setFont ( i , font ) ;
2010-01-13 16:25:18 -05:00
}
2010-08-03 08:35:26 -04:00
} else if ( sslDetail . state & RS_PEER_STATE_ONLINE ) {
sslItem - > setHidden ( bHideUnconnected ) ;
gpg_online = true ;
2010-01-13 16:25:18 -05:00
2010-08-03 08:35:26 -04:00
QFont font ;
font . setBold ( true ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
sslItem - > setTextColor ( i , ( Qt : : black ) ) ;
sslItem - > setFont ( i , font ) ;
2010-01-13 16:22:52 -05:00
}
2010-08-03 08:35:26 -04:00
} else {
sslItem - > setHidden ( bHideUnconnected ) ;
if ( sslDetail . autoconnect ! = " Offline " ) {
sslItem - > setIcon ( COLUMN_NAME , ( QIcon ( " :/images/connect_creating.png " ) ) ) ;
2010-01-13 16:22:52 -05:00
} else {
2010-08-03 08:35:26 -04:00
sslItem - > setIcon ( COLUMN_NAME , ( QIcon ( " :/images/connect_no.png " ) ) ) ;
2010-01-13 16:16:18 -05:00
}
2010-01-13 16:22:52 -05:00
2010-08-03 08:35:26 -04:00
QFont font ;
font . setBold ( false ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
sslItem - > setTextColor ( i , ( Qt : : black ) ) ;
sslItem - > setFont ( i , font ) ;
2010-01-13 16:22:52 -05:00
}
2010-01-13 16:16:18 -05:00
}
2010-01-13 16:25:18 -05:00
2010-08-03 08:35:26 -04:00
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog::insertPeers() inserting sslItem. " < < std : : endl ;
# endif
/* add ssl child to the list. If item is already in the list, it won't be duplicated thanks to Qt */
if ( newChild ) {
gpg_item - > addChild ( sslItem ) ;
gpg_item - > setExpanded ( true ) ;
}
}
int i = 0 ;
if ( gpg_connected ) {
gpg_item - > setHidden ( false ) ;
gpg_item - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_ONLINE ) ) ) ;
gpg_item - > setText ( COLUMN_STATE , tr ( " Online " ) ) ;
gpg_item - > setData ( COLUMN_STATE , ROLE_SORT , BuildStateSortString ( true , gpg_item - > text ( COLUMN_NAME ) , PEER_STATE_ONLINE ) ) ;
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
std : : list < StatusInfo > : : iterator it ;
for ( it = statusInfo . begin ( ) ; it ! = statusInfo . end ( ) ; it + + ) {
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
std : : list < std : : string > : : iterator cont_it ;
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
// don't forget the kids
for ( cont_it = sslContacts . begin ( ) ; cont_it ! = sslContacts . end ( ) ; cont_it + + ) {
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
if ( ( it - > id = = * cont_it ) & & ( rsPeers - > isOnline ( * cont_it ) ) ) {
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
std : : string status ;
rsStatus - > getStatusString ( it - > status , status ) ;
gpg_item - > setText ( COLUMN_INFO , QString : : fromStdString ( status ) ) ;
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
QFont font ;
font . setBold ( true ) ;
2010-06-08 17:38:36 -04:00
2010-08-03 08:35:26 -04:00
switch ( it - > status ) {
case RS_STATUS_INACTIVE :
gpg_item - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_INACTIVE ) ) ) ;
gpg_item - > setToolTip ( COLUMN_NAME , tr ( " Peer Idle " ) ) ;
gpg_item - > setText ( COLUMN_STATE , tr ( " Idle " ) ) ;
gpg_item - > setData ( COLUMN_STATE , ROLE_SORT , BuildStateSortString ( true , gpg_item - > text ( COLUMN_NAME ) , PEER_STATE_INACTIVE ) ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpg_item - > setTextColor ( i , ( Qt : : gray ) ) ;
gpg_item - > setFont ( i , font ) ;
2010-06-08 17:38:36 -04:00
}
2010-08-03 08:35:26 -04:00
break ;
case RS_STATUS_ONLINE :
gpg_item - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_ONLINE ) ) ) ;
gpg_item - > setToolTip ( COLUMN_NAME , tr ( " Peer Online " ) ) ;
gpg_item - > setText ( COLUMN_STATE , tr ( " Online " ) ) ;
gpg_item - > setData ( COLUMN_STATE , ROLE_SORT , BuildStateSortString ( true , gpg_item - > text ( COLUMN_NAME ) , PEER_STATE_ONLINE ) ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpg_item - > setTextColor ( i , ( Qt : : darkBlue ) ) ;
gpg_item - > setFont ( i , font ) ;
2010-06-08 17:38:36 -04:00
}
2010-08-03 08:35:26 -04:00
break ;
case RS_STATUS_AWAY :
gpg_item - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_AWAY ) ) ) ;
gpg_item - > setToolTip ( COLUMN_NAME , tr ( " Peer Away " ) ) ;
gpg_item - > setText ( COLUMN_STATE , tr ( " Away " ) ) ;
gpg_item - > setData ( COLUMN_STATE , ROLE_SORT , BuildStateSortString ( true , gpg_item - > text ( COLUMN_NAME ) , PEER_STATE_AWAY ) ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpg_item - > setTextColor ( i , ( Qt : : gray ) ) ;
gpg_item - > setFont ( i , font ) ;
2010-06-08 17:38:36 -04:00
}
2010-08-03 08:35:26 -04:00
break ;
case RS_STATUS_BUSY :
gpg_item - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_BUSY ) ) ) ;
gpg_item - > setToolTip ( COLUMN_NAME , tr ( " Peer Busy " ) ) ;
gpg_item - > setText ( COLUMN_STATE , tr ( " Busy " ) ) ;
gpg_item - > setData ( COLUMN_STATE , ROLE_SORT , BuildStateSortString ( true , gpg_item - > text ( COLUMN_NAME ) , PEER_STATE_BUSY ) ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpg_item - > setTextColor ( i , ( Qt : : gray ) ) ;
gpg_item - > setFont ( i , font ) ;
2010-06-08 17:38:36 -04:00
}
2010-08-03 08:35:26 -04:00
break ;
2010-06-08 17:38:36 -04:00
}
2010-06-05 18:42:32 -04:00
}
2010-01-18 17:42:10 -05:00
}
}
2010-08-03 08:35:26 -04:00
} else if ( gpg_online ) {
gpg_item - > setHidden ( bHideUnconnected ) ;
gpg_item - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_AVAIBLE ) ) ) ;
gpg_item - > setText ( COLUMN_STATE , tr ( " Available " ) ) ;
gpg_item - > setData ( COLUMN_STATE , ROLE_SORT , BuildStateSortString ( true , gpg_item - > text ( COLUMN_NAME ) , PEER_STATE_AVAILABLE ) ) ;
QFont font ;
font . setBold ( true ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpg_item - > setTextColor ( i , ( Qt : : black ) ) ;
gpg_item - > setFont ( i , font ) ;
}
} else {
gpg_item - > setHidden ( bHideUnconnected ) ;
gpg_item - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_OFFLINE ) ) ) ;
gpg_item - > setText ( COLUMN_STATE , tr ( " Offline " ) ) ;
gpg_item - > setData ( COLUMN_STATE , ROLE_SORT , BuildStateSortString ( true , gpg_item - > text ( COLUMN_NAME ) , PEER_STATE_OFFLINE ) ) ;
QFont font ;
font . setBold ( false ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpg_item - > setTextColor ( i , ( Qt : : black ) ) ;
gpg_item - > setFont ( i , font ) ;
2010-06-13 08:26:23 -04:00
}
2010-01-13 16:22:52 -05:00
}
2010-08-03 08:35:26 -04:00
if ( bNew ) {
/* add gpg item to the list */
peertreeWidget - > addTopLevelItem ( gpg_item ) ;
}
}
2007-11-14 22:18:48 -05:00
}
/* Utility Fns */
std : : string getPeerRsCertId ( QTreeWidgetItem * i )
{
2010-06-25 10:19:48 -04:00
std : : string id = i - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
return id ;
2007-11-14 22:18:48 -05:00
}
/** Open a QFileDialog to browse for export a file. */
void PeersDialog : : exportfriend ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
2008-07-09 05:53:47 -04:00
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " PeersDialog::exportfriend() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
if ( ! c )
{
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2010-01-13 16:16:18 -05:00
std : : cerr < < " PeersDialog::exportfriend() None Selected -- sorry " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
return ;
}
std : : string id = getPeerRsCertId ( c ) ;
QString fileName = QFileDialog : : getSaveFileName ( this , tr ( " Save Certificate " ) , " " ,
tr ( " Certificates (*.pqi) " ) ) ;
std : : string file = fileName . toStdString ( ) ;
if ( file ! = " " )
{
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2010-02-07 18:01:46 -05:00
std : : cerr < < " PeersDialog::exportfriend() Saving to: " < < file < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-01-25 03:49:40 -05:00
if ( rsPeers )
{
2010-01-13 16:22:52 -05:00
rsPeers - > saveCertificateToFile ( id , file ) ;
2008-01-25 03:49:40 -05:00
}
2007-11-14 22:18:48 -05:00
}
}
2010-06-17 13:39:32 -04:00
void PeersDialog : : chatfriendproxy ( )
{
chatfriend ( getCurrentPeer ( ) ) ;
2010-04-15 08:02:23 -04:00
}
2010-06-17 13:39:32 -04:00
void PeersDialog : : chatfriend ( QTreeWidgetItem * pPeer )
2010-04-15 08:02:23 -04:00
{
2010-06-17 13:39:32 -04:00
if ( pPeer = = NULL ) {
return ;
2010-04-15 08:02:23 -04:00
}
2007-11-14 22:18:48 -05:00
2010-06-25 10:19:48 -04:00
std : : string id = pPeer - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
2010-06-17 13:39:32 -04:00
PopupChatDialog : : chatFriend ( id ) ;
2007-11-14 22:18:48 -05:00
}
void PeersDialog : : msgfriend ( )
{
2010-06-17 13:39:32 -04:00
QTreeWidgetItem * peer = getCurrentPeer ( ) ;
2007-11-14 22:18:48 -05:00
2010-06-17 13:39:32 -04:00
if ( ! peer )
return ;
2010-05-02 20:09:55 -04:00
2010-06-25 10:19:48 -04:00
std : : string id = peer - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
2010-06-17 13:39:32 -04:00
MessageComposer : : msgFriend ( id ) ;
2007-11-14 22:18:48 -05:00
}
2010-07-15 07:25:34 -04:00
void PeersDialog : : recommendfriend ( )
{
QTreeWidgetItem * peer = getCurrentPeer ( ) ;
if ( ! peer )
return ;
std : : list < std : : string > ids ;
ids . push_back ( peer - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ) ;
MessageComposer : : recommendFriend ( ids ) ;
}
void PeersDialog : : pastePerson ( )
{
RSLinkClipboard : : process ( RetroShareLink : : TYPE_PERSON , RSLINK_PROCESS_NOTIFY_ERROR ) ;
}
2007-11-14 22:18:48 -05:00
QTreeWidgetItem * PeersDialog : : getCurrentPeer ( )
{
/* get the current, and extract the Id */
/* get a link to the table */
QTreeWidget * peerWidget = ui . peertreeWidget ;
QTreeWidgetItem * item = peerWidget - > currentItem ( ) ;
if ( ! item )
{
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " Invalid Current Item " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
return NULL ;
}
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2007-11-14 22:18:48 -05:00
/* Display the columns of this item. */
std : : ostringstream out ;
out < < " CurrentPeerItem: " < < std : : endl ;
2010-06-08 17:38:36 -04:00
for ( int i = 1 ; i < COLUMN_COUNT ; i + + )
2007-11-14 22:18:48 -05:00
{
QString txt = item - > text ( i ) ;
out < < " \t " < < i < < " : " < < txt . toStdString ( ) < < std : : endl ;
}
std : : cerr < < out . str ( ) ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
return item ;
}
/* So from the Peers Dialog we can call the following control Functions:
* ( 1 ) Remove Current . FriendRemove ( id )
* ( 2 ) Allow / DisAllow . FriendStatus ( id , accept )
* ( 2 ) Connect . FriendConnectAttempt ( id , accept )
* ( 3 ) Set Address . FriendSetAddress ( id , str , port )
* ( 4 ) Set Trust . FriendTrustSignature ( id , bool )
* ( 5 ) Configure ( GUI Only ) - > 3 / 4
*
* All of these rely on the finding of the current Id .
*/
2009-07-13 15:58:11 -04:00
2007-11-14 22:18:48 -05:00
2008-11-24 09:07:26 -05:00
void PeersDialog : : removefriend ( )
2007-11-14 22:18:48 -05:00
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " PeersDialog::removefriend() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
if ( ! c )
{
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2010-04-15 08:02:23 -04:00
std : : cerr < < " PeersDialog::removefriend() None Selected -- sorry " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
return ;
}
2008-01-25 03:49:40 -05:00
if ( rsPeers )
{
2010-05-06 13:04:09 -04:00
if ( ( QMessageBox : : question ( this , tr ( " RetroShare " ) , tr ( " Do you want to remove this Friend? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes )
{
rsPeers - > removeFriend ( getPeerRsCertId ( c ) ) ;
emit friendsUpdated ( ) ;
}
else
return ;
2008-01-25 03:49:40 -05:00
}
2007-11-14 22:18:48 -05:00
}
2008-11-24 09:07:26 -05:00
void PeersDialog : : connectfriend ( )
2007-11-14 22:18:48 -05:00
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " PeersDialog::connectfriend() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-04-07 18:54:15 -04:00
if ( ! c )
{
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2008-04-07 18:54:15 -04:00
std : : cerr < < " PeersDialog::connectfriend() Noone Selected -- sorry " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-04-07 18:54:15 -04:00
return ;
}
2008-01-25 03:49:40 -05:00
if ( rsPeers )
{
rsPeers - > connectAttempt ( getPeerRsCertId ( c ) ) ;
2010-06-08 17:38:36 -04:00
c - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_CONNECT2 ) ) ) ;
2008-01-25 03:49:40 -05:00
}
2007-11-14 22:18:48 -05:00
}
/* GUI stuff -> don't do anything directly with Control */
2008-11-24 09:07:26 -05:00
void PeersDialog : : configurefriend ( )
2007-11-14 22:18:48 -05:00
{
2009-05-07 18:43:11 -04:00
ConfCertDialog : : show ( getPeerRsCertId ( getCurrentPeer ( ) ) ) ;
2007-11-14 22:18:48 -05:00
}
2009-09-30 18:30:57 -04:00
void PeersDialog : : resetStatusBar ( )
{
2010-02-08 11:42:26 -05:00
# ifdef PEERS_DEBUG
2009-09-30 18:30:57 -04:00
std : : cerr < < " PeersDialog: reseting status bar. " < < std : : endl ;
2010-02-08 11:42:26 -05:00
# endif
2009-09-30 18:30:57 -04:00
ui . statusStringLabel - > setText ( QString ( " " ) ) ;
}
void PeersDialog : : updateStatusTyping ( )
{
if ( time ( NULL ) - last_status_send_time > 5 ) // limit 'peer is typing' packets to at most every 10 sec
{
2010-02-10 05:56:54 -05:00
# ifdef PEERS_DEBUG
2009-09-30 18:30:57 -04:00
std : : cerr < < " PeersDialog: sending group chat typing info. " < < std : : endl ;
2010-02-10 05:56:54 -05:00
# endif
2009-09-30 18:30:57 -04:00
rsMsgs - > sendGroupChatStatusString ( rsiface - > getConfig ( ) . ownName + " is typing... " ) ;
last_status_send_time = time ( NULL ) ;
}
}
// Called by libretroshare through notifyQt to display the peer's status
//
void PeersDialog : : updateStatusString ( const QString & status_string )
{
2010-02-10 16:53:37 -05:00
# ifdef PEERS_DEBUG
2009-09-30 18:30:57 -04:00
std : : cerr < < " PeersDialog: received group chat typing info. updating gui. " < < std : : endl ;
2010-02-10 16:53:37 -05:00
# endif
2009-09-30 18:30:57 -04:00
ui . statusStringLabel - > setText ( status_string ) ; // displays info for 5 secs.
QTimer : : singleShot ( 5000 , this , SLOT ( resetStatusBar ( ) ) ) ;
}
2009-10-04 18:27:42 -04:00
void PeersDialog : : updatePeersCustomStateString ( const QString & peer_id )
{
# ifdef JUST_AN_EXAMPLE
// This is an example of how to retrieve the custom string.
//
std : : cerr < < " PeersDialog: Got notified that state string changed for peer " < < peer_id . toStdString ( ) < < std : : endl ;
std : : cerr < < " New state string for this peer is : " < < rsMsgs - > getCustomStateString ( peer_id . toStdString ( ) ) < < std : : endl ;
QMessageBox : : information ( NULL , " Notification " , peer_id + " has new custom string: " + QString : : fromStdString ( rsMsgs - > getCustomStateString ( peer_id . toStdString ( ) ) ) ) ;
# endif
}
2009-09-30 16:53:18 -04:00
void PeersDialog : : updatePeersAvatar ( const QString & peer_id )
{
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2009-09-30 16:53:18 -04:00
std : : cerr < < " PeersDialog: Got notified of new avatar for peer " < < peer_id . toStdString ( ) < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2009-09-30 16:53:18 -04:00
2010-06-17 13:39:32 -04:00
PopupChatDialog * pcd = PopupChatDialog : : getPrivateChat ( peer_id . toStdString ( ) , rsPeers - > getPeerName ( peer_id . toStdString ( ) ) , 0 ) ;
2009-09-30 16:53:18 -04:00
pcd - > updatePeerAvatar ( peer_id . toStdString ( ) ) ;
}
2009-09-29 16:37:20 -04:00
void PeersDialog : : updatePeerStatusString ( const QString & peer_id , const QString & status_string , bool is_private_chat )
2009-05-05 15:15:32 -04:00
{
2009-09-29 16:37:20 -04:00
if ( is_private_chat )
{
2010-06-17 13:39:32 -04:00
PopupChatDialog * pcd = PopupChatDialog : : getPrivateChat ( peer_id . toStdString ( ) , rsPeers - > getPeerName ( peer_id . toStdString ( ) ) , 0 ) ;
2009-09-29 16:37:20 -04:00
pcd - > updateStatusString ( status_string ) ;
}
else
{
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2009-09-29 16:37:20 -04:00
std : : cerr < < " Updating public chat msg from peer " < < rsPeers - > getPeerName ( peer_id . toStdString ( ) ) < < " : " < < status_string . toStdString ( ) < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2009-09-30 18:30:57 -04:00
updateStatusString ( status_string ) ;
2009-09-29 16:37:20 -04:00
}
2009-05-05 15:15:32 -04:00
}
2007-11-14 22:18:48 -05:00
2008-07-10 06:34:49 -04:00
void PeersDialog : : insertChat ( )
{
if ( ! rsMsgs - > chatAvailable ( ) )
{
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2009-06-08 13:09:00 -04:00
std : : cerr < < " no chat available. " < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2008-07-10 06:34:49 -04:00
return ;
}
std : : list < ChatInfo > newchat ;
if ( ! rsMsgs - > getNewChat ( newchat ) )
{
2010-02-08 11:42:26 -05:00
# ifdef PEERS_DEBUG
2009-05-05 15:15:32 -04:00
std : : cerr < < " could not get new chat. " < < std : : endl ;
2010-02-08 11:42:26 -05:00
# endif
2008-07-10 06:34:49 -04:00
return ;
}
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
std : : cerr < < " got new chat. " < < std : : endl ;
# endif
QTextEdit * msgWidget = ui . msgText ;
2008-07-10 06:34:49 -04:00
std : : list < ChatInfo > : : iterator it ;
2010-05-20 17:53:27 -04:00
uint chatflags = Settings - > getChatFlags ( ) ;
2008-07-10 06:34:49 -04:00
/* add in lines at the bottom */
for ( it = newchat . begin ( ) ; it ! = newchat . end ( ) ; it + + )
{
2010-02-07 07:36:37 -05:00
std : : string msg ( it - > msg . begin ( ) , it - > msg . end ( ) ) ;
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2008-07-10 14:52:56 -04:00
std : : cerr < < " PeersDialog::insertChat(): " < < msg < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2008-07-10 06:34:49 -04:00
/* are they private? */
if ( it - > chatflags & RS_CHAT_PRIVATE )
{
2010-06-17 13:39:32 -04:00
PopupChatDialog * pcd = PopupChatDialog : : getPrivateChat ( it - > rsid , it - > name , chatflags ) ;
2008-07-10 06:34:49 -04:00
pcd - > addChatMsg ( & ( * it ) ) ;
2010-05-05 07:47:29 -04:00
playsound ( ) ;
2009-07-13 15:58:11 -04:00
QApplication : : alert ( pcd ) ;
2008-07-10 06:34:49 -04:00
continue ;
}
std : : ostringstream out ;
QString extraTxt ;
2010-02-07 07:36:37 -05:00
QString timestamp = QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss " ) ;
QString name = QString : : fromStdString ( it - > name ) ;
QString line = " <span style= \" color:#C00000 \" > " + timestamp + " </span> " +
" <span style= \" color:#2D84C9 \" ><strong> " + " " + name + " </strong></span> " ;
2010-05-11 20:17:10 -04:00
QString msgContents = QString : : fromStdWString ( it - > msg ) ;
2010-02-07 07:36:37 -05:00
//std::cerr << "PeersDialog::insertChat(): 1.11\n";
2010-05-11 20:17:10 -04:00
historyKeeper . addMessage ( name , " THIS " , msgContents ) ;
2010-02-07 07:36:37 -05:00
//std::cerr << "PeersDialog::insertChat(): 1.12\n";
extraTxt + = line ;
// notify with a systray icon msg
if ( it - > rsid ! = rsPeers - > getOwnId ( ) )
{
// This is a trick to translate HTML into text.
QTextEdit editor ;
editor . setHtml ( QString : : fromStdWString ( it - > msg ) ) ;
QString notifyMsg ( QString : : fromStdString ( it - > name ) + " : " + editor . toPlainText ( ) ) ;
if ( notifyMsg . length ( ) > 30 )
emit notifyGroupChat ( QString ( " New group chat " ) , notifyMsg . left ( 30 ) + QString ( " ... " ) ) ;
else
emit notifyGroupChat ( QString ( " New group chat " ) , notifyMsg ) ;
}
2008-07-10 06:34:49 -04:00
2010-05-11 20:17:10 -04:00
// create a DOM tree object from the message and embed contents with HTML tags
QDomDocument doc ;
doc . setContent ( msgContents ) ;
2010-02-07 07:36:37 -05:00
2010-05-11 20:17:10 -04:00
// embed links
QDomElement body = doc . documentElement ( ) ;
RsChat : : embedHtml ( doc , body , defEmbedAhref ) ;
2010-02-07 07:36:37 -05:00
2010-05-11 20:17:10 -04:00
// embed smileys
2010-05-20 17:53:27 -04:00
Settings - > beginGroup ( " Chat " ) ;
if ( Settings - > value ( QString : : fromUtf8 ( " Emoteicons_GroupChat " ) , true ) . toBool ( ) )
2010-05-11 20:17:10 -04:00
RsChat : : embedHtml ( doc , body , defEmbedImg ) ;
2010-05-20 17:53:27 -04:00
Settings - > endGroup ( ) ;
2010-05-11 20:17:10 -04:00
msgContents = doc . toString ( - 1 ) ; // -1 removes any annoying carriage return misinterpreted by QTextEdit
extraTxt + = msgContents ;
2010-05-03 17:17:36 -04:00
2010-02-07 07:36:37 -05:00
if ( ( msgWidget - > verticalScrollBar ( ) - > maximum ( ) - 30 ) < msgWidget - > verticalScrollBar ( ) - > value ( ) ) {
msgWidget - > append ( extraTxt ) ;
} else {
//the vertical scroll is not at the bottom, so just update the text, the scroll will stay at the current position
int scroll = msgWidget - > verticalScrollBar ( ) - > value ( ) ;
msgWidget - > setHtml ( msgWidget - > toHtml ( ) + extraTxt ) ;
msgWidget - > verticalScrollBar ( ) - > setValue ( scroll ) ;
msgWidget - > update ( ) ;
}
}
2008-07-10 06:34:49 -04:00
}
void PeersDialog : : checkChat ( )
{
/* if <return> at the end of the text -> we can send it! */
QTextEdit * chatWidget = ui . lineEdit ;
std : : string txt = chatWidget - > toPlainText ( ) . toStdString ( ) ;
if ( ' \n ' = = txt [ txt . length ( ) - 1 ] )
{
//std::cerr << "Found <return> found at end of :" << txt << ": should send!";
//std::cerr << std::endl;
if ( txt . length ( ) - 1 = = txt . find ( ' \n ' ) ) /* only if on first line! */
{
/* should remove last char ... */
sendMsg ( ) ;
}
}
else
{
2009-09-30 18:30:57 -04:00
updateStatusTyping ( ) ;
2008-07-10 06:34:49 -04:00
//std::cerr << "No <return> found in :" << txt << ":";
//std::cerr << std::endl;
}
}
void PeersDialog : : sendMsg ( )
{
QTextEdit * lineWidget = ui . lineEdit ;
ChatInfo ci ;
//ci.msg = lineWidget->Text().toStdWString();
ci . msg = lineWidget - > toHtml ( ) . toStdWString ( ) ;
ci . chatflags = RS_CHAT_PUBLIC ;
2009-03-12 10:14:55 -04:00
//historyKeeper.addMessage("THIS", "ALL", lineWidget->toHtml() );
2009-07-13 15:58:11 -04:00
2008-07-10 06:34:49 -04:00
std : : string msg ( ci . msg . begin ( ) , ci . msg . end ( ) ) ;
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2008-07-10 14:52:56 -04:00
std : : cerr < < " PeersDialog::sendMsg(): " < < msg < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2008-07-10 06:34:49 -04:00
rsMsgs - > ChatSend ( ci ) ;
ui . lineEdit - > clear ( ) ;
setFont ( ) ;
/* redraw send list */
insertSendList ( ) ;
}
void PeersDialog : : insertSendList ( )
{
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 */
void PeersDialog : : toggleSendItem ( QTreeWidgetItem * item , int col )
{
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2008-07-10 06:34:49 -04:00
std : : cerr < < " ToggleSendItem() " < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2008-07-10 06:34:49 -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 ;
}
2009-03-12 13:57:30 -04:00
//============================================================================
2008-07-10 06:34:49 -04:00
void PeersDialog : : setColor ( )
{
2009-07-13 15:58:11 -04:00
2008-07-10 06:34:49 -04:00
bool ok ;
QRgb color = QColorDialog : : getRgba ( ui . lineEdit - > textColor ( ) . rgba ( ) , & ok , this ) ;
if ( ok ) {
_currentColor = QColor ( color ) ;
2009-01-22 20:58:56 -05:00
QPixmap pxm ( 16 , 16 ) ;
2008-07-10 06:34:49 -04:00
pxm . fill ( _currentColor ) ;
ui . colorChatButton - > setIcon ( pxm ) ;
}
setFont ( ) ;
}
void PeersDialog : : getFont ( )
{
bool ok ;
mCurrentFont = QFontDialog : : getFont ( & ok , mCurrentFont , this ) ;
setFont ( ) ;
}
void PeersDialog : : setFont ( )
{
mCurrentFont . setBold ( ui . textboldChatButton - > isChecked ( ) ) ;
mCurrentFont . setUnderline ( ui . textunderlineChatButton - > isChecked ( ) ) ;
mCurrentFont . setItalic ( ui . textitalicChatButton - > isChecked ( ) ) ;
ui . lineEdit - > setFont ( mCurrentFont ) ;
ui . lineEdit - > setTextColor ( _currentColor ) ;
2010-05-20 17:53:27 -04:00
Settings - > beginGroup ( " Chat " ) ;
Settings - > setValue ( QString : : fromUtf8 ( " ChatScreenFont " ) , mCurrentFont . toString ( ) ) ;
Settings - > endGroup ( ) ;
2010-05-14 12:54:30 -04:00
2008-07-10 06:34:49 -04:00
2008-11-24 09:07:26 -05:00
ui . lineEdit - > setFocus ( ) ;
2009-07-13 15:58:11 -04:00
2008-07-10 06:34:49 -04:00
}
2009-07-13 15:58:11 -04:00
void PeersDialog : : underline ( )
2008-11-24 09:07:26 -05:00
{
_underline = ! _underline ;
ui . lineEdit - > setFontUnderline ( _underline ) ;
2008-07-10 06:34:49 -04:00
}
2009-07-13 15:58:11 -04:00
2008-07-10 06:34:49 -04:00
2008-11-24 09:07:26 -05:00
// Update Chat Info information
2009-07-13 15:58:11 -04:00
void PeersDialog : : 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> " ) ) ;
}
2009-07-13 15:58:11 -04:00
void PeersDialog : : on_actionClearChat_triggered ( )
2008-11-24 09:07:26 -05:00
{
ui . msgText - > clear ( ) ;
}
2009-07-13 15:58:11 -04:00
void PeersDialog : : displayInfoChatMenu ( const QPoint & pos )
2008-11-24 09:07:26 -05:00
{
// Log Menu
QMenu myChatMenu ( this ) ;
myChatMenu . addAction ( ui . actionClearChat ) ;
// XXX: Why mapToGlobal() is not enough?
myChatMenu . exec ( mapToGlobal ( pos ) + QPoint ( 0 , 80 ) ) ;
2008-07-10 06:34:49 -04:00
}
void PeersDialog : : loadEmoticonsgroupchat ( )
{
2009-01-05 21:47:42 -05:00
QString sm_codes ;
2009-03-12 10:14:55 -04:00
# if defined(Q_OS_WIN32)
QFile sm_file ( QApplication : : applicationDirPath ( ) + " /emoticons/emotes.acs " ) ;
# else
QFile sm_file ( QString ( " :/smileys/emotes.acs " ) ) ;
2009-01-25 13:25:36 -05:00
# endif
2009-01-25 09:09:05 -05:00
if ( ! sm_file . open ( QIODevice : : ReadOnly ) )
{
2010-05-11 20:17:10 -04:00
std : : cerr < < " Could not open resouce file :/emoticons/emotes.acs " < < std : : endl ;
2009-01-25 09:09:05 -05:00
return ;
}
2009-01-05 21:47:42 -05:00
sm_codes = sm_file . readAll ( ) ;
sm_file . close ( ) ;
sm_codes . remove ( " \n " ) ;
sm_codes . remove ( " \r " ) ;
int i = 0 ;
QString smcode ;
QString smfile ;
while ( sm_codes [ i ] ! = ' { ' )
2008-07-10 06:34:49 -04:00
{
2009-01-05 21:47:42 -05:00
i + + ;
2009-07-13 15:58:11 -04:00
2009-01-05 21:47:42 -05:00
}
while ( i < sm_codes . length ( ) - 2 )
{
smcode = " " ;
smfile = " " ;
while ( sm_codes [ i ] ! = ' \" ' )
{
i + + ;
}
i + + ;
while ( sm_codes [ i ] ! = ' \" ' )
{
smcode + = sm_codes [ i ] ;
i + + ;
2009-07-13 15:58:11 -04:00
2009-01-05 21:47:42 -05:00
}
i + + ;
2009-07-13 15:58:11 -04:00
2009-01-05 21:47:42 -05:00
while ( sm_codes [ i ] ! = ' \" ' )
{
i + + ;
}
i + + ;
while ( sm_codes [ i ] ! = ' \" ' & & sm_codes [ i + 1 ] ! = ' ; ' )
2008-07-10 06:34:49 -04:00
{
2009-01-05 21:47:42 -05:00
smfile + = sm_codes [ i ] ;
i + + ;
2008-07-10 06:34:49 -04:00
}
2009-01-05 21:47:42 -05:00
i + + ;
if ( ! smcode . isEmpty ( ) & & ! smfile . isEmpty ( ) )
2009-01-25 14:02:52 -05:00
# if defined(Q_OS_WIN32)
2009-01-25 13:25:36 -05:00
smileys . insert ( smcode , smfile ) ;
2009-01-25 14:02:52 -05:00
# else
smileys . insert ( smcode , " :/ " + smfile ) ;
2009-01-25 13:25:36 -05:00
# endif
2008-07-10 06:34:49 -04:00
}
2010-05-11 20:17:10 -04:00
// init <img> embedder
defEmbedImg . InitFromAwkwardHash ( smileys ) ;
2008-11-24 09:07:26 -05:00
}
2008-07-10 06:34:49 -04:00
void PeersDialog : : smileyWidgetgroupchat ( )
2009-07-13 15:58:11 -04:00
{
2008-07-10 06:34:49 -04:00
qDebug ( " MainWindow::smileyWidget() " ) ;
2010-05-12 15:03:30 -04:00
if ( smWidget = = 0 ) {
smWidget = new QWidget ( this , Qt : : Popup ) ;
smWidget - > setWindowTitle ( " Emoticons " ) ;
smWidget - > setWindowIcon ( QIcon ( QString ( " :/images/rstray3.png " ) ) ) ;
//smWidget->setFixedSize(256,256);
smWidget - > setBaseSize ( 4 * 24 , ( smileys . size ( ) / 4 ) * 24 ) ;
//Warning: this part of code was taken from kadu instant messenger;
// It was EmoticonSelector::alignTo(QWidget* w) function there
// comments are Polish, I dont' know how does it work...
// oblicz pozycj<63> widgetu do kt<6B> rego r<> wnamy
QWidget * w = ui . emoticonBtn ;
QPoint w_pos = w - > mapToGlobal ( QPoint ( 0 , 0 ) ) ;
// oblicz rozmiar selektora
QSize e_size = smWidget - > sizeHint ( ) ;
// oblicz rozmiar pulpitu
QSize s_size = QApplication : : desktop ( ) - > size ( ) ;
// oblicz dystanse od widgetu do lewego brzegu i do prawego
int l_dist = w_pos . x ( ) ;
int r_dist = s_size . width ( ) - ( w_pos . x ( ) + w - > width ( ) ) ;
// oblicz pozycj<63> w zale<6C> no<6E> ci od tego czy po lewej stronie
// jest wi<77> cej miejsca czy po prawej
int x ;
if ( l_dist > = r_dist )
x = w_pos . x ( ) - e_size . width ( ) ;
else
x = w_pos . x ( ) + w - > width ( ) ;
// oblicz pozycj<63> y - centrujemy w pionie
int y = w_pos . y ( ) + w - > height ( ) / 2 - e_size . height ( ) / 2 ;
// je<6A> li wychodzi poza doln<6C> kraw<61> d<EFBFBD> to r<> wnamy do niej
if ( y + e_size . height ( ) > s_size . height ( ) )
y = s_size . height ( ) - e_size . height ( ) ;
// je<6A> li wychodzi poza g<> rn<72> kraw<61> d<EFBFBD> to r<> wnamy do niej
if ( y < 0 )
y = 0 ;
// ustawiamy selektor na wyliczonej pozycji
smWidget - > move ( x , y ) ;
x = 0 ;
y = 0 ;
QHashIterator < QString , QString > i ( smileys ) ;
while ( i . hasNext ( ) )
2008-07-10 06:34:49 -04:00
{
2010-05-12 15:03:30 -04:00
i . next ( ) ;
QPushButton * smButton = new QPushButton ( " " , smWidget ) ;
smButton - > setGeometry ( x * 24 , y * 24 , 24 , 24 ) ;
smButton - > setIconSize ( QSize ( 24 , 24 ) ) ;
smButton - > setIcon ( QPixmap ( i . value ( ) ) ) ;
smButton - > setToolTip ( i . key ( ) ) ;
//smButton->setFixedSize(24,24);
+ + x ;
if ( x > 4 )
{
x = 0 ;
y + + ;
}
connect ( smButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addSmileys ( ) ) ) ;
connect ( smButton , SIGNAL ( clicked ( ) ) , smWidget , SLOT ( close ( ) ) ) ;
2008-07-10 06:34:49 -04:00
}
}
2009-07-13 15:58:11 -04:00
2008-07-10 06:34:49 -04:00
smWidget - > show ( ) ;
2008-11-24 09:07:26 -05:00
}
2008-07-10 06:34:49 -04:00
void PeersDialog : : addSmileys ( )
{
2009-01-05 21:47:42 -05:00
ui . lineEdit - > setText ( ui . lineEdit - > toHtml ( ) + qobject_cast < QPushButton * > ( sender ( ) ) - > toolTip ( ) . split ( " | " ) . first ( ) ) ;
2008-07-10 06:34:49 -04:00
}
2007-11-14 22:18:48 -05:00
2009-01-22 20:58:56 -05:00
/* GUI stuff -> don't do anything directly with Control */
void PeersDialog : : viewprofile ( )
{
/* display Dialog */
QTreeWidgetItem * c = getCurrentPeer ( ) ;
static ProfileView * profileview = new ProfileView ( ) ;
if ( ! c )
return ;
/* set the Id */
std : : string id = getPeerRsCertId ( c ) ;
profileview - > setPeerId ( id ) ;
profileview - > show ( ) ;
}
2009-09-02 18:42:31 -04:00
void PeersDialog : : updateAvatar ( )
{
unsigned char * data = NULL ;
int size = 0 ;
rsMsgs - > getOwnAvatarData ( data , size ) ;
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2009-09-02 18:42:31 -04:00
std : : cerr < < " Image size = " < < size < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2009-09-02 18:42:31 -04:00
if ( size = = 0 )
std : : cerr < < " Got no image " < < std : : endl ;
// set the image
QPixmap pix ;
2009-09-07 09:59:38 -04:00
pix . loadFromData ( data , size , " PNG " ) ;
ui . avatartoolButton - > setIcon ( pix ) ; // writes image into ba in PNG format
2009-09-02 18:42:31 -04:00
2010-06-17 13:39:32 -04:00
PopupChatDialog : : updateAllAvatars ( ) ;
2009-09-30 18:30:57 -04:00
2009-09-02 18:42:31 -04:00
delete [ ] data ;
}
void PeersDialog : : getAvatar ( )
{
2010-02-22 07:53:24 -05:00
QString fileName = QFileDialog : : getOpenFileName ( this , " Load File " , QDir : : homePath ( ) , " Pictures (*.png *.xpm *.jpg *.tiff *.gif) " ) ;
2009-09-02 18:42:31 -04:00
if ( ! fileName . isEmpty ( ) )
{
2010-05-14 07:17:19 -04:00
QPixmap picture ;
2010-02-23 09:11:47 -05:00
picture = QPixmap ( fileName ) . scaled ( 82 , 82 , Qt : : IgnoreAspectRatio , Qt : : SmoothTransformation ) ;
2009-09-02 18:42:31 -04:00
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2009-09-02 18:42:31 -04:00
std : : cerr < < " Sending avatar image down the pipe " < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2009-09-02 18:42:31 -04:00
// send avatar down the pipe for other peers to get it.
QByteArray ba ;
QBuffer buffer ( & ba ) ;
buffer . open ( QIODevice : : WriteOnly ) ;
2009-09-07 09:59:38 -04:00
picture . save ( & buffer , " PNG " ) ; // writes image into ba in PNG format
2009-09-02 18:42:31 -04:00
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
2009-09-02 18:42:31 -04:00
std : : cerr < < " Image size = " < < ba . size ( ) < < std : : endl ;
2010-02-07 18:01:46 -05:00
# endif
2009-09-02 18:42:31 -04:00
rsMsgs - > setOwnAvatarData ( ( unsigned char * ) ( ba . data ( ) ) , ba . size ( ) ) ; // last char 0 included.
2009-09-30 18:30:57 -04:00
// I suppressed this because it gets called already by rsMsgs->setOwnAvatarData() through a Qt notification signal
//updateAvatar() ;
2009-09-02 18:42:31 -04:00
}
}
void PeersDialog : : changeAvatarClicked ( )
{
updateAvatar ( ) ;
2009-09-22 18:47:49 -04:00
}
void PeersDialog : : on_actionAdd_Friend_activated ( )
{
2010-05-02 20:09:55 -04:00
ConnectFriendWizard connectwiz ( this ) ;
2009-09-22 18:47:49 -04:00
2010-05-02 20:09:55 -04:00
connectwiz . exec ( ) ;
2009-09-22 18:47:49 -04:00
}
2010-01-16 20:36:50 -05:00
void PeersDialog : : on_actionCreate_New_Forum_activated ( )
{
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
}
void PeersDialog : : on_actionCreate_New_Channel_activated ( )
{
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 . setWindowTitle ( tr ( " Create a new Channel " ) ) ;
cf . ui . labelicon - > setPixmap ( QPixmap ( " :/images/add_channel64.png " ) ) ;
2010-01-16 20:36:50 -05:00
QString titleStr ( " <span style= \" font-size:24pt; font-weight:500; "
" color:#32CD32; \" >%1</span> " ) ;
2010-05-02 20:09:55 -04:00
cf . ui . textlabelcreatforums - > setText ( titleStr . arg ( tr ( " New Channel " ) ) ) ;
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 */
void PeersDialog : : loadmypersonalstatus ( )
{
2010-07-20 15:45:07 -04:00
ui . mypersonalstatuslabel - > setText ( QString : : fromStdString ( rsMsgs - > getCustomStateString ( ) ) ) ;
2009-09-29 18:52:46 -04:00
}
2009-10-08 15:08:44 -04:00
void PeersDialog : : statusmessage ( )
{
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
void PeersDialog : : addExtraFile ( )
{
// select a file
QString qfile = QFileDialog : : getOpenFileName ( this , tr ( " Add Extra File " ) , " " , " " , 0 ,
QFileDialog : : DontResolveSymlinks ) ;
std : : string filePath = qfile . toStdString ( ) ;
if ( filePath ! = " " )
{
PeersDialog : : addAttachment ( filePath ) ;
}
}
void PeersDialog : : addAttachment ( std : : string filePath ) {
/* add a AttachFileItem to the attachment section */
2010-02-07 18:01:46 -05:00
std : : cerr < < " PopupChatDialog::addExtraFile() hashing file. " < < std : : endl ;
2010-01-31 17:29:30 -05:00
/* add widget in for new destination */
AttachFileItem * file = new AttachFileItem ( filePath ) ;
//file->
ui . verticalLayout - > addWidget ( file , 1 , 0 ) ;
//when the file is local or is finished hashing, call the fileHashingFinished method to send a chat message
if ( file - > getState ( ) = = AFI_STATE_LOCAL ) {
fileHashingFinished ( file ) ;
} else {
QObject : : connect ( file , SIGNAL ( fileFinished ( AttachFileItem * ) ) , SLOT ( fileHashingFinished ( AttachFileItem * ) ) ) ;
}
}
void PeersDialog : : fileHashingFinished ( AttachFileItem * file ) {
2010-02-07 18:01:46 -05:00
std : : cerr < < " PeersDialog::fileHashingFinished() started. " < < std : : endl ;
2010-01-31 17:29:30 -05:00
//check that the file is ok tos end
if ( file - > getState ( ) = = AFI_STATE_ERROR ) {
2010-02-07 18:01:46 -05:00
# ifdef PEERS_DEBUG
std : : cerr < < " PopupChatDialog::fileHashingFinished error file is not hashed. " < < std : : endl ;
# endif
2010-01-31 17:29:30 -05:00
return ;
}
ChatInfo ci ;
{
rsiface - > lockData ( ) ; /* Lock Interface */
const RsConfig & conf = rsiface - > getConfig ( ) ;
ci . rsid = conf . ownId ;
ci . name = conf . ownName ;
rsiface - > unlockData ( ) ; /* Unlock Interface */
}
2010-02-07 18:01:46 -05:00
//convert fileSize from uint_64 to string for html link
2010-05-11 20:17:10 -04:00
// char fileSizeChar [100];
// sprintf(fileSizeChar, "%lld", file->FileSize());
// std::string fileSize = *(&fileSizeChar);
2010-01-31 17:29:30 -05:00
2010-03-17 11:34:36 -04:00
std : : string mesgString = RetroShareLink ( QString : : fromStdString ( file - > FileName ( ) ) ,
2010-05-11 20:17:10 -04:00
file - > FileSize ( ) ,
QString : : fromStdString ( file - > FileHash ( ) ) ) . toHtml ( ) . toStdString ( ) ;
2010-03-17 11:34:36 -04:00
// std::string mesgString = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>"
// + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>";
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog::fileHashingFinished mesgString : " < < mesgString < < std : : endl ;
# endif
2010-01-31 17:29:30 -05:00
const char * messageString = mesgString . c_str ( ) ;
//convert char massageString to w_char
wchar_t * message ;
2010-05-11 20:17:10 -04:00
size_t requiredSize = mbstowcs ( NULL , messageString , 0 ) ; // C4996
2010-01-31 17:29:30 -05:00
/* Add one to leave room for the NULL terminator */
message = ( wchar_t * ) malloc ( ( requiredSize + 1 ) * sizeof ( wchar_t ) ) ;
if ( ! message ) {
std : : cerr < < ( " Memory allocation failure. \n " ) ;
}
2010-05-11 20:17:10 -04:00
size_t size = mbstowcs ( message , messageString , requiredSize + 1 ) ; // C4996
2010-01-31 17:29:30 -05:00
if ( size = = ( size_t ) ( - 1 ) ) {
printf ( " Couldn't convert string--invalid multibyte character. \n " ) ;
}
ci . msg = message ;
ci . chatflags = RS_CHAT_PUBLIC ;
rsMsgs - > ChatSend ( ci ) ;
setFont ( ) ;
}
void PeersDialog : : anchorClicked ( const QUrl & link )
{
2010-07-15 07:25:34 -04:00
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog::anchorClicked link.scheme() : " < < link . scheme ( ) . toStdString ( ) < < std : : endl ;
# endif
2010-01-31 17:29:30 -05:00
2010-07-15 07:25:34 -04:00
RetroShareLink : : processUrl ( link , NULL , RSLINK_PROCESS_NOTIFY_ALL ) ;
2010-01-31 17:29:30 -05:00
}
void PeersDialog : : dropEvent ( QDropEvent * event )
{
if ( ! ( Qt : : CopyAction & event - > possibleActions ( ) ) )
{
2010-02-07 18:01:46 -05:00
std : : cerr < < " PeersDialog::dropEvent() Rejecting uncopyable DropAction " < < std : : endl ;
2010-01-31 17:29:30 -05:00
/* can't do it */
return ;
}
2010-02-07 18:01:46 -05:00
std : : cerr < < " PeersDialog::dropEvent() Formats " < < std : : endl ;
2010-01-31 17:29:30 -05:00
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; it + + )
{
2010-02-07 18:01:46 -05:00
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) < < std : : endl ;
2010-01-31 17:29:30 -05:00
}
if ( event - > mimeData ( ) - > hasUrls ( ) )
{
2010-02-07 18:01:46 -05:00
std : : cerr < < " PeersDialog::dropEvent() Urls: " < < std : : endl ;
2010-01-31 17:29:30 -05:00
QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
QList < QUrl > : : iterator uit ;
for ( uit = urls . begin ( ) ; uit ! = urls . end ( ) ; uit + + )
{
std : : string localpath = uit - > toLocalFile ( ) . toStdString ( ) ;
2010-02-07 18:01:46 -05:00
std : : cerr < < " Whole URL: " < < uit - > toString ( ) . toStdString ( ) < < std : : endl ;
std : : cerr < < " or As Local File: " < < localpath < < std : : endl ;
2010-01-31 17:29:30 -05:00
if ( localpath . size ( ) > 0 )
{
struct stat buf ;
//Check that the file does exist and is not a directory
if ( ( - 1 = = stat ( localpath . c_str ( ) , & buf ) ) ) {
std : : cerr < < " PeersDialog::dropEvent() file does not exists. " < < std : : endl ;
QMessageBox mb ( tr ( " Drop file error. " ) , tr ( " File not found or file name not accepted. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
mb . exec ( ) ;
} else if ( S_ISDIR ( buf . st_mode ) ) {
std : : cerr < < " PeersDialog::dropEvent() directory not accepted. " < < std : : endl ;
QMessageBox mb ( tr ( " Drop file error. " ) , tr ( " Directory can't be dropped, only files are accepted. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
mb . exec ( ) ;
} else {
PeersDialog : : addAttachment ( localpath ) ;
}
}
}
}
event - > setDropAction ( Qt : : CopyAction ) ;
event - > accept ( ) ;
}
void PeersDialog : : dragEnterEvent ( QDragEnterEvent * event )
{
/* print out mimeType */
2010-02-07 18:01:46 -05:00
std : : cerr < < " PeersDialog::dragEnterEvent() Formats " < < std : : endl ;
2010-01-31 17:29:30 -05:00
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; it + + )
{
2010-02-07 18:01:46 -05:00
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) < < std : : endl ;
2010-01-31 17:29:30 -05:00
}
if ( event - > mimeData ( ) - > hasUrls ( ) )
{
2010-02-07 18:01:46 -05:00
std : : cerr < < " PeersDialog::dragEnterEvent() Accepting Urls " < < std : : endl ;
2010-01-31 17:29:30 -05:00
event - > acceptProposedAction ( ) ;
}
else
{
2010-02-07 18:01:46 -05:00
std : : cerr < < " PeersDialog::dragEnterEvent() No Urls " < < std : : endl ;
2010-01-31 17:29:30 -05:00
}
}
2010-04-27 18:08:38 -04:00
bool PeersDialog : : fileSave ( )
{
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 ;
}
bool PeersDialog : : fileSaveAs ( )
{
QString fn = QFileDialog : : getSaveFileName ( this , tr ( " Save as... " ) ,
QString ( ) , tr ( " Text File (*.txt );;All Files (*) " ) ) ;
if ( fn . isEmpty ( ) )
return false ;
setCurrentFileName ( fn ) ;
return fileSave ( ) ;
}
void PeersDialog : : setCurrentFileName ( const QString & fileName )
{
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
////play sound when recv a message
void PeersDialog : : playsound ( ) {
2010-05-20 17:53:27 -04:00
Settings - > beginGroup ( " Sound " ) ;
Settings - > beginGroup ( " SoundFilePath " ) ;
QString OnlineSound = Settings - > value ( " NewChatMessage " , " " ) . toString ( ) ;
Settings - > endGroup ( ) ;
Settings - > beginGroup ( " Enable " ) ;
bool flag = Settings - > value ( " NewChatMessage " , false ) . toBool ( ) ;
Settings - > endGroup ( ) ;
Settings - > endGroup ( ) ;
2010-05-05 07:47:29 -04:00
if ( ! OnlineSound . isEmpty ( ) & & flag )
if ( QSound : : isAvailable ( ) )
2010-05-11 16:02:52 -04:00
QSound : : play ( OnlineSound ) ;
2010-05-05 07:47:29 -04:00
}
2010-06-18 17:59:33 -04:00
void PeersDialog : : displayMenu ( )
{
QMenu * displaymenu = new QMenu ( ) ;
displaymenu - > addAction ( ui . action_Hide_Offline_Friends ) ;
displaymenu - > addAction ( ui . action_Hide_Status_Column ) ;
ui . displayButton - > setMenu ( displaymenu ) ;
}
void PeersDialog : : statusColumn ( )
{
/* Set header resize modes and initial section sizes */
QHeaderView * peerheader = ui . peertreeWidget - > header ( ) ;
if ( ui . action_Hide_Status_Column - > isChecked ( ) )
{
ui . peertreeWidget - > setColumnHidden ( 1 , true ) ;
peerheader - > resizeSection ( 0 , 200 ) ;
}
else
{
ui . peertreeWidget - > setColumnHidden ( 1 , false ) ;
peerheader - > resizeSection ( 0 , 200 ) ;
}
}