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;
|
|
|
|
static std::set<std::string> *expandedPeers = NULL;
|
2011-11-11 20:26:26 -05:00
|
|
|
static std::set<std::string> *expandedGroups = NULL;
|
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;
|
|
|
|
}
|
|
|
|
if (expandedPeers) {
|
|
|
|
/* delete saved expanded peers */
|
|
|
|
delete(expandedPeers);
|
|
|
|
expandedPeers = NULL;
|
|
|
|
}
|
2011-11-11 20:26:26 -05:00
|
|
|
if (expandedGroups) {
|
|
|
|
/* delete saved expanded groups */
|
|
|
|
delete(expandedGroups);
|
|
|
|
expandedGroups = 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 );
|
|
|
|
|
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.shareButton, SIGNAL(clicked()), SLOT(openShareManager()));
|
|
|
|
connect( ui.addIMAccountButton, SIGNAL(clicked( bool ) ), this , SLOT( addFriend() ) );
|
|
|
|
|
|
|
|
connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage()));
|
2012-04-05 17:03:03 -04:00
|
|
|
connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), ui.friendList, SLOT(filterItems(QString)));
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2010-07-18 07:43:39 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(ownAvatarChanged()), this, SLOT(updateAvatar()));
|
|
|
|
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
|
|
|
|
2011-10-20 17:34:44 -04:00
|
|
|
if (expandedPeers != NULL) {
|
|
|
|
for (std::set<std::string>::iterator peerIt = expandedPeers->begin(); peerIt != expandedPeers->end(); peerIt++) {
|
|
|
|
ui.friendList->addPeerToExpand(*peerIt);
|
|
|
|
}
|
|
|
|
delete expandedPeers;
|
|
|
|
expandedPeers = NULL;
|
|
|
|
}
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2011-11-11 20:26:26 -05:00
|
|
|
if (expandedGroups != NULL) {
|
|
|
|
for (std::set<std::string>::iterator groupIt = expandedGroups->begin(); groupIt != expandedGroups->end(); groupIt++) {
|
|
|
|
ui.friendList->addGroupToExpand(*groupIt);
|
|
|
|
}
|
|
|
|
delete expandedGroups;
|
|
|
|
expandedGroups = NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
//LogoBar
|
|
|
|
_rsLogoBarmessenger = new LogoBar(ui.logoframe);
|
|
|
|
Widget::createLayout(ui.logoframe)->addWidget(_rsLogoBarmessenger);
|
|
|
|
|
|
|
|
ui.messagelineEdit->setMinimumWidth(20);
|
|
|
|
|
2011-11-11 20:26:26 -05:00
|
|
|
ui.displaypushButton->setMenu(ui.friendList->createDisplayMenu());
|
2010-06-17 13:39:32 -04:00
|
|
|
|
|
|
|
// load settings
|
2011-10-20 17:34:44 -04:00
|
|
|
RsAutoUpdatePage::lockAllEvents();
|
2011-11-11 20:26:26 -05:00
|
|
|
ui.friendList->setShowStatusColumn(false);
|
|
|
|
ui.friendList->setShowLastContactColumn(false);
|
|
|
|
ui.friendList->setShowAvatarColumn(true);
|
|
|
|
ui.friendList->setRootIsDecorated(true);
|
|
|
|
ui.friendList->setShowGroups(false);
|
2010-06-17 13:39:32 -04:00
|
|
|
processSettings(true);
|
2011-10-20 17:34:44 -04:00
|
|
|
ui.friendList->setBigName(true);
|
|
|
|
RsAutoUpdatePage::unlockAllEvents();
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2010-08-25 14:31:56 -04:00
|
|
|
// add self nick
|
|
|
|
RsPeerDetails pd;
|
2010-09-11 14:08:38 -04:00
|
|
|
std::string ownId = rsPeers->getOwnId();
|
|
|
|
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);
|
2010-09-11 15:06:22 -04:00
|
|
|
updateOwnStatus(QString::fromStdString(ownId), 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();
|
2010-08-31 16:00:49 -04:00
|
|
|
|
2010-06-17 13:39:32 -04:00
|
|
|
/* 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
|
|
|
|
|
|
|
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 */
|
|
|
|
if (expandedPeers == NULL) {
|
|
|
|
expandedPeers = new std::set<std::string>;
|
|
|
|
} else {
|
|
|
|
expandedPeers->clear();
|
|
|
|
}
|
|
|
|
|
2011-10-20 17:34:44 -04:00
|
|
|
ui.friendList->getExpandedPeers(*expandedPeers);
|
2011-11-11 20:26:26 -05:00
|
|
|
|
|
|
|
/* save the expanded groups */
|
|
|
|
if (expandedGroups == NULL) {
|
|
|
|
expandedGroups = new std::set<std::string>;
|
|
|
|
} else {
|
|
|
|
expandedGroups->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.friendList->getExpandedGroups(*expandedGroups);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
LogoBar & MessengerWindow::getLogoBar() const {
|
|
|
|
return *_rsLogoBarmessenger;
|
|
|
|
}
|
|
|
|
|
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
|
2010-09-12 10:10:28 -04:00
|
|
|
if (peer_id.toStdString() == rsPeers->getOwnId())
|
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
|
|
|
}
|
|
|
|
}
|