Fix for volume rocker bug
[pierogi] / mainwindow.cpp
index aa60e1b..1b5ee5e 100644 (file)
@@ -5,6 +5,7 @@
 #include <QMutex>
 #include <QtGui/QMessageBox>
 #include <QSettings>
+#include <QMaemo5InformationBox>
 
 #include "pirkeysetwidgetitem.h"
 #include "pirselectkeysetform.h"
@@ -26,6 +27,7 @@ QMutex commandIFMutex;
 bool stopRepeatingFlag = false;
 QMutex stopRepeatingMutex;
 
+
 extern PIRMakeMgr makeManager;
 
 
@@ -44,7 +46,7 @@ MainWindow::MainWindow(QWidget *parent)
   setAttribute(Qt::WA_Maemo5StackedWindow);
 
   // Collect the keysets:
-  myKeysets = new PIRKeysetManager(this);
+  myKeysets = new PIRKeysetManager();
 
   // Set up the keyset selection window:
   selectKeysetForm = new PIRSelectKeysetForm(this);
@@ -68,12 +70,10 @@ MainWindow::MainWindow(QWidget *parent)
   }
 
   enableButtons();
-  secondaryForm->enableButtons(myKeysets, currentKeyset);
 
   connect(
     ui->favoriteKeysetsWidget,
-//    SIGNAL(itemActivated(QListWidgetItem *)),
-    SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
+    SIGNAL(itemActivated(QListWidgetItem *)),
     this,
     SLOT(keysetSelectionChanged(QListWidgetItem *)),
     Qt::QueuedConnection);
@@ -178,6 +178,9 @@ void MainWindow::showExpanded()
 
 void MainWindow::enableButtons()
 {
+  // Just to be sure, check to see if the keyset has been populated:
+  myKeysets->populateKeyset(this, currentKeyset);
+
   // This is going to be a little painful...
   // Main keys
   emit powerEnabled(myKeysets->hasKey(currentKeyset, Power_Key));
@@ -185,6 +188,7 @@ void MainWindow::enableButtons()
   emit volumeDownEnabled(myKeysets->hasKey(currentKeyset, VolumeDown_Key));
   emit channelUpEnabled(myKeysets->hasKey(currentKeyset, ChannelUp_Key));
   emit channelDownEnabled(myKeysets->hasKey(currentKeyset, ChannelDown_Key));
+  emit muteEnabled(myKeysets->hasKey(currentKeyset, Mute_Key));
 
   // Main tab labels:
   emit keysetMakeChanged(
@@ -196,14 +200,15 @@ void MainWindow::enableButtons()
   emit greenEnabled(myKeysets->hasKey(currentKeyset, Green_Key));
   emit yellowEnabled(myKeysets->hasKey(currentKeyset, Yellow_Key));
   emit blueEnabled(myKeysets->hasKey(currentKeyset, Blue_Key));
+  emit pictureModeEnabled(myKeysets->hasKey(currentKeyset, PictureMode_Key));
+  emit soundModeEnabled(myKeysets->hasKey(currentKeyset, SoundMode_Key));
   emit aspectRatioEnabled(myKeysets->hasKey(currentKeyset, AspectRatio_Key));
-  emit surroundEnabled(myKeysets->hasKey(currentKeyset, Surround_Key));
+//  emit surroundEnabled(myKeysets->hasKey(currentKeyset, Surround_Key));
   emit audioEnabled(myKeysets->hasKey(currentKeyset, Audio_Key));
   emit infoEnabled(myKeysets->hasKey(currentKeyset, Info_Key));
   emit captionsEnabled(myKeysets->hasKey(currentKeyset, Captions_Key));
   emit sleepEnabled(myKeysets->hasKey(currentKeyset, Sleep_Key));
   emit inputEnabled(myKeysets->hasKey(currentKeyset, Input_Key));
-  emit muteEnabled(myKeysets->hasKey(currentKeyset, Mute_Key));
 
   // Keypad keys
   emit zeroEnabled(myKeysets->hasKey(currentKeyset, Zero_Key));
@@ -247,6 +252,9 @@ void MainWindow::enableButtons()
   emit pauseEnabled(myKeysets->hasKey(currentKeyset, Pause_Key));
   emit stopEnabled(myKeysets->hasKey(currentKeyset, Stop_Key));
   emit ejectEnabled(myKeysets->hasKey(currentKeyset, Eject_Key));
+
+  // Also enable the buttons on the secondary form:
+  secondaryForm->enableButtons(myKeysets, currentKeyset);
 }
 
 
@@ -312,6 +320,16 @@ void MainWindow::on_mainVolumeDownButton_released()
   stopRepeating();
 }
 
+void MainWindow::on_muteButton_pressed()
+{
+  startRepeating(Mute_Key);
+}
+
+void MainWindow::on_muteButton_released()
+{
+  stopRepeating();
+}
+
 
 // Utility tab buttons:
 
@@ -355,6 +373,26 @@ void MainWindow::on_blueButton_released()
   stopRepeating();
 }
 
+void MainWindow::on_pictureModeButton_pressed()
+{
+  startRepeating(PictureMode_Key);
+}
+
+void MainWindow::on_pictureModeButton_released()
+{
+  stopRepeating();
+}
+
+void MainWindow::on_soundModeButton_pressed()
+{
+  startRepeating(SoundMode_Key);
+}
+
+void MainWindow::on_soundModeButton_released()
+{
+  stopRepeating();
+}
+
 void MainWindow::on_aspectRatioButton_pressed()
 {
   startRepeating(AspectRatio_Key);
@@ -365,6 +403,7 @@ void MainWindow::on_aspectRatioButton_released()
   stopRepeating();
 }
 
+/*
 void MainWindow::on_surroundButton_pressed()
 {
   startRepeating(Surround_Key);
@@ -374,6 +413,7 @@ void MainWindow::on_surroundButton_released()
 {
   stopRepeating();
 }
+*/
 
 void MainWindow::on_audioButton_pressed()
 {
@@ -425,16 +465,6 @@ void MainWindow::on_sleepButton_released()
   stopRepeating();
 }
 
-void MainWindow::on_muteButton_pressed()
-{
-  startRepeating(Mute_Key);
-}
-
-void MainWindow::on_muteButton_released()
-{
-  stopRepeating();
-}
-
 
 // Keypad tab buttons:
 
@@ -858,11 +888,17 @@ void MainWindow::on_actionDocumentation_triggered()
 void MainWindow::keysetSelectionChanged(
   QListWidgetItem *item)
 {
-  if (!item) return;  // Should probably say something here!
+  if (!item) return;  // Should probably display error message here!
 
   PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
 
   if (!kwi) return; // Also need to say something here
+
+  if (currentKeyset == kwi->getID())
+  {
+    // We're already on that keyset, so nothing to do:
+    return;
+  }
   
   currentKeyset = kwi->getID();
 
@@ -878,7 +914,6 @@ void MainWindow::keysetSelectionChanged(
     myKeysets->getDisplayName(currentKeyset));
 
   enableButtons();
-  secondaryForm->enableButtons(myKeysets, currentKeyset);
 }
 
 
@@ -1035,3 +1070,70 @@ void MainWindow::stopRepeating()
   stopRepeatingFlag = true;
 }
 
+
+QWidget *MainWindow::getSecondaryWindow()
+{
+  return secondaryForm;
+}
+
+
+void MainWindow::selectPrevFavKeyset()
+{
+  int size = ui->favoriteKeysetsWidget->count();
+
+  if (size == 0)
+  {
+    // No favorites, so nothing to do!
+    return;
+  }
+
+  int position = ui->favoriteKeysetsWidget->currentRow();
+
+  --position;
+  if (position < 0)
+  {
+    position = size - 1;
+  }
+
+  ui->favoriteKeysetsWidget->setCurrentRow(
+    position,
+    QItemSelectionModel::ClearAndSelect);
+
+  keysetSelectionChanged(ui->favoriteKeysetsWidget->currentItem());
+
+  // Tell the user about the change:
+  QMaemo5InformationBox::information(
+    0,
+    ui->favoriteKeysetsWidget->item(position)->text());
+}
+
+
+void MainWindow::selectNextFavKeyset()
+{
+  int size = ui->favoriteKeysetsWidget->count();
+
+  if (size == 0)
+  {
+    // No favorites, so just return:
+    return;
+  }
+
+  int position = ui->favoriteKeysetsWidget->currentRow();
+
+  ++position;
+  if (position == size)
+  {
+    position = 0;
+  }
+
+  ui->favoriteKeysetsWidget->setCurrentRow(
+    position,
+    QItemSelectionModel::ClearAndSelect);
+
+  keysetSelectionChanged(ui->favoriteKeysetsWidget->currentItem());
+
+  // Tell the user about the change:
+  QMaemo5InformationBox::information(
+    0,
+    ui->favoriteKeysetsWidget->item(position)->text());
+}