2016-02-21 05:32:57 +08:00
|
|
|
/*
|
2017-02-22 21:35:34 +08:00
|
|
|
Copyright © 2015-2017 by The qTox Project Contributors
|
2016-02-21 05:32:57 +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 "groupinviteform.h"
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "ui_mainwindow.h"
|
2017-02-22 20:54:02 +08:00
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/nexus.h"
|
|
|
|
#include "src/persistence/settings.h"
|
|
|
|
#include "src/widget/contentlayout.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/widget/form/groupinvitewidget.h"
|
2017-02-22 20:54:02 +08:00
|
|
|
#include "src/widget/translator.h"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
2016-04-10 18:25:27 +08:00
|
|
|
#include <QDebug>
|
2016-02-21 05:32:57 +08:00
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QLabel>
|
2017-02-22 20:54:02 +08:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSignalMapper>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QVBoxLayout>
|
2016-02-22 07:29:12 +08:00
|
|
|
#include <QWindow>
|
2016-02-21 05:32:57 +08:00
|
|
|
|
2017-02-22 21:35:34 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <tox/tox.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class GroupInviteForm
|
|
|
|
*
|
|
|
|
* @brief This form contains all group invites you received
|
|
|
|
*/
|
|
|
|
|
2016-02-21 05:32:57 +08:00
|
|
|
GroupInviteForm::GroupInviteForm()
|
2017-03-19 21:36:01 +08:00
|
|
|
: headWidget(new QWidget(this))
|
|
|
|
, headLabel(new QLabel(this))
|
|
|
|
, createButton(new QPushButton(this))
|
2017-02-22 20:54:02 +08:00
|
|
|
, inviteBox(new QGroupBox(this))
|
|
|
|
, scroll(new QScrollArea(this))
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
2017-02-26 19:52:45 +08:00
|
|
|
connect(createButton, &QPushButton::clicked,
|
|
|
|
[this]() { emit groupCreate(TOX_CONFERENCE_TYPE_AV); });
|
2016-02-21 05:32:57 +08:00
|
|
|
|
2016-04-22 07:29:53 +08:00
|
|
|
QWidget* innerWidget = new QWidget(scroll);
|
|
|
|
innerWidget->setLayout(new QVBoxLayout());
|
|
|
|
innerWidget->layout()->setAlignment(Qt::AlignTop);
|
|
|
|
scroll->setWidget(innerWidget);
|
|
|
|
scroll->setWidgetResizable(true);
|
|
|
|
|
2017-02-22 20:54:02 +08:00
|
|
|
QVBoxLayout* inviteLayout = new QVBoxLayout(inviteBox);
|
2016-04-22 07:29:53 +08:00
|
|
|
inviteLayout->addWidget(scroll);
|
2016-02-21 05:32:57 +08:00
|
|
|
|
|
|
|
layout->addWidget(createButton);
|
|
|
|
layout->addWidget(inviteBox);
|
|
|
|
|
|
|
|
QFont bold;
|
|
|
|
bold.setBold(true);
|
|
|
|
|
|
|
|
headLabel->setFont(bold);
|
|
|
|
QHBoxLayout* headLayout = new QHBoxLayout(headWidget);
|
|
|
|
headLayout->addWidget(headLabel);
|
|
|
|
|
|
|
|
retranslateUi();
|
|
|
|
Translator::registerHandler(std::bind(&GroupInviteForm::retranslateUi, this), this);
|
|
|
|
}
|
|
|
|
|
2016-02-25 21:59:25 +08:00
|
|
|
GroupInviteForm::~GroupInviteForm()
|
|
|
|
{
|
|
|
|
Translator::unregister(this);
|
|
|
|
}
|
|
|
|
|
2017-02-22 21:35:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Detects that form is shown
|
|
|
|
* @return True if form is visible
|
|
|
|
*/
|
2016-02-22 07:29:12 +08:00
|
|
|
bool GroupInviteForm::isShown() const
|
|
|
|
{
|
2017-02-22 20:54:02 +08:00
|
|
|
bool result = isVisible();
|
2017-02-26 19:52:45 +08:00
|
|
|
if (result) {
|
2016-02-22 07:29:12 +08:00
|
|
|
headWidget->window()->windowHandle()->alert(0);
|
|
|
|
}
|
2017-02-22 20:54:02 +08:00
|
|
|
return result;
|
2016-02-22 07:29:12 +08:00
|
|
|
}
|
|
|
|
|
2017-02-22 21:35:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Shows the form
|
|
|
|
* @param contentLayout Main layout that contains all components of the form
|
|
|
|
*/
|
2016-02-21 07:45:18 +08:00
|
|
|
void GroupInviteForm::show(ContentLayout* contentLayout)
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
2016-02-21 07:45:18 +08:00
|
|
|
contentLayout->mainContent->layout()->addWidget(this);
|
2016-02-21 20:46:45 +08:00
|
|
|
contentLayout->mainHead->layout()->addWidget(headWidget);
|
2016-02-21 05:32:57 +08:00
|
|
|
QWidget::show();
|
|
|
|
headWidget->show();
|
|
|
|
}
|
|
|
|
|
2017-02-22 21:35:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Adds group invite
|
|
|
|
* @param friendId Id of a friend that invited you
|
|
|
|
* @param type Type of the invitation - text or AV
|
|
|
|
* @param invite Information that invited person needs to see an invitation
|
|
|
|
*/
|
2016-02-21 05:32:57 +08:00
|
|
|
void GroupInviteForm::addGroupInvite(int32_t friendId, uint8_t type, QByteArray invite)
|
|
|
|
{
|
2017-02-22 21:35:34 +08:00
|
|
|
GroupInviteWidget* widget = new GroupInviteWidget(this, GroupInvite(friendId, type, invite));
|
|
|
|
scroll->widget()->layout()->addWidget(widget);
|
|
|
|
invites.append(widget);
|
2017-02-26 19:52:45 +08:00
|
|
|
connect(widget, &GroupInviteWidget::accepted, [this](const GroupInvite& inviteInfo) {
|
2017-02-22 20:54:02 +08:00
|
|
|
deleteInviteWidget(inviteInfo);
|
2017-02-26 19:52:45 +08:00
|
|
|
emit groupInviteAccepted(inviteInfo.getFriendId(), inviteInfo.getType(),
|
2017-02-22 20:54:02 +08:00
|
|
|
inviteInfo.getInvite());
|
|
|
|
});
|
2017-02-22 21:35:34 +08:00
|
|
|
connect(widget, &GroupInviteWidget::rejected,
|
2017-02-26 19:52:45 +08:00
|
|
|
[this](const GroupInvite& inviteInfo) { deleteInviteWidget(inviteInfo); });
|
2017-02-22 20:54:02 +08:00
|
|
|
if (isVisible()) {
|
2016-02-21 05:32:57 +08:00
|
|
|
emit groupInvitesSeen();
|
2017-02-22 20:54:02 +08:00
|
|
|
}
|
2016-02-21 05:32:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupInviteForm::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
QWidget::showEvent(event);
|
|
|
|
emit groupInvitesSeen();
|
|
|
|
}
|
|
|
|
|
2017-02-22 21:35:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Deletes accepted/declined group invite widget
|
|
|
|
* @param inviteInfo Invite information of accepted/declined widget
|
|
|
|
*/
|
2017-02-26 19:52:45 +08:00
|
|
|
void GroupInviteForm::deleteInviteWidget(const GroupInvite& inviteInfo)
|
2016-04-10 18:25:27 +08:00
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
auto deletingWidget =
|
|
|
|
std::find_if(invites.begin(), invites.end(), [=](const GroupInviteWidget* widget) {
|
|
|
|
return inviteInfo == widget->getInviteInfo();
|
|
|
|
});
|
2017-02-22 20:54:02 +08:00
|
|
|
(*deletingWidget)->deleteLater();
|
|
|
|
scroll->widget()->layout()->removeWidget(*deletingWidget);
|
|
|
|
invites.erase(deletingWidget);
|
2016-02-21 05:32:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupInviteForm::retranslateUi()
|
|
|
|
{
|
|
|
|
headLabel->setText(tr("Groups"));
|
2017-02-26 19:52:45 +08:00
|
|
|
if (createButton) {
|
2016-02-25 21:59:25 +08:00
|
|
|
createButton->setText(tr("Create new group"));
|
2017-02-22 20:54:02 +08:00
|
|
|
}
|
2016-02-21 05:32:57 +08:00
|
|
|
inviteBox->setTitle(tr("Group invites"));
|
2017-02-26 19:52:45 +08:00
|
|
|
for (GroupInviteWidget* invite : invites) {
|
2017-02-22 20:54:02 +08:00
|
|
|
invite->retranslateUi();
|
|
|
|
}
|
2016-02-21 05:32:57 +08:00
|
|
|
}
|