2016-02-21 05:32:57 +08:00
|
|
|
/*
|
2016-11-28 21:33:38 +08:00
|
|
|
Copyright © 2015 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-22 20:54:02 +08:00
|
|
|
#include "src/widget/form/groupinvitewidget.h"
|
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/nexus.h"
|
|
|
|
#include "src/persistence/settings.h"
|
|
|
|
#include "src/widget/contentlayout.h"
|
|
|
|
#include "src/widget/translator.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2016-02-21 05:32:57 +08:00
|
|
|
#include <tox/tox.h>
|
2017-02-22 20:54:02 +08:00
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#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>
|
2016-02-22 07:29:12 +08:00
|
|
|
#include <QWindow>
|
2016-02-21 05:32:57 +08:00
|
|
|
|
|
|
|
GroupInviteForm::GroupInviteForm()
|
2017-02-22 20:54:02 +08:00
|
|
|
: createButton(new QPushButton(this))
|
|
|
|
, inviteBox(new QGroupBox(this))
|
|
|
|
, scroll(new QScrollArea(this))
|
|
|
|
, headLabel(new QLabel(this))
|
|
|
|
, headWidget(new QWidget(this))
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
2017-02-22 20:54:02 +08:00
|
|
|
connect(createButton, &QPushButton::clicked, [=]()
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
2016-09-22 14:48:01 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-02-22 07:29:12 +08:00
|
|
|
bool GroupInviteForm::isShown() const
|
|
|
|
{
|
2017-02-22 20:54:02 +08:00
|
|
|
bool result = isVisible();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupInviteForm::addGroupInvite(int32_t friendId, uint8_t type, QByteArray invite)
|
|
|
|
{
|
2017-02-22 20:54:02 +08:00
|
|
|
GroupInviteWidget* addingInviteWidget = new GroupInviteWidget(this, GroupInvite(friendId, type, invite));
|
|
|
|
scroll->widget()->layout()->addWidget(addingInviteWidget);
|
|
|
|
invites.append(addingInviteWidget);
|
|
|
|
connect(addingInviteWidget, &GroupInviteWidget::accepted,
|
|
|
|
[=] (const GroupInvite& inviteInfo) {
|
|
|
|
deleteInviteWidget(inviteInfo);
|
|
|
|
emit groupInviteAccepted(inviteInfo.getFriendId(),
|
|
|
|
inviteInfo.getType(),
|
|
|
|
inviteInfo.getInvite());
|
|
|
|
});
|
|
|
|
connect(addingInviteWidget, &GroupInviteWidget::rejected,
|
|
|
|
[=] (const GroupInvite& inviteInfo) {
|
|
|
|
deleteInviteWidget(inviteInfo);
|
|
|
|
});
|
|
|
|
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 20:54:02 +08:00
|
|
|
void GroupInviteForm::deleteInviteWidget(const GroupInvite &inviteInfo)
|
2016-04-10 18:25:27 +08:00
|
|
|
{
|
2017-02-22 20:54:02 +08:00
|
|
|
auto deletingWidget = std::find_if(invites.begin(), invites.end(),
|
|
|
|
[=] (const GroupInviteWidget* widget) {
|
|
|
|
return inviteInfo == widget->getInviteInfo();
|
|
|
|
});
|
|
|
|
(*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"));
|
2016-07-07 17:55:53 +08:00
|
|
|
if (createButton)
|
2017-02-22 20:54:02 +08:00
|
|
|
{
|
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-22 20:54:02 +08:00
|
|
|
for (GroupInviteWidget* invite : invites)
|
|
|
|
{
|
|
|
|
invite->retranslateUi();
|
|
|
|
}
|
2016-02-21 05:32:57 +08:00
|
|
|
}
|