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>
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QWidgetAction>
|
2010-08-28 15:50:38 -04:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QFileDialog>
|
2008-01-25 03:49:40 -05:00
|
|
|
#include "common/vmessagebox.h"
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsiface.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
#include <retroshare/rsstatus.h>
|
|
|
|
#include <retroshare/rsnotify.h>
|
2008-01-25 03:49:40 -05:00
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
#include "MessengerWindow.h"
|
2010-06-17 13:39:32 -04:00
|
|
|
#include "RsAutoUpdatePage.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
|
|
|
#include "MainWindow.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "chat/PopupChatDialog.h"
|
2010-05-23 15:13:41 -04:00
|
|
|
#include "msgs/MessageComposer.h"
|
2010-08-31 16:00:49 -04:00
|
|
|
#include "ShareManager.h"
|
|
|
|
#include "gui/notifyqt.h"
|
|
|
|
#include "gui/connect/ConnectFriendWizard.h"
|
|
|
|
#endif // MINIMAL_RSGUI
|
|
|
|
#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"
|
2010-05-11 16:02:52 -04:00
|
|
|
#include "settings/rsharesettings.h"
|
2009-09-30 18:10:49 -04:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
#include "RetroShareLink.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2010-08-25 14:31:56 -04:00
|
|
|
#include <algorithm>
|
2010-08-28 15:50:38 -04:00
|
|
|
#include <set>
|
2007-11-14 22:18:48 -05:00
|
|
|
|
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"
|
2010-02-03 12:39:30 -05:00
|
|
|
#define IMAGE_MSG ":/images/message-mail.png"
|
|
|
|
#define IMAGE_CONNECT ":/images/connect_friend.png"
|
|
|
|
#define IMAGE_PEERINFO ":/images/peerdetails_16x16.png"
|
|
|
|
#define IMAGE_AVAIBLE ":/images/user/identityavaiblecyan24.png"
|
|
|
|
#define IMAGE_CONNECT2 ":/images/reload24.png"
|
2010-07-15 07:25:34 -04:00
|
|
|
#define IMAGE_PASTELINK ":/images/pasterslink.png"
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* Images for Status icons */
|
2009-09-08 12:26:52 -04:00
|
|
|
#define IMAGE_ONLINE ":/images/im-user.png"
|
|
|
|
#define IMAGE_OFFLINE ":/images/im-user-offline.png"
|
2010-04-15 08:02:23 -04:00
|
|
|
#define IMAGE_AWAY ":/images/im-user-away.png"
|
|
|
|
#define IMAGE_BUSY ":/images/im-user-busy.png"
|
2010-04-27 08:21:39 -04:00
|
|
|
#define IMAGE_INACTIVE ":/images/im-user-inactive.png"
|
2008-07-09 05:53:47 -04:00
|
|
|
|
2010-06-25 10:19:48 -04:00
|
|
|
#define COLUMN_COUNT 3
|
2010-06-17 13:39:32 -04:00
|
|
|
#define COLUMN_NAME 0
|
|
|
|
#define COLUMN_STATE 1
|
|
|
|
#define COLUMN_INFO 2
|
2010-06-25 10:19:48 -04:00
|
|
|
|
|
|
|
#define COLUMN_DATA 0 // column for storing the userdata id
|
|
|
|
|
|
|
|
#define ROLE_SORT Qt::UserRole
|
|
|
|
#define ROLE_ID Qt::UserRole + 1
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
/******
|
|
|
|
* #define MSG_DEBUG 1
|
|
|
|
*****/
|
2010-07-18 07:43:39 -04:00
|
|
|
|
|
|
|
MessengerWindow* MessengerWindow::_instance = NULL;
|
|
|
|
static std::set<std::string> *expandedPeers = NULL;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
// quick and dirty for sorting, better use QTreeView and QSortFilterProxyModel
|
|
|
|
class MyMessengerTreeWidgetItem : public QTreeWidgetItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyMessengerTreeWidgetItem(QTreeWidget *pWidget, int type) : QTreeWidgetItem(type)
|
|
|
|
{
|
|
|
|
m_pWidget = pWidget; // can't access the member "view"
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const QTreeWidgetItem &other) const
|
|
|
|
{
|
|
|
|
int column = m_pWidget ? m_pWidget->sortColumn() : 0;
|
|
|
|
|
|
|
|
switch (column) {
|
|
|
|
case COLUMN_NAME:
|
|
|
|
{
|
2010-06-25 10:19:48 -04:00
|
|
|
const QVariant v1 = data(column, ROLE_SORT);
|
|
|
|
const QVariant v2 = other.data(column, ROLE_SORT);
|
2010-06-17 13:39:32 -04:00
|
|
|
return (v1.toString().compare (v2.toString(), Qt::CaseInsensitive) < 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// let the standard do the sort
|
|
|
|
return QTreeWidgetItem::operator<(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QTreeWidget *m_pWidget; // the member "view" is private
|
|
|
|
};
|
|
|
|
|
2010-07-18 07:43:39 -04:00
|
|
|
/*static*/ void MessengerWindow::showYourself ()
|
|
|
|
{
|
|
|
|
if (_instance == NULL) {
|
|
|
|
_instance = new MessengerWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
_instance->show();
|
|
|
|
_instance->activateWindow();
|
|
|
|
}
|
|
|
|
|
2009-11-30 11:12:13 -05:00
|
|
|
MessengerWindow* MessengerWindow::getInstance()
|
|
|
|
{
|
2010-07-18 07:43:39 -04:00
|
|
|
return _instance;
|
2009-11-30 11:12:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::releaseInstance()
|
|
|
|
{
|
2010-07-18 07:43:39 -04:00
|
|
|
if (_instance) {
|
|
|
|
delete _instance;
|
|
|
|
}
|
|
|
|
if (expandedPeers) {
|
|
|
|
/* delete saved expanded peers */
|
|
|
|
delete(expandedPeers);
|
|
|
|
expandedPeers = NULL;
|
|
|
|
}
|
2009-11-30 11:12:13 -05:00
|
|
|
}
|
2008-07-09 05:53:47 -04:00
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
/** Constructor */
|
2009-01-07 16:12:31 -05:00
|
|
|
MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
|
2010-07-17 19:19:43 -04:00
|
|
|
: RWindow("MessengerWindow", parent, flags)
|
2009-01-01 18:25:16 -05:00
|
|
|
{
|
2010-06-17 13:39:32 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2010-07-18 07:43:39 -04:00
|
|
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifdef MINIMAL_RSGUI
|
|
|
|
setAttribute (Qt::WA_QuitOnClose, true);
|
|
|
|
#endif // MINIMAL_RSGUI
|
2010-07-18 07:43:39 -04:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
connect( ui.messengertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messengertreeWidgetCostumPopupMenu( QPoint ) ) );
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-06-17 13:39:32 -04:00
|
|
|
connect( ui.messengertreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *)));
|
|
|
|
|
|
|
|
connect( ui.avatarButton, SIGNAL(clicked()), SLOT(getAvatar()));
|
|
|
|
connect( ui.shareButton, SIGNAL(clicked()), SLOT(openShareManager()));
|
|
|
|
connect( ui.addIMAccountButton, SIGNAL(clicked( bool ) ), this , SLOT( addFriend() ) );
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-06-17 13:39:32 -04:00
|
|
|
connect( ui.actionHide_Offline_Friends, SIGNAL(triggered()), this, SLOT(insertPeers()));
|
|
|
|
connect( ui.actionSort_by_State, SIGNAL(triggered()), this, SLOT(insertPeers()));
|
|
|
|
connect(ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
|
|
|
|
|
|
|
|
connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage()));
|
|
|
|
connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-07-18 07:43:39 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateMessengerDisplay()));
|
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(ownAvatarChanged()), this, SLOT(updateAvatar()));
|
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage()));
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-07-18 07:43:39 -04:00
|
|
|
|
2010-07-20 15:45:07 -04:00
|
|
|
timer = new QTimer(this);
|
2010-06-17 13:39:32 -04:00
|
|
|
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateMessengerDisplay()));
|
2010-07-20 15:45:07 -04:00
|
|
|
timer->setInterval(1000); /* one second */
|
|
|
|
timer->setSingleShot(true);
|
2010-06-17 13:39:32 -04:00
|
|
|
|
|
|
|
/* to hide the header */
|
|
|
|
ui.messengertreeWidget->header()->hide();
|
|
|
|
|
|
|
|
/* Set header resize modes and initial section sizes */
|
|
|
|
ui.messengertreeWidget->setColumnCount(COLUMN_COUNT);
|
|
|
|
ui.messengertreeWidget->setColumnHidden ( COLUMN_INFO, true);
|
|
|
|
ui.messengertreeWidget->sortItems( COLUMN_NAME, Qt::AscendingOrder );
|
|
|
|
|
|
|
|
QHeaderView * _header = ui.messengertreeWidget->header () ;
|
|
|
|
_header->setResizeMode (COLUMN_NAME, QHeaderView::Stretch);
|
|
|
|
_header->setResizeMode (COLUMN_STATE, QHeaderView::Custom);
|
|
|
|
_header->setStretchLastSection(false);
|
|
|
|
|
|
|
|
_header->resizeSection ( COLUMN_NAME, 200 );
|
|
|
|
_header->resizeSection ( COLUMN_STATE, 42 );
|
|
|
|
|
|
|
|
//LogoBar
|
|
|
|
_rsLogoBarmessenger = NULL;
|
|
|
|
_rsLogoBarmessenger = new LogoBar(ui.logoframe);
|
|
|
|
Widget::createLayout(ui.logoframe)->addWidget(_rsLogoBarmessenger);
|
|
|
|
|
|
|
|
ui.messagelineEdit->setMinimumWidth(20);
|
|
|
|
|
|
|
|
itemFont = QFont("ARIAL", 10);
|
|
|
|
itemFont.setBold(true);
|
|
|
|
|
|
|
|
displayMenu();
|
|
|
|
|
|
|
|
// load settings
|
|
|
|
processSettings(true);
|
|
|
|
|
2010-08-25 14:31:56 -04:00
|
|
|
// add self nick
|
|
|
|
RsPeerDetails pd;
|
|
|
|
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),pd)) {
|
2010-08-30 15:10:07 -04:00
|
|
|
ui.statusButton->setText(QString::fromStdString(pd.name) + tr(" - ") + QString::fromStdString(pd.location));
|
2010-08-25 14:31:56 -04:00
|
|
|
}
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-07-17 19:19:43 -04:00
|
|
|
MainWindow *pMainWindow = MainWindow::getInstance();
|
|
|
|
if (pMainWindow) {
|
2010-08-30 15:10:07 -04:00
|
|
|
QMenu *pStatusMenu = new QMenu();
|
|
|
|
pMainWindow->initializeStatusObject(pStatusMenu, true);
|
|
|
|
ui.statusButton->setMenu(pStatusMenu);
|
2010-07-17 19:19:43 -04:00
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
updateAvatar();
|
|
|
|
loadmystatusmessage();
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
|
|
|
|
|
|
|
insertPeers();
|
2010-06-17 13:39:32 -04:00
|
|
|
|
|
|
|
ui.clearButton->hide();
|
|
|
|
|
|
|
|
updateMessengerDisplay();
|
|
|
|
|
|
|
|
/* Hide platform specific features */
|
2008-04-24 08:58:27 -04:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
#endif
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
MessengerWindow::~MessengerWindow ()
|
|
|
|
{
|
|
|
|
// save settings
|
|
|
|
processSettings(false);
|
2010-07-17 19:19:43 -04:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-07-17 19:19:43 -04:00
|
|
|
MainWindow *pMainWindow = MainWindow::getInstance();
|
|
|
|
if (pMainWindow) {
|
2010-08-30 15:10:07 -04:00
|
|
|
pMainWindow->removeStatusObject(ui.statusButton);
|
2010-07-17 19:19:43 -04:00
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-07-18 07:43:39 -04:00
|
|
|
|
|
|
|
_instance = NULL;
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::processSettings(bool bLoad)
|
|
|
|
{
|
|
|
|
QHeaderView *header = ui.messengertreeWidget->header ();
|
|
|
|
|
|
|
|
Settings->beginGroup(_name);
|
|
|
|
|
|
|
|
if (bLoad) {
|
|
|
|
// load settings
|
|
|
|
|
|
|
|
// state of messenger tree
|
|
|
|
header->restoreState(Settings->value("MessengerTree").toByteArray());
|
|
|
|
|
|
|
|
// state of actionHide_Offline_Friends
|
|
|
|
ui.actionHide_Offline_Friends->setChecked(Settings->value("hideOfflineFriends", false).toBool());
|
|
|
|
|
|
|
|
// state of actionSort_by_State
|
|
|
|
ui.actionSort_by_State->setChecked(Settings->value("sortByState", false).toBool());
|
|
|
|
|
|
|
|
// state of actionRoot_is_decorated
|
|
|
|
ui.actionRoot_is_decorated->setChecked(Settings->value("rootIsDecorated", true).toBool());
|
|
|
|
on_actionRoot_is_decorated_activated();
|
|
|
|
} else {
|
|
|
|
// save settings
|
|
|
|
|
|
|
|
// state of messenger tree
|
|
|
|
Settings->setValue("MessengerTree", header->saveState());
|
|
|
|
|
|
|
|
// state of actionSort_by_State
|
|
|
|
Settings->setValue("sortByState", ui.actionSort_by_State->isChecked());
|
|
|
|
|
|
|
|
// state of actionHide_Offline_Friends
|
|
|
|
Settings->setValue("hideOfflineFriends", ui.actionHide_Offline_Friends->isChecked());
|
|
|
|
|
|
|
|
// state of actionRoot_is_decorated
|
|
|
|
Settings->setValue("rootIsDecorated", ui.actionRoot_is_decorated->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings->endGroup();
|
|
|
|
}
|
2010-04-20 04:42:45 -04:00
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point )
|
|
|
|
{
|
2010-02-15 18:47:12 -05:00
|
|
|
QTreeWidgetItem *c = getCurrentPeer();
|
2009-01-01 18:25:16 -05:00
|
|
|
|
|
|
|
QMenu contextMnu( this );
|
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* expandAll = new QAction(tr( "Expand all" ), &contextMnu );
|
2010-02-03 12:39:30 -05:00
|
|
|
connect( expandAll , SIGNAL( triggered() ), ui.messengertreeWidget, SLOT (expandAll()) );
|
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* collapseAll = new QAction(tr( "Collapse all" ), &contextMnu );
|
2010-02-03 12:39:30 -05:00
|
|
|
connect( collapseAll , SIGNAL( triggered() ), ui.messengertreeWidget, SLOT(collapseAll()) );
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* chatAct = new QAction(QIcon(IMAGE_CHAT), tr( "Chat" ), &contextMnu );
|
2010-08-30 09:03:12 -04:00
|
|
|
if (c) {
|
|
|
|
connect( chatAct , SIGNAL( triggered() ), this, SLOT( chatfriendproxy() ) );
|
|
|
|
} else {
|
|
|
|
chatAct->setDisabled(true);
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* sendMessageAct = new QAction(QIcon(IMAGE_MSG), tr( "Message Friend" ), &contextMnu );
|
2010-08-30 09:03:12 -04:00
|
|
|
if (c) {
|
|
|
|
connect( sendMessageAct , SIGNAL( triggered() ), this, SLOT( sendMessage() ) );
|
|
|
|
} else {
|
|
|
|
sendMessageAct->setDisabled(true);
|
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* connectfriendAct = new QAction(QIcon(IMAGE_CONNECT), tr( "Connect To Friend" ), &contextMnu );
|
2010-08-30 09:03:12 -04:00
|
|
|
if (c) {
|
|
|
|
connect( connectfriendAct , SIGNAL( triggered() ), this, SLOT( connectfriend() ) );
|
|
|
|
} else {
|
|
|
|
connectfriendAct->setDisabled(true);
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* configurefriendAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Peer Details" ), &contextMnu );
|
2010-08-30 09:03:12 -04:00
|
|
|
if (c) {
|
|
|
|
connect( configurefriendAct , SIGNAL( triggered() ), this, SLOT( configurefriend() ) );
|
|
|
|
} else {
|
|
|
|
configurefriendAct->setDisabled(true);
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* recommendfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Recomend this Friend to..." ), &contextMnu );
|
2010-08-30 09:03:12 -04:00
|
|
|
if (c && c->type() == 0) {
|
|
|
|
connect( recommendfriendAct , SIGNAL( triggered() ), this, SLOT( recommendfriend() ) );
|
|
|
|
} else {
|
|
|
|
recommendfriendAct->setDisabled(true);
|
|
|
|
}
|
2010-07-15 07:25:34 -04:00
|
|
|
|
|
|
|
QAction* pastePersonAct = new QAction(QIcon(IMAGE_PASTELINK), tr( "Paste retroshare Link" ), &contextMnu );
|
|
|
|
if(!RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) {
|
|
|
|
connect( pastePersonAct , SIGNAL( triggered() ), this, SLOT( pastePerson() ) );
|
|
|
|
} else {
|
|
|
|
pastePersonAct->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//QAction* profileviewAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Profile View" ), &contextMnu );
|
2010-02-03 12:39:30 -05:00
|
|
|
//connect( profileviewAct , SIGNAL( triggered() ), this, SLOT( viewprofile() ) );
|
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* exportfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Export Friend" ), &contextMnu );
|
2010-08-30 09:03:12 -04:00
|
|
|
if (c) {
|
|
|
|
connect( exportfriendAct , SIGNAL( triggered() ), this, SLOT( exportfriend() ) );
|
2010-02-03 12:39:30 -05:00
|
|
|
} else {
|
2010-08-30 09:03:12 -04:00
|
|
|
exportfriendAct->setDisabled(true);
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
2010-08-30 09:03:12 -04:00
|
|
|
QAction* removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Deny Friend" ), &contextMnu );
|
|
|
|
if (c) {
|
|
|
|
if (c->type() == 1) {
|
|
|
|
//this is a SSL key
|
|
|
|
removefriendAct->setText(tr( "Remove Friend Location"));
|
|
|
|
}
|
|
|
|
connect( removefriendAct , SIGNAL( triggered() ), this, SLOT( removefriend() ) );
|
|
|
|
} else {
|
|
|
|
removefriendAct->setDisabled(true);
|
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-02-03 12:39:30 -05:00
|
|
|
|
|
|
|
QWidget *widget = new QWidget();
|
|
|
|
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-07-15 07:25:34 -04:00
|
|
|
QHBoxLayout *hbox = new QHBoxLayout(&contextMnu);
|
2010-02-03 12:39:30 -05:00
|
|
|
hbox->setMargin(0);
|
|
|
|
hbox->setSpacing(6);
|
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
QLabel *iconLabel = new QLabel(&contextMnu);
|
2010-06-14 07:57:22 -04:00
|
|
|
iconLabel->setPixmap(QPixmap(":/images/user/friends24.png"));
|
2010-02-03 12:39:30 -05:00
|
|
|
iconLabel->setMaximumSize( iconLabel->frameSize().height() + 24, 24 );
|
|
|
|
hbox->addWidget(iconLabel);
|
2010-07-15 07:25:34 -04:00
|
|
|
|
|
|
|
QLabel *textLabel;
|
2010-08-30 09:03:12 -04:00
|
|
|
textLabel = new QLabel( tr("<strong>RetroShare instance</strong>"), widget );
|
|
|
|
if (c && c->type() == 0) {
|
2010-02-03 12:39:30 -05:00
|
|
|
//this is a GPG key
|
2010-08-30 09:03:12 -04:00
|
|
|
textLabel->setText(tr("<strong>GPG Key</strong>"));
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
hbox->addWidget(textLabel);
|
2010-07-15 07:25:34 -04:00
|
|
|
|
|
|
|
QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
2010-02-03 12:39:30 -05:00
|
|
|
hbox->addItem(spacerItem);
|
|
|
|
|
|
|
|
widget->setLayout( hbox );
|
|
|
|
|
|
|
|
QWidgetAction *widgetAction = new QWidgetAction(this);
|
|
|
|
widgetAction->setDefaultWidget(widget);
|
2007-11-16 20:35:52 -05:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
contextMnu.addAction( widgetAction);
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2007-11-14 22:18:48 -05:00
|
|
|
contextMnu.addAction( chatAct);
|
|
|
|
contextMnu.addAction( sendMessageAct);
|
|
|
|
contextMnu.addAction( configurefriendAct);
|
2010-02-03 12:39:30 -05:00
|
|
|
//contextMnu.addAction( profileviewAct);
|
2010-08-30 09:03:12 -04:00
|
|
|
contextMnu.addAction( recommendfriendAct);
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-08-28 15:50:38 -04:00
|
|
|
contextMnu.addAction( connectfriendAct);
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-07-15 07:25:34 -04:00
|
|
|
contextMnu.addAction(pastePersonAct);
|
2010-02-03 12:39:30 -05:00
|
|
|
contextMnu.addAction( removefriendAct);
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-02-03 12:39:30 -05:00
|
|
|
//contextMnu.addAction( exportfriendAct);
|
|
|
|
contextMnu.addSeparator();
|
|
|
|
contextMnu.addAction( expandAll);
|
|
|
|
contextMnu.addAction( collapseAll);
|
2010-05-14 16:55:44 -04:00
|
|
|
contextMnu.exec(QCursor::pos());
|
2009-01-01 18:25:16 -05:00
|
|
|
}
|
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
void MessengerWindow::updateMessengerDisplay()
|
|
|
|
{
|
2010-07-20 15:45:07 -04:00
|
|
|
if (RsAutoUpdatePage::eventsLocked() == false) {
|
2010-04-27 08:21:39 -04:00
|
|
|
insertPeers();
|
2010-07-20 15:45:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
timer->start();
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* get the list of peers from the RsIface. */
|
|
|
|
void MessengerWindow::insertPeers()
|
|
|
|
{
|
2010-06-17 13:39:32 -04:00
|
|
|
std::list<std::string> gpgFriends;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
std::list<StatusInfo> statusInfo;
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-08-20 14:45:44 -04:00
|
|
|
rsStatus->getStatusList(statusInfo);
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
if (!rsPeers) {
|
|
|
|
/* not ready yet! */
|
|
|
|
std::cerr << "PeersDialog::insertPeers() not ready yet : rsPeers unintialized." << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
std::list<std::string> privateChatIds;
|
|
|
|
rsMsgs->getPrivateChatQueueIds(privateChatIds);
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
rsPeers->getGPGAcceptedList(gpgFriends);
|
|
|
|
|
2010-07-09 18:57:44 -04:00
|
|
|
std::string sOwnId = rsPeers->getGPGOwnId();
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
//add own gpg id, if we have more than on location (ssl client)
|
|
|
|
std::list<std::string> ownSslContacts;
|
2010-07-09 18:57:44 -04:00
|
|
|
rsPeers->getSSLChildListOfGPGId(sOwnId, ownSslContacts);
|
2010-06-17 13:39:32 -04:00
|
|
|
if (ownSslContacts.size() > 0) {
|
2010-07-09 18:57:44 -04:00
|
|
|
gpgFriends.push_back(sOwnId);
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get a link to the table */
|
|
|
|
QTreeWidget *peertreeWidget = ui.messengertreeWidget;
|
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
bool sortState = ui.actionSort_by_State->isChecked();
|
|
|
|
bool hideOfflineFriends = ui.actionHide_Offline_Friends->isChecked();
|
2010-06-17 13:39:32 -04:00
|
|
|
|
|
|
|
//remove items that are not fiends anymore
|
2010-08-03 08:35:26 -04:00
|
|
|
int itemCount = peertreeWidget->topLevelItemCount();
|
2010-06-17 13:39:32 -04:00
|
|
|
int index = 0;
|
2010-08-03 08:35:26 -04:00
|
|
|
while (index < itemCount) {
|
2010-06-25 10:19:48 -04:00
|
|
|
std::string gpg_widget_id = peertreeWidget->topLevelItem(index)->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
|
2010-08-25 14:31:56 -04:00
|
|
|
if (std::find(gpgFriends.begin(), gpgFriends.end(), gpg_widget_id) == gpgFriends.end()) {
|
2010-06-17 13:39:32 -04:00
|
|
|
delete (peertreeWidget->takeTopLevelItem(index));
|
2010-08-03 08:35:26 -04:00
|
|
|
// count again
|
|
|
|
itemCount = peertreeWidget->topLevelItemCount();
|
2010-06-17 13:39:32 -04:00
|
|
|
} else {
|
|
|
|
index++;
|
2008-01-25 03:49:40 -05:00
|
|
|
}
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
//add the gpg friends
|
|
|
|
for(it = gpgFriends.begin(); it != gpgFriends.end(); it++) {
|
2010-07-09 18:57:44 -04:00
|
|
|
// if (*it == sOwnId) {
|
2010-06-17 13:39:32 -04:00
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/* make a widget per friend */
|
|
|
|
QTreeWidgetItem *gpg_item = NULL;
|
2010-06-25 10:19:48 -04:00
|
|
|
QTreeWidgetItem *gpg_item_loop = NULL;
|
|
|
|
QString gpgid = QString::fromStdString(*it);
|
2010-08-03 08:35:26 -04:00
|
|
|
itemCount = peertreeWidget->topLevelItemCount();
|
|
|
|
for (int nIndex = 0; nIndex < itemCount; nIndex++) {
|
2010-06-25 10:19:48 -04:00
|
|
|
gpg_item_loop = peertreeWidget->topLevelItem(nIndex);
|
|
|
|
if (gpg_item_loop->data(COLUMN_DATA, ROLE_ID).toString() == gpgid) {
|
|
|
|
gpg_item = gpg_item_loop;
|
|
|
|
break;
|
|
|
|
}
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
RsPeerDetails detail;
|
|
|
|
if ((!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection)
|
2010-07-09 18:57:44 -04:00
|
|
|
&& detail.gpg_id != sOwnId) {
|
2010-06-17 13:39:32 -04:00
|
|
|
//don't accept anymore connection, remove from the view
|
|
|
|
delete (peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item)));
|
|
|
|
continue;
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
if (gpg_item == NULL) {
|
|
|
|
gpg_item = new MyMessengerTreeWidgetItem(peertreeWidget, 0); //set type to 0 for custom popup menu
|
|
|
|
gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
2010-01-25 17:08:23 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
gpg_item -> setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter );
|
2010-08-31 18:17:02 -04:00
|
|
|
gpg_item -> setSizeHint(COLUMN_NAME, QSize( 40,40 ) );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
/* not displayed, used to find back the item */
|
2010-06-25 10:19:48 -04:00
|
|
|
gpg_item -> setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.id));
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
//remove items that are not friends anymore
|
2010-08-03 08:35:26 -04:00
|
|
|
int childCount = gpg_item->childCount();
|
2010-06-17 13:39:32 -04:00
|
|
|
int childIndex = 0;
|
2010-08-03 08:35:26 -04:00
|
|
|
while (childIndex < childCount) {
|
2010-06-25 10:19:48 -04:00
|
|
|
std::string ssl_id = gpg_item->child(childIndex)->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
|
2010-06-17 13:39:32 -04:00
|
|
|
if (!rsPeers->isFriend(ssl_id)) {
|
|
|
|
delete (gpg_item->takeChild(childIndex));
|
2010-08-03 08:35:26 -04:00
|
|
|
// count again
|
|
|
|
childCount = gpg_item->childCount();
|
2010-02-03 12:39:30 -05:00
|
|
|
} else {
|
2010-06-17 13:39:32 -04:00
|
|
|
childIndex++;
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
//update the childs (ssl certs)
|
|
|
|
bool gpg_connected = false;
|
|
|
|
bool gpg_online = false;
|
2010-09-01 13:56:15 -04:00
|
|
|
bool gpg_hasPrivateChat = false;
|
2010-06-17 13:39:32 -04:00
|
|
|
std::list<std::string> sslContacts;
|
2010-09-08 14:36:36 -04:00
|
|
|
std::map<std::string, std::string> sslLocations;
|
|
|
|
std::map<std::string, QString> sslCustomStateStrings;
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
rsPeers->getSSLChildListOfGPGId(detail.gpg_id, sslContacts);
|
|
|
|
for(std::list<std::string>::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); sslIt++) {
|
|
|
|
QTreeWidgetItem *sslItem = NULL;
|
|
|
|
|
|
|
|
//find the corresponding sslItem child item of the gpg item
|
|
|
|
bool newChild = true;
|
2010-08-03 08:35:26 -04:00
|
|
|
childCount = gpg_item->childCount();
|
|
|
|
for (int childIndex = 0; childIndex < childCount; childIndex++) {
|
2010-06-25 10:19:48 -04:00
|
|
|
if (gpg_item->child(childIndex)->data(COLUMN_DATA, ROLE_ID).toString().toStdString() == *sslIt) {
|
2010-06-17 13:39:32 -04:00
|
|
|
sslItem = gpg_item->child(childIndex);
|
|
|
|
newChild = false;
|
|
|
|
break;
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
RsPeerDetails sslDetail;
|
|
|
|
if (!rsPeers->getPeerDetails(*sslIt, sslDetail) || !rsPeers->isFriend(*sslIt)) {
|
|
|
|
std::cerr << "Removing widget from the view : id : " << *sslIt << std::endl;
|
|
|
|
if (sslItem) {
|
|
|
|
//child has disappeared, remove it from the gpg_item
|
|
|
|
gpg_item->removeChild(sslItem);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
if (sslItem == NULL) {
|
|
|
|
sslItem = new MyMessengerTreeWidgetItem(peertreeWidget, 1); //set type to 1 for custom popup menu
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
|
|
|
|
/* not displayed, used to find back the item */
|
2010-06-25 10:19:48 -04:00
|
|
|
sslItem -> setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(sslDetail.id));
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
/* store location */
|
|
|
|
sslLocations[sslDetail.id] = sslDetail.location;
|
|
|
|
|
2010-08-06 17:14:25 -04:00
|
|
|
QString sCustomString;
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-08-06 17:14:25 -04:00
|
|
|
if (sslDetail.state & RS_PEER_STATE_CONNECTED) {
|
|
|
|
sCustomString = QString::fromStdString(rsMsgs->getCustomStateString(sslDetail.id));
|
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-08-06 17:14:25 -04:00
|
|
|
if (sCustomString.isEmpty()) {
|
2010-06-17 13:39:32 -04:00
|
|
|
sslItem -> setText( COLUMN_NAME, tr("location : ") + QString::fromStdString(sslDetail.location) + " " + QString::fromStdString(sslDetail.autoconnect));
|
|
|
|
sslItem -> setToolTip( COLUMN_NAME, tr("location : ") + QString::fromStdString(sslDetail.location));
|
2010-08-06 17:14:25 -04:00
|
|
|
} else {
|
|
|
|
sslItem -> setText( COLUMN_NAME, tr("location : ") + QString::fromStdString(sslDetail.location) + " " + QString::fromStdString(sslDetail.autoconnect) );
|
|
|
|
sslItem -> setToolTip( COLUMN_NAME, tr("location : ") + QString::fromStdString(sslDetail.location) + tr(" - ") + sCustomString);
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
/* store custom state string */
|
|
|
|
sslCustomStateStrings[sslDetail.id] = sCustomString;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
QIcon sslIcon;
|
2010-09-08 14:36:36 -04:00
|
|
|
QFont sslFont;
|
|
|
|
QColor sslColor;
|
2010-06-17 13:39:32 -04:00
|
|
|
if (sslDetail.state & RS_PEER_STATE_CONNECTED) {
|
|
|
|
sslItem->setHidden(false);
|
|
|
|
gpg_connected = true;
|
2010-05-16 07:10:13 -04:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifdef MINIMAL_RSGUI
|
|
|
|
// to show the gpg as online, remove it with MINIMAL_RSGUI
|
|
|
|
QFont font1;
|
|
|
|
font1.setBold(true);
|
|
|
|
|
|
|
|
gpg_item->setIcon(COLUMN_NAME,(QIcon(IMAGE_ONLINE)));
|
|
|
|
gpg_item->setToolTip(COLUMN_NAME, tr("Peer Online"));
|
2010-09-08 14:36:36 -04:00
|
|
|
gpg_item->setData(COLUMN_NAME, ROLE_SORT, BuildStateSortString(sortState, gpg_item->text(COLUMN_NAME), PEER_STATE_ONLINE));
|
2010-08-31 16:00:49 -04:00
|
|
|
|
|
|
|
for(i = 0; i < COLUMN_COUNT; i++) {
|
|
|
|
gpg_item->setTextColor(i,(Qt::darkBlue));
|
|
|
|
gpg_item->setFont(i,font1);
|
|
|
|
}
|
|
|
|
#endif // MINIMAL_RSGUI
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
/* change color and icon */
|
2010-09-01 13:56:15 -04:00
|
|
|
sslIcon = QIcon(":/images/connect_established.png");
|
2010-09-08 14:36:36 -04:00
|
|
|
sslFont.setBold(true);
|
|
|
|
sslColor = Qt::darkBlue;
|
2010-06-17 13:39:32 -04:00
|
|
|
} else if (sslDetail.state & RS_PEER_STATE_ONLINE) {
|
2010-09-08 14:36:36 -04:00
|
|
|
sslItem->setHidden(hideOfflineFriends);
|
2010-06-17 13:39:32 -04:00
|
|
|
gpg_online = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
sslFont.setBold(true);
|
|
|
|
sslColor = Qt::black;
|
2010-06-17 13:39:32 -04:00
|
|
|
} else {
|
2010-09-08 14:36:36 -04:00
|
|
|
sslItem->setHidden(hideOfflineFriends);
|
2010-06-17 13:39:32 -04:00
|
|
|
if (sslDetail.autoconnect !="Offline") {
|
2010-09-01 13:56:15 -04:00
|
|
|
sslIcon = QIcon(":/images/connect_creating.png");
|
2010-02-03 12:39:30 -05:00
|
|
|
} else {
|
2010-09-01 13:56:15 -04:00
|
|
|
sslIcon = QIcon(":/images/connect_no.png");
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
sslFont.setBold(false);
|
|
|
|
sslColor = Qt::black;
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
2010-09-01 13:56:15 -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-09-08 14:36:36 -04:00
|
|
|
for (int i = 0; i < COLUMN_COUNT; i++) {
|
|
|
|
sslItem -> setTextColor(i, sslColor);
|
|
|
|
sslItem -> setFont(i, sslFont);
|
|
|
|
}
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
std::cerr << "PeersDialog::insertPeers() inserting sslItem." << std::endl;
|
|
|
|
#endif
|
|
|
|
/* add sl child to the list. If item is already in the list, it won't be duplicated thanks to Qt */
|
|
|
|
gpg_item->addChild(sslItem);
|
|
|
|
if (newChild) {
|
|
|
|
gpg_item->setExpanded(true);
|
|
|
|
}
|
|
|
|
}
|
2010-04-15 08:02:23 -04:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
int i = 0;
|
2010-09-01 13:56:15 -04:00
|
|
|
QIcon gpgIcon;
|
2010-09-08 14:36:36 -04:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
if (gpg_connected) {
|
|
|
|
gpg_item->setHidden(false);
|
|
|
|
//gpg_item -> setText(COLUMN_STATE, tr("Online")); // set to online regardless on update
|
2010-04-15 08:02:23 -04:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-09-08 14:36:36 -04:00
|
|
|
int bestPeerState = 0; // for gpg item
|
|
|
|
std::string bestSslId; // for gpg item
|
2010-04-15 08:02:23 -04:00
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
std::list<StatusInfo>::iterator it = statusInfo.begin();
|
2010-06-17 13:39:32 -04:00
|
|
|
for(; it != statusInfo.end() ; it++){
|
2010-04-20 04:42:45 -04:00
|
|
|
|
2010-06-05 18:42:32 -04:00
|
|
|
// don't forget the kids
|
2010-09-08 14:36:36 -04:00
|
|
|
std::list<std::string>::iterator cont_it = sslContacts.begin();
|
|
|
|
for(; cont_it != sslContacts.end(); cont_it++){
|
2010-04-20 04:42:45 -04:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
if((it->id == *cont_it) && (rsPeers->isOnline(*cont_it))) {
|
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
int peerState = 0;
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
std::string status;
|
|
|
|
rsStatus->getStatusString(it->status, status);
|
|
|
|
gpg_item -> setText(COLUMN_STATE, QString::fromStdString(status));
|
|
|
|
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
int size = 0 ;
|
|
|
|
rsMsgs->getAvatarData(it->id ,data,size);
|
|
|
|
|
|
|
|
if(size != 0){
|
|
|
|
QPixmap avatar ;
|
|
|
|
avatar.loadFromData(data,size,"PNG") ;
|
|
|
|
QIcon avatar_icon(avatar);
|
2010-09-01 13:56:15 -04:00
|
|
|
gpg_item-> setIcon(COLUMN_STATE, avatar_icon);
|
2010-06-17 13:39:32 -04:00
|
|
|
delete[] data;
|
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
} else {
|
2010-06-17 13:39:32 -04:00
|
|
|
gpg_item -> setIcon(COLUMN_STATE,(QIcon(":/images/no_avatar_70.png")));
|
|
|
|
}
|
2010-08-03 08:35:26 -04:00
|
|
|
|
|
|
|
switch (it->status) {
|
|
|
|
case RS_STATUS_INACTIVE:
|
2010-09-08 14:36:36 -04:00
|
|
|
peerState = PEER_STATE_INACTIVE;
|
2010-08-03 08:35:26 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RS_STATUS_ONLINE:
|
2010-09-08 14:36:36 -04:00
|
|
|
peerState = PEER_STATE_ONLINE;
|
2010-08-03 08:35:26 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RS_STATUS_AWAY:
|
2010-09-08 14:36:36 -04:00
|
|
|
peerState = PEER_STATE_AWAY;
|
2010-08-03 08:35:26 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RS_STATUS_BUSY:
|
2010-09-08 14:36:36 -04:00
|
|
|
peerState = PEER_STATE_BUSY;
|
|
|
|
break;
|
|
|
|
}
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
/* find the best ssl contact for the gpg item */
|
|
|
|
if (bestPeerState == 0) {
|
|
|
|
/* first ssl contact */
|
|
|
|
bestPeerState = peerState;
|
|
|
|
bestSslId = *cont_it;
|
|
|
|
} else if (peerState < bestPeerState) {
|
|
|
|
/* higher state */
|
|
|
|
bestPeerState = peerState;
|
|
|
|
bestSslId = *cont_it;
|
|
|
|
} else if (peerState == bestPeerState) {
|
|
|
|
/* equal state */
|
|
|
|
|
|
|
|
/* use the ssl id with existing custom state string */
|
|
|
|
std::map<std::string, QString>::iterator it1 = sslCustomStateStrings.find(bestSslId);
|
|
|
|
std::map<std::string, QString>::iterator it2 = sslCustomStateStrings.find(*cont_it);
|
|
|
|
|
|
|
|
if (it1 == sslCustomStateStrings.end()) {
|
|
|
|
if (it2 == sslCustomStateStrings.end()) {
|
|
|
|
/* both with no custom state string ... use first */
|
|
|
|
} else {
|
|
|
|
/* second with a custom state string ... use second */
|
|
|
|
bestPeerState = peerState;
|
|
|
|
bestSslId = *cont_it;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* use first */
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
}
|
2010-09-08 14:36:36 -04:00
|
|
|
|
|
|
|
if (bestPeerState) {
|
|
|
|
QFont font;
|
|
|
|
font.setBold(true);
|
|
|
|
|
|
|
|
switch (bestPeerState) {
|
|
|
|
case PEER_STATE_INACTIVE:
|
|
|
|
gpgIcon = QIcon(IMAGE_INACTIVE);
|
|
|
|
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Idle"));
|
|
|
|
|
|
|
|
for(i = 0; i < COLUMN_COUNT; i++) {
|
|
|
|
gpg_item -> setTextColor(i,(Qt::gray));
|
|
|
|
gpg_item -> setFont(i,font);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PEER_STATE_ONLINE:
|
|
|
|
gpgIcon = QIcon(IMAGE_ONLINE);
|
|
|
|
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Online"));
|
|
|
|
|
|
|
|
for(i = 0; i < COLUMN_COUNT; i++) {
|
|
|
|
gpg_item -> setTextColor(i,(Qt::darkBlue));
|
|
|
|
gpg_item -> setFont(i,font);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PEER_STATE_AWAY:
|
|
|
|
gpgIcon = QIcon(IMAGE_AWAY);
|
|
|
|
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Away"));
|
|
|
|
|
|
|
|
for(i = 0; i < COLUMN_COUNT; i++) {
|
|
|
|
gpg_item -> setTextColor(i,(Qt::gray));
|
|
|
|
gpg_item -> setFont(i,font);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PEER_STATE_BUSY:
|
|
|
|
gpgIcon = QIcon(IMAGE_BUSY);
|
|
|
|
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Busy"));
|
|
|
|
|
|
|
|
for(i = 0; i < COLUMN_COUNT; i++) {
|
|
|
|
gpg_item -> setTextColor(i,(Qt::gray));
|
|
|
|
gpg_item -> setFont(i,font);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name));
|
|
|
|
|
|
|
|
std::map<std::string, QString>::iterator customStateString = sslCustomStateStrings.find(bestSslId);
|
|
|
|
if (customStateString == sslCustomStateStrings.end()) {
|
|
|
|
std::map<std::string, std::string>::iterator location = sslLocations.find(bestSslId);
|
|
|
|
if (location == sslLocations.end()) {
|
|
|
|
/* show only the name */
|
|
|
|
gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name));
|
|
|
|
} else {
|
|
|
|
/* show the name with location */
|
|
|
|
gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name) + "\n" + QString::fromStdString(location->second));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* show the name with custom state string */
|
|
|
|
gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name) + "\n" + customStateString->second);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* show only the name */
|
|
|
|
gpgIcon = QIcon(IMAGE_ONLINE);
|
|
|
|
gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name));
|
|
|
|
bestPeerState = PEER_STATE_ONLINE; // show as online
|
|
|
|
}
|
|
|
|
|
|
|
|
gpg_item->setData(COLUMN_NAME, ROLE_SORT, BuildStateSortString(sortState, gpg_item->text(COLUMN_NAME), bestPeerState));
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-06-17 13:39:32 -04:00
|
|
|
} else if (gpg_online) {
|
2010-09-08 14:36:36 -04:00
|
|
|
gpg_item->setHidden(hideOfflineFriends);
|
|
|
|
gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name));
|
2010-09-01 13:56:15 -04:00
|
|
|
gpgIcon = QIcon(IMAGE_AVAIBLE);
|
2010-09-08 14:36:36 -04:00
|
|
|
gpg_item->setData(COLUMN_NAME, ROLE_SORT, BuildStateSortString(sortState, gpg_item->text(COLUMN_NAME), PEER_STATE_ONLINE));
|
2010-06-17 13:39:32 -04:00
|
|
|
//gpg_item -> setText(COLUMN_STATE, tr("Available"));
|
|
|
|
QFont font;
|
|
|
|
font.setBold(true);
|
|
|
|
for(i = 0; i < COLUMN_COUNT; i++) {
|
|
|
|
gpg_item -> setTextColor(i,(Qt::black));
|
|
|
|
gpg_item -> setFont(i,font);
|
|
|
|
}
|
|
|
|
} else {
|
2010-09-08 14:36:36 -04:00
|
|
|
gpg_item->setHidden(hideOfflineFriends);
|
|
|
|
gpg_item->setText(COLUMN_NAME, QString::fromStdString(detail.name));
|
2010-09-01 13:56:15 -04:00
|
|
|
gpgIcon = QIcon(IMAGE_OFFLINE);
|
2010-09-08 14:36:36 -04:00
|
|
|
gpg_item->setData(COLUMN_NAME, ROLE_SORT, BuildStateSortString(sortState, gpg_item->text(COLUMN_NAME), PEER_STATE_OFFLINE));
|
2010-06-17 13:39:32 -04:00
|
|
|
//gpg_item -> setText(COLUMN_STATE, tr("Offline"));
|
|
|
|
QFont font;
|
|
|
|
font.setBold(false);
|
|
|
|
for(i = 0; i < COLUMN_COUNT; i++) {
|
|
|
|
gpg_item -> setTextColor(i,(Qt::black));
|
|
|
|
gpg_item -> setFont(i,font);
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
if (gpg_hasPrivateChat) {
|
|
|
|
gpgIcon = QIcon(":/images/chat.png");
|
|
|
|
}
|
|
|
|
|
|
|
|
gpg_item -> setIcon(COLUMN_NAME, gpgIcon);
|
|
|
|
|
2010-09-08 14:36:36 -04:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
/* add gpg item to the list. If item is already in the list, it won't be duplicated thanks to Qt */
|
|
|
|
peertreeWidget->addTopLevelItem(gpg_item);
|
2010-07-18 07:43:39 -04:00
|
|
|
|
|
|
|
if (expandedPeers && expandedPeers->find(detail.gpg_id) != expandedPeers->end()) {
|
|
|
|
/* we have information about expanded peers and the peer was expanded */
|
|
|
|
gpg_item->setExpanded(true);
|
|
|
|
}
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
|
|
|
|
2010-05-23 20:59:12 -04:00
|
|
|
if (ui.filterPatternLineEdit->text().isEmpty() == false) {
|
|
|
|
FilterItems();
|
|
|
|
}
|
2010-07-18 07:43:39 -04:00
|
|
|
|
|
|
|
if (expandedPeers) {
|
|
|
|
/* we don't need the informations anymore */
|
|
|
|
delete(expandedPeers);
|
|
|
|
expandedPeers = NULL;
|
|
|
|
}
|
2010-08-30 09:03:12 -04:00
|
|
|
|
|
|
|
QTreeWidgetItem *c = getCurrentPeer();
|
|
|
|
if (c && c->isHidden()) {
|
|
|
|
// active item is hidden, deselect it
|
|
|
|
ui.messengertreeWidget->setCurrentItem(NULL);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Utility Fns */
|
2010-02-03 12:39:30 -05:00
|
|
|
std::string getPeersRsCertId(QTreeWidgetItem *i)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-06-25 10:19:48 -04:00
|
|
|
std::string id = i -> data(COLUMN_DATA, ROLE_ID).toString().toStdString();
|
2010-06-17 13:39:32 -04:00
|
|
|
return id;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-02-03 12:39:30 -05:00
|
|
|
/** Add a Friend ShortCut */
|
|
|
|
void MessengerWindow::addFriend()
|
|
|
|
{
|
2010-05-02 20:09:55 -04:00
|
|
|
ConnectFriendWizard connwiz (this);
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-05-02 20:09:55 -04:00
|
|
|
connwiz.exec ();
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/** Open a QFileDialog to browse for export a file. */
|
2010-02-03 12:39:30 -05:00
|
|
|
void MessengerWindow::exportfriend()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-02-03 12:39:30 -05:00
|
|
|
QTreeWidgetItem *c = getCurrentPeer();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
std::cerr << "PeersDialog::exportfriend()" << std::endl;
|
|
|
|
#endif
|
|
|
|
if (!c)
|
|
|
|
{
|
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
std::cerr << "PeersDialog::exportfriend() None Selected -- sorry" << std::endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
std::string id = getPeersRsCertId(c);
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Certificate"), "",
|
|
|
|
tr("Certificates (*.pqi)"));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
std::string file = fileName.toStdString();
|
|
|
|
if (file != "")
|
|
|
|
{
|
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
std::cerr << "PeersDialog::exportfriend() Saving to: " << file << std::endl;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
if (rsPeers)
|
|
|
|
{
|
|
|
|
rsPeers->saveCertificateToFile(id, file);
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
void MessengerWindow::chatfriendproxy()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-06-17 13:39:32 -04:00
|
|
|
chatfriend(getCurrentPeer());
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
void MessengerWindow::chatfriend(QTreeWidgetItem *pPeer)
|
|
|
|
{
|
|
|
|
if (pPeer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-04 18:12:35 -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
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
QTreeWidgetItem *MessengerWindow::getCurrentPeer()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-02-03 12:39:30 -05:00
|
|
|
/* get the current, and extract the Id */
|
|
|
|
|
|
|
|
/* get a link to the table */
|
|
|
|
QTreeWidget *peerWidget = ui.messengertreeWidget;
|
|
|
|
QTreeWidgetItem *item = peerWidget -> currentItem();
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
std::cerr << "Invalid Current Item" << std::endl;
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
/* 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();
|
|
|
|
#endif
|
|
|
|
return item;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-02-03 12:39:30 -05:00
|
|
|
void MessengerWindow::removefriend()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-02-03 12:39:30 -05:00
|
|
|
QTreeWidgetItem *c = getCurrentPeer();
|
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
std::cerr << "PeersDialog::removefriend()" << std::endl;
|
|
|
|
#endif
|
|
|
|
if (!c)
|
|
|
|
{
|
|
|
|
#ifdef PEERS_DEBUG
|
|
|
|
std::cerr << "PeersDialog::removefriend() Noone Selected -- sorry" << std::endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rsPeers)
|
|
|
|
{
|
|
|
|
rsPeers->removeFriend(getPeersRsCertId(c));
|
|
|
|
emit friendsUpdated() ;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
void MessengerWindow::connectfriend()
|
|
|
|
{
|
2010-08-28 15:50:38 -04:00
|
|
|
QTreeWidgetItem *c = getCurrentPeer();
|
2010-02-03 12:39:30 -05:00
|
|
|
#ifdef PEERS_DEBUG
|
2010-08-28 15:50:38 -04:00
|
|
|
std::cerr << "PeersDialog::connectfriend()" << std::endl;
|
2010-02-03 12:39:30 -05:00
|
|
|
#endif
|
2010-08-28 15:50:38 -04:00
|
|
|
if (!c)
|
|
|
|
{
|
2010-02-03 12:39:30 -05:00
|
|
|
#ifdef PEERS_DEBUG
|
2010-08-28 15:50:38 -04:00
|
|
|
std::cerr << "PeersDialog::connectfriend() Noone Selected -- sorry" << std::endl;
|
2010-02-03 12:39:30 -05:00
|
|
|
#endif
|
2010-08-28 15:50:38 -04:00
|
|
|
return;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-08-28 15:50:38 -04:00
|
|
|
if (rsPeers)
|
|
|
|
{
|
|
|
|
if (c->type() == 0) {
|
|
|
|
int childCount = c->childCount();
|
|
|
|
for (int childIndex = 0; childIndex < childCount; childIndex++) {
|
|
|
|
QTreeWidgetItem *item = c->child(childIndex);
|
|
|
|
if (item->type() == 1) {
|
|
|
|
rsPeers->connectAttempt(getPeersRsCertId(item));
|
|
|
|
item->setIcon(COLUMN_NAME,(QIcon(IMAGE_CONNECT2)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//this is a SSL key
|
|
|
|
rsPeers->connectAttempt(getPeersRsCertId(c));
|
|
|
|
c->setIcon(COLUMN_NAME,(QIcon(IMAGE_CONNECT2)));
|
|
|
|
}
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2007-11-14 22:18:48 -05:00
|
|
|
/* GUI stuff -> don't do anything directly with Control */
|
2010-02-03 12:39:30 -05:00
|
|
|
void MessengerWindow::configurefriend()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-02-03 12:39:30 -05:00
|
|
|
ConfCertDialog::show(getPeersRsCertId(getCurrentPeer()));
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
void MessengerWindow::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 MessengerWindow::pastePerson()
|
|
|
|
{
|
|
|
|
RSLinkClipboard::process(RetroShareLink::TYPE_PERSON, RSLINK_PROCESS_NOTIFY_ERROR);
|
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-07-15 07:25:34 -04:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
//============================================================================
|
|
|
|
|
2009-01-01 18:25:16 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
void MessengerWindow::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
2010-07-18 07:43:39 -04:00
|
|
|
/* save the expanded peers */
|
|
|
|
if (expandedPeers == NULL) {
|
|
|
|
expandedPeers = new std::set<std::string>;
|
|
|
|
} else {
|
|
|
|
expandedPeers->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int nIndex = 0; nIndex < ui.messengertreeWidget->topLevelItemCount(); nIndex++) {
|
|
|
|
QTreeWidgetItem *item = ui.messengertreeWidget->topLevelItem(nIndex);
|
|
|
|
if (item->isExpanded()) {
|
|
|
|
expandedPeers->insert(expandedPeers->end(), item->data(COLUMN_DATA, ROLE_ID).toString().toStdString());
|
|
|
|
}
|
|
|
|
}
|
2007-11-18 18:35:53 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
LogoBar & MessengerWindow::getLogoBar() const {
|
|
|
|
return *_rsLogoBarmessenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef MINIMAL_RSGUI
|
2009-01-08 12:29:01 -05:00
|
|
|
/** Shows Share Manager */
|
|
|
|
void MessengerWindow::openShareManager()
|
|
|
|
{
|
2009-08-03 15:43:52 -04:00
|
|
|
ShareManager::showYourself();
|
2009-01-08 12:29:01 -05:00
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
void MessengerWindow::sendMessage()
|
|
|
|
{
|
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;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-25 10:19:48 -04:00
|
|
|
std::string id = peer->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
|
2010-06-17 13:39:32 -04:00
|
|
|
MessageComposer::msgFriend(id);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
void MessengerWindow::changeAvatarClicked()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
updateAvatar();
|
|
|
|
}
|
|
|
|
|
2009-01-30 18:51:59 -05:00
|
|
|
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 ;
|
2009-09-07 09:59:38 -04:00
|
|
|
pix.loadFromData(data,size,"PNG") ;
|
|
|
|
ui.avatarButton->setIcon(pix); // writes image into ba in PNG format
|
2009-01-30 18:51:59 -05:00
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
2010-08-30 11:43:07 -04:00
|
|
|
picture = QPixmap(fileName).scaled(96,96, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
2009-01-30 18:51:59 -05:00
|
|
|
|
|
|
|
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);
|
2009-09-07 09:59:38 -04:00
|
|
|
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
2009-01-30 18:51:59 -05:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2010-01-25 17:08:23 -05:00
|
|
|
|
2010-02-23 17:26:38 -05:00
|
|
|
/** Loads own personal status message */
|
|
|
|
void MessengerWindow::loadmystatusmessage()
|
2010-01-25 17:08:23 -05:00
|
|
|
{
|
|
|
|
ui.messagelineEdit->setText(QString::fromStdString(rsMsgs->getCustomStateString()));
|
|
|
|
}
|
2010-02-03 12:39:30 -05:00
|
|
|
|
2010-02-23 17:26:38 -05:00
|
|
|
/** Save own status message */
|
2010-07-17 19:19:43 -04:00
|
|
|
void MessengerWindow::savestatusmessage()
|
2010-02-23 17:26:38 -05:00
|
|
|
{
|
2010-07-20 15:45:07 -04:00
|
|
|
rsMsgs->setCustomStateString(ui.messagelineEdit->text().toStdString());
|
2010-07-17 19:19:43 -04:00
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_RSGUI
|
2010-07-17 19:19:43 -04:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
void MessengerWindow::on_actionSort_Peers_Descending_Order_activated()
|
|
|
|
{
|
2010-06-17 13:39:32 -04:00
|
|
|
ui.messengertreeWidget->sortItems ( COLUMN_NAME, Qt::DescendingOrder );
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::on_actionSort_Peers_Ascending_Order_activated()
|
|
|
|
{
|
2010-06-17 13:39:32 -04:00
|
|
|
ui.messengertreeWidget->sortItems ( COLUMN_NAME, Qt::AscendingOrder );
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::on_actionRoot_is_decorated_activated()
|
|
|
|
{
|
2010-06-17 13:39:32 -04:00
|
|
|
ui.messengertreeWidget->setRootIsDecorated(ui.actionRoot_is_decorated->isChecked());
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::displayMenu()
|
|
|
|
{
|
2010-06-17 13:39:32 -04:00
|
|
|
QMenu *lookmenu = new QMenu();
|
|
|
|
lookmenu->addAction(ui.actionSort_Peers_Descending_Order);
|
|
|
|
lookmenu->addAction(ui.actionSort_Peers_Ascending_Order);
|
|
|
|
lookmenu->addAction(ui.actionSort_by_State);
|
|
|
|
lookmenu->addAction(ui.actionHide_Offline_Friends);
|
|
|
|
lookmenu->addAction(ui.actionRoot_is_decorated);
|
|
|
|
|
|
|
|
ui.displaypushButton->setMenu(lookmenu);
|
2010-02-03 12:39:30 -05:00
|
|
|
}
|
|
|
|
|
2010-05-23 20:59:12 -04:00
|
|
|
/* clear Filter */
|
|
|
|
void MessengerWindow::clearFilter()
|
|
|
|
{
|
|
|
|
ui.filterPatternLineEdit->clear();
|
|
|
|
ui.filterPatternLineEdit->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::filterRegExpChanged()
|
|
|
|
{
|
|
|
|
|
|
|
|
QString text = ui.filterPatternLineEdit->text();
|
|
|
|
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
ui.clearButton->hide();
|
|
|
|
} else {
|
|
|
|
ui.clearButton->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::FilterItems()
|
|
|
|
{
|
|
|
|
QString sPattern = ui.filterPatternLineEdit->text();
|
|
|
|
|
|
|
|
int nCount = ui.messengertreeWidget->topLevelItemCount ();
|
|
|
|
for (int nIndex = 0; nIndex < nCount; nIndex++) {
|
|
|
|
FilterItem(ui.messengertreeWidget->topLevelItem(nIndex), sPattern);
|
|
|
|
}
|
2010-08-30 09:03:12 -04:00
|
|
|
|
|
|
|
QTreeWidgetItem *c = getCurrentPeer();
|
|
|
|
if (c && c->isHidden()) {
|
|
|
|
// active item is hidden, deselect it
|
|
|
|
ui.messengertreeWidget->setCurrentItem(NULL);
|
|
|
|
}
|
2010-05-23 20:59:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MessengerWindow::FilterItem(QTreeWidgetItem *pItem, QString &sPattern)
|
|
|
|
{
|
|
|
|
bool bVisible = true;
|
|
|
|
|
|
|
|
if (sPattern.isEmpty() == false) {
|
|
|
|
if (pItem->text(0).contains(sPattern, Qt::CaseInsensitive) == false) {
|
|
|
|
bVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int nVisibleChildCount = 0;
|
|
|
|
int nCount = pItem->childCount();
|
|
|
|
for (int nIndex = 0; nIndex < nCount; nIndex++) {
|
|
|
|
if (FilterItem(pItem->child(nIndex), sPattern)) {
|
|
|
|
nVisibleChildCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bVisible || nVisibleChildCount) {
|
|
|
|
pItem->setHidden(false);
|
|
|
|
} else {
|
|
|
|
pItem->setHidden(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (bVisible || nVisibleChildCount);
|
|
|
|
}
|