From f39fa5f0c71a1b04997005f54e33d162c82528de Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Sun, 5 Dec 2010 15:01:39 +0000
Subject: Ask for confirmation before clearing chat windows.

Resolves: #702
Release-Notes: You'll now be asked for confirmation before clearing the chat window history.

diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 4738da3..9646afb 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -15,6 +15,7 @@
 #include <QKeyEvent>
 #include <QStackedWidget>
 #include <QTimer>
+#include <QMessageBox>
 
 #include "QtWebView.h"
 #include "QtChatTheme.h"
@@ -32,7 +33,7 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) {
 	connect(webView_, SIGNAL(linkClicked(const QUrl&)), SLOT(handleLinkClicked(const QUrl&)));
 	connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool)));
 	connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus()));
-	connect(webView_, SIGNAL(clearRequested()), SLOT(resetView()));
+	connect(webView_, SIGNAL(clearRequested()), SLOT(handleClearRequested()));
 #ifdef Q_WS_X11
 	/* To give a border on Linux, where it looks bad without */
 	QStackedWidget* stack = new QStackedWidget(this);
@@ -54,6 +55,18 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) {
 	resetView();
 }
 
+void QtChatView::handleClearRequested() {
+	QMessageBox messageBox(this);
+	messageBox.setText("Clear log.");
+	messageBox.setInformativeText("Are you sure you want to clear your chat log?");
+	messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+	messageBox.setDefaultButton(QMessageBox::Yes);
+	int button = messageBox.exec();
+	if (button == QMessageBox::Yes) {
+		resetView();
+	}
+}
+
 void QtChatView::handleKeyPressEvent(QKeyEvent* event) {
 	webView_->keyPressEvent(event);
 }
diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h
index 84738d4..58b33df 100644
--- a/Swift/QtUI/QtChatView.h
+++ b/Swift/QtUI/QtChatView.h
@@ -46,6 +46,7 @@ namespace Swift {
 		private slots:
 			void handleViewLoadFinished(bool);
 			void handleFrameSizeChanged();
+			void handleClearRequested();
 
 		private:
 			void headerEncode();
-- 
cgit v0.10.2-6-g49f6