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>
2010-09-17 17:54:25 -04:00
# include <QDir>
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 <QColorDialog>
# include <QFontDialog>
# include <QDropEvent>
2008-11-24 09:07:26 -05:00
# include "common/vmessagebox.h"
2010-09-12 10:10:28 -04:00
# include "common/StatusDefs.h"
2010-09-22 18:37:57 -04:00
# include "common/GroupDefs.h"
2010-09-14 13:47:11 -04:00
# include "common/Emoticons.h"
2010-01-18 17:44:09 -05:00
# include <gui/mainpagestack.h>
2008-11-24 09:07:26 -05:00
2010-09-04 10:23:30 -04:00
# include "retroshare/rsinit.h"
2008-11-24 09:07:26 -05:00
# 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"
2010-11-25 11:45:44 -05:00
# include "notifyqt.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"
2010-09-19 20:10:51 -04:00
# include "connect/ConnectFriendWizard.h"
# include "forums/CreateForum.h"
# include "channels/CreateChannel.h"
2010-09-21 12:11:19 -04:00
# include "groups/CreateGroup.h"
2010-09-19 20:10:51 -04:00
# include "feeds/AttachFileItem.h"
# include "im_history/ImHistoryBrowser.h"
# include "common/RSTreeWidgetItem.h"
2010-09-01 10:15:50 -04:00
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-12-02 19:54:40 -05:00
# include "util/misc.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 */
2010-09-23 18:34:40 -04:00
# define IMAGE_DENYFRIEND ": / images / denied16.png"
2007-11-14 22:18:48 -05:00
# define IMAGE_REMOVEFRIEND ": / images / removefriend16.png"
2010-09-23 14:49:52 -04:00
# define IMAGE_EXPORTFRIEND ": / images / exportpeers_16x16.png"
2010-09-29 15:30:59 -04:00
# define IMAGE_ADDFRIEND ": / images / user / add_user16.png"
2010-09-23 19:41:54 -04:00
# define IMAGE_FRIENDINFO ": / images / peerdetails_16x16.png"
2007-11-14 22:18:48 -05:00
# define IMAGE_CHAT ": / images / chat.png"
2010-09-23 19:41:54 -04:00
# define IMAGE_MSG ": / images / mail_new.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 */
2010-09-02 04:25:30 -04:00
# define IMAGE_AVAILABLE ": / images / user / identityavaiblecyan24.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"
2010-09-23 14:49:52 -04:00
# define IMAGE_GROUP16 ": / images / user / group16.png"
# define IMAGE_GROUP24 ": / images / user / group24.png"
2010-09-23 17:32:07 -04:00
# define IMAGE_EDIT ": / images / edit_16.png"
# define IMAGE_REMOVE ": / images / delete.png"
2010-09-23 18:46:36 -04:00
# define IMAGE_EXPAND ": / images / edit_add24.png"
# define IMAGE_COLLAPSE ": / images / edit_remove24.png"
2010-11-10 07:24:36 -05:00
# define IMAGE_NEWSFEED ""
# define IMAGE_NEWSFEED_NEW ": / images / message-state-new.png"
2008-11-24 09:07:26 -05:00
2010-12-17 20:45:32 -05:00
# define COLUMN_COUNT 2
2010-06-08 17:38:36 -04:00
# define COLUMN_NAME 0
2010-12-17 20:45:32 -05:00
# define COLUMN_STATE 1
2010-06-25 10:19:48 -04:00
# define COLUMN_DATA 0 // column for storing the userdata id
2010-12-17 20:45:32 -05:00
# define ROLE_SORT Qt::UserRole
# define ROLE_ID Qt::UserRole + 1
# define ROLE_STANDARD Qt::UserRole + 2
2010-09-22 18:37:57 -04:00
# define TYPE_GPG 0
# define TYPE_SSL 1
# define TYPE_GROUP 2
2010-06-08 17:38:36 -04:00
2008-07-09 05:53:47 -04:00
/******
* # define PEERS_DEBUG 1
* * * * */
2008-11-24 09:07:26 -05:00
/** Constructor */
PeersDialog : : PeersDialog ( 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
2010-09-04 10:23:30 -04:00
last_status_send_time = 0 ;
2010-09-22 18:37:57 -04:00
groupsHasChanged = false ;
2010-12-18 16:30:24 -05:00
correctColumnStatusSize = false ;
2010-01-18 17:44:09 -05:00
2010-09-19 20:10:51 -04:00
m_compareRole = new RSTreeWidgetItemCompareRole ;
2010-12-17 20:45:32 -05:00
m_compareRole - > setRole ( COLUMN_NAME , ROLE_SORT ) ;
m_compareRole - > setRole ( COLUMN_STATE , ROLE_SORT ) ;
2010-09-19 20:10:51 -04:00
2010-09-04 10:23:30 -04:00
connect ( ui . peertreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( peertreeWidgetCostumPopupMenu ( QPoint ) ) ) ;
connect ( ui . peertreeWidget , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( chatfriend ( QTreeWidgetItem * ) ) ) ;
2010-12-17 20:45:32 -05:00
connect ( ui . peertreeWidget - > header ( ) , SIGNAL ( sortIndicatorChanged ( int , Qt : : SortOrder ) ) , this , SLOT ( peerSortIndicatorChanged ( int , Qt : : SortOrder ) ) ) ;
2010-11-25 11:45:44 -05:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerStatusChanged ( QString , int ) ) , this , SLOT ( updateOwnStatus ( QString , int ) ) ) ;
2007-11-14 22:18:48 -05:00
2010-09-04 10:23:30 -04:00
connect ( ui . avatartoolButton , SIGNAL ( clicked ( ) ) , SLOT ( getAvatar ( ) ) ) ;
connect ( ui . mypersonalstatuslabel , SIGNAL ( clicked ( ) ) , SLOT ( statusmessage ( ) ) ) ;
connect ( ui . actionSet_your_Avatar , SIGNAL ( triggered ( ) ) , this , SLOT ( getAvatar ( ) ) ) ;
connect ( ui . actionSet_your_Personal_Message , SIGNAL ( triggered ( ) ) , this , SLOT ( statusmessage ( ) ) ) ;
connect ( ui . addfileButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
2010-01-16 20:36:50 -05:00
2010-09-29 15:30:59 -04:00
connect ( ui . actionAdd_Friend , SIGNAL ( triggered ( ) ) , this , SLOT ( addFriend ( ) ) ) ;
2010-09-04 10:23:30 -04:00
connect ( ui . action_Hide_Offline_Friends , SIGNAL ( triggered ( ) ) , this , SLOT ( insertPeers ( ) ) ) ;
2010-12-17 20:45:32 -05:00
connect ( ui . action_Hide_Status_Column , SIGNAL ( triggered ( ) ) , this , SLOT ( setStateColumn ( ) ) ) ;
connect ( ui . action_Sort_by_State , SIGNAL ( triggered ( ) ) , this , SLOT ( setStateColumn ( ) ) ) ;
2010-12-15 16:32:44 -05:00
connect ( ui . actionSort_Peers_Ascending_Order , SIGNAL ( triggered ( ) ) , this , SLOT ( sortPeersAscendingOrder ( ) ) ) ;
connect ( ui . actionSort_Peers_Descending_Order , SIGNAL ( triggered ( ) ) , this , SLOT ( sortPeersDescendingOrder ( ) ) ) ;
2010-01-19 16:43:40 -05:00
2010-09-04 10:23:30 -04:00
ui . peertabWidget - > setTabPosition ( QTabWidget : : North ) ;
2010-11-10 07:24:36 -05:00
ui . peertabWidget - > addTab ( new ProfileWidget ( ) , tr ( " Profile " ) ) ;
NewsFeed * newsFeed = new NewsFeed ( ) ;
newsFeedTabIndex = ui . peertabWidget - > addTab ( newsFeed , tr ( " Friends Storm " ) ) ;
ui . peertabWidget - > tabBar ( ) - > setIconSize ( QSize ( 10 , 10 ) ) ;
/* get the current text and text color of the tab bar */
newsFeedTabColor = ui . peertabWidget - > tabBar ( ) - > tabTextColor ( newsFeedTabIndex ) ;
newsFeedText = ui . peertabWidget - > tabBar ( ) - > tabText ( newsFeedTabIndex ) ;
connect ( newsFeed , SIGNAL ( newsFeedChanged ( int ) ) , this , SLOT ( newsFeedChanged ( int ) ) ) ;
2009-09-25 21:10:25 -04:00
2010-12-15 16:32:44 -05:00
ui . peertreeWidget - > setColumnCount ( COLUMN_COUNT ) ;
ui . peertreeWidget - > sortItems ( COLUMN_NAME , Qt : : AscendingOrder ) ;
2009-07-13 15:58:11 -04:00
2010-09-04 10:23:30 -04:00
// set header text aligment
QTreeWidgetItem * headerItem = ui . peertreeWidget - > headerItem ( ) ;
headerItem - > setTextAlignment ( COLUMN_NAME , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
2010-12-17 20:45:32 -05:00
headerItem - > setTextAlignment ( COLUMN_STATE , Qt : : AlignLeft | Qt : : AlignVCenter ) ;
wasStatusColumnHidden = ui . peertreeWidget - > isColumnHidden ( COLUMN_STATE ) ;
2008-07-12 07:57:09 -04:00
2010-09-04 10:23:30 -04:00
connect ( ui . Sendbtn , SIGNAL ( clicked ( ) ) , this , SLOT ( sendMsg ( ) ) ) ;
connect ( ui . emoticonBtn , SIGNAL ( clicked ( ) ) , this , SLOT ( smileyWidgetgroupchat ( ) ) ) ;
2008-07-10 06:34:49 -04:00
2010-09-04 10:23:30 -04:00
connect ( ui . lineEdit , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
2010-03-17 11:34:36 -04:00
2010-09-04 10:23:30 -04:00
connect ( ui . textboldChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textunderlineChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textitalicChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . fontsButton , SIGNAL ( clicked ( ) ) , this , SLOT ( getFont ( ) ) ) ;
connect ( ui . colorChatButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setColor ( ) ) ) ;
connect ( ui . actionSave_History , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSaveAs ( ) ) ) ;
2009-07-13 15:58:11 -04:00
2010-09-04 10:23:30 -04:00
ui . fontsButton - > setIcon ( QIcon ( QString ( " :/images/fonts.png " ) ) ) ;
2009-07-13 15:58:11 -04:00
2010-10-07 20:07:44 -04:00
mCurrentColor = Qt : : black ;
2010-09-10 14:38:46 -04:00
mCurrentFont . fromString ( Settings - > getChatScreenFont ( ) ) ;
2010-10-07 20:07:44 -04:00
colorChanged ( mCurrentColor ) ;
fontChanged ( mCurrentFont ) ;
2010-09-04 10:23:30 -04:00
2010-09-07 11:49:31 -04:00
style . setStyleFromSettings ( ChatStyle : : TYPE_PUBLIC ) ;
2010-09-04 10:23:30 -04:00
setChatInfo ( tr ( " Welcome to RetroShare's group chat. " ) , QString : : fromUtf8 ( " blue " ) ) ;
if ( Settings - > valueFromGroup ( " Chat " , QString : : fromUtf8 ( " GroupChat_History " ) , true ) . toBool ( ) ) {
historyKeeper . init ( QString : : fromStdString ( RsInit : : RsProfileConfigDirectory ( ) ) + " /chatPublic.xml " ) ;
2010-11-06 20:22:46 -04:00
int messageCount = Settings - > getPublicChatHistoryCount ( ) ;
if ( messageCount > 0 ) {
QList < IMHistoryItem > historyItems ;
historyKeeper . getMessages ( historyItems , messageCount ) ;
foreach ( IMHistoryItem item , historyItems ) {
addChatMsg ( item . incoming , true , item . name , item . recvTime , item . messageText ) ;
}
2010-09-04 10:23:30 -04:00
}
}
QMenu * grpchatmenu = new QMenu ( ) ;
2011-02-08 16:59:17 -05:00
grpchatmenu - > addAction ( ui . actionClear_Chat_History ) ;
grpchatmenu - > addAction ( ui . actionDelete_Chat_History ) ;
2010-09-04 10:23:30 -04:00
grpchatmenu - > addAction ( ui . actionSave_History ) ;
grpchatmenu - > addAction ( ui . actionMessageHistory ) ;
ui . menuButton - > setMenu ( grpchatmenu ) ;
QMenu * menu = new QMenu ( ) ;
menu - > addAction ( ui . actionAdd_Friend ) ;
2010-09-21 12:11:19 -04:00
menu - > addAction ( ui . actionAdd_Group ) ;
2010-09-04 10:23:30 -04:00
menu - > addSeparator ( ) ;
menu - > addAction ( ui . actionCreate_New_Forum ) ;
# ifndef RS_RELEASE_VERSION
menu - > addAction ( ui . actionCreate_New_Channel ) ;
# endif
menu - > addAction ( ui . actionSet_your_Avatar ) ;
menu - > addAction ( ui . actionSet_your_Personal_Message ) ;
2009-07-13 15:58:11 -04:00
2010-09-04 10:23:30 -04:00
ui . menupushButton - > setMenu ( menu ) ;
setAcceptDrops ( true ) ;
ui . lineEdit - > setAcceptDrops ( false ) ;
updateAvatar ( ) ;
loadmypersonalstatus ( ) ;
displayMenu ( ) ;
// load settings
processSettings ( true ) ;
2010-12-18 16:30:24 -05:00
/* Set header sizes for the fixed columns and resize modes, must be set after processSettings */
QHeaderView * header = ui . peertreeWidget - > header ( ) ;
header - > setStretchLastSection ( true ) ;
ui . peertreeWidget - > setColumnWidth ( COLUMN_STATE , 20 ) ; // small enough
header - > setResizeMode ( COLUMN_STATE , QHeaderView : : Stretch ) ;
2010-12-17 20:45:32 -05:00
2010-09-04 10:23:30 -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 ( ) ) ) ;
ui . lineEdit - > installEventFilter ( this ) ;
// add self nick and Avatar to Friends.
RsPeerDetails pd ;
if ( rsPeers - > getPeerDetails ( rsPeers - > getOwnId ( ) , pd ) ) {
QString titleStr ( " <span style= \" font-size:16pt; font-weight:500; "
" color:#32cd32; \" >%1</span> " ) ;
2010-09-15 12:06:31 -04:00
ui . nicklabel - > setText ( titleStr . arg ( QString : : fromStdString ( pd . name ) + " ( " + tr ( " me " ) + " ) " + QString : : fromStdString ( pd . location ) ) ) ;
2010-09-04 10:23:30 -04:00
}
/* Hide platform specific features */
2008-11-24 09:07:26 -05:00
# ifdef Q_WS_WIN
# endif
}
2007-11-14 22:18:48 -05:00
2010-05-11 16:02:52 -04:00
PeersDialog : : ~ PeersDialog ( )
{
2010-06-08 17:38:36 -04:00
// save settings
processSettings ( false ) ;
2010-09-19 20:10:51 -04:00
delete ( m_compareRole ) ;
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-12-17 20:45:32 -05:00
wasStatusColumnHidden = ui . peertreeWidget - > isColumnHidden ( COLUMN_STATE ) ;
2010-06-08 17:38:36 -04:00
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 ( ) ) ;
2010-12-15 16:32:44 -05:00
// state of the status
ui . action_Hide_State - > setChecked ( Settings - > value ( " hideState " , false ) . toBool ( ) ) ;
2010-06-16 15:00:28 -04:00
2010-12-17 20:45:32 -05:00
// state of hideStatusColumn
ui . action_Hide_Status_Column - > setChecked ( Settings - > value ( " hideStatusColumn " , false ) . toBool ( ) ) ;
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-09-22 18:37:57 -04:00
// open groups
openGroups . clear ( ) ;
int arrayIndex = Settings - > beginReadArray ( " Groups " ) ;
for ( int index = 0 ; index < arrayIndex ; index + + ) {
Settings - > setArrayIndex ( index ) ;
openGroups . push_back ( Settings - > value ( " open " ) . toString ( ) . toStdString ( ) ) ;
}
Settings - > endArray ( ) ;
2010-12-15 16:32:44 -05:00
2010-12-18 16:30:24 -05:00
if ( ui . peertreeWidget - > isColumnHidden ( COLUMN_STATE ) & & header - > sectionSize ( COLUMN_STATE ) < 100 ) {
// Workaround
correctColumnStatusSize = true ;
}
2010-12-17 20:45:32 -05:00
setStateColumn ( ) ;
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 ( ) ) ;
2010-12-15 16:32:44 -05:00
// state of the status
Settings - > setValue ( " hideState " , ui . action_Hide_State - > isChecked ( ) ) ;
2010-06-16 15:00:28 -04:00
2010-12-17 20:45:32 -05:00
// state of hideStatusColumn
Settings - > setValue ( " hideStatusColumn " , ui . action_Hide_Status_Column - > isChecked ( ) ) ;
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-09-22 18:37:57 -04:00
// open groups
Settings - > beginWriteArray ( " Groups " ) ;
int arrayIndex = 0 ;
int itemCount = ui . peertreeWidget - > topLevelItemCount ( ) ;
for ( int index = 0 ; index < itemCount ; index + + ) {
QTreeWidgetItem * item = ui . peertreeWidget - > topLevelItem ( index ) ;
if ( item - > type ( ) = = TYPE_GROUP & & item - > isExpanded ( ) ) {
Settings - > setArrayIndex ( arrayIndex + + ) ;
Settings - > setValue ( " open " , item - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) ) ;
}
}
Settings - > endArray ( ) ;
2010-06-08 17:38:36 -04:00
}
Settings - > endGroup ( ) ;
}
2010-09-04 10:23:30 -04:00
void PeersDialog : : showEvent ( QShowEvent * event )
{
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
}
2010-03-17 11:34:36 -04:00
void PeersDialog : : pasteLink ( )
{
2010-10-07 20:07:44 -04:00
ui . lineEdit - > insertHtml ( RSLinkClipboard : : toHtml ( ) ) ;
2010-03-17 11:34:36 -04:00
}
2010-11-21 16:12:35 -05:00
void PeersDialog : : contextMenu ( QPoint point )
2010-03-17 11:34:36 -04:00
{
2010-11-21 16:12:35 -05:00
QMenu * contextMnu = ui . lineEdit - > createStandardContextMenu ( ) ;
2010-03-17 11:34:36 -04:00
2010-11-21 16:12:35 -05:00
contextMnu - > addSeparator ( ) ;
QAction * action = contextMnu - > addAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste RetroShare Link " ) , this , SLOT ( pasteLink ( ) ) ) ;
action - > setDisabled ( RSLinkClipboard : : empty ( ) ) ;
2010-03-17 11:34:36 -04:00
2010-11-21 16:12:35 -05:00
contextMnu - > exec ( QCursor : : pos ( ) ) ;
delete ( contextMnu ) ;
2010-03-17 11:34:36 -04:00
}
2008-11-24 09:07:26 -05:00
void PeersDialog : : peertreeWidgetCostumPopupMenu ( QPoint point )
{
2010-07-15 07:25:34 -04:00
QTreeWidgetItem * c = getCurrentPeer ( ) ;
2008-11-24 09:07:26 -05:00
2010-07-15 07:25:34 -04:00
QMenu contextMnu ( this ) ;
2010-09-23 14:49:52 -04:00
QAction * action ;
2010-01-18 17:44:40 -05:00
2010-09-23 14:49:52 -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;} " ) ;
2010-01-18 17:44:40 -05:00
2010-09-23 14:49:52 -04:00
// create menu header
QHBoxLayout * hbox = new QHBoxLayout ( ) ;
hbox - > setMargin ( 0 ) ;
hbox - > setSpacing ( 6 ) ;
2007-11-14 22:18:48 -05:00
2010-09-23 14:49:52 -04:00
iconLabel = new QLabel ( this ) ;
iconLabel - > setPixmap ( QPixmap ( " :/images/user/friends24.png " ) ) ;
iconLabel - > setMaximumSize ( iconLabel - > frameSize ( ) . height ( ) + 24 , 24 ) ;
hbox - > addWidget ( iconLabel ) ;
2010-09-22 18:37:57 -04:00
2010-09-28 16:33:34 -04:00
textLabel = new QLabel ( " <strong> " + tr ( " RetroShare " ) + " </strong> " , widget ) ;
2010-09-22 18:37:57 -04:00
2010-09-23 14:49:52 -04:00
hbox - > addWidget ( textLabel ) ;
2009-07-13 15:58:11 -04:00
2010-09-23 14:49:52 -04:00
spacerItem = new QSpacerItem ( 40 , 20 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ;
hbox - > addItem ( spacerItem ) ;
2010-07-15 07:25:34 -04:00
2010-09-23 14:49:52 -04:00
widget - > setLayout ( hbox ) ;
2010-07-15 07:25:34 -04:00
2010-09-23 14:49:52 -04:00
QWidgetAction * widgetAction = new QWidgetAction ( this ) ;
widgetAction - > setDefaultWidget ( widget ) ;
2010-07-15 07:25:34 -04:00
2010-09-23 14:49:52 -04:00
contextMnu . addAction ( widgetAction ) ;
2009-07-13 15:58:11 -04:00
2010-09-23 14:49:52 -04:00
// create menu entries
2010-08-30 09:03:12 -04:00
if ( c ) {
2010-09-23 14:49:52 -04:00
int type = c - > type ( ) ;
2010-09-22 18:37:57 -04:00
2010-09-23 14:49:52 -04:00
// define header
switch ( type ) {
case TYPE_GROUP :
2010-09-28 16:33:34 -04:00
//this is a GPG key
textLabel - > setText ( " <strong> " + tr ( " Group " ) + " </strong> " ) ;
break ;
2010-09-23 14:49:52 -04:00
case TYPE_GPG :
//this is a GPG key
2010-09-28 16:33:34 -04:00
textLabel - > setText ( " <strong> " + tr ( " Friend " ) + " </strong> " ) ;
break ;
case TYPE_SSL :
//this is a SSL key
textLabel - > setText ( " <strong> " + tr ( " Location " ) + " </strong> " ) ;
2010-09-23 14:49:52 -04:00
break ;
}
2010-09-22 18:37:57 -04:00
2010-09-23 14:49:52 -04:00
switch ( type ) {
case TYPE_GROUP :
{
bool standard = c - > data ( COLUMN_DATA , ROLE_STANDARD ) . toBool ( ) ;
2010-09-22 18:37:57 -04:00
2010-09-29 15:30:59 -04:00
contextMnu . addAction ( QIcon ( IMAGE_MSG ) , tr ( " Message Group " ) , this , SLOT ( msgfriend ( ) ) ) ;
contextMnu . addAction ( QIcon ( IMAGE_ADDFRIEND ) , tr ( " Add Friend " ) , this , SLOT ( addFriend ( ) ) ) ;
2010-09-27 17:05:52 -04:00
contextMnu . addSeparator ( ) ;
2010-09-29 15:30:59 -04:00
action = contextMnu . addAction ( QIcon ( IMAGE_EDIT ) , tr ( " Edit Group " ) , this , SLOT ( editGroup ( ) ) ) ;
2010-09-23 14:49:52 -04:00
action - > setDisabled ( standard ) ;
2010-09-22 18:37:57 -04:00
2010-09-29 15:30:59 -04:00
action = contextMnu . addAction ( QIcon ( IMAGE_REMOVE ) , tr ( " Remove Group " ) , this , SLOT ( removeGroup ( ) ) ) ;
2010-09-23 14:49:52 -04:00
action - > setDisabled ( standard ) ;
2010-09-22 18:37:57 -04:00
}
2010-09-23 14:49:52 -04:00
break ;
case TYPE_GPG :
case TYPE_SSL :
{
contextMnu . addAction ( QIcon ( IMAGE_CHAT ) , tr ( " Chat " ) , this , SLOT ( chatfriendproxy ( ) ) ) ;
contextMnu . addAction ( QIcon ( IMAGE_MSG ) , tr ( " Message Friend " ) , this , SLOT ( msgfriend ( ) ) ) ;
2010-09-23 19:41:54 -04:00
contextMnu . addSeparator ( ) ;
2010-09-27 17:05:52 -04:00
2010-09-23 19:41:54 -04:00
contextMnu . addAction ( QIcon ( IMAGE_FRIENDINFO ) , tr ( " Friend Details " ) , this , SLOT ( configurefriend ( ) ) ) ;
2010-09-23 14:49:52 -04:00
// contextMnu.addAction(QIcon(IMAGE_PEERINFO), tr("Profile View"), this, SLOT(viewprofile()));
// action = contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Export Friend"), this, SLOT(exportfriend()));
if ( type = = TYPE_GPG ) {
2010-09-27 17:05:52 -04:00
contextMnu . addAction ( QIcon ( IMAGE_EXPORTFRIEND ) , tr ( " Recommend this Friend to... " ) , this , SLOT ( recommendfriend ( ) ) ) ;
2010-09-23 14:49:52 -04:00
}
2010-09-22 18:37:57 -04:00
2010-09-23 14:49:52 -04:00
contextMnu . addAction ( QIcon ( IMAGE_CONNECT ) , tr ( " Connect To Friend " ) , this , SLOT ( connectfriend ( ) ) ) ;
2010-09-22 18:37:57 -04:00
2010-09-23 14:49:52 -04:00
action = contextMnu . addAction ( QIcon ( IMAGE_PASTELINK ) , tr ( " Paste Friend Link " ) , this , SLOT ( pastePerson ( ) ) ) ;
if ( RSLinkClipboard : : empty ( RetroShareLink : : TYPE_PERSON ) ) {
action - > setDisabled ( true ) ;
2010-09-22 18:37:57 -04:00
}
2010-09-23 14:49:52 -04:00
if ( type = = TYPE_GPG ) {
2010-09-23 18:34:40 -04:00
contextMnu . addAction ( QIcon ( IMAGE_DENYFRIEND ) , tr ( " Deny Friend " ) , this , SLOT ( removefriend ( ) ) ) ;
2010-09-23 14:49:52 -04:00
} else {
//this is a SSL key
contextMnu . addAction ( QIcon ( IMAGE_REMOVEFRIEND ) , tr ( " Remove Friend Location " ) , this , SLOT ( removefriend ( ) ) ) ;
2010-09-22 18:37:57 -04:00
}
2010-09-23 14:49:52 -04:00
if ( type = = TYPE_GPG ) {
QMenu * groupsMenu = NULL ;
QMenu * addToGroupMenu = NULL ;
QMenu * moveToGroupMenu = NULL ;
2010-09-22 18:37:57 -04:00
2010-09-23 14:49:52 -04:00
std : : list < RsGroupInfo > groupInfoList ;
rsPeers - > getGroupInfoList ( groupInfoList ) ;
2008-11-24 09:07:26 -05:00
2010-09-23 14:49:52 -04:00
GroupDefs : : sortByName ( groupInfoList ) ;
2007-11-14 22:18:48 -05:00
2010-09-23 14:49:52 -04:00
std : : string gpgId = c - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
2010-07-15 07:25:34 -04:00
2010-09-23 14:49:52 -04:00
QTreeWidgetItem * parent = c - > parent ( ) ;
2010-07-15 07:25:34 -04:00
2010-09-23 14:49:52 -04:00
bool foundGroup = false ;
// add action for all groups, except the own group
for ( std : : list < RsGroupInfo > : : iterator groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; groupIt + + ) {
if ( std : : find ( groupIt - > peerIds . begin ( ) , groupIt - > peerIds . end ( ) , gpgId ) = = groupIt - > peerIds . end ( ) ) {
if ( parent ) {
if ( addToGroupMenu = = NULL ) {
addToGroupMenu = new QMenu ( tr ( " Add to group " ) , & contextMnu ) ;
}
QAction * addToGroupAction = new QAction ( GroupDefs : : name ( * groupIt ) , addToGroupMenu ) ;
addToGroupAction - > setData ( QString : : fromStdString ( groupIt - > id ) ) ;
connect ( addToGroupAction , SIGNAL ( triggered ( ) ) , this , SLOT ( addToGroup ( ) ) ) ;
addToGroupMenu - > addAction ( addToGroupAction ) ;
}
2010-07-15 07:25:34 -04:00
2010-09-23 14:49:52 -04:00
if ( moveToGroupMenu = = NULL ) {
moveToGroupMenu = new QMenu ( tr ( " Move to group " ) , & contextMnu ) ;
}
QAction * moveToGroupAction = new QAction ( GroupDefs : : name ( * groupIt ) , moveToGroupMenu ) ;
moveToGroupAction - > setData ( QString : : fromStdString ( groupIt - > id ) ) ;
connect ( moveToGroupAction , SIGNAL ( triggered ( ) ) , this , SLOT ( moveToGroup ( ) ) ) ;
moveToGroupMenu - > addAction ( moveToGroupAction ) ;
} else {
foundGroup = true ;
}
}
2010-07-15 07:25:34 -04:00
2010-09-23 14:49:52 -04:00
if ( addToGroupMenu | | moveToGroupMenu | | foundGroup ) {
groupsMenu = contextMnu . addMenu ( QIcon ( IMAGE_GROUP16 ) , tr ( " Groups " ) ) ;
2010-07-15 07:25:34 -04:00
2010-09-23 14:49:52 -04:00
if ( addToGroupMenu ) {
groupsMenu - > addMenu ( addToGroupMenu ) ;
}
if ( moveToGroupMenu ) {
groupsMenu - > addMenu ( moveToGroupMenu ) ;
}
if ( foundGroup ) {
// add remove from group
if ( parent & & parent - > type ( ) = = TYPE_GROUP ) {
QAction * removeFromGroup = groupsMenu - > addAction ( tr ( " Remove from group " ) ) ;
removeFromGroup - > setData ( parent - > data ( COLUMN_DATA , ROLE_ID ) ) ;
connect ( removeFromGroup , SIGNAL ( triggered ( ) ) , this , SLOT ( removeFromGroup ( ) ) ) ;
}
QAction * removeFromAllGroups = groupsMenu - > addAction ( tr ( " Remove from all groups " ) ) ;
removeFromAllGroups - > setData ( " " ) ;
connect ( removeFromAllGroups , SIGNAL ( triggered ( ) ) , this , SLOT ( removeFromGroup ( ) ) ) ;
}
}
}
}
}
} else {
action = contextMnu . addAction ( QIcon ( IMAGE_PASTELINK ) , tr ( " Paste Friend Link " ) , this , SLOT ( pastePerson ( ) ) ) ;
if ( RSLinkClipboard : : empty ( RetroShareLink : : TYPE_PERSON ) ) {
action - > setDisabled ( true ) ;
}
2010-09-22 18:37:57 -04:00
}
2010-09-23 14:49:52 -04:00
2010-07-15 07:25:34 -04:00
contextMnu . addSeparator ( ) ;
2010-09-23 14:49:52 -04:00
2010-09-23 18:46:36 -04:00
contextMnu . addAction ( QIcon ( IMAGE_EXPAND ) , tr ( " Expand all " ) , ui . peertreeWidget , SLOT ( expandAll ( ) ) ) ;
contextMnu . addAction ( QIcon ( IMAGE_COLLAPSE ) , tr ( " Collapse all " ) , ui . peertreeWidget , SLOT ( collapseAll ( ) ) ) ;
2010-07-15 07:25:34 -04:00
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-09-04 10:23:30 -04:00
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 ;
2010-09-22 18:37:57 -04:00
std : : list < std : : string > : : iterator gpgIt ;
2010-08-03 08:35:26 -04:00
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 ;
}
2010-12-15 16:32:44 -05:00
bool hideUnconnected = ui . action_Hide_Offline_Friends - > isChecked ( ) ;
2010-12-17 20:45:32 -05:00
bool useStatusColumn = ! ui . action_Hide_Status_Column - > isChecked ( ) ;
bool showState = ! ui . action_Hide_State - > isChecked ( ) ;
2010-08-03 08:35:26 -04:00
2010-09-22 18:37:57 -04:00
// get ids of existing private chat messages
2010-09-01 13:56:15 -04:00
std : : list < std : : string > privateChatIds ;
2010-09-20 20:08:06 -04:00
rsMsgs - > getPrivateChatQueueIds ( true , privateChatIds ) ;
2010-09-01 13:56:15 -04:00
2010-09-22 18:37:57 -04:00
// get existing groups
std : : list < RsGroupInfo > groupInfoList ;
std : : list < RsGroupInfo > : : iterator groupIt ;
rsPeers - > getGroupInfoList ( groupInfoList ) ;
2010-08-03 08:35:26 -04:00
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 ;
2010-09-22 18:37:57 -04:00
// remove items don't exist anymore
QTreeWidgetItemIterator itemIterator ( peertreeWidget ) ;
QTreeWidgetItem * item ;
while ( ( item = * itemIterator ) ! = NULL ) {
itemIterator + + ;
switch ( item - > type ( ) ) {
case TYPE_GPG :
{
QTreeWidgetItem * parent = item - > parent ( ) ;
std : : string gpg_widget_id = item - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
// remove items that are not friends anymore
if ( std : : find ( gpgFriends . begin ( ) , gpgFriends . end ( ) , gpg_widget_id ) = = gpgFriends . end ( ) ) {
if ( parent ) {
delete ( parent - > takeChild ( parent - > indexOfChild ( item ) ) ) ;
} else {
delete ( peertreeWidget - > takeTopLevelItem ( peertreeWidget - > indexOfTopLevelItem ( item ) ) ) ;
}
break ;
}
if ( groupsHasChanged ) {
if ( parent ) {
if ( parent - > type ( ) = = TYPE_GROUP ) {
std : : string groupId = parent - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
// the parent is a group, check if the gpg id is assigned to the group
for ( groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; groupIt + + ) {
if ( groupIt - > id = = groupId ) {
if ( std : : find ( groupIt - > peerIds . begin ( ) , groupIt - > peerIds . end ( ) , gpg_widget_id ) = = groupIt - > peerIds . end ( ) ) {
delete ( parent - > takeChild ( parent - > indexOfChild ( item ) ) ) ;
}
break ;
}
}
}
} else {
// gpg item without group, check if the gpg id is assigned to the group
for ( groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; groupIt + + ) {
if ( std : : find ( groupIt - > peerIds . begin ( ) , groupIt - > peerIds . end ( ) , gpg_widget_id ) ! = groupIt - > peerIds . end ( ) ) {
delete ( peertreeWidget - > takeTopLevelItem ( peertreeWidget - > indexOfTopLevelItem ( item ) ) ) ;
break ;
}
}
}
}
}
break ;
case TYPE_GROUP :
{
if ( groupsHasChanged ) {
// remove deleted groups
std : : string groupId = item - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
for ( groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; groupIt + + ) {
if ( groupIt - > id = = groupId ) {
break ;
}
}
if ( groupIt = = groupInfoList . end ( ) | | groupIt - > peerIds . size ( ) = = 0 ) {
if ( item - > parent ( ) ) {
delete ( item - > parent ( ) - > takeChild ( item - > parent ( ) - > indexOfChild ( item ) ) ) ;
} else {
delete ( peertreeWidget - > takeTopLevelItem ( peertreeWidget - > indexOfTopLevelItem ( item ) ) ) ;
}
}
}
}
break ;
2010-08-03 08:35:26 -04:00
}
}
2010-09-22 18:37:57 -04:00
std : : list < std : : string > fillGpgIds ;
// start with groups
groupIt = groupInfoList . begin ( ) ;
while ( true ) {
QTreeWidgetItem * groupItem = NULL ;
RsGroupInfo * groupInfo = NULL ;
int onlineCount = 0 ;
int availableCount = 0 ;
if ( groupIt ! = groupInfoList . end ( ) ) {
groupInfo = & ( * groupIt ) ;
2010-06-08 17:38:36 -04:00
2010-09-23 04:37:03 -04:00
if ( ( groupInfo - > flag & RS_GROUP_FLAG_STANDARD ) & & groupInfo - > peerIds . size ( ) = = 0 ) {
// don't show empty standard groups
2010-09-22 18:37:57 -04:00
groupIt + + ;
continue ;
2010-08-03 08:35:26 -04:00
}
2007-11-14 22:18:48 -05:00
2010-09-22 18:37:57 -04:00
// search existing group item
int itemCount = peertreeWidget - > topLevelItemCount ( ) ;
for ( int index = 0 ; index < itemCount ; index + + ) {
QTreeWidgetItem * groupItemLoop = peertreeWidget - > topLevelItem ( index ) ;
if ( groupItemLoop - > type ( ) = = TYPE_GROUP & & groupItemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) = = groupInfo - > id ) {
groupItem = groupItemLoop ;
break ;
}
2010-08-03 08:35:26 -04:00
}
2008-01-25 03:49:40 -05:00
2010-09-22 18:37:57 -04:00
if ( groupItem = = NULL ) {
// add group item
groupItem = new RSTreeWidgetItem ( m_compareRole , TYPE_GROUP ) ;
2010-09-10 16:43:11 -04:00
2010-09-22 18:37:57 -04:00
/* Add item to the list. Add here, because for setHidden the item must be added */
peertreeWidget - > addTopLevelItem ( groupItem ) ;
2010-09-10 16:43:11 -04:00
2010-09-22 18:37:57 -04:00
groupItem - > setChildIndicatorPolicy ( QTreeWidgetItem : : DontShowIndicatorWhenChildless ) ;
groupItem - > setSizeHint ( COLUMN_NAME , QSize ( 26 , 26 ) ) ;
groupItem - > setTextAlignment ( COLUMN_NAME , Qt : : AlignLeft | Qt : : AlignVCenter ) ;
2010-09-23 14:49:52 -04:00
groupItem - > setIcon ( COLUMN_NAME , QIcon ( IMAGE_GROUP24 ) ) ;
2010-09-28 07:21:42 -04:00
groupItem - > setForeground ( COLUMN_NAME , QBrush ( QColor ( 123 , 123 , 123 ) ) ) ;
2010-06-08 17:38:36 -04:00
2010-09-22 18:37:57 -04:00
/* used to find back the item */
groupItem - > setData ( COLUMN_DATA , ROLE_ID , QString : : fromStdString ( groupInfo - > id ) ) ;
groupItem - > setData ( COLUMN_DATA , ROLE_STANDARD , ( groupInfo - > flag & RS_GROUP_FLAG_STANDARD ) ? true : false ) ;
2007-11-14 22:18:48 -05:00
2010-09-22 18:37:57 -04:00
if ( openGroups . size ( ) ) {
if ( std : : find ( openGroups . begin ( ) , openGroups . end ( ) , groupInfo - > id ) ! = openGroups . end ( ) ) {
groupItem - > setExpanded ( true ) ;
}
}
} else {
// remove all gpg items that are not more assigned
int childCount = groupItem - > childCount ( ) ;
int childIndex = 0 ;
while ( childIndex < childCount ) {
QTreeWidgetItem * gpgItemLoop = groupItem - > child ( childIndex ) ;
if ( gpgItemLoop - > type ( ) = = TYPE_GPG ) {
if ( std : : find ( groupInfo - > peerIds . begin ( ) , groupInfo - > peerIds . end ( ) , gpgItemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ) = = groupInfo - > peerIds . end ( ) ) {
delete ( groupItem - > takeChild ( groupItem - > indexOfChild ( gpgItemLoop ) ) ) ;
childCount = groupItem - > childCount ( ) ;
continue ;
}
}
childIndex + + ;
}
}
// name is set after calculation of online/offline items
}
2010-01-13 19:38:36 -05:00
2010-09-22 18:37:57 -04:00
// iterate through gpg friends
for ( gpgIt = gpgFriends . begin ( ) ; gpgIt ! = gpgFriends . end ( ) ; gpgIt + + ) {
std : : string gpgId = * gpgIt ;
2010-01-02 16:45:46 -05:00
2010-09-22 18:37:57 -04:00
if ( groupInfo ) {
// we fill a group, check if gpg id is assigned
if ( std : : find ( groupInfo - > peerIds . begin ( ) , groupInfo - > peerIds . end ( ) , gpgId ) = = groupInfo - > peerIds . end ( ) ) {
continue ;
}
2010-01-13 16:25:18 -05:00
} else {
2010-09-22 18:37:57 -04:00
// we fill the not assigned gpg ids
if ( std : : find ( fillGpgIds . begin ( ) , fillGpgIds . end ( ) , gpgId ) ! = fillGpgIds . end ( ) ) {
continue ;
}
2010-01-13 16:25:18 -05:00
}
2010-09-22 18:37:57 -04:00
// add equal too, its no problem
fillGpgIds . push_back ( gpgId ) ;
2010-09-08 14:36:36 -04:00
2010-09-22 18:37:57 -04:00
//add the gpg friends
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog::insertPeers() inserting gpg_id : " < < * it < < std : : endl ;
# endif
2010-08-03 08:35:26 -04:00
2010-09-22 18:37:57 -04:00
/* make a widget per friend */
QTreeWidgetItem * gpgItem = NULL ;
QTreeWidgetItem * gpgItemLoop = NULL ;
// search existing gpg item
int itemCount = groupItem ? groupItem - > childCount ( ) : peertreeWidget - > topLevelItemCount ( ) ;
for ( int index = 0 ; index < itemCount ; index + + ) {
gpgItemLoop = groupItem ? groupItem - > child ( index ) : peertreeWidget - > topLevelItem ( index ) ;
if ( gpgItemLoop - > type ( ) = = TYPE_GPG & & gpgItemLoop - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) = = gpgId ) {
gpgItem = gpgItemLoop ;
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-09-22 18:37:57 -04:00
RsPeerDetails detail ;
if ( ( ! rsPeers - > getPeerDetails ( gpgId , detail ) | | ! detail . accept_connection ) & & detail . gpg_id ! = ownId ) {
// don't accept anymore connection, remove from the view
if ( gpgItem ) {
if ( groupItem ) {
delete ( groupItem - > takeChild ( groupItem - > indexOfChild ( gpgItem ) ) ) ;
} else {
delete ( peertreeWidget - > takeTopLevelItem ( peertreeWidget - > indexOfTopLevelItem ( gpgItem ) ) ) ;
}
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-09-22 18:37:57 -04:00
if ( gpgItem = = NULL ) {
// create gpg item and add it to tree
gpgItem = new RSTreeWidgetItem ( m_compareRole , TYPE_GPG ) ; //set type to 0 for custom popup menu
2010-09-10 16:43:11 -04:00
2010-09-22 18:37:57 -04:00
/* Add gpg item to the list. Add here, because for setHidden the item must be added */
if ( groupItem ) {
groupItem - > addChild ( gpgItem ) ;
} else {
peertreeWidget - > addTopLevelItem ( gpgItem ) ;
}
gpgItem - > setChildIndicatorPolicy ( QTreeWidgetItem : : DontShowIndicatorWhenChildless ) ;
gpgItem - > setSizeHint ( COLUMN_NAME , QSize ( 26 , 26 ) ) ;
gpgItem - > setTextAlignment ( COLUMN_NAME , Qt : : AlignLeft | Qt : : AlignVCenter ) ;
2010-09-10 16:43:11 -04:00
2010-09-22 18:37:57 -04:00
/* not displayed, used to find back the item */
gpgItem - > setData ( COLUMN_DATA , ROLE_ID , QString : : fromStdString ( detail . id ) ) ;
2010-05-12 16:10:22 -04:00
}
2010-09-22 18:37:57 -04:00
availableCount + + ;
2010-01-13 16:16:18 -05:00
2010-12-15 16:32:44 -05:00
QString gpgItemText = QString : : fromStdString ( detail . name ) ;
2010-09-22 18:37:57 -04:00
// remove items that are not friends anymore
int childCount = gpgItem - > childCount ( ) ;
int childIndex = 0 ;
while ( childIndex < childCount ) {
std : : string ssl_id = gpgItem - > child ( childIndex ) - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
if ( ! rsPeers - > isFriend ( ssl_id ) ) {
delete ( gpgItem - > takeChild ( childIndex ) ) ;
// count again
childCount = gpgItem - > childCount ( ) ;
2010-01-13 16:22:52 -05:00
} else {
2010-09-22 18:37:57 -04:00
childIndex + + ;
2010-01-13 16:16:18 -05:00
}
}
2010-01-13 16:25:18 -05:00
2010-09-22 18:37:57 -04:00
// update the childs (ssl certs)
bool gpg_connected = false ;
bool gpg_online = false ;
bool gpg_hasPrivateChat = 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 ;
std : : string sslId = * sslIt ;
//find the corresponding sslItem child item of the gpg item
bool newChild = true ;
childCount = gpgItem - > childCount ( ) ;
for ( int childIndex = 0 ; childIndex < childCount ; childIndex + + ) {
// we assume, that only ssl items are child of the gpg item, so we don't need to test the type
if ( gpgItem - > child ( childIndex ) - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) = = sslId ) {
sslItem = gpgItem - > child ( childIndex ) ;
newChild = false ;
break ;
}
}
2010-09-01 13:56:15 -04:00
2010-09-22 18:37:57 -04:00
RsPeerDetails sslDetail ;
if ( ! rsPeers - > getPeerDetails ( sslId , sslDetail ) | | ! rsPeers - > isFriend ( sslId ) ) {
# ifdef PEERS_DEBUG
std : : cerr < < " Removing widget from the view : id : " < < sslId < < std : : endl ;
# endif
//child has disappeared, remove it from the gpg_item
if ( sslItem ) {
gpgItem - > removeChild ( sslItem ) ;
}
continue ;
}
2010-08-03 08:35:26 -04:00
2010-09-22 18:37:57 -04:00
if ( newChild ) {
sslItem = new RSTreeWidgetItem ( m_compareRole , TYPE_SSL ) ; //set type to 1 for custom popup menu
2010-09-08 14:36:36 -04:00
2010-09-22 18:37:57 -04:00
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog::insertPeers() inserting sslItem. " < < std : : endl ;
# endif
2010-06-08 17:38:36 -04:00
2010-09-22 18:37:57 -04:00
/* Add ssl child to the list. Add here, because for setHidden the item must be added */
gpgItem - > addChild ( sslItem ) ;
}
2010-06-08 17:38:36 -04:00
2010-09-22 18:37:57 -04:00
/* not displayed, used to find back the item */
sslItem - > setData ( COLUMN_DATA , ROLE_ID , QString : : fromStdString ( sslDetail . id ) ) ;
2010-06-08 17:38:36 -04:00
2010-09-22 18:37:57 -04:00
QString sText ;
2010-11-24 14:25:53 -05:00
QString customStateString ;
2010-09-22 18:37:57 -04:00
if ( sslDetail . state & RS_PEER_STATE_CONNECTED ) {
2010-11-24 14:25:53 -05:00
customStateString = QString : : fromUtf8 ( rsMsgs - > getCustomStateString ( sslDetail . id ) . c_str ( ) ) ;
2010-09-22 18:37:57 -04:00
}
sText = tr ( " location " ) + " : " + QString : : fromStdString ( sslDetail . location ) ;
2010-11-24 14:25:53 -05:00
if ( customStateString . isEmpty ( ) = = false ) {
sText + = " - " + customStateString ;
2010-09-22 18:37:57 -04:00
}
2011-01-06 13:26:39 -05:00
QString connectStateString = StatusDefs : : connectStateString ( sslDetail ) ;
if ( useStatusColumn ) {
sslItem - > setText ( COLUMN_STATE , connectStateString ) ;
} else if ( showState & & connectStateString . isEmpty ( ) = = false ) {
sText + = " [ " + StatusDefs : : connectStateString ( sslDetail ) + " ] " ;
2010-12-15 16:32:44 -05:00
}
2010-09-22 18:37:57 -04:00
sslItem - > setText ( COLUMN_NAME , sText ) ;
2010-12-22 18:02:21 -05:00
if ( useStatusColumn = = false & & showState = = false ) {
/* Show the state as tooltip */
2011-01-06 13:26:39 -05:00
sslItem - > setToolTip ( COLUMN_NAME , connectStateString ) ;
2010-12-22 18:02:21 -05:00
} else {
sslItem - > setToolTip ( COLUMN_NAME , " " ) ;
}
2010-09-22 18:37:57 -04:00
// sort location
2010-12-17 20:45:32 -05:00
sslItem - > setData ( COLUMN_STATE , ROLE_SORT , sText ) ;
2010-09-22 18:37:57 -04:00
/* change color and icon */
QIcon sslIcon ;
QFont sslFont ;
QColor sslColor ;
if ( sslDetail . state & RS_PEER_STATE_CONNECTED ) {
sslItem - > setHidden ( false ) ;
gpg_connected = true ;
sslIcon = QIcon ( " :/images/connect_established.png " ) ;
sslFont . setBold ( true ) ;
sslColor = Qt : : darkBlue ;
} else if ( sslDetail . state & RS_PEER_STATE_ONLINE ) {
2010-12-15 16:32:44 -05:00
sslItem - > setHidden ( hideUnconnected ) ;
2010-09-22 18:37:57 -04:00
gpg_online = true ;
2011-01-06 13:26:39 -05:00
if ( sslDetail . connectState ) {
sslIcon = QIcon ( " :/images/connect_creating.png " ) ;
} else {
sslIcon = QIcon ( " :/images/connect_no.png " ) ;
}
2010-09-22 18:37:57 -04:00
sslFont . setBold ( true ) ;
sslColor = Qt : : black ;
} else {
2010-12-15 16:32:44 -05:00
sslItem - > setHidden ( hideUnconnected ) ;
2011-01-06 13:26:39 -05:00
if ( sslDetail . connectState ) {
2010-09-22 18:37:57 -04:00
sslIcon = QIcon ( " :/images/connect_creating.png " ) ;
} else {
sslIcon = QIcon ( " :/images/connect_no.png " ) ;
}
2010-06-08 17:38:36 -04:00
2010-09-22 18:37:57 -04:00
sslFont . setBold ( false ) ;
sslColor = Qt : : black ;
}
2010-09-08 14:36:36 -04:00
2010-09-22 18:37:57 -04:00
if ( std : : find ( privateChatIds . begin ( ) , privateChatIds . end ( ) , sslDetail . id ) ! = privateChatIds . end ( ) ) {
// private chat is available
sslIcon = QIcon ( " :/images/chat.png " ) ;
gpg_hasPrivateChat = true ;
}
sslItem - > setIcon ( COLUMN_NAME , sslIcon ) ;
2010-06-08 17:38:36 -04:00
2010-09-22 18:37:57 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
sslItem - > setTextColor ( i , sslColor ) ;
sslItem - > setFont ( i , sslFont ) ;
}
}
2010-08-03 08:35:26 -04:00
2010-12-27 09:00:13 -05:00
int bestPeerState = 0 ; // for gpg item
2010-09-22 18:37:57 -04:00
int i = 0 ;
QIcon gpgIcon ;
if ( gpg_connected ) {
gpgItem - > setHidden ( false ) ;
onlineCount + + ;
std : : string bestSslId ; // for gpg item
unsigned int bestRSState = 0 ; // for gpg item
std : : list < StatusInfo > : : iterator it ;
for ( it = statusInfo . begin ( ) ; it ! = statusInfo . end ( ) ; it + + ) {
// don't forget the kids
std : : list < std : : string > : : iterator cont_it ;
for ( cont_it = sslContacts . begin ( ) ; cont_it ! = sslContacts . end ( ) ; cont_it + + ) {
if ( ( it - > id = = * cont_it ) & & ( rsPeers - > isOnline ( * cont_it ) ) ) {
int peerState = 0 ;
switch ( it - > status ) {
case RS_STATUS_INACTIVE :
peerState = PEER_STATE_INACTIVE ;
break ;
case RS_STATUS_ONLINE :
peerState = PEER_STATE_ONLINE ;
break ;
case RS_STATUS_AWAY :
peerState = PEER_STATE_AWAY ;
break ;
case RS_STATUS_BUSY :
peerState = PEER_STATE_BUSY ;
break ;
}
/* find the best ssl contact for the gpg item */
if ( bestPeerState = = 0 ) {
/* first ssl contact */
bestPeerState = peerState ;
bestSslId = * cont_it ;
bestRSState = it - > status ;
} else if ( peerState < bestPeerState ) {
/* higher state */
bestPeerState = peerState ;
bestSslId = * cont_it ;
bestRSState = it - > status ;
} else if ( peerState = = bestPeerState ) {
/* equal state ... use first */
}
}
}
}
2010-08-03 08:35:26 -04:00
2010-09-22 18:37:57 -04:00
if ( bestPeerState = = 0 ) {
// show as online
bestPeerState = PEER_STATE_ONLINE ;
bestRSState = RS_STATUS_ONLINE ;
}
2010-08-03 08:35:26 -04:00
2010-09-22 18:37:57 -04:00
QColor textColor = StatusDefs : : textColor ( bestRSState ) ;
QFont font = StatusDefs : : font ( bestRSState ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpgItem - > setTextColor ( i , textColor ) ;
gpgItem - > setFont ( i , font ) ;
}
2010-09-08 14:36:36 -04:00
2010-09-22 18:37:57 -04:00
gpgIcon = QIcon ( StatusDefs : : imageUser ( bestRSState ) ) ;
2010-12-17 20:45:32 -05:00
if ( useStatusColumn ) {
gpgItem - > setText ( COLUMN_STATE , StatusDefs : : name ( bestRSState ) ) ;
} else if ( showState ) {
2010-12-15 16:32:44 -05:00
gpgItemText + = " [ " + StatusDefs : : name ( bestRSState ) + " ] " ;
}
2010-12-17 20:45:32 -05:00
2010-12-22 18:02:21 -05:00
// gpgItem->setToolTip(COLUMN_NAME, StatusDefs::tooltip(bestRSState));
2010-09-22 18:37:57 -04:00
} else if ( gpg_online ) {
2010-12-17 20:45:32 -05:00
if ( useStatusColumn ) {
gpgItem - > setText ( COLUMN_STATE , tr ( " Available " ) ) ;
} else if ( showState ) {
gpgItemText + = " [ " + tr ( " Available " ) + " ] " ;
}
2010-12-27 09:00:13 -05:00
bestPeerState = PEER_STATE_AVAILABLE ;
2010-09-22 18:37:57 -04:00
onlineCount + + ;
2010-12-15 16:32:44 -05:00
gpgItem - > setHidden ( hideUnconnected ) ;
2010-09-22 18:37:57 -04:00
gpgIcon = QIcon ( IMAGE_AVAILABLE ) ;
QFont font ;
font . setBold ( true ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpgItem - > setTextColor ( i , ( Qt : : black ) ) ;
gpgItem - > setFont ( i , font ) ;
}
} else {
2010-12-17 20:45:32 -05:00
if ( useStatusColumn ) {
gpgItem - > setText ( COLUMN_STATE , StatusDefs : : name ( RS_STATUS_OFFLINE ) ) ;
} else if ( showState ) {
gpgItemText + = " [ " + StatusDefs : : name ( RS_STATUS_OFFLINE ) + " ] " ;
}
2010-12-27 09:00:13 -05:00
bestPeerState = PEER_STATE_OFFLINE ;
2010-12-15 16:32:44 -05:00
gpgItem - > setHidden ( hideUnconnected ) ;
2010-09-22 18:37:57 -04:00
gpgIcon = QIcon ( StatusDefs : : imageUser ( RS_STATUS_OFFLINE ) ) ;
QColor textColor = StatusDefs : : textColor ( RS_STATUS_OFFLINE ) ;
QFont font = StatusDefs : : font ( RS_STATUS_OFFLINE ) ;
for ( i = 0 ; i < COLUMN_COUNT ; i + + ) {
gpgItem - > setTextColor ( i , textColor ) ;
gpgItem - > setFont ( i , font ) ;
2010-09-08 14:36:36 -04:00
}
}
2010-09-22 18:37:57 -04:00
if ( gpg_hasPrivateChat ) {
gpgIcon = QIcon ( " :/images/chat.png " ) ;
2010-09-11 16:25:08 -04:00
}
2010-09-08 14:36:36 -04:00
2010-12-15 16:32:44 -05:00
gpgItem - > setText ( COLUMN_NAME , gpgItemText ) ;
2010-12-17 20:45:32 -05:00
gpgItem - > setData ( COLUMN_NAME , ROLE_SORT , " 2 " + gpgItemText ) ;
2010-12-27 09:00:13 -05:00
gpgItem - > setData ( COLUMN_STATE , ROLE_SORT , " 2 " + BuildStateSortString ( true , gpgItemText , bestPeerState ) ) ;
2010-09-22 18:37:57 -04:00
gpgItem - > setIcon ( COLUMN_NAME , gpgIcon ) ;
}
2010-09-08 14:36:36 -04:00
2010-09-22 18:37:57 -04:00
if ( groupInfo & & groupItem ) {
2010-09-23 04:37:03 -04:00
if ( ( groupInfo - > flag & RS_GROUP_FLAG_STANDARD ) & & groupItem - > childCount ( ) = = 0 ) {
2010-09-22 18:37:57 -04:00
// there are some dead id's assigned
groupItem - > setHidden ( true ) ;
} else {
2010-11-09 14:57:05 -05:00
QString groupName = GroupDefs : : name ( * groupInfo ) ;
groupItem - > setText ( COLUMN_NAME , QString ( " %1 (%2/%3) " ) . arg ( groupName ) . arg ( onlineCount ) . arg ( availableCount ) ) ;
2010-09-23 04:37:03 -04:00
// show first the standard groups, than the user groups
2010-12-17 20:45:32 -05:00
groupItem - > setData ( COLUMN_NAME , ROLE_SORT , ( ( groupInfo - > flag & RS_GROUP_FLAG_STANDARD ) ? " 0 " : " 1 " ) + groupName ) ;
2010-06-13 08:26:23 -04:00
}
2010-01-13 16:22:52 -05:00
}
2010-08-03 08:35:26 -04:00
2010-09-22 18:37:57 -04:00
if ( groupIt ! = groupInfoList . end ( ) ) {
groupIt + + ;
} else {
// all done
break ;
2010-09-01 13:56:15 -04:00
}
2010-08-03 08:35:26 -04:00
}
2010-08-30 09:03:12 -04:00
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c & & c - > isHidden ( ) ) {
// active item is hidden, deselect it
ui . peertreeWidget - > setCurrentItem ( NULL ) ;
}
2010-09-22 18:37:57 -04:00
groupsHasChanged = false ;
openGroups . clear ( ) ;
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 ) ;
2010-12-02 19:54:40 -05:00
if ( misc : : getSaveFileName ( this , RshareSettings : : LASTDIR_CERT , tr ( " Save Certificate " ) , tr ( " Certificates (*.pqi) " ) , fileName ) )
2007-11-14 22:18:48 -05:00
{
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-12-02 19:54:40 -05:00
rsPeers - > saveCertificateToFile ( id , fileName . toUtf8 ( ) . constData ( ) ) ;
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-09-27 17:05:52 -04:00
MessageComposer : : msgFriend ( id , ( peer - > type ( ) = = TYPE_GROUP ) ) ;
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
{
2010-08-28 15:50:38 -04:00
QTreeWidgetItem * c = getCurrentPeer ( ) ;
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2010-08-28 15:50:38 -04:00
std : : cerr < < " PeersDialog::connectfriend() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2010-08-28 15:50:38 -04:00
if ( ! c )
{
2009-07-13 15:58:11 -04:00
# ifdef PEERS_DEBUG
2010-08-28 15:50:38 -04:00
std : : cerr < < " PeersDialog::connectfriend() Noone Selected -- sorry " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2010-08-28 15:50:38 -04:00
return ;
}
2008-04-07 18:54:15 -04:00
2010-08-28 15:50:38 -04:00
if ( rsPeers )
{
2010-09-22 18:37:57 -04:00
if ( c - > type ( ) = = TYPE_GPG ) {
2010-08-28 15:50:38 -04:00
int childCount = c - > childCount ( ) ;
for ( int childIndex = 0 ; childIndex < childCount ; childIndex + + ) {
QTreeWidgetItem * item = c - > child ( childIndex ) ;
2010-09-22 18:37:57 -04:00
if ( item - > type ( ) = = TYPE_SSL ) {
2010-08-28 15:50:38 -04:00
rsPeers - > connectAttempt ( getPeerRsCertId ( item ) ) ;
item - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_CONNECT2 ) ) ) ;
}
}
} else {
//this is a SSL key
rsPeers - > connectAttempt ( getPeerRsCertId ( c ) ) ;
c - > setIcon ( COLUMN_NAME , ( QIcon ( IMAGE_CONNECT2 ) ) ) ;
}
}
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
{
2010-10-25 16:19:57 -04:00
ConfCertDialog : : showIt ( getPeerRsCertId ( getCurrentPeer ( ) ) , ConfCertDialog : : PageDetails ) ;
2007-11-14 22:18:48 -05:00
}
2010-09-29 15:30:59 -04:00
void PeersDialog : : addFriend ( )
{
std : : string groupId ;
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c & & c - > type ( ) = = TYPE_GROUP ) {
groupId = c - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
}
ConnectFriendWizard connwiz ( this ) ;
if ( groupId . empty ( ) = = false ) {
connwiz . setGroup ( groupId ) ;
}
connwiz . exec ( ) ;
}
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 ( )
{
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
{
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog: sending group chat typing info. " < < std : : endl ;
# 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
//
2010-08-30 14:33:19 -04:00
void PeersDialog : : updateStatusString ( const QString & peer_id , const QString & status_string )
2009-09-30 18:30:57 -04:00
{
2010-08-30 14:33:19 -04:00
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog: received group chat typing info. updating gui. " < < std : : endl ;
# endif
2009-09-30 18:30:57 -04:00
2010-08-30 14:33:19 -04:00
QString status = QString : : fromStdString ( rsPeers - > getPeerName ( peer_id . toStdString ( ) ) ) + " " + tr ( status_string . toAscii ( ) ) ;
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
}
2009-09-30 16:53:18 -04:00
void PeersDialog : : updatePeersAvatar ( const QString & peer_id )
{
2010-09-01 13:56:15 -04:00
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog: Got notified of new avatar for peer " < < peer_id . toStdString ( ) < < std : : endl ;
# endif
2009-09-30 16:53:18 -04:00
2010-09-01 13:56:15 -04:00
PopupChatDialog * pcd = PopupChatDialog : : getPrivateChat ( peer_id . toStdString ( ) , 0 ) ;
if ( pcd ) {
pcd - > updatePeerAvatar ( peer_id . toStdString ( ) ) ;
}
2009-09-30 16:53:18 -04:00
}
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
{
2010-08-30 14:33:19 -04:00
if ( is_private_chat )
{
2010-11-13 16:53:06 -05:00
PopupChatDialog * pcd = PopupChatDialog : : getExistingInstance ( peer_id . toStdString ( ) ) ;
2010-09-01 13:56:15 -04:00
if ( pcd ) {
pcd - > updateStatusString ( peer_id , status_string ) ;
}
2010-08-30 14:33:19 -04:00
}
else
{
# ifdef PEERS_DEBUG
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
2010-09-01 13:56:15 -04:00
void PeersDialog : : publicChatChanged ( int type )
{
if ( type = = NOTIFY_TYPE_ADD ) {
insertChat ( ) ;
}
}
2010-10-03 06:08:58 -04:00
void PeersDialog : : addChatMsg ( bool incoming , bool history , QString & name , QDateTime & recvTime , QString & message )
2010-09-04 10:23:30 -04:00
{
unsigned int formatFlag = CHAT_FORMATMSG_EMBED_LINKS ;
// embed smileys ?
if ( Settings - > valueFromGroup ( QString ( " Chat " ) , QString : : fromUtf8 ( " Emoteicons_GroupChat " ) , true ) . toBool ( ) ) {
formatFlag | = CHAT_FORMATMSG_EMBED_SMILEYS ;
}
ChatStyle : : enumFormatMessage type ;
if ( incoming ) {
if ( history ) {
type = ChatStyle : : FORMATMSG_HINCOMING ;
} else {
type = ChatStyle : : FORMATMSG_INCOMING ;
}
} else {
if ( history ) {
type = ChatStyle : : FORMATMSG_HOUTGOING ;
} else {
type = ChatStyle : : FORMATMSG_OUTGOING ;
}
}
2010-10-03 06:08:58 -04:00
QString formatMsg = style . formatMessage ( type , name , recvTime , message , formatFlag ) ;
2010-09-04 10:23:30 -04:00
ui . msgText - > append ( formatMsg ) ;
}
2008-07-10 06:34:49 -04:00
void PeersDialog : : insertChat ( )
{
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
{
# ifdef PEERS_DEBUG
std : : cerr < < " no chat available. " < < std : : endl ;
# endif
return ;
}
# ifdef PEERS_DEBUG
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 ) ;
2010-09-04 10:23:30 -04:00
QString name = QString : : fromStdString ( rsPeers - > getPeerName ( it - > rsid ) ) ;
QString msg = QString : : fromStdWString ( it - > msg ) ;
2008-07-10 06:34:49 -04:00
2010-09-04 10:23:30 -04:00
# ifdef PEERS_DEBUG
std : : cerr < < " PeersDialog::insertChat(): " < < msg < < std : : endl ;
# 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
2010-10-03 06:08:58 -04:00
historyKeeper . addMessage ( incoming , it - > rsid , name , sendTime , recvTime , msg ) ;
addChatMsg ( incoming , false , name , recvTime , msg ) ;
2010-08-31 13:13:52 -04:00
}
2008-07-10 06:34:49 -04:00
}
2010-09-04 10:23:30 -04:00
bool PeersDialog : : 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
}
void PeersDialog : : sendMsg ( )
{
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
2010-09-04 10:23:30 -04:00
std : : wstring message = lineWidget - > toHtml ( ) . toStdWString ( ) ;
2009-07-13 15:58:11 -04:00
2010-09-01 13:56:15 -04:00
# ifdef PEERS_DEBUG
std : : string msg ( ci . msg . begin ( ) , ci . msg . end ( ) ) ;
std : : cerr < < " PeersDialog::sendMsg(): " < < msg < < std : : endl ;
# endif
2008-07-10 06:34:49 -04:00
2010-09-01 13:56:15 -04:00
rsMsgs - > sendPublicChat ( message ) ;
ui . lineEdit - > clear ( ) ;
2010-10-07 20:07:44 -04:00
// workaround for Qt bug - http://bugreports.qt.nokia.com/browse/QTBUG-2533
// QTextEdit::clear() does not reset the CharFormat if document contains hyperlinks that have been accessed.
ui . lineEdit - > setCurrentCharFormat ( QTextCharFormat ( ) ) ;
2010-09-01 13:56:15 -04:00
setFont ( ) ;
2008-07-10 06:34:49 -04:00
2010-09-01 13:56:15 -04:00
/* redraw send list */
insertSendList ( ) ;
2008-07-10 06:34:49 -04:00
}
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 */
2010-09-24 07:38:46 -04:00
//void PeersDialog::toggleSendItem( QTreeWidgetItem *item, int col )
//{
// #ifdef PEERS_DEBUG
// std::cerr << "ToggleSendItem()" << std::endl;
// #endif
//
// /* 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
//============================================================================
2008-07-10 06:34:49 -04:00
void PeersDialog : : setColor ( )
{
2010-10-07 20:07:44 -04:00
bool ok ;
QRgb color = QColorDialog : : getRgba ( ui . lineEdit - > textColor ( ) . rgba ( ) , & ok , this ) ;
if ( ok ) {
mCurrentColor = QColor ( color ) ;
colorChanged ( mCurrentColor ) ;
}
setFont ( ) ;
}
2009-07-13 15:58:11 -04:00
2010-10-07 20:07:44 -04:00
void PeersDialog : : colorChanged ( const QColor & c )
{
QPixmap pxm ( 16 , 16 ) ;
pxm . fill ( mCurrentColor ) ;
ui . colorChatButton - > setIcon ( pxm ) ;
2008-07-10 06:34:49 -04:00
}
void PeersDialog : : getFont ( )
{
bool ok ;
mCurrentFont = QFontDialog : : getFont ( & ok , mCurrentFont , this ) ;
2010-10-07 20:07:44 -04:00
if ( ok ) {
fontChanged ( mCurrentFont ) ;
}
2008-07-10 06:34:49 -04:00
}
2010-10-07 20:07:44 -04:00
void PeersDialog : : fontChanged ( const QFont & font )
2008-07-10 06:34:49 -04:00
{
2010-10-07 20:07:44 -04:00
mCurrentFont = font ;
2008-07-10 06:34:49 -04:00
2010-10-07 20:07:44 -04:00
ui . textboldChatButton - > setChecked ( mCurrentFont . bold ( ) ) ;
ui . textunderlineChatButton - > setChecked ( mCurrentFont . underline ( ) ) ;
ui . textitalicChatButton - > setChecked ( mCurrentFont . italic ( ) ) ;
2009-07-13 15:58:11 -04:00
2010-10-07 20:07:44 -04:00
setFont ( ) ;
2008-07-10 06:34:49 -04:00
}
2010-10-07 20:07:44 -04:00
void PeersDialog : : setFont ( )
2008-11-24 09:07:26 -05:00
{
2010-10-07 20:07:44 -04:00
mCurrentFont . setBold ( ui . textboldChatButton - > isChecked ( ) ) ;
mCurrentFont . setUnderline ( ui . textunderlineChatButton - > isChecked ( ) ) ;
mCurrentFont . setItalic ( ui . textitalicChatButton - > isChecked ( ) ) ;
ui . lineEdit - > setFont ( mCurrentFont ) ;
ui . lineEdit - > setTextColor ( mCurrentColor ) ;
Settings - > setChatScreenFont ( mCurrentFont . toString ( ) ) ;
2009-07-13 15:58:11 -04:00
2010-10-07 20:07:44 -04:00
ui . lineEdit - > setFocus ( ) ;
}
2008-07-10 06:34:49 -04:00
2008-11-24 09:07:26 -05:00
// Update Chat Info information
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> " ) ) ;
}
2011-02-08 16:59:17 -05:00
void PeersDialog : : 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-02-08 16:59:17 -05:00
void PeersDialog : : on_actionDelete_Chat_History_triggered ( )
{
on_actionClear_Chat_History_triggered ( ) ;
historyKeeper . clear ( ) ;
}
2008-07-10 06:34:49 -04:00
void PeersDialog : : 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
}
2008-07-10 06:34:49 -04:00
void PeersDialog : : addSmileys ( )
{
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
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-12-02 19:54:40 -05:00
QString fileName ;
if ( misc : : getOpenFileName ( this , RshareSettings : : LASTDIR_IMAGES , tr ( " Load File " ) , tr ( " Pictures (*.png *.xpm *.jpg *.tiff *.gif) " ) , fileName ) )
2009-09-02 18:42:31 -04:00
{
2010-05-14 07:17:19 -04:00
QPixmap picture ;
2010-08-30 11:43:07 -04:00
picture = QPixmap ( fileName ) . scaled ( 96 , 96 , 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
}
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 . 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-11-24 14:25:53 -05:00
ui . mypersonalstatuslabel - > setText ( QString : : fromUtf8 ( rsMsgs - > getCustomStateString ( ) . c_str ( ) ) ) ;
2009-09-29 18:52:46 -04:00
}
2009-10-08 15:08:44 -04:00
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 ( )
{
2010-12-02 19:54:40 -05:00
QString file ;
if ( misc : : getOpenFileName ( this , RshareSettings : : LASTDIR_EXTRAFILE , tr ( " Add Extra File " ) , " " , file ) ) {
addAttachment ( file . toUtf8 ( ) . constData ( ) ) ;
}
2010-01-31 17:29:30 -05:00
}
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 * ) ) ) ;
}
}
2010-09-01 13:56:15 -04:00
void PeersDialog : : fileHashingFinished ( AttachFileItem * file )
{
std : : cerr < < " PeersDialog::fileHashingFinished() started. " < < std : : endl ;
2010-03-17 11:34:36 -04:00
2010-09-01 13:56:15 -04:00
//check that the file is ok tos end
if ( file - > getState ( ) = = AFI_STATE_ERROR ) {
2010-03-17 11:34:36 -04:00
# ifdef PEERS_DEBUG
2010-09-01 13:56:15 -04:00
std : : cerr < < " PopupChatDialog::fileHashingFinished error file is not hashed. " < < std : : endl ;
2010-03-17 11:34:36 -04:00
# endif
2010-09-01 13:56:15 -04:00
return ;
}
2010-01-31 17:29:30 -05:00
2010-09-01 13:56:15 -04:00
//convert fileSize from uint_64 to string for html link
// char fileSizeChar [100];
// sprintf(fileSizeChar, "%lld", file->FileSize());
// std::string fileSize = *(&fileSizeChar);
2010-01-31 17:29:30 -05:00
2010-11-19 20:40:24 -05:00
QString mesgString = RetroShareLink ( QString : : fromUtf8 ( file - > FileName ( ) . c_str ( ) ) ,
file - > FileSize ( ) ,
QString : : fromStdString ( file - > FileHash ( ) ) ) . toHtmlSize ( ) ;
2010-01-31 17:29:30 -05:00
2010-09-01 13:56:15 -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
2010-11-19 20:40:24 -05:00
/* convert to real html document */
QTextBrowser textBrowser ;
textBrowser . setHtml ( mesgString ) ;
std : : wstring msg = textBrowser . toHtml ( ) . toStdWString ( ) ;
rsMsgs - > sendPublicChat ( msg ) ;
2010-09-01 13:56:15 -04:00
setFont ( ) ;
2010-01-31 17:29:30 -05:00
}
void PeersDialog : : dropEvent ( QDropEvent * event )
{
2010-09-17 17:54:25 -04:00
if ( ! ( Qt : : CopyAction & event - > possibleActions ( ) ) )
{
std : : cerr < < " PeersDialog::dropEvent() Rejecting uncopyable DropAction " < < std : : endl ;
2010-01-31 17:29:30 -05:00
2010-09-17 17:54:25 -04:00
/* can't do it */
return ;
}
2010-01-31 17:29:30 -05:00
2010-09-17 17:54:25 -04:00
std : : cerr < < " PeersDialog::dropEvent() Formats " < < std : : endl ;
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; it + + )
{
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) < < std : : endl ;
}
2010-01-31 17:29:30 -05:00
2010-09-17 17:54:25 -04:00
if ( event - > mimeData ( ) - > hasUrls ( ) )
{
std : : cerr < < " PeersDialog::dropEvent() Urls: " < < std : : endl ;
2010-01-31 17:29:30 -05:00
2010-09-17 17:54:25 -04:00
QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
QList < QUrl > : : iterator uit ;
for ( uit = urls . begin ( ) ; uit ! = urls . end ( ) ; uit + + )
{
QString localpath = uit - > toLocalFile ( ) ;
std : : cerr < < " Whole URL: " < < uit - > toString ( ) . toStdString ( ) < < std : : endl ;
std : : cerr < < " or As Local File: " < < localpath . toStdString ( ) < < std : : endl ;
if ( localpath . isEmpty ( ) = = false )
{
//Check that the file does exist and is not a directory
QDir dir ( localpath ) ;
if ( dir . exists ( ) ) {
std : : cerr < < " PeersDialog::dropEvent() directory not accepted. " < < std : : endl ;
2010-11-16 04:31:30 -05:00
QMessageBox mb ( tr ( " Drop file error. " ) , tr ( " Directory can't be dropped, only files are accepted. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 , this ) ;
2010-09-17 17:54:25 -04:00
mb . exec ( ) ;
} else if ( QFile : : exists ( localpath ) ) {
PeersDialog : : addAttachment ( localpath . toUtf8 ( ) . constData ( ) ) ;
} else {
std : : cerr < < " PeersDialog::dropEvent() file does not exists. " < < std : : endl ;
2010-11-16 04:31:30 -05:00
QMessageBox mb ( tr ( " Drop file error. " ) , tr ( " File not found or file name not accepted. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 , this ) ;
2010-09-17 17:54:25 -04:00
mb . exec ( ) ;
}
}
}
}
2010-01-31 17:29:30 -05:00
2010-09-17 17:54:25 -04:00
event - > setDropAction ( Qt : : CopyAction ) ;
event - > accept ( ) ;
2010-01-31 17:29:30 -05:00
}
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 ( )
{
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
}
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 ( ) ;
2010-12-15 16:32:44 -05:00
displaymenu - > addAction ( ui . actionSort_Peers_Descending_Order ) ;
displaymenu - > addAction ( ui . actionSort_Peers_Ascending_Order ) ;
2010-06-18 17:59:33 -04:00
displaymenu - > addAction ( ui . action_Hide_Offline_Friends ) ;
2010-12-15 16:32:44 -05:00
displaymenu - > addAction ( ui . action_Sort_by_State ) ;
2010-12-17 20:45:32 -05:00
displaymenu - > addAction ( ui . action_Hide_Status_Column ) ;
2010-12-15 16:32:44 -05:00
displaymenu - > addAction ( ui . action_Hide_State ) ;
2010-06-18 17:59:33 -04:00
ui . displayButton - > setMenu ( displaymenu ) ;
}
2010-12-17 20:45:32 -05:00
void PeersDialog : : setStateColumn ( )
2010-06-18 17:59:33 -04:00
{
2010-12-17 20:45:32 -05:00
if ( ui . action_Hide_Status_Column - > isChecked ( ) ) {
ui . peertreeWidget - > setColumnHidden ( COLUMN_STATE , true ) ;
ui . peertreeWidget - > setHeaderHidden ( true ) ;
ui . action_Hide_State - > setEnabled ( true ) ;
wasStatusColumnHidden = true ;
} else {
ui . peertreeWidget - > setColumnHidden ( COLUMN_STATE , false ) ;
ui . peertreeWidget - > setHeaderHidden ( false ) ;
ui . action_Hide_State - > setEnabled ( false ) ;
2010-12-18 16:30:24 -05:00
if ( correctColumnStatusSize ) {
correctColumnStatusSize = false ;
ui . peertreeWidget - > header ( ) - > resizeSection ( COLUMN_STATE , 100 ) ;
}
2010-12-17 20:45:32 -05:00
if ( wasStatusColumnHidden ) {
ui . peertreeWidget - > header ( ) - > resizeSection ( COLUMN_NAME , ui . peertreeWidget - > header ( ) - > sectionSize ( COLUMN_NAME ) - ui . peertreeWidget - > header ( ) - > sectionSize ( COLUMN_STATE ) ) ;
}
wasStatusColumnHidden = false ;
}
2010-12-15 16:32:44 -05:00
if ( ui . action_Sort_by_State - > isChecked ( ) ) {
2010-12-17 20:45:32 -05:00
ui . peertreeWidget - > sortByColumn ( COLUMN_STATE ) ;
2010-12-15 16:32:44 -05:00
} else {
2010-12-17 20:45:32 -05:00
ui . peertreeWidget - > sortByColumn ( COLUMN_NAME ) ;
2010-06-18 17:59:33 -04:00
}
2010-12-15 16:32:44 -05:00
}
void PeersDialog : : sortPeersAscendingOrder ( )
{
2010-12-17 20:45:32 -05:00
ui . peertreeWidget - > sortByColumn ( ui . peertreeWidget - > sortColumn ( ) , Qt : : AscendingOrder ) ;
2010-12-15 16:32:44 -05:00
}
void PeersDialog : : sortPeersDescendingOrder ( )
{
2010-12-17 20:45:32 -05:00
ui . peertreeWidget - > sortByColumn ( ui . peertreeWidget - > sortColumn ( ) , Qt : : DescendingOrder ) ;
}
void PeersDialog : : peerSortIndicatorChanged ( int column , Qt : : SortOrder )
{
ui . action_Sort_by_State - > setChecked ( column = = COLUMN_STATE ) ;
2010-06-18 17:59:33 -04:00
}
2010-09-01 10:15:50 -04:00
void PeersDialog : : on_actionMessageHistory_triggered ( )
{
2010-10-02 18:42:30 -04:00
ImHistoryBrowser imBrowser ( " " , historyKeeper , ui . lineEdit , this ) ;
2010-09-01 10:15:50 -04:00
imBrowser . exec ( ) ;
}
2010-09-21 12:11:19 -04:00
void PeersDialog : : on_actionAdd_Group_activated ( )
{
2010-09-22 18:37:57 -04:00
CreateGroup createGrpDialog ( " " , this ) ;
2010-09-21 12:11:19 -04:00
createGrpDialog . exec ( ) ;
}
2010-09-22 18:37:57 -04:00
void PeersDialog : : addToGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GPG ) {
// wrong type
return ;
}
std : : string groupId = qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toStdString ( ) ;
std : : string gpgId = c - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
if ( gpgId . empty ( ) | | groupId . empty ( ) ) {
return ;
}
// add to group
rsPeers - > assignPeerToGroup ( groupId , gpgId , true ) ;
}
void PeersDialog : : moveToGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GPG ) {
// wrong type
return ;
}
std : : string groupId = qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toStdString ( ) ;
std : : string gpgId = c - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
if ( gpgId . empty ( ) | | groupId . empty ( ) ) {
return ;
}
// remove from all groups
rsPeers - > assignPeerToGroup ( " " , gpgId , false ) ;
// add to group
rsPeers - > assignPeerToGroup ( groupId , gpgId , true ) ;
}
void PeersDialog : : removeFromGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GPG ) {
// wrong type
return ;
}
std : : string groupId = qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toStdString ( ) ;
std : : string gpgId = c - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
if ( gpgId . empty ( ) ) {
return ;
}
// remove from (all) group(s)
rsPeers - > assignPeerToGroup ( groupId , gpgId , false ) ;
}
2010-09-23 14:49:52 -04:00
void PeersDialog : : editGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GROUP ) {
// wrong type
return ;
}
std : : string groupId = c - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
if ( groupId . empty ( ) ) {
return ;
}
CreateGroup editGrpDialog ( groupId , this ) ;
editGrpDialog . exec ( ) ;
}
2010-09-22 18:37:57 -04:00
void PeersDialog : : removeGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GROUP ) {
// wrong type
return ;
}
std : : string groupId = c - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
if ( groupId . empty ( ) ) {
return ;
}
rsPeers - > removeGroup ( groupId ) ;
}
void PeersDialog : : groupsChanged ( int type )
{
Q_UNUSED ( type ) ;
groupsHasChanged = true ;
}
2010-11-10 07:24:36 -05:00
void PeersDialog : : newsFeedChanged ( int count )
{
if ( count ) {
ui . peertabWidget - > tabBar ( ) - > setTabText ( newsFeedTabIndex , QString ( " %1 (%2) " ) . arg ( newsFeedText ) . arg ( count ) ) ;
ui . peertabWidget - > tabBar ( ) - > setTabTextColor ( newsFeedTabIndex , Qt : : blue ) ;
ui . peertabWidget - > tabBar ( ) - > setTabIcon ( newsFeedTabIndex , QIcon ( IMAGE_NEWSFEED_NEW ) ) ;
} else {
ui . peertabWidget - > tabBar ( ) - > setTabText ( newsFeedTabIndex , newsFeedText ) ;
ui . peertabWidget - > tabBar ( ) - > setTabTextColor ( newsFeedTabIndex , newsFeedTabColor ) ;
ui . peertabWidget - > tabBar ( ) - > setTabIcon ( newsFeedTabIndex , QIcon ( IMAGE_NEWSFEED ) ) ;
}
}
2010-11-25 11:45:44 -05:00
void PeersDialog : : updateOwnStatus ( const QString & peer_id , int status )
{
// add self nick + own status
if ( peer_id . toStdString ( ) = = rsPeers - > getOwnId ( ) )
{
// my status has changed
switch ( status ) {
case RS_STATUS_OFFLINE :
ui . avatartoolButton - > setStyleSheet ( " QToolButton#avatartoolButton{border-image:url(:/images/mystatus_bg_offline.png); } " ) ;
break ;
case RS_STATUS_INACTIVE :
ui . avatartoolButton - > setStyleSheet ( " QToolButton#avatartoolButton{border-image:url(:/images/mystatus_bg_idle.png); } " ) ;
break ;
case RS_STATUS_ONLINE :
ui . avatartoolButton - > setStyleSheet ( " QToolButton#avatartoolButton{border-image:url(:/images/mystatus_bg_online.png); } " ) ;
break ;
case RS_STATUS_AWAY :
ui . avatartoolButton - > setStyleSheet ( " QToolButton#avatartoolButton{border-image:url(:/images/mystatus_bg_idle.png); } " ) ;
break ;
case RS_STATUS_BUSY :
ui . avatartoolButton - > setStyleSheet ( " QToolButton#avatartoolButton{border-image:url(:/images/mystatus_bg_busy.png); } " ) ;
break ;
}
return ;
}
}