Imported Upstream version 0.6.0
[debian/confclerk.git] / src / gui / eventdialog.cpp
index 6fd700470f040fd3537f769db554d15b9ee46178..eb006ce55ce822d6c759ab67ff7663b56e25d677 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 Ixonos Plc.
- * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
+ * Copyright (C) 2011-2013 Philipp Spitzer, gregor herrmann, Stefan Stahl
  *
  * This file is part of ConfClerk.
  *
  * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "eventdialog.h"
-#include <conference.h>
+#include "conference.h"
 
 #include <QScrollBar>
 
 #ifdef MAEMO
-#include <alarm.h>
+#include "alarm.h"
+#include "appsettings.h"
 #endif
 
-EventDialog::EventDialog(const int &aEventId, QWidget *aParent)
-    : QDialog(aParent)
-    , mEventId(aEventId)
-{
+EventDialog::EventDialog(int conferenceId, int eventId, QWidget *parent): QDialog(parent), mConferenceId(conferenceId), mEventId(eventId) {
     setupUi(this);
 
 #ifdef MAEMO
     showFullScreen();
-#else
-    alarmButton->hide();
 #endif
 
-    Event event = Event::getById(mEventId,Conference::activeConference());
+    Event event = Event::getById(mEventId, mConferenceId);
+
+    QString info;
+    // title
+    info.append(QString("<h1>%1</h1>\n").arg(event.title()));
+
+    // persons
+    info += QString("<h2>%1</h2>\n").arg(tr("Persons"));
+    info += QString("<p>%1</p>\n").arg(event.persons().join(", "));
+
+    // abstract
+    info += QString("<h2>%1</h2>\n").arg(tr("Abstract"));
+    info += QString("<p>%1</p>\n").arg(event.abstract());
+
+    // description
+    info += QString("<h2>%1</h2>\n").arg(tr("Description"));
+    info += QString("<p>%1</p>\n").arg(event.description());
+
+    // links
+    info += QString("<h2>%1</h2>\n<ul>\n").arg(tr("Links"));
+    QMapIterator<QString, QString> i(event.links());
+    while (i.hasNext()) {
+        i.next();
+        QString url(i.value());
+        QString name(i.key());
+        if (url.isEmpty() || url == "http://") continue;
+        if (name.isEmpty()) name = url;
+        info += QString("<li><a href=\"%1\">%2</a></li>\n").arg(url, name);
+    }
+    info += QString("</ul>\n");
+    eventInfoTextBrowser->setHtml(info);
 
-    title->setText(event.title());
-    persons->setText(event.persons().join(" and "));
-    abstract->setText(event.abstract());
-    description->setText(event.description());
-    QStringList linksText = static_cast<QStringList>(event.links().values());
-    for (QStringList::iterator linkIterator = linksText.begin(); linkIterator != linksText.end(); ++linkIterator)
-        *linkIterator = QString("<a href=\"%1\">%1</a>").arg(*linkIterator);
-    links->setText(linksText.join("<br/>"));
+    // make sure colours are the same as usual
+    eventInfoTextBrowser->setPalette(qApp->palette());
+    // reduce font size, on maemo
+#ifdef MAEMO
+    QFont font = eventInfoTextBrowser->font();
+    font.setPointSizeF(font.pointSizeF()*0.8);
+    eventInfoTextBrowser->setFont(font);
+#endif
 
     connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
     connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
 
     if(event.isFavourite())
     {
-        favouriteButton->setIcon(QIcon(":/icons/emblem-new.png"));
+        favouriteButton->setIcon(QIcon(":/icons/favourite-on.png"));
     }
 
     if(event.hasAlarm())
     {
-        alarmButton->setIcon(QIcon(":/icons/appointment-soon.png"));
+        alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
     }
 }
 
 void EventDialog::favouriteClicked()
 {
-    Event event = Event::getById(mEventId,Conference::activeConference());
+    Event event = Event::getById(mEventId, mConferenceId);
 
-    QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
+    QList<Event> conflicts = Event::conflictEvents(event.id(), mConferenceId);
     if(event.isFavourite())
     {
         event.setFavourite(false);
-        favouriteButton->setIcon(QIcon(":/icons/emblem-new-off.png"));
+        favouriteButton->setIcon(QIcon(":/icons/favourite-off.png"));
     }
     else
     {
         event.setFavourite(true);
-        favouriteButton->setIcon(QIcon(":/icons/emblem-new.png"));
+        favouriteButton->setIcon(QIcon(":/icons/favourite-on.png"));
     }
     event.update("favourite");
 
     if(event.isFavourite())
     {
         // event has became 'favourite' and so 'conflicts' list may have changed
-        conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
+        conflicts = Event::conflictEvents(event.id(), mConferenceId);
     }
 
-    // have to emit 'eventHasChanged' signal on all events in conflict
+    // have to emit 'eventChanged' signal on all events in conflict
     for(int i=0; i<conflicts.count(); i++)
-        emit(eventHasChanged(conflicts[i].id()));
+        emit eventChanged(conflicts[i].id(), false);
 
     // since the Favourite icon has changed, update TreeViews accordingly
     // all TreeViews have to listen on this signal
-    emit(eventHasChanged(event.id(),true));
+    emit eventChanged(event.id(), true);
 }
 
 void EventDialog::alarmClicked()
 {
-    Event event = Event::getById(mEventId,Conference::activeConference());
+    Event event = Event::getById(mEventId, mConferenceId);
 
     if(event.hasAlarm())
     {
         event.setHasAlarm(false); // update DB
-        alarmButton->setIcon(QIcon(":/icons/appointment-soon-off.png"));
+        alarmButton->setIcon(QIcon(":/icons/alarm-off.png"));
 #ifdef MAEMO
-        // remove alarm from the 'alarmd' alrms list
+        // remove alarm from the 'alarmd' alarms list
         Alarm alarm;
-        alarm.deleteAlarm(event.id());
+        alarm.deleteAlarm(event.conferenceId(), event.id());
         // TODO: test if removing was successfull
 #endif /* MAEMO */
     }
     else
     {
         event.setHasAlarm(true);
-        alarmButton->setIcon(QIcon(":/icons/appointment-soon.png"));
+        alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
 #ifdef MAEMO
         // add alarm to the 'alarmd'
         Alarm alarm;
-        int cookie = alarm.addAlarm(event.id(),event.title(),QDateTime::currentDateTime().addSecs(10));
+        alarm.addAlarm(event.conferenceId(), event.id(), event.title(), event.start().addSecs(-AppSettings::preEventAlarmSec()));
 #endif /* MAEMO */
     }
     event.update("alarm");
     // since the Alarm icon has changed, update TreeView accordingly
     // all TreeViews have to listen on this signal
-    emit(eventHasChanged(event.id()));
+    emit eventChanged(event.id(), false);
 }