/**************************************************************************
KitchenAlert
- Copyright (C) 2010 Heli Hyvättinen
+ Copyright (C) 2010-2011 Heli Hyvättinen
This file is part of KitchenAlert.
#include "timer.h"
#include "currentalertstablemodel.h"
#include <qdebug.h>
+#include <QFile>
+#include <QXmlStreamWriter>
Timer::Timer(QObject *parent) :
QObject(parent)
alerting_ = true;
alertSound_.play();
emit alert(whereAmI());
- qDebug () << "Alerting 00:00:00 from row: " << whereAmI().row();
+// qDebug () << "Alerting 00:00:00 from row: " << whereAmI().row();
}
else
void Timer::stop()
{
_actualTimer.stop();
- _remainingTime = 0; //Stopped timer shows 00:00:00 (which unfortunately makes it red...)
+ _remainingTime = 0; //Stopped timer shows 00:00:00
alerting_ = false;
alertSound_.stop();
}
+void Timer::enableDefaultSound()
+{
+alertSound_.setDefaultSound();
+}
+
+void Timer::changeAlertSound(QString filename)
+{
+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();
+
+ filenameWithPath_ = filename;
+
+ return true;
+}
+
+QString Timer::getFilename()
+{
+ return filenameWithPath_;
+}
+
+