The search result is now synced with the daynavigator.
[toast/confclerk.git] / src / gui / mainwindow.cpp
index b9969a9d5a1eefb5409a6790381136d956784e83..c6505ad490c484b81a9208daf206256f5e1bf2ab 100644 (file)
@@ -97,6 +97,10 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     connect(dayNavigator, SIGNAL(dateChanged(QDate)), roomsTabContainer, SLOT(redisplayDate(QDate)));
     connect(dayNavigator, SIGNAL(dateChanged(QDate)), searchTabContainer, SLOT(redisplayDate(QDate)));
 
+    // search result has changed
+    connect(searchTabContainer, SIGNAL(searchResultChanged()), SLOT(onSearchResultChanged()));
+
+
     useConference(Conference::activeConference());
     // optimization, see useConference() code
     try {
@@ -172,6 +176,28 @@ void MainWindow::onEventChanged(int aEventId, bool favouriteChanged) {
 }
 
 
+void MainWindow::onSearchResultChanged() {
+    // Are results found on the current date?
+    QDate date = dayNavigator->curDate();
+    int count = searchTabContainer->searchResultCount(date);
+    if (count > 0) {searchTabContainer->redisplayDate(date); return;}
+
+    // Are results found in the future?
+    for (date = date.addDays(1); date <= dayNavigator->endDate(); date = date.addDays(1)) {
+        int count = searchTabContainer->searchResultCount(date);
+        if (count > 0) {dayNavigator->setCurDate(date); return;}
+    }
+
+    // Are results found in the past?
+    for (date = dayNavigator->startDate(); date < dayNavigator->curDate(); date = date.addDays(1)) {
+        int count = searchTabContainer->searchResultCount(date);
+        if (count > 0) {dayNavigator->setCurDate(date); return;}
+    }
+    // No results were found
+    searchTabContainer->redisplayDate(dayNavigator->curDate());
+}
+
+
 void MainWindow::useConference(int id)
 {
     if (id == -1)  // in case no conference is active