1
0
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:
Jakie.OYMJ 2018-10-05 10:24:39 +08:00
parent 96b5f5d1b5
commit e6d40be72e
15 changed files with 69 additions and 21 deletions

View File

@ -110,3 +110,14 @@ bool AboutFriend::clearHistory()
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;
}

View File

@ -36,6 +36,7 @@ public:
void setAutoGroupInvite(bool enabled) override;
bool clearHistory() override;
bool isHistoryExistence() override;
SIGNAL_IMPL(AboutFriend, nameChanged, const QString&)
SIGNAL_IMPL(AboutFriend, statusChanged, const QString&)

View File

@ -29,6 +29,7 @@ public:
virtual void setAutoGroupInvite(bool enabled) = 0;
virtual bool clearHistory() = 0;
virtual bool isHistoryExistence() = 0;
/* signals */
DECLARE_SIGNAL(nameChanged, const QString&);

View File

@ -85,6 +85,16 @@ bool History::isValid()
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.
*/

View File

@ -73,6 +73,8 @@ public:
bool isValid();
void import(const HistoryKeeper& oldHistory);
bool isHistoryExistence(const QString& friendPk);
void eraseHistory();
void removeFriendHistory(const QString& friendPk);
void addNewMessage(const QString& friendPk, const QString& message, const QString& sender,

View File

@ -1,4 +1,5 @@
#include "aboutfriendform.h"
#include "src/widget/gui.h"
#include "ui_aboutfriendform.h"
#include "src/core/core.h"
@ -25,6 +26,8 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget*
const QString dir = about->getAutoAcceptDir();
ui->autoacceptfile->setChecked(!dir.isEmpty());
ui->removeHistory->setEnabled(about->isHistoryExistence());
const int index = static_cast<int>(about->getAutoAcceptCall());
ui->autoacceptcall->setCurrentIndex(index);
@ -105,10 +108,24 @@ void AboutFriendForm::onAcceptedClicked()
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!")
.arg(about->getName().toHtmlEscaped()), QMessageBox::Ok);
const bool result = about->clearHistory();
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()

View File

@ -24,6 +24,9 @@ private:
Ui::AboutFriendForm* ui;
const std::unique_ptr<IAboutFriend> about;
signals:
void histroyRemoved();
private slots:
void onAutoAcceptDirChanged(const QString& path);
void onAcceptedClicked();

View File

@ -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();
}

View File

@ -74,6 +74,7 @@ public slots:
void onAvEnd(uint32_t friendId, bool error);
void onAvatarChanged(const ToxPk &friendPk, const QPixmap& pic);
void onFileNameChanged(const ToxPk& friendPk);
void clearChatArea();
protected slots:
void searchInBegin(const QString& phrase, const ParameterSearch& parameter) override;
@ -81,7 +82,6 @@ protected slots:
void onSearchDown(const QString& phrase, const ParameterSearch& parameter) override;
private slots:
void clearChatArea(bool notInForm) override final;
void onSendTriggered() override;
void onAttachClicked() override;
void onScreenshotClicked() override;

View File

@ -220,7 +220,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent)
saveChatAction = menu.addAction(QIcon::fromTheme("document-save"), QString(),
this, SLOT(onSaveLogClicked()));
clearAction = menu.addAction(QIcon::fromTheme("edit-clear"), QString(),
this, SLOT(clearChatArea(bool)),
this, SLOT(clearChatArea()),
QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_L));
addAction(clearAction);
@ -816,27 +816,28 @@ std::pair<int, int> GenericChatForm::indexForSearchInLine(const QString& txt, co
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 =
QMessageBox::question(this, tr("Confirmation"),
tr("You are sure that you want to clear all displayed messages?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (mboxResult == QMessageBox::No) {
return;
if (confirm) {
QMessageBox::StandardButton mboxResult =
QMessageBox::question(this, tr("Confirmation"),
tr("You are sure that you want to clear all displayed messages?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (mboxResult == QMessageBox::No) {
return;
}
}
chatWidget->clear();
previousId = ToxPk();
if (!notinform)
if (inform)
addSystemInfoMessage(tr("Cleared"), ChatMessage::INFO, QDateTime::currentDateTime());
earliestMessage = QDateTime(); // null
emit chatAreaCleared();
}
void GenericChatForm::onSelectAllClicked()

View File

@ -87,7 +87,6 @@ public:
signals:
void sendMessage(uint32_t, QString);
void sendAction(uint32_t, QString);
void chatAreaCleared();
void messageInserted();
void messageNotFoundShow(SearchDirection direction);
@ -104,8 +103,8 @@ protected slots:
void onEmoteInsertRequested(QString str);
void onSaveLogClicked();
void onCopyLogClicked();
virtual void clearChatArea(bool);
void clearChatArea();
void clearChatArea(bool confirm, bool inform);
void onSelectAllClicked();
void showFileMenu();
void hideFileMenu();

View File

@ -294,6 +294,7 @@ void FriendWidget::showDetails()
const auto iabout = new AboutFriend(frnd, &Settings::getInstance());
std::unique_ptr<IAboutFriend> about = std::unique_ptr<IAboutFriend>(iabout);
const auto aboutUser = new AboutFriendForm(std::move(about), Widget::getInstance());
connect(aboutUser, &AboutFriendForm::histroyRemoved, this, &FriendWidget::friendHistoryRemoved);
aboutUser->show();
}

View File

@ -48,6 +48,7 @@ signals:
void removeFriend(int friendId);
void copyFriendIdToClipboard(int friendId);
void contextMenuCalled(QContextMenuEvent* event);
void friendHistoryRemoved();
public slots:
void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic);

View File

@ -1015,6 +1015,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
connect(widget, &FriendWidget::newWindowOpened, this, &Widget::openNewDialog);
connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
connect(widget, &FriendWidget::chatroomWidgetClicked, friendForm, &ChatForm::focusInput);
connect(widget, &FriendWidget::friendHistoryRemoved, friendForm, &ChatForm::clearChatArea);
connect(widget, &FriendWidget::copyFriendIdToClipboard, this, &Widget::copyFriendIdToClipboard);
connect(widget, &FriendWidget::contextMenuCalled, widget, &FriendWidget::onContextMenuCalled);
connect(widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));

View File

@ -104,7 +104,7 @@ private:
public:
explicit Widget(QWidget* parent = nullptr);
~Widget();
~Widget() override;
void init();
void setCentralWidget(QWidget* widget, const QString& widgetName);
QString getUsername();