mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix: add remove history prompt, clear log area after remove
This commit is contained in:
parent
96b5f5d1b5
commit
e6d40be72e
|
@ -110,3 +110,14 @@ bool AboutFriend::clearHistory()
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AboutFriend::isHistoryExistence()
|
||||||
|
{
|
||||||
|
History* const history = Nexus::getProfile()->getHistory();
|
||||||
|
if (history) {
|
||||||
|
const ToxPk pk = f->getPublicKey();
|
||||||
|
return history->isHistoryExistence(pk.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
void setAutoGroupInvite(bool enabled) override;
|
void setAutoGroupInvite(bool enabled) override;
|
||||||
|
|
||||||
bool clearHistory() override;
|
bool clearHistory() override;
|
||||||
|
bool isHistoryExistence() override;
|
||||||
|
|
||||||
SIGNAL_IMPL(AboutFriend, nameChanged, const QString&)
|
SIGNAL_IMPL(AboutFriend, nameChanged, const QString&)
|
||||||
SIGNAL_IMPL(AboutFriend, statusChanged, const QString&)
|
SIGNAL_IMPL(AboutFriend, statusChanged, const QString&)
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
virtual void setAutoGroupInvite(bool enabled) = 0;
|
virtual void setAutoGroupInvite(bool enabled) = 0;
|
||||||
|
|
||||||
virtual bool clearHistory() = 0;
|
virtual bool clearHistory() = 0;
|
||||||
|
virtual bool isHistoryExistence() = 0;
|
||||||
|
|
||||||
/* signals */
|
/* signals */
|
||||||
DECLARE_SIGNAL(nameChanged, const QString&);
|
DECLARE_SIGNAL(nameChanged, const QString&);
|
||||||
|
|
|
@ -85,6 +85,16 @@ bool History::isValid()
|
||||||
return db && db->isOpen();
|
return db && db->isOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if a friend has chat history
|
||||||
|
* @param friendPk
|
||||||
|
* @return True if has, false otherwise.
|
||||||
|
*/
|
||||||
|
bool History::isHistoryExistence(const QString& friendPk)
|
||||||
|
{
|
||||||
|
return !getChatHistoryDefaultNum(friendPk).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Erases all the chat history from the database.
|
* @brief Erases all the chat history from the database.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -73,6 +73,8 @@ public:
|
||||||
bool isValid();
|
bool isValid();
|
||||||
void import(const HistoryKeeper& oldHistory);
|
void import(const HistoryKeeper& oldHistory);
|
||||||
|
|
||||||
|
bool isHistoryExistence(const QString& friendPk);
|
||||||
|
|
||||||
void eraseHistory();
|
void eraseHistory();
|
||||||
void removeFriendHistory(const QString& friendPk);
|
void removeFriendHistory(const QString& friendPk);
|
||||||
void addNewMessage(const QString& friendPk, const QString& message, const QString& sender,
|
void addNewMessage(const QString& friendPk, const QString& message, const QString& sender,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "aboutfriendform.h"
|
#include "aboutfriendform.h"
|
||||||
|
#include "src/widget/gui.h"
|
||||||
#include "ui_aboutfriendform.h"
|
#include "ui_aboutfriendform.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
|
|
||||||
|
@ -25,6 +26,8 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget*
|
||||||
const QString dir = about->getAutoAcceptDir();
|
const QString dir = about->getAutoAcceptDir();
|
||||||
ui->autoacceptfile->setChecked(!dir.isEmpty());
|
ui->autoacceptfile->setChecked(!dir.isEmpty());
|
||||||
|
|
||||||
|
ui->removeHistory->setEnabled(about->isHistoryExistence());
|
||||||
|
|
||||||
const int index = static_cast<int>(about->getAutoAcceptCall());
|
const int index = static_cast<int>(about->getAutoAcceptCall());
|
||||||
ui->autoacceptcall->setCurrentIndex(index);
|
ui->autoacceptcall->setCurrentIndex(index);
|
||||||
|
|
||||||
|
@ -105,10 +108,24 @@ void AboutFriendForm::onAcceptedClicked()
|
||||||
|
|
||||||
void AboutFriendForm::onRemoveHistoryClicked()
|
void AboutFriendForm::onRemoveHistoryClicked()
|
||||||
{
|
{
|
||||||
about->clearHistory();
|
const bool retYes = GUI::askQuestion(tr("Confirmation"),
|
||||||
|
tr("Are you sure to remove %1 chat history?").arg(about->getName()),
|
||||||
|
/* defaultAns = */ false, /* warning = */ true, /* yesno = */ true);
|
||||||
|
if (!retYes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QMessageBox::information(this, tr("History removed"), tr("Chat history with %1 removed!")
|
const bool result = about->clearHistory();
|
||||||
.arg(about->getName().toHtmlEscaped()), QMessageBox::Ok);
|
|
||||||
|
if (!result) {
|
||||||
|
GUI::showWarning(tr("History removed"),
|
||||||
|
tr("Failed to remove chat history with %1!").arg(about->getName()).toHtmlEscaped());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit histroyRemoved();
|
||||||
|
|
||||||
|
ui->removeHistory->setEnabled(false); // For know clearly to has removed the history
|
||||||
}
|
}
|
||||||
|
|
||||||
AboutFriendForm::~AboutFriendForm()
|
AboutFriendForm::~AboutFriendForm()
|
||||||
|
|
|
@ -24,6 +24,9 @@ private:
|
||||||
Ui::AboutFriendForm* ui;
|
Ui::AboutFriendForm* ui;
|
||||||
const std::unique_ptr<IAboutFriend> about;
|
const std::unique_ptr<IAboutFriend> about;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void histroyRemoved();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onAutoAcceptDirChanged(const QString& path);
|
void onAutoAcceptDirChanged(const QString& path);
|
||||||
void onAcceptedClicked();
|
void onAcceptedClicked();
|
||||||
|
|
|
@ -725,9 +725,9 @@ void ChatForm::dropEvent(QDropEvent* ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::clearChatArea(bool notInForm)
|
void ChatForm::clearChatArea()
|
||||||
{
|
{
|
||||||
GenericChatForm::clearChatArea(notInForm);
|
GenericChatForm::clearChatArea(/* confirm = */ false, /* inform = */ true);
|
||||||
offlineEngine->removeAllReceipts();
|
offlineEngine->removeAllReceipts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ public slots:
|
||||||
void onAvEnd(uint32_t friendId, bool error);
|
void onAvEnd(uint32_t friendId, bool error);
|
||||||
void onAvatarChanged(const ToxPk &friendPk, const QPixmap& pic);
|
void onAvatarChanged(const ToxPk &friendPk, const QPixmap& pic);
|
||||||
void onFileNameChanged(const ToxPk& friendPk);
|
void onFileNameChanged(const ToxPk& friendPk);
|
||||||
|
void clearChatArea();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void searchInBegin(const QString& phrase, const ParameterSearch& parameter) override;
|
void searchInBegin(const QString& phrase, const ParameterSearch& parameter) override;
|
||||||
|
@ -81,7 +82,6 @@ protected slots:
|
||||||
void onSearchDown(const QString& phrase, const ParameterSearch& parameter) override;
|
void onSearchDown(const QString& phrase, const ParameterSearch& parameter) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void clearChatArea(bool notInForm) override final;
|
|
||||||
void onSendTriggered() override;
|
void onSendTriggered() override;
|
||||||
void onAttachClicked() override;
|
void onAttachClicked() override;
|
||||||
void onScreenshotClicked() override;
|
void onScreenshotClicked() override;
|
||||||
|
|
|
@ -220,7 +220,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent)
|
||||||
saveChatAction = menu.addAction(QIcon::fromTheme("document-save"), QString(),
|
saveChatAction = menu.addAction(QIcon::fromTheme("document-save"), QString(),
|
||||||
this, SLOT(onSaveLogClicked()));
|
this, SLOT(onSaveLogClicked()));
|
||||||
clearAction = menu.addAction(QIcon::fromTheme("edit-clear"), QString(),
|
clearAction = menu.addAction(QIcon::fromTheme("edit-clear"), QString(),
|
||||||
this, SLOT(clearChatArea(bool)),
|
this, SLOT(clearChatArea()),
|
||||||
QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_L));
|
QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_L));
|
||||||
addAction(clearAction);
|
addAction(clearAction);
|
||||||
|
|
||||||
|
@ -816,27 +816,28 @@ std::pair<int, int> GenericChatForm::indexForSearchInLine(const QString& txt, co
|
||||||
|
|
||||||
void GenericChatForm::clearChatArea()
|
void GenericChatForm::clearChatArea()
|
||||||
{
|
{
|
||||||
clearChatArea(true);
|
clearChatArea(/* confirm = */ true, /* inform = */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatForm::clearChatArea(bool notinform)
|
void GenericChatForm::clearChatArea(bool confirm, bool inform)
|
||||||
{
|
{
|
||||||
QMessageBox::StandardButton mboxResult =
|
if (confirm) {
|
||||||
QMessageBox::question(this, tr("Confirmation"),
|
QMessageBox::StandardButton mboxResult =
|
||||||
tr("You are sure that you want to clear all displayed messages?"),
|
QMessageBox::question(this, tr("Confirmation"),
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
tr("You are sure that you want to clear all displayed messages?"),
|
||||||
if (mboxResult == QMessageBox::No) {
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||||
return;
|
if (mboxResult == QMessageBox::No) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chatWidget->clear();
|
chatWidget->clear();
|
||||||
previousId = ToxPk();
|
previousId = ToxPk();
|
||||||
|
|
||||||
if (!notinform)
|
if (inform)
|
||||||
addSystemInfoMessage(tr("Cleared"), ChatMessage::INFO, QDateTime::currentDateTime());
|
addSystemInfoMessage(tr("Cleared"), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||||
|
|
||||||
earliestMessage = QDateTime(); // null
|
earliestMessage = QDateTime(); // null
|
||||||
|
|
||||||
emit chatAreaCleared();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatForm::onSelectAllClicked()
|
void GenericChatForm::onSelectAllClicked()
|
||||||
|
|
|
@ -87,7 +87,6 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void sendMessage(uint32_t, QString);
|
void sendMessage(uint32_t, QString);
|
||||||
void sendAction(uint32_t, QString);
|
void sendAction(uint32_t, QString);
|
||||||
void chatAreaCleared();
|
|
||||||
void messageInserted();
|
void messageInserted();
|
||||||
void messageNotFoundShow(SearchDirection direction);
|
void messageNotFoundShow(SearchDirection direction);
|
||||||
|
|
||||||
|
@ -104,8 +103,8 @@ protected slots:
|
||||||
void onEmoteInsertRequested(QString str);
|
void onEmoteInsertRequested(QString str);
|
||||||
void onSaveLogClicked();
|
void onSaveLogClicked();
|
||||||
void onCopyLogClicked();
|
void onCopyLogClicked();
|
||||||
virtual void clearChatArea(bool);
|
|
||||||
void clearChatArea();
|
void clearChatArea();
|
||||||
|
void clearChatArea(bool confirm, bool inform);
|
||||||
void onSelectAllClicked();
|
void onSelectAllClicked();
|
||||||
void showFileMenu();
|
void showFileMenu();
|
||||||
void hideFileMenu();
|
void hideFileMenu();
|
||||||
|
|
|
@ -294,6 +294,7 @@ void FriendWidget::showDetails()
|
||||||
const auto iabout = new AboutFriend(frnd, &Settings::getInstance());
|
const auto iabout = new AboutFriend(frnd, &Settings::getInstance());
|
||||||
std::unique_ptr<IAboutFriend> about = std::unique_ptr<IAboutFriend>(iabout);
|
std::unique_ptr<IAboutFriend> about = std::unique_ptr<IAboutFriend>(iabout);
|
||||||
const auto aboutUser = new AboutFriendForm(std::move(about), Widget::getInstance());
|
const auto aboutUser = new AboutFriendForm(std::move(about), Widget::getInstance());
|
||||||
|
connect(aboutUser, &AboutFriendForm::histroyRemoved, this, &FriendWidget::friendHistoryRemoved);
|
||||||
aboutUser->show();
|
aboutUser->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ signals:
|
||||||
void removeFriend(int friendId);
|
void removeFriend(int friendId);
|
||||||
void copyFriendIdToClipboard(int friendId);
|
void copyFriendIdToClipboard(int friendId);
|
||||||
void contextMenuCalled(QContextMenuEvent* event);
|
void contextMenuCalled(QContextMenuEvent* event);
|
||||||
|
void friendHistoryRemoved();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic);
|
void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic);
|
||||||
|
|
|
@ -1015,6 +1015,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
||||||
connect(widget, &FriendWidget::newWindowOpened, this, &Widget::openNewDialog);
|
connect(widget, &FriendWidget::newWindowOpened, this, &Widget::openNewDialog);
|
||||||
connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
|
connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
|
||||||
connect(widget, &FriendWidget::chatroomWidgetClicked, friendForm, &ChatForm::focusInput);
|
connect(widget, &FriendWidget::chatroomWidgetClicked, friendForm, &ChatForm::focusInput);
|
||||||
|
connect(widget, &FriendWidget::friendHistoryRemoved, friendForm, &ChatForm::clearChatArea);
|
||||||
connect(widget, &FriendWidget::copyFriendIdToClipboard, this, &Widget::copyFriendIdToClipboard);
|
connect(widget, &FriendWidget::copyFriendIdToClipboard, this, &Widget::copyFriendIdToClipboard);
|
||||||
connect(widget, &FriendWidget::contextMenuCalled, widget, &FriendWidget::onContextMenuCalled);
|
connect(widget, &FriendWidget::contextMenuCalled, widget, &FriendWidget::onContextMenuCalled);
|
||||||
connect(widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
connect(widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||||
|
|
|
@ -104,7 +104,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Widget(QWidget* parent = nullptr);
|
explicit Widget(QWidget* parent = nullptr);
|
||||||
~Widget();
|
~Widget() override;
|
||||||
void init();
|
void init();
|
||||||
void setCentralWidget(QWidget* widget, const QString& widgetName);
|
void setCentralWidget(QWidget* widget, const QString& widgetName);
|
||||||
QString getUsername();
|
QString getUsername();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user