]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/gui/searchtabcontainer.cpp
Removed commented out reference to removed files.
[toast/confclerk.git] / src / gui / searchtabcontainer.cpp
index b0938a6a81544282b72fd007c39b937ad6cd72d8..0f4aac8475cad9e61651c997608c503377fabd39 100644 (file)
@@ -1,7 +1,26 @@
+/*
+ * Copyright (C) 2010 Ixonos Plc.
+ * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
+ *
+ * This file is part of ConfClerk.
+ *
+ * ConfClerk 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.
+ *
+ * ConfClerk 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
+ * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
 #include "searchtabcontainer.h"
 #include "searchhead.h"
-
+#include <QMessageBox>
 
 SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent )
 {
@@ -14,39 +33,31 @@ SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent
     sizePolicy.setHeightForWidth(header->sizePolicy().hasHeightForWidth());
     header->setSizePolicy(sizePolicy);
     header->setMinimumSize(QSize(10, 10));
-
     verticalLayout->insertWidget(0,header);
+    connect(header, SIGNAL(searchClicked()), SLOT(searchButtonClicked()));
+    showSearchDialog();
+}
 
-    header->show();
-
-    searchAgainButton = new QToolButton(this);
-    searchAgainButton->setObjectName(QString::fromUtf8("button"));
-    QIcon icon;
-    icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/search.png")), QIcon::Normal, QIcon::Off);
-    searchAgainButton->setIcon(icon);
-    QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum);
-    sizePolicy1.setHorizontalStretch(0);
-    sizePolicy1.setVerticalStretch(0);
-    sizePolicy1.setHeightForWidth(searchAgainButton->sizePolicy().hasHeightForWidth());
-    searchAgainButton->setSizePolicy(sizePolicy1);
 
-    verticalLayout_2->insertWidget(0,searchAgainButton);
+bool SearchTabContainer::searchDialogIsVisible() const {
+    return header->isVisible();
+}
 
-    searchAgainButton->hide();
-    treeView->hide();
 
-    connect( header, SIGNAL(searchClicked()), SLOT(searchButtonClicked()));
-    connect( searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
+int SearchTabContainer::searchResultCount(const QDate& date) const {
+    int confId = Conference::activeConference();
+    if (confId == -1) return 0;
+    return Event::getSearchResultByDate(date, confId, "start, duration").count();
 }
 
-SearchTabContainer::~SearchTabContainer()
-{
+
+void SearchTabContainer::showSearchDialog(bool show) {
+    header->setVisible(show);
+    treeView->setVisible(!show);
 }
 
-void SearchTabContainer::searchButtonClicked()
-{
-    qDebug() << "SearchTab::searchButtonClicked()";
 
+void SearchTabContainer::searchButtonClicked() {
     QHash<QString,QString> columns;
 
     SearchHead *searchHeader = static_cast<SearchHead*>(header);
@@ -61,43 +72,37 @@ void SearchTabContainer::searchButtonClicked()
     if( searchHeader->searchRoom->isChecked() )
         columns["ROOM"] = "name";
 
-    QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
-    qDebug() << "\nKeyword to search: " << keyword;
+    QString keyword = searchHeader->searchEdit->text();
 
     int confId = Conference::activeConference();
+    if (confId == -1) return;
+    Conference conf = Conference::getById(confId);
+
     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;
+    for (QDate d = conf.start(); d <= conf.end(); d = d.addDays(1))
+        nrofFounds += Event::getSearchResultByDate(d, confId, "start, duration").count();
 
-void SearchTabContainer::searchAgainClicked()
-{
-    qDebug() << "SearchTab::searchAgainClicked()";
-    header->show();
-    searchAgainButton->hide();
-    dayNavigator->hide();
-    treeView->hide();
+    if (!nrofFounds) {
+        treeView->hide();
+        header->show();
+        QMessageBox::information(
+                this,
+                QString("Keyword '%1' not found!").arg(keyword),
+                QString("No events containing '%1' found!").arg(keyword),
+                QMessageBox::Ok);
+    } else {
+        treeView->show();
+        header->hide();
+
+        emit searchResultChanged();
+    }
 }
 
+
 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 );
 }
+