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>
|
2010-12-30 12:09:32 -05:00
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
#include "common/vmessagebox.h"
|
2010-09-12 10:10:28 -04:00
|
|
|
#include "common/StatusDefs.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#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
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "ShareManager.h"
|
2010-09-19 20:10:51 -04:00
|
|
|
#include "notifyqt.h"
|
|
|
|
#include "connect/ConnectFriendWizard.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "util/PixmapMerging.h"
|
|
|
|
#include "LogoBar.h"
|
|
|
|
#include "util/Widget.h"
|
2011-08-12 16:27:05 -04:00
|
|
|
#include "util/misc.h"
|
2010-05-11 16:02:52 -04:00
|
|
|
#include "settings/rsharesettings.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
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
|
|
|
|
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;
|
2016-07-05 23:49:43 -04:00
|
|
|
|
|
|
|
std::set<std::string> MessengerWindow::expandedPeers ;
|
|
|
|
std::set<RsNodeGroupId> MessengerWindow::expandedGroups ;
|
2008-07-09 05:53:47 -04:00
|
|
|
|
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;
|
|
|
|
}
|
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 */
|
2013-10-18 17:10:33 -04:00
|
|
|
MessengerWindow::MessengerWindow(QWidget* parent, Qt::WindowFlags 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 );
|
|
|
|
|
2011-09-05 17:19:07 -04:00
|
|
|
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
|
|
|
|
ui.avatar->setOwnId();
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage()));
|
|
|
|
|
2010-07-18 07:43:39 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage()));
|
2010-09-11 15:06:22 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int)));
|
2010-07-18 07:43:39 -04:00
|
|
|
|
2016-07-05 23:49:43 -04:00
|
|
|
for (std::set<std::string>::iterator peerIt = expandedPeers.begin(); peerIt != expandedPeers.end(); ++peerIt) {
|
2011-10-20 17:34:44 -04:00
|
|
|
ui.friendList->addPeerToExpand(*peerIt);
|
|
|
|
}
|
2016-07-05 23:49:43 -04:00
|
|
|
expandedPeers.clear();
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2016-07-05 23:49:43 -04:00
|
|
|
for (std::set<RsNodeGroupId>::iterator groupIt = expandedGroups.begin(); groupIt != expandedGroups.end(); ++groupIt) {
|
2011-11-11 20:26:26 -05:00
|
|
|
ui.friendList->addGroupToExpand(*groupIt);
|
|
|
|
}
|
2016-07-05 23:49:43 -04:00
|
|
|
expandedGroups.clear();
|
2011-11-11 20:26:26 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
ui.messagelineEdit->setMinimumWidth(20);
|
|
|
|
|
2013-08-30 08:24:39 -04: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-05 19:28:11 -05:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
// load settings
|
2011-10-20 17:34:44 -04:00
|
|
|
RsAutoUpdatePage::lockAllEvents();
|
2015-07-09 16:53:28 -04:00
|
|
|
ui.friendList->setColumnVisible(FriendList::COLUMN_LAST_CONTACT, false);
|
|
|
|
ui.friendList->setColumnVisible(FriendList::COLUMN_IP, false);
|
2011-11-11 20:26:26 -05:00
|
|
|
ui.friendList->setShowGroups(false);
|
2010-06-17 13:39:32 -04:00
|
|
|
processSettings(true);
|
2011-10-20 17:34:44 -04:00
|
|
|
RsAutoUpdatePage::unlockAllEvents();
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2010-08-25 14:31:56 -04:00
|
|
|
// add self nick
|
|
|
|
RsPeerDetails pd;
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPeerId ownId = rsPeers->getOwnId();
|
2010-09-11 14:08:38 -04:00
|
|
|
if (rsPeers->getPeerDetails(ownId, pd)) {
|
|
|
|
/* calculate only once */
|
2010-10-02 15:02:53 -04:00
|
|
|
m_nickName = QString::fromUtf8(pd.name.c_str());
|
2010-08-25 14:31:56 -04:00
|
|
|
}
|
|
|
|
|
2010-09-11 14:08:38 -04:00
|
|
|
/* Show nick and current state */
|
|
|
|
StatusInfo statusInfo;
|
|
|
|
rsStatus->getOwnStatus(statusInfo);
|
2014-03-17 16:56:06 -04:00
|
|
|
updateOwnStatus(QString::fromStdString(ownId.toStdString()), statusInfo.status);
|
2010-09-11 14:08:38 -04:00
|
|
|
|
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
|
|
|
loadmystatusmessage();
|
2008-04-24 08:58:27 -04:00
|
|
|
}
|
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
|
|
|
|
|
|
|
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-07-18 07:43:39 -04:00
|
|
|
|
|
|
|
_instance = NULL;
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessengerWindow::processSettings(bool bLoad)
|
|
|
|
{
|
|
|
|
Settings->beginGroup(_name);
|
2011-11-11 20:26:26 -05:00
|
|
|
ui.friendList->processSettings(bLoad);
|
2010-06-17 13:39:32 -04:00
|
|
|
Settings->endGroup();
|
|
|
|
}
|
2010-04-20 04:42:45 -04:00
|
|
|
|
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
|
|
|
}
|
2010-07-15 07:25:34 -04:00
|
|
|
|
2010-02-03 12:39:30 -05:00
|
|
|
//============================================================================
|
|
|
|
|
2011-08-12 10:06:29 -04:00
|
|
|
void MessengerWindow::closeEvent (QCloseEvent * /*event*/)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-07-18 07:43:39 -04:00
|
|
|
/* save the expanded peers */
|
2016-07-05 23:49:43 -04:00
|
|
|
expandedPeers.clear();
|
|
|
|
ui.friendList->getExpandedPeers(expandedPeers);
|
2011-11-11 20:26:26 -05:00
|
|
|
|
|
|
|
/* save the expanded groups */
|
2016-07-05 23:49:43 -04:00
|
|
|
expandedGroups.clear();
|
|
|
|
ui.friendList->getExpandedGroups(expandedGroups);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-02-23 17:26:38 -05:00
|
|
|
/** Loads own personal status message */
|
|
|
|
void MessengerWindow::loadmystatusmessage()
|
2010-01-25 17:08:23 -05:00
|
|
|
{
|
2010-11-24 14:25:53 -05:00
|
|
|
ui.messagelineEdit->setEditText( QString::fromUtf8(rsMsgs->getCustomStateString().c_str()));
|
2010-01-25 17:08:23 -05:00
|
|
|
}
|
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-11-24 14:25:53 -05:00
|
|
|
rsMsgs->setCustomStateString(ui.messagelineEdit->currentText().toUtf8().constData());
|
2010-07-17 19:19:43 -04:00
|
|
|
}
|
2010-09-11 14:08:38 -04:00
|
|
|
|
2010-09-11 15:06:22 -04:00
|
|
|
void MessengerWindow::updateOwnStatus(const QString &peer_id, int status)
|
2010-09-11 14:08:38 -04:00
|
|
|
{
|
2010-09-11 15:06:22 -04:00
|
|
|
// add self nick + own status
|
2014-03-17 16:56:06 -04:00
|
|
|
if (peer_id == QString::fromStdString(rsPeers->getOwnId().toStdString()))
|
2010-09-11 16:25:08 -04:00
|
|
|
{
|
2010-09-11 15:06:22 -04:00
|
|
|
// my status has changed
|
2010-09-12 10:10:28 -04:00
|
|
|
|
|
|
|
ui.statusButton->setText(m_nickName + " (" + StatusDefs::name(status) + ")");
|
2010-09-11 16:25:08 -04:00
|
|
|
|
2010-09-11 15:06:22 -04:00
|
|
|
return;
|
2010-09-11 14:08:38 -04:00
|
|
|
}
|
|
|
|
}
|