Alignment works + scrolls to the alerting timer
[kitchenalert] / src / kitchenalertmainwindow.cpp
index bd1c1f2..13b2454 100644 (file)
@@ -42,6 +42,7 @@
 #include <QAction>
 #include <QMenuBar>
 #include <QMessageBox>
+#include <QSettings>
 
 
 
@@ -51,6 +52,8 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) :
     {
     ui->setupUi(this);
 
+    setWindowIcon(QIcon(":/kitchenalert.png"));
+
 
 
 
@@ -63,8 +66,16 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) :
   ui->ComingAlertsTableView->setModel(&model_);
   ui->ComingAlertsTableView->setSelectionMode(QAbstractItemView::SingleSelection);
   ui->ComingAlertsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
-  ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
+
   ui->ComingAlertsTableView->horizontalHeader()->hide();
+//  ui->ComingAlertsTableView->verticalHeader()->setVisible(true);
+
+  ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
+  ui->ComingAlertsTableView->horizontalHeader()->resizeSection(0,535);
+  ui->ComingAlertsTableView->horizontalHeader()->resizeSection(1,140);
+  ui->ComingAlertsTableView->horizontalHeader()->resizeSection(2,100);
+
+  ui->ComingAlertsTableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
 
 
   //Buttons used to reacting an alarm are hidden by default
@@ -123,19 +134,26 @@ void KitchenAlertMainWindow::newTimerSequence()
        Timer* timer1 = alltimers.at(0); // take first timer (currently the only one!)
 
 
-       timer1->start();
+
        connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex)));
 
+       //TODO: FIND A WAY TO INFORM THE TIMERS' ALERTSOUND'S OF A CHANGE OF THE SOUND FILE THEY SHOULD USE!!!!
 
+       connect(this,SIGNAL(defaultSoundEnabled()),timer1,SLOT(enableDefaultSound()));
+       connect(this,SIGNAL(soundChanged(QString)),timer1,SLOT(changeAlertSound(QString)));
 
-        model_.addTimers(alltimers); // give timers to the model
+
+
+        model_.addTimers(alltimers); // give timers to the model, they are started automatically by default
 
  //       ui->ComingAlertsTableView->resizeColumnsToContents();
 
 
         //Disable buttons, as selection is cleared when view is refreshed to show the new timer
+        //But only if the timer has not already alerted and thus been selected
 
-        disableSelectionDependentButtons();
+        if (!selectedRow().isValid())
+            disableSelectionDependentButtons();
 
 
 
@@ -160,6 +178,7 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
 
     // The alerting timer is selected
     ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
+    ui->ComingAlertsTableView->scrollTo(indexOfAlerter);
     qDebug() << "Should be selected now";
 
 
@@ -168,20 +187,27 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
 
     ui->SnoozeButton->setEnabled(true);
 
-    //The alert sound is played
+    //Debug message
+
 
-    alertSound_.play();
+
+    ui->debugLabel->setText(tr("Alert received from row %1").arg(indexOfAlerter.row()));
+    qDebug() << "Wrote the debug message";
+
+    //The alert sound is played
+   //TESTING TO MOVE THIS OPERATION TO THE TIMER ITSELF
+//    alertSound_.play();
 
 }
 
 
-void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelection deselected)
+void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelection)
 {
     ui->DoneButton->setEnabled(true);
     ui->RestartButton->setEnabled(true);
 
 
-    //enabled only when alerting
+    //snooze button enabled only when alerting
     QModelIndexList indexes = selected.indexes();
 
     //the selection model only allows selecting one row at the time & we only need to know the row, so we can just take the first one
@@ -205,7 +231,7 @@ void KitchenAlertMainWindow::snooze()
         model_.snoozeTimer(row);
     }
     ui->SnoozeButton->setDisabled(true);
-    alertSound_.stop();
+  //  alertSound_.stop();
 
 }
 
@@ -218,7 +244,7 @@ void KitchenAlertMainWindow::restart()
         model_.startTimer(row);
     }
     ui->SnoozeButton->setDisabled(true);
-    alertSound_.stop();
+ //   alertSound_.stop();
 
 }
 
@@ -230,7 +256,7 @@ void KitchenAlertMainWindow::stop()
         model_.stopTimer(row);
     }
     ui->SnoozeButton->setDisabled(true);
-    alertSound_.stop();
+//    alertSound_.stop();
 }
 
 QModelIndex KitchenAlertMainWindow::selectedRow()
@@ -245,36 +271,40 @@ QModelIndex KitchenAlertMainWindow::selectedRow()
 
 void KitchenAlertMainWindow::openSelectSoundDialog()
 {
+
     SelectSoundDialog dialog;
    if ( dialog.exec() == QDialog::Accepted) //if user pressed OK
     {
        if (dialog.isDefaultSoundChecked() == true)
-           alertSound_.setDefaultSound();
+           emit defaultSoundEnabled();
        else
-        alertSound_.setSound(dialog.getSoundFileName());
-
-   //opening a dialog clears the selection so the selection dependen buttons must be disabled
+           emit soundChanged(dialog.getSoundFileName());
     }
-    disableSelectionDependentButtons();
+
 }
 
 void KitchenAlertMainWindow::openAbout()
 {
-    QMessageBox::about(this,tr("About KitchenAlert"),tr("<p>Version 0.1"
+    QMessageBox::about(this,tr("About KitchenAlert"),tr("<p>Version %1"
                                                         "<p>Copyright &copy; Heli Hyv&auml;ttinen 2010"
                                                          "<p>License: General Public License v3"
-                                                         "<p>Bugtracker and project page: https://garage.maemo.org/projects/kitchenalert/"));
+                                                         "<p>Web page: http://kitchenalert.garage.maemo.org/"
+                                                         "<p>Bugtracker: https://garage.maemo.org/projects/kitchenalert/").arg(QApplication::applicationVersion()));
 }
 
 bool KitchenAlertMainWindow::event(QEvent *event)
 {
     QMainWindow::event(event);
 
+
+
     switch (event->type())
     {
         case QEvent::WindowActivate:
 
             model_.setUpdateViewOnChanges(true);
+
+
               break;
 
        case QEvent::WindowDeactivate:
@@ -283,6 +313,8 @@ bool KitchenAlertMainWindow::event(QEvent *event)
 
        default:
             break;
+
+
     }
 }
 
@@ -293,3 +325,29 @@ void KitchenAlertMainWindow::disableSelectionDependentButtons()
     ui->RestartButton->setDisabled(true);
 
 }
+
+void KitchenAlertMainWindow::initializeAlertSound()
+{
+    QSettings settings;
+
+    bool useDefaultSound = settings.value("UseDefaultSound",true).toBool();
+    QString filename = settings.value("soundfile","").toString();
+
+    if (useDefaultSound == true)
+    {
+        openSelectSoundDialog();
+    }
+    else if (filename.isEmpty())
+    {
+        openSelectSoundDialog();
+    }
+
+   QString currentFilename = settings.value("soundfile","").toString();
+
+   if (currentFilename.isEmpty())
+   {
+        ui->debugLabel->setText("<FONT color=red>No alert sound file set. Alert sound will not be played!</FONT>");
+
+   }
+
+}