From 32bf56c7d94e56a32ce9a0959d9e6ed2c3b267da Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Sun, 25 Jan 2015 04:57:20 +0100 Subject: [PATCH] Implement new call confirm widget logic Works, but does not have any styling at the moment --- qtox.pro | 6 +- src/core.h | 1 + src/coreav.cpp | 9 ++- src/widget/callconfirmwidget.cpp | 33 +++++++++++ src/widget/callconfirmwidget.h | 19 ++++++ src/widget/form/chatform.cpp | 99 +++++++++++++++++++++++++++----- src/widget/form/chatform.h | 9 +++ src/widget/widget.cpp | 1 + 8 files changed, 159 insertions(+), 18 deletions(-) create mode 100644 src/widget/callconfirmwidget.cpp create mode 100644 src/widget/callconfirmwidget.h diff --git a/qtox.pro b/qtox.pro index 541de4d65..215237c00 100644 --- a/qtox.pro +++ b/qtox.pro @@ -188,7 +188,8 @@ HEADERS += src/widget/form/addfriendform.h \ src/autoupdate.h \ src/misc/serialize.h \ src/widget/form/settings/advancedform.h \ - src/audio.h + src/audio.h \ + src/widget/callconfirmwidget.h SOURCES += \ src/widget/form/addfriendform.cpp \ @@ -255,7 +256,8 @@ SOURCES += \ src/autoupdate.cpp \ src/misc/serialize.cpp \ src/widget/form/settings/advancedform.cpp \ - src/audio.cpp + src/audio.cpp \ + src/widget/callconfirmwidget.cpp contains(DEFINES, QTOX_FILTER_AUDIO) { HEADERS += src/audiofilterer.h diff --git a/src/core.h b/src/core.h index 14d42a12f..de9b62215 100644 --- a/src/core.h +++ b/src/core.h @@ -117,6 +117,7 @@ public slots: void pauseResumeFileRecv(int friendId, int fileNum); void answerCall(int callId); + void rejectCall(int callId); void hangupCall(int callId); void startCall(int friendId, bool video=false); void cancelCall(int callId, int friendId); diff --git a/src/coreav.cpp b/src/coreav.cpp index b26be579c..b615661cd 100644 --- a/src/coreav.cpp +++ b/src/coreav.cpp @@ -159,6 +159,13 @@ void Core::hangupCall(int callId) toxav_hangup(toxav, callId); } +void Core::rejectCall(int callId) +{ + qDebug() << QString("Core: rejecting call %1").arg(callId); + calls[callId].active = false; + toxav_reject(toxav, callId, nullptr); +} + void Core::startCall(int friendId, bool video) { int callId; @@ -201,7 +208,7 @@ void Core::cancelCall(int callId, int friendId) { qDebug() << QString("Core: Cancelling call with %1").arg(friendId); calls[callId].active = false; - toxav_cancel(toxav, callId, friendId, 0); + toxav_cancel(toxav, callId, friendId, nullptr); } void Core::cleanupCall(int callId) diff --git a/src/widget/callconfirmwidget.cpp b/src/widget/callconfirmwidget.cpp new file mode 100644 index 000000000..07ad5b224 --- /dev/null +++ b/src/widget/callconfirmwidget.cpp @@ -0,0 +1,33 @@ +#include "callconfirmwidget.h" +#include "widget.h" +#include +#include +#include +#include +#include + +CallConfirmWidget::CallConfirmWidget(QWidget *anchor) : + QWidget(Widget::getInstance()) +{ + Widget* w = Widget::getInstance(); + + setWindowFlags(Qt::SubWindow); + setAutoFillBackground(true); + + QVBoxLayout *layout = new QVBoxLayout(this); + QLabel *callLabel = new QLabel(tr("Incoming call..."), this); + QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this); + QPushButton *accept = new QPushButton("Y", this), *reject = new QPushButton("N", this); + + buttonBox->addButton(accept, QDialogButtonBox::AcceptRole); + buttonBox->addButton(reject, QDialogButtonBox::RejectRole); + + connect(buttonBox, &QDialogButtonBox::accepted, this, &CallConfirmWidget::accepted); + connect(buttonBox, &QDialogButtonBox::rejected, this, &CallConfirmWidget::rejected); + + layout->addWidget(callLabel); + layout->addWidget(buttonBox); + + setFixedSize(150,90); + move(anchor->mapToGlobal({(anchor->width()-width())/2,anchor->height()})-w->mapToGlobal({0,0})); +} diff --git a/src/widget/callconfirmwidget.h b/src/widget/callconfirmwidget.h new file mode 100644 index 000000000..cea51ad56 --- /dev/null +++ b/src/widget/callconfirmwidget.h @@ -0,0 +1,19 @@ +#ifndef CALLCONFIRMWIDGET_H +#define CALLCONFIRMWIDGET_H + +#include + +class QMoveEvent; + +class CallConfirmWidget : public QWidget +{ + Q_OBJECT +public: + explicit CallConfirmWidget(QWidget *anchor); + +signals: + void accepted(); + void rejected(); +}; + +#endif // CALLCONFIRMWIDGET_H diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 12de13fbb..02b61dc98 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -24,22 +24,23 @@ #include #include #include "chatform.h" -#include "src/historykeeper.h" -#include "src/widget/form/loadhistorydialog.h" -#include "src/friend.h" -#include "src/widget/friendwidget.h" -#include "src/filetransferinstance.h" -#include "src/widget/tool/chatactions/filetransferaction.h" -#include "src/widget/netcamview.h" -#include "src/widget/chatareawidget.h" -#include "src/widget/tool/chattextedit.h" #include "src/core.h" -#include "src/widget/widget.h" -#include "src/widget/maskablepixmapwidget.h" -#include "src/widget/croppinglabel.h" +#include "src/friend.h" +#include "src/filetransferinstance.h" +#include "src/historykeeper.h" #include "src/misc/style.h" #include "src/misc/settings.h" #include "src/misc/cstring.h" +#include "src/widget/callconfirmwidget.h" +#include "src/widget/friendwidget.h" +#include "src/widget/netcamview.h" +#include "src/widget/chatareawidget.h" +#include "src/widget/form/loadhistorydialog.h" +#include "src/widget/tool/chattextedit.h" +#include "src/widget/tool/chatactions/filetransferaction.h" +#include "src/widget/widget.h" +#include "src/widget/maskablepixmapwidget.h" +#include "src/widget/croppinglabel.h" ChatForm::ChatForm(Friend* chatFriend) : f(chatFriend) @@ -54,6 +55,8 @@ ChatForm::ChatForm(Friend* chatFriend) statusMessageLabel->setFont(Style::getFont(Style::Medium)); statusMessageLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize()); + callConfirm = nullptr; + isTypingLabel = new QLabel(); QFont font = isTypingLabel->font(); font.setItalic(true); @@ -97,6 +100,7 @@ ChatForm::ChatForm(Friend* chatFriend) ChatForm::~ChatForm() { delete netcam; + delete callConfirm; } void ChatForm::setStatusMessage(QString newMessage) @@ -261,6 +265,12 @@ void ChatForm::onAvInvite(int FriendId, int CallId, bool video) qDebug() << "onAvInvite"; + callConfirm = new CallConfirmWidget(callButton); + if (isVisible()) + callConfirm->show(); + connect(callConfirm, SIGNAL(accepted()), this, SLOT(onAnswerCallTriggered())); + connect(callConfirm, SIGNAL(rejected()), this, SLOT(onRejectCallTriggered())); + callId = CallId; callButton->disconnect(); videoButton->disconnect(); @@ -329,12 +339,14 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video) void ChatForm::onAvCancel(int FriendId, int) { - if (FriendId != f->getFriendID()) return; qDebug() << "onAvCancel"; + delete callConfirm; + callConfirm = nullptr; + stopCounter(); audioInputFlag = false; @@ -364,6 +376,9 @@ void ChatForm::onAvEnd(int FriendId, int) qDebug() << "onAvEnd"; + delete callConfirm; + callConfirm = nullptr; + audioInputFlag = false; audioOutputFlag = false; micButton->setObjectName("green"); @@ -452,6 +467,9 @@ void ChatForm::onAvEnding(int FriendId, int) qDebug() << "onAvEnding"; + delete callConfirm; + callConfirm = nullptr; + audioInputFlag = false; audioOutputFlag = false; micButton->setObjectName("green"); @@ -481,6 +499,9 @@ void ChatForm::onAvRequestTimeout(int FriendId, int) qDebug() << "onAvRequestTimeout"; + delete callConfirm; + callConfirm = nullptr; + audioInputFlag = false; audioOutputFlag = false; micButton->setObjectName("green"); @@ -508,6 +529,9 @@ void ChatForm::onAvPeerTimeout(int FriendId, int) qDebug() << "onAvPeerTimeout"; + delete callConfirm; + callConfirm = nullptr; + audioInputFlag = false; audioOutputFlag = false; micButton->setObjectName("green"); @@ -535,6 +559,9 @@ void ChatForm::onAvRejected(int FriendId, int) qDebug() << "onAvRejected"; + delete callConfirm; + callConfirm = nullptr; + audioInputFlag = false; audioOutputFlag = false; micButton->setObjectName("green"); @@ -577,7 +604,13 @@ void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video) void ChatForm::onAnswerCallTriggered() { qDebug() << "onAnswerCallTriggered"; - + + if (callConfirm) + { + delete callConfirm; + callConfirm = nullptr; + } + audioInputFlag = true; audioOutputFlag = true; emit answerCall(callId); @@ -596,10 +629,29 @@ void ChatForm::onHangupCallTriggered() volButton->style()->polish(volButton); } +void ChatForm::onRejectCallTriggered() +{ + qDebug() << "onRejectCallTriggered"; + + if (callConfirm) + { + delete callConfirm; + callConfirm = nullptr; + } + + audioInputFlag = false; + audioOutputFlag = false; + emit rejectCall(callId); + micButton->setObjectName("green"); + micButton->style()->polish(micButton); + volButton->setObjectName("green"); + volButton->style()->polish(volButton); +} + void ChatForm::onCallTriggered() { qDebug() << "onCallTriggered"; - + audioInputFlag = true; audioOutputFlag = true; callButton->disconnect(); @@ -625,6 +677,9 @@ void ChatForm::onAvCallFailed(int FriendId) qDebug() << "onAvCallFailed"; + delete callConfirm; + callConfirm = nullptr; + audioInputFlag = false; audioOutputFlag = false; callButton->disconnect(); @@ -947,3 +1002,17 @@ void ChatForm::deliverOfflineMsgs() registerReceipt(rec, iter.key(), iter.value()); } } + +void ChatForm::show(Ui::MainWindow &ui) +{ + GenericChatForm::show(ui); + + if (callConfirm) + callConfirm->show(); +} + +void ChatForm::hideEvent(QHideEvent*) +{ + if (callConfirm) + callConfirm->hide(); +} diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 21e97078d..7dfbd1f74 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -28,6 +28,9 @@ struct Friend; class FileTransferInstance; class NetCamView; class QPixmap; +class CallConfirmWidget; +class QHideEvent; +class QMoveEvent; class ChatForm : public GenericChatForm { @@ -41,6 +44,8 @@ public: void dischargeReceipt(int receipt); void setFriendTyping(bool isTyping); + virtual void show(Ui::MainWindow &ui); + signals: void sendFile(int32_t friendId, QString, QString, long long); void startCall(int friendId); @@ -48,6 +53,7 @@ signals: void answerCall(int callId); void hangupCall(int callId); void cancelCall(int callId, int friendId); + void rejectCall(int callId); void micMuteToggle(int callId); void volMuteToggle(int callId); void aliasChanged(const QString& alias); @@ -83,6 +89,7 @@ private slots: void onAnswerCallTriggered(); void onHangupCallTriggered(); void onCancelCallTriggered(); + void onRejectCallTriggered(); void onFileTansBtnClicked(QString widgetName, QString buttonName); void onFileSendFailed(int FriendId, const QString &fname); void onLoadHistory(); @@ -92,6 +99,7 @@ protected: // drag & drop void dragEnterEvent(QDragEnterEvent* ev); void dropEvent(QDropEvent* ev); + virtual void hideEvent(QHideEvent* event); void registerReceipt(int receipt, int messageID, MessageActionPtr msg); private: @@ -111,6 +119,7 @@ private: QString secondsToDHMS(quint32 duration); QHash receipts; QMap undeliveredMsgs; + CallConfirmWidget *callConfirm; }; #endif // CHATFORM_H diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 89f148a81..11cdf17b6 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -679,6 +679,7 @@ void Widget::addFriend(int friendId, const QString &userId) connect(newfriend->getChatForm(), SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long))); connect(newfriend->getChatForm(), SIGNAL(answerCall(int)), core, SLOT(answerCall(int))); connect(newfriend->getChatForm(), SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int))); + connect(newfriend->getChatForm(), SIGNAL(rejectCall(int)), core, SLOT(rejectCall(int))); connect(newfriend->getChatForm(), SIGNAL(startCall(int)), core, SLOT(startCall(int))); connect(newfriend->getChatForm(), SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool))); connect(newfriend->getChatForm(), SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int)));