From 36377ac0e0443de02d2a0d24bbe8632f12d211cd Mon Sep 17 00:00:00 2001
From: Catalin Badea <catalin.badea392@gmail.com>
Date: Fri, 20 Jul 2012 17:03:04 +0300
Subject: add previous/next button callbacks


diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp
index 6ec8a3e..baa7ebf 100644
--- a/Swift/Controllers/HistoryViewController.cpp
+++ b/Swift/Controllers/HistoryViewController.cpp
@@ -46,6 +46,8 @@ HistoryViewController::~HistoryViewController() {
 		historyWindow_->onReturnPressed.disconnect(boost::bind(&HistoryViewController::handleReturnPressed, this, _1));
 		historyWindow_->onScrollReachedTop.disconnect(boost::bind(&HistoryViewController::handleScrollReachedTop, this, _1));
 		historyWindow_->onScrollReachedBottom.disconnect(boost::bind(&HistoryViewController::handleScrollReachedBottom, this, _1));
+		historyWindow_->onPreviousButtonClicked.disconnect(boost::bind(&HistoryViewController::handlePreviousButtonClicked, this));
+		historyWindow_->onNextButtonClicked.disconnect(boost::bind(&HistoryViewController::handleNextButtonClicked, this));
 		delete historyWindow_;
 	}
 	delete roster_;
@@ -61,6 +63,8 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
 			historyWindow_->onReturnPressed.connect(boost::bind(&HistoryViewController::handleReturnPressed, this, _1));
 			historyWindow_->onScrollReachedTop.connect(boost::bind(&HistoryViewController::handleScrollReachedTop, this, _1));
 			historyWindow_->onScrollReachedBottom.connect(boost::bind(&HistoryViewController::handleScrollReachedBottom, this, _1));
+			historyWindow_->onPreviousButtonClicked.connect(boost::bind(&HistoryViewController::handlePreviousButtonClicked, this));
+			historyWindow_->onNextButtonClicked.connect(boost::bind(&HistoryViewController::handleNextButtonClicked, this));
 
 			historyWindow_->setRosterModel(roster_);
 		}
@@ -149,12 +153,7 @@ void HistoryViewController::addNewMessage(const HistoryMessage& message, bool ad
 }
 
 void HistoryViewController::handleReturnPressed(const std::string& keyword) {
-	roster_->removeAll();
-	rooms_.clear();
-	contacts_.clear();
-	roomPrivateContacts_.clear();
-	selectedItem_ = NULL;
-	historyWindow_->resetConversationView();
+	reset();
 
 	// MUCs
 	rooms_ = historyController_->getContacts(selfJID_, HistoryMessage::Groupchat, keyword);
@@ -194,4 +193,21 @@ void HistoryViewController::handleScrollReachedBottom(const boost::gregorian::da
 	}
 }
 
+void HistoryViewController::handlePreviousButtonClicked() {
+	reset();
+}
+
+void HistoryViewController::handleNextButtonClicked() {
+	reset();
+}
+
+void HistoryViewController::reset() {
+	roster_->removeAll();
+	rooms_.clear();
+	contacts_.clear();
+	roomPrivateContacts_.clear();
+	selectedItem_ = NULL;
+	historyWindow_->resetConversationView();
+}
+
 }
diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h
index 5c4dc96..b4ae19d 100644
--- a/Swift/Controllers/HistoryViewController.h
+++ b/Swift/Controllers/HistoryViewController.h
@@ -35,10 +35,14 @@ namespace Swift {
 			void handleUIEvent(boost::shared_ptr<UIEvent> event);
 			void handleSelectedContactChanged(RosterItem* item);
 			void handleNewMessage(const HistoryMessage& message);
-			void addNewMessage(const HistoryMessage& message, bool addAtTheTop);
 			void handleReturnPressed(const std::string& keyword);
 			void handleScrollReachedTop(const boost::gregorian::date& date);
 			void handleScrollReachedBottom(const boost::gregorian::date& date);
+			void handlePreviousButtonClicked();
+			void handleNextButtonClicked();
+
+			void addNewMessage(const HistoryMessage& message, bool addAtTheTop);
+			void reset();
 
 		private:
 			JID selfJID_;
diff --git a/Swift/Controllers/UIInterfaces/HistoryWindow.h b/Swift/Controllers/UIInterfaces/HistoryWindow.h
index 03f4886..cb8225b 100644
--- a/Swift/Controllers/UIInterfaces/HistoryWindow.h
+++ b/Swift/Controllers/UIInterfaces/HistoryWindow.h
@@ -23,5 +23,7 @@ namespace Swift {
 			boost::signal<void (const std::string&)> onReturnPressed;
 			boost::signal<void (const boost::gregorian::date&)> onScrollReachedTop;
 			boost::signal<void (const boost::gregorian::date&)> onScrollReachedBottom;
+			boost::signal<void ()> onPreviousButtonClicked();
+			boost::signal<void ()> onNextButtonClicked();
 	};
 }
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp
index 6e779ea..ba463d3 100644
--- a/Swift/QtUI/QtHistoryWindow.cpp
+++ b/Swift/QtUI/QtHistoryWindow.cpp
@@ -60,6 +60,8 @@ QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* even
 	connect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
 	connect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
 	connect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+	connect(ui_.previousButton_, SIGNAL(clicked(bool)), this SLOT(handlePreviousButtonClicked()));
+	connect(ui_.nextButton_, SIGNAL(clicked(bool)), this SLOT(handleNextButtonClicked()));
 }
 
 QtHistoryWindow::~QtHistoryWindow() {
@@ -68,6 +70,8 @@ QtHistoryWindow::~QtHistoryWindow() {
 	disconnect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
 	disconnect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
 	disconnect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+	disconnect(ui_.previousButton_, SIGNAL(clicked(bool)), this SLOT(handlePreviousButtonClicked()));
+	disconnect(ui_.nextButton_, SIGNAL(clicked(bool)), this SLOT(handleNextButtonClicked()));
 
 	delete theme_;
 	delete conversation_;
@@ -169,4 +173,12 @@ void QtHistoryWindow::setDate(const boost::gregorian::date& date) {
 	ui_.calendarWidget_->setSelectedDate(QDate::fromJulianDay(date.julian_day()));
 }
 
+void QtHistoryWindow::handleNextButtonClicked() {
+	onNextButtonClicked();
+}
+
+void QtHistoryWindow::handlePreviousButtonClicked() {
+	onPreviousButtonClicked();
+}
+
 }
diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h
index 721b4da..cfd558a 100644
--- a/Swift/QtUI/QtHistoryWindow.h
+++ b/Swift/QtUI/QtHistoryWindow.h
@@ -36,6 +36,8 @@ namespace Swift {
 			void handleScrollReachedBottom();
 			void handleReturnPressed();
 			void handleCalendarClicked(const QDate& date);
+			void handlePreviousButtonClicked();
+			void handleNextButtonClicked();
 
 		private:
 			void handleSomethingSelectedChanged(RosterItem* item);
-- 
cgit v0.10.2-6-g49f6