From 5342eb76d3508d70aadc1b2299d15e8234856561 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Wed, 8 Sep 2010 20:04:21 +0300 Subject: [PATCH] Fresh start from released sources + some work done New since released: Fixed bug 6346 Quick-fixed bug 6381 (changing alert sound works only partially because of this) 00:00:00 now alerts Multiline for alert text + associated layout change for the view --- src/KitchenAlert.pro | 13 +- src/KitchenAlert.pro.user | 136 ++++++++++----------- src/alertsound.cpp | 25 +--- src/createtimersequencedialog.cpp | 1 - src/createtimersequencedialog.h | 4 +- src/currentalertstablemodel.cpp | 69 +++++------ src/currentalertstablemodel.h | 71 +++++++++-- src/kitchenalert.png | Bin 0 -> 7511 bytes src/kitchenalert.qrc | 2 +- src/kitchenalertmainwindow.cpp | 238 ++++++++++--------------------------- src/kitchenalertmainwindow.h | 75 ++++++++++-- src/kitchenalertmainwindow.ui | 40 ++----- src/main.cpp | 6 +- src/selectsounddialog.cpp | 12 -- src/selectsounddialog.h | 4 - src/selectsounddialog.ui | 7 -- src/timer.cpp | 79 +++--------- src/timer.h | 16 ++- 18 files changed, 332 insertions(+), 466 deletions(-) create mode 100644 src/kitchenalert.png diff --git a/src/KitchenAlert.pro b/src/KitchenAlert.pro index 2fc4ff7..cdd89fc 100644 --- a/src/KitchenAlert.pro +++ b/src/KitchenAlert.pro @@ -17,26 +17,19 @@ SOURCES += main.cpp\ timer.cpp \ currentalertstablemodel.cpp \ alertsound.cpp \ - selectsounddialog.cpp \ - savedtimers.cpp + selectsounddialog.cpp HEADERS += kitchenalertmainwindow.h \ createtimersequencedialog.h \ timer.h \ currentalertstablemodel.h \ alertsound.h \ - selectsounddialog.h \ - savedtimers.h + selectsounddialog.h FORMS += kitchenalertmainwindow.ui \ createtimersequencedialog.ui \ selectsounddialog.ui \ - kitchenalertmainwindow.ui \ - choosetimersequencedialog.ui - -CONFIG += mobility -MOBILITY = - + kitchenalertmainwindow.ui symbian { diff --git a/src/KitchenAlert.pro.user b/src/KitchenAlert.pro.user index 975b471..2078c84 100644 --- a/src/KitchenAlert.pro.user +++ b/src/KitchenAlert.pro.user @@ -2,12 +2,12 @@ ProjectExplorer.Project.ActiveTarget - 2 + 1 ProjectExplorer.Project.EditorSettings - System + UTF-8 @@ -15,16 +15,16 @@ Desktop Qt4ProjectManager.Target.DesktopTarget - 1 + 0 0 - + qmake QtProjectManager.QMakeBuildStep - + Make Qt4ProjectManager.MakeStep false @@ -32,7 +32,7 @@ 2 - + Make Qt4ProjectManager.MakeStep true @@ -53,12 +53,12 @@ - + qmake QtProjectManager.QMakeBuildStep - + Make Qt4ProjectManager.MakeStep false @@ -66,10 +66,12 @@ 2 - + Make Qt4ProjectManager.MakeStep true - + + clean + 1 @@ -103,9 +105,9 @@ ProjectExplorer.Project.Target.1 - Qt Simulator - Qt4ProjectManager.Target.QtSimulatorTarget - 1 + Maemo + Qt4ProjectManager.Target.MaemoDeviceTarget + 0 0 @@ -120,7 +122,15 @@ - 2 + + + Qt4ProjectManager.MaemoPackageCreationStep + + false + /usr/local/bin/KitchenAlert + + + 3 Make Qt4ProjectManager.MakeStep @@ -136,9 +146,9 @@ Debug Qt4ProjectManager.Qt4BuildConfiguration 2 - /holvi/heli/ohjelmointi/KitchenAlert-build-simulator - 2 - 0 + /holvi/heli/ohjelmointi/KitchenAlert-build-maemo + 8 + 9 true @@ -154,7 +164,15 @@ - 2 + + + Qt4ProjectManager.MaemoPackageCreationStep + + true + + + + 3 Make Qt4ProjectManager.MakeStep @@ -170,24 +188,22 @@ Release Qt4ProjectManager.Qt4BuildConfiguration 0 - /holvi/heli/ohjelmointi/KitchenAlert-build-simulator - 2 - 0 + /holvi/heli/ohjelmointi/KitchenAlert-build-maemo + 8 + 9 true 2 - KitchenAlert - Qt4ProjectManager.Qt4RunConfiguration - 2 - - KitchenAlert.pro - false - false - - false - false - + KitchenAlert.pro + New Maemo Run Configuration + Qt4ProjectManager.MaemoRunConfiguration + + + 17 + + 2010-09-08T15:52:20 + 1 @@ -195,8 +211,8 @@ ProjectExplorer.Project.Target.2 - Maemo - Qt4ProjectManager.Target.MaemoDeviceTarget + Qt Simulator + Qt4ProjectManager.Target.QtSimulatorTarget 0 0 @@ -212,15 +228,7 @@ - - - Qt4ProjectManager.MaemoPackageCreationStep - - false - /usr/local/bin/KitchenAlert - - - 3 + 2 Make Qt4ProjectManager.MakeStep @@ -236,9 +244,9 @@ Debug Qt4ProjectManager.Qt4BuildConfiguration 2 - /holvi/heli/ohjelmointi/KitchenAlert-build-maemo - 8 - 9 + /holvi/heli/ohjelmointi/KitchenAlert-build-simulator + 2 + 0 true @@ -254,15 +262,7 @@ - - - Qt4ProjectManager.MaemoPackageCreationStep - - true - - - - 3 + 2 Make Qt4ProjectManager.MakeStep @@ -278,22 +278,24 @@ Release Qt4ProjectManager.Qt4BuildConfiguration 0 - /holvi/heli/ohjelmointi/KitchenAlert-build-maemo - 8 - 9 + /holvi/heli/ohjelmointi/KitchenAlert-build-simulator + 2 + 0 true 2 - KitchenAlert.pro - New Maemo Run Configuration - Qt4ProjectManager.MaemoRunConfiguration - - - 17 - - 2010-08-16T21:04:14 - + KitchenAlert + Qt4ProjectManager.Qt4RunConfiguration + 2 + + KitchenAlert.pro + false + false + + false + false + 1 diff --git a/src/alertsound.cpp b/src/alertsound.cpp index b11f538..0f83d32 100644 --- a/src/alertsound.cpp +++ b/src/alertsound.cpp @@ -26,8 +26,6 @@ #include #include -#include - @@ -53,32 +51,11 @@ AlertSound::AlertSound(QObject *parent) : filename = settings.value("soundfile",defaultsound_).toString(); } pSound_ = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(filename)); - - - //TESTCODE!!! - - QList audioOutputDevices = - Phonon::BackendCapabilities::availableAudioOutputDevices(); - - foreach (Phonon::AudioOutputDevice device, audioOutputDevices) - { - qDebug() << device.name() << device.description(); - } } void AlertSound::play() { - - //TESTCODE - - Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); - - Phonon::Path path = Phonon::createPath(pSound_, audioOutput); - - audioOutput->setVolumeDecibel(0); - - //TESTCODE ENDS - + pSound_->stop(); //Just testing if stopping the previous alert will prevent the jammming of the sound pSound_->play(); qDebug() << "Sound should be played now"; } diff --git a/src/createtimersequencedialog.cpp b/src/createtimersequencedialog.cpp index b7c360f..d7b696c 100644 --- a/src/createtimersequencedialog.cpp +++ b/src/createtimersequencedialog.cpp @@ -32,7 +32,6 @@ CreateTimerSequenceDialog::CreateTimerSequenceDialog(QWidget *parent) : ui(new Ui::CreateTimerSequenceDialog) { ui->setupUi(this); - // ui->timer1AlertText->setMaxLength(40); //needed only with fixed cell height } CreateTimerSequenceDialog::~CreateTimerSequenceDialog() diff --git a/src/createtimersequencedialog.h b/src/createtimersequencedialog.h index d53ac38..4765387 100644 --- a/src/createtimersequencedialog.h +++ b/src/createtimersequencedialog.h @@ -39,8 +39,8 @@ namespace Ui { /*! Class for the dialog for creating timers' @author Heli Hyvättinen - @date 2010-08-12 - @version 0.1.1 + @date 2010-07-20 + @version 0.1 Class for the dialog for creating timers diff --git a/src/currentalertstablemodel.cpp b/src/currentalertstablemodel.cpp index 755a109..00c207e 100644 --- a/src/currentalertstablemodel.cpp +++ b/src/currentalertstablemodel.cpp @@ -140,7 +140,7 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const // qDebug () << timeAsText; - return timeAsText; + return timeAsText; case statusColumnNumber_: @@ -165,24 +165,24 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const - case Qt::BackgroundRole : +// case Qt::BackgroundRole : - //For some reason, these have no effect at all!!! They are asked by the view though. +// //For some reason, these have no effect at all!!! They are asked by the view though. - //No need to care for the column number, all have the same color +// //No need to care for the column number, all have the same color // qDebug() << "BackgroundRole asked"; - if (currentTimers_.at(index.row())->isAlerting()) - { +// if (currentTimers_.at(index.row())->isAlerting()) +// { // qDebug() << "black background"; - return QBrush (QColor(Qt::black)); - } - else - { +// return QBrush (QColor(Qt::black)); +// } +// else +// { // qDebug() << "red background"; - return QBrush (QColor(Qt::red)); - } +// return QBrush (QColor(Qt::red)); +// } default: return QVariant(); @@ -195,8 +195,10 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const -void CurrentAlertsTableModel::addTimers(QList timers) +void CurrentAlertsTableModel::addTimers(QList timers, bool startImmediately) { + +//preparatory work foreach (Timer* timer, timers) { connect (timer,SIGNAL(remainingTimeChanged()),this,SLOT(refreshTimeColumn())); @@ -204,13 +206,23 @@ void CurrentAlertsTableModel::addTimers(QList timers) timer->setParent(this); //The model becomes the timers parent giving the timer access to model } - int nextRow = rowCount(QModelIndex()); //As row numbering starts from zero, number of the rows is the row number of the row after current ones - int lastRow = nextRow + timers.length()-1; - beginInsertRows(QModelIndex(),nextRow,lastRow); + +//Add the timers + + beginResetModel(); currentTimers_.append(timers); - endInsertRows(); -// qDebug() << "Timers should be appended"; -// reset(); + endResetModel(); + + //start the timers if requested + + if (startImmediately) + { + foreach (Timer* timer, timers) + { + timer->start(); + } + } + } @@ -281,7 +293,7 @@ void CurrentAlertsTableModel::setUpdateViewOnChanges(bool update) { updateViewOnChanges_ = update; if (update == true) - reset(); //Refresh view to catch up with past changes + refreshTimeColumn(); //Refresh to catch up with past changes } bool CurrentAlertsTableModel::isThisTimerAlerting(QModelIndex index) @@ -296,20 +308,3 @@ bool CurrentAlertsTableModel::isThisTimerAlerting(QModelIndex index) } return false; } - -void CurrentAlertsTableModel::removeTimer(QModelIndex index) -{ - if (index.isValid()) - { - int row = index.row(); - beginRemoveRows(QModelIndex(),row,row); - Timer* p_timer = currentTimers_.takeAt(row); - endRemoveRows(); - delete p_timer; - } -} - -bool CurrentAlertsTableModel::saveTimer(QModelIndex index, QString filename) -{ - return currentTimers_.at(index.row())->save(filename); -} diff --git a/src/currentalertstablemodel.h b/src/currentalertstablemodel.h index 52f3f5c..8bf341a 100644 --- a/src/currentalertstablemodel.h +++ b/src/currentalertstablemodel.h @@ -35,7 +35,7 @@ /*! Class that contains the model that holds the timers' @author Heli Hyvättinen - @date 2010-08-08 + @date 2010-09-08 @version 0.1.1 Class that contains the model that holds the timers @@ -49,48 +49,93 @@ class CurrentAlertsTableModel : public QAbstractTableModel public: explicit CurrentAlertsTableModel(QObject *parent = 0); + /*! + Returns the number of rows in the model. + Used by the view. + */ int rowCount(const QModelIndex &parent) const; + /*! + Returns the (fixed) number of columns in the model. + Used by the view. + */ int columnCount(const QModelIndex &parent) const; + /*! + Returns the queried contents of the cell + Used by the view. + */ QVariant data(const QModelIndex &index, int role) const; + /*! + Returns the queried header data. + As no headers are wanted, it always returns an empty QVariant. + Used by the view. + */ QVariant headerData(int section, Qt::Orientation orientation, int role) const; + /*! + Returns the index in the model of the given timer + */ QModelIndex giveIndexForTimer(Timer * ptimer); + /*! + Returns whether the timer in the given position is currently alerting. + @param index Any cell from the row of the alert is good here. + */ bool isThisTimerAlerting(QModelIndex index); - bool saveTimer(QModelIndex index,QString filename); - signals: public slots: - void addTimers(QList timers); + /*! + Adds the timers to the model + @param timers List of timers to be added + @param startImmediately If true, the timers will be started after adding to the model. + */ + void addTimers(QList timers, bool startImmediately = true); + /*! + Tells the view to refresh all information in the time column. + */ void refreshTimeColumn (); + /*! + Passes the start command to the timer in the given index. + @param index Any cell from the row of the alert is good here. + */ void startTimer(QModelIndex index); + + /*! + Passes the snooze command to the timer in the given index. + @param index Any cell from the row of the alert is good here. + */ void snoozeTimer(QModelIndex index); - void stopTimer(QModelIndex index); - void setUpdateViewOnChanges(bool update); + /*! + Passes the stop command to the timer in the given index. + @param index Any cell from the row of the alert is good here. + */ + void stopTimer(QModelIndex index); - void removeTimer(QModelIndex index); +/*! +Sets whether the view should be kept up to date. +*/ + void setUpdateViewOnChanges(bool update); private: - QList currentTimers_; + QList currentTimers_; /*! Holds the timers */ - static const int numberOfColumns_ = 3; - static const int alertTextColumnNumber_ = 0; - static const int timeRemainingColumnNumber_ = 1; - static const int statusColumnNumber_ = 2; + static const int numberOfColumns_ = 3; /*! The fixed number of columns in the model */ + static const int alertTextColumnNumber_ = 0; /*! Tells which column contains the alert text */ + static const int timeRemainingColumnNumber_ = 1; /*! Tells which column contains the time remaining until alert */ + static const int statusColumnNumber_ = 2; /*! Tells which column contains status information, such as that the timer is alerting */ - bool updateViewOnChanges_; + bool updateViewOnChanges_; /*! Keeps track on whether the view should be kept up to date. */ }; diff --git a/src/kitchenalert.png b/src/kitchenalert.png new file mode 100644 index 0000000000000000000000000000000000000000..160541347aeb8b5e1692fb3e1aaccae31f09a841 GIT binary patch literal 7511 zcmV-d9jM}oP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2igb( z2QVNZ1WCaF000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}0011aNkl8EHS}^2xCu- zBx}NE>O-T3Fm8p}n`)-EXhGDwlhYKV()_ z)>~S79obctm6e(2+;jftf0k6Ax=a2^5aO3Yf+!|PQ$leBG z`745mAb`tX1%)UOfWrIXei(lS$&UjOHhmWGd>_xI_^~3WlnJAVQkqguQ%crSDpx2W z_`Z(`15_!*+LSa5h)N{}tE>2)M?Z>CGj-_qq1i-&0H-xBj&Z3)i$hB$poZ+GMU8G# zAt=c<8NNa;LiVS$&flovo{_-AKP6)kvvbH;Bcn4h-sdTWXFLKCg28}NtwyCkpqeIB zQ%g1QsW?ZeRKhP;P~|dd91{fryks#RQ);Gzg;9d0DJLMy?E z$^=GGPEg{q<;ibSp%A4;f-0r5uaug+`H^s&UN^trNdW*}5M)ZQmQX25{XUiHX{LI8 zrftfM2=!8#DWFuVqQa24Ql%UCG+QkiBAD4(SX#==v{b?lqRdL1U{q$}dMLCA%DIu? zqqS5DrBy-r!s-wID=29@!POSIN4B%+weZ$622a2beFC5)j%t6v^sX6pce~8TF?;9d znT{*?d-j0uVXHNIXBS!VJc4>1wY-cALu|iK8poN>1D=A^fp&s+7VTW708}Qh@v>Jy z6^(s6SIA#?T**y>jh$=Kjka2V@8fBWrxZR=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z^^S){@o*m@?mV`u(SGp|vUXJ5@C2Dzch)*UZ@IB3lvVeWqvll1#1(oz4}UQ+J5J@Gql3CTF_eyM;F*+`~8~* zX6q=c0J6UN^yNp79`S6_!w*UmPl$}hL5CIK5%8(WanDh4UkVq>{^s}WqFnZ`+79uH z4-Xc9rMHwdGc1Oy>H<0!{X2I_YdFe5ld0x&_OW ztXSf`#z)O$NAus=4P>+GJgt~52V)SMFz+JiP!mbe$Q34r{f37Yn45y~@Yz1ajzN3K z5rzX27kX$-y>@8406yeraw0^wFxyv*?VDoMMDkNOUJ7~pg!$+1)6v68o7!R{Q^+ry z|K8hiMR%aU>Q%I%E^wYm&3xg9r;}Y$81SDEiUKXoR#vi^A<3u7WYgq`6mo=|Or<70 hwgW^>)CluS{(s|- - icon64.png + kitchenalert.png diff --git a/src/kitchenalertmainwindow.cpp b/src/kitchenalertmainwindow.cpp index 18c4e2f..e2e79ff 100644 --- a/src/kitchenalertmainwindow.cpp +++ b/src/kitchenalertmainwindow.cpp @@ -42,9 +42,7 @@ #include #include #include -#include -#include -#include +#include @@ -54,12 +52,14 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) : { ui->setupUi(this); - setWindowIcon(QIcon(":/icon64.png")); + setWindowIcon(QIcon(":/kitchenalert.png")); - //load sticky alerts to the model here... + connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence())); + + //alerts' tableview setup @@ -67,42 +67,27 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) : ui->ComingAlertsTableView->setSelectionMode(QAbstractItemView::SingleSelection); ui->ComingAlertsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->ComingAlertsTableView->horizontalHeader()->hide(); +// ui->ComingAlertsTableView->verticalHeader()->setVisible(true); - //Commented out for testing their potebtial effect for slowdown: - - // ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed); -// ui->ComingAlertsTableView->horizontalHeader()->resizeSection(0,460); -// ui->ComingAlertsTableView->horizontalHeader()->resizeSection(1,140); -// ui->ComingAlertsTableView->horizontalHeader()->resizeSection(2,100); - -// ui->ComingAlertsTableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); - - - - -// ui->ComingAlertsTableView->verticalHeader()->setDefaultSectionSize(40); //Needed with fixed cell height only - - - + 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->horizontalHeader()->hide(); - ui->ComingAlertsTableView->setWordWrap(true); + ui->ComingAlertsTableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); - //Buttons used when a timer is selected are disabled by default and enabled upon selection + //Buttons used to reacting an alarm are hidden by default disableSelectionDependentButtons(); + connect(ui->ComingAlertsTableView->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(timerSelected(QItemSelection,QItemSelection))); - //connect buttons to respective functions - connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence())); 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())); - connect(ui->SaveButton,SIGNAL(clicked()),this,SLOT(saveTimer())); - connect(ui->loadButton,SIGNAL(clicked()),this,SLOT(loadTimer())); // menu setup @@ -143,38 +128,29 @@ void KitchenAlertMainWindow::newTimerSequence() if (createdialog.exec() == QDialog::Accepted) //if user pressed OK { - //get user input from the dialog - - - QList alltimers = createdialog.getTimers(); - // take first timer (currently the only one!) + QList alltimers = createdialog.getTimers(); //get user input from the dialog + Timer* timer1 = alltimers.at(0); // take first timer (currently the only one!) - Timer* timer1 = alltimers.at(0); - - - //connect alert connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex))); - //Disable buttons, as selection is cleared when view is refreshed to show the new timer - - disableSelectionDependentButtons(); + model_.addTimers(alltimers); // give timers to the model, they are started automatically by default - // give timers to the model + // ui->ComingAlertsTableView->resizeColumnsToContents(); - model_.addTimers(alltimers); + //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 - //start the timer when it's safely in the model (consider moving this to the model's addTimers function) + if (!selectedRow().isValid()) + disableSelectionDependentButtons(); - timer1->start(); - } // if cancelled, do nothing @@ -197,7 +173,7 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter) // The alerting timer is selected ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows ); -// qDebug() << "Should be selected now"; + qDebug() << "Should be selected now"; //Snooze button is enabled @@ -205,22 +181,27 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter) ui->SnoozeButton->setEnabled(true); - //The alert sound is played (consider moving this operation inside timer, as now stopping one alert will silence all alerting alerts) + //Debug message + - alertSound_.play(); + + ui->debugLabel->setText(tr("Alert received from row %1").arg(indexOfAlerter.row())); + qDebug() << "Wrote the debug message"; + + //The alert sound is played + //TESTING TO MOVE THIS OPERATION TO THE TIMER ITSELF +// alertSound_.play(); } -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); - ui->SaveButton->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 @@ -244,7 +225,7 @@ void KitchenAlertMainWindow::snooze() model_.snoozeTimer(row); } ui->SnoozeButton->setDisabled(true); - alertSound_.stop(); + // alertSound_.stop(); } @@ -257,7 +238,7 @@ void KitchenAlertMainWindow::restart() model_.startTimer(row); } ui->SnoozeButton->setDisabled(true); - alertSound_.stop(); + // alertSound_.stop(); } @@ -269,8 +250,7 @@ void KitchenAlertMainWindow::stop() model_.stopTimer(row); } ui->SnoozeButton->setDisabled(true); - alertSound_.stop(); - qDebug() << "Stopped."; +// alertSound_.stop(); } QModelIndex KitchenAlertMainWindow::selectedRow() @@ -285,17 +265,16 @@ QModelIndex KitchenAlertMainWindow::selectedRow() void KitchenAlertMainWindow::openSelectSoundDialog() { + //THIS CEASED TO WORK WHEN SOUND WAS MOVED TO TIMERS THEMSELVES SelectSoundDialog dialog; if ( dialog.exec() == QDialog::Accepted) //if user pressed OK { if (dialog.isDefaultSoundChecked() == true) alertSound_.setDefaultSound(); else - alertSound_.setSound(dialog.getSoundFileName()); - - //opening a dialog clears the selection so the selection dependen buttons must be disabled + alertSound_.setSound(dialog.getSoundFileName()); } - disableSelectionDependentButtons(); + } void KitchenAlertMainWindow::openAbout() @@ -303,18 +282,23 @@ void KitchenAlertMainWindow::openAbout() QMessageBox::about(this,tr("About KitchenAlert"),tr("

Version %1" "

Copyright © Heli Hyvättinen 2010" "

License: General Public License v3" - "

Bugtracker and project page: https://garage.maemo.org/projects/kitchenalert/").arg(QApplication::applicationVersion())); + "

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; case QEvent::WindowDeactivate: @@ -323,6 +307,8 @@ bool KitchenAlertMainWindow::event(QEvent *event) default: break; + + } } @@ -331,133 +317,31 @@ void KitchenAlertMainWindow::disableSelectionDependentButtons() ui->DoneButton->setDisabled(true); ui->SnoozeButton->setDisabled(true); ui->RestartButton->setDisabled(true); - ui->RemoveButton->setDisabled(true); - ui->SaveButton->setDisabled(true); -} -void KitchenAlertMainWindow::remove() -{ - QModelIndex row = selectedRow(); - if (row.isValid()) - { - model_.removeTimer(row); - alertSound_.stop(); - ui->ComingAlertsTableView->clearSelection(); - disableSelectionDependentButtons(); - } } -void KitchenAlertMainWindow::saveTimer() +void KitchenAlertMainWindow::initializeAlertSound() { + QSettings settings; - QModelIndex row = selectedRow(); - - if (row.isValid() == false) //If there was no row selected invalid row was returned - return; - - - //file name is asked. As the filename will be appended, there's no point in confirming owerwrite here - QString filename = QFileDialog::getSaveFileName(this, "", "", "*.kitchenalert",NULL,QFileDialog::DontConfirmOverwrite); + bool useDefaultSound = settings.value("UseDefaultSound",true).toBool(); + QString filename = settings.value("soundfile","").toString(); - disableSelectionDependentButtons(); - - qDebug() << filename; - - if (filename.isEmpty()) //user cancelled the dialog (or gave an empty name) + if (useDefaultSound == true) { - return; + openSelectSoundDialog(); } - - if (!filename.endsWith(".kitchenalert")) + else if (filename.isEmpty()) { - filename.append(".kitchenalert"); - + openSelectSoundDialog(); } - qDebug() << "filename appended to " << filename; - + QString currentFilename = settings.value("soundfile","").toString(); - //MANUAL CONFIRMATION OF OWERWRITE - - if ( QFile::exists(filename)) - { - //ASK FOR CONFIRMATION - - QString overwriteQuestion ("File "); - overwriteQuestion.append(filename); - overwriteQuestion.append(" already exists. Do you want to overwrite it?"); - if (QMessageBox::question(this,"Confirm overwrite?", overwriteQuestion,QMessageBox::Yes | QMessageBox::No,QMessageBox::No) != QMessageBox::Yes) - { - return; - } - } - - - - - - QString errorMessage(tr("Cannot write to file ")); - errorMessage.append(filename); - - if (!model_.saveTimer(row,filename)) //Save the file, if not successful give an error message - { - QMessageBox::critical(this,tr("Save timer failed!"), errorMessage); - } - - -} - -void KitchenAlertMainWindow::loadTimer() -{ - QString filename = QFileDialog::getOpenFileName(this,"","",tr("KitchenAlert timer files (*.kitchenalert)")); - if (!filename.isEmpty()) - { - -// if (!filename.endsWith(".kitchenalert")) //not needed, the dialog won't let the user to select files not ending with ".kitchenalert" -// { -// filename.append(".kitchenalert"); -// } - - QString errorTitle(tr("Failed to load file ")); - errorTitle.append(filename); - - Timer * p_timer = new Timer(); - if (!p_timer->load(filename)) - { - QMessageBox::critical(this,errorTitle,tr("Unable to open file or not a valid KitchenAlert timer file.")); - delete p_timer; - return; - } - - initializeTimer(p_timer); - } -} - - -void KitchenAlertMainWindow::initializeTimer(Timer *p_timer) -{ - -//connect alert - - -connect(p_timer,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex))); - - -//Disable buttons, as selection is cleared when view is refreshed to show the new timer - -disableSelectionDependentButtons(); - - -// give timers to the model (model wants list of timers now..) - -QList timerList; - -timerList.append(p_timer); -model_.addTimers(timerList); - - -//start the timer when it's safely in the model (consider moving this to the model's addTimers function) + if (currentFilename.isEmpty()) + { + ui->debugLabel->setText("No alert sound file set. Alert sound will not be played!"); + } -p_timer->start(); } diff --git a/src/kitchenalertmainwindow.h b/src/kitchenalertmainwindow.h index 30711ea..720da7b 100644 --- a/src/kitchenalertmainwindow.h +++ b/src/kitchenalertmainwindow.h @@ -40,7 +40,7 @@ namespace Ui { /*! The main window class of KitchenAlert' @author Heli Hyvättinen - @date 2010-08-08 + @date 2010-09-08 @version 0.1.1 Operates the UI. @@ -60,41 +60,90 @@ public: public slots: - void newTimerSequence(); - void openSelectSoundDialog(); + /*! + Opens a dialog for creating a new timer + Connects the new timer's alert and adds it to the model, starting the timer + */ + void newTimerSequence(); + + /*! + Opens a dialog for choosing the alert sound + Gives the sound filename to AlertSound + */ + void openSelectSoundDialog(); + + /*! + Shows the application's about box + */ void openAbout(); +/*! Sounds the alert sound and selects the alarming timer + Also bring the application to top and activates it + Used by connecting it to the timer's alert signal + @param indexOfAlerted The index of the alerting timer in the model. + */ void alert(QModelIndex indexOfAlerted); - void timerSelected(QItemSelection selected,QItemSelection deselected); + +/*! + Reacts to selecting of timer in the view. + Needs to be connected to the corresponding signal. + Sets enabling of buttons as necessary. + Does not receive information of clearing the selection (because no signal is sent). + Disabling selection dependent buttons must be done manually by everything that clears the selection. + It cannot be cleared by the user with the selection policy used. + + @param selected Selection that contains all selected cells (all cells of the row selected). +*/ + void timerSelected(QItemSelection selected,QItemSelection); + + /*! Snoozes the timer that is currently selected. + Needs to be connected to the associated button. + */ void snooze(); + + /*! Restarts the timer selected. + Needs to be connected to the associated button. + */ void restart(); - void stop(); - void remove(); - void saveTimer(); - void loadTimer(); + /*! Stops the timer selected. + Needs to be connected to the associated button. + */ + void stop(); protected: void changeEvent(QEvent *e); + + /*! + Reimplemented to catch WindowActivate and WindowDeactivate events. + Stops refreshing the view when the window is deactivated and resumes it when reactivated. + */ bool event(QEvent *event); + /*! + Disables all buttons that should only be enabled when a timer is selected. + */ void disableSelectionDependentButtons(); private: Ui::KitchenAlertMainWindow *ui; - QList currentTimers_; - - CurrentAlertsTableModel model_; + CurrentAlertsTableModel model_; /*! The model that stores the alerts */ + /*! + Returns a QMoldelIndex pointing to a cell in the row that is currently selected. + */ QModelIndex selectedRow(); - AlertSound alertSound_; + AlertSound alertSound_; /*! Takes care of alert sound */ //This has been moved to the timers themselves - void initializeTimer(Timer * p_timer); + /*! + Not used. Would allow getting rid of the default sound if used. + */ + void initializeAlertSound(); }; diff --git a/src/kitchenalertmainwindow.ui b/src/kitchenalertmainwindow.ui index 3303d88..23cf09e 100644 --- a/src/kitchenalertmainwindow.ui +++ b/src/kitchenalertmainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 736 - 403 + 785 + 413 @@ -31,8 +31,8 @@ 0 0 - 1445 - 585 + 1447 + 587 @@ -40,8 +40,8 @@ 350 0 - 721 - 391 + 791 + 411 @@ -49,6 +49,13 @@ + + + + + + + @@ -96,27 +103,6 @@ - - - Remove - - - - - - - Save - - - - - - - Load - - - - Qt::Horizontal diff --git a/src/main.cpp b/src/main.cpp index 7a30501..ff33e51 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,9 +28,9 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - a.setApplicationName("KitchenAlert"); //a name required by phonon - a.setApplicationVersion("0.2"); - + a.setApplicationName("KitchenAlert"); //a name is required by phonon + a.setApplicationVersion("0.1.1"); + a.setOrganizationName("KitchenAlert"); KitchenAlertMainWindow w; #if defined(Q_WS_S60) w.showMaximized(); diff --git a/src/selectsounddialog.cpp b/src/selectsounddialog.cpp index 210fb90..539796e 100644 --- a/src/selectsounddialog.cpp +++ b/src/selectsounddialog.cpp @@ -29,7 +29,6 @@ #include #include #include -#include SelectSoundDialog::SelectSoundDialog(QWidget *parent) : QDialog(parent), @@ -51,11 +50,6 @@ SelectSoundDialog::SelectSoundDialog(QWidget *parent) : } else ui->CustomSoundRadioButton->setChecked(true); qDebug() << "UseDefaultSoundfile is " << useDefaultSoundFile; - - connect(ui->testButton,SIGNAL(clicked()),this,SLOT(testSound())); - pSound_ = Phonon::createPlayer(Phonon::NoCategory, Phonon::MediaSource(ui->lineEdit->displayText())); - - } SelectSoundDialog::~SelectSoundDialog() @@ -83,9 +77,3 @@ bool SelectSoundDialog::isDefaultSoundChecked() { return ui->DefaultSoundRadioButton->isChecked(); } - -void SelectSoundDialog::testSound( ) -{ - pSound_->setCurrentSource(ui->lineEdit->displayText()); - pSound_->play(); -} diff --git a/src/selectsounddialog.h b/src/selectsounddialog.h index 24bbc9c..818d3e5 100644 --- a/src/selectsounddialog.h +++ b/src/selectsounddialog.h @@ -28,7 +28,6 @@ #define SELECTSOUNDDIALOG_H #include -#include namespace Ui { class SelectSoundDialog; @@ -56,12 +55,9 @@ public: public slots: void browse(); - void testSound(); private: Ui::SelectSoundDialog *ui; - Phonon::MediaObject* pSound_; - }; #endif // SELECTSOUNDDIALOG_H diff --git a/src/selectsounddialog.ui b/src/selectsounddialog.ui index 6a34a08..0104637 100644 --- a/src/selectsounddialog.ui +++ b/src/selectsounddialog.ui @@ -101,13 +101,6 @@ p, li { white-space: pre-wrap; } - - - Test sound - - - - Done diff --git a/src/timer.cpp b/src/timer.cpp index 1b3eed6..177a9a2 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -27,9 +27,6 @@ #include "timer.h" #include "currentalertstablemodel.h" #include -#include -#include -#include Timer::Timer(QObject *parent) : QObject(parent) @@ -43,7 +40,6 @@ Timer::Timer(QObject *parent) : } - int Timer::getOriginalTimeInSeconds() { return _originalTime; @@ -77,8 +73,9 @@ void Timer::secondPassed() if (_remainingTime == 0) { alerting_ = true; + alertSound_.play(); emit alert(whereAmI()); - qDebug() << "alerted"; +// qDebug() << "alerting"; } emit remainingTimeChanged(); //after alerting in case of alert so that status gets updated immediately @@ -89,24 +86,32 @@ void Timer::start() _remainingTime = _originalTime; _actualTimer.start(); - alerting_ = false; - if (_originalTime == 0) //has to be checked here, since 00:00:00 alert will already be negative when checked next time - //THIS ALERTS EVERY SECOND TIME THE TIMER IS STARTED! //This bug disappeared without explanation... + + if (_originalTime == 0) //a 00:00:00 alert has to be checked here, since it's already negative when checked for the next time { - alerting_ = true; + alerting_ = true; + alertSound_.play(); emit alert(whereAmI()); - qDebug () << "Alerted for 00:00:00 alert"; + qDebug () << "Alerting 00:00:00 from row: " << whereAmI().row(); } + + else + { + alerting_ = false; + alertSound_.stop(); + } + } void Timer::stop() { _actualTimer.stop(); - _remainingTime = 0; //Stopped timer shows 00:00:00 + _remainingTime = 0; //Stopped timer shows 00:00:00 (which unfortunately makes it red...) alerting_ = false; + alertSound_.stop(); } void Timer::snooze() @@ -114,6 +119,7 @@ void Timer::snooze() _remainingTime = 120; alerting_ = false; + alertSound_.stop(); } @@ -140,54 +146,3 @@ QModelIndex Timer::whereAmI() } -bool Timer::save(QString filename) -{ - QFile file(filename); - - if (!file.open(QFile::WriteOnly | QFile::Text)) - { - return false; - } - - QXmlStreamWriter xmlWriter(&file); - xmlWriter.setAutoFormatting(true); - xmlWriter.writeStartDocument(); - xmlWriter.writeStartElement("kitchenalert"); - xmlWriter.writeStartElement("timer"); - xmlWriter.writeAttribute("alert_text",_alertText); - xmlWriter.writeAttribute("time_in_seconds", QString().setNum(_originalTime)); - xmlWriter.writeEndDocument(); //this should close all open elements - - return true; -} - -bool Timer::load(QString filename) -{ - QFile file (filename); - if (!file.open(QFile::ReadOnly | QFile::Text)) - { - return false; - } - - QXmlStreamReader reader; - reader.setDevice(&file); - - reader.readNextStartElement(); - - if (reader.name() != "kitchenalert") - return false; - - reader.readNextStartElement(); - if (reader.name() != "timer") - return false; - - - _alertText = reader.attributes().value("alert_text").toString(); - _originalTime = reader.attributes().value("time_in_seconds").toString().toInt(); - return true; - - - - -} - diff --git a/src/timer.h b/src/timer.h index 81b64cd..7df8c2d 100644 --- a/src/timer.h +++ b/src/timer.h @@ -34,12 +34,12 @@ #include - +#include "alertsound.h" /*! The timer class of KitchenAlert' @author Heli Hyvättinen - @date 2010-08-12 + @date 2010-09-08 @version 0.1.1 The timer class of KitchenAlert. @@ -52,18 +52,21 @@ class Timer : public QObject public: explicit Timer(QObject *parent = 0); + /*! Returns the original time in seconds + When the alert restarts, it is set to this time. + */ + int getOriginalTimeInSeconds(); - int getOriginalTimeInSeconds(); + /*! Sets the original time in seconds */ void setOriginalTimeInSeconds(int seconds); + /*! Returns the time remaining before the alert in seconds */ int getRemainingTimeInSeconds(); QString getAlertText(); void setAlertText(QString text); bool isAlerting(); - bool save(QString filename); - bool load(QString filename); signals: @@ -79,7 +82,6 @@ public slots: - private: int _originalTime; //seconds! int _remainingTime; //seconds! @@ -89,6 +91,8 @@ private: QModelIndex whereAmI(); + AlertSound alertSound_; + }; #endif // TIMER_H -- 1.7.9.5