2007-11-15 03:18:48 +00: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 23:25:16 +00:00
|
|
|
****************************************************************/
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2009-01-01 23:25:16 +00:00
|
|
|
#include <QFile>
|
2007-11-15 03:18:48 +00:00
|
|
|
#include <QFileInfo>
|
2010-07-23 18:52:58 +00:00
|
|
|
#include <QWidgetAction>
|
2010-08-28 19:50:38 +00:00
|
|
|
#include <QTimer>
|
2010-12-30 17:09:32 +00:00
|
|
|
|
2008-01-25 08:49:40 +00:00
|
|
|
#include "common/vmessagebox.h"
|
2010-09-12 14:10:28 +00:00
|
|
|
#include "common/StatusDefs.h"
|
2008-01-25 08:49:40 +00:00
|
|
|
|
2010-08-06 09:40:23 +00:00
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
#include <retroshare/rsstatus.h>
|
|
|
|
#include <retroshare/rsnotify.h>
|
2008-01-25 08:49:40 +00:00
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
#include "MessengerWindow.h"
|
2010-06-17 17:39:32 +00:00
|
|
|
#include "RsAutoUpdatePage.h"
|
2008-01-25 08:49:40 +00:00
|
|
|
|
2010-08-31 20:00:49 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "ShareManager.h"
|
2010-09-20 00:10:51 +00:00
|
|
|
#include "notifyqt.h"
|
|
|
|
#include "connect/ConnectFriendWizard.h"
|
2007-11-15 03:18:48 +00:00
|
|
|
#include "util/PixmapMerging.h"
|
|
|
|
#include "LogoBar.h"
|
|
|
|
#include "util/Widget.h"
|
2011-08-12 20:27:05 +00:00
|
|
|
#include "util/misc.h"
|
2010-05-11 20:02:52 +00:00
|
|
|
#include "settings/rsharesettings.h"
|
2007-11-15 03:18:48 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
2010-08-25 18:31:56 +00:00
|
|
|
#include <algorithm>
|
2010-08-28 19:50:38 +00:00
|
|
|
#include <set>
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2010-06-17 17:39:32 +00:00
|
|
|
|
2008-07-09 09:53:47 +00:00
|
|
|
/******
|
|
|
|
* #define MSG_DEBUG 1
|
|
|
|
*****/
|
2010-07-18 11:43:39 +00:00
|
|
|
|
|
|
|
MessengerWindow* MessengerWindow::_instance = NULL;
|
2016-07-05 23:49:43 -04:00
|
|
|
|
2016-11-27 12:21:14 +01:00
|
|
|
std::set<RsPgpId> MessengerWindow::expandedPeers ;
|
2016-07-05 23:49:43 -04:00
|
|
|
std::set<RsNodeGroupId> MessengerWindow::expandedGroups ;
|
2008-07-09 09:53:47 +00:00
|
|
|
|
2010-07-18 11:43:39 +00:00
|
|
|
/*static*/ void MessengerWindow::showYourself ()
|
|
|
|
{
|
|
|
|
if (_instance == NULL) {
|
|
|
|
_instance = new MessengerWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
_instance->show();
|
|
|
|
_instance->activateWindow();
|
|
|
|
}
|
|
|
|
|
2009-11-30 16:12:13 +00:00
|
|
|
MessengerWindow* MessengerWindow::getInstance()
|
|
|
|
{
|
2010-07-18 11:43:39 +00:00
|
|
|
return _instance;
|
2009-11-30 16:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::releaseInstance()
|
|
|
|
{
|
2010-07-18 11:43:39 +00:00
|
|
|
if (_instance) {
|
|
|
|
delete _instance;
|
|
|
|
}
|
2009-11-30 16:12:13 +00:00
|
|
|
}
|
2008-07-09 09:53:47 +00:00
|
|
|
|
2009-01-01 23:25:16 +00:00
|
|
|
/** Constructor */
|
2013-10-18 21:10:33 +00:00
|
|
|
MessengerWindow::MessengerWindow(QWidget* parent, Qt::WindowFlags flags)
|
2010-07-17 23:19:43 +00:00
|
|
|
: RWindow("MessengerWindow", parent, flags)
|
2009-01-01 23:25:16 +00:00
|
|
|
{
|
2010-06-17 17:39:32 +00:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2010-07-18 11:43:39 +00:00
|
|
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
|
|
|
|
2011-09-05 21:19:07 +00:00
|
|
|
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
|
|
|
|
ui.avatar->setOwnId();
|
|
|
|
|
2010-06-17 17:39:32 +00:00
|
|
|
connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage()));
|
|
|
|
|
2010-07-18 11:43:39 +00:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage()));
|
2010-09-11 19:06:22 +00:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int)));
|
2010-07-18 11:43:39 +00:00
|
|
|
|
2016-11-27 12:21:14 +01:00
|
|
|
for (std::set<RsPgpId>::iterator peerIt = expandedPeers.begin(); peerIt != expandedPeers.end(); ++peerIt) {
|
2011-10-20 21:34:44 +00:00
|
|
|
ui.friendList->addPeerToExpand(*peerIt);
|
|
|
|
}
|
2016-07-05 23:49:43 -04:00
|
|
|
expandedPeers.clear();
|
2010-06-17 17:39:32 +00:00
|
|
|
|
2016-07-05 23:49:43 -04:00
|
|
|
for (std::set<RsNodeGroupId>::iterator groupIt = expandedGroups.begin(); groupIt != expandedGroups.end(); ++groupIt) {
|
2011-11-12 01:26:26 +00:00
|
|
|
ui.friendList->addGroupToExpand(*groupIt);
|
|
|
|
}
|
2016-07-05 23:49:43 -04:00
|
|
|
expandedGroups.clear();
|
2011-11-12 01:26:26 +00:00
|
|
|
|
2010-06-17 17:39:32 +00:00
|
|
|
ui.messagelineEdit->setMinimumWidth(20);
|
|
|
|
|
2013-08-30 12:24:39 +00:00
|
|
|
/* Initialize friend list */
|
|
|
|
QToolButton *button = new QToolButton(this);
|
|
|
|
button->setIcon(QIcon(":/images/user/add_user24.png"));
|
|
|
|
button->setToolTip(tr("Add a Friend"));
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(addFriend()));
|
|
|
|
ui.friendList->addToolButton(button);
|
|
|
|
|
|
|
|
button = new QToolButton(this);
|
|
|
|
button->setIcon(QIcon(":/images/friendsfolder24.png"));
|
|
|
|
button->setToolTip(tr("Share files for your friends"));
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(openShareManager()));
|
|
|
|
ui.friendList->addToolButton(button);
|
2012-11-06 00:28:11 +00:00
|
|
|
|
2010-06-17 17:39:32 +00:00
|
|
|
// load settings
|
2011-10-20 21:34:44 +00:00
|
|
|
RsAutoUpdatePage::lockAllEvents();
|
2015-07-09 20:53:28 +00:00
|
|
|
ui.friendList->setColumnVisible(FriendList::COLUMN_LAST_CONTACT, false);
|
|
|
|
ui.friendList->setColumnVisible(FriendList::COLUMN_IP, false);
|
2011-11-12 01:26:26 +00:00
|
|
|
ui.friendList->setShowGroups(false);
|
2010-06-17 17:39:32 +00:00
|
|
|
processSettings(true);
|
2011-10-20 21:34:44 +00:00
|
|
|
RsAutoUpdatePage::unlockAllEvents();
|
2010-06-17 17:39:32 +00:00
|
|
|
|
2010-08-25 18:31:56 +00:00
|
|
|
// add self nick
|
|
|
|
RsPeerDetails pd;
|
2014-03-17 20:56:06 +00:00
|
|
|
RsPeerId ownId = rsPeers->getOwnId();
|
2010-09-11 18:08:38 +00:00
|
|
|
if (rsPeers->getPeerDetails(ownId, pd)) {
|
|
|
|
/* calculate only once */
|
2010-10-02 19:02:53 +00:00
|
|
|
m_nickName = QString::fromUtf8(pd.name.c_str());
|
2010-08-25 18:31:56 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 18:08:38 +00:00
|
|
|
/* Show nick and current state */
|
|
|
|
StatusInfo statusInfo;
|
|
|
|
rsStatus->getOwnStatus(statusInfo);
|
2014-03-17 20:56:06 +00:00
|
|
|
updateOwnStatus(QString::fromStdString(ownId.toStdString()), statusInfo.status);
|
2010-09-11 18:08:38 +00:00
|
|
|
|
2010-07-17 23:19:43 +00:00
|
|
|
MainWindow *pMainWindow = MainWindow::getInstance();
|
|
|
|
if (pMainWindow) {
|
2010-08-30 19:10:07 +00:00
|
|
|
QMenu *pStatusMenu = new QMenu();
|
|
|
|
pMainWindow->initializeStatusObject(pStatusMenu, true);
|
|
|
|
ui.statusButton->setMenu(pStatusMenu);
|
2010-07-17 23:19:43 +00:00
|
|
|
}
|
2010-08-31 20:00:49 +00:00
|
|
|
|
2010-06-17 17:39:32 +00:00
|
|
|
loadmystatusmessage();
|
2008-04-24 12:58:27 +00:00
|
|
|
}
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2010-06-17 17:39:32 +00:00
|
|
|
MessengerWindow::~MessengerWindow ()
|
|
|
|
{
|
|
|
|
// save settings
|
|
|
|
processSettings(false);
|
2010-07-17 23:19:43 +00:00
|
|
|
|
|
|
|
MainWindow *pMainWindow = MainWindow::getInstance();
|
|
|
|
if (pMainWindow) {
|
2010-08-30 19:10:07 +00:00
|
|
|
pMainWindow->removeStatusObject(ui.statusButton);
|
2010-07-17 23:19:43 +00:00
|
|
|
}
|
2010-07-18 11:43:39 +00:00
|
|
|
|
|
|
|
_instance = NULL;
|
2010-06-17 17:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::processSettings(bool bLoad)
|
|
|
|
{
|
|
|
|
Settings->beginGroup(_name);
|
2011-11-12 01:26:26 +00:00
|
|
|
ui.friendList->processSettings(bLoad);
|
2010-06-17 17:39:32 +00:00
|
|
|
Settings->endGroup();
|
|
|
|
}
|
2010-04-20 08:42:45 +00:00
|
|
|
|
2010-02-03 17:39:30 +00:00
|
|
|
/** Add a Friend ShortCut */
|
|
|
|
void MessengerWindow::addFriend()
|
|
|
|
{
|
2010-05-03 00:09:55 +00:00
|
|
|
ConnectFriendWizard connwiz (this);
|
2010-02-03 17:39:30 +00:00
|
|
|
|
2010-05-03 00:09:55 +00:00
|
|
|
connwiz.exec ();
|
2010-02-03 17:39:30 +00:00
|
|
|
}
|
2010-07-15 11:25:34 +00:00
|
|
|
|
2010-02-03 17:39:30 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2011-08-12 14:06:29 +00:00
|
|
|
void MessengerWindow::closeEvent (QCloseEvent * /*event*/)
|
2007-11-15 03:18:48 +00:00
|
|
|
{
|
2010-07-18 11:43:39 +00:00
|
|
|
/* save the expanded peers */
|
2016-07-05 23:49:43 -04:00
|
|
|
expandedPeers.clear();
|
|
|
|
ui.friendList->getExpandedPeers(expandedPeers);
|
2011-11-12 01:26:26 +00:00
|
|
|
|
|
|
|
/* save the expanded groups */
|
2016-07-05 23:49:43 -04:00
|
|
|
expandedGroups.clear();
|
|
|
|
ui.friendList->getExpandedGroups(expandedGroups);
|
2007-11-15 03:18:48 +00:00
|
|
|
}
|
|
|
|
|
2009-01-08 17:29:01 +00:00
|
|
|
/** Shows Share Manager */
|
|
|
|
void MessengerWindow::openShareManager()
|
|
|
|
{
|
2009-08-03 19:43:52 +00:00
|
|
|
ShareManager::showYourself();
|
2009-01-08 17:29:01 +00:00
|
|
|
}
|
|
|
|
|
2010-02-23 22:26:38 +00:00
|
|
|
/** Loads own personal status message */
|
|
|
|
void MessengerWindow::loadmystatusmessage()
|
2010-01-25 22:08:23 +00:00
|
|
|
{
|
2010-11-24 19:25:53 +00:00
|
|
|
ui.messagelineEdit->setEditText( QString::fromUtf8(rsMsgs->getCustomStateString().c_str()));
|
2010-01-25 22:08:23 +00:00
|
|
|
}
|
2010-02-03 17:39:30 +00:00
|
|
|
|
2010-02-23 22:26:38 +00:00
|
|
|
/** Save own status message */
|
2010-07-17 23:19:43 +00:00
|
|
|
void MessengerWindow::savestatusmessage()
|
2010-02-23 22:26:38 +00:00
|
|
|
{
|
2010-11-24 19:25:53 +00:00
|
|
|
rsMsgs->setCustomStateString(ui.messagelineEdit->currentText().toUtf8().constData());
|
2010-07-17 23:19:43 +00:00
|
|
|
}
|
2010-09-11 18:08:38 +00:00
|
|
|
|
2010-09-11 19:06:22 +00:00
|
|
|
void MessengerWindow::updateOwnStatus(const QString &peer_id, int status)
|
2010-09-11 18:08:38 +00:00
|
|
|
{
|
2010-09-11 19:06:22 +00:00
|
|
|
// add self nick + own status
|
2014-03-17 20:56:06 +00:00
|
|
|
if (peer_id == QString::fromStdString(rsPeers->getOwnId().toStdString()))
|
2010-09-11 20:25:08 +00:00
|
|
|
{
|
2010-09-11 19:06:22 +00:00
|
|
|
// my status has changed
|
2010-09-12 14:10:28 +00:00
|
|
|
|
|
|
|
ui.statusButton->setText(m_nickName + " (" + StatusDefs::name(status) + ")");
|
2010-09-11 20:25:08 +00:00
|
|
|
|
2010-09-11 19:06:22 +00:00
|
|
|
return;
|
2010-09-11 18:08:38 +00:00
|
|
|
}
|
|
|
|
}
|