A couple of UI additions
[pierogi] / mainwindow.cpp
index ade853a..d7e9921 100644 (file)
@@ -19,6 +19,7 @@
 #include "pirpanelmanager.h"
 
 //#define DEBUGGING
+//#include <iostream>
 
 // Some ugly globals used for thread communications:
 
@@ -44,7 +45,7 @@ MainWindow::MainWindow(QWidget *parent)
     preferencesForm(0),
     documentationForm(0),
     aboutForm(0),
-    currentKeyset(0)
+    currentKeyset(1) // Zero is not a valid keyset any more
 {
   ui->setupUi(this);
 
@@ -55,20 +56,17 @@ MainWindow::MainWindow(QWidget *parent)
   myKeysets = new PIRKeysetManager();
   myPanels = new PIRPanelManager(this);
 
-  // Set up the keyset selection window:
+  // Construct the forms:
+  panelSelectionForm = new PIRPanelSelectionForm(this);
+  myPanels->setupPanels(panelSelectionForm);
+
   selectKeysetForm = new PIRSelectKeysetForm(this);
   myKeysets->populateSelectionWidget(selectKeysetForm);
 
-  // Set up the device selection window:
   selectDeviceForm = new PIRSelectDeviceForm(this);
   PIRKeysetMetaData::populateDevices(selectDeviceForm);
 
-  // Set up the panel selection window:
-  panelSelectionForm = new PIRPanelSelectionForm(this);
-  myPanels->setupPanels(panelSelectionForm);
-
-  // Set up the preferences window:
-  preferencesForm = new PIRPreferencesForm(this);
+  preferencesForm = new PIRPreferencesForm(this, myKeysets);
 
   // Remember any favorites the user has already set:
   populateFavorites();
@@ -235,7 +233,23 @@ void MainWindow::enableButtons()
   // Just to be sure, check to see if the keyset has been populated:
   myKeysets->populateKeyset(this, currentKeyset);
 
-  myPanels->enableButtons(myKeysets, currentKeyset);
+  if (preferencesForm)
+  {
+    unsigned int dk = preferencesForm->getDefaultKeyset();
+    if (preferencesForm->defaultControlsVolume() && dk)
+    {
+      myKeysets->populateKeyset(this, dk);
+      myPanels->enableButtons(myKeysets, currentKeyset, dk);
+    }
+    else
+    {
+      myPanels->enableButtons(myKeysets, currentKeyset);
+    }
+  }
+  else
+  {
+    myPanels->enableButtons(myKeysets, currentKeyset);
+  }
 }
 
 
@@ -251,6 +265,18 @@ void MainWindow::useAltMainPanel()
 }
 
 
+QString MainWindow::getCurrentMake()
+{
+  return makeManager.getMakeString(myKeysets->getMake(currentKeyset));
+}
+
+
+QString MainWindow::getCurrentName()
+{
+  return myKeysets->getDisplayName(currentKeyset);
+}
+
+
 void MainWindow::receivedExternalWarning(
   const char *warning)
 {
@@ -486,6 +512,19 @@ void MainWindow::startRepeating(
 }
 
 
+void MainWindow::startRepeating(
+  PIRKeyName name,
+  unsigned int keysetID)
+{
+  QMutexLocker locker(&commandIFMutex);
+  if (!commandInFlight)
+  {
+    commandInFlight = true;
+    emit buttonPressed(keysetID, name);
+  }
+}
+
+
 void MainWindow::stopRepeating()
 {
   QMutexLocker locker(&stopRepeatingMutex);