Skip to content

Commit

Permalink
feat(autoAnswer): add auto answer feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Grokafar committed Sep 25, 2016
1 parent 63db185 commit 7fe8a86
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 47 deletions.
7 changes: 7 additions & 0 deletions doc/user_manual_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ can have different nicknames, status messages and friends.
+ _Change password:_ Allows you to either change an existing password, or create
a new password if your profile does not have one.

## Friends' options
In the friend's window you can customize some options for this friend specifically.
* _Auto answer:_ chooses the way to autoaccept audio and video calls.
* _Manual:_ All calls must be manually accepted.
* _Audio:_ Only audio calls will be automatically accepted. Video calls must be manually accepted.
* _Audio + video:_ All calls will be automatically accepted.

## Settings
### General

Expand Down
31 changes: 31 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ void Settings::loadPersonal(Profile* profile)
fp.alias = ps.value("alias").toString();
fp.note = ps.value("note").toString();
fp.autoAcceptDir = ps.value("autoAcceptDir").toString();

if(fp.autoAcceptDir == "")
fp.autoAcceptDir = ps.value("autoAccept").toString();

fp.autoAcceptCall = Settings::AutoAcceptCallFlags(QFlag(ps.value("autoAcceptCall", 0).toInt()));
fp.circleID = ps.value("circle", -1).toInt();

if (getEnableLogging())
Expand Down Expand Up @@ -558,6 +563,7 @@ void Settings::savePersonal(QString profileName, const QString &password)
ps.setValue("alias", frnd.alias);
ps.setValue("note", frnd.note);
ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
ps.setValue("autoAcceptCall", static_cast<int>(frnd.autoAcceptCall));
ps.setValue("circle", frnd.circleID);

if (getEnableLogging())
Expand Down Expand Up @@ -1312,6 +1318,31 @@ void Settings::setAutoAcceptDir(const ToxId &id, const QString& dir)
}
}

Settings::AutoAcceptCallFlags Settings::getAutoAcceptCall(const ToxId &id) const
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;

auto it = friendLst.find(key);
if (it != friendLst.end())
return it->autoAcceptCall;

return Settings::AutoAcceptCallFlags();
}

void Settings::setAutoAcceptCall(const ToxId& id, AutoAcceptCallFlags accept)
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;

auto it = friendLst.find(key);
if(it != friendLst.end())
{
it->autoAcceptCall = accept;
emit autoAcceptCallChanged(id, accept);
}
}

QString Settings::getContactNote(const ToxId &id) const
{
QMutexLocker locker{&bigLock};
Expand Down
15 changes: 15 additions & 0 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QMutex>
#include <QDate>
#include <QNetworkProxy>
#include <QFlags>
#include "src/core/corestructs.h"

class ToxId;
Expand Down Expand Up @@ -131,6 +132,14 @@ class Settings : public QObject
public:
enum class ProxyType {ptNone = 0, ptSOCKS5 = 1, ptHTTP = 2};
enum class StyleType {NONE = 0, WITH_CHARS = 1, WITHOUT_CHARS = 2};
enum class AutoAcceptCall
{
None = 0x00,
Audio = 0x01,
Video = 0x02,
AV = Audio | Video
};
Q_DECLARE_FLAGS(AutoAcceptCallFlags, AutoAcceptCall);

public:
static Settings& getInstance();
Expand Down Expand Up @@ -192,6 +201,7 @@ public slots:
void globalAutoAcceptDirChanged(const QString& path);
void checkUpdatesChanged(bool enabled);
void widgetDataChanged(const QString& key);
void autoAcceptCallChanged(const ToxId& id, AutoAcceptCallFlags accept);

// GUI
void autoLoginChanged(bool enabled);
Expand Down Expand Up @@ -397,6 +407,9 @@ public slots:
QString getAutoAcceptDir(const ToxId& id) const;
void setAutoAcceptDir(const ToxId& id, const QString& dir);

AutoAcceptCallFlags getAutoAcceptCall(const ToxId& id) const;
void setAutoAcceptCall(const ToxId& id, AutoAcceptCallFlags accept);

QString getGlobalAutoAcceptDir() const;
void setGlobalAutoAcceptDir(const QString& dir);

Expand Down Expand Up @@ -620,6 +633,7 @@ private slots:
QString note;
int circleID = -1;
QDate activity = QDate();
AutoAcceptCallFlags autoAcceptCall;
};

struct circleProp
Expand All @@ -640,4 +654,5 @@ private slots:
static QThread* settingsThread;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Settings::AutoAcceptCallFlags)
#endif // SETTINGS_HPP
34 changes: 22 additions & 12 deletions src/widget/about/aboutuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ AboutUser::AboutUser(ToxId &toxId, QWidget *parent) :
ui->aliases->hide();

connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AboutUser::onAcceptedClicked);
connect(ui->autoaccept, &QCheckBox::clicked, this, &AboutUser::onAutoAcceptClicked);
connect(ui->autoacceptfile, &QCheckBox::clicked, this, &AboutUser::onAutoAcceptDirClicked);
connect(ui->autoacceptcall, SIGNAL(activated(int)), this, SLOT(onAutoAcceptCallClicked(void)));
connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutUser::onSelectDirClicked);
connect(ui->removeHistory, &QPushButton::clicked, this, &AboutUser::onRemoveHistoryClicked);

this->toxId = toxId;
QString dir = Settings::getInstance().getAutoAcceptDir(this->toxId);
ui->autoaccept->setChecked(!dir.isEmpty());
ui->selectSaveDir->setEnabled(ui->autoaccept->isChecked());
ui->autoacceptfile->setChecked(!dir.isEmpty());

if(ui->autoaccept->isChecked())
ui->autoacceptcall->setCurrentIndex(Settings::getInstance().getAutoAcceptCall(this->toxId));

ui->selectSaveDir->setEnabled(ui->autoacceptfile->isChecked());

if(ui->autoacceptfile->isChecked())
ui->selectSaveDir->setText(Settings::getInstance().getAutoAcceptDir(this->toxId));
}

Expand All @@ -48,32 +52,38 @@ void AboutUser::setFriend(Friend *f)

}

void AboutUser::onAutoAcceptClicked()
void AboutUser::onAutoAcceptDirClicked()
{
QString dir;
if (!ui->autoaccept->isChecked())
if (!ui->autoacceptfile->isChecked())
{
dir = QDir::homePath();
ui->autoaccept->setChecked(false);
ui->autoacceptfile->setChecked(false);
Settings::getInstance().setAutoAcceptDir(this->toxId, "");
ui->selectSaveDir->setText(tr("Auto accept for this contact is disabled"));
}
else if (ui->autoaccept->isChecked())
else if (ui->autoacceptfile->isChecked())
{
dir = QFileDialog::getExistingDirectory(this,
tr("Choose an auto accept directory", "popup title"),
dir,
QFileDialog::DontUseNativeDialog);
if(dir.isEmpty())
{
ui->autoaccept->setChecked(false);
ui->autoacceptfile->setChecked(false);
return; // user canellced
}
Settings::getInstance().setAutoAcceptDir(this->toxId, dir);
ui->selectSaveDir->setText(Settings::getInstance().getAutoAcceptDir(this->toxId));
}
Settings::getInstance().saveGlobal();
ui->selectSaveDir->setEnabled(ui->autoaccept->isChecked());
ui->selectSaveDir->setEnabled(ui->autoacceptfile->isChecked());
}

void AboutUser::onAutoAcceptCallClicked()
{
Settings::getInstance().setAutoAcceptCall(this->toxId,Settings::AutoAcceptCallFlags(QFlag(ui->autoacceptcall->currentIndex())));
Settings::getInstance().savePersonal();
}

void AboutUser::onSelectDirClicked()
Expand All @@ -83,9 +93,9 @@ void AboutUser::onSelectDirClicked()
tr("Choose an auto accept directory", "popup title"),
dir,
QFileDialog::DontUseNativeDialog);
ui->autoaccept->setChecked(true);
ui->autoacceptfile->setChecked(true);
Settings::getInstance().setAutoAcceptDir(this->toxId, dir);
Settings::getInstance().saveGlobal();
Settings::getInstance().savePersonal();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/widget/about/aboutuser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class AboutUser : public QDialog

private slots:
void onAcceptedClicked();
void onAutoAcceptClicked();
void onAutoAcceptDirClicked();
void onAutoAcceptCallClicked();
void onSelectDirClicked();
void onRemoveHistoryClicked();
};
Expand Down
48 changes: 39 additions & 9 deletions src/widget/about/aboutuser.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>465</width>
<height>406</height>
<height>460</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -164,26 +164,56 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="autoacceptfile">
<property name="text">
<string>Auto accept file</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Default directory to save files:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="8" column="1">
<widget class="QPushButton" name="selectSaveDir">
<property name="text">
<string>Auto accept for this contact is disabled</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="autoaccept">
<property name="text">
<string>Auto accept files</string>
</property>
</widget>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Auto accept call :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="autoacceptcall">
<item>
<property name="text">
<string>Manual</string>
</property>
</item>
<item>
<property name="text">
<string>Audio</string>
</property>
</item>
<item>
<property name="text">
<string>Audio + Video</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</item>
Expand Down
60 changes: 35 additions & 25 deletions src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,39 +280,49 @@ void ChatForm::onAvInvite(uint32_t FriendId, bool video)
return;

qDebug() << "onAvInvite";

disableCallButtons();
if (video)
insertChatMessage(ChatMessage::createChatInfoMessage(tr("%1 calling").arg(f->getDisplayedName()),
ChatMessage::INFO,
QDateTime::currentDateTime()));
/* AutoAcceptCall is set for this friend */
if ((video && Settings::getInstance().getAutoAcceptCall(f->getToxId()).testFlag(Settings::AutoAcceptCall::Video)) ||
(!video && Settings::getInstance().getAutoAcceptCall(f->getToxId()).testFlag(Settings::AutoAcceptCall::Audio)))
{
callConfirm = new CallConfirmWidget(videoButton, *f);
videoButton->setObjectName("yellow");
videoButton->setToolTip(tr("Accept video call"));
videoButton->style()->polish(videoButton);
connect(videoButton, &QPushButton::clicked, this, &ChatForm::onAnswerCallTriggered);
uint32_t friendId = f->getFriendID();
qDebug() << "automatic call answer";
QMetaObject::invokeMethod(coreav, "answerCall", Qt::QueuedConnection, Q_ARG(uint32_t, friendId));
onAvStart(friendId,video);
}
else
{
callConfirm = new CallConfirmWidget(callButton, *f);
callButton->setObjectName("yellow");
callButton->setToolTip(tr("Accept audio call"));
callButton->style()->polish(callButton);
connect(callButton, &QPushButton::clicked, this, &ChatForm::onAnswerCallTriggered);
}

if (f->getFriendWidget()->chatFormIsSet(false))
callConfirm->show();
if (video)
{
callConfirm = new CallConfirmWidget(videoButton, *f);
videoButton->setObjectName("yellow");
videoButton->setToolTip(tr("Accept video call"));
videoButton->style()->polish(videoButton);
connect(videoButton, &QPushButton::clicked, this, &ChatForm::onAnswerCallTriggered);
}
else
{
callConfirm = new CallConfirmWidget(callButton, *f);
callButton->setObjectName("yellow");
callButton->setToolTip(tr("Accept audio call"));
callButton->style()->polish(callButton);
connect(callButton, &QPushButton::clicked, this, &ChatForm::onAnswerCallTriggered);
}

connect(callConfirm, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered);
connect(callConfirm, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered);
if (f->getFriendWidget()->chatFormIsSet(false))
callConfirm->show();

insertChatMessage(ChatMessage::createChatInfoMessage(tr("%1 calling").arg(f->getDisplayedName()),
ChatMessage::INFO,
QDateTime::currentDateTime()));
connect(callConfirm, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered);
connect(callConfirm, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered);

Widget::getInstance()->newFriendMessageAlert(FriendId, false);
Audio& audio = Audio::getInstance();
audio.startLoop();
audio.playMono16Sound(QStringLiteral(":/audio/ToxicIncomingCall.pcm"));
Widget::getInstance()->newFriendMessageAlert(FriendId, false);
Audio& audio = Audio::getInstance();
audio.startLoop();
audio.playMono16Sound(QStringLiteral(":/audio/ToxicIncomingCall.pcm"));
}
}

void ChatForm::onAvStart(uint32_t FriendId, bool video)
Expand Down

0 comments on commit 7fe8a86

Please sign in to comment.