2018-12-25 15:34:59 -05: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-14 22:18:48 -05:00
|
|
|
|
2011-10-20 17:34:44 -04:00
|
|
|
#include <time.h>
|
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QDropEvent>
|
2011-10-20 17:34:44 -04:00
|
|
|
#include <QMenu>
|
2012-05-11 20:40:53 -04:00
|
|
|
#include <QTimer>
|
2012-10-24 09:22:14 -04:00
|
|
|
#include <QMessageBox>
|
2008-11-24 09:07:26 -05:00
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
#include <retroshare/rspeers.h>
|
2011-09-29 05:20:09 -04:00
|
|
|
#include <retroshare/rshistory.h>
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2012-08-05 16:12:55 -04:00
|
|
|
#include "chat/ChatUserNotify.h"
|
2010-09-19 20:10:51 -04:00
|
|
|
#include "connect/ConnectFriendWizard.h"
|
2010-09-21 12:11:19 -04:00
|
|
|
#include "groups/CreateGroup.h"
|
2010-05-02 20:09:55 -04:00
|
|
|
#include "MainWindow.h"
|
2010-08-12 12:00:21 -04:00
|
|
|
#include "NewsFeed.h"
|
2011-10-20 17:34:44 -04:00
|
|
|
#include "notifyqt.h"
|
|
|
|
#include "profile/ProfileWidget.h"
|
|
|
|
#include "profile/StatusMessage.h"
|
|
|
|
#include "RetroShareLink.h"
|
|
|
|
#include "settings/rsharesettings.h"
|
2010-12-02 19:54:40 -05:00
|
|
|
#include "util/misc.h"
|
2012-11-15 16:35:37 -05:00
|
|
|
#include "util/DateTime.h"
|
2011-10-20 17:34:44 -04:00
|
|
|
#include "FriendsDialog.h"
|
2013-02-22 16:42:27 -05:00
|
|
|
#include "NetworkView.h"
|
|
|
|
#include "NetworkDialog.h"
|
2019-06-28 05:12:44 -04:00
|
|
|
#include "gui/common/NewFriendList.h"
|
2014-05-07 19:45:53 -04:00
|
|
|
#include "gui/Identity/IdDialog.h"
|
2011-10-20 17:34:44 -04:00
|
|
|
/* Images for Newsfeed icons */
|
2014-05-09 22:38:47 -04:00
|
|
|
//#define IMAGE_NEWSFEED ""
|
|
|
|
//#define IMAGE_NEWSFEED_NEW ":/images/message-state-new.png"
|
2019-11-24 00:04:10 -05:00
|
|
|
#define IMAGE_NETWORK2 ":/icons/png/netgraph2.png"
|
|
|
|
#define IMAGE_PEERS ":/icons/png/digital-key.png"
|
2014-05-07 19:45:53 -04:00
|
|
|
#define IMAGE_IDENTITY ":/images/identity/identities_32.png"
|
2008-11-24 09:07:26 -05:00
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
/******
|
2011-05-24 19:35:11 -04:00
|
|
|
* #define FRIENDS_DEBUG 1
|
2008-07-09 05:53:47 -04:00
|
|
|
*****/
|
|
|
|
|
2012-01-18 15:02:19 -05:00
|
|
|
static FriendsDialog *instance = NULL;
|
|
|
|
|
2008-11-24 09:07:26 -05:00
|
|
|
/** Constructor */
|
2019-09-22 12:13:18 -04:00
|
|
|
FriendsDialog::FriendsDialog(QWidget *parent) : MainPage(parent)
|
2008-11-24 09:07:26 -05:00
|
|
|
{
|
2010-09-04 10:23:30 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
2009-09-30 18:30:57 -04:00
|
|
|
|
2018-11-20 09:54:24 -05:00
|
|
|
if (!instance) instance = this;
|
|
|
|
|
|
|
|
#ifdef RS_DIRECT_CHAT
|
2014-12-29 16:41:05 -05: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 15:02:19 -05:00
|
|
|
|
2019-06-28 05:12:44 -04: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 09:54:24 -05:00
|
|
|
#else // def RS_DIRECT_CHAT
|
|
|
|
ui.tabWidget->removeTab(ui.tabWidget->indexOf(ui.groupChatTab));
|
|
|
|
#endif // def RS_DIRECT_CHAT
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2012-08-26 16:31:10 -04:00
|
|
|
connect( ui.mypersonalstatusLabel, SIGNAL(clicked()), SLOT(statusmessage()));
|
2010-09-04 10:23:30 -04: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 17:34:44 -04:00
|
|
|
|
2011-09-05 17:19:07 -04:00
|
|
|
ui.avatar->setOwnId();
|
2015-02-07 17:43:53 -05:00
|
|
|
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
|
2011-09-05 17:19:07 -04:00
|
|
|
|
2012-01-18 15:02:19 -05:00
|
|
|
ui.tabWidget->setTabPosition(QTabWidget::North);
|
2014-09-09 15:19:18 -04:00
|
|
|
ui.tabWidget->addTab(networkView = new NetworkView(),QIcon(IMAGE_NETWORK2), tr("Network graph"));
|
2013-07-16 16:00:46 -04:00
|
|
|
ui.tabWidget->addTab(networkDialog = new NetworkDialog(),QIcon(IMAGE_PEERS), tr("Keyring"));
|
2013-02-22 16:42:27 -05:00
|
|
|
|
2012-01-18 15:02:19 -05:00
|
|
|
ui.tabWidget->hideCloseButton(0);
|
|
|
|
ui.tabWidget->hideCloseButton(1);
|
|
|
|
ui.tabWidget->hideCloseButton(2);
|
|
|
|
ui.tabWidget->hideCloseButton(3);
|
2014-05-07 19:45:53 -04:00
|
|
|
ui.tabWidget->hideCloseButton(4);
|
2010-11-10 07:24:36 -05:00
|
|
|
|
2011-08-15 19:42:07 -04:00
|
|
|
/* Set initial size the splitter */
|
2014-12-12 14:44:45 -05:00
|
|
|
ui.splitter->setStretchFactor(0, 0);
|
|
|
|
ui.splitter->setStretchFactor(1, 1);
|
2011-08-15 19:42:07 -04:00
|
|
|
|
2010-09-04 10:23:30 -04:00
|
|
|
loadmypersonalstatus();
|
|
|
|
|
2014-12-23 20:40:08 -05:00
|
|
|
ui.mypersonalstatusLabel->setMinimumWidth(25);
|
|
|
|
|
2010-09-04 10:23:30 -04:00
|
|
|
// load settings
|
2011-10-20 17:34:44 -04:00
|
|
|
RsAutoUpdatePage::lockAllEvents();
|
2019-08-03 15:07:48 -04: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-11 20:26:26 -05:00
|
|
|
ui.friendList->setShowGroups(true);
|
2010-09-04 10:23:30 -04:00
|
|
|
processSettings(true);
|
2011-10-20 17:34:44 -04:00
|
|
|
RsAutoUpdatePage::unlockAllEvents();
|
2010-09-04 10:23:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
// add self nick and Avatar to Friends.
|
|
|
|
RsPeerDetails pd ;
|
|
|
|
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),pd)) {
|
2015-05-12 16:30:44 -04:00
|
|
|
ui.nicknameLabel->setText(QString::fromUtf8(pd.name.c_str()) + " (" + QString::fromUtf8(pd.location.c_str())+")");
|
2010-09-04 10:23:30 -04:00
|
|
|
}
|
|
|
|
|
2013-09-08 11:08:36 -04:00
|
|
|
QString hlp_str = tr(
|
2015-06-30 12:44:58 -04:00
|
|
|
" <h1><img width=\"32\" src=\":/icons/help_64.png\"> Network</h1> \
|
2014-09-09 15:19:18 -04:00
|
|
|
<p>The Network tab shows your friend Retroshare nodes: the neighbor Retroshare nodes that are connected to you. \
|
2013-09-08 11:08:36 -04:00
|
|
|
</p> \
|
2014-09-09 15:19:18 -04: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 11:08:36 -04:00
|
|
|
<p>On the right, you will find 3 useful tabs: \
|
|
|
|
<ul> \
|
2014-09-09 15:19:18 -04: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 11:08:36 -04:00
|
|
|
</ul> </p> \
|
|
|
|
") ;
|
2013-07-19 08:18:58 -04:00
|
|
|
|
2017-02-25 17:52:57 -05:00
|
|
|
registerHelpButton(ui.helpButton, hlp_str,"FriendsDialog") ;
|
2008-11-24 09:07:26 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-05-17 13:27:47 -04:00
|
|
|
FriendsDialog::~FriendsDialog ()
|
2010-05-11 16:02:52 -04:00
|
|
|
{
|
2010-06-08 17:38:36 -04:00
|
|
|
// save settings
|
|
|
|
processSettings(false);
|
2012-01-18 15:02:19 -05:00
|
|
|
|
|
|
|
if (this == instance) {
|
|
|
|
instance = NULL;
|
|
|
|
}
|
2010-05-11 16:02:52 -04:00
|
|
|
}
|
|
|
|
|
2013-02-23 09:29:36 -05:00
|
|
|
void FriendsDialog::activatePage(FriendsDialog::Page page)
|
|
|
|
{
|
|
|
|
switch(page)
|
|
|
|
{
|
2014-05-07 19:45:53 -04:00
|
|
|
case FriendsDialog::IdTab: ui.tabWidget->setCurrentWidget(idDialog) ;
|
|
|
|
break ;
|
2013-02-23 09:29:36 -05: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 17:19:20 -05:00
|
|
|
UserNotify *FriendsDialog::createUserNotify(QObject *parent)
|
2012-08-05 16:12:55 -04:00
|
|
|
{
|
|
|
|
return new ChatUserNotify(parent);
|
|
|
|
}
|
|
|
|
|
2011-05-17 13:27:47 -04:00
|
|
|
void FriendsDialog::processSettings(bool bLoad)
|
2010-06-08 17:38:36 -04:00
|
|
|
{
|
2011-05-17 13:27:47 -04:00
|
|
|
Settings->beginGroup(QString("FriendsDialog"));
|
2010-06-08 17:38:36 -04:00
|
|
|
|
|
|
|
if (bLoad) {
|
|
|
|
// load settings
|
|
|
|
|
|
|
|
// state of splitter
|
|
|
|
ui.splitter->restoreState(Settings->value("Splitter").toByteArray());
|
2014-12-29 16:41:05 -05:00
|
|
|
//remove ui.splitter_2->restoreState(Settings->value("GroupChatSplitter").toByteArray());
|
2010-06-08 17:38:36 -04:00
|
|
|
} else {
|
|
|
|
// save settings
|
|
|
|
|
|
|
|
// state of splitter
|
|
|
|
Settings->setValue("Splitter", ui.splitter->saveState());
|
2014-12-29 16:41:05 -05:00
|
|
|
//remove Settings->setValue("GroupChatSplitter", ui.splitter_2->saveState());
|
2010-06-08 17:38:36 -04:00
|
|
|
}
|
|
|
|
|
2011-11-11 20:26:26 -05:00
|
|
|
ui.friendList->processSettings(bLoad);
|
|
|
|
|
2010-06-08 17:38:36 -04:00
|
|
|
Settings->endGroup();
|
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void FriendsDialog::chatMessageReceived(const ChatMessage &msg)
|
2010-03-17 11:34:36 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05: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 11:34:36 -04:00
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
ui.chatWidget->addChatMsg(msg.incoming, name, sendTime, recvTime, message, ChatWidget::MSGTYPE_NORMAL);
|
2015-01-10 08:13:41 -05: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 16:41:05 -05:00
|
|
|
}
|
2010-03-17 11:34:36 -04:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void FriendsDialog::chatStatusReceived(const ChatId &chat_id, const QString &status_string)
|
2012-04-12 19:00:39 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05: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 19:00:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-17 13:27:47 -04:00
|
|
|
void FriendsDialog::addFriend()
|
2010-09-29 15:30:59 -04:00
|
|
|
{
|
2011-10-20 17:34:44 -04:00
|
|
|
std::string groupId = ui.friendList->getSelectedGroupId();
|
2010-09-29 15:30:59 -04:00
|
|
|
|
|
|
|
ConnectFriendWizard connwiz (this);
|
|
|
|
|
|
|
|
if (groupId.empty() == false) {
|
|
|
|
connwiz.setGroup(groupId);
|
|
|
|
}
|
|
|
|
|
|
|
|
connwiz.exec ();
|
|
|
|
}
|
|
|
|
|
2011-05-17 13:27:47 -04:00
|
|
|
void FriendsDialog::getAvatar()
|
2009-09-02 18:42:31 -04:00
|
|
|
{
|
2011-08-12 16:27:05 -04:00
|
|
|
QByteArray ba;
|
|
|
|
if (misc::getOpenAvatarPicture(this, ba))
|
2009-09-02 18:42:31 -04:00
|
|
|
{
|
2011-05-24 19:35:11 -04:00
|
|
|
#ifdef FRIENDS_DEBUG
|
2011-08-12 16:27:05 -04:00
|
|
|
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
|
2011-05-24 19:35:11 -04:00
|
|
|
#endif
|
2009-09-02 18:42:31 -04:00
|
|
|
|
2011-08-12 16:27:05 -04:00
|
|
|
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()) ; // last char 0 included.
|
2009-09-02 18:42:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-29 18:52:46 -04:00
|
|
|
/** Loads own personal status */
|
2011-05-17 13:27:47 -04:00
|
|
|
void FriendsDialog::loadmypersonalstatus()
|
2009-09-29 18:52:46 -04:00
|
|
|
{
|
2014-12-15 10:53:10 -05:00
|
|
|
QString statustring = QString::fromUtf8(rsMsgs->getCustomStateString().c_str());
|
|
|
|
|
|
|
|
if (statustring.isEmpty())
|
|
|
|
{
|
2014-12-22 10:44:47 -05:00
|
|
|
ui.mypersonalstatusLabel->setText(tr("Set your status message here."));
|
2014-12-15 10:53:10 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.mypersonalstatusLabel->setText(statustring);
|
|
|
|
}
|
2009-09-29 18:52:46 -04:00
|
|
|
}
|
2009-10-08 15:08:44 -04:00
|
|
|
|
2015-01-10 08:13:41 -05:00
|
|
|
void FriendsDialog::clearChatNotify()
|
|
|
|
{
|
|
|
|
ChatUserNotify::clearWaitingChat(ChatId::makeBroadcastId());
|
|
|
|
}
|
|
|
|
|
2011-05-17 13:27:47 -04:00
|
|
|
void FriendsDialog::statusmessage()
|
2009-10-08 15:08:44 -04:00
|
|
|
{
|
2010-05-02 20:09:55 -04:00
|
|
|
StatusMessage statusmsgdialog (this);
|
|
|
|
statusmsgdialog.exec();
|
2009-10-08 15:08:44 -04:00
|
|
|
}
|
2010-01-31 17:29:30 -05:00
|
|
|
|
2012-03-30 19:02:52 -04: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 16:41:05 -05:00
|
|
|
friendsDialog->ui.chatWidget->focusDialog();
|
2012-03-30 19:02:52 -04:00
|
|
|
}
|