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

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.

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.
This commit is contained in:
rku 2015-08-22 12:05:16 +03:00
parent 2f6b5e052f
commit 74d98fd0c2
5 changed files with 175 additions and 10 deletions

View File

@ -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

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RemoveFriendDialog</class>
<widget class="QDialog" name="RemoveFriendDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>180</height>
</rect>
</property>
<property name="windowTitle">
<string>Remove friend</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Are you sure you want to remove &lt;span style=&quot; font-weight:600;&quot;&gt;&amp;lt;name&amp;gt;&lt;/span&gt; from your contacts list?&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="yes">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="placeholderText">
<string>YES</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="removeHistory">
<property name="text">
<string>Also remove chat history</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>RemoveFriendDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RemoveFriendDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,31 @@
#include "removefrienddialog.h"
#include <QPushButton>
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("&lt;name&gt;", 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());
}

View File

@ -0,0 +1,35 @@
#ifndef DELETEFRIENDDIALOG_H
#define DELETEFRIENDDIALOG_H
#include <QDialog>
#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

View File

@ -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 <cassert>
#include <QMessageBox>
#include <QDebug>
@ -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);
}