From: Heli Hyvättinen Date: Sat, 30 Apr 2011 15:23:20 +0000 (+0300) Subject: Merge branch 'savebletimers' X-Git-Tag: v0.4.0~17 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=383c3ee723d6ff55d01bcc83a8f98fab1b32cc03;hp=b9560d75511ff0e094a63cb12f3f2711c5bbc91a;p=kitchenalert Merge branch 'savebletimers' --- diff --git a/src/KitchenAlert.pro.user b/src/KitchenAlert.pro.user index bbc6a8f..d2626ad 100644 --- a/src/KitchenAlert.pro.user +++ b/src/KitchenAlert.pro.user @@ -13,81 +13,129 @@ ProjectExplorer.Project.Target.0 - Desktop - Qt4ProjectManager.Target.DesktopTarget + Qt Simulator + Qt Simulator + Qt4ProjectManager.Target.QtSimulatorTarget 0 + 0 0 - - qmake - QtProjectManager.QMakeBuildStep - + + + qmake + qmake + QtProjectManager.QMakeBuildStep + + false + + + Make + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build - - Make - Qt4ProjectManager.MakeStep - false - - + + + Make + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean - 2 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 + 2 false + Debug Debug Qt4ProjectManager.Qt4BuildConfiguration 2 - /holvi/heli/ohjelmointi/KitchenAlert-build-desktop - 4 + /home/heli/Build Directories for Qt Projects/KitchenAlert-build-simulator + 2 0 true - - qmake - QtProjectManager.QMakeBuildStep - + + + qmake + qmake + QtProjectManager.QMakeBuildStep + + false + + + Make + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build - - Make - Qt4ProjectManager.MakeStep - false - - + + + Make + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean - 2 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 + 2 false + Release Release Qt4ProjectManager.Qt4BuildConfiguration 0 - /holvi/heli/ohjelmointi/KitchenAlert-build-desktop - 4 + /home/heli/Build Directories for Qt Projects/KitchenAlert-build-simulator + 2 0 true 2 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + No deployment + No deployment + ProjectExplorer.DefaultDeployConfiguration + + 1 - KitchenAlert + KitchenAlert + Qt4ProjectManager.Qt4RunConfiguration 2 @@ -95,9 +143,11 @@ false false - false false + 3768 + true + false 1 @@ -105,223 +155,179 @@ ProjectExplorer.Project.Target.1 + Maemo Maemo Qt4ProjectManager.Target.MaemoDeviceTarget 0 + 0 0 - - qmake - QtProjectManager.QMakeBuildStep - + + + qmake + qmake + QtProjectManager.QMakeBuildStep + + false + + + Make + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build - - Make - Qt4ProjectManager.MakeStep - false - - + + + Make + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean - - true - - Qt4ProjectManager.MaemoPackageCreationStep - - false - /usr/local/bin/KitchenAlert - - 0.0.1 - - 3 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 + 2 false + Debug Debug Qt4ProjectManager.Qt4BuildConfiguration 2 - /holvi/heli/ohjelmointi/KitchenAlert-build-maemo - 8 + /home/heli/Build Directories for Qt Projects/KitchenAlert-build-maemo + 3 9 true - - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - - - - true - - Qt4ProjectManager.MaemoPackageCreationStep - - true - - - 0.0.1 + + + qmake + qmake + QtProjectManager.QMakeBuildStep + + false + + + Make + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build - 3 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - + + + Make + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean - 1 + 2 false + Release Release Qt4ProjectManager.Qt4BuildConfiguration 0 - /holvi/heli/ohjelmointi/KitchenAlert-build-maemo - 8 + /home/heli/Build Directories for Qt Projects/KitchenAlert-build-maemo + 3 9 true 2 + + + + true + + + Qt4ProjectManager.MaemoPackageCreationStep + + + + + Qt4ProjectManager.MaemoDeployStep + true + 1 + + /home/heli/Build Directories for Qt Projects/KitchenAlert-build-maemo/kitchenalert_0.0.1_armel.deb + + + 192.168.2.15 + + + + + + 2011-04-05T19:27:15 + + + 2 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy to Maemo device + Deploy to Maemo device + ProjectExplorer.DefaultDeployConfiguration + + 1 - KitchenAlert.pro + KitchenAlert New Maemo Run Configuration Qt4ProjectManager.MaemoRunConfiguration - 17 - - /holvi/heli/ohjelmointi/KitchenAlert-build-maemo/kitchenalert_0.0.1_armel.deb - 192.168.2.15 - - - 192.168.2.15 - /holvi/heli/ohjelmointi/KitchenAlert-build-maemo/kitchenalert_0.0.1_armel.deb - - - /home/developer/kitchenalert_0.0.1_armel.deb - /home/developer/kitchenalert_0.0.1_armel.deb - - - 2010-09-19T21:36:38 - 2010-09-20T14:15:54 - + 1 + + KitchenAlert.pro + + false + + 3768 + true + false 1 - ProjectExplorer.Project.Target.2 - - Qt Simulator - Qt4ProjectManager.Target.QtSimulatorTarget - 0 - 0 - - - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - - - 2 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - /holvi/heli/ohjelmointi/KitchenAlert-build-simulator - 2 - 0 - true - - - - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - - - 2 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - /holvi/heli/ohjelmointi/KitchenAlert-build-simulator - 2 - 0 - true - - 2 - - KitchenAlert - Qt4ProjectManager.Qt4RunConfiguration - 2 - - KitchenAlert.pro - false - false - - false - false - - - 1 - + ProjectExplorer.Project.TargetCount + 2 - ProjectExplorer.Project.TargetCount - 3 + ProjectExplorer.Project.Updater.EnvironmentId + {f9d47005-7c3c-4c91-accd-62aa22a16497} ProjectExplorer.Project.Updater.FileVersion - 4 + 8 diff --git a/src/alertsound.cpp b/src/alertsound.cpp index f27eb50..b6c1fa3 100644 --- a/src/alertsound.cpp +++ b/src/alertsound.cpp @@ -27,7 +27,8 @@ #include #include - +// Initialize static const + const QString AlertSound::defaultsound_ = "/home/opt/KitchenAlert/DoorbellModifiedFinal.mp3"; @@ -35,7 +36,7 @@ AlertSound::AlertSound(QObject *parent) : QObject(parent) { - defaultsound_ = "/home/opt/KitchenAlert/DoorbellModifiedFinal.mp3"; + QString filename; QSettings settings("KitchenAlert","KitchenAlert"); diff --git a/src/alertsound.h b/src/alertsound.h index 6e7dec2..d7f22ec 100755 --- a/src/alertsound.h +++ b/src/alertsound.h @@ -35,8 +35,8 @@ /*! Class for playing the alert sound' @author Heli Hyvättinen - @date 2011-03-29 - @version 0.2.1 + @date 2011-04-26 + @version 0.3.0 Class for playing (and stopping) the alert sound. @@ -50,6 +50,8 @@ public: virtual ~AlertSound(); + static const QString defaultsound_ ; /*! the name (with full path) of the default sound file */ + signals: public slots: @@ -69,10 +71,12 @@ private: - QMediaPlayer *pSound_; - QString defaultsound_; + QMediaPlayer *pSound_; /*! The media player used to play the sound */ + }; + + #endif // ALERTSOUND_H diff --git a/src/currentalertstablemodel.cpp b/src/currentalertstablemodel.cpp index 9913288..62e8327 100644 --- a/src/currentalertstablemodel.cpp +++ b/src/currentalertstablemodel.cpp @@ -325,3 +325,8 @@ void CurrentAlertsTableModel::removeTimer(QModelIndex index) } +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 8f4622a..b20ead1 100755 --- 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 2011-03-29 + @date 2011-04-05 @version 0.2.1 Class that contains the model that holds the timers @@ -86,6 +86,13 @@ public: bool isThisTimerAlerting(QModelIndex index); + /*! Saves a timer to a file + @param index The index of the timer to be saved. Any cell from the row of the timer is good here. + @param filename The name of the file to which the timer is to be saved + */ + bool saveTimer(QModelIndex index,QString filename); + + signals: public slots: diff --git a/src/kitchenalert.pro b/src/kitchenalert.pro new file mode 100644 index 0000000..ce9192d --- /dev/null +++ b/src/kitchenalert.pro @@ -0,0 +1,57 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-05-25T15:17:43 +# +#------------------------------------------------- + +QT += core gui + + + +TARGET = KitchenAlert +TEMPLATE = app + + +SOURCES += main.cpp\ + kitchenalertmainwindow.cpp \ + createtimersequencedialog.cpp \ + timer.cpp \ + currentalertstablemodel.cpp \ + alertsound.cpp \ + selectsounddialog.cpp + +HEADERS += kitchenalertmainwindow.h \ + createtimersequencedialog.h \ + timer.h \ + currentalertstablemodel.h \ + alertsound.h \ + selectsounddialog.h + +FORMS += kitchenalertmainwindow.ui \ + createtimersequencedialog.ui \ + selectsounddialog.ui \ + kitchenalertmainwindow.ui + + +symbian { + TARGET.UID3 = 0xe1020059 + # TARGET.CAPABILITY += + TARGET.EPOCSTACKSIZE = 0x14000 + TARGET.EPOCHEAPSIZE = 0x020000 0x800000 +} + +RESOURCES += \ + kitchenalert.qrc + +CONFIG += mobility +MOBILITY += multimedia + + +unix:!symbian { + maemo5 { + target.path = /opt/usr/bin + } else { + target.path = /usr/local/bin + } + INSTALLS += target +} diff --git a/src/kitchenalertmainwindow.cpp b/src/kitchenalertmainwindow.cpp index 4fc1c18..33ae87a 100644 --- a/src/kitchenalertmainwindow.cpp +++ b/src/kitchenalertmainwindow.cpp @@ -43,6 +43,7 @@ #include #include #include +#include @@ -50,19 +51,15 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::KitchenAlertMainWindow) { - ui->setupUi(this); - setWindowIcon(QIcon(":/kitchenalert.png")); + defaultSaveDirectory_ = "/home/user/MyDocs/KitchenAlert/"; + ui->setupUi(this); - - - connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence())); - + setWindowIcon(QIcon(":/kitchenalert.png")); //alerts' tableview setup - ui->ComingAlertsTableView->setModel(&model_); ui->ComingAlertsTableView->setSelectionMode(QAbstractItemView::SingleSelection); ui->ComingAlertsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -78,17 +75,20 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) : ui->ComingAlertsTableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); - //Buttons used to reacting an alarm are hidden by default + //Buttons used to reacting to an alarm are hidden by default disableSelectionDependentButtons(); connect(ui->ComingAlertsTableView->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(timerSelected(QItemSelection,QItemSelection))); - + connect(ui->CreateNewScheduleButton, SIGNAL (clicked()), 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->OpenButton,SIGNAL(clicked()),this,SLOT(loadTimer())); + // menu setup QAction * p_SelectSoundAction = new QAction(tr("Select alert sound"),this); @@ -203,6 +203,7 @@ void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelectio ui->DoneButton->setEnabled(true); ui->RestartButton->setEnabled(true); ui->RemoveButton->setEnabled(true); + ui->SaveButton->setEnabled(true); //snooze button enabled only when alerting @@ -346,6 +347,8 @@ void KitchenAlertMainWindow::disableSelectionDependentButtons() ui->SnoozeButton->setDisabled(true); ui->RestartButton->setDisabled(true); ui->RemoveButton->setDisabled(true); + ui->SaveButton->setDisabled(true); + } @@ -389,3 +392,120 @@ void KitchenAlertMainWindow::remove() } ui->SnoozeButton->setDisabled(true); } + +void KitchenAlertMainWindow::saveTimer() +{ + + 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, "", defaultSaveDirectory_, "*.kitchenalert",NULL,QFileDialog::DontConfirmOverwrite); + + + +// qDebug() << filename; + + if (filename.isEmpty()) //user cancelled the dialog (or gave an empty name) + { + return; + } + + if (!filename.endsWith(".kitchenalert")) + { + filename.append(".kitchenalert"); + + } + + // qDebug() << "filename appended to " << filename; + + + //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,"",defaultSaveDirectory_,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))); + + +//connect change sound functions + +connect(this,SIGNAL(defaultSoundEnabled()),p_timer,SLOT(enableDefaultSound())); +connect(this,SIGNAL(soundChanged(QString)),p_timer,SLOT(changeAlertSound(QString))); + + +//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,true); //timer gets started in the model + +} + + + diff --git a/src/kitchenalertmainwindow.h b/src/kitchenalertmainwindow.h index a9e86a6..1ec3974 100644 --- a/src/kitchenalertmainwindow.h +++ b/src/kitchenalertmainwindow.h @@ -40,8 +40,8 @@ namespace Ui { /*! The main window class of KitchenAlert' @author Heli Hyvättinen - @date 2011-03-29 - @version 0.2.1 + @date 2011-04-26 + @version 0.3.0 Operates the UI. @@ -52,8 +52,6 @@ class KitchenAlertMainWindow : public QMainWindow Q_OBJECT - - public: explicit KitchenAlertMainWindow(QWidget *parent = 0); ~KitchenAlertMainWindow(); @@ -117,6 +115,15 @@ public slots: */ void remove(); + /*! Opens a dialog for saving the selected timer and, if confirmed, saves the timer to a file. + */ + void saveTimer(); + + /*! Opens a dialog for reading a timer from a timer file, and if confirmed opens and starts the timer. + */ + void loadTimer(); + + signals: void defaultSoundEnabled(); @@ -143,6 +150,8 @@ private: CurrentAlertsTableModel model_; /*! The model that stores the alerts */ + QString defaultSaveDirectory_; + /*! Returns a QMoldelIndex pointing to the cell in the column 0 of the row that is currently selected. */ @@ -154,6 +163,8 @@ private: */ void initializeAlertSound(); + void initializeTimer(Timer * p_timer); + }; diff --git a/src/kitchenalertmainwindow.ui b/src/kitchenalertmainwindow.ui index 5f13826..44ea136 100644 --- a/src/kitchenalertmainwindow.ui +++ b/src/kitchenalertmainwindow.ui @@ -83,19 +83,6 @@ - - - Qt::Horizontal - - - - 40 - 20 - - - - - New timer @@ -110,17 +97,18 @@ - - - Qt::Horizontal + + + Save timer - - - 40 - 20 - + + + + + + Open timer - + diff --git a/src/main.cpp b/src/main.cpp index e162590..1e0b10f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ /************************************************************************** KitchenAlert - Copyright (C) 2010 Heli Hyvättinen + Copyright (C) 2010-11 Heli Hyvättinen This file is part of KitchenAlert. diff --git a/src/savedtimers.cpp b/src/savedtimers.cpp deleted file mode 100644 index 0de87cf..0000000 --- a/src/savedtimers.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/************************************************************************** - KitchenAlert - - Copyright (C) 2010 Heli Hyvättinen - - This file is part of KitchenAlert. - - Kitchen Alert is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -**************************************************************************/ - - - - - -#include "savedtimers.h" - -SavedTimers::SavedTimers(QObject *parent) : - QObject(parent) -{ -} diff --git a/src/savedtimers.h b/src/savedtimers.h deleted file mode 100644 index 79ae9e6..0000000 --- a/src/savedtimers.h +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************************************** - KitchenAlert - - Copyright (C) 2010 Heli Hyvättinen - - This file is part of KitchenAlert. - - Kitchen Alert is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -**************************************************************************/ - - - - - -#ifndef SAVEDTIMERS_H -#define SAVEDTIMERS_H - -#include - -class SavedTimers : public QObject -{ - Q_OBJECT -public: - explicit SavedTimers(QObject *parent = 0); - -signals: - -public slots: - -}; - -#endif // SAVEDTIMERS_H diff --git a/src/selectsounddialog.cpp b/src/selectsounddialog.cpp index b23f961..0a78d3e 100644 --- a/src/selectsounddialog.cpp +++ b/src/selectsounddialog.cpp @@ -26,14 +26,18 @@ #include "selectsounddialog.h" #include "ui_selectsounddialog.h" +#include "alertsound.h" #include #include #include + + SelectSoundDialog::SelectSoundDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SelectSoundDialog) { + ui->setupUi(this); connect(ui->browseButton,SIGNAL(clicked()),this,SLOT(browse())); @@ -50,6 +54,11 @@ SelectSoundDialog::SelectSoundDialog(QWidget *parent) : } else ui->CustomSoundRadioButton->setChecked(true); // qDebug() << "UseDefaultSoundfile is " << useDefaultSoundFile; + + + + isTesting_ = false; + connect(ui->TestButton,SIGNAL(clicked()),this,SLOT(testSound())); } SelectSoundDialog::~SelectSoundDialog() @@ -77,3 +86,33 @@ bool SelectSoundDialog::isDefaultSoundChecked() { return ui->DefaultSoundRadioButton->isChecked(); } + +void SelectSoundDialog::testSound() +{ + if (isTesting_ == false) + { + if (ui->CustomSoundRadioButton->isChecked() == false) + { + player.setMedia(QUrl::fromLocalFile(AlertSound::defaultsound_)); + } + + else + { + player.setMedia(QUrl::fromLocalFile(ui->lineEdit->displayText())); + } + + player.play(); + + ui->TestButton->setText(tr("Stop test")); + + isTesting_ = true; + } + + else + { + player.stop(); + ui->TestButton->setText(tr("Test sound")); + isTesting_ = false; + } + +} diff --git a/src/selectsounddialog.h b/src/selectsounddialog.h index f6b13eb..5ed0842 100644 --- a/src/selectsounddialog.h +++ b/src/selectsounddialog.h @@ -28,6 +28,7 @@ #define SELECTSOUNDDIALOG_H #include +#include namespace Ui { class SelectSoundDialog; @@ -36,8 +37,8 @@ namespace Ui { /*! The class for sound selection dialog of KitchenAlert' @author Heli Hyvättinen - @date 2011-03-29 - @version 0.2.1 + @date 2011-04-27 + @version 0.3.0 The class for sound selection dialog in KitchenAlert. @@ -50,14 +51,22 @@ class SelectSoundDialog : public QDialog public: explicit SelectSoundDialog(QWidget *parent = 0); ~SelectSoundDialog(); + QString getSoundFileName(); + /*! returns the filename for custom sound the user has chosen in the dialog */ + bool isDefaultSoundChecked(); + /*! Returns whether "use default sound" was checked by the user in the dialog */ public slots: void browse(); + void testSound(); private: Ui::SelectSoundDialog *ui; + + QMediaPlayer player; + bool isTesting_; }; #endif // SELECTSOUNDDIALOG_H diff --git a/src/selectsounddialog.ui b/src/selectsounddialog.ui index 0104637..ec64a23 100644 --- a/src/selectsounddialog.ui +++ b/src/selectsounddialog.ui @@ -58,9 +58,9 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:16pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt; font-weight:600;">Warning:</span><span style=" font-size:12pt;"> choosing a sound file inside the &quot;N900&quot; folder will prevent mounting it outside the device when KitchenAlert is running and the sound from playing if the folder has been mounted out before starting KitchenAlert.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;"></p></body></html> +</style></head><body style=" font-family:'Ubuntu'; font-size:16pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:12pt; font-weight:600;">Warning:</span><span style=" font-family:'Sans Serif'; font-size:12pt;"> choosing a sound file inside the &quot;N900&quot; folder will prevent mounting it outside the device when KitchenAlert is running and the sound from playing if the folder has been mounted out before starting KitchenAlert.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:12pt;"></p></body></html> @@ -86,6 +86,43 @@ p, li { white-space: pre-wrap; } + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Test sound + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + diff --git a/src/timer.cpp b/src/timer.cpp index efe8af9..c65e862 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -27,6 +27,8 @@ #include "timer.h" #include "currentalertstablemodel.h" #include +#include +#include Timer::Timer(QObject *parent) : QObject(parent) @@ -157,3 +159,53 @@ alertSound_.setSound(filename); } + + +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 061475d..ff2c22b 100644 --- a/src/timer.h +++ b/src/timer.h @@ -39,7 +39,7 @@ /*! The timer class of KitchenAlert' @author Heli Hyvättinen - @date 2011-02-10 + @date 2011-04-05 @version 0.2.1 The timer class of KitchenAlert. @@ -72,6 +72,16 @@ public: /*! Returns whether the timer is alerting */ bool isAlerting(); + /*! Saves the timer to a file + @param filename The file to which to save. + */ + bool save(QString filename); + + /*! Loads a timer from a file + @param filename The file from which to load. + */ + bool load(QString filename); + signals: /*! Emitted when the remaining time in the timer has changed */