2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of ConfClerk.
6 * ConfClerk is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
11 * ConfClerk is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
20 #include "searchtabcontainer.h"
21 #include "searchhead.h"
22 #include <QMessageBox>
24 SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent )
26 header = new SearchHead(this);
27 header->setObjectName(QString::fromUtf8("header"));
28 QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
29 sizePolicy.setHorizontalStretch(0);
30 sizePolicy.setVerticalStretch(0);
31 //sizePolicy.setHeightForWidth(TabContainer::sizePolicy().hasHeightForWidth());
32 sizePolicy.setHeightForWidth(header->sizePolicy().hasHeightForWidth());
33 header->setSizePolicy(sizePolicy);
34 header->setMinimumSize(QSize(10, 10));
36 verticalLayout->insertWidget(0,header);
40 searchAgainButton = new QToolButton(this);
41 searchAgainButton->setObjectName(QString::fromUtf8("button"));
43 icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/search.png")), QIcon::Normal, QIcon::Off);
44 searchAgainButton->setIcon(icon);
45 QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum);
46 sizePolicy1.setHorizontalStretch(0);
47 sizePolicy1.setVerticalStretch(0);
48 sizePolicy1.setHeightForWidth(searchAgainButton->sizePolicy().hasHeightForWidth());
49 searchAgainButton->setSizePolicy(sizePolicy1);
51 verticalLayout_2->insertWidget(0,searchAgainButton);
53 searchAgainButton->hide();
55 // do not show 'search' header if there are no conferences in the DB
56 if(Conference::getAll().count()==0)
61 connect( header, SIGNAL(searchClicked()), SLOT(searchButtonClicked()));
62 connect( searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
65 SearchTabContainer::~SearchTabContainer()
69 void SearchTabContainer::searchButtonClicked()
71 QHash<QString,QString> columns;
73 SearchHead *searchHeader = static_cast<SearchHead*>(header);
74 if( searchHeader->searchTitle->isChecked() )
75 columns.insertMulti("EVENT", "title");
76 if( searchHeader->searchAbstract->isChecked() )
77 columns.insertMulti("EVENT", "abstract");
78 if( searchHeader->searchTag->isChecked() )
79 columns.insertMulti("EVENT", "tag");
80 if( searchHeader->searchSpeaker->isChecked() )
81 columns["PERSON"] = "name";
82 if( searchHeader->searchRoom->isChecked() )
83 columns["ROOM"] = "name";
85 QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
86 //qDebug() << "\nKeyword to search: " << keyword;
88 int confId = Conference::activeConference();
89 SqlEngine::searchEvent( confId, columns, keyword );
91 QDate startDate = Conference::getById(confId).start();
92 QDate endDate = Conference::getById(confId).end();
95 QDate firstDateWithFounds = endDate;
96 QDate lastDateWithFounds = startDate;
97 for(QDate d=startDate; d<=endDate; d=d.addDays(1))
100 int count = Event::getSearchResultByDate(d, confId, "start").count();
101 if(count && (firstDateWithFounds==endDate))
102 firstDateWithFounds=d;
104 lastDateWithFounds=d;
107 catch( OrmException &e ){
108 qDebug() << "Event::getSearchResultByDate failed: " << e.text();
111 qDebug() << "Event::getSearchResultByDate failed";
117 // TODO: display some message
119 searchAgainButton->hide();
120 dayNavigator->hide();
122 QMessageBox::information(
124 QString("Keyword '%1' not found!").arg(keyword),
125 QString("No events containing '%1' found!").arg(keyword),
130 searchAgainButton->show();
131 dayNavigator->show();
135 updateTreeView( firstDateWithFounds );
136 dayNavigator->setDates(firstDateWithFounds, lastDateWithFounds);
140 void SearchTabContainer::searchAgainClicked()
143 searchAgainButton->hide();
144 dayNavigator->hide();
148 void SearchTabContainer::loadEvents( const QDate &aDate, const int aConferenceId )
150 static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );