From: Heli Hyvättinen Date: Sun, 14 Aug 2011 11:32:27 +0000 (+0300) Subject: Added sticky alerts X-Git-Tag: v0.4.0~6^2~1 X-Git-Url: https://vcs.maemo.org/git/?p=kitchenalert;a=commitdiff_plain;h=a06334fdc173e26d116b5625aa50b1236d119dfe Added sticky alerts Alerts can now be loaded at startup. Dialog (from menu) provided to add and remove timer files to load. --- diff --git a/src/kitchenalert.pro b/src/kitchenalert.pro index 171ca7b..c850638 100644 --- a/src/kitchenalert.pro +++ b/src/kitchenalert.pro @@ -18,14 +18,16 @@ SOURCES += main.cpp\ timer.cpp \ currentalertstablemodel.cpp \ alertsound.cpp \ - selectsounddialog.cpp + selectsounddialog.cpp \ + stickydialog.cpp HEADERS += kitchenalertmainwindow.h \ createtimersequencedialog.h \ timer.h \ currentalertstablemodel.h \ alertsound.h \ - selectsounddialog.h + selectsounddialog.h \ + stickydialog.h FORMS += kitchenalertmainwindow.ui \ createtimersequencedialog.ui \ @@ -67,3 +69,11 @@ maemo5 { desktopfile.path = /usr/share/applications/hildon INSTALLS += desktopfile } + +OTHER_FILES += \ + qtc_packaging/debian_fremantle/rules \ + qtc_packaging/debian_fremantle/README \ + qtc_packaging/debian_fremantle/copyright \ + qtc_packaging/debian_fremantle/control \ + qtc_packaging/debian_fremantle/compat \ + qtc_packaging/debian_fremantle/changelog diff --git a/src/kitchenalertmainwindow.cpp b/src/kitchenalertmainwindow.cpp index f5fbfa5..b2dc075 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); + + loadStickies(); + } KitchenAlertMainWindow::~KitchenAlertMainWindow() @@ -486,22 +493,12 @@ void KitchenAlertMainWindow::loadTimer() // 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 @@ -526,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; +} diff --git a/src/kitchenalertmainwindow.h b/src/kitchenalertmainwindow.h index 392d05b..d80e6c8 100644 --- a/src/kitchenalertmainwindow.h +++ b/src/kitchenalertmainwindow.h @@ -123,6 +123,8 @@ public slots: */ void loadTimer(); + /*! Opens a dialog for choosing which timers to preload at start */ + void openStickyDialog(); signals: @@ -144,6 +146,10 @@ protected: */ void disableSelectionDependentButtons(); + bool loadStickies(); + + + private: Ui::KitchenAlertMainWindow *ui; @@ -163,9 +169,10 @@ private: */ void initializeAlertSound(); - void initializeTimer(Timer * p_timer); - + void initializeTimer(Timer * p_timer, bool startImmediately = true); + //Adds the timer to the model and optionally starts it on success, gives an error message on failure + bool loadTimer(QString filename, bool startImmediately); }; #endif // KITCHENALERTMAINWINDOW_H diff --git a/src/stickydialog.cpp b/src/stickydialog.cpp new file mode 100644 index 0000000..2b44a09 --- /dev/null +++ b/src/stickydialog.cpp @@ -0,0 +1,88 @@ +#include "stickydialog.h" +#include +#include +#include +#include +#include + +StickyDialog::StickyDialog(QString defaultDirectory, QWidget *parent) : + QDialog(parent) +{ + defaultDirectory_ = defaultDirectory; + + + QVBoxLayout* pMainLayout = new QVBoxLayout(this); + + QSettings settings; + QStringList stickies = settings.value("sticky").toStringList(); + +// stickies.append("Test String"); + + pStickiesModel_ = new QStringListModel; + pStickiesModel_->setStringList(stickies); + + pStickiesView_ = new QListView; + pStickiesView_->setModel(pStickiesModel_); + pStickiesView_->setSelectionMode(QAbstractItemView::SingleSelection); + pMainLayout->addWidget(pStickiesView_); + + QHBoxLayout * pButtonLayout = new QHBoxLayout; + pMainLayout->addLayout(pButtonLayout); + + QPushButton * pAddButton = new QPushButton (tr("Add")); + connect(pAddButton,SIGNAL(clicked()),this,SLOT(add())); + pButtonLayout->addWidget(pAddButton); + + QPushButton * pRemoveButton = new QPushButton(tr("Remove")); + connect(pRemoveButton,SIGNAL(clicked()),this,SLOT(remove())); + pButtonLayout->addWidget(pRemoveButton); + + QPushButton * pOkButton = new QPushButton(tr("OK")); + connect (pOkButton,SIGNAL(clicked()),this,SLOT(accept())); + pButtonLayout->addWidget(pOkButton); +} + +void StickyDialog::add() +{ + QString startDirectory; + + if (QFile(defaultDirectory_).exists()) + { + startDirectory = defaultDirectory_; + } + else + { + startDirectory = "/home/user/"; + qDebug () << "default save directory not found"; + } + + + QString filename = QFileDialog::getOpenFileName(this,tr("KitchenAlert - Choose a timer to add to stickied"),startDirectory,tr("KitchenAlert timer files (*.kitchenalert)")); + + if (filename.isEmpty()) // user cancelled the dialog + return; + + + QStringList tempList = pStickiesModel_->stringList(); + tempList.append(filename); + pStickiesModel_->setStringList(tempList); + +} + +void StickyDialog::remove() +{ + QItemSelectionModel* pSelected = pStickiesView_->selectionModel(); + QModelIndex index = pSelected->currentIndex(); //Only single selection allowed, so we only need to care about current item + + + if (!index.isValid()) + return; //Nothing selected, nothing to remove... + + pStickiesModel_->removeRows(index.row(),1); + +} + +QStringList StickyDialog::getStickyList() +{ + return pStickiesModel_->stringList(); +} diff --git a/src/stickydialog.h b/src/stickydialog.h new file mode 100644 index 0000000..62ff5b3 --- /dev/null +++ b/src/stickydialog.h @@ -0,0 +1,35 @@ +#ifndef STICKYDIALOG_H +#define STICKYDIALOG_H + +#include +#include +#include + +class StickyDialog : public QDialog +{ + Q_OBJECT +public: + explicit StickyDialog(QString defaultDirectory, QWidget *parent = 0); + + QStringList getStickyList(); + + +signals: + +public slots: + + void add(); + void remove(); + +protected: + + QListView * pStickiesView_; + QStringListModel * pStickiesModel_; + + QString defaultDirectory_; + + + +}; + +#endif // STICKYDIALOG_H diff --git a/src/timer.cpp b/src/timer.cpp index 8174177..1a182b9 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -39,6 +39,8 @@ Timer::Timer(QObject *parent) : connect(&_actualTimer, SIGNAL(timeout()), this, SLOT(secondPassed())); alerting_ = false; + + _remainingTime = 0; //Same as when stopped } @@ -211,9 +213,9 @@ bool Timer::load(QString filename) return true; } -QString Timer::getFilename() -{ - return filenameWithPath_; -} +//QString Timer::getFilename() +//{ +// return filenameWithPath_; +//}