+/*
+ * Copyright (C) 2010 Ixonos Plc.
+ *
+ * This file is part of fosdem-schedule.
+ *
+ * fosdem-schedule is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * fosdem-schedule is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "searchtabcontainer.h"
#include "searchhead.h"
-
+#include <QMessageBox>
SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent )
{
columns["ROOM"] = "name";
QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
- qDebug() << "\nKeyword to search: " << keyword;
+ //qDebug() << "\nKeyword to search: " << keyword;
int confId = Conference::activeConference();
SqlEngine::searchEvent( confId, columns, keyword );
QDate startDate = Conference::getById(confId).start();
QDate endDate = Conference::getById(confId).end();
- dayNavigator->setDates(startDate, endDate);
- updateTreeView( Conference::getById(confId).start() );
+
+ int nrofFounds = 0;
+ QDate firstDateWithFounds = endDate;
+ QDate lastDateWithFounds = startDate;
+ for(QDate d=startDate; d<=endDate; d=d.addDays(1))
+ {
+ try{
+ int count = Event::getSearchResultByDate(d, confId, "start").count();
+ if(count && (firstDateWithFounds==endDate))
+ firstDateWithFounds=d;
+ if(count)
+ lastDateWithFounds=d;
+ nrofFounds+=count;
+ }
+ catch( OrmException &e ){
+ qDebug() << "Event::getSearchResultByDate failed: " << e.text();
+ }
+ catch(...){
+ qDebug() << "Event::getSearchResultByDate failed";
+ }
+ }
+
+ if(!nrofFounds)
+ {
+ // TODO: display some message
+ treeView->hide();
+ searchAgainButton->hide();
+ dayNavigator->hide();
+ header->show();
+ QMessageBox::information(
+ this,
+ QString("Keyword '%1' not found!").arg(keyword),
+ QString("No events containing '%1' found!").arg(keyword),
+ QMessageBox::Ok);
+ }
+ else
+ {
+ searchAgainButton->show();
+ dayNavigator->show();
+ treeView->show();
+ header->hide();
+
+ updateTreeView( firstDateWithFounds );
+ dayNavigator->setDates(firstDateWithFounds, lastDateWithFounds);
+ }
}
void SearchTabContainer::searchAgainClicked()
{
- qDebug() << "SearchTab::searchAgainClicked()";
header->show();
searchAgainButton->hide();
dayNavigator->hide();
void SearchTabContainer::loadEvents( const QDate &aDate, const int aConferenceId )
{
- int eventsCount = static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
- if( eventsCount ||
- //TODO: this is not good test
- dayNavigator->getCurrentDate() != Conference::getById( aConferenceId ).start()
- ){
- searchAgainButton->show();
- dayNavigator->show();
- treeView->show();
- header->hide();
- }
- else{
- treeView->hide();
- searchAgainButton->hide();
- dayNavigator->hide();
- header->show();
- }
+ static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
}
+