X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fkitchenalertmainwindow.cpp;h=4fc1c18331720cf39e4a2bf94ca6e5689ae5ac53;hb=bf54bc695f809c9ee99a3be1eedee2a503936f3a;hp=257915521b8c10fe3b139fc73e2ddcf721bd0618;hpb=55e83dd6677893a7d2ed9de67c675fd9b45a68bc;p=kitchenalert diff --git a/src/kitchenalertmainwindow.cpp b/src/kitchenalertmainwindow.cpp index 2579155..4fc1c18 100644 --- a/src/kitchenalertmainwindow.cpp +++ b/src/kitchenalertmainwindow.cpp @@ -2,7 +2,7 @@ KitchenAlert - Copyright (C) 2010 Heli Hyvättinen + Copyright (C) 2010-2011 Heli Hyvättinen This file is part of KitchenAlert. @@ -42,6 +42,7 @@ #include #include #include +#include @@ -51,6 +52,8 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) : { ui->setupUi(this); + setWindowIcon(QIcon(":/kitchenalert.png")); + @@ -63,8 +66,16 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) : ui->ComingAlertsTableView->setModel(&model_); ui->ComingAlertsTableView->setSelectionMode(QAbstractItemView::SingleSelection); ui->ComingAlertsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); - ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); + ui->ComingAlertsTableView->horizontalHeader()->hide(); +// ui->ComingAlertsTableView->verticalHeader()->setVisible(true); + + ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed); + ui->ComingAlertsTableView->horizontalHeader()->resizeSection(0,535); + ui->ComingAlertsTableView->horizontalHeader()->resizeSection(1,140); + ui->ComingAlertsTableView->horizontalHeader()->resizeSection(2,100); + + ui->ComingAlertsTableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); //Buttons used to reacting an alarm are hidden by default @@ -77,7 +88,7 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) : connect(ui->DoneButton,SIGNAL(clicked()),this,SLOT(stop())); connect(ui->RestartButton,SIGNAL(clicked()),this,SLOT(restart())); connect(ui->SnoozeButton,SIGNAL(clicked()),this, SLOT(snooze())); - + connect(ui->RemoveButton,SIGNAL(clicked()),this,SLOT(remove())); // menu setup QAction * p_SelectSoundAction = new QAction(tr("Select alert sound"),this); @@ -123,19 +134,26 @@ void KitchenAlertMainWindow::newTimerSequence() Timer* timer1 = alltimers.at(0); // take first timer (currently the only one!) - timer1->start(); + connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex))); - model_.addTimers(alltimers); // give timers to the model + connect(this,SIGNAL(defaultSoundEnabled()),timer1,SLOT(enableDefaultSound())); + connect(this,SIGNAL(soundChanged(QString)),timer1,SLOT(changeAlertSound(QString))); + + + + model_.addTimers(alltimers); // give timers to the model, they are started automatically by default // ui->ComingAlertsTableView->resizeColumnsToContents(); //Disable buttons, as selection is cleared when view is refreshed to show the new timer + //But only if the timer has not already alerted and thus been selected - disableSelectionDependentButtons(); + if (!selectedRow().isValid()) + disableSelectionDependentButtons(); @@ -155,33 +173,39 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter) // The program is brought to front and activated when alerted - raise(); + activateWindow(); +// removing everything below does not solve the bug #6752! + + raise(); //this may be unnecessary + // The alerting timer is selected ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows ); - qDebug() << "Should be selected now"; + //Scrolls the view so that the alerting timer is visible + ui->ComingAlertsTableView->scrollTo(indexOfAlerter); - //Snooze button is enabled + // qDebug() << "Should be selected now"; - ui->SnoozeButton->setEnabled(true); + //Snooze button is enabled - //The alert sound is played - alertSound_.play(); + ui->SnoozeButton->setEnabled(true); +//qDebug ("Snooze on when alerting"); } -void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelection deselected) +void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelection) { ui->DoneButton->setEnabled(true); ui->RestartButton->setEnabled(true); + ui->RemoveButton->setEnabled(true); - //enabled only when alerting + //snooze button enabled only when alerting QModelIndexList indexes = selected.indexes(); //the selection model only allows selecting one row at the time & we only need to know the row, so we can just take the first one @@ -191,8 +215,13 @@ void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelectio if (model_.isThisTimerAlerting(index) == true) { ui->SnoozeButton->setEnabled(true); +//qDebug() << "Snooze on"; + } + else + { + ui->SnoozeButton->setDisabled(true); +//qDebug() << "Snooze off"; } - else ui->SnoozeButton->setDisabled(true); } } @@ -205,7 +234,7 @@ void KitchenAlertMainWindow::snooze() model_.snoozeTimer(row); } ui->SnoozeButton->setDisabled(true); - alertSound_.stop(); + } @@ -217,8 +246,14 @@ void KitchenAlertMainWindow::restart() model_.startTimer(row); } - ui->SnoozeButton->setDisabled(true); - alertSound_.stop(); + + + if (model_.isThisTimerAlerting(row) == false) //This has to be checked, because 00:00:00 alerts alert *before* the program execution reaches here + { + ui->SnoozeButton->setDisabled(true); + } + // qDebug () << "disabled snooze because of restart"; + } @@ -230,60 +265,79 @@ void KitchenAlertMainWindow::stop() model_.stopTimer(row); } ui->SnoozeButton->setDisabled(true); - alertSound_.stop(); + } QModelIndex KitchenAlertMainWindow::selectedRow() { + //Returns the cells in row 0 that have the whole row selected (the selection mode used allows only selecting whole rows + QModelIndexList chosenRows = ui->ComingAlertsTableView->selectionModel()->selectedRows(); //The selection mode used allows only one row to be selected at time, so we just take the first - //There are indexes for all columns in the row in the list, but as we only use the row, it does not matter which one we take + return chosenRows.value(0); //gives an invalid QModelIndex if the list is empty } void KitchenAlertMainWindow::openSelectSoundDialog() { + SelectSoundDialog dialog; if ( dialog.exec() == QDialog::Accepted) //if user pressed OK { + QSettings settings ("KitchenAlert","KitchenAlert"); + if (dialog.isDefaultSoundChecked() == true) - alertSound_.setDefaultSound(); - else - alertSound_.setSound(dialog.getSoundFileName()); + { + + settings.setValue("UseDefaultSound",true); + emit defaultSoundEnabled(); + } + else + { + QString filename = dialog.getSoundFileName(); + settings.setValue("UseDefaultSound",false); + settings.setValue("soundfile",filename); + emit soundChanged(filename); + } - //opening a dialog clears the selection so the selection dependen buttons must be disabled } - disableSelectionDependentButtons(); + } void KitchenAlertMainWindow::openAbout() { - QMessageBox::about(this,tr("About KitchenAlert"),tr("

Version 0.09" - "

Copyright © Heli Hyvättinen 2010" + QMessageBox::about(this,tr("About KitchenAlert"),tr("

Version %1" + "

Copyright © Heli Hyvättinen 2010-2011" "

License: General Public License v3" - "

Bugtracker: https://garage.maemo.org/projects/kitchenalert/")); + "

Web page: http://kitchenalert.garage.maemo.org/" + "

Bugtracker: https://garage.maemo.org/projects/kitchenalert/").arg(QApplication::applicationVersion())); } bool KitchenAlertMainWindow::event(QEvent *event) { - QMainWindow::event(event); + switch (event->type()) { case QEvent::WindowActivate: model_.setUpdateViewOnChanges(true); - break; +// ui->debugLabel->setText("Returned to the application!"); + break; case QEvent::WindowDeactivate: model_.setUpdateViewOnChanges(false); +// ui->debugLabel->setText(""); break; default: break; + } + + return QMainWindow::event(event); // Send the event to the base class implementation (also when handling the event in this function): necessary for the program to work! } void KitchenAlertMainWindow::disableSelectionDependentButtons() @@ -291,5 +345,47 @@ void KitchenAlertMainWindow::disableSelectionDependentButtons() ui->DoneButton->setDisabled(true); ui->SnoozeButton->setDisabled(true); ui->RestartButton->setDisabled(true); + ui->RemoveButton->setDisabled(true); + +} + +void KitchenAlertMainWindow::initializeAlertSound() +{ + QSettings settings; + + bool useDefaultSound = settings.value("UseDefaultSound",true).toBool(); + QString filename = settings.value("soundfile","").toString(); + + if (useDefaultSound == true) + { + openSelectSoundDialog(); + } + else if (filename.isEmpty()) + { + openSelectSoundDialog(); + } + + QString currentFilename = settings.value("soundfile","").toString(); + + if (currentFilename.isEmpty()) + { + ui->debugLabel->setText("No alert sound file set. Alert sound will not be played!"); + + } } + +void KitchenAlertMainWindow::remove() +{ + QModelIndex row = selectedRow(); + if (row.isValid()) //If there was no row selected invalid row was returned + { + QString text = tr("Are you sure you want to remove this timer from the list:\n"); + text.append((row.data().toString())); + if (QMessageBox::question(this,tr("Confirm timer removal"),text,QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + { + model_.removeTimer(row); + } + } + ui->SnoozeButton->setDisabled(true); +}