From: pavelpa Date: Wed, 27 Jan 2010 15:31:10 +0000 (+0000) Subject: removed appsettings X-Git-Tag: 0.5.0~173 X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/commitdiff_plain/0bb39f584c6cf15956ec3f92d1d39bd4fd4fd80a removed appsettings - created 'active' column in 'conference' table --- diff --git a/src/app/app.pro b/src/app/app.pro index bd1d96f..46edaa0 100644 --- a/src/app/app.pro +++ b/src/app/app.pro @@ -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 index 44341fc..0000000 --- a/src/app/appsettings.cpp +++ /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 index 70e8cb7..0000000 --- a/src/app/appsettings.h +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef APPSETTINGS_H -#define APPSETTINGS_H - -#include -#include - -class AppSettings -{ - private: - AppSettings(); - static QSettings mSettings; - - public: - static int confId(); // conference Id - static void setConfId(int aConfId); -}; - -#endif /* APPSETTINGS_H */ - diff --git a/src/gui/alarmdialog.cpp b/src/gui/alarmdialog.cpp index 3caeb3b..9dd3511 100644 --- a/src/gui/alarmdialog.cpp +++ b/src/gui/alarmdialog.cpp @@ -1,5 +1,5 @@ #include "alarmdialog.h" -#include +#include #include #include @@ -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"); } diff --git a/src/gui/eventdialog.cpp b/src/gui/eventdialog.cpp index 5f140ed..bf06f36 100644 --- a/src/gui/eventdialog.cpp +++ b/src/gui/eventdialog.cpp @@ -1,5 +1,5 @@ #include "eventdialog.h" -#include +#include #include @@ -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()) { diff --git a/src/gui/favtabcontainer.cpp b/src/gui/favtabcontainer.cpp index 4a8e98f..341dd9f 100644 --- a/src/gui/favtabcontainer.cpp +++ b/src/gui/favtabcontainer.cpp @@ -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(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() ); } + diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 0016b4b..485667a 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1,5 +1,4 @@ #include "mainwindow.h" -#include #include #include @@ -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 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 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); diff --git a/src/gui/searchtabcontainer.cpp b/src/gui/searchtabcontainer.cpp index 64d989f..b4c0be4 100644 --- a/src/gui/searchtabcontainer.cpp +++ b/src/gui/searchtabcontainer.cpp @@ -1,6 +1,4 @@ -#include - #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() diff --git a/src/gui/tabcontainer.cpp b/src/gui/tabcontainer.cpp index f2e3fff..c03b2e1 100644 --- a/src/gui/tabcontainer.cpp +++ b/src/gui/tabcontainer.cpp @@ -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); } - - diff --git a/src/gui/tabcontainer.h b/src/gui/tabcontainer.h index 8c682fe..4959ce4 100644 --- a/src/gui/tabcontainer.h +++ b/src/gui/tabcontainer.h @@ -4,7 +4,7 @@ #include #include "ui_tabcontainer.h" -#include +#include #include #include #include diff --git a/src/mvc/conference.cpp b/src/mvc/conference.cpp index c2d7d90..17c4a90 100644 --- a/src/mvc/conference.cpp +++ b/src/mvc/conference.cpp @@ -10,7 +10,8 @@ QSqlRecord const Conference::sColumns = Conference::toRecord(QList() << 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::getAll() return load(query); } +int Conference::activeConference() +{ + QSqlQuery query("SELECT id FROM conference WHERE active = 1"); + query.exec(); + + QList 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]; +} + diff --git a/src/mvc/conference.h b/src/mvc/conference.h index c6c8e01..deb9280 100644 --- a/src/mvc/conference.h +++ b/src/mvc/conference.h @@ -16,6 +16,7 @@ public: public: static Conference getById(int id); static QList 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 */ diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index 03b2ba4..c64c758 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -1,5 +1,4 @@ #include "eventmodel.h" -#include #include #include #include @@ -280,7 +279,7 @@ void EventModel::updateModel(int aEventId) for(int i=0; i #include -#include #include "sqlengine.h" #include #include @@ -94,13 +93,11 @@ void SqlEngine::addConferenceToDB(QHash &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, "