2007-11-14 22:18:48 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, 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
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-01-01 18:25:16 -05:00
|
|
|
****************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
#include <QFile>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <QFileInfo>
|
2008-01-25 03:49:40 -05:00
|
|
|
#include "common/vmessagebox.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"
|
2009-01-30 18:51:59 -05:00
|
|
|
#include "rsiface/rsmsgs.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
#include "MessengerWindow.h"
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "chat/PopupChatDialog.h"
|
|
|
|
#include "msgs/ChanMsgDialog.h"
|
2008-07-10 14:52:56 -04:00
|
|
|
#include "PeersDialog.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "connect/ConfCertDialog.h"
|
|
|
|
#include "util/PixmapMerging.h"
|
|
|
|
#include "LogoBar.h"
|
|
|
|
#include "util/Widget.h"
|
2007-11-16 20:35:52 -05:00
|
|
|
#include "gui/connect/InviteDialog.h"
|
|
|
|
#include "gui/connect/AddFriendDialog.h"
|
2009-01-08 12:29:01 -05:00
|
|
|
#include "MessagesPopupDialog.h"
|
|
|
|
#include "ShareManager.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QCursor>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
|
|
|
|
2009-01-01 18:25:16 -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"
|
|
|
|
#define IMAGE_CHAT ":/images/chat.png"
|
|
|
|
#define IMAGE_SENDMESSAGE ":/images/message-mail.png"
|
|
|
|
/* Images for Status icons */
|
|
|
|
#define IMAGE_ONLINE ":/images/donline.png"
|
|
|
|
#define IMAGE_OFFLINE ":/images/dhidden.png"
|
|
|
|
/* Images for Status icons */
|
|
|
|
#define IMAGE_ON ":/images/contract_hover.png"
|
2009-01-01 18:25:16 -05:00
|
|
|
#define IMAGE_OFF ":/images/expand_hover.png"
|
2008-07-09 05:53:47 -04:00
|
|
|
|
|
|
|
/******
|
|
|
|
* #define MSG_DEBUG 1
|
|
|
|
*****/
|
|
|
|
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
/** Constructor */
|
2009-01-07 16:12:31 -05:00
|
|
|
MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
|
|
|
|
: RWindow("MessengerWindow", parent, flags)
|
2009-01-01 18:25:16 -05:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
2008-04-07 07:11:16 -04:00
|
|
|
ui.setupUi(this);
|
2007-11-18 18:35:53 -05:00
|
|
|
|
2009-01-07 16:12:31 -05:00
|
|
|
//RshareSettings config;
|
|
|
|
//config.loadWidgetInformation(this);
|
2009-01-01 18:25:16 -05:00
|
|
|
|
|
|
|
connect( ui.messengertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messengertreeWidgetCostumPopupMenu( QPoint ) ) );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-30 18:51:59 -05:00
|
|
|
connect( ui.avatarButton, SIGNAL(clicked()), SLOT(getAvatar()));
|
2009-01-08 12:29:01 -05:00
|
|
|
connect( ui.shareButton, SIGNAL(clicked()), SLOT(openShareManager()));
|
2009-01-07 16:12:31 -05:00
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
connect( ui.addIMAccountButton, SIGNAL(clicked( bool ) ), this , SLOT( addFriend2() ) );
|
|
|
|
|
|
|
|
connect( ui.messengertreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend2()));
|
|
|
|
|
2007-11-16 20:35:52 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
/* to hide the header */
|
2008-04-07 07:11:16 -04:00
|
|
|
ui.messengertreeWidget->header()->hide();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-07 16:12:31 -05:00
|
|
|
/* Set header resize modes and initial section sizes */
|
2007-11-14 22:18:48 -05:00
|
|
|
ui.messengertreeWidget->setColumnCount(1);
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
QHeaderView * _header = ui.messengertreeWidget->header () ;
|
|
|
|
_header->setResizeMode (0, QHeaderView::Interactive);
|
|
|
|
//_header->setResizeMode (1, QHeaderView::Interactive);
|
2007-11-14 22:18:48 -05:00
|
|
|
//_header->setResizeMode (2, QHeaderView::Interactive);
|
2009-01-01 18:25:16 -05:00
|
|
|
//_header->setResizeMode (3, QHeaderView::Interactive);
|
|
|
|
|
|
|
|
_header->resizeSection ( 0, 200 );
|
2009-01-07 16:12:31 -05:00
|
|
|
|
|
|
|
/* Create all the dialogs of which we only want one instance */
|
|
|
|
//_mainWindow = new MainWindow();
|
2009-01-01 18:25:16 -05:00
|
|
|
|
2008-04-07 07:11:16 -04:00
|
|
|
//LogoBar
|
|
|
|
_rsLogoBarmessenger = NULL;
|
|
|
|
_rsLogoBarmessenger = new LogoBar(ui.logoframe);
|
|
|
|
Widget::createLayout(ui.logoframe)->addWidget(_rsLogoBarmessenger);
|
|
|
|
|
|
|
|
|
|
|
|
ui.statuscomboBox->setMinimumWidth(20);
|
|
|
|
ui.messagecomboBox->setMinimumWidth(20);
|
|
|
|
ui.searchlineEdit->setMinimumWidth(20);
|
2008-04-24 08:58:27 -04:00
|
|
|
|
2009-01-30 18:51:59 -05:00
|
|
|
updateAvatar();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2008-04-24 08:58:27 -04:00
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
#endif
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::messengertreeWidgetCostumPopupMenu( 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( chatfriend2() ) );
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
sendMessageAct = new QAction(QIcon(IMAGE_SENDMESSAGE), tr( "Send Message" ), this );
|
2007-11-14 22:18:48 -05:00
|
|
|
connect( sendMessageAct , SIGNAL( triggered() ), this, SLOT( sendMessage() ) );
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
connectfriendAct = new QAction( tr( "Connect To Friend" ), this );
|
|
|
|
connect( connectfriendAct , SIGNAL( triggered() ), this, SLOT( connectfriend2() ) );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/************ Do we want these options here???
|
|
|
|
*
|
|
|
|
*
|
2009-01-01 18:25:16 -05:00
|
|
|
configurefriendAct = new QAction( tr( "Configure Friend" ), this );
|
2007-11-14 22:18:48 -05:00
|
|
|
connect( configurefriendAct , SIGNAL( triggered() ), this, SLOT( configurefriend2() ) );
|
|
|
|
|
2009-01-01 18:25:16 -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( exportfriend2() ) );
|
2007-11-16 20:35:52 -05:00
|
|
|
*
|
|
|
|
*
|
2007-11-14 22:18:48 -05:00
|
|
|
*********/
|
2007-11-16 20:35:52 -05:00
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
removefriend2Act = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Remove Friend" ), this );
|
|
|
|
connect( removefriend2Act , SIGNAL( triggered() ), this, SLOT( removefriend2() ) );
|
|
|
|
|
2007-11-16 20:35:52 -05:00
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
contextMnu.clear();
|
2007-11-14 22:18:48 -05:00
|
|
|
contextMnu.addAction( chatAct);
|
|
|
|
contextMnu.addAction( sendMessageAct);
|
|
|
|
contextMnu.addSeparator();
|
|
|
|
contextMnu.addAction( connectfriendAct);
|
2007-11-16 20:35:52 -05:00
|
|
|
contextMnu.addAction( removefriend2Act);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/**** Do we want these options here???
|
|
|
|
*
|
|
|
|
*
|
|
|
|
contextMnu.addAction( configurefriendAct);
|
2009-01-01 18:25:16 -05:00
|
|
|
contextMnu.addAction( exportfriendAct);
|
2007-11-14 22:18:48 -05:00
|
|
|
*
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
contextMnu.exec( mevent->globalPos() );
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
/* get the list of peers from the RsIface. */
|
|
|
|
void MessengerWindow::insertPeers()
|
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
if (!rsPeers)
|
|
|
|
{
|
|
|
|
/* not ready yet! */
|
|
|
|
return;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
std::list<std::string> peers;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
|
|
|
rsPeers->getFriendList(peers);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* get a link to the table */
|
|
|
|
QTreeWidget *peerWidget = ui.messengertreeWidget;
|
|
|
|
|
|
|
|
/* have two lists: online / offline */
|
|
|
|
QList<QTreeWidgetItem *> online_items;
|
|
|
|
QList<QTreeWidgetItem *> offline_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 details;
|
|
|
|
if (!rsPeers->getPeerDetails(*it, details))
|
|
|
|
{
|
|
|
|
continue; /* BAD */
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* make a widget per friend */
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
|
|
|
|
|
|
|
|
/* add all the labels */
|
|
|
|
/* (0) Person */
|
2008-01-25 03:49:40 -05:00
|
|
|
item -> setText(0, QString::fromStdString(details.name));
|
2007-11-14 22:18:48 -05:00
|
|
|
/* (1) Org */
|
2008-01-25 03:49:40 -05:00
|
|
|
//item -> setText(1, QString::fromStdString(details.org));
|
2007-11-14 22:18:48 -05:00
|
|
|
/* (2) Location */
|
2008-01-25 03:49:40 -05:00
|
|
|
//item -> setText(2, QString::fromStdString(details.location));
|
|
|
|
/* (3) Email */
|
|
|
|
//item -> setText(3, QString::fromStdString(details.email));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
/* Hidden ones: RsCertId */
|
|
|
|
item -> setText(4, QString::fromStdString(details.id));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* add to the list */
|
2008-01-25 03:49:40 -05:00
|
|
|
if (details.state & RS_PEER_STATE_CONNECTED)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
online_items.append(item);
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_ONLINE)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offline_items.append(item);
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_OFFLINE)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
/* remove old items */
|
|
|
|
peerWidget->clear();
|
|
|
|
peerWidget->setColumnCount(1);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
if (online_items.size() > 0)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
|
|
|
|
|
|
|
|
/* add all the labels */
|
|
|
|
/* (0) Person */
|
|
|
|
item -> setText(0, "Online");
|
|
|
|
item -> addChildren(online_items);
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_ON)));
|
|
|
|
peerWidget->addTopLevelItem(item);
|
|
|
|
peerWidget->expandItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offline_items.size() > 0)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
|
|
|
|
|
|
|
|
/* add all the labels */
|
|
|
|
/* (0) Person */
|
|
|
|
item -> setText(0, "Offline");
|
|
|
|
item -> addChildren(offline_items);
|
|
|
|
|
|
|
|
peerWidget->addTopLevelItem(item);
|
|
|
|
peerWidget->expandItem(item);
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_OFF)));
|
|
|
|
}
|
|
|
|
|
|
|
|
peerWidget->update(); /* update display */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Utility Fns */
|
|
|
|
std::string getMessengerPeerRsCertId(QTreeWidgetItem *i)
|
|
|
|
{
|
|
|
|
std::string id = (i -> text(4)).toStdString();
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Open a QFileDialog to browse for export a file. */
|
|
|
|
void MessengerWindow::exportfriend2()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::allowfriend2()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::connectfriend2()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
bool isOnline;
|
|
|
|
QTreeWidgetItem *i = getCurrentPeer(isOnline);
|
|
|
|
if (!i)
|
|
|
|
return;
|
|
|
|
|
2008-06-16 16:28:16 -04:00
|
|
|
std::string id = (i -> text(4)).toStdString();
|
|
|
|
if (rsPeers->isOnline(id))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef MSG_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "MessengerWindow::connectfriend2() Already online" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef MSG_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "MessengerWindow::connectfriend2() Trying" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2008-01-25 03:49:40 -05:00
|
|
|
rsPeers->connectAttempt(getMessengerPeerRsCertId(i));
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::setaddressfriend2()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::trustfriend2()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GUI stuff -> don't do anything directly with Control */
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::configurefriend2()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
|
|
|
|
/** Overloads the default show */
|
|
|
|
void MessengerWindow::show()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!this->isVisible()) {
|
|
|
|
QWidget::show();
|
|
|
|
} else {
|
|
|
|
QWidget::activateWindow();
|
|
|
|
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
|
|
|
|
QWidget::raise();
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
2009-01-07 16:12:31 -05:00
|
|
|
//RshareSettings config;
|
|
|
|
//config.saveWidgetInformation(this);
|
2007-11-18 18:35:53 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
hide();
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
2009-01-08 12:29:01 -05:00
|
|
|
/** Shows MessagesPopupDialog */
|
|
|
|
void MessengerWindow::showMessagesPopup()
|
|
|
|
{
|
|
|
|
static MessagesPopupDialog* messagespopup = new MessagesPopupDialog(this);
|
|
|
|
messagespopup->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Shows Share Manager */
|
|
|
|
void MessengerWindow::openShareManager()
|
|
|
|
{
|
|
|
|
static ShareManager* sharemanager = new ShareManager(this);
|
|
|
|
sharemanager->show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-07 16:12:31 -05:00
|
|
|
/** Shows Messages */
|
|
|
|
/*void MessengerWindow::showMessages(MainWindow::Page page)
|
|
|
|
{
|
2009-01-08 12:29:01 -05:00
|
|
|
showWindow(page);
|
2009-01-07 16:12:31 -05:00
|
|
|
}*/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2008-07-10 14:52:56 -04:00
|
|
|
void MessengerWindow::setChatDialog(PeersDialog *cd)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
chatDialog = cd;
|
|
|
|
}
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::chatfriend2()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
bool isOnline;
|
|
|
|
QTreeWidgetItem *i = getCurrentPeer(isOnline);
|
|
|
|
if (!i)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string name = (i -> text(0)).toStdString();
|
|
|
|
std::string id = (i -> text(4)).toStdString();
|
|
|
|
|
2008-06-16 16:28:16 -04:00
|
|
|
if (!(rsPeers->isOnline(id)))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* info dialog */
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::question ( NULL,
|
|
|
|
"Friend Not Online",
|
|
|
|
"Your Friend is offline \nDo You want to send them a Message instead",
|
|
|
|
(QMessageBox::Yes | QMessageBox::No ));
|
|
|
|
if (sb == QMessageBox::Yes)
|
|
|
|
{
|
|
|
|
rsicontrol -> ClearInMsg();
|
|
|
|
rsicontrol -> SetInMsg(id, true);
|
|
|
|
|
|
|
|
/* create a message */
|
|
|
|
ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true);
|
|
|
|
|
|
|
|
nMsgDialog->newMsg();
|
|
|
|
nMsgDialog->show();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must reference ChatDialog */
|
|
|
|
if (chatDialog)
|
|
|
|
{
|
|
|
|
chatDialog->getPrivateChat(id, name, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::sendMessage()
|
|
|
|
{
|
|
|
|
bool isOnline;
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef MSG_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(isOnline);
|
|
|
|
|
|
|
|
if (!i)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//std::string status = (i -> text(0)).toStdString();
|
|
|
|
std::string name = (i -> text(0)).toStdString();
|
|
|
|
std::string id = (i -> text(4)).toStdString();
|
|
|
|
|
|
|
|
rsicontrol -> ClearInMsg();
|
|
|
|
rsicontrol -> SetInMsg(id, true);
|
|
|
|
|
|
|
|
/* create a message */
|
|
|
|
ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true);
|
|
|
|
|
|
|
|
nMsgDialog->newMsg();
|
|
|
|
nMsgDialog->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem *MessengerWindow::getCurrentPeer(bool &isOnline)
|
|
|
|
{
|
|
|
|
/* get the current, and extract the Id */
|
|
|
|
|
|
|
|
/* get a link to the table */
|
|
|
|
QTreeWidget *peerWidget = ui.messengertreeWidget;
|
|
|
|
QTreeWidgetItem *item = peerWidget -> currentItem();
|
|
|
|
if (!item)
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef MSG_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if parent is online or offline */
|
|
|
|
QTreeWidgetItem *parent = item->parent();
|
|
|
|
if ((!parent) ||
|
|
|
|
(parent == peerWidget->invisibleRootItem()))
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef MSG_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "Selected Parent Invalid Item" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-07 07:11:16 -04:00
|
|
|
isOnline = (parent->text(0) == "<span><strong>Online</strong></span>");
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::removefriend2()
|
2007-11-16 20:35:52 -05:00
|
|
|
{
|
|
|
|
bool isOnline;
|
|
|
|
QTreeWidgetItem *c = getCurrentPeer(isOnline);
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef MSG_DEBUG
|
2007-11-16 20:35:52 -05:00
|
|
|
std::cerr << "MessengerWindow::removefriend2()" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2007-11-16 20:35:52 -05:00
|
|
|
if (!c)
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef MSG_DEBUG
|
2007-11-16 20:35:52 -05:00
|
|
|
std::cerr << "MessengerWindow::removefriend2() Noone Selected -- sorry" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2007-11-16 20:35:52 -05:00
|
|
|
return;
|
|
|
|
}
|
2008-01-25 03:49:40 -05:00
|
|
|
rsPeers->removeFriend(getMessengerPeerRsCertId(c));
|
2007-11-16 20:35:52 -05:00
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
void MessengerWindow::changeAvatarClicked()
|
|
|
|
{
|
|
|
|
|
|
|
|
updateAvatar();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-16 20:35:52 -05:00
|
|
|
/** Add a Friend ShortCut */
|
|
|
|
void MessengerWindow::addFriend2()
|
|
|
|
{
|
|
|
|
/* call load Certificate */
|
|
|
|
#if 0
|
|
|
|
std::string id;
|
|
|
|
if (connectionsDialog)
|
|
|
|
{
|
|
|
|
id = connectionsDialog->loadneighbour();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call make Friend */
|
|
|
|
if (id != "")
|
|
|
|
{
|
|
|
|
connectionsDialog->showpeerdetails(id);
|
|
|
|
}
|
|
|
|
virtual int NeighLoadPEMString(std::string pem, std::string &id) = 0;
|
|
|
|
#else
|
|
|
|
|
|
|
|
static AddFriendDialog *addDialog2 =
|
|
|
|
new AddFriendDialog(networkDialog2, this);
|
|
|
|
|
|
|
|
std::string invite = "";
|
|
|
|
addDialog2->setInfo(invite);
|
|
|
|
addDialog2->show();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-01-30 18:51:59 -05:00
|
|
|
LogoBar & MessengerWindow::getLogoBar() const {
|
|
|
|
return *_rsLogoBarmessenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::updateAvatar()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-01-30 18:51:59 -05:00
|
|
|
unsigned char *data = NULL;
|
|
|
|
int size = 0 ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-30 18:51:59 -05:00
|
|
|
rsMsgs->getOwnAvatarData(data,size);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-30 18:51:59 -05:00
|
|
|
std::cerr << "Image size = " << size << std::endl ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-30 18:51:59 -05:00
|
|
|
if(size == 0)
|
|
|
|
std::cerr << "Got no image" << std::endl ;
|
|
|
|
|
|
|
|
// set the image
|
|
|
|
QPixmap pix ;
|
|
|
|
pix.loadFromData(data,size,"JPG") ;
|
|
|
|
ui.avatarButton->setIcon(pix); // writes image into ba in JPG format
|
|
|
|
|
|
|
|
delete[] data ;
|
2009-01-01 18:25:16 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-30 18:51:59 -05:00
|
|
|
void MessengerWindow::getAvatar()
|
2009-01-03 21:28:30 -05:00
|
|
|
{
|
2009-01-30 18:51:59 -05:00
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)");
|
2009-01-03 21:28:30 -05:00
|
|
|
if(!fileName.isEmpty())
|
|
|
|
{
|
2009-01-30 18:51:59 -05:00
|
|
|
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() ;
|
2009-01-03 21:28:30 -05:00
|
|
|
}
|
|
|
|
}
|