X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fkitchenalertmainwindow.cpp;h=f74da41e6dadd73789ca179bb60d27b175b084f0;hb=d6ebfc1ae1c6c753f39a44478dbf2ad2087a3883;hp=0c3194be94f4d415f161d3ed03fa32beb1787b07;hpb=f072065b7aea720a1f064e50db68d80aa071c714;p=kitchenalert diff --git a/src/kitchenalertmainwindow.cpp b/src/kitchenalertmainwindow.cpp index 0c3194b..f74da41 100644 --- a/src/kitchenalertmainwindow.cpp +++ b/src/kitchenalertmainwindow.cpp @@ -35,8 +35,6 @@ #include "createtimersequencedialog.h" #include "selectsounddialog.h" - - #include #include @@ -45,7 +43,9 @@ #include #include - +#include +#include +#include "stickydialog.h" KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) : @@ -99,6 +99,13 @@ 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() @@ -458,7 +465,26 @@ void KitchenAlertMainWindow::saveTimer() void KitchenAlertMainWindow::loadTimer() { - QString filename = QFileDialog::getOpenFileName(this,"",defaultSaveDirectory_,tr("KitchenAlert timer files (*.kitchenalert)")); + +// If the default save directory does not exist use /home/user instead (as that's what the save dialog will use) +// This avoids a situation where save directs to a folder that cannot be accessed with open... + + QString startDirectory; + + if (QFile(defaultSaveDirectory_).exists()) + { + startDirectory = defaultSaveDirectory_; + } + else + { + startDirectory = "/home/user/"; + qDebug () << "default save directory not found"; + } + + + //Get the filename to open with a dialog + + QString filename = QFileDialog::getOpenFileName(this,"",startDirectory,tr("KitchenAlert timer files (*.kitchenalert)")); if (!filename.isEmpty()) { @@ -467,22 +493,12 @@ void KitchenAlertMainWindow::loadTimer() // filename.append(".kitchenalert"); // } - QString errorTitle(tr("Failed to load file ")); - errorTitle.append(filename); + loadTimer(filename,true); //timer gets started - 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) +void KitchenAlertMainWindow::initializeTimer(Timer *p_timer, bool startImmediately) { //connect alert @@ -507,9 +523,53 @@ disableSelectionDependentButtons(); QList 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; +}