1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #3442

Jeanbon (1):
      feat(autoAnswer): add auto answer feature
This commit is contained in:
sudden6 2016-09-26 19:13:16 +02:00
commit 610e21169a
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
7 changed files with 154 additions and 50 deletions

View File

@ -112,6 +112,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

View File

@ -380,6 +380,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())
@ -662,6 +667,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())
@ -1437,6 +1443,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};

View File

@ -28,6 +28,7 @@
#include <QMutex>
#include <QDate>
#include <QNetworkProxy>
#include <QFlags>
#include "src/core/corestructs.h"
class ToxId;
@ -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();
@ -194,6 +203,7 @@ signals:
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);
@ -399,6 +409,9 @@ public:
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);
@ -622,6 +635,7 @@ private:
QString note;
int circleID = -1;
QDate activity = QDate();
AutoAcceptCallFlags autoAcceptCall;
};
struct circleProp
@ -642,4 +656,5 @@ private:
static QThread* settingsThread;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Settings::AutoAcceptCallFlags)
#endif // SETTINGS_HPP

View File

@ -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));
}
@ -48,17 +52,17 @@ 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"),
@ -66,14 +70,20 @@ void AboutUser::onAutoAcceptClicked()
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()
@ -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();
}
/**

View File

@ -24,7 +24,8 @@ private:
private slots:
void onAcceptedClicked();
void onAutoAcceptClicked();
void onAutoAcceptDirClicked();
void onAutoAcceptCallClicked();
void onSelectDirClicked();
void onRemoveHistoryClicked();
};

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>465</width>
<height>406</height>
<height>460</height>
</rect>
</property>
<property name="windowTitle">
@ -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>

View File

@ -282,39 +282,49 @@ void ChatForm::onAvInvite(uint32_t FriendId, bool video)
return;
qDebug() << "onAvInvite";
disableCallButtons();
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);
}
if (f->getFriendWidget()->chatFormIsSet(false))
callConfirm->show();
connect(callConfirm, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered);
connect(callConfirm, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered);
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)))
{
uint32_t friendId = f->getFriendID();
qDebug() << "automatic call answer";
QMetaObject::invokeMethod(coreav, "answerCall", Qt::QueuedConnection, Q_ARG(uint32_t, friendId));
onAvStart(friendId,video);
}
else
{
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);
}
Widget::getInstance()->newFriendMessageAlert(FriendId, false);
Audio& audio = Audio::getInstance();
audio.startLoop();
audio.playMono16Sound(QStringLiteral(":/audio/ToxicIncomingCall.pcm"));
if (f->getFriendWidget()->chatFormIsSet(false))
callConfirm->show();
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"));
}
}
void ChatForm::onAvStart(uint32_t FriendId, bool video)