summaryrefslogtreecommitdiffstats
path: root/pica-client/callwindow.cpp
blob: 21bbcb0ca6c359fd6a6774a7c9f1f852061978bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
	(c) Copyright  2012 - 2020 Anton Sviridenko
	https://picapica.im

	This program is free 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, version 3.

	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 General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

#include "callwindow.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QCloseEvent>

CallWindow::CallWindow(QByteArray peer_id, bool incoming)
	: m_peer_id(peer_id), is_incoming(incoming)
{
	setAttribute(Qt::WA_DeleteOnClose);

	QVBoxLayout *lv = new QVBoxLayout(this);
	QHBoxLayout *lh = new QHBoxLayout();

	pbAccept = new QPushButton(tr("Accept"), this);
	pbCall = new QPushButton(tr("Call"), this);
	pbHang = new QPushButton(tr("Hang Up"), this);
	lbTimer = new QLabel(this);
	lbTimer->setAlignment(Qt::AlignCenter);
	lbTimer->hide();
	callTimer = new QTimer(this);
	callElapsedSeconds = 0;

	lv->addWidget(lbTimer);

	lh->addWidget(pbAccept, Qt::AlignLeft);
	lh->addWidget(pbCall, Qt::AlignLeft);
	lh->addWidget(pbHang, Qt::AlignRight);
	lv->addLayout(lh);
	setLayout(lv);

	connect(pbCall, SIGNAL(clicked()), this, SLOT(call()));
	connect(pbHang, SIGNAL(clicked()), this, SLOT(hang()));
	connect(pbAccept, SIGNAL(clicked()), this, SLOT(accept()));
	connect(callTimer, SIGNAL(timeout()), this, SLOT(update_call_timer()));

	if (is_incoming)
	{
		pbCall->hide();
	}
	else
	{
		pbAccept->hide();
	}
}

void CallWindow::call_started()
{
	pbCall->hide();
	pbAccept->hide();

	callElapsedSeconds = 0;
	lbTimer->setText("00:00");
	lbTimer->show();
	callTimer->start(1000);
}

void CallWindow::call_ended()
{
	callTimer->stop();
	pbHang->setDisabled(true);
}

void CallWindow::update_call_timer()
{
	int hours, minutes, seconds;
	QString text;

	callElapsedSeconds++;

	hours = callElapsedSeconds / 3600;
	minutes = (callElapsedSeconds % 3600) / 60;
	seconds = callElapsedSeconds % 60;

	if (hours > 0)
		text = QString("%1:%2:%3").
		    arg(hours, 2, 10, QChar('0')).
		    arg(minutes, 2, 10, QChar('0')).
		    arg(seconds, 2, 10, QChar('0'));
	else
		text = QString("%1:%2").
		    arg(minutes, 2, 10, QChar('0')).
		    arg(seconds, 2, 10, QChar('0'));

	lbTimer->setText(text);
}

void CallWindow::call()
{
	emit start_call_pressed();
}

void CallWindow::hang()
{
	emit hang_call_pressed();
}

void CallWindow::accept()
{
	emit accept_call_pressed();
}

void CallWindow::closeEvent(QCloseEvent *e)
{
	emit callwindow_closed(this);

	e->accept();
}