From 8bd618cfc135d0dccd0617dad4a4d12b5b1df463 Mon Sep 17 00:00:00 2001 From: Philipp Spitzer Date: Wed, 17 Oct 2012 18:49:16 +0000 Subject: [PATCH] We added the conferenceId to some alarm related methods (ticket #41). --- src/alarm/alarm.cpp | 2 +- src/app/main.cpp | 19 +++++++++---------- src/gui/eventdialog.cpp | 15 ++++++--------- src/gui/eventdialog.h | 3 ++- src/gui/mainwindow.cpp | 36 +++++++++--------------------------- src/gui/mainwindow.h | 7 ++----- src/gui/tabcontainer.cpp | 2 +- src/mvc/conference.cpp | 23 ++++------------------- src/mvc/conference.h | 5 ++++- 9 files changed, 38 insertions(+), 74 deletions(-) diff --git a/src/alarm/alarm.cpp b/src/alarm/alarm.cpp index a5f051b..5390ddd 100644 --- a/src/alarm/alarm.cpp +++ b/src/alarm/alarm.cpp @@ -57,7 +57,7 @@ int Alarm::addAlarm(int conferenceId, int eventId, QString eventTitle, const QDa alarmAction = alarm_event_add_actions(alarmEvent, 1); alarm_action_set_label(alarmAction, "ConfClerk"); - QString command = QFileInfo(*qApp->argv()).absoluteFilePath() + QString(" %1").arg(QString::number(eventId)); + QString command = QFileInfo(*qApp->argv()).absoluteFilePath() + QString(" %1 %2").arg(conferenceId, eventId); qDebug() << "Setting alarm: " << command; alarm_action_set_exec_command(alarmAction, command.toLocal8Bit().data()); alarmAction->flags |= ALARM_ACTION_TYPE_EXEC; diff --git a/src/app/main.cpp b/src/app/main.cpp index 29f36fb..cc749b6 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -44,10 +44,8 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationName("Toastfreeware"); QCoreApplication::setApplicationName("ConfClerk"); QCoreApplication::setApplicationVersion(VERSION); - - QWidget *window; - window = new MainWindow; + QWidget* window = new MainWindow; #ifdef MAEMO // Alarm Dbus @@ -59,25 +57,26 @@ int main(int argc, char *argv[]) { if( connection.registerService("at.priv.toastfreeware.confclerk") == false) { - if(argc>1) + if(argc==3) { QDBusInterface *interface = new QDBusInterface("at.priv.toastfreeware.confclerk", "/ConfClerk", "at.priv.toastfreeware.confclerk.AlarmInterface", connection); - interface->call("Alarm",atoi(argv[1])); + interface->call("Alarm",atoi(argv[2])); return 0; } } } +#endif - if(argc > 1) - { - EventDialog dialog(atoi(argv[1]), window); + // If we were started with the parameters confernceid and eventid, show the corresponding event (alarm) + if (argc == 3) { + QString conferenceIdStr = argv[1]; + QString eventIdStr = argv[2]; + EventDialog dialog(conferenceIdStr.toInt(), eventIdStr.toInt(), window); dialog.exec(); } -#endif - window->show(); return a.exec(); diff --git a/src/gui/eventdialog.cpp b/src/gui/eventdialog.cpp index ff3cecc..fcd66ec 100644 --- a/src/gui/eventdialog.cpp +++ b/src/gui/eventdialog.cpp @@ -26,10 +26,7 @@ #include "alarm.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 @@ -38,7 +35,7 @@ EventDialog::EventDialog(const int &aEventId, QWidget *aParent) alarmButton->hide(); #endif - Event event = Event::getById(mEventId,Conference::activeConference()); + Event event = Event::getById(mEventId, mConferenceId); title->setText(event.title()); persons->setText(event.persons().join(" and ")); @@ -65,9 +62,9 @@ EventDialog::EventDialog(const int &aEventId, QWidget *aParent) void EventDialog::favouriteClicked() { - Event event = Event::getById(mEventId,Conference::activeConference()); + Event event = Event::getById(mEventId, mConferenceId); - QList conflicts = Event::conflictEvents(event.id(),Conference::activeConference()); + QList conflicts = Event::conflictEvents(event.id(), mConferenceId); if(event.isFavourite()) { event.setFavourite(false); @@ -83,7 +80,7 @@ void EventDialog::favouriteClicked() 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 'eventChanged' signal on all events in conflict @@ -97,7 +94,7 @@ void EventDialog::favouriteClicked() void EventDialog::alarmClicked() { - Event event = Event::getById(mEventId,Conference::activeConference()); + Event event = Event::getById(mEventId, mConferenceId); if(event.hasAlarm()) { diff --git a/src/gui/eventdialog.h b/src/gui/eventdialog.h index cd7f1ba..54cda47 100644 --- a/src/gui/eventdialog.h +++ b/src/gui/eventdialog.h @@ -28,7 +28,7 @@ class EventDialog : public QDialog, Ui::EventDialog { Q_OBJECT public: - EventDialog(const int &aEventId, QWidget *aParent = NULL); + EventDialog(int conferencdId, int eventId, QWidget *parent = 0); ~EventDialog() {} private slots: void favouriteClicked(); @@ -36,6 +36,7 @@ private slots: signals: void eventChanged(int aEventId, bool favouriteChanged); // emited when user changes some event details, eg. sets it Favourite private: + int mConferenceId; int mEventId; }; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index a0b7cec..3bd1655 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -50,7 +50,7 @@ const QString PROXY_USERNAME; const QString PROXY_PASSWD; -MainWindow::MainWindow(int aEventId, QWidget *aParent): QMainWindow(aParent) { +MainWindow::MainWindow(QWidget* parent): QMainWindow(parent) { setupUi(this); // Open database @@ -75,12 +75,6 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent): QMainWindow(aParent) { if(!AppSettings::contains("proxyIsDirectConnection")) AppSettings::setDirectConnection(true); - /* - if(AppSettings::isDirectConnection()) - { - qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort(); - } - */ QNetworkProxy proxy( AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy, AppSettings::proxyAddress(), @@ -116,21 +110,7 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent): QMainWindow(aParent) { clearTabs(); } - // 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 - } - connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), SLOT(networkQueryFinished(QNetworkReply*))); - connect(mXmlParser, SIGNAL(parsingScheduleBegin()), conferenceModel, SLOT(newConferenceBegin())); connect(mXmlParser, SIGNAL(parsingScheduleEnd(int)), conferenceModel, SLOT(newConferenceEnd(int))); } @@ -226,20 +206,22 @@ void MainWindow::onSearchResultChanged() { } -void MainWindow::useConference(int id) +void MainWindow::useConference(int conferenceId) { - if (id == -1) // in case no conference is active + if (conferenceId == -1) // in case no conference is active { unsetConference(); return; } try { - Conference::getById(Conference::activeConference()).update("active",0); - Conference new_active = Conference::getById(id); - new_active.update("active",1); + int oldActiveConferenceId = Conference::activeConference(); + bool switchActiveConference = conferenceId != oldActiveConferenceId; + if (switchActiveConference) Conference::getById(oldActiveConferenceId).update("active", 0); + Conference activeConference = Conference::getById(conferenceId); + if (switchActiveConference) activeConference.update("active",1); // looks like it does not work at n900 - setWindowTitle(new_active.title()); + setWindowTitle(activeConference.title()); // optimization. // dont run initTabs() here diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index a063075..674b4a7 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -34,10 +34,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow { Q_OBJECT public: - // aEventId is used to inform widget to automatically open - // Event dialog for given Event ID - MainWindow(int aEventId = 0, QWidget *aParent = NULL); - ~MainWindow() {} + MainWindow(QWidget *parent = 0); signals: void conferenceRemoved(); private slots: @@ -59,7 +56,7 @@ private slots: void removeConference(int); void changeConferenceUrl(int, const QString&); - void useConference(int id); + void useConference(int conferenceId); void unsetConference(); void showError(const QString& message); diff --git a/src/gui/tabcontainer.cpp b/src/gui/tabcontainer.cpp index a6be863..a0e5090 100644 --- a/src/gui/tabcontainer.cpp +++ b/src/gui/tabcontainer.cpp @@ -65,7 +65,7 @@ void TabContainer::itemClicked(const QModelIndex &aIndex) if(!aIndex.parent().isValid()) // time-group return; - EventDialog dialog(static_cast(aIndex.internalPointer())->id(),this); + EventDialog dialog(Conference::activeConference(), static_cast(aIndex.internalPointer())->id(),this); #ifdef N810 dialog.setFixedWidth(static_cast(parent())->width()); #endif diff --git a/src/mvc/conference.cpp b/src/mvc/conference.cpp index 655e5f2..3ae8914 100644 --- a/src/mvc/conference.cpp +++ b/src/mvc/conference.cpp @@ -51,25 +51,10 @@ QList Conference::getAll() return load(query); } -int Conference::activeConference() -{ - { - QSqlQuery query("SELECT id FROM conference WHERE active = 1"); - query.exec(); - - // TODO: change it so that it will select somw existing ID - - if (query.next()) { - return query.record().value("id").toInt(); - } - } - - QSqlQuery query2("SELECT id FROM conference ORDER BY id"); - if (query2.next()) { - return query2.record().value("id").toInt(); - } - - return -1; +int Conference::activeConference() { + QSqlQuery query("SELECT id FROM conference ORDER BY active DESC, id LIMIT 1"); + if (!query.exec() || !query.first()) return -1; + return query.record().value("id").toInt(); } diff --git a/src/mvc/conference.h b/src/mvc/conference.h index 1b3157f..4c7984a 100644 --- a/src/mvc/conference.h +++ b/src/mvc/conference.h @@ -35,7 +35,10 @@ public: public: static Conference getById(int id); static QList getAll(); - static int activeConference(); ///< returns -1 if no conference is active + + /// Returns the active conference. If no active conference can be found, it returns the conference with the lowest id. + /// If no conference exists or database errors occur, it returns -1. + static int activeConference(); public: int id() const { return value("id").toInt(); } -- 2.39.5