2018-12-25 21:34:59 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/FriendsDialog.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2012 Retroshare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2011-10-20 21:34:44 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2010-07-23 18:52:58 +00:00
|
|
|
#include <QDropEvent>
|
2011-10-20 21:34:44 +00:00
|
|
|
#include <QMenu>
|
2012-05-12 00:40:53 +00:00
|
|
|
#include <QTimer>
|
2012-10-24 13:22:14 +00:00
|
|
|
#include <QMessageBox>
|
2008-11-24 14:07:26 +00:00
|
|
|
|
2014-12-29 21:41:05 +00:00
|
|
|
#include <retroshare/rspeers.h>
|
2011-09-29 09:20:09 +00:00
|
|
|
#include <retroshare/rshistory.h>
|
2008-01-25 08:49:40 +00:00
|
|
|
|
2012-08-05 20:12:55 +00:00
|
|
|
#include "chat/ChatUserNotify.h"
|
2010-09-20 00:10:51 +00:00
|
|
|
#include "connect/ConnectFriendWizard.h"
|
2010-09-21 16:11:19 +00:00
|
|
|
#include "groups/CreateGroup.h"
|
2010-05-03 00:09:55 +00:00
|
|
|
#include "MainWindow.h"
|
2010-08-12 16:00:21 +00:00
|
|
|
#include "NewsFeed.h"
|
2011-10-20 21:34:44 +00:00
|
|
|
#include "notifyqt.h"
|
|
|
|
#include "profile/ProfileWidget.h"
|
|
|
|
#include "profile/StatusMessage.h"
|
|
|
|
#include "RetroShareLink.h"
|
|
|
|
#include "settings/rsharesettings.h"
|
2010-12-03 00:54:40 +00:00
|
|
|
#include "util/misc.h"
|
2012-11-15 21:35:37 +00:00
|
|
|
#include "util/DateTime.h"
|
2011-10-20 21:34:44 +00:00
|
|
|
#include "FriendsDialog.h"
|
2013-02-22 21:42:27 +00:00
|
|
|
#include "NetworkView.h"
|
|
|
|
#include "NetworkDialog.h"
|
2019-06-28 11:12:44 +02:00
|
|
|
#include "gui/common/NewFriendList.h"
|
2014-05-07 23:45:53 +00:00
|
|
|
#include "gui/Identity/IdDialog.h"
|
2011-10-20 21:34:44 +00:00
|
|
|
/* Images for Newsfeed icons */
|
2014-05-10 02:38:47 +00:00
|
|
|
//#define IMAGE_NEWSFEED ""
|
|
|
|
//#define IMAGE_NEWSFEED_NEW ":/images/message-state-new.png"
|
2019-11-24 06:04:10 +01:00
|
|
|
#define IMAGE_NETWORK2 ":/icons/png/netgraph2.png"
|
|
|
|
#define IMAGE_PEERS ":/icons/png/digital-key.png"
|
2014-05-07 23:45:53 +00:00
|
|
|
#define IMAGE_IDENTITY ":/images/identity/identities_32.png"
|
2008-11-24 14:07:26 +00:00
|
|
|
|
2008-07-09 09:53:47 +00:00
|
|
|
/******
|
2011-05-24 23:35:11 +00:00
|
|
|
* #define FRIENDS_DEBUG 1
|
2008-07-09 09:53:47 +00:00
|
|
|
*****/
|
|
|
|
|
2012-01-18 20:02:19 +00:00
|
|
|
static FriendsDialog *instance = NULL;
|
|
|
|
|
2008-11-24 14:07:26 +00:00
|
|
|
/** Constructor */
|
2019-09-22 18:13:18 +02:00
|
|
|
FriendsDialog::FriendsDialog(QWidget *parent) : MainPage(parent)
|
2008-11-24 14:07:26 +00:00
|
|
|
{
|
2010-09-04 14:23:30 +00:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
2009-09-30 22:30:57 +00:00
|
|
|
|
2018-11-20 15:54:24 +01:00
|
|
|
if (!instance) instance = this;
|
|
|
|
|
|
|
|
#ifdef RS_DIRECT_CHAT
|
2014-12-29 21:41:05 +00:00
|
|
|
QString msg = tr("Retroshare broadcast chat: messages are sent to all connected friends.");
|
|
|
|
// "<font color='grey'>" + DateTime::formatTime(QTime::currentTime()) + "</font> -
|
|
|
|
msg = QString("<font color='blue'><i>" + msg + "</i></font>");
|
|
|
|
ui.chatWidget->setWelcomeMessage(msg);
|
|
|
|
ui.chatWidget->init(ChatId::makeBroadcastId(), tr("Broadcast"));
|
2012-01-18 20:02:19 +00:00
|
|
|
|
2019-06-28 11:12:44 +02:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(chatMessageReceived(ChatMessage)), this, SLOT(chatMessageReceived(ChatMessage)));
|
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(chatStatusChanged(ChatId,QString)), this, SLOT(chatStatusReceived(ChatId,QString)));
|
2018-11-20 15:54:24 +01:00
|
|
|
#else // def RS_DIRECT_CHAT
|
|
|
|
ui.tabWidget->removeTab(ui.tabWidget->indexOf(ui.groupChatTab));
|
|
|
|
#endif // def RS_DIRECT_CHAT
|
|
|
|
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2012-08-26 20:31:10 +00:00
|
|
|
connect( ui.mypersonalstatusLabel, SIGNAL(clicked()), SLOT(statusmessage()));
|
2010-09-04 14:23:30 +00:00
|
|
|
connect( ui.actionSet_your_Avatar, SIGNAL(triggered()), this, SLOT(getAvatar()));
|
|
|
|
connect( ui.actionSet_your_Personal_Message, SIGNAL(triggered()), this, SLOT(statusmessage()));
|
2011-10-20 21:34:44 +00:00
|
|
|
|
2011-09-05 21:19:07 +00:00
|
|
|
ui.avatar->setOwnId();
|
2015-02-07 22:43:53 +00:00
|
|
|
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
|
2011-09-05 21:19:07 +00:00
|
|
|
|
2012-01-18 20:02:19 +00:00
|
|
|
ui.tabWidget->setTabPosition(QTabWidget::North);
|
2014-09-09 19:19:18 +00:00
|
|
|
ui.tabWidget->addTab(networkView = new NetworkView(),QIcon(IMAGE_NETWORK2), tr("Network graph"));
|
2013-07-16 20:00:46 +00:00
|
|
|
ui.tabWidget->addTab(networkDialog = new NetworkDialog(),QIcon(IMAGE_PEERS), tr("Keyring"));
|
2013-02-22 21:42:27 +00:00
|
|
|
|
2012-01-18 20:02:19 +00:00
|
|
|
ui.tabWidget->hideCloseButton(0);
|
|
|
|
ui.tabWidget->hideCloseButton(1);
|
|
|
|
ui.tabWidget->hideCloseButton(2);
|
|
|
|
ui.tabWidget->hideCloseButton(3);
|
2014-05-07 23:45:53 +00:00
|
|
|
ui.tabWidget->hideCloseButton(4);
|
2010-11-10 12:24:36 +00:00
|
|
|
|
2011-08-15 23:42:07 +00:00
|
|
|
/* Set initial size the splitter */
|
2014-12-12 19:44:45 +00:00
|
|
|
ui.splitter->setStretchFactor(0, 0);
|
|
|
|
ui.splitter->setStretchFactor(1, 1);
|
2011-08-15 23:42:07 +00:00
|
|
|
|
2010-09-04 14:23:30 +00:00
|
|
|
loadmypersonalstatus();
|
|
|
|
|
2014-12-24 01:40:08 +00:00
|
|
|
ui.mypersonalstatusLabel->setMinimumWidth(25);
|
|
|
|
|
2010-09-04 14:23:30 +00:00
|
|
|
// load settings
|
2011-10-20 21:34:44 +00:00
|
|
|
RsAutoUpdatePage::lockAllEvents();
|
2019-08-03 21:07:48 +02:00
|
|
|
ui.friendList->setColumnVisible(RsFriendListModel::COLUMN_THREAD_LAST_CONTACT, false);
|
|
|
|
ui.friendList->setColumnVisible(RsFriendListModel::COLUMN_THREAD_IP, false);
|
|
|
|
ui.friendList->setColumnVisible(RsFriendListModel::COLUMN_THREAD_ID, false);
|
2011-11-12 01:26:26 +00:00
|
|
|
ui.friendList->setShowGroups(true);
|
2010-09-04 14:23:30 +00:00
|
|
|
processSettings(true);
|
2011-10-20 21:34:44 +00:00
|
|
|
RsAutoUpdatePage::unlockAllEvents();
|
2010-09-04 14:23:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
// add self nick and Avatar to Friends.
|
|
|
|
RsPeerDetails pd ;
|
|
|
|
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),pd)) {
|
2015-05-12 20:30:44 +00:00
|
|
|
ui.nicknameLabel->setText(QString::fromUtf8(pd.name.c_str()) + " (" + QString::fromUtf8(pd.location.c_str())+")");
|
2010-09-04 14:23:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-08 15:08:36 +00:00
|
|
|
QString hlp_str = tr(
|
2015-06-30 16:44:58 +00:00
|
|
|
" <h1><img width=\"32\" src=\":/icons/help_64.png\"> Network</h1> \
|
2014-09-09 19:19:18 +00:00
|
|
|
<p>The Network tab shows your friend Retroshare nodes: the neighbor Retroshare nodes that are connected to you. \
|
2013-09-08 15:08:36 +00:00
|
|
|
</p> \
|
2014-09-09 19:19:18 +00:00
|
|
|
<p>You can group nodes together to allow a finer level of information access, for instance to only allow \
|
|
|
|
some nodes to see some of your files.</p> \
|
2013-09-08 15:08:36 +00:00
|
|
|
<p>On the right, you will find 3 useful tabs: \
|
|
|
|
<ul> \
|
2014-09-09 19:19:18 +00:00
|
|
|
<li>Broadcast sends messages to all connected nodes at once</li> \
|
|
|
|
<li>Local network graph shows the network around you, based on discovery information</li> \
|
|
|
|
<li>Keyring contains node keys you collected, mostly forwarded to you by your friend nodes</li> \
|
2013-09-08 15:08:36 +00:00
|
|
|
</ul> </p> \
|
|
|
|
") ;
|
2013-07-19 12:18:58 +00:00
|
|
|
|
2017-02-25 23:52:57 +01:00
|
|
|
registerHelpButton(ui.helpButton, hlp_str,"FriendsDialog") ;
|
2008-11-24 14:07:26 +00:00
|
|
|
}
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2011-05-17 17:27:47 +00:00
|
|
|
FriendsDialog::~FriendsDialog ()
|
2010-05-11 20:02:52 +00:00
|
|
|
{
|
2010-06-08 21:38:36 +00:00
|
|
|
// save settings
|
|
|
|
processSettings(false);
|
2012-01-18 20:02:19 +00:00
|
|
|
|
|
|
|
if (this == instance) {
|
|
|
|
instance = NULL;
|
|
|
|
}
|
2010-05-11 20:02:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:29:36 +00:00
|
|
|
void FriendsDialog::activatePage(FriendsDialog::Page page)
|
|
|
|
{
|
|
|
|
switch(page)
|
|
|
|
{
|
2014-05-07 23:45:53 +00:00
|
|
|
case FriendsDialog::IdTab: ui.tabWidget->setCurrentWidget(idDialog) ;
|
|
|
|
break ;
|
2013-02-23 14:29:36 +00:00
|
|
|
case FriendsDialog::NetworkTab: ui.tabWidget->setCurrentWidget(networkDialog) ;
|
|
|
|
break ;
|
|
|
|
case FriendsDialog::BroadcastTab: ui.tabWidget->setCurrentWidget(networkDialog) ;
|
|
|
|
break ;
|
|
|
|
case FriendsDialog::NetworkViewTab: ui.tabWidget->setCurrentWidget(networkView) ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 23:19:20 +01:00
|
|
|
UserNotify *FriendsDialog::createUserNotify(QObject *parent)
|
2012-08-05 20:12:55 +00:00
|
|
|
{
|
|
|
|
return new ChatUserNotify(parent);
|
|
|
|
}
|
|
|
|
|
2011-05-17 17:27:47 +00:00
|
|
|
void FriendsDialog::processSettings(bool bLoad)
|
2010-06-08 21:38:36 +00:00
|
|
|
{
|
2011-05-17 17:27:47 +00:00
|
|
|
Settings->beginGroup(QString("FriendsDialog"));
|
2010-06-08 21:38:36 +00:00
|
|
|
|
|
|
|
if (bLoad) {
|
|
|
|
// load settings
|
|
|
|
|
|
|
|
// state of splitter
|
|
|
|
ui.splitter->restoreState(Settings->value("Splitter").toByteArray());
|
2014-12-29 21:41:05 +00:00
|
|
|
//remove ui.splitter_2->restoreState(Settings->value("GroupChatSplitter").toByteArray());
|
2010-06-08 21:38:36 +00:00
|
|
|
} else {
|
|
|
|
// save settings
|
|
|
|
|
|
|
|
// state of splitter
|
|
|
|
Settings->setValue("Splitter", ui.splitter->saveState());
|
2014-12-29 21:41:05 +00:00
|
|
|
//remove Settings->setValue("GroupChatSplitter", ui.splitter_2->saveState());
|
2010-06-08 21:38:36 +00:00
|
|
|
}
|
|
|
|
|
2011-11-12 01:26:26 +00:00
|
|
|
ui.friendList->processSettings(bLoad);
|
|
|
|
|
2010-06-08 21:38:36 +00:00
|
|
|
Settings->endGroup();
|
|
|
|
}
|
|
|
|
|
2014-12-29 21:41:05 +00:00
|
|
|
void FriendsDialog::chatMessageReceived(const ChatMessage &msg)
|
2010-03-17 15:34:36 +00:00
|
|
|
{
|
2014-12-29 21:41:05 +00:00
|
|
|
if(msg.chat_id.isBroadcast())
|
|
|
|
{
|
|
|
|
QDateTime sendTime = QDateTime::fromTime_t(msg.sendTime);
|
|
|
|
QDateTime recvTime = QDateTime::fromTime_t(msg.recvTime);
|
|
|
|
QString message = QString::fromUtf8(msg.msg.c_str());
|
|
|
|
QString name = QString::fromUtf8(rsPeers->getPeerName(msg.broadcast_peer_id).c_str());
|
2010-03-17 15:34:36 +00:00
|
|
|
|
2014-12-29 21:41:05 +00:00
|
|
|
ui.chatWidget->addChatMsg(msg.incoming, name, sendTime, recvTime, message, ChatWidget::MSGTYPE_NORMAL);
|
2015-01-10 13:13:41 +00:00
|
|
|
|
|
|
|
if(ui.chatWidget->isActive())
|
|
|
|
{
|
|
|
|
// clear the chat notify when control returns to the Qt event loop
|
|
|
|
// we have to do this later, because we don't know if we or the notify receives the chat message first
|
|
|
|
QMetaObject::invokeMethod(this, "clearChatNotify", Qt::QueuedConnection);
|
|
|
|
}
|
2014-12-29 21:41:05 +00:00
|
|
|
}
|
2010-03-17 15:34:36 +00:00
|
|
|
}
|
|
|
|
|
2014-12-29 21:41:05 +00:00
|
|
|
void FriendsDialog::chatStatusReceived(const ChatId &chat_id, const QString &status_string)
|
2012-04-12 23:00:39 +00:00
|
|
|
{
|
2014-12-29 21:41:05 +00:00
|
|
|
if(chat_id.isBroadcast())
|
|
|
|
{
|
|
|
|
QString name = QString::fromUtf8(rsPeers->getPeerName(chat_id.broadcast_status_peer_id).c_str());
|
|
|
|
ui.chatWidget->updateStatusString(name + " %1", status_string);
|
2012-04-12 23:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-17 17:27:47 +00:00
|
|
|
void FriendsDialog::addFriend()
|
2010-09-29 19:30:59 +00:00
|
|
|
{
|
2011-10-20 21:34:44 +00:00
|
|
|
std::string groupId = ui.friendList->getSelectedGroupId();
|
2010-09-29 19:30:59 +00:00
|
|
|
|
|
|
|
ConnectFriendWizard connwiz (this);
|
|
|
|
|
|
|
|
if (groupId.empty() == false) {
|
|
|
|
connwiz.setGroup(groupId);
|
|
|
|
}
|
|
|
|
|
|
|
|
connwiz.exec ();
|
|
|
|
}
|
|
|
|
|
2011-05-17 17:27:47 +00:00
|
|
|
void FriendsDialog::getAvatar()
|
2009-09-02 22:42:31 +00:00
|
|
|
{
|
2011-08-12 20:27:05 +00:00
|
|
|
QByteArray ba;
|
|
|
|
if (misc::getOpenAvatarPicture(this, ba))
|
2009-09-02 22:42:31 +00:00
|
|
|
{
|
2011-05-24 23:35:11 +00:00
|
|
|
#ifdef FRIENDS_DEBUG
|
2011-08-12 20:27:05 +00:00
|
|
|
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
|
2011-05-24 23:35:11 +00:00
|
|
|
#endif
|
2009-09-02 22:42:31 +00:00
|
|
|
|
2011-08-12 20:27:05 +00:00
|
|
|
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()) ; // last char 0 included.
|
2009-09-02 22:42:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-29 22:52:46 +00:00
|
|
|
/** Loads own personal status */
|
2011-05-17 17:27:47 +00:00
|
|
|
void FriendsDialog::loadmypersonalstatus()
|
2009-09-29 22:52:46 +00:00
|
|
|
{
|
2014-12-15 15:53:10 +00:00
|
|
|
QString statustring = QString::fromUtf8(rsMsgs->getCustomStateString().c_str());
|
|
|
|
|
|
|
|
if (statustring.isEmpty())
|
|
|
|
{
|
2014-12-22 15:44:47 +00:00
|
|
|
ui.mypersonalstatusLabel->setText(tr("Set your status message here."));
|
2014-12-15 15:53:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.mypersonalstatusLabel->setText(statustring);
|
|
|
|
}
|
2009-09-29 22:52:46 +00:00
|
|
|
}
|
2009-10-08 19:08:44 +00:00
|
|
|
|
2015-01-10 13:13:41 +00:00
|
|
|
void FriendsDialog::clearChatNotify()
|
|
|
|
{
|
|
|
|
ChatUserNotify::clearWaitingChat(ChatId::makeBroadcastId());
|
|
|
|
}
|
|
|
|
|
2011-05-17 17:27:47 +00:00
|
|
|
void FriendsDialog::statusmessage()
|
2009-10-08 19:08:44 +00:00
|
|
|
{
|
2010-05-03 00:09:55 +00:00
|
|
|
StatusMessage statusmsgdialog (this);
|
|
|
|
statusmsgdialog.exec();
|
2009-10-08 19:08:44 +00:00
|
|
|
}
|
2010-01-31 22:29:30 +00:00
|
|
|
|
2012-03-30 23:02:52 +00:00
|
|
|
/*static*/ bool FriendsDialog::isGroupChatActive()
|
|
|
|
{
|
|
|
|
FriendsDialog *friendsDialog = dynamic_cast<FriendsDialog*>(MainWindow::getPage(MainWindow::Friends));
|
|
|
|
if (!friendsDialog) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (friendsDialog->ui.tabWidget->currentWidget() == friendsDialog->ui.groupChatTab) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void FriendsDialog::groupChatActivate()
|
|
|
|
{
|
|
|
|
FriendsDialog *friendsDialog = dynamic_cast<FriendsDialog*>(MainWindow::getPage(MainWindow::Friends));
|
|
|
|
if (!friendsDialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::showWindow(MainWindow::Friends);
|
|
|
|
friendsDialog->ui.tabWidget->setCurrentWidget(friendsDialog->ui.groupChatTab);
|
2014-12-29 21:41:05 +00:00
|
|
|
friendsDialog->ui.chatWidget->focusDialog();
|
2012-03-30 23:02:52 +00:00
|
|
|
}
|