From 74d98fd0c2e2541d8b98da0971c3f8544f1fc004 Mon Sep 17 00:00:00 2001 From: rku Date: Sat, 22 Aug 2015 12:05:16 +0300 Subject: [PATCH] This dialog solves all confusion that arose from current verification method and is accident-proof. Current method asks if user also wants to remove chat history. However confused user may not carefully read message and click "no" because he does not want to remve contact. However in this case contact is in fact removed but history is preserved. It is also open to possiblity that key smashing deletes contact by accident. This is very inconvenient because tox ids are long and hard to memorize. If someone removes contact by accident then he would need to find id of that contact in order to contact him/her. Sometimes this may be difficult. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New contact removal confirmation dialog prompts use to enter "YES" in the text boxin order to enable "OK" button so removal can be accepted. It also has checkbox for history removal. Dialog will work with translations. Russian user would need to enter "Да" in order to accept removal. --- qtox.pro | 9 ++- src/widget/form/removefrienddialog.ui | 97 ++++++++++++++++++++++++++ src/widget/tool/removefrienddialog.cpp | 31 ++++++++ src/widget/tool/removefrienddialog.h | 35 ++++++++++ src/widget/widget.cpp | 13 ++-- 5 files changed, 175 insertions(+), 10 deletions(-) create mode 100644 src/widget/form/removefrienddialog.ui create mode 100644 src/widget/tool/removefrienddialog.cpp create mode 100644 src/widget/tool/removefrienddialog.h diff --git a/qtox.pro b/qtox.pro index f2548a76e..3eec7904d 100644 --- a/qtox.pro +++ b/qtox.pro @@ -34,7 +34,8 @@ FORMS += \ src/widget/form/settings/advancedsettings.ui \ src/widget/form/settings/avsettings.ui \ src/widget/form/settings/generalsettings.ui \ - src/widget/form/settings/privacysettings.ui + src/widget/form/settings/privacysettings.ui \ + src/widget/form/removefrienddialog.ui CONFIG += c++11 @@ -493,7 +494,8 @@ SOURCES += \ src/widget/genericchatitemwidget.cpp \ src/widget/friendlistlayout.cpp \ src/widget/genericchatitemlayout.cpp \ - src/widget/categorywidget.cpp + src/widget/categorywidget.cpp \ + src/widget/tool/removefrienddialog.cpp HEADERS += \ src/audio/audio.h \ @@ -536,4 +538,5 @@ HEADERS += \ src/widget/genericchatitemwidget.h \ src/widget/friendlistlayout.h \ src/widget/genericchatitemlayout.h \ - src/widget/categorywidget.h + src/widget/categorywidget.h \ + src/widget/tool/removefrienddialog.h diff --git a/src/widget/form/removefrienddialog.ui b/src/widget/form/removefrienddialog.ui new file mode 100644 index 000000000..f7f1c564e --- /dev/null +++ b/src/widget/form/removefrienddialog.ui @@ -0,0 +1,97 @@ + + + RemoveFriendDialog + + + + 0 + 0 + 300 + 180 + + + + Remove friend + + + + + + <html><head/><body><p>Are you sure you want to remove <span style=" font-weight:600;">&lt;name&gt;</span> from your contacts list?</p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + + + Qt::AlignCenter + + + YES + + + + + + + Also remove chat history + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + RemoveFriendDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RemoveFriendDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/widget/tool/removefrienddialog.cpp b/src/widget/tool/removefrienddialog.cpp new file mode 100644 index 000000000..3d3f39bea --- /dev/null +++ b/src/widget/tool/removefrienddialog.cpp @@ -0,0 +1,31 @@ +#include "removefrienddialog.h" +#include + + +RemoveFriendDialog::RemoveFriendDialog(QWidget *parent, const Friend *f) + : QDialog(parent) +{ + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + setAttribute(Qt::WA_QuitOnClose, false); + ui.setupUi(this); + ui.label->setText(ui.label->text().replace("<name>", f->getDisplayedName())); + auto removeButton = ui.buttonBox->button(QDialogButtonBox::Ok); + removeButton->setEnabled(false); + removeButton->setText(tr("Remove")); + connect(ui.yes, &QLineEdit::textChanged, this, &RemoveFriendDialog::onTextChanged); + connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &RemoveFriendDialog::onAccepted); + connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &RemoveFriendDialog::close); + setFocus(); +} + +void RemoveFriendDialog::onAccepted() +{ + _accepted = true; + close(); +} + +void RemoveFriendDialog::onTextChanged(QString text) +{ + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(text == ui.yes->placeholderText()); +} + diff --git a/src/widget/tool/removefrienddialog.h b/src/widget/tool/removefrienddialog.h new file mode 100644 index 000000000..00421f34e --- /dev/null +++ b/src/widget/tool/removefrienddialog.h @@ -0,0 +1,35 @@ +#ifndef DELETEFRIENDDIALOG_H +#define DELETEFRIENDDIALOG_H + + +#include +#include "ui_removefrienddialog.h" +#include "src/friend.h" + + +class RemoveFriendDialog : public QDialog +{ + Q_OBJECT +public: + explicit RemoveFriendDialog(QWidget *parent, const Friend* f); + + inline bool removeHistory() + { + return ui.removeHistory->isChecked(); + } + + inline bool accepted() + { + return _accepted; + } + +public slots: + void onAccepted(); + void onTextChanged(QString text); + +protected: + Ui_RemoveFriendDialog ui; + bool _accepted = false; +}; + +#endif // DELETEFRIENDDIALOG_H diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index cd7fcd1d3..5ae66a024 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -47,6 +47,7 @@ #include "src/widget/form/filesform.h" #include "src/widget/form/profileform.h" #include "src/widget/form/settingswidget.h" +#include "tool/removefrienddialog.h" #include #include #include @@ -994,14 +995,12 @@ void Widget::removeFriend(Friend* f, bool fake) { if (!fake) { - QMessageBox::StandardButton removeFriendMB; - removeFriendMB = QMessageBox::question(0, - tr("Removal of friend ")+"\""+ f->getDisplayedName()+"\"", - tr("Do you want to remove history as well?"), - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); - if (removeFriendMB == QMessageBox::Cancel) + RemoveFriendDialog ask(this, f); + ask.exec(); + + if (!ask.accepted()) return; - else if (removeFriendMB == QMessageBox::Yes) + else if (ask.removeHistory()) HistoryKeeper::getInstance()->removeFriendHistory(f->getToxId().publicKey); }