2015-06-19 22:58:48 +08:00
|
|
|
/*
|
2016-11-28 21:33:38 +08:00
|
|
|
Copyright © 2015 by The qTox Project Contributors
|
2015-06-19 22:58:48 +08:00
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
qTox is libre 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "contentdialog.h"
|
2017-02-26 06:06:07 +08:00
|
|
|
#include "splitterrestorer.h"
|
2016-06-30 18:29:30 +08:00
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QSplitter>
|
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
#include "contentlayout.h"
|
|
|
|
#include "friendwidget.h"
|
2015-06-23 02:01:50 +08:00
|
|
|
#include "groupwidget.h"
|
2015-06-19 22:58:48 +08:00
|
|
|
#include "style.h"
|
2015-06-23 02:01:50 +08:00
|
|
|
#include "widget.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/core/core.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/friend.h"
|
|
|
|
#include "src/friendlist.h"
|
|
|
|
#include "src/group.h"
|
|
|
|
#include "src/grouplist.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/persistence/settings.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/widget/form/chatform.h"
|
|
|
|
#include "src/widget/form/settingswidget.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/widget/friendlistlayout.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/widget/translator.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "tool/adjustingscrollarea.h"
|
2015-06-24 00:54:00 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
QString ContentDialog::username = "";
|
2015-06-19 22:58:48 +08:00
|
|
|
ContentDialog* ContentDialog::currentDialog = nullptr;
|
|
|
|
QHash<int, std::tuple<ContentDialog*, GenericChatroomWidget*>> ContentDialog::friendList;
|
2015-06-23 02:01:50 +08:00
|
|
|
QHash<int, std::tuple<ContentDialog*, GenericChatroomWidget*>> ContentDialog::groupList;
|
2015-06-19 22:58:48 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
static const int minWidget = 220;
|
|
|
|
static const int minHeight = 220;
|
|
|
|
static const QSize minSize(minHeight, minWidget);
|
|
|
|
static const QSize defaultSize(720, 400);
|
|
|
|
|
2015-06-30 00:26:49 +08:00
|
|
|
ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent)
|
2015-07-30 07:46:19 +08:00
|
|
|
: ActivateDialog(parent, Qt::Window)
|
2017-02-26 22:22:28 +08:00
|
|
|
, splitter{new QSplitter(this)}
|
|
|
|
, friendLayout{new FriendListLayout(this)}
|
2015-06-19 22:58:48 +08:00
|
|
|
, activeChatroomWidget(nullptr)
|
2015-06-30 00:26:49 +08:00
|
|
|
, settingsWidget(settingsWidget)
|
2016-06-30 18:29:30 +08:00
|
|
|
, videoSurfaceSize(QSize())
|
|
|
|
, videoCount(0)
|
2015-06-19 22:58:48 +08:00
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
const Settings& s = Settings::getInstance();
|
2016-07-07 17:55:53 +08:00
|
|
|
setStyleSheet(Style::getStylesheet(":/ui/contentDialog/contentDialog.css"));
|
2017-02-26 22:22:28 +08:00
|
|
|
|
|
|
|
friendLayout->setMargin(0);
|
|
|
|
friendLayout->setSpacing(0);
|
|
|
|
|
2017-06-01 15:50:59 +08:00
|
|
|
layouts = {friendLayout->getLayoutOnline(), groupLayout.getLayout(),
|
|
|
|
friendLayout->getLayoutOffline()};
|
2017-02-26 22:22:28 +08:00
|
|
|
|
|
|
|
if (s.getGroupchatPosition()) {
|
|
|
|
layouts.swap(0, 1);
|
|
|
|
}
|
2015-06-19 22:58:48 +08:00
|
|
|
|
2017-01-06 19:02:54 +08:00
|
|
|
QWidget* friendWidget = new QWidget();
|
2015-06-19 22:58:48 +08:00
|
|
|
friendWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
|
friendWidget->setAutoFillBackground(true);
|
2015-06-27 04:13:20 +08:00
|
|
|
friendWidget->setLayout(friendLayout);
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
onGroupchatPositionChanged(s.getGroupchatPosition());
|
2015-06-19 22:58:48 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
QScrollArea* friendScroll = new QScrollArea(this);
|
2017-02-26 22:22:28 +08:00
|
|
|
friendScroll->setMinimumWidth(minWidget);
|
2015-06-19 22:58:48 +08:00
|
|
|
friendScroll->setFrameStyle(QFrame::NoFrame);
|
|
|
|
friendScroll->setLayoutDirection(Qt::RightToLeft);
|
|
|
|
friendScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
friendScroll->setStyleSheet(Style::getStylesheet(":/ui/friendList/friendList.css"));
|
|
|
|
friendScroll->setWidgetResizable(true);
|
|
|
|
friendScroll->setWidget(friendWidget);
|
|
|
|
|
|
|
|
QWidget* contentWidget = new QWidget(this);
|
|
|
|
contentWidget->setAutoFillBackground(true);
|
2017-02-26 22:22:28 +08:00
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
contentLayout = new ContentLayout(contentWidget);
|
|
|
|
contentLayout->setMargin(0);
|
|
|
|
contentLayout->setSpacing(0);
|
|
|
|
|
|
|
|
splitter->addWidget(friendScroll);
|
|
|
|
splitter->addWidget(contentWidget);
|
|
|
|
splitter->setStretchFactor(1, 1);
|
|
|
|
splitter->setCollapsible(1, false);
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
QVBoxLayout* boxLayout = new QVBoxLayout(this);
|
|
|
|
boxLayout->setMargin(0);
|
|
|
|
boxLayout->setSpacing(0);
|
|
|
|
boxLayout->addWidget(splitter);
|
2015-06-30 00:26:49 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
setMinimumSize(minSize);
|
2015-06-19 22:58:48 +08:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
2017-02-26 06:06:07 +08:00
|
|
|
QByteArray geometry = s.getDialogGeometry();
|
2015-07-01 21:22:05 +08:00
|
|
|
|
2017-02-26 06:06:07 +08:00
|
|
|
if (!geometry.isNull()) {
|
2015-07-01 21:22:05 +08:00
|
|
|
restoreGeometry(geometry);
|
2017-02-26 06:06:07 +08:00
|
|
|
} else {
|
2017-02-26 22:22:28 +08:00
|
|
|
resize(defaultSize);
|
2017-02-26 06:06:07 +08:00
|
|
|
}
|
2015-07-01 21:22:05 +08:00
|
|
|
|
2017-02-26 06:06:07 +08:00
|
|
|
SplitterRestorer restorer(splitter);
|
2017-05-11 17:58:16 +08:00
|
|
|
restorer.restore(s.getDialogSplitterState(), size());
|
2015-06-19 22:58:48 +08:00
|
|
|
|
|
|
|
currentDialog = this;
|
2015-06-24 00:54:00 +08:00
|
|
|
setAcceptDrops(true);
|
2015-06-30 00:26:49 +08:00
|
|
|
|
|
|
|
new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close()));
|
|
|
|
new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab, this, SLOT(previousContact()));
|
|
|
|
new QShortcut(Qt::CTRL + Qt::Key_Tab, this, SLOT(nextContact()));
|
|
|
|
new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(previousContact()));
|
|
|
|
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact()));
|
2015-07-03 01:16:11 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
connect(&s, &Settings::groupchatPositionChanged, this, &ContentDialog::onGroupchatPositionChanged);
|
|
|
|
connect(splitter, &QSplitter::splitterMoved, this, &ContentDialog::saveSplitterState);
|
2015-07-03 02:38:18 +08:00
|
|
|
|
|
|
|
Translator::registerHandler(std::bind(&ContentDialog::retranslateUi, this), this);
|
2015-06-19 22:58:48 +08:00
|
|
|
}
|
|
|
|
|
2017-06-01 15:50:59 +08:00
|
|
|
void ContentDialog::removeCurrent(QHash<int, ContactInfo>& infos)
|
|
|
|
{
|
|
|
|
for (auto it = infos.begin(); it != infos.end();) {
|
2017-02-26 22:22:28 +08:00
|
|
|
if (std::get<0>(*it) == this) {
|
|
|
|
it = infos.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
ContentDialog::~ContentDialog()
|
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
if (currentDialog == this) {
|
2015-06-19 22:58:48 +08:00
|
|
|
currentDialog = nullptr;
|
|
|
|
}
|
2015-06-27 04:13:20 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
removeCurrent(friendList);
|
|
|
|
removeCurrent(groupList);
|
2015-07-03 02:38:18 +08:00
|
|
|
|
|
|
|
Translator::unregister(this);
|
2015-06-19 22:58:48 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 18:02:32 +08:00
|
|
|
FriendWidget* ContentDialog::addFriend(const Friend* frnd)
|
2015-06-19 22:58:48 +08:00
|
|
|
{
|
2017-04-18 05:55:23 +08:00
|
|
|
bool compact = Settings::getInstance().getCompactLayout();
|
2017-07-26 17:39:54 +08:00
|
|
|
uint32_t friendId = frnd->getFriendId();
|
2017-07-26 18:02:32 +08:00
|
|
|
FriendWidget* friendWidget = new FriendWidget(frnd, compact);
|
2017-02-26 22:22:28 +08:00
|
|
|
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
|
2015-06-19 22:58:48 +08:00
|
|
|
|
2017-05-28 17:39:11 +08:00
|
|
|
ChatForm* form = frnd->getChatForm();
|
2016-08-24 08:13:26 +08:00
|
|
|
connect(frnd, &Friend::aliasChanged, this, &ContentDialog::updateFriendWidget);
|
2017-05-28 17:39:11 +08:00
|
|
|
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
|
|
|
|
connect(friendWidget, &FriendWidget::newWindowOpened, this, &ContentDialog::openNewDialog);
|
|
|
|
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, form, &ChatForm::focusInput);
|
2015-06-19 22:58:48 +08:00
|
|
|
|
2015-07-01 00:29:09 +08:00
|
|
|
ContentDialog* lastDialog = getFriendDialog(friendId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (lastDialog) {
|
2015-07-01 00:29:09 +08:00
|
|
|
lastDialog->removeFriend(friendId);
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-07-01 00:29:09 +08:00
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
friendList.insert(friendId, std::make_tuple(this, friendWidget));
|
2016-08-20 16:34:55 +08:00
|
|
|
// FIXME: emit should be removed
|
2017-05-28 17:39:11 +08:00
|
|
|
emit friendWidget->chatroomWidgetClicked(friendWidget);
|
2015-06-23 02:01:50 +08:00
|
|
|
|
|
|
|
return friendWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupWidget* ContentDialog::addGroup(int groupId, const QString& name)
|
|
|
|
{
|
2017-04-18 05:55:23 +08:00
|
|
|
bool compact = Settings::getInstance().getCompactLayout();
|
|
|
|
GroupWidget* groupWidget = new GroupWidget(groupId, name, compact);
|
2015-06-30 00:26:49 +08:00
|
|
|
groupLayout.addSortedWidget(groupWidget);
|
2015-06-23 02:01:50 +08:00
|
|
|
|
|
|
|
Group* group = groupWidget->getGroup();
|
|
|
|
connect(group, &Group::titleChanged, this, &ContentDialog::updateGroupWidget);
|
|
|
|
connect(group, &Group::userListChanged, this, &ContentDialog::updateGroupWidget);
|
2017-05-28 17:39:11 +08:00
|
|
|
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
|
|
|
|
connect(groupWidget, &FriendWidget::newWindowOpened, this, &ContentDialog::openNewDialog);
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2015-07-01 00:29:09 +08:00
|
|
|
ContentDialog* lastDialog = getGroupDialog(groupId);
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
if (lastDialog) {
|
2015-07-01 00:29:09 +08:00
|
|
|
lastDialog->removeGroup(groupId);
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
|
|
|
groupList.insert(groupId, std::make_tuple(this, groupWidget));
|
2016-08-20 16:34:55 +08:00
|
|
|
// FIXME: emit should be removed
|
2017-05-28 17:39:11 +08:00
|
|
|
emit groupWidget->chatroomWidgetClicked(groupWidget);
|
2015-06-23 02:01:50 +08:00
|
|
|
|
|
|
|
return groupWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentDialog::removeFriend(int friendId)
|
|
|
|
{
|
2015-06-27 04:13:20 +08:00
|
|
|
auto iter = friendList.find(friendId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == friendList.end()) {
|
2015-06-27 04:13:20 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-27 04:13:20 +08:00
|
|
|
|
|
|
|
FriendWidget* chatroomWidget = static_cast<FriendWidget*>(std::get<1>(iter.value()));
|
2017-02-26 19:52:45 +08:00
|
|
|
disconnect(chatroomWidget->getFriend(), &Friend::aliasChanged, this,
|
|
|
|
&ContentDialog::updateFriendWidget);
|
2015-06-27 04:13:20 +08:00
|
|
|
|
2016-01-05 05:34:30 +08:00
|
|
|
// Need to find replacement to show here instead.
|
2017-02-26 22:22:28 +08:00
|
|
|
if (activeChatroomWidget == chatroomWidget) {
|
2015-07-01 00:29:09 +08:00
|
|
|
cycleContacts(true, false);
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-27 04:13:20 +08:00
|
|
|
|
|
|
|
friendLayout->removeFriendWidget(chatroomWidget, Status::Offline);
|
|
|
|
friendLayout->removeFriendWidget(chatroomWidget, Status::Online);
|
|
|
|
|
|
|
|
chatroomWidget->deleteLater();
|
|
|
|
friendList.remove(friendId);
|
2015-07-01 00:29:09 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (chatroomWidgetCount() == 0) {
|
2015-07-01 00:29:09 +08:00
|
|
|
contentLayout->clear();
|
|
|
|
activeChatroomWidget = nullptr;
|
|
|
|
deleteLater();
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2015-07-01 00:29:09 +08:00
|
|
|
update();
|
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentDialog::removeGroup(int groupId)
|
|
|
|
{
|
2015-06-30 00:26:49 +08:00
|
|
|
Group* group = GroupList::findGroup(groupId);
|
2015-07-20 20:13:51 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (group) {
|
2015-07-20 20:13:51 +08:00
|
|
|
disconnect(group, &Group::titleChanged, this, &ContentDialog::updateGroupWidget);
|
|
|
|
disconnect(group, &Group::userListChanged, this, &ContentDialog::updateGroupWidget);
|
|
|
|
}
|
2015-06-30 00:26:49 +08:00
|
|
|
|
2015-07-03 21:16:27 +08:00
|
|
|
auto iter = groupList.find(groupId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == groupList.end()) {
|
2015-07-03 21:16:27 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-07-03 21:16:27 +08:00
|
|
|
|
|
|
|
GenericChatroomWidget* chatroomWidget = std::get<1>(iter.value());
|
|
|
|
|
2016-01-05 05:34:30 +08:00
|
|
|
// Need to find replacement to show here instead.
|
2017-02-26 22:22:28 +08:00
|
|
|
if (activeChatroomWidget == chatroomWidget) {
|
2015-07-03 21:16:27 +08:00
|
|
|
cycleContacts(true, false);
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-07-03 21:16:27 +08:00
|
|
|
|
|
|
|
groupLayout.removeSortedWidget(chatroomWidget);
|
|
|
|
chatroomWidget->deleteLater();
|
|
|
|
groupList.remove(groupId);
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (chatroomWidgetCount() == 0) {
|
2015-07-03 21:16:27 +08:00
|
|
|
contentLayout->clear();
|
|
|
|
activeChatroomWidget = nullptr;
|
|
|
|
deleteLater();
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2015-07-03 21:16:27 +08:00
|
|
|
update();
|
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-07-27 13:55:32 +08:00
|
|
|
bool ContentDialog::hasFriendWidget(int friendId, const GenericChatroomWidget* chatroomWidget) const
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
return hasWidget(friendId, chatroomWidget, friendList);
|
|
|
|
}
|
|
|
|
|
2017-07-27 13:55:32 +08:00
|
|
|
bool ContentDialog::hasGroupWidget(int groupId, const GenericChatroomWidget* chatroomWidget) const
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
return hasWidget(groupId, chatroomWidget, groupList);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ContentDialog::chatroomWidgetCount() const
|
|
|
|
{
|
2015-06-30 00:26:49 +08:00
|
|
|
return friendLayout->friendTotalCount() + groupLayout.getLayout()->count();
|
|
|
|
}
|
|
|
|
|
2015-07-01 19:49:36 +08:00
|
|
|
void ContentDialog::ensureSplitterVisible()
|
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
if (splitter->sizes().at(0) == 0) {
|
2015-07-01 19:49:36 +08:00
|
|
|
splitter->setSizes({1, 1});
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-07-01 19:49:36 +08:00
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Get current layout and index of current wiget in it.
|
|
|
|
* Current layout -- layout contains activated widget.
|
|
|
|
*
|
|
|
|
* @param[out] layout Current layout
|
|
|
|
* @return Index of current widget in current layout.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
int ContentDialog::getCurrentLayout(QLayout*& layout)
|
2015-06-30 00:26:49 +08:00
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
layout = friendLayout->getLayoutOnline();
|
|
|
|
int index = friendLayout->indexOfFriendWidget(activeChatroomWidget, true);
|
|
|
|
if (index != -1) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout = friendLayout->getLayoutOffline();
|
|
|
|
index = friendLayout->indexOfFriendWidget(activeChatroomWidget, false);
|
|
|
|
if (index != -1) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout = groupLayout.getLayout();
|
|
|
|
index = groupLayout.indexOfSortedWidget(activeChatroomWidget);
|
|
|
|
if (index != -1) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout = nullptr;
|
|
|
|
return -1;
|
|
|
|
}
|
2015-06-30 00:26:49 +08:00
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Activate next/previous contact.
|
|
|
|
* @param forward If true, activate next contace, previous otherwise.
|
|
|
|
* @param inverse ??? TODO: Add docs.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
void ContentDialog::cycleContacts(bool forward, bool inverse)
|
|
|
|
{
|
2015-06-30 00:26:49 +08:00
|
|
|
QLayout* currentLayout;
|
2017-02-26 22:22:28 +08:00
|
|
|
int index = getCurrentLayout(currentLayout);
|
|
|
|
if (!currentLayout || index == -1) {
|
|
|
|
return;
|
2015-06-30 00:26:49 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
if (!inverse && index == currentLayout->count() - 1) {
|
2015-07-03 21:16:27 +08:00
|
|
|
bool groupsOnTop = Settings::getInstance().getGroupchatPosition();
|
2016-07-31 22:17:11 +08:00
|
|
|
bool offlineEmpty = friendLayout->getLayoutOffline()->isEmpty();
|
2017-02-26 22:22:28 +08:00
|
|
|
bool onlineEmpty = friendLayout->getLayoutOnline()->isEmpty();
|
|
|
|
bool groupsEmpty = groupLayout.getLayout()->isEmpty();
|
|
|
|
bool isCurOffline = currentLayout == friendLayout->getLayoutOffline();
|
|
|
|
bool isCurOnline = currentLayout == friendLayout->getLayoutOnline();
|
|
|
|
bool isCurGroup = currentLayout == groupLayout.getLayout();
|
2017-06-01 15:50:59 +08:00
|
|
|
bool nextIsEmpty = (isCurOnline && offlineEmpty && (groupsEmpty || groupsOnTop))
|
|
|
|
|| (isCurGroup && offlineEmpty && (onlineEmpty || !groupsOnTop))
|
|
|
|
|| isCurOffline;
|
2017-02-26 22:22:28 +08:00
|
|
|
|
|
|
|
if (nextIsEmpty) {
|
2015-07-03 21:16:27 +08:00
|
|
|
forward = !forward;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 00:26:49 +08:00
|
|
|
index += forward ? 1 : -1;
|
2017-02-26 22:22:28 +08:00
|
|
|
// If goes out of the layout, then go to the next and skip empty. This loop goes more
|
|
|
|
// then 1 time, because for empty layout index will be out of interval (0 < 0 || 0 >= 0)
|
|
|
|
while (index < 0 || index >= currentLayout->count()) {
|
|
|
|
int oldCount = currentLayout->count();
|
|
|
|
currentLayout = nextLayout(currentLayout, forward);
|
|
|
|
int newCount = currentLayout->count();
|
2017-02-26 19:52:45 +08:00
|
|
|
if (index < 0) {
|
2017-02-26 22:22:28 +08:00
|
|
|
index = newCount - 1;
|
|
|
|
} else if (index >= oldCount) {
|
2015-07-17 22:12:00 +08:00
|
|
|
index = 0;
|
2016-08-20 16:34:55 +08:00
|
|
|
}
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-30 00:26:49 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
QWidget* widget = currentLayout->itemAt(index)->widget();
|
|
|
|
GenericChatroomWidget* chatWidget = qobject_cast<GenericChatroomWidget*>(widget);
|
|
|
|
if (chatWidget && chatWidget != activeChatroomWidget) {
|
|
|
|
// FIXME: emit should be removed
|
2017-05-28 17:39:11 +08:00
|
|
|
emit chatWidget->chatroomWidgetClicked(chatWidget);
|
2015-06-30 00:26:49 +08:00
|
|
|
}
|
2015-06-19 22:58:48 +08:00
|
|
|
}
|
|
|
|
|
2016-06-30 18:29:30 +08:00
|
|
|
void ContentDialog::onVideoShow(QSize size)
|
|
|
|
{
|
2016-10-30 06:48:03 +08:00
|
|
|
++videoCount;
|
2017-02-26 22:22:28 +08:00
|
|
|
if (videoCount > 1) {
|
2016-06-30 18:29:30 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2016-06-30 18:29:30 +08:00
|
|
|
|
|
|
|
videoSurfaceSize = size;
|
|
|
|
QSize minSize = minimumSize();
|
|
|
|
setMinimumSize(minSize + videoSurfaceSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentDialog::onVideoHide()
|
|
|
|
{
|
|
|
|
videoCount--;
|
2017-02-26 22:22:28 +08:00
|
|
|
if (videoCount > 0) {
|
2016-06-30 18:29:30 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2016-06-30 18:29:30 +08:00
|
|
|
|
|
|
|
QSize minSize = minimumSize();
|
|
|
|
setMinimumSize(minSize - videoSurfaceSize);
|
|
|
|
videoSurfaceSize = QSize();
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
ContentDialog* ContentDialog::current()
|
|
|
|
{
|
|
|
|
return currentDialog;
|
|
|
|
}
|
|
|
|
|
2017-05-08 02:04:55 +08:00
|
|
|
bool ContentDialog::friendWidgetExists(int friendId)
|
2017-02-26 22:22:28 +08:00
|
|
|
{
|
|
|
|
return existsWidget(friendId, friendList);
|
|
|
|
}
|
|
|
|
|
2017-05-08 02:04:55 +08:00
|
|
|
bool ContentDialog::groupWidgetExists(int groupId)
|
2017-02-26 22:22:28 +08:00
|
|
|
{
|
|
|
|
return existsWidget(groupId, groupList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentDialog::focusFriend(int friendId)
|
2015-06-19 22:58:48 +08:00
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
focusDialog(friendId, friendList);
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
void ContentDialog::focusGroup(int groupId)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
focusDialog(groupId, groupList);
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
2015-06-19 22:58:48 +08:00
|
|
|
|
2015-06-23 02:01:50 +08:00
|
|
|
void ContentDialog::updateFriendStatus(int friendId)
|
|
|
|
{
|
|
|
|
updateStatus(friendId, friendList);
|
2015-06-30 00:26:49 +08:00
|
|
|
ContentDialog* contentDialog = getFriendDialog(friendId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (contentDialog) {
|
|
|
|
auto iter = friendList.find(friendId).value();
|
|
|
|
GenericChatroomWidget* widget = std::get<1>(iter);
|
|
|
|
FriendWidget* friendWidget = static_cast<FriendWidget*>(widget);
|
|
|
|
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
|
|
|
contentDialog->friendLayout->addFriendWidget(friendWidget, f->getStatus());
|
2015-06-30 00:26:49 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
2015-06-19 22:58:48 +08:00
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Update friend status message.
|
|
|
|
* @param friendId Id friend, whose status was changed.
|
|
|
|
* @param message Status message.
|
|
|
|
*/
|
2017-02-26 19:52:45 +08:00
|
|
|
void ContentDialog::updateFriendStatusMessage(int friendId, const QString& message)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
auto iter = friendList.find(friendId);
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == friendList.end()) {
|
2015-06-23 02:01:50 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
|
|
|
std::get<1>(iter.value())->setStatusMsg(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentDialog::updateGroupStatus(int groupId)
|
|
|
|
{
|
|
|
|
updateStatus(groupId, groupList);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContentDialog::isFriendWidgetActive(int friendId)
|
|
|
|
{
|
|
|
|
return isWidgetActive(friendId, friendList);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContentDialog::isGroupWidgetActive(int groupId)
|
|
|
|
{
|
|
|
|
return isWidgetActive(groupId, groupList);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentDialog* ContentDialog::getFriendDialog(int friendId)
|
|
|
|
{
|
|
|
|
return getDialog(friendId, friendList);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentDialog* ContentDialog::getGroupDialog(int groupId)
|
|
|
|
{
|
|
|
|
return getDialog(groupId, groupList);
|
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Update window title and icon.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
void ContentDialog::updateTitleAndStatusIcon()
|
2015-07-03 01:16:11 +08:00
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
if (!activeChatroomWidget) {
|
|
|
|
setWindowTitle(username);
|
|
|
|
return;
|
|
|
|
}
|
2016-01-05 05:34:30 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
setWindowTitle(activeChatroomWidget->getTitle() + QStringLiteral(" - ") + username);
|
2016-01-05 05:34:30 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
bool isGroupchat = activeChatroomWidget->getGroup() != nullptr;
|
|
|
|
if (isGroupchat) {
|
|
|
|
setWindowIcon(QIcon(":/img/group.svg"));
|
|
|
|
return;
|
|
|
|
}
|
2016-01-05 05:34:30 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
Status currentStatus = activeChatroomWidget->getFriend()->getStatus();
|
|
|
|
|
2017-06-01 15:50:59 +08:00
|
|
|
QMap<Status, QIcon> icons{{Status::Online, QIcon(":/img/status/dot_online.svg")},
|
|
|
|
{Status::Away, QIcon(":/img/status/dot_away.svg")},
|
|
|
|
{Status::Busy, QIcon(":/img/status/dot_busy.svg")},
|
|
|
|
{Status::Offline, QIcon(":/img/status/dot_offline.svg")}};
|
2017-02-26 22:22:28 +08:00
|
|
|
|
|
|
|
setWindowIcon(icons[currentStatus]);
|
2015-07-03 01:16:11 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
/**
|
|
|
|
* @brief Update layouts order according to settings.
|
|
|
|
* @param groupOnTop If true move groupchat layout on the top. Move under online otherwise.
|
|
|
|
*/
|
|
|
|
void ContentDialog::reorderLayouts(bool newGroupOnTop)
|
2015-07-03 01:16:11 +08:00
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
bool oldGroupOnTop = layouts.first() == groupLayout.getLayout();
|
|
|
|
if (newGroupOnTop != oldGroupOnTop) {
|
|
|
|
layouts.swap(0, 1);
|
|
|
|
}
|
2015-07-03 01:16:11 +08:00
|
|
|
}
|
|
|
|
|
2015-06-30 00:26:49 +08:00
|
|
|
void ContentDialog::previousContact()
|
|
|
|
{
|
|
|
|
cycleContacts(false);
|
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Enable next contact.
|
|
|
|
*/
|
2015-06-30 00:26:49 +08:00
|
|
|
void ContentDialog::nextContact()
|
|
|
|
{
|
|
|
|
cycleContacts(true);
|
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Update username to show in the title.
|
|
|
|
* @param newName New name to display.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
void ContentDialog::setUsername(const QString& newName)
|
|
|
|
{
|
|
|
|
username = newName;
|
|
|
|
updateTitleAndStatusIcon();
|
|
|
|
}
|
|
|
|
|
2015-07-01 19:49:36 +08:00
|
|
|
bool ContentDialog::event(QEvent* event)
|
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
switch (event->type()) {
|
2016-08-19 20:44:30 +08:00
|
|
|
case QEvent::WindowActivate:
|
2017-02-26 22:22:28 +08:00
|
|
|
if (activeChatroomWidget) {
|
2016-08-19 20:44:30 +08:00
|
|
|
activeChatroomWidget->resetEventFlags();
|
|
|
|
activeChatroomWidget->updateStatusLight();
|
2017-02-26 22:22:28 +08:00
|
|
|
|
|
|
|
updateTitleAndStatusIcon();
|
2016-05-04 07:36:19 +08:00
|
|
|
|
2017-07-26 18:02:32 +08:00
|
|
|
const Friend* frnd = activeChatroomWidget->getFriend();
|
2016-08-19 20:44:30 +08:00
|
|
|
Group* group = activeChatroomWidget->getGroup();
|
2016-05-04 07:36:19 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (frnd) {
|
2016-08-19 20:44:30 +08:00
|
|
|
emit friendDialogShown(frnd);
|
2017-02-26 19:52:45 +08:00
|
|
|
} else if (group) {
|
2016-08-19 20:44:30 +08:00
|
|
|
emit groupDialogShown(group);
|
2015-07-01 19:49:36 +08:00
|
|
|
}
|
2016-08-19 20:44:30 +08:00
|
|
|
}
|
2015-07-01 19:49:36 +08:00
|
|
|
|
2016-08-19 20:44:30 +08:00
|
|
|
currentDialog = this;
|
2015-07-30 07:46:19 +08:00
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
2016-08-19 20:44:30 +08:00
|
|
|
emit activated();
|
2015-07-30 07:46:19 +08:00
|
|
|
#endif
|
2016-08-19 20:44:30 +08:00
|
|
|
default:
|
|
|
|
break;
|
2015-07-01 19:49:36 +08:00
|
|
|
}
|
|
|
|
|
2015-07-30 07:46:19 +08:00
|
|
|
return ActivateDialog::event(event);
|
2015-07-01 19:49:36 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void ContentDialog::dragEnterEvent(QDragEnterEvent* event)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
QObject* o = event->source();
|
|
|
|
FriendWidget* frnd = qobject_cast<FriendWidget*>(o);
|
|
|
|
GroupWidget* group = qobject_cast<GroupWidget*>(o);
|
|
|
|
if (frnd) {
|
2016-08-07 03:28:40 +08:00
|
|
|
ToxId toxId(event->mimeData()->text());
|
2017-02-26 19:52:45 +08:00
|
|
|
Friend* contact = FriendList::findFriend(toxId.getPublicKey());
|
2017-02-26 22:22:28 +08:00
|
|
|
if (!contact) {
|
2016-08-07 03:28:40 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2016-08-07 03:28:40 +08:00
|
|
|
|
2016-08-22 05:30:07 +08:00
|
|
|
int friendId = contact->getFriendId();
|
2015-06-24 00:54:00 +08:00
|
|
|
auto iter = friendList.find(friendId);
|
|
|
|
|
|
|
|
// If friend is already in a dialog then you can't drop friend where it already is.
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == friendList.end() || std::get<0>(iter.value()) != this) {
|
2015-06-24 00:54:00 +08:00
|
|
|
event->acceptProposedAction();
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2017-02-26 19:52:45 +08:00
|
|
|
} else if (group) {
|
2017-02-26 22:22:28 +08:00
|
|
|
if (!event->mimeData()->hasFormat("groupId")) {
|
2016-08-07 03:28:40 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-27 04:13:20 +08:00
|
|
|
|
2016-08-07 03:28:40 +08:00
|
|
|
int groupId = event->mimeData()->data("groupId").toInt();
|
2017-02-26 19:52:45 +08:00
|
|
|
Group* contact = GroupList::findGroup(groupId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (!contact) {
|
2016-08-07 03:28:40 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2016-08-07 03:28:40 +08:00
|
|
|
|
|
|
|
auto iter = groupList.find(groupId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == groupList.end() || std::get<0>(iter.value()) != this) {
|
2015-06-27 04:13:20 +08:00
|
|
|
event->acceptProposedAction();
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-27 04:13:20 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void ContentDialog::dropEvent(QDropEvent* event)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
QObject* o = event->source();
|
|
|
|
FriendWidget* frnd = qobject_cast<FriendWidget*>(o);
|
|
|
|
GroupWidget* group = qobject_cast<GroupWidget*>(o);
|
|
|
|
if (frnd) {
|
2016-08-07 03:28:40 +08:00
|
|
|
ToxId toxId(event->mimeData()->text());
|
2017-02-26 19:52:45 +08:00
|
|
|
Friend* contact = FriendList::findFriend(toxId.getPublicKey());
|
2017-02-26 22:22:28 +08:00
|
|
|
if (!contact) {
|
2016-08-07 03:28:40 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-24 00:54:00 +08:00
|
|
|
|
2016-08-22 05:30:07 +08:00
|
|
|
int friendId = contact->getFriendId();
|
2016-08-07 03:28:40 +08:00
|
|
|
auto iter = friendList.find(friendId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter != friendList.end()) {
|
2015-06-24 00:54:00 +08:00
|
|
|
std::get<0>(iter.value())->removeFriend(friendId);
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-24 00:54:00 +08:00
|
|
|
|
|
|
|
Widget::getInstance()->addFriendDialog(contact, this);
|
2015-07-01 19:49:36 +08:00
|
|
|
ensureSplitterVisible();
|
2017-02-26 19:52:45 +08:00
|
|
|
} else if (group) {
|
2017-02-26 22:22:28 +08:00
|
|
|
if (!event->mimeData()->hasFormat("groupId")) {
|
2016-08-07 03:28:40 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-27 04:13:20 +08:00
|
|
|
|
2016-08-07 03:28:40 +08:00
|
|
|
int groupId = event->mimeData()->data("groupId").toInt();
|
2017-02-26 19:52:45 +08:00
|
|
|
Group* contact = GroupList::findGroup(groupId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (!contact) {
|
2016-08-07 03:28:40 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2016-08-07 03:28:40 +08:00
|
|
|
|
|
|
|
auto iter = friendList.find(groupId);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter != friendList.end()) {
|
2015-06-27 04:13:20 +08:00
|
|
|
std::get<0>(iter.value())->removeGroup(groupId);
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-27 04:13:20 +08:00
|
|
|
|
|
|
|
Widget::getInstance()->addGroupDialog(contact, this);
|
2015-07-01 19:49:36 +08:00
|
|
|
ensureSplitterVisible();
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void ContentDialog::changeEvent(QEvent* event)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
QWidget::changeEvent(event);
|
2017-02-26 19:52:45 +08:00
|
|
|
if (event->type() == QEvent::ActivationChange) {
|
2017-02-26 22:22:28 +08:00
|
|
|
if (isActiveWindow()) {
|
2015-06-23 02:01:50 +08:00
|
|
|
currentDialog = this;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
2015-06-19 22:58:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentDialog::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
saveDialogGeometry();
|
2015-07-03 01:16:11 +08:00
|
|
|
QDialog::resizeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentDialog::moveEvent(QMoveEvent* event)
|
|
|
|
{
|
|
|
|
saveDialogGeometry();
|
|
|
|
QDialog::moveEvent(event);
|
2015-06-19 22:58:48 +08:00
|
|
|
}
|
|
|
|
|
2015-07-03 21:16:27 +08:00
|
|
|
void ContentDialog::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
// Ignore escape keyboard shortcut.
|
|
|
|
if (event->key() != Qt::Key_Escape) {
|
|
|
|
QDialog::keyPressEvent(event);
|
|
|
|
}
|
2015-07-03 21:16:27 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
2017-05-28 17:39:11 +08:00
|
|
|
* @brief Open a new dialog window associated with widget
|
|
|
|
* @param widget Widget associated with contact.
|
2017-03-05 04:35:42 +08:00
|
|
|
*/
|
2017-05-28 17:39:11 +08:00
|
|
|
void ContentDialog::openNewDialog(GenericChatroomWidget* widget)
|
2015-06-19 22:58:48 +08:00
|
|
|
{
|
2017-05-28 17:39:11 +08:00
|
|
|
ContentDialog* contentDialog = new ContentDialog(settingsWidget);
|
|
|
|
contentDialog->show();
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2017-05-28 17:39:11 +08:00
|
|
|
if (widget->getFriend()) {
|
|
|
|
removeFriend(widget->getFriend()->getFriendId());
|
|
|
|
Widget::getInstance()->addFriendDialog(widget->getFriend(), contentDialog);
|
|
|
|
} else {
|
|
|
|
removeGroup(widget->getGroup()->getGroupId());
|
|
|
|
Widget::getInstance()->addGroupDialog(widget->getGroup(), contentDialog);
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-05-28 17:39:11 +08:00
|
|
|
contentDialog->raise();
|
|
|
|
contentDialog->activateWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Show ContentDialog, activate chatroom widget.
|
|
|
|
* @param widget Widget which should be activated.
|
|
|
|
*/
|
|
|
|
void ContentDialog::activate(GenericChatroomWidget* widget)
|
|
|
|
{
|
2015-09-06 05:53:30 +08:00
|
|
|
// If we clicked on the currently active widget, don't reload and relayout everything
|
2017-02-26 22:22:28 +08:00
|
|
|
if (activeChatroomWidget == widget) {
|
2015-09-06 05:53:30 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-09-06 05:53:30 +08:00
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
contentLayout->clear();
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
if (activeChatroomWidget) {
|
2015-06-19 22:58:48 +08:00
|
|
|
activeChatroomWidget->setAsInactiveChatroom();
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-19 22:58:48 +08:00
|
|
|
|
|
|
|
activeChatroomWidget = widget;
|
|
|
|
|
|
|
|
widget->setChatForm(contentLayout);
|
|
|
|
widget->setAsActiveChatroom();
|
|
|
|
widget->resetEventFlags();
|
|
|
|
widget->updateStatusLight();
|
2017-02-26 22:22:28 +08:00
|
|
|
|
|
|
|
updateTitleAndStatusIcon();
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Update friend widget name and position.
|
|
|
|
* @param friendId Friend Id.
|
|
|
|
* @param alias Alias to display on widget.
|
|
|
|
*/
|
2016-08-24 08:13:26 +08:00
|
|
|
void ContentDialog::updateFriendWidget(uint32_t friendId, QString alias)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
|
|
|
GenericChatroomWidget* widget = std::get<1>(friendList.find(friendId).value());
|
2016-08-24 08:13:26 +08:00
|
|
|
FriendWidget* friendWidget = static_cast<FriendWidget*>(widget);
|
|
|
|
friendWidget->setName(alias);
|
|
|
|
|
|
|
|
Status status = f->getStatus();
|
|
|
|
friendLayout->addFriendWidget(friendWidget, status);
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Update group widget name and 'status'.
|
|
|
|
* @param w Group widget to update.
|
|
|
|
*/
|
2017-02-26 19:52:45 +08:00
|
|
|
void ContentDialog::updateGroupWidget(GroupWidget* w)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
ContactInfo info = groupList.find(w->groupId).value();
|
|
|
|
GroupWidget* widget = static_cast<GroupWidget*>(std::get<1>(info));
|
|
|
|
|
|
|
|
QString name = w->getName();
|
|
|
|
widget->setName(name);
|
|
|
|
widget->onUserListChanged();
|
2015-06-19 22:58:48 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Handler of `groupchatPositionChanged` action.
|
|
|
|
* Move group layout on the top or on the buttom.
|
|
|
|
*
|
|
|
|
* @param top If true, move group layout on the top, false otherwise.
|
|
|
|
*/
|
2015-06-30 00:26:49 +08:00
|
|
|
void ContentDialog::onGroupchatPositionChanged(bool top)
|
|
|
|
{
|
|
|
|
friendLayout->removeItem(groupLayout.getLayout());
|
2017-02-26 22:22:28 +08:00
|
|
|
friendLayout->insertLayout(top ? 0 : 1, groupLayout.getLayout());
|
2015-06-30 00:26:49 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Retranslate all elements in the form.
|
|
|
|
*/
|
2015-07-03 02:38:18 +08:00
|
|
|
void ContentDialog::retranslateUi()
|
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
updateTitleAndStatusIcon();
|
2015-07-03 02:38:18 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Save size of dialog window.
|
|
|
|
*/
|
2015-06-19 22:58:48 +08:00
|
|
|
void ContentDialog::saveDialogGeometry()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setDialogGeometry(saveGeometry());
|
|
|
|
}
|
2015-07-03 01:16:11 +08:00
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Save state of splitter between dialog and dialog list.
|
|
|
|
*/
|
2015-06-19 22:58:48 +08:00
|
|
|
void ContentDialog::saveSplitterState()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setDialogSplitterState(splitter->saveState());
|
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Check if current ContentDialog instance and chatroom widget associated with user.
|
|
|
|
* @param id User Id.
|
|
|
|
* @param chatroomWidget Widget which should be a pair for current dialog.
|
|
|
|
* @param list List with contact info.
|
|
|
|
* @return True, if chatroomWidget is pair for current instance.
|
|
|
|
*/
|
2017-07-27 13:55:32 +08:00
|
|
|
bool ContentDialog::hasWidget(int id, const GenericChatroomWidget* chatroomWidget,
|
|
|
|
const QHash<int, ContactInfo>& list) const
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
auto iter = list.find(id);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == list.end()) {
|
2015-06-23 02:01:50 +08:00
|
|
|
return false;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2017-06-01 15:50:59 +08:00
|
|
|
return std::get<0>(*iter) == this && std::get<1>(*iter) == chatroomWidget;
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Focus the dialog if it exists.
|
|
|
|
* @param id User Id.
|
|
|
|
* @param list List with contact info.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
void ContentDialog::focusDialog(int id, const QHash<int, ContactInfo>& list)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
auto iter = list.find(id);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == list.end()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-19 00:10:08 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
ContentDialog* dialog = std::get<0>(*iter);
|
|
|
|
if (dialog->windowState() & Qt::WindowMinimized) {
|
|
|
|
dialog->showNormal();
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
dialog->raise();
|
|
|
|
dialog->activateWindow();
|
2017-05-28 17:39:11 +08:00
|
|
|
dialog->activate(std::get<1>(iter.value()));
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Check, if widget is exists.
|
|
|
|
* @param id User Id.
|
|
|
|
* @param list List with contact info.
|
|
|
|
* @return True is widget exists, false otherwise.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
bool ContentDialog::existsWidget(int id, const QHash<int, ContactInfo>& list)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
auto iter = list.find(id);
|
2017-02-26 22:22:28 +08:00
|
|
|
return iter != list.end();
|
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Update widget status and dialog title for current user.
|
|
|
|
* @param id User Id.
|
|
|
|
* @param list List with contact info.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
void ContentDialog::updateStatus(int id, const QHash<int, ContactInfo>& list)
|
|
|
|
{
|
|
|
|
auto iter = list.find(id);
|
|
|
|
if (iter == list.end()) {
|
2015-06-23 02:01:50 +08:00
|
|
|
return;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
GenericChatroomWidget* chatroomWidget = std::get<1>(*iter);
|
2015-06-23 02:01:50 +08:00
|
|
|
chatroomWidget->updateStatusLight();
|
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
if (chatroomWidget->isActive()) {
|
|
|
|
ContentDialog* dialog = std::get<0>(*iter);
|
|
|
|
dialog->updateTitleAndStatusIcon();
|
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Check, if user dialog is active.
|
|
|
|
* @param id User Id.
|
|
|
|
* @param list List with contact info.
|
|
|
|
* @return True if user dialog is active, false otherwise.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
bool ContentDialog::isWidgetActive(int id, const QHash<int, ContactInfo>& list)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
auto iter = list.find(id);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == list.end()) {
|
2015-06-23 02:01:50 +08:00
|
|
|
return false;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
|
|
|
return std::get<0>(iter.value())->activeChatroomWidget == std::get<1>(iter.value());
|
|
|
|
}
|
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Select ContentDialog by id from the list.
|
|
|
|
* @param id User Id.
|
|
|
|
* @param list List with contact info.
|
|
|
|
* @return ContentDialog for user and nullptr if not found.
|
|
|
|
*/
|
2017-02-26 22:22:28 +08:00
|
|
|
ContentDialog* ContentDialog::getDialog(int id, const QHash<int, ContactInfo>& list)
|
2015-06-23 02:01:50 +08:00
|
|
|
{
|
|
|
|
auto iter = list.find(id);
|
2017-02-26 22:22:28 +08:00
|
|
|
if (iter == list.end()) {
|
2015-06-23 02:01:50 +08:00
|
|
|
return nullptr;
|
2017-02-26 22:22:28 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
|
|
|
return std::get<0>(iter.value());
|
|
|
|
}
|
2015-06-30 00:26:49 +08:00
|
|
|
|
2017-03-05 04:35:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Find the next or previous layout in layout list.
|
|
|
|
* @param layout Current layout.
|
|
|
|
* @param forward If true, move forward, backward othwerwise.
|
|
|
|
* @return Next/previous layout.
|
|
|
|
*/
|
2015-06-30 00:26:49 +08:00
|
|
|
QLayout* ContentDialog::nextLayout(QLayout* layout, bool forward) const
|
|
|
|
{
|
2017-02-26 22:22:28 +08:00
|
|
|
int index = layouts.indexOf(layout);
|
|
|
|
if (index == -1) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-06-30 00:26:49 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
int next = forward ? index + 1 : index - 1;
|
|
|
|
size_t size = layouts.size();
|
|
|
|
next = (next + size) % size;
|
2015-06-30 00:26:49 +08:00
|
|
|
|
2017-02-26 22:22:28 +08:00
|
|
|
return layouts[next];
|
2015-06-30 00:26:49 +08:00
|
|
|
}
|