first working version of the search
[toast/confclerk.git] / src / gui / mainwindow.cpp
index 5f7a5e3..defed3c 100644 (file)
@@ -6,6 +6,7 @@
 #include <sqlengine.h>
 #include <schedulexmlparser.h>
 
+#include <track.h>
 #include <eventmodel.h>
 #include <delegate.h>
 
 #include "daynavigatorwidget.h"
 #include "mapwindow.h"
 
-MainWindow::MainWindow(QWidget *parent)
-    : QMainWindow(parent)
+const int confId = 1;
+
+MainWindow::MainWindow(int aEventId, QWidget *aParent)
+    : QMainWindow(aParent)
 {
     setupUi(this);
 
@@ -36,8 +39,12 @@ MainWindow::MainWindow(QWidget *parent)
     connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
     statusBar()->showMessage(tr("Ready"));
 
+    //update track map
+    Track::updateTrackMap();
+
     connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
-    connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
+    connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
+    connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
 
     // DAY EVENTS View
     dayTreeView->setHeaderHidden(true);
@@ -56,27 +63,38 @@ MainWindow::MainWindow(QWidget *parent)
     favTreeView->setItemDelegate(new Delegate(favTreeView));
 
     //ACTIVITIES View
-    actTreeView->setHeaderHidden(true);
-    actTreeView->setRootIsDecorated(false);
-    actTreeView->setIndentation(0);
-    actTreeView->setAnimated(true);
-    actTreeView->setModel(new EventModel());
-    actTreeView->setItemDelegate(new Delegate(actTreeView));
-
-    // event double clicked
-    connect(dayTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
-    connect(favTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
-    connect(actTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
+    trackTreeView->setHeaderHidden(true);
+    trackTreeView->setRootIsDecorated(false);
+    trackTreeView->setIndentation(0);
+    trackTreeView->setAnimated(true);
+    trackTreeView->setModel(new EventModel());
+    trackTreeView->setItemDelegate(new Delegate(trackTreeView));
+
+    // SEARCH EVENTS View
+       searchTreeView->setHeaderHidden(true);
+       searchTreeView->setRootIsDecorated(false);
+       searchTreeView->setIndentation(0);
+       searchTreeView->setAnimated(true);
+       searchTreeView->setModel(new EventModel());
+       searchTreeView->setItemDelegate(new Delegate(searchTreeView));
+       searchTreeView->setVisible(false);
+       searchDayNavigator->setVisible(false);
+    // event clicked
+    connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
+    connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
+    connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
+    connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
     // request for map to be displayed
     connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
     connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-
+    connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
+    connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
+    // event search button clicked
+    connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
 
     // TESTING: load some 'fav' data
     if(Conference::getAll().count()) // no conference(s) in the DB
     {
-        int confId = 1;
         static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
         favTreeView->reset();
     }
@@ -84,19 +102,32 @@ MainWindow::MainWindow(QWidget *parent)
     if(!Conference::getAll().count()) // no conference(s) in the DB
     {
         dayNavigator->hide(); // hide DayNavigatorWidget
-        activityDayNavigator->hide();
+        trackDayNavigator->hide();
     }
     else
     {
-        int confId = 1;
         QDate aStartDate = Conference::getById(confId).start();
         QDate aEndDate = Conference::getById(confId).end();
         dayNavigator->setDates(aStartDate, aEndDate);
-        activityDayNavigator->setDates(aStartDate, aEndDate);
+        trackDayNavigator->setDates(aStartDate, aEndDate);
+        favouriteDayNavigator->setDates(aStartDate, aEndDate);
+        searchDayNavigator->setDates(aStartDate, aEndDate);
     }
 
     connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
 
+    // open dialog for given Event ID
+    // this is used in case Alarm Dialog request application to start
+    if(aEventId)
+    {
+        try
+        {
+            EventDialog dialog(aEventId,this);
+            dialog.exec();
+        }
+        catch(OrmNoObjectException*) {} // just start application
+        catch(...) {} // just start application
+    }
 }
 
 MainWindow::~MainWindow()
@@ -115,7 +146,7 @@ MainWindow::~MainWindow()
 
 void MainWindow::importSchedule()
 {
-    QFile file("../schedule.en.xml");
+    QFile file(":/schedule.en.xml");
     if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
     {
         qDebug() << "can't open " << file.fileName();
@@ -127,13 +158,14 @@ void MainWindow::importSchedule()
 
     if(Conference::getAll().count())
     {
-        int confId = 1;
         // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
         QDate aStartDate = Conference::getById(confId).start();
         QDate aEndDate = Conference::getById(confId).end();
         dayNavigator->setDates(aStartDate, aEndDate);
-        activityDayNavigator->setDates(aStartDate, aEndDate);
+        trackDayNavigator->setDates(aStartDate, aEndDate);
     }
+    //update track map
+    Track::updateTrackMap();
 }
 
 void MainWindow::showParsingProgress(int aStatus)
@@ -152,7 +184,6 @@ void MainWindow::aboutApp()
 
 void MainWindow::updateDayView(const QDate &aDate)
 {
-    int confId = 1;
     static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
     dayTreeView->reset();
     dayNavigator->show();
@@ -160,46 +191,57 @@ void MainWindow::updateDayView(const QDate &aDate)
 
 void MainWindow::updateTab(const int aIndex)
 {
-    int confId = 1;
     switch(aIndex)
     {
     case 0://index 0 of tabWidget: dayViewTab
         {
             static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
             dayTreeView->reset();
+            dayNavigator->show();
         }
         break;
     case 1: //index 1 of tabWidget: favouritesTab
         {
-                static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
-                favTreeView->reset();
+            static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
+            favTreeView->reset();
+            favouriteDayNavigator->show();
+        }
+        break;
+    case 2: //index 2 of tabWidget: trackTab
+        {
+            static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(Conference::getById(confId).start(), confId);
+            trackTreeView->reset();
+            trackDayNavigator->show();
         }
         break;
     default:
         {
-            //TODO: update of activitiesTab needed?
+
         }
     };
-
-    dayNavigator->show();
 }
 
+void MainWindow::updateTracksView(const QDate &aDate)
+{
+    static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, confId);
+    trackTreeView->reset();
+    trackDayNavigator->show();
+}
 
-void MainWindow::updateActivitiesDayView(const QDate &aDate)
+void MainWindow::updateFavouritesView(const QDate &aDate)
 {
-    int confId = 1;
-    static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId);
-    actTreeView->reset();
-    activityDayNavigator->show();
+    static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
+    favTreeView->reset();
+    favouriteDayNavigator->show();
 }
 
-void MainWindow::itemDoubleClicked(const QModelIndex &aIndex)
+void MainWindow::itemClicked(const QModelIndex &aIndex)
 {
     // have to handle only events, not time-groups
     if(!aIndex.parent().isValid()) // time-group
         return;
 
-    EventDialog dialog(aIndex,this);
+    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
     dialog.exec();
 }
 
@@ -224,3 +266,20 @@ void MainWindow::displayMap(const QModelIndex &aIndex)
     window.exec();
 }
 
+void MainWindow::searchClicked()
+{
+    QList<QString> columns;
+
+    if( searchTitle->isChecked() )
+        columns.append( "title" );
+    if( searchAbstract->isChecked() )
+        columns.append( "abstract" );
+
+    searchTreeView->reset();
+    if( mSqlEngine->searchEvent( confId, columns, searchEdit->text() ) > 0 ){
+        static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(Conference::getById(confId).start(),confId);
+        searchDayNavigator->show();
+        searchTreeView->show();
+    }
+}
+