removed appsettings
authorpavelpa <pavelpa@localhost>
Wed, 27 Jan 2010 15:31:10 +0000 (15:31 +0000)
committerpavelpa <pavelpa@localhost>
Wed, 27 Jan 2010 15:31:10 +0000 (15:31 +0000)
 - created 'active' column in 'conference' table

14 files changed:
src/app/app.pro
src/app/appsettings.cpp [deleted file]
src/app/appsettings.h [deleted file]
src/gui/alarmdialog.cpp
src/gui/eventdialog.cpp
src/gui/favtabcontainer.cpp
src/gui/mainwindow.cpp
src/gui/searchtabcontainer.cpp
src/gui/tabcontainer.cpp
src/gui/tabcontainer.h
src/mvc/conference.cpp
src/mvc/conference.h
src/mvc/eventmodel.cpp
src/sql/sqlengine.cpp

index bd1d96f..46edaa0 100644 (file)
@@ -16,10 +16,7 @@ maemo {
     TARGETDEPS += $$DESTDIR/libqalarm.a
 }
 
-SOURCES += main.cpp \
-           appsettings.cpp
-
-HEADERS += appsettings.h
+SOURCES += main.cpp
 
 RESOURCES += ../icons.qrc \
              ../maps.qrc
diff --git a/src/app/appsettings.cpp b/src/app/appsettings.cpp
deleted file mode 100644 (file)
index 44341fc..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "appsettings.h"
-
-const QString CONF_ID_SETTING ("confId"); 
-
-QSettings AppSettings::mSettings("Ixonos", "FOSDEM");
-
-AppSettings::AppSettings()
-{ }
-
-int AppSettings::confId()
-{
-    return mSettings.value(CONF_ID_SETTING).toInt();
-}
-
-void AppSettings::setConfId(int aConfId)
-{
-    mSettings.setValue(CONF_ID_SETTING, aConfId);
-}
-
diff --git a/src/app/appsettings.h b/src/app/appsettings.h
deleted file mode 100644 (file)
index 70e8cb7..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-
-#ifndef APPSETTINGS_H
-#define APPSETTINGS_H
-
-#include <QString>
-#include <QSettings>
-
-class AppSettings
-{
-    private:
-        AppSettings();
-        static QSettings mSettings;
-
-    public:
-        static int confId(); // conference Id
-        static void setConfId(int aConfId);
-};
-
-#endif /* APPSETTINGS_H */
-
index 3caeb3b..9dd3511 100644 (file)
@@ -1,5 +1,5 @@
 #include "alarmdialog.h"
-#include <appsettings.h>
+#include <conference.h>
 
 #include <QApplication>
 #include <alarm.h>
@@ -46,7 +46,7 @@ AlarmDialog::AlarmDialog(int argc, char *argv[], QWidget *aParent)
     QString roomStr;
     try
     {
-        Event event = Event::getById(mEventId,AppSettings::confId());
+        Event event = Event::getById(mEventId,Conference::activeConference());
         titleStr = "Event alarm";
         messageStr = event.title();
         timeStr = event.start().toString("hh:mm") + "-" + event.start().addSecs(event.duration()).toString("hh:mm");
@@ -88,7 +88,7 @@ void AlarmDialog::closeDialog()
     // before closing the dialog, it is necessary to remove alarm flag from the DB
     try
     {
-        Event event = Event::getById(mEventId,AppSettings::confId());
+        Event event = Event::getById(mEventId,Conference::activeConference());
         event.setHasAlarm(false);
         event.update("alarm");
     }
index 5f140ed..bf06f36 100644 (file)
@@ -1,5 +1,5 @@
 #include "eventdialog.h"
-#include <appsettings.h>
+#include <conference.h>
 
 #include <QScrollBar>
 
@@ -17,7 +17,7 @@ EventDialog::EventDialog(const int &aEventId, QWidget *aParent)
     showFullScreen();
 #endif
 
-    Event event = Event::getById(mEventId,AppSettings::confId());
+    Event event = Event::getById(mEventId,Conference::activeConference());
 
     title->setText(event.title());
     persons->setText(event.persons().join(" and "));
@@ -41,7 +41,7 @@ EventDialog::EventDialog(const int &aEventId, QWidget *aParent)
 
 void EventDialog::favouriteClicked()
 {
-    Event event = Event::getById(mEventId,AppSettings::confId());
+    Event event = Event::getById(mEventId,Conference::activeConference());
 
     if(event.isFavourite())
     {
@@ -64,7 +64,7 @@ void EventDialog::favouriteClicked()
 
 void EventDialog::alarmClicked()
 {
-    Event event = Event::getById(mEventId,AppSettings::confId());
+    Event event = Event::getById(mEventId,Conference::activeConference());
 
     if(event.hasAlarm())
     {
index 4a8e98f..341dd9f 100644 (file)
@@ -1,9 +1,3 @@
-/*
- * favtabcontainer.cpp
- *
- *  Created on: Jan 27, 2010
- *      Author: maemo
- */
 
 #include "favtabcontainer.h"
 
@@ -21,8 +15,10 @@ void FavTabContainer::updateTreeViewModel(int aEventId)
     // requires special handling
     // we need to reload favourites, because some favourite could be deleted
     //static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
-    QDate aStartDate = Conference::getById(AppSettings::confId()).start();
-    QDate aEndDate = Conference::getById(AppSettings::confId()).end();
-    dayNavigator->setDates(aStartDate, aEndDate);
-    updateTreeView( Conference::getById(AppSettings::confId()).start() );
+    int confId = Conference::activeConference();
+    QDate startDate = Conference::getById(confId).start();
+    QDate endDate = Conference::getById(confId).end();
+    dayNavigator->setDates(startDate, endDate);
+    updateTreeView( Conference::getById(confId).start() );
 }
+
index 0016b4b..485667a 100644 (file)
@@ -1,5 +1,4 @@
 #include "mainwindow.h"
-#include <appsettings.h>
 
 #include <QTreeView>
 #include <QFile>
@@ -27,19 +26,11 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
 {
     setupUi(this);
 
-    // Sanity check for existence of any Conference in the DB
-    // it AppSettings::confId() is 0, but there are any Conference(s) in the DB
-    // set the confId in the AppSettings for the ID of the first conference in the DB
+    int confId = Conference::activeConference();
+
     QList<Conference> confs = Conference::getAll();
-    if(!confs.count()) // no conference(s) in the DB
-    {
-        AppSettings::setConfId(0); // no conference in the DB
-    }
-    else
+    if(confs.count())
     {
-        if(AppSettings::confId() == 0)
-            AppSettings::setConfId(confs[0].id());
-
         setWindowTitle(confs[0].title());
     }
 
@@ -61,8 +52,8 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
 
     if(Conference::getAll().count()) // no conference(s) in the DB
     {
-        QDate startDate = Conference::getById(AppSettings::confId()).start();
-        QDate endDate = Conference::getById(AppSettings::confId()).end();
+        QDate startDate = Conference::getById(confId).start();
+        QDate endDate = Conference::getById(confId).end();
         //
         dayTabContainer->setDates(startDate, endDate);
         tracksTabContainer->setDates(startDate, endDate);
@@ -70,13 +61,13 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
         favsTabContainer->setDates(startDate, endDate);
         searchTabContainer->setDates(startDate, endDate);
         //
-        conferenceTitle->setText(Conference::getById(AppSettings::confId()).title());
-        conferenceSubtitle->setText(Conference::getById(AppSettings::confId()).subtitle());
-        conferenceWhere->setText(Conference::getById(AppSettings::confId()).city() + ", " + Conference::getById(AppSettings::confId()).venue());
+        conferenceTitle->setText(Conference::getById(confId).title());
+        conferenceSubtitle->setText(Conference::getById(confId).subtitle());
+        conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
         conferenceWhen->setText(
-                Conference::getById(AppSettings::confId()).start().toString("dd-MM-yyyy")
+                Conference::getById(confId).start().toString("dd-MM-yyyy")
                 + ", " +
-                Conference::getById(AppSettings::confId()).end().toString("dd-MM-yyyy"));
+                Conference::getById(confId).end().toString("dd-MM-yyyy"));
     }
 
     // open dialog for given Event ID
@@ -98,18 +89,11 @@ void MainWindow::scheduleImported(int aConfId)
     Q_UNUSED(aConfId);
 
     QList<Conference> confs = Conference::getAll();
-    if(!confs.count()) // no conference(s) in the DB
+    if(confs.count())
     {
-        AppSettings::setConfId(0); // no conference in the DB
-    }
-    else
-    {
-        if(AppSettings::confId() == 0)
-            AppSettings::setConfId(confs[0].id());
-
         // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
-        QDate startDate = Conference::getById(AppSettings::confId()).start();
-        QDate endDate = Conference::getById(AppSettings::confId()).end();
+        QDate startDate = Conference::getById(Conference::activeConference()).start();
+        QDate endDate = Conference::getById(Conference::activeConference()).end();
         dayTabContainer->setDates(startDate, endDate);
         tracksTabContainer->setDates(startDate, endDate);
         roomsTabContainer->setDates(startDate, endDate);
index 64d989f..b4c0be4 100644 (file)
@@ -1,6 +1,4 @@
 
-#include <appsettings.h>
-
 #include "searchtabcontainer.h"
 #include "searchhead.h"
 
@@ -64,12 +62,14 @@ void SearchTabContainer::searchButtonClicked()
 
     QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
     qDebug() << "\nKeyword to search: " << keyword;
-    SqlEngine::searchEvent( AppSettings::confId(), columns, keyword );
 
-    QDate startDate = Conference::getById(AppSettings::confId()).start();
-    QDate endDate = Conference::getById(AppSettings::confId()).end();
+    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(AppSettings::confId()).start() );
+    updateTreeView( Conference::getById(confId).start() );
 }
 
 void SearchTabContainer::searchAgainClicked()
index f2e3fff..c03b2e1 100644 (file)
@@ -35,8 +35,8 @@ TabContainer::TabContainer(QWidget *aParent)
     }
     else
     {
-        QDate aStartDate = Conference::getById(AppSettings::confId()).start();
-        QDate aEndDate = Conference::getById(AppSettings::confId()).end();
+        QDate aStartDate = Conference::getById(Conference::activeConference()).start();
+        QDate aEndDate = Conference::getById(Conference::activeConference()).end();
         dayNavigator->setDates(aStartDate, aEndDate);
     }
 }
@@ -44,7 +44,7 @@ TabContainer::TabContainer(QWidget *aParent)
 void TabContainer::updateTreeView(const QDate &aDate)
 {
     dayNavigator->show();
-    loadEvents( aDate, AppSettings::confId() );
+    loadEvents( aDate, Conference::activeConference() );
     treeView->reset();
 }
 
@@ -101,5 +101,3 @@ void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
     dayNavigator->setDates(aStart, aEnd);
 }
 
-
-
index 8c682fe..4959ce4 100644 (file)
@@ -4,7 +4,7 @@
 #include <QWidget>
 #include "ui_tabcontainer.h"
 
-#include <appsettings.h>
+#include <conference.h>
 #include <sqlengine.h>
 #include <conference.h>
 #include <eventmodel.h>
index c2d7d90..17c4a90 100644 (file)
@@ -10,7 +10,8 @@ QSqlRecord const Conference::sColumns = Conference::toRecord(QList<QSqlField>()
     << QSqlField("end", QVariant::DateTime)
     << QSqlField("days", QVariant::Int)
     << QSqlField("day_change", QVariant::Int)
-    << QSqlField("timeslot_duration", QVariant::Int));
+    << QSqlField("timeslot_duration", QVariant::Int)
+    << QSqlField("active", QVariant::Bool));
 
 QString const Conference::sTableName = QString("conference");
 
@@ -29,3 +30,18 @@ QList<Conference> Conference::getAll()
     return load(query);
 }
 
+int Conference::activeConference()
+{
+    QSqlQuery query("SELECT id FROM conference WHERE active = 1");
+    query.exec();
+
+    QList<int> activeConfs;
+    while(query.next())
+        activeConfs.append(query.record().value("id").toInt());
+
+    if(activeConfs.count()==0) // no active DB
+        return 1;
+    else // even if there are more active confs, the first from the list is confidered active
+        return activeConfs[0];
+}
+
index c6c8e01..deb9280 100644 (file)
@@ -16,6 +16,7 @@ public:
 public:
     static Conference getById(int id);
     static QList<Conference> getAll();
+    static int activeConference();
 
 public:
     int id() const { return value("id").toInt(); }
@@ -28,19 +29,19 @@ public:
     int days() const { return value("days").toInt(); }
     int dayChange() const { return value("day_change").toInt(); } // in seconds from 00:00
     int timeslotDuration() const { return value("timeslot_duration").toInt(); } // in seconds
+    bool isActive() const { return value("active").toBool(); }
 
     void setId(int id) { setValue("id", id); }
     void setTitle(const QString& title) { setValue("title", title); }
     void setSubtitle(const QString& subtitle) { setValue("subtitle", subtitle); }
     void setVenue(const QString& venue) { setValue("venue", venue); }
     void setCity(const QString& city) { setValue("city", city); }
-    //void setStart(const QDate& start) { setValue("start", QDateTime(start)); }
     void setStart(const QDate& start) { setValue("start", start); }
-    //void setEnd(const QDate& end) { setValue("end", QDateTime(end)); }
     void setEnd(const QDate& end) { setValue("end", end); }
     void setDays(int days) { setValue("days", days); }
     void setDayChange(int dayChange) { setValue("day_change", dayChange); }
     void setTimeslotDuration(int timeslotDuration) { setValue("timeslot_duration", timeslotDuration); }
+    void setActive(bool active) { setValue("active", (int)((active))); }
 };
 
 #endif /* CONFERENCE_H */
index 03b2ba4..c64c758 100644 (file)
@@ -1,5 +1,4 @@
 #include "eventmodel.h"
-#include <appsettings.h>
 #include <conference.h>
 #include <track.h>
 #include <room.h>
@@ -280,7 +279,7 @@ void EventModel::updateModel(int aEventId)
     for(int i=0; i<mEvents.count(); i++)
     {
         if(mEvents[i].id() == aEventId)
-            mEvents[i] = Event::getById(aEventId,AppSettings::confId());
+            mEvents[i] = Event::getById(aEventId,Conference::activeConference());
     }
 
     // find the ModelIndex for given aEventId
index 14c68fc..ea56d7a 100644 (file)
@@ -6,7 +6,6 @@
 #include <QDateTime>
 
 #include <QDir>
-#include <appsettings.h>
 #include "sqlengine.h"
 #include <track.h>
 #include <conference.h>
@@ -94,13 +93,11 @@ void SqlEngine::addConferenceToDB(QHash<QString,QString> &aConference)
                              .arg(aConference["days"]) \
                              .arg(-QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0))) \
                              .arg(-QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
+                             values.append(QString(", '%1'").arg(confsList.count()>0?"0":"1"));
 
-            QString query = QString("INSERT INTO CONFERENCE (title,subtitle,venue,city,start,end,days,day_change,timeslot_duration) VALUES (%1)").arg(values);
+            QString query = QString("INSERT INTO CONFERENCE (title,subtitle,venue,city,start,end,days,day_change,timeslot_duration,active) VALUES (%1)").arg(values);
             QSqlQuery result (query, db);
             aConference["id"] = result.lastInsertId().toString(); // 'id' is assigned automatically
-
-            if(!AppSettings::confId()) // default conf Id isn't set yet => set it up
-                AppSettings::setConfId(confId);
         }
     }
 }
@@ -240,7 +237,8 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             "end INTEGER NOT NULL, "
             "days INTEGER, "
             "day_change INTEGER, "
-            "timeslot_duration INTEGER);");
+            "timeslot_duration INTEGER, "
+            "active INTEGER DEFAULT 0);");
 
         query.exec("CREATE TABLE TRACK ( "
             "id INTEGER  PRIMARY KEY AUTOINCREMENT  NOT NULL, "