#include "createtimersequencedialog.h"
#include "selectsounddialog.h"
-
-
#include <QDebug>
#include <QAction>
#include <QSettings>
#include <QFileDialog>
-
+#include <QStringListModel>
+#include <QListView>
+#include "stickydialog.h"
KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) :
QAction * p_AboutAction = new QAction(tr("About"),this);
connect(p_AboutAction,SIGNAL(triggered()),this,SLOT(openAbout()));
menuBar()->addAction(p_AboutAction);
+
+ QAction * p_StickyAction = new QAction(tr("Edit sticky timers"),this);
+ connect(p_StickyAction, SIGNAL(triggered()),this,SLOT(openStickyDialog()));
+ menuBar()->addAction(p_StickyAction);
+
+ QTimer::singleShot(0,this,SLOT(loadStickies())); //Load sticky timers after construction to speed the application showing up
+
}
KitchenAlertMainWindow::~KitchenAlertMainWindow()
// 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;
- }
+ loadTimer(filename,true); //timer gets started
- initializeTimer(p_timer);
}
}
-void KitchenAlertMainWindow::initializeTimer(Timer *p_timer)
+void KitchenAlertMainWindow::initializeTimer(Timer *p_timer, bool startImmediately)
{
//connect alert
QList<Timer *> timerList;
timerList.append(p_timer);
-model_.addTimers(timerList,true); //timer gets started in the model
+model_.addTimers(timerList,startImmediately); //timer gets started in the model if startImmediately is true (default)
+
+}
+
+void KitchenAlertMainWindow::openStickyDialog()
+{
+ StickyDialog stickyDialog(defaultSaveDirectory_);
+
+
+ if (stickyDialog.exec()== QDialog::Accepted)
+ {
+ QSettings settings;
+ settings.setValue("sticky",stickyDialog.getStickyList());
+ }
+}
+
+bool KitchenAlertMainWindow::loadStickies()
+{
+ bool allSuccess = true;
+
+ QSettings settings;
+
+ QStringList stickies = settings.value("sticky").toStringList();
+
+ foreach (QString stickyFileName, stickies)
+ {
+ if (!loadTimer(stickyFileName,false)) //initializes the timer without starting it
+ allSuccess = false;
+ }
+
+ return allSuccess;
}
+bool KitchenAlertMainWindow::loadTimer(QString filename, bool startImmediately)
+{
+ 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 false;
+ }
+ initializeTimer(p_timer,startImmediately);
+ return true;
+}