Added sticky alerts
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Sun, 14 Aug 2011 11:32:27 +0000 (14:32 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Sun, 14 Aug 2011 11:32:27 +0000 (14:32 +0300)
Alerts can now be loaded at startup. Dialog (from menu) provided to add
and remove timer files to load.

src/kitchenalert.pro
src/kitchenalertmainwindow.cpp
src/kitchenalertmainwindow.h
src/stickydialog.cpp [new file with mode: 0644]
src/stickydialog.h [new file with mode: 0644]
src/timer.cpp

index 171ca7b..c850638 100644 (file)
@@ -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
index f5fbfa5..b2dc075 100644 (file)
@@ -35,8 +35,6 @@
 #include "createtimersequencedialog.h"
 #include "selectsounddialog.h"
 
-
-
 #include <QDebug>
 
 #include <QAction>
@@ -45,7 +43,9 @@
 #include <QSettings>
 #include <QFileDialog>
 
-
+#include <QStringListModel>
+#include <QListView>
+#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<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;
+}
index 392d05b..d80e6c8 100644 (file)
@@ -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 (file)
index 0000000..2b44a09
--- /dev/null
@@ -0,0 +1,88 @@
+#include "stickydialog.h"
+#include <QVBoxLayout>
+#include <QSettings>
+#include <QPushButton>
+#include <QFileDialog>
+#include <QDebug>
+
+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 (file)
index 0000000..62ff5b3
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef STICKYDIALOG_H
+#define STICKYDIALOG_H
+
+#include <QDialog>
+#include <QListView>
+#include <QStringListModel>
+
+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
index 8174177..1a182b9 100644 (file)
@@ -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_;
+//}