2007-11-14 22:18:48 -05:00
|
|
|
|
/****************************************************************
|
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006,2007 crypton
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2009-07-13 15:58:11 -04:00
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2007-11-14 22:18:48 -05:00
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-11-24 09:07:26 -05:00
|
|
|
|
****************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
#include <QFile>
|
2007-11-14 22:18:48 -05:00
|
|
|
|
#include <QFileInfo>
|
2008-11-24 09:07:26 -05:00
|
|
|
|
#include "common/vmessagebox.h"
|
|
|
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
|
#include "PeersDialog.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
#include "rsiface/rsiface.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
|
#include "rsiface/rspeers.h"
|
2008-04-28 08:09:26 -04:00
|
|
|
|
#include "rsiface/rsstatus.h"
|
2008-07-10 06:34:49 -04:00
|
|
|
|
#include "rsiface/rsmsgs.h"
|
2008-12-07 09:19:13 -05:00
|
|
|
|
#include "rsiface/rsnotify.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
#include "chat/PopupChatDialog.h"
|
|
|
|
|
#include "msgs/ChanMsgDialog.h"
|
|
|
|
|
#include "connect/ConfCertDialog.h"
|
2009-01-22 20:58:56 -05:00
|
|
|
|
#include "profile/ProfileView.h"
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2008-12-07 09:19:13 -05:00
|
|
|
|
#include "gui/Preferences/rsharesettings.h"
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
#include <QTextEdit>
|
|
|
|
|
#include <QTextCursor>
|
2008-07-10 06:34:49 -04:00
|
|
|
|
#include <QTextList>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QTextDocumentFragment>
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QCursor>
|
|
|
|
|
#include <QPoint>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QHeaderView>
|
2008-07-10 06:34:49 -04:00
|
|
|
|
#include <QtGui/QKeyEvent>
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
/* Images for context menu icons */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
#define IMAGE_REMOVEFRIEND ":/images/removefriend16.png"
|
|
|
|
|
#define IMAGE_EXPIORTFRIEND ":/images/exportpeers_16x16.png"
|
2008-04-07 20:31:46 -04:00
|
|
|
|
#define IMAGE_PEERINFO ":/images/peerdetails_16x16.png"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
#define IMAGE_CHAT ":/images/chat.png"
|
2008-04-03 17:32:45 -04:00
|
|
|
|
#define IMAGE_MSG ":/images/message-mail.png"
|
2009-01-22 20:58:56 -05:00
|
|
|
|
#define IMAGE_CONNECT ":/images/connect_friend.png"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* Images for Status icons */
|
2008-07-10 06:34:49 -04:00
|
|
|
|
#define IMAGE_ONLINE ":/images/user/identity24.png"
|
2008-07-11 11:51:49 -04:00
|
|
|
|
#define IMAGE_OFFLINE ":/images/user/identityoffline24.png"
|
2008-11-24 09:07:26 -05:00
|
|
|
|
#define IMAGE_OFFLINE2 ":/images/user/identitylightgrey24.png"
|
2009-04-29 11:48:01 -04:00
|
|
|
|
#define IMAGE_AVAIBLE ":/images/user/identityavaiblecyan24.png"
|
|
|
|
|
#define IMAGE_CONNECT2 ":/images/reload24.png"
|
2008-11-24 09:07:26 -05: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)
|
2009-03-12 10:14:55 -04:00
|
|
|
|
: MainPage(parent),
|
|
|
|
|
historyKeeper(Rshare::dataDirectory() + "/his1.xml")
|
2008-11-24 09:07:26 -05:00
|
|
|
|
{
|
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
|
|
connect( ui.peertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( peertreeWidgetCostumPopupMenu( QPoint ) ) );
|
2009-01-01 18:25:16 -05:00
|
|
|
|
connect( ui.peertreeWidget, SIGNAL( itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2009-09-02 18:42:31 -04:00
|
|
|
|
connect( ui.avatartoolButton, SIGNAL(clicked()), SLOT(getAvatar()));
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* hide the Tree +/- */
|
|
|
|
|
ui.peertreeWidget -> setRootIsDecorated( false );
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* Set header resize modes and initial section sizes */
|
2008-11-24 09:07:26 -05:00
|
|
|
|
QHeaderView * _header = ui.peertreeWidget->header () ;
|
|
|
|
|
_header->setResizeMode (0, QHeaderView::Custom);
|
|
|
|
|
_header->setResizeMode (1, QHeaderView::Interactive);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
_header->setResizeMode (2, QHeaderView::Interactive);
|
2008-11-24 09:07:26 -05:00
|
|
|
|
/*_header->setResizeMode (3, QHeaderView::Interactive);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
_header->setResizeMode (4, QHeaderView::Interactive);
|
2008-11-24 09:07:26 -05:00
|
|
|
|
_header->setResizeMode (5, QHeaderView::Interactive);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
_header->setResizeMode (6, QHeaderView::Interactive);
|
2008-11-24 09:07:26 -05:00
|
|
|
|
_header->setResizeMode (7, QHeaderView::Interactive);*/
|
|
|
|
|
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
_header->resizeSection ( 0, 25 );
|
|
|
|
|
_header->resizeSection ( 1, 100 );
|
|
|
|
|
_header->resizeSection ( 2, 100 );
|
2008-07-10 06:34:49 -04:00
|
|
|
|
/*_header->resizeSection ( 3, 120 );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
_header->resizeSection ( 4, 100 );
|
2008-03-20 21:03:27 -04:00
|
|
|
|
_header->resizeSection ( 5, 230 );
|
2008-04-03 17:32:45 -04:00
|
|
|
|
_header->resizeSection ( 6, 120 );
|
2008-07-10 06:34:49 -04:00
|
|
|
|
_header->resizeSection ( 7, 220 );*/
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-12 07:57:09 -04:00
|
|
|
|
// set header text aligment
|
|
|
|
|
QTreeWidgetItem * headerItem = ui.peertreeWidget->headerItem();
|
|
|
|
|
headerItem->setTextAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
headerItem->setTextAlignment(1, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
headerItem->setTextAlignment(2, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
loadEmoticonsgroupchat();
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-02-09 09:09:25 -05:00
|
|
|
|
//setWindowIcon(QIcon(QString(":/images/rstray3.png")));
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
|
|
|
|
connect(ui.lineEdit, SIGNAL(textChanged ( ) ), this, SLOT(checkChat( ) ));
|
|
|
|
|
connect(ui.Sendbtn, SIGNAL(clicked()), this, SLOT(sendMsg()));
|
2008-11-24 09:07:26 -05:00
|
|
|
|
connect(ui.emoticonBtn, SIGNAL(clicked()), this, SLOT(smileyWidgetgroupchat()));
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
//connect( ui.msgSendList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgSendListCostumPopupMenu( QPoint ) ) );
|
|
|
|
|
connect( ui.msgText, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoChatMenu(const QPoint&)));
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
|
|
|
|
connect(ui.textboldChatButton, SIGNAL(clicked()), this, SLOT(setFont()));
|
|
|
|
|
connect(ui.textunderlineChatButton, SIGNAL(clicked()), this, SLOT(setFont()));
|
2008-07-10 06:34:49 -04:00
|
|
|
|
connect(ui.textitalicChatButton, SIGNAL(clicked()), this, SLOT(setFont()));
|
2009-07-13 15:58:11 -04:00
|
|
|
|
connect(ui.fontsButton, SIGNAL(clicked()), this, SLOT(getFont()));
|
2008-07-10 06:34:49 -04:00
|
|
|
|
connect(ui.colorChatButton, SIGNAL(clicked()), this, SLOT(setColor()));
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
ui.fontsButton->setIcon(QIcon(QString(":/images/fonts.png")));
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
_currentColor = Qt::black;
|
2009-01-22 20:58:56 -05:00
|
|
|
|
QPixmap pxm(16,16);
|
2008-07-10 06:34:49 -04:00
|
|
|
|
pxm.fill(_currentColor);
|
|
|
|
|
ui.colorChatButton->setIcon(pxm);
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
mCurrentFont = QFont("Comic Sans MS", 12);
|
|
|
|
|
ui.lineEdit->setFont(mCurrentFont);
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-03-12 10:14:55 -04:00
|
|
|
|
setChatInfo(tr("Welcome to RetroShare's group chat."),
|
|
|
|
|
QString::fromUtf8("blue"));
|
|
|
|
|
|
|
|
|
|
QStringList him;
|
|
|
|
|
historyKeeper.getMessages(him, "", "THIS", 8);
|
|
|
|
|
foreach(QString mess, him)
|
|
|
|
|
ui.msgText->append(mess);
|
|
|
|
|
//setChatInfo(mess, "green");
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
QMenu * grpchatmenu = new QMenu();
|
2008-07-10 06:34:49 -04:00
|
|
|
|
grpchatmenu->addAction(ui.actionClearChat);
|
|
|
|
|
ui.menuButton->setMenu(grpchatmenu);
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
_underline = false;
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
|
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
|
timer->connect(timer, SIGNAL(timeout()), this, SLOT(insertChat()));
|
|
|
|
|
timer->start(500); /* half a second */
|
2008-03-20 21:03:27 -04:00
|
|
|
|
|
2009-09-02 18:42:31 -04:00
|
|
|
|
ui.peertreeWidget->sortItems( 1, Qt::AscendingOrder );
|
|
|
|
|
|
|
|
|
|
updateAvatar();
|
2008-11-24 09:07:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Hide platform specific features */
|
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
QMenu contextMnu( this );
|
|
|
|
|
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
|
|
|
|
|
|
|
|
|
chatAct = new QAction(QIcon(IMAGE_CHAT), tr( "Chat" ), this );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
connect( chatAct , SIGNAL( triggered() ), this, SLOT( chatfriend() ) );
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
msgAct = new QAction(QIcon(IMAGE_MSG), tr( "Message Friend" ), this );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
connect( msgAct , SIGNAL( triggered() ), this, SLOT( msgfriend() ) );
|
|
|
|
|
|
2009-01-22 20:58:56 -05:00
|
|
|
|
connectfriendAct = new QAction(QIcon(IMAGE_CONNECT), tr( "Connect To Friend" ), this );
|
2008-11-24 09:07:26 -05:00
|
|
|
|
connect( connectfriendAct , SIGNAL( triggered() ), this, SLOT( connectfriend() ) );
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
configurefriendAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Peer Details" ), this );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
connect( configurefriendAct , SIGNAL( triggered() ), this, SLOT( configurefriend() ) );
|
2009-01-22 20:58:56 -05:00
|
|
|
|
|
|
|
|
|
profileviewAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Profile View" ), this );
|
|
|
|
|
connect( profileviewAct , SIGNAL( triggered() ), this, SLOT( viewprofile() ) );
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
exportfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Export Friend" ), this );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
connect( exportfriendAct , SIGNAL( triggered() ), this, SLOT( exportfriend() ) );
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-05-15 08:07:37 -04:00
|
|
|
|
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Deny Friend" ), this );
|
2008-11-24 09:07:26 -05:00
|
|
|
|
connect( removefriendAct , SIGNAL( triggered() ), this, SLOT( removefriend() ) );
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
contextMnu.clear();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
contextMnu.addAction( chatAct);
|
|
|
|
|
contextMnu.addAction( msgAct);
|
2009-07-13 15:58:11 -04:00
|
|
|
|
contextMnu.addSeparator();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
contextMnu.addAction( configurefriendAct);
|
2009-01-22 20:58:56 -05:00
|
|
|
|
//contextMnu.addAction( profileviewAct);
|
2008-04-07 20:31:46 -04:00
|
|
|
|
contextMnu.addSeparator();
|
2009-07-13 15:58:11 -04:00
|
|
|
|
contextMnu.addAction( connectfriendAct);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
contextMnu.addAction( exportfriendAct);
|
2008-11-24 09:07:26 -05:00
|
|
|
|
contextMnu.addAction( removefriendAct);
|
|
|
|
|
contextMnu.exec( mevent->globalPos() );
|
2009-09-02 18:42:31 -04:00
|
|
|
|
|
|
|
|
|
updateAvatar();
|
2008-11-24 09:07:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* get the list of peers from the RsIface. */
|
|
|
|
|
void PeersDialog::insertPeers()
|
|
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
|
std::list<std::string> peers;
|
|
|
|
|
std::list<std::string>::iterator it;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
|
if (!rsPeers)
|
|
|
|
|
{
|
|
|
|
|
/* not ready yet! */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rsPeers->getFriendList(peers);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
/* get a link to the table */
|
|
|
|
|
QTreeWidget *peerWidget = ui.peertreeWidget;
|
|
|
|
|
QTreeWidgetItem *oldSelect = getCurrentPeer();
|
|
|
|
|
QTreeWidgetItem *newSelect = NULL;
|
2008-03-02 09:25:59 -05:00
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
std::string oldId;
|
|
|
|
|
if (oldSelect)
|
|
|
|
|
{
|
2008-03-20 21:03:27 -04:00
|
|
|
|
oldId = (oldSelect -> text(7)).toStdString();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remove old items ??? */
|
|
|
|
|
peerWidget->clear();
|
2008-07-10 06:34:49 -04:00
|
|
|
|
peerWidget->setColumnCount(3);
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-09-02 18:42:31 -04:00
|
|
|
|
// add self nick and Avatar to Friends.
|
|
|
|
|
RsPeerDetails pd ;
|
|
|
|
|
|
|
|
|
|
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),pd))
|
|
|
|
|
{
|
|
|
|
|
QString titleStr("<span style=\"font-size:16pt; font-weight:500;"
|
|
|
|
|
"color:#32cd32;\">%1</span>");
|
|
|
|
|
ui.nicklabel->setText(titleStr.arg(QString::fromStdString(pd.name) + tr(" (me)"))) ;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> items;
|
2008-01-25 03:49:40 -05:00
|
|
|
|
for(it = peers.begin(); it != peers.end(); it++)
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
|
RsPeerDetails detail;
|
|
|
|
|
if (!rsPeers->getPeerDetails(*it, detail))
|
|
|
|
|
{
|
|
|
|
|
continue; /* BAD */
|
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* make a widget per friend */
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
|
|
|
|
|
|
|
|
|
|
/* add all the labels */
|
|
|
|
|
/* First 5 (1-5) Key Items */
|
|
|
|
|
/* () Status Icon */
|
|
|
|
|
item -> setText(0, "");
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
|
|
|
|
/* (0) Status */
|
2008-04-28 08:09:26 -04:00
|
|
|
|
QString status = QString::fromStdString(RsPeerStateString(detail.state));
|
|
|
|
|
|
|
|
|
|
/* Append additional status info from status service */
|
|
|
|
|
StatusInfo statusInfo;
|
2008-06-13 19:36:40 -04:00
|
|
|
|
if ((rsStatus) && (rsStatus->getStatus(*it, statusInfo)))
|
2008-04-28 08:09:26 -04:00
|
|
|
|
{
|
|
|
|
|
status.append(QString::fromStdString("/" + RsStatusString(statusInfo.status)));
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-10 17:26:44 -04:00
|
|
|
|
//item -> setText(1, status);
|
|
|
|
|
item -> setText(1, QString::fromStdString(detail.autoconnect));
|
2008-11-24 09:07:26 -05:00
|
|
|
|
item -> setTextAlignment(1, Qt::AlignCenter | Qt::AlignVCenter );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
/* (1) Person */
|
2008-01-25 03:49:40 -05:00
|
|
|
|
item -> setText(2, QString::fromStdString(detail.name));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
/* (2) Auto Connect */
|
2008-07-10 17:26:44 -04:00
|
|
|
|
//item -> setText(3, QString::fromStdString(detail.autoconnect));
|
|
|
|
|
item -> setText(3, status);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
/* (3) Trust Level */
|
2008-01-25 03:49:40 -05:00
|
|
|
|
item -> setText(4,QString::fromStdString(
|
|
|
|
|
RsPeerTrustString(detail.trustLvl)));
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* (4) Peer Address */
|
2008-01-25 03:49:40 -05:00
|
|
|
|
{
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
out << detail.localAddr << ":";
|
|
|
|
|
out << detail.localPort << "/";
|
|
|
|
|
out << detail.extAddr << ":";
|
|
|
|
|
out << detail.extPort;
|
|
|
|
|
item -> setText(5, QString::fromStdString(out.str()));
|
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* less important ones */
|
|
|
|
|
/* () Last Contact */
|
2008-01-25 03:49:40 -05:00
|
|
|
|
item -> setText(6,QString::fromStdString(
|
2008-03-02 09:25:59 -05:00
|
|
|
|
RsPeerLastConnectString(now - detail.lastConnect)));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
/* () Org */
|
2008-03-20 21:03:27 -04:00
|
|
|
|
//item -> setText(7, QString::fromStdString(detail.org));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* () Location */
|
2008-03-20 21:03:27 -04:00
|
|
|
|
//item -> setText(8, QString::fromStdString(detail.location));
|
2008-01-25 03:49:40 -05:00
|
|
|
|
/* () Email */
|
2008-03-20 21:03:27 -04:00
|
|
|
|
//item -> setText(9, QString::fromStdString(detail.email));
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
|
/* Hidden ones: RsCertId */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
2008-03-20 21:03:27 -04:00
|
|
|
|
item -> setText(7, QString::fromStdString(detail.id));
|
2008-01-25 03:49:40 -05:00
|
|
|
|
if ((oldSelect) && (oldId == detail.id))
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
|
|
|
|
newSelect = item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 15:58:11 -04:00
|
|
|
|
/* () AuthCode */
|
2008-03-20 21:03:27 -04:00
|
|
|
|
// item -> setText(11, QString::fromStdString(detail.authcode));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
/* change background */
|
|
|
|
|
int i;
|
2008-01-25 03:49:40 -05:00
|
|
|
|
if (detail.state & RS_PEER_STATE_CONNECTED)
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
|
|
|
|
/* bright green */
|
2008-03-20 21:03:27 -04:00
|
|
|
|
for(i = 1; i < 8; i++)
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
2009-01-25 09:09:05 -05:00
|
|
|
|
// CsoLer: I uncommented the color because it's really confortable
|
|
|
|
|
// to be able to see at some distance that people are connected.
|
|
|
|
|
// The blue/gray icons need a close look indeed.
|
2009-01-25 14:02:52 -05:00
|
|
|
|
//item -> setBackground(i,QBrush(Qt::green))
|
|
|
|
|
item -> setTextColor(i,(Qt::darkBlue));
|
|
|
|
|
QFont font ;
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
item -> setFont(i,font);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_ONLINE)));
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-28 10:58:54 -05:00
|
|
|
|
else if (detail.state & RS_PEER_STATE_UNREACHABLE)
|
|
|
|
|
{
|
|
|
|
|
/* bright green */
|
2008-03-20 21:03:27 -04:00
|
|
|
|
for(i = 1; i < 8; i++)
|
2008-02-28 10:58:54 -05:00
|
|
|
|
{
|
|
|
|
|
item -> setBackground(i,QBrush(Qt::red));
|
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_OFFLINE)));
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-25 03:49:40 -05:00
|
|
|
|
else if (detail.state & RS_PEER_STATE_ONLINE)
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
|
/* bright green */
|
2008-03-20 21:03:27 -04:00
|
|
|
|
for(i = 1; i < 8; i++)
|
2008-01-25 03:49:40 -05:00
|
|
|
|
{
|
2009-04-29 11:48:01 -04:00
|
|
|
|
//item -> setBackground(i,QBrush(Qt::cyan));
|
|
|
|
|
item -> setTextColor(i,(Qt::darkCyan));
|
|
|
|
|
QFont font ;
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
item -> setFont(i,font);
|
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_AVAIBLE)));
|
2008-01-25 03:49:40 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
else
|
2008-01-25 03:49:40 -05:00
|
|
|
|
{
|
2008-03-02 09:25:59 -05:00
|
|
|
|
if (now - detail.lastConnect < 3600)
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
2008-03-20 21:03:27 -04:00
|
|
|
|
for(i = 1; i < 8; i++)
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
2008-07-10 06:34:49 -04:00
|
|
|
|
//item -> setBackground(i,QBrush(Qt::lightGray));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_OFFLINE)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-03-20 21:03:27 -04:00
|
|
|
|
for(i = 1; i < 8; i++)
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
2008-07-11 11:51:49 -04:00
|
|
|
|
//item -> setBackground(i,QBrush(Qt::gray));
|
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_OFFLINE2)));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* add to the list */
|
|
|
|
|
items.append(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add the items in! */
|
|
|
|
|
peerWidget->insertTopLevelItems(0, items);
|
|
|
|
|
if (newSelect)
|
|
|
|
|
{
|
|
|
|
|
peerWidget->setCurrentItem(newSelect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peerWidget->update(); /* update display */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Utility Fns */
|
|
|
|
|
std::string getPeerRsCertId(QTreeWidgetItem *i)
|
|
|
|
|
{
|
2008-03-20 21:03:27 -04:00
|
|
|
|
std::string id = (i -> text(7)).toStdString();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 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
|
2007-11-14 22:18:48 -05:00
|
|
|
|
std::cerr << "PeersDialog::exportfriend() Noone Selected -- sorry" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string id = getPeerRsCertId(c);
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Certificate"), "",
|
|
|
|
|
tr("Certificates (*.pqi)"));
|
|
|
|
|
|
|
|
|
|
std::string file = fileName.toStdString();
|
|
|
|
|
if (file != "")
|
|
|
|
|
{
|
2009-07-13 15:58:11 -04:00
|
|
|
|
#ifdef PEERS_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
|
std::cerr << "PeersDialog::exportfriend() Saving to: " << file << std::endl;
|
|
|
|
|
std::cerr << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
#endif
|
2008-01-25 03:49:40 -05:00
|
|
|
|
if (rsPeers)
|
|
|
|
|
{
|
|
|
|
|
rsPeers->SaveCertificateToFile(id, file);
|
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
void PeersDialog::chatfriend()
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *i = getCurrentPeer();
|
|
|
|
|
|
|
|
|
|
if (!i)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::string name = (i -> text(2)).toStdString();
|
2008-03-20 21:03:27 -04:00
|
|
|
|
std::string id = (i -> text(7)).toStdString();
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-01-26 08:08:28 -05:00
|
|
|
|
RsPeerDetails detail;
|
|
|
|
|
if (!rsPeers->getPeerDetails(id, detail))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2008-07-10 14:52:56 -04:00
|
|
|
|
if (detail.state & RS_PEER_STATE_CONNECTED)
|
|
|
|
|
{
|
2008-12-07 09:19:13 -05:00
|
|
|
|
getPrivateChat(id, name, RS_CHAT_REOPEN);
|
2008-07-10 14:52:56 -04:00
|
|
|
|
}
|
2008-01-26 08:08:28 -05:00
|
|
|
|
else
|
2008-07-10 14:52:56 -04:00
|
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/* info dialog */
|
2009-07-13 15:58:11 -04:00
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::question ( NULL,
|
|
|
|
|
"Friend Not Online",
|
2008-07-10 14:52:56 -04:00
|
|
|
|
"Your Friend is offline \nDo you want to send them a Message instead",
|
|
|
|
|
(QMessageBox::Yes | QMessageBox::No));
|
|
|
|
|
if (sb == QMessageBox::Yes)
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
|
|
|
|
msgfriend();
|
|
|
|
|
}
|
2008-07-10 14:52:56 -04:00
|
|
|
|
}
|
2008-01-26 08:08:28 -05:00
|
|
|
|
return;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-26 08:08:28 -05:00
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
void PeersDialog::msgfriend()
|
|
|
|
|
{
|
2009-07-13 15:58:11 -04:00
|
|
|
|
#ifdef PEERS_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
|
std::cerr << "SharedFilesDialog::msgfriend()" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
QTreeWidgetItem *i = getCurrentPeer();
|
|
|
|
|
|
|
|
|
|
if (!i)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::string status = (i -> text(1)).toStdString();
|
|
|
|
|
std::string name = (i -> text(2)).toStdString();
|
2008-03-20 21:03:27 -04:00
|
|
|
|
std::string id = (i -> text(7)).toStdString();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
rsicontrol -> ClearInMsg();
|
|
|
|
|
rsicontrol -> SetInMsg(id, true);
|
|
|
|
|
|
|
|
|
|
/* create a message */
|
|
|
|
|
ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true);
|
|
|
|
|
|
|
|
|
|
nMsgDialog->newMsg();
|
|
|
|
|
nMsgDialog->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
for(int i = 1; i < 6; i++)
|
|
|
|
|
{
|
|
|
|
|
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
|
2007-11-14 22:18:48 -05:00
|
|
|
|
std::cerr << "PeersDialog::removefriend() Noone 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)
|
|
|
|
|
{
|
|
|
|
|
rsPeers->removeFriend(getPeerRsCertId(c));
|
2009-05-15 08:07:37 -04:00
|
|
|
|
emit friendsUpdated() ;
|
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::allowfriend()
|
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::allowfriend()" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/*
|
|
|
|
|
bool accept = true;
|
|
|
|
|
rsServer->FriendStatus(getPeerRsCertId(c), accept);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
void PeersDialog::connectfriend()
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *c = getCurrentPeer();
|
2009-07-13 15:58:11 -04:00
|
|
|
|
#ifdef PEERS_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
|
std::cerr << "PeersDialog::connectfriend()" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
#endif
|
2008-04-07 18:54:15 -04:00
|
|
|
|
if (!c)
|
|
|
|
|
{
|
2009-07-13 15:58:11 -04:00
|
|
|
|
#ifdef PEERS_DEBUG
|
2008-04-07 18:54:15 -04:00
|
|
|
|
std::cerr << "PeersDialog::connectfriend() Noone Selected -- sorry" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
#endif
|
2008-04-07 18:54:15 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
|
if (rsPeers)
|
|
|
|
|
{
|
|
|
|
|
rsPeers->connectAttempt(getPeerRsCertId(c));
|
2009-04-29 11:48:01 -04:00
|
|
|
|
c -> setIcon(0,(QIcon(IMAGE_CONNECT2)));
|
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::setaddressfriend()
|
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::setaddressfriend()" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
/* need to get the input address / port */
|
|
|
|
|
/*
|
|
|
|
|
std::string addr;
|
|
|
|
|
unsigned short port;
|
|
|
|
|
rsServer->FriendSetAddress(getPeerRsCertId(c), addr, port);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
void PeersDialog::trustfriend()
|
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::trustfriend()" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
/*
|
|
|
|
|
bool trust = true;
|
|
|
|
|
rsServer->FriendTrust(getPeerRsCertId(c), trust);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GUI stuff -> don't do anything directly with Control */
|
2008-11-24 09:07:26 -05:00
|
|
|
|
void PeersDialog::configurefriend()
|
2007-11-14 22:18:48 -05:00
|
|
|
|
{
|
2009-05-07 18:43:11 -04:00
|
|
|
|
ConfCertDialog::show(getPeerRsCertId(getCurrentPeer()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-05 15:15:32 -04:00
|
|
|
|
void PeersDialog::updatePeerStatusString(const QString& peer_id,const QString& status_string)
|
|
|
|
|
{
|
|
|
|
|
RshareSettings settings;
|
2009-05-14 17:14:25 -04:00
|
|
|
|
// uint chatflags = settings.getChatFlags();
|
2009-05-05 15:15:32 -04:00
|
|
|
|
|
2009-05-14 17:14:25 -04:00
|
|
|
|
PopupChatDialog *pcd = getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
|
2009-05-05 15:15:32 -04:00
|
|
|
|
pcd->updateStatusString(status_string);
|
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
void PeersDialog::insertChat()
|
|
|
|
|
{
|
|
|
|
|
if (!rsMsgs->chatAvailable())
|
|
|
|
|
{
|
2009-06-08 13:09:00 -04:00
|
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
|
std::cerr << "no chat available." << std::endl ;
|
|
|
|
|
#endif
|
2008-07-10 06:34:49 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::list<ChatInfo> newchat;
|
|
|
|
|
if (!rsMsgs->getNewChat(newchat))
|
|
|
|
|
{
|
2009-05-05 15:15:32 -04:00
|
|
|
|
std::cerr << "could not get new chat." << std::endl ;
|
2008-07-10 06:34:49 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-05 15:15:32 -04:00
|
|
|
|
std::cerr << "got new chat." << std::endl ;
|
2008-07-10 06:34:49 -04:00
|
|
|
|
QTextEdit *msgWidget = ui.msgText;
|
|
|
|
|
std::list<ChatInfo>::iterator it;
|
|
|
|
|
|
2008-12-07 09:19:13 -05:00
|
|
|
|
/** A RshareSettings object used for saving/loading settings */
|
|
|
|
|
RshareSettings settings;
|
|
|
|
|
uint chatflags = settings.getChatFlags();
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
|
|
|
|
/* add in lines at the bottom */
|
|
|
|
|
for(it = newchat.begin(); it != newchat.end(); it++)
|
|
|
|
|
{
|
|
|
|
|
std::string msg(it->msg.begin(), it->msg.end());
|
2009-07-13 15:58:11 -04:00
|
|
|
|
#ifdef PEERS_DEBUG
|
2008-07-10 14:52:56 -04:00
|
|
|
|
std::cerr << "PeersDialog::insertChat(): " << msg << std::endl;
|
|
|
|
|
#endif
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
|
|
|
|
/* are they private? */
|
|
|
|
|
if (it->chatflags & RS_CHAT_PRIVATE)
|
|
|
|
|
{
|
2008-12-07 09:19:13 -05:00
|
|
|
|
PopupChatDialog *pcd = getPrivateChat(it->rsid, it->name, chatflags);
|
2008-07-10 06:34:49 -04:00
|
|
|
|
pcd->addChatMsg(&(*it));
|
2009-07-13 15:58:11 -04:00
|
|
|
|
QApplication::alert(pcd);
|
2008-07-10 06:34:49 -04:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
QString currenttxt = msgWidget->toHtml();
|
|
|
|
|
QString extraTxt;
|
|
|
|
|
|
|
|
|
|
QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss");
|
|
|
|
|
QString name = QString::fromStdString(it->name);
|
2009-07-13 15:58:11 -04:00
|
|
|
|
QString line = "<span style=\"color:#C00000\">" + timestamp + "</span>" +
|
2009-04-20 16:02:32 -04:00
|
|
|
|
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
|
2009-03-12 10:14:55 -04:00
|
|
|
|
|
|
|
|
|
//std::cerr << "PeersDialog::insertChat(): 1.11\n";
|
|
|
|
|
historyKeeper.addMessage(name, "THIS", QString::fromStdWString(it->msg));
|
|
|
|
|
//std::cerr << "PeersDialog::insertChat(): 1.12\n";
|
2008-07-10 06:34:49 -04:00
|
|
|
|
extraTxt += line;
|
|
|
|
|
|
|
|
|
|
extraTxt += QString::fromStdWString(it->msg);
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-07-13 10:01:49 -04:00
|
|
|
|
// notify with a systray icon msg
|
|
|
|
|
if(it->rsid != rsPeers->getOwnId())
|
|
|
|
|
{
|
2009-07-26 17:05:13 -04:00
|
|
|
|
// This is a trick to translate HTML into text.
|
2009-07-13 10:01:49 -04:00
|
|
|
|
QTextEdit editor ;
|
|
|
|
|
editor.setHtml(QString::fromStdWString(it->msg));
|
|
|
|
|
QString notifyMsg(QString::fromStdString(it->name)+": "+editor.toPlainText()) ;
|
|
|
|
|
|
|
|
|
|
if(notifyMsg.length() > 30)
|
|
|
|
|
emit notifyGroupChat(QString("New group chat"), notifyMsg.left(30)+QString("..."));
|
|
|
|
|
else
|
|
|
|
|
emit notifyGroupChat(QString("New group chat"), notifyMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
/* add it everytime */
|
2008-07-10 06:34:49 -04:00
|
|
|
|
currenttxt += extraTxt;
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
QHashIterator<QString, QString> i(smileys);
|
2009-01-05 21:47:42 -05:00
|
|
|
|
while(i.hasNext())
|
|
|
|
|
{
|
2008-07-10 06:34:49 -04:00
|
|
|
|
i.next();
|
2009-01-05 21:47:42 -05:00
|
|
|
|
foreach(QString code, i.key().split("|"))
|
|
|
|
|
currenttxt.replace(code, "<img src=\"" + i.value() + "\" />");
|
|
|
|
|
}
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-08-04 10:38:12 -04:00
|
|
|
|
QScrollBar *qsb = msgWidget->verticalScrollBar();
|
|
|
|
|
int oldQsbValue = qsb->value();
|
|
|
|
|
bool maxQsbValue = (qsb->maximum() == qsb->value());
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
2009-08-04 10:38:12 -04:00
|
|
|
|
msgWidget->setHtml(currenttxt);
|
2009-07-26 17:05:13 -04:00
|
|
|
|
msgWidget->update();
|
2009-08-04 10:38:12 -04:00
|
|
|
|
|
|
|
|
|
if (maxQsbValue ) {
|
|
|
|
|
qsb -> setValue(qsb->maximum());
|
|
|
|
|
} else {
|
|
|
|
|
qsb -> setValue(oldQsbValue);
|
|
|
|
|
}
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::checkChat()
|
|
|
|
|
{
|
|
|
|
|
/* if <return> at the end of the text -> we can send it! */
|
|
|
|
|
QTextEdit *chatWidget = ui.lineEdit;
|
|
|
|
|
std::string txt = chatWidget->toPlainText().toStdString();
|
|
|
|
|
if ('\n' == txt[txt.length()-1])
|
|
|
|
|
{
|
|
|
|
|
//std::cerr << "Found <return> found at end of :" << txt << ": should send!";
|
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
|
if (txt.length()-1 == txt.find('\n')) /* only if on first line! */
|
|
|
|
|
{
|
|
|
|
|
/* should remove last char ... */
|
|
|
|
|
sendMsg();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//std::cerr << "No <return> found in :" << txt << ":";
|
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::sendMsg()
|
|
|
|
|
{
|
|
|
|
|
QTextEdit *lineWidget = ui.lineEdit;
|
|
|
|
|
|
|
|
|
|
ChatInfo ci;
|
|
|
|
|
//ci.msg = lineWidget->Text().toStdWString();
|
|
|
|
|
ci.msg = lineWidget->toHtml().toStdWString();
|
|
|
|
|
ci.chatflags = RS_CHAT_PUBLIC;
|
|
|
|
|
|
2009-03-12 10:14:55 -04:00
|
|
|
|
//historyKeeper.addMessage("THIS", "ALL", lineWidget->toHtml() );
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
std::string msg(ci.msg.begin(), ci.msg.end());
|
2009-07-13 15:58:11 -04:00
|
|
|
|
#ifdef PEERS_DEBUG
|
2008-07-10 14:52:56 -04:00
|
|
|
|
std::cerr << "PeersDialog::sendMsg(): " << msg << std::endl;
|
|
|
|
|
#endif
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
|
|
|
|
rsMsgs -> ChatSend(ci);
|
|
|
|
|
ui.lineEdit->clear();
|
|
|
|
|
setFont();
|
|
|
|
|
|
|
|
|
|
/* redraw send list */
|
|
|
|
|
insertSendList();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::insertSendList()
|
|
|
|
|
{
|
|
|
|
|
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 */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* to toggle the state */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PeersDialog::toggleSendItem( QTreeWidgetItem *item, int col )
|
|
|
|
|
{
|
2009-07-13 15:58:11 -04:00
|
|
|
|
#ifdef PEERS_DEBUG
|
2008-07-10 06:34:49 -04:00
|
|
|
|
std::cerr << "ToggleSendItem()" << std::endl;
|
2008-07-10 14:52:56 -04:00
|
|
|
|
#endif
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
|
|
|
|
/* extract id */
|
|
|
|
|
std::string id = (item -> text(4)).toStdString();
|
|
|
|
|
|
|
|
|
|
/* get state */
|
|
|
|
|
bool inChat = (Qt::Checked == item -> checkState(0)); /* alway column 0 */
|
|
|
|
|
|
|
|
|
|
/* call control fns */
|
|
|
|
|
|
|
|
|
|
rsicontrol -> SetInChat(id, inChat);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-12 13:57:30 -04:00
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
PopupChatDialog *
|
|
|
|
|
PeersDialog::getPrivateChat(std::string id, std::string name, uint chatflags)
|
2008-07-10 06:34:49 -04:00
|
|
|
|
{
|
|
|
|
|
/* see if it exists already */
|
|
|
|
|
PopupChatDialog *popupchatdialog = NULL;
|
2008-12-07 09:19:13 -05:00
|
|
|
|
bool show = false;
|
|
|
|
|
|
|
|
|
|
if (chatflags & RS_CHAT_REOPEN)
|
|
|
|
|
{
|
|
|
|
|
show = true;
|
|
|
|
|
std::cerr << "reopen flag so: enable SHOW popupchatdialog()";
|
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
|
|
|
|
std::map<std::string, PopupChatDialog *>::iterator it;
|
|
|
|
|
if (chatDialogs.end() != (it = chatDialogs.find(id)))
|
|
|
|
|
{
|
|
|
|
|
/* exists already */
|
|
|
|
|
popupchatdialog = it->second;
|
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
else
|
2008-07-10 06:34:49 -04:00
|
|
|
|
{
|
|
|
|
|
popupchatdialog = new PopupChatDialog(id, name);
|
|
|
|
|
chatDialogs[id] = popupchatdialog;
|
2008-12-07 09:19:13 -05:00
|
|
|
|
|
|
|
|
|
if (chatflags & RS_CHAT_OPEN_NEW)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "new chat so: enable SHOW popupchatdialog()";
|
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
|
|
show = true;
|
|
|
|
|
}
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (show)
|
|
|
|
|
{
|
2008-12-07 09:19:13 -05:00
|
|
|
|
std::cerr << "SHOWING popupchatdialog()";
|
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
|
|
popupchatdialog->show();
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-07 09:19:13 -05:00
|
|
|
|
/* now only do these if the window is visible */
|
|
|
|
|
if (popupchatdialog->isVisible())
|
|
|
|
|
{
|
|
|
|
|
if (chatflags & RS_CHAT_FOCUS)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "focus chat flag so: GETFOCUS popupchatdialog()";
|
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
|
|
popupchatdialog->getfocus();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "no focus chat flag so: FLASH popupchatdialog()";
|
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
|
|
popupchatdialog->flash();
|
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
}
|
2008-12-07 09:19:13 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "not visible ... so leave popupchatdialog()";
|
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
return popupchatdialog;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-12 13:57:30 -04:00
|
|
|
|
//============================================================================
|
2008-12-07 09:19:13 -05:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
void PeersDialog::clearOldChats()
|
|
|
|
|
{
|
|
|
|
|
/* nothing yet */
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::setColor()
|
|
|
|
|
{
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
bool ok;
|
|
|
|
|
QRgb color = QColorDialog::getRgba(ui.lineEdit->textColor().rgba(), &ok, this);
|
|
|
|
|
if (ok) {
|
|
|
|
|
_currentColor = QColor(color);
|
2009-01-22 20:58:56 -05:00
|
|
|
|
QPixmap pxm(16,16);
|
2008-07-10 06:34:49 -04:00
|
|
|
|
pxm.fill(_currentColor);
|
|
|
|
|
ui.colorChatButton->setIcon(pxm);
|
|
|
|
|
}
|
|
|
|
|
setFont();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::getFont()
|
|
|
|
|
{
|
|
|
|
|
bool ok;
|
|
|
|
|
mCurrentFont = QFontDialog::getFont(&ok, mCurrentFont, this);
|
|
|
|
|
setFont();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::setFont()
|
|
|
|
|
{
|
|
|
|
|
mCurrentFont.setBold(ui.textboldChatButton->isChecked());
|
|
|
|
|
mCurrentFont.setUnderline(ui.textunderlineChatButton->isChecked());
|
|
|
|
|
mCurrentFont.setItalic(ui.textitalicChatButton->isChecked());
|
|
|
|
|
ui.lineEdit->setFont(mCurrentFont);
|
|
|
|
|
ui.lineEdit->setTextColor(_currentColor);
|
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
ui.lineEdit->setFocus();
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 15:58:11 -04:00
|
|
|
|
void PeersDialog::underline()
|
2008-11-24 09:07:26 -05:00
|
|
|
|
{
|
|
|
|
|
_underline = !_underline;
|
|
|
|
|
ui.lineEdit->setFontUnderline(_underline);
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
|
// Update Chat Info information
|
2009-07-13 15:58:11 -04:00
|
|
|
|
void PeersDialog::setChatInfo(QString info, QColor color)
|
2008-11-24 09:07:26 -05:00
|
|
|
|
{
|
|
|
|
|
static unsigned int nbLines = 0;
|
|
|
|
|
++nbLines;
|
|
|
|
|
// Check log size, clear it if too big
|
|
|
|
|
if(nbLines > 200) {
|
|
|
|
|
ui.msgText->clear();
|
|
|
|
|
nbLines = 1;
|
|
|
|
|
}
|
|
|
|
|
ui.msgText->append(QString::fromUtf8("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - <font color='") + color.name() +QString::fromUtf8("'><i>") + info + QString::fromUtf8("</i></font>"));
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 15:58:11 -04:00
|
|
|
|
void PeersDialog::on_actionClearChat_triggered()
|
2008-11-24 09:07:26 -05:00
|
|
|
|
{
|
|
|
|
|
ui.msgText->clear();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 15:58:11 -04:00
|
|
|
|
void PeersDialog::displayInfoChatMenu(const QPoint& pos)
|
2008-11-24 09:07:26 -05:00
|
|
|
|
{
|
|
|
|
|
// Log Menu
|
|
|
|
|
QMenu myChatMenu(this);
|
|
|
|
|
myChatMenu.addAction(ui.actionClearChat);
|
|
|
|
|
// XXX: Why mapToGlobal() is not enough?
|
|
|
|
|
myChatMenu.exec(mapToGlobal(pos)+QPoint(0,80));
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::loadEmoticonsgroupchat()
|
|
|
|
|
{
|
2009-01-05 21:47:42 -05:00
|
|
|
|
QString sm_codes;
|
2009-03-12 10:14:55 -04:00
|
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
|
QFile sm_file(QApplication::applicationDirPath() + "/emoticons/emotes.acs");
|
|
|
|
|
#else
|
|
|
|
|
QFile sm_file(QString(":/smileys/emotes.acs"));
|
2009-01-25 13:25:36 -05:00
|
|
|
|
#endif
|
2009-01-25 09:09:05 -05:00
|
|
|
|
if(!sm_file.open(QIODevice::ReadOnly))
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "Could not open resouce file :/emoticons/emotes.acs" << endl ;
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2009-01-05 21:47:42 -05:00
|
|
|
|
sm_codes = sm_file.readAll();
|
|
|
|
|
sm_file.close();
|
|
|
|
|
sm_codes.remove("\n");
|
|
|
|
|
sm_codes.remove("\r");
|
|
|
|
|
int i = 0;
|
|
|
|
|
QString smcode;
|
|
|
|
|
QString smfile;
|
|
|
|
|
while(sm_codes[i] != '{')
|
2008-07-10 06:34:49 -04:00
|
|
|
|
{
|
2009-01-05 21:47:42 -05:00
|
|
|
|
i++;
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-01-05 21:47:42 -05:00
|
|
|
|
}
|
|
|
|
|
while (i < sm_codes.length()-2)
|
|
|
|
|
{
|
|
|
|
|
smcode = "";
|
|
|
|
|
smfile = "";
|
|
|
|
|
while(sm_codes[i] != '\"')
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
while (sm_codes[i] != '\"')
|
|
|
|
|
{
|
|
|
|
|
smcode += sm_codes[i];
|
|
|
|
|
i++;
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-01-05 21:47:42 -05:00
|
|
|
|
}
|
|
|
|
|
i++;
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-01-05 21:47:42 -05:00
|
|
|
|
while(sm_codes[i] != '\"')
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
while(sm_codes[i] != '\"' && sm_codes[i+1] != ';')
|
2008-07-10 06:34:49 -04:00
|
|
|
|
{
|
2009-01-05 21:47:42 -05:00
|
|
|
|
smfile += sm_codes[i];
|
|
|
|
|
i++;
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
2009-01-05 21:47:42 -05:00
|
|
|
|
i++;
|
|
|
|
|
if(!smcode.isEmpty() && !smfile.isEmpty())
|
2009-01-25 14:02:52 -05:00
|
|
|
|
#if defined(Q_OS_WIN32)
|
2009-01-25 13:25:36 -05:00
|
|
|
|
smileys.insert(smcode, smfile);
|
2009-01-25 14:02:52 -05:00
|
|
|
|
#else
|
|
|
|
|
smileys.insert(smcode, ":/"+smfile);
|
2009-01-25 13:25:36 -05:00
|
|
|
|
#endif
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
2008-11-24 09:07:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
void PeersDialog::smileyWidgetgroupchat()
|
2009-07-13 15:58:11 -04:00
|
|
|
|
{
|
2008-07-10 06:34:49 -04:00
|
|
|
|
qDebug("MainWindow::smileyWidget()");
|
2009-03-12 13:57:30 -04:00
|
|
|
|
QWidget *smWidget = new QWidget(this , Qt::Popup );
|
2008-11-24 09:07:26 -05:00
|
|
|
|
smWidget->setWindowTitle("Emoticons");
|
2008-07-10 06:34:49 -04:00
|
|
|
|
smWidget->setWindowIcon(QIcon(QString(":/images/rstray3.png")));
|
2009-03-12 13:57:30 -04:00
|
|
|
|
//smWidget->setFixedSize(256,256);
|
|
|
|
|
|
|
|
|
|
smWidget->setBaseSize( 4*24, (smileys.size()/4)*24 );
|
|
|
|
|
|
|
|
|
|
//Warning: this part of code was taken from kadu instant messenger;
|
|
|
|
|
// It was EmoticonSelector::alignTo(QWidget* w) function there
|
|
|
|
|
// comments are Polish, I dont' know how does it work...
|
|
|
|
|
// oblicz pozycj<63> widgetu do kt<6B>rego r<>wnamy
|
|
|
|
|
QWidget* w = ui.emoticonBtn;
|
|
|
|
|
QPoint w_pos = w->mapToGlobal(QPoint(0,0));
|
|
|
|
|
// oblicz rozmiar selektora
|
|
|
|
|
QSize e_size = smWidget->sizeHint();
|
|
|
|
|
// oblicz rozmiar pulpitu
|
|
|
|
|
QSize s_size = QApplication::desktop()->size();
|
|
|
|
|
// oblicz dystanse od widgetu do lewego brzegu i do prawego
|
|
|
|
|
int l_dist = w_pos.x();
|
|
|
|
|
int r_dist = s_size.width() - (w_pos.x() + w->width());
|
|
|
|
|
// oblicz pozycj<63> w zale<6C>no<6E>ci od tego czy po lewej stronie
|
|
|
|
|
// jest wi<77>cej miejsca czy po prawej
|
|
|
|
|
int x;
|
|
|
|
|
if (l_dist >= r_dist)
|
|
|
|
|
x = w_pos.x() - e_size.width();
|
|
|
|
|
else
|
|
|
|
|
x = w_pos.x() + w->width();
|
|
|
|
|
// oblicz pozycj<63> y - centrujemy w pionie
|
|
|
|
|
int y = w_pos.y() + w->height()/2 - e_size.height()/2;
|
|
|
|
|
// je<6A>li wychodzi poza doln<6C> kraw<61>d<EFBFBD> to r<>wnamy do niej
|
|
|
|
|
if (y + e_size.height() > s_size.height())
|
|
|
|
|
y = s_size.height() - e_size.height();
|
|
|
|
|
// je<6A>li wychodzi poza g<>rn<72> kraw<61>d<EFBFBD> to r<>wnamy do niej
|
|
|
|
|
if (y < 0)
|
|
|
|
|
y = 0;
|
|
|
|
|
// ustawiamy selektor na wyliczonej pozycji
|
|
|
|
|
smWidget->move(x, y);
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2009-03-12 13:57:30 -04:00
|
|
|
|
x = 0;
|
|
|
|
|
y = 0;
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
QHashIterator<QString, QString> i(smileys);
|
|
|
|
|
while(i.hasNext())
|
|
|
|
|
{
|
|
|
|
|
i.next();
|
|
|
|
|
QPushButton *smButton = new QPushButton("", smWidget);
|
|
|
|
|
smButton->setGeometry(x*24, y*24, 24,24);
|
|
|
|
|
smButton->setIconSize(QSize(24,24));
|
|
|
|
|
smButton->setIcon(QPixmap(i.value()));
|
|
|
|
|
smButton->setToolTip(i.key());
|
|
|
|
|
//smButton->setFixedSize(24,24);
|
|
|
|
|
++x;
|
|
|
|
|
if(x > 4)
|
|
|
|
|
{
|
|
|
|
|
x = 0;
|
|
|
|
|
y++;
|
|
|
|
|
}
|
|
|
|
|
connect(smButton, SIGNAL(clicked()), this, SLOT(addSmileys()));
|
2009-03-12 13:57:30 -04:00
|
|
|
|
connect(smButton, SIGNAL(clicked()), smWidget, SLOT(close()));
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
2009-07-13 15:58:11 -04:00
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
smWidget->show();
|
2008-11-24 09:07:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-10 06:34:49 -04:00
|
|
|
|
void PeersDialog::addSmileys()
|
|
|
|
|
{
|
2009-01-05 21:47:42 -05:00
|
|
|
|
ui.lineEdit->setText(ui.lineEdit->toHtml() + qobject_cast<QPushButton*>(sender())->toolTip().split("|").first());
|
2008-07-10 06:34:49 -04:00
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
2009-01-22 20:58:56 -05:00
|
|
|
|
/* GUI stuff -> don't do anything directly with Control */
|
|
|
|
|
void PeersDialog::viewprofile()
|
|
|
|
|
{
|
|
|
|
|
/* display Dialog */
|
|
|
|
|
|
|
|
|
|
QTreeWidgetItem *c = getCurrentPeer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static ProfileView *profileview = new ProfileView();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!c)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* set the Id */
|
|
|
|
|
std::string id = getPeerRsCertId(c);
|
|
|
|
|
|
|
|
|
|
profileview -> setPeerId(id);
|
|
|
|
|
profileview -> show();
|
|
|
|
|
}
|
2009-09-02 18:42:31 -04:00
|
|
|
|
|
|
|
|
|
void PeersDialog::updateAvatar()
|
|
|
|
|
{
|
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
|
int size = 0 ;
|
|
|
|
|
|
|
|
|
|
rsMsgs->getOwnAvatarData(data,size);
|
|
|
|
|
|
|
|
|
|
std::cerr << "Image size = " << size << std::endl ;
|
|
|
|
|
|
|
|
|
|
if(size == 0)
|
|
|
|
|
std::cerr << "Got no image" << std::endl ;
|
|
|
|
|
|
|
|
|
|
// set the image
|
|
|
|
|
QPixmap pix ;
|
|
|
|
|
pix.loadFromData(data,size,"JPG") ;
|
|
|
|
|
ui.avatartoolButton->setIcon(pix); // writes image into ba in JPG format
|
|
|
|
|
|
|
|
|
|
delete[] data ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::getAvatar()
|
|
|
|
|
{
|
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)");
|
|
|
|
|
if(!fileName.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
picture = QPixmap(fileName).scaled(82,82, Qt::IgnoreAspectRatio);
|
|
|
|
|
|
|
|
|
|
std::cerr << "Sending avatar image down the pipe" << std::endl ;
|
|
|
|
|
|
|
|
|
|
// send avatar down the pipe for other peers to get it.
|
|
|
|
|
QByteArray ba;
|
|
|
|
|
QBuffer buffer(&ba);
|
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
|
|
|
|
picture.save(&buffer, "JPG"); // writes image into ba in JPG format
|
|
|
|
|
|
|
|
|
|
std::cerr << "Image size = " << ba.size() << std::endl ;
|
|
|
|
|
|
|
|
|
|
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()),ba.size()) ; // last char 0 included.
|
|
|
|
|
|
|
|
|
|
updateAvatar() ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeersDialog::changeAvatarClicked()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
updateAvatar();
|
|
|
|
|
}
|