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;
QCoreApplication::setOrganizationName("Toastfreeware");
QCoreApplication::setApplicationName("ConfClerk");
QCoreApplication::setApplicationVersion(VERSION);
-
- QWidget *window;
- window = new MainWindow;
+ QWidget* window = new MainWindow;
#ifdef MAEMO
// Alarm Dbus
{
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();
#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
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 "));
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);
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
void EventDialog::alarmClicked()
{
- Event event = Event::getById(mEventId,Conference::activeConference());
+ Event event = Event::getById(mEventId, mConferenceId);
if(event.hasAlarm())
{
{
Q_OBJECT
public:
- EventDialog(const int &aEventId, QWidget *aParent = NULL);
+ EventDialog(int conferencdId, int eventId, QWidget *parent = 0);
~EventDialog() {}
private slots:
void favouriteClicked();
signals:
void eventChanged(int aEventId, bool favouriteChanged); // emited when user changes some event details, eg. sets it Favourite
private:
+ int mConferenceId;
int mEventId;
};
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
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(),
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)));
}
}
-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
{
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:
void removeConference(int);
void changeConferenceUrl(int, const QString&);
- void useConference(int id);
+ void useConference(int conferenceId);
void unsetConference();
void showError(const QString& message);
if(!aIndex.parent().isValid()) // time-group
return;
- EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
+ EventDialog dialog(Conference::activeConference(), static_cast<Event*>(aIndex.internalPointer())->id(),this);
#ifdef N810
dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
#endif
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();
}
public:
static Conference getById(int id);
static QList<Conference> 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(); }