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

feat(groups): add option to automatically accept groupchat invites

Allows to accept group chat invites from select contacts automatically.

fix #1197
This commit is contained in:
sudden6 2017-03-12 17:37:38 +01:00
parent 9236763865
commit 6a16a2bdbc
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
7 changed files with 76 additions and 17 deletions

View File

@ -69,6 +69,8 @@ right-clicking on a contact a menu appears that has the following options:
* __Move to circle:__ offers an option to move friend to a new * __Move to circle:__ offers an option to move friend to a new
[circle](#circles), or to an existing one. [circle](#circles), or to an existing one.
* __Set alias:__ set alias that will be displayed instead of contact's name. * __Set alias:__ set alias that will be displayed instead of contact's name.
* __Auto accept group invites:__ if enabled, all group chat invites from this
friend are automatically accepted.
* __Auto accept files from this friend:__ option to automatically save files * __Auto accept files from this friend:__ option to automatically save files
from the selected contact in a chosen directory. from the selected contact in a chosen directory.
* __Remove friend:__ option to remove the contact. Confirmation is needed to * __Remove friend:__ option to remove the contact. Confirmation is needed to

View File

@ -369,6 +369,7 @@ void Settings::loadPersonal(Profile* profile)
fp.autoAcceptCall = fp.autoAcceptCall =
Settings::AutoAcceptCallFlags(QFlag(ps.value("autoAcceptCall", 0).toInt())); Settings::AutoAcceptCallFlags(QFlag(ps.value("autoAcceptCall", 0).toInt()));
fp.autoGroupInvite = ps.value("autoGroupInvite").toBool();
fp.circleID = ps.value("circle", -1).toInt(); fp.circleID = ps.value("circle", -1).toInt();
if (getEnableLogging()) if (getEnableLogging())
@ -646,6 +647,7 @@ void Settings::savePersonal(QString profileName, const QString& password)
ps.setValue("note", frnd.note); ps.setValue("note", frnd.note);
ps.setValue("autoAcceptDir", frnd.autoAcceptDir); ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
ps.setValue("autoAcceptCall", static_cast<int>(frnd.autoAcceptCall)); ps.setValue("autoAcceptCall", static_cast<int>(frnd.autoAcceptCall));
ps.setValue("autoGroupInvite", frnd.autoGroupInvite);
ps.setValue("circle", frnd.circleID); ps.setValue("circle", frnd.circleID);
if (getEnableLogging()) if (getEnableLogging())
@ -1416,6 +1418,29 @@ void Settings::setAutoAcceptCall(const ToxPk& id, AutoAcceptCallFlags accept)
} }
} }
bool Settings::getAutoGroupInvite(const ToxPk& id) const
{
QMutexLocker locker{&bigLock};
auto it = friendLst.find(id.getKey());
if (it != friendLst.end()) {
return it->autoGroupInvite;
}
return false;
}
void Settings::setAutoGroupInvite(const ToxPk& id, bool accept)
{
QMutexLocker locker{&bigLock};
auto it = friendLst.find(id.getKey());
if (it != friendLst.end()) {
it->autoGroupInvite = accept;
emit autoGroupInviteChanged(id, accept);
}
}
QString Settings::getContactNote(const ToxPk& id) const QString Settings::getContactNote(const ToxPk& id) const
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};

View File

@ -192,6 +192,7 @@ signals:
void checkUpdatesChanged(bool enabled); void checkUpdatesChanged(bool enabled);
void widgetDataChanged(const QString& key); void widgetDataChanged(const QString& key);
void autoAcceptCallChanged(const ToxPk& id, AutoAcceptCallFlags accept); void autoAcceptCallChanged(const ToxPk& id, AutoAcceptCallFlags accept);
void autoGroupInviteChanged(const ToxPk& id, bool accept);
// GUI // GUI
void autoLoginChanged(bool enabled); void autoLoginChanged(bool enabled);
@ -407,6 +408,9 @@ public:
QString getGlobalAutoAcceptDir() const; QString getGlobalAutoAcceptDir() const;
void setGlobalAutoAcceptDir(const QString& dir); void setGlobalAutoAcceptDir(const QString& dir);
bool getAutoGroupInvite(const ToxPk& id) const;
void setAutoGroupInvite(const ToxPk& id, bool accept);
// ChatView // ChatView
const QFont& getChatMessageFont() const; const QFont& getChatMessageFont() const;
void setChatMessageFont(const QFont& font); void setChatMessageFont(const QFont& font);
@ -629,6 +633,7 @@ private:
int circleID = -1; int circleID = -1;
QDate activity = QDate(); QDate activity = QDate();
AutoAcceptCallFlags autoAcceptCall; AutoAcceptCallFlags autoAcceptCall;
bool autoGroupInvite = false;
}; };
struct circleProp struct circleProp

View File

@ -19,19 +19,23 @@ AboutUser::AboutUser(ToxPk& toxId, QWidget* parent)
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AboutUser::onAcceptedClicked); connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AboutUser::onAcceptedClicked);
connect(ui->autoacceptfile, &QCheckBox::clicked, this, &AboutUser::onAutoAcceptDirClicked); connect(ui->autoacceptfile, &QCheckBox::clicked, this, &AboutUser::onAutoAcceptDirClicked);
connect(ui->autoacceptcall, SIGNAL(activated(int)), this, SLOT(onAutoAcceptCallClicked(void))); connect(ui->autoacceptcall, SIGNAL(activated(int)), this, SLOT(onAutoAcceptCallClicked(void)));
connect(ui->autogroupinvite, &QCheckBox::clicked, this, &AboutUser::onAutoGroupInvite);
connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutUser::onSelectDirClicked); connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutUser::onSelectDirClicked);
connect(ui->removeHistory, &QPushButton::clicked, this, &AboutUser::onRemoveHistoryClicked); connect(ui->removeHistory, &QPushButton::clicked, this, &AboutUser::onRemoveHistoryClicked);
this->friendPk = toxId; this->friendPk = toxId;
QString dir = Settings::getInstance().getAutoAcceptDir(this->friendPk); Settings& s = Settings::getInstance();
QString dir = s.getAutoAcceptDir(this->friendPk);
ui->autoacceptfile->setChecked(!dir.isEmpty()); ui->autoacceptfile->setChecked(!dir.isEmpty());
ui->autoacceptcall->setCurrentIndex(Settings::getInstance().getAutoAcceptCall(this->friendPk)); ui->autoacceptcall->setCurrentIndex(s.getAutoAcceptCall(this->friendPk));
ui->selectSaveDir->setEnabled(ui->autoacceptfile->isChecked()); ui->selectSaveDir->setEnabled(ui->autoacceptfile->isChecked());
ui->autogroupinvite->setChecked(s.getAutoGroupInvite(this->friendPk));
if (ui->autoacceptfile->isChecked()) if (ui->autoacceptfile->isChecked()) {
ui->selectSaveDir->setText(Settings::getInstance().getAutoAcceptDir(this->friendPk)); ui->selectSaveDir->setText(s.getAutoAcceptDir(this->friendPk));
}
} }
void AboutUser::setFriend(Friend* f) void AboutUser::setFriend(Friend* f)
@ -82,6 +86,15 @@ void AboutUser::onAutoAcceptCallClicked()
Settings::getInstance().savePersonal(); Settings::getInstance().savePersonal();
} }
/**
* @brief Sets the AutoGroupinvite status and saves the settings.
*/
void AboutUser::onAutoGroupInvite()
{
Settings::getInstance().setAutoGroupInvite(this->friendPk, ui->autogroupinvite->isChecked());
Settings::getInstance().savePersonal();
}
void AboutUser::onSelectDirClicked() void AboutUser::onSelectDirClicked()
{ {
QString dir; QString dir;

View File

@ -26,6 +26,7 @@ private slots:
void onAcceptedClicked(); void onAcceptedClicked();
void onAutoAcceptDirClicked(); void onAutoAcceptDirClicked();
void onAutoAcceptCallClicked(); void onAutoAcceptCallClicked();
void onAutoGroupInvite();
void onSelectDirClicked(); void onSelectDirClicked();
void onRemoveHistoryClicked(); void onRemoveHistoryClicked();
}; };

View File

@ -218,6 +218,16 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="autogroupinvite">
<property name="accessibleDescription">
<string>Automatically accept group chat invitations from this contact if set.</string>
</property>
<property name="text">
<string>Auto accept group invites</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

View File

@ -1556,13 +1556,18 @@ void Widget::copyFriendIdToClipboard(int friendId)
void Widget::onGroupInviteReceived(int32_t friendId, uint8_t type, QByteArray invite) void Widget::onGroupInviteReceived(int32_t friendId, uint8_t type, QByteArray invite)
{ {
updateFriendActivity(FriendList::findFriend(friendId)); Friend* f = FriendList::findFriend(friendId);
updateFriendActivity(f);
if (type == TOX_CONFERENCE_TYPE_TEXT || type == TOX_CONFERENCE_TYPE_AV) { if (type == TOX_CONFERENCE_TYPE_TEXT || type == TOX_CONFERENCE_TYPE_AV) {
if (Settings::getInstance().getAutoGroupInvite(f->getPublicKey())) {
onGroupInviteAccepted(friendId, type, invite);
} else {
++unreadGroupInvites; ++unreadGroupInvites;
groupInvitesUpdate(); groupInvitesUpdate();
newMessageAlert(window(), isActiveWindow(), true, true); newMessageAlert(window(), isActiveWindow(), true, true);
groupInviteForm->addGroupInvite(friendId, type, invite); groupInviteForm->addGroupInvite(friendId, type, invite);
}
} else { } else {
qWarning() << "onGroupInviteReceived: Unknown groupchat type:" << type; qWarning() << "onGroupInviteReceived: Unknown groupchat type:" << type;
return; return;
@ -2076,16 +2081,14 @@ inline QIcon Widget::prepareIcon(QString path, int w, int h)
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QString desktop = getenv("XDG_CURRENT_DESKTOP"); QString desktop = getenv("XDG_CURRENT_DESKTOP");
if (desktop.isEmpty()) if (desktop.isEmpty()) {
{
desktop = getenv("DESKTOP_SESSION"); desktop = getenv("DESKTOP_SESSION");
} }
desktop = desktop.toLower(); desktop = desktop.toLower();
if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate" || desktop == "x-cinnamon") if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate"
{ || desktop == "x-cinnamon") {
if (w > 0 && h > 0) if (w > 0 && h > 0) {
{
QSvgRenderer renderer(path); QSvgRenderer renderer(path);
QPixmap pm(w, h); QPixmap pm(w, h);