Adding per-keyset editable data
[pierogi] / mainwindow.cpp
index 1b5ee5e..bdce733 100644 (file)
@@ -4,17 +4,28 @@
 #include <QtCore/QCoreApplication>
 #include <QMutex>
 #include <QtGui/QMessageBox>
+#include <QPushButton>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QScrollArea>
 #include <QSettings>
-#include <QMaemo5InformationBox>
+
+#include "pirkeysetmetadata.h"
 
 #include "pirkeysetwidgetitem.h"
 #include "pirselectkeysetform.h"
-#include "pirsecondaryform.h"
+#include "pirselectdeviceform.h"
+#include "pirpreferencesform.h"
 #include "pirdocumentationform.h"
 #include "piraboutform.h"
+#include "dialogs/pirtabschoicedialog.h"
+#include "dialogs/pirfavoritesdialog.h"
+
 #include "pirkeysetmanager.h"
+#include "pirpanelmanager.h"
 
 //#define DEBUGGING
+//#include <iostream>
 
 // Some ugly globals used for thread communications:
 
@@ -35,30 +46,37 @@ MainWindow::MainWindow(QWidget *parent)
   : QMainWindow(parent),
     ui(new Ui::MainWindow),
     selectKeysetForm(0),
-    secondaryForm(0),
+    selectDeviceForm(0),
+    preferencesForm(0),
     documentationForm(0),
     aboutForm(0),
-    currentKeyset(0)
+    myKeysets(0),
+    myPanels(0),
+    currentKeyset(1) // Zero is not a valid keyset any more
 {
   ui->setupUi(this);
 
   // Make this a Maemo 5 stacked widget:
   setAttribute(Qt::WA_Maemo5StackedWindow);
 
-  // Collect the keysets:
+  // Create the managers:
   myKeysets = new PIRKeysetManager();
+  myPanels = new PIRPanelManager(this);
 
-  // Set up the keyset selection window:
-  selectKeysetForm = new PIRSelectKeysetForm(this);
+  // Display the panels:
+  myPanels->updateTabSet();
 
-  // Set up the secondary buttons window:
-  secondaryForm = new PIRSecondaryForm(this);
+  // Construct the rest of the forms:
+  selectKeysetForm = new PIRSelectKeysetForm(this);
+  favoritesDialog = new PIRFavoritesDialog(this);
+  myKeysets->populateListWidgets(selectKeysetForm, favoritesDialog);
 
-  myKeysets->populateGuiWidget(selectKeysetForm);
+  selectDeviceForm = new PIRSelectDeviceForm(this);
+  PIRKeysetMetaData::populateDevices(selectDeviceForm);
 
-  // Remember any favorites the user has already set:
-  populateFavorites();
+  preferencesForm = new PIRPreferencesForm(this, myKeysets);
 
+  // Retrieve the user's preferences:
   QSettings settings("pietrzak.org", "Pierogi");
   if (settings.contains("currentKeysetName"))
   {
@@ -66,31 +84,71 @@ MainWindow::MainWindow(QWidget *parent)
       settings.value("currentKeysetMake").toString(),
       settings.value("currentKeysetName").toString(),
       currentKeyset);
-//    currentKeyset = settings.value("currentKeyset").toInt();
   }
 
+  // Add the corner buttons:
+  insertCornerButtons();
+
   enableButtons();
 
+  QListWidget *fkw = favoritesDialog->getFavoritesListWidget();
+
   connect(
-    ui->favoriteKeysetsWidget,
+    fkw,
     SIGNAL(itemActivated(QListWidgetItem *)),
     this,
     SLOT(keysetSelectionChanged(QListWidgetItem *)),
     Qt::QueuedConnection);
 
-  // Make sure the two selection lists don't show different selections:
+  // Make sure the three selection lists don't show different selections:
   QListWidget *klw = selectKeysetForm->getKeysetListWidget();
+  QListWidget *dlw = selectDeviceForm->getDeviceListWidget();
+
+  // favorites -> keyset name
+  connect(
+    fkw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    klw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
+
+  // favorites -> device name
   connect(
-    ui->favoriteKeysetsWidget,
+    fkw,
     SIGNAL(itemActivated(QListWidgetItem *)),
+    dlw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
+
+  // keyset name -> favorites
+  connect(
     klw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    fkw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
+
+  // device name -> favorites
+  connect(
+    dlw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    fkw,
     SLOT(clearSelection()),
     Qt::QueuedConnection);
 
+  // keyset name -> device name
   connect(
     klw,
     SIGNAL(itemActivated(QListWidgetItem *)),
-    ui->favoriteKeysetsWidget,
+    dlw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
+
+  // device name -> keyset name
+  connect(
+    dlw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    klw,
     SLOT(clearSelection()),
     Qt::QueuedConnection);
 
@@ -115,6 +173,8 @@ MainWindow::~MainWindow()
 {
   delete myKeysets;
   if (selectKeysetForm) delete selectKeysetForm;
+  if (selectDeviceForm) delete selectDeviceForm;
+//  if (panelSelectionForm) delete panelSelectionForm;
   if (documentationForm) delete documentationForm;
   if (aboutForm) delete aboutForm;
   delete ui;
@@ -181,667 +241,57 @@ 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));
-  emit volumeUpEnabled(myKeysets->hasKey(currentKeyset, VolumeUp_Key));
-  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(
-    makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
-  emit keysetNameChanged(myKeysets->getDisplayName(currentKeyset));
-
-  // Utility keys:
-  emit redEnabled(myKeysets->hasKey(currentKeyset, Red_Key));
-  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 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));
-
-  // Keypad keys
-  emit zeroEnabled(myKeysets->hasKey(currentKeyset, Zero_Key));
-  emit oneEnabled(myKeysets->hasKey(currentKeyset, One_Key));
-  emit twoEnabled(myKeysets->hasKey(currentKeyset, Two_Key));
-  emit threeEnabled(myKeysets->hasKey(currentKeyset, Three_Key));
-  emit fourEnabled(myKeysets->hasKey(currentKeyset, Four_Key));
-  emit fiveEnabled(myKeysets->hasKey(currentKeyset, Five_Key));
-  emit sixEnabled(myKeysets->hasKey(currentKeyset, Six_Key));
-  emit sevenEnabled(myKeysets->hasKey(currentKeyset, Seven_Key));
-  emit eightEnabled(myKeysets->hasKey(currentKeyset, Eight_Key));
-  emit nineEnabled(myKeysets->hasKey(currentKeyset, Nine_Key));
-  emit enterEnabled(myKeysets->hasKey(currentKeyset, Enter_Key));
-  emit clearEnabled(myKeysets->hasKey(currentKeyset, Clear_Key));
-  emit dashEnabled(myKeysets->hasKey(currentKeyset, Dash_Key));
-  emit plusOneHundredEnabled(myKeysets->hasKey(currentKeyset, PlusOneHundred_Key));
-  emit doubleDigitEnabled(myKeysets->hasKey(currentKeyset, DoubleDigit_Key));
-  emit prevChannelEnabled(myKeysets->hasKey(currentKeyset, PrevChannel_Key));
-
-  // Menu keys:
-  emit upEnabled(myKeysets->hasKey(currentKeyset, Up_Key));
-  emit downEnabled(myKeysets->hasKey(currentKeyset, Down_Key));
-  emit leftEnabled(myKeysets->hasKey(currentKeyset, Left_Key));
-  emit rightEnabled(myKeysets->hasKey(currentKeyset, Right_Key));
-  emit selectEnabled(myKeysets->hasKey(currentKeyset, Select_Key));
-  emit menuEnabled(myKeysets->hasKey(currentKeyset, Menu_Key));
-  emit exitEnabled(myKeysets->hasKey(currentKeyset, Exit_Key));
-  emit guideEnabled(myKeysets->hasKey(currentKeyset, Guide_Key));
-  emit discMenuEnabled(myKeysets->hasKey(currentKeyset, DiscMenu_Key));
-
-  // Media keys:
-  emit nextEnabled(myKeysets->hasKey(currentKeyset, Next_Key));
-  emit previousEnabled(myKeysets->hasKey(currentKeyset, Previous_Key));
-  emit advanceEnabled(myKeysets->hasKey(currentKeyset, Advance_Key));
-  emit replayEnabled(myKeysets->hasKey(currentKeyset, Replay_Key));
-  emit stepForwardEnabled(myKeysets->hasKey(currentKeyset, StepForward_Key));
-  emit stepBackEnabled(myKeysets->hasKey(currentKeyset, StepBack_Key));
-  emit fastForwardEnabled(myKeysets->hasKey(currentKeyset, FastForward_Key));
-  emit reverseEnabled(myKeysets->hasKey(currentKeyset, Rewind_Key));
-  emit playEnabled(myKeysets->hasKey(currentKeyset, Play_Key));
-  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);
-}
-
-
-void MainWindow::receivedExternalWarning(
-  const char *warning)
-{
-  QMessageBox errBox;
-  errBox.setText(warning);
-  errBox.setIcon(QMessageBox::Warning);
-  errBox.exec();
-}
-
-
-// Main tab buttons:
-
-void MainWindow::on_powerButton_pressed()
-{
-  startRepeating(Power_Key);
-}
-
-void MainWindow::on_powerButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_mainChannelUpButton_pressed()
-{
-  startRepeating(ChannelUp_Key);
-}
-
-void MainWindow::on_mainChannelUpButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_mainChannelDownButton_pressed()
-{
-  startRepeating(ChannelDown_Key);
-}
-
-void MainWindow::on_mainChannelDownButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_mainVolumeUp_pressed()
-{
-  startRepeating(VolumeUp_Key);
-}
-
-void MainWindow::on_mainVolumeUp_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_mainVolumeDownButton_pressed()
-{
-  startRepeating(VolumeDown_Key);
-}
-
-void MainWindow::on_mainVolumeDownButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_muteButton_pressed()
-{
-  startRepeating(Mute_Key);
-}
-
-void MainWindow::on_muteButton_released()
-{
-  stopRepeating();
-}
-
-
-// Utility tab buttons:
-
-void MainWindow::on_redButton_pressed()
-{
-  startRepeating(Red_Key);
-}
-
-void MainWindow::on_redButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_greenButton_pressed()
-{
-  startRepeating(Green_Key);
-}
-
-void MainWindow::on_greenButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_yellowButton_pressed()
-{
-  startRepeating(Yellow_Key);
-}
-
-void MainWindow::on_yellowButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_blueButton_pressed()
-{
-  startRepeating(Blue_Key);
-}
-
-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);
-}
-
-void MainWindow::on_aspectRatioButton_released()
-{
-  stopRepeating();
-}
-
-/*
-void MainWindow::on_surroundButton_pressed()
-{
-  startRepeating(Surround_Key);
-}
-
-void MainWindow::on_surroundButton_released()
-{
-  stopRepeating();
-}
-*/
-
-void MainWindow::on_audioButton_pressed()
-{
-  startRepeating(Audio_Key);
-}
-
-void MainWindow::on_audioButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_infoButton_pressed()
-{
-  startRepeating(Info_Key);
-}
-
-void MainWindow::on_infoButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_captionButton_pressed()
-{
-  startRepeating(Captions_Key);
-}
-
-void MainWindow::on_captionButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_inputButton_pressed()
-{
-  startRepeating(Input_Key);
-}
-
-void MainWindow::on_inputButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_sleepButton_pressed()
-{
-  startRepeating(Sleep_Key);
-}
-
-void MainWindow::on_sleepButton_released()
-{
-  stopRepeating();
-}
-
-
-// Keypad tab buttons:
-
-void MainWindow::on_oneButton_pressed()
-{
-  startRepeating(One_Key);
-}
-
-void MainWindow::on_oneButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_twoButton_pressed()
-{
-  startRepeating(Two_Key);
-}
-
-void MainWindow::on_twoButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_threeButton_pressed()
-{
-  startRepeating(Three_Key);
-}
-
-void MainWindow::on_threeButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_fourButton_pressed()
-{
-  startRepeating(Four_Key);
-}
-
-void MainWindow::on_fourButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_fiveButton_pressed()
-{
-  startRepeating(Five_Key);
-}
-
-void MainWindow::on_fiveButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_sixButton_pressed()
-{
-  startRepeating(Six_Key);
-}
-
-void MainWindow::on_sixButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_sevenButton_pressed()
-{
-  startRepeating(Seven_Key);
-}
-
-void MainWindow::on_sevenButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_eightButton_pressed()
-{
-  startRepeating(Eight_Key);
-}
-
-void MainWindow::on_eightButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_nineButton_pressed()
-{
-  startRepeating(Nine_Key);
-}
-
-void MainWindow::on_nineButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_zeroButton_pressed()
-{
-  startRepeating(Zero_Key);
-}
-
-void MainWindow::on_zeroButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_enterButton_pressed()
-{
-  startRepeating(Enter_Key);
-}
-
-void MainWindow::on_enterButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_clearButton_pressed()
-{
-  startRepeating(Clear_Key);
-}
-
-void MainWindow::on_clearButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_prevChannelButton_pressed()
-{
-  startRepeating(PrevChannel_Key);
-}
-
-void MainWindow::on_prevChannelButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_plusOneHundredButton_pressed()
-{
-  startRepeating(PlusOneHundred_Key);
-}
-
-void MainWindow::on_plusOneHundredButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_dashButton_pressed()
-{
-  startRepeating(Dash_Key);
-}
-
-void MainWindow::on_dashButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_doubleDigitButton_pressed()
-{
-  startRepeating(DoubleDigit_Key);
-}
-
-void MainWindow::on_doubleDigitButton_released()
-{
-  stopRepeating();
-}
-
-
-// Menu tab buttons:
-
-void MainWindow::on_upButton_pressed()
-{
-  startRepeating(Up_Key);
-}
-
-void MainWindow::on_upButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_leftButton_pressed()
-{
-  startRepeating(Left_Key);
-}
-
-void MainWindow::on_leftButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_rightButton_pressed()
-{
-  startRepeating(Right_Key);
-}
-
-void MainWindow::on_rightButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_downButton_pressed()
-{
-  startRepeating(Down_Key);
-}
-
-void MainWindow::on_downButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_selectButton_pressed()
-{
-  startRepeating(Select_Key);
-}
-
-void MainWindow::on_selectButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_menuButton_pressed()
-{
-  startRepeating(Menu_Key);
-}
-
-void MainWindow::on_menuButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_exitButton_pressed()
-{
-  startRepeating(Exit_Key);
-}
-
-void MainWindow::on_exitButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_guideButton_pressed()
-{
-  startRepeating(Guide_Key);
-}
-
-void MainWindow::on_guideButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_discMenuButton_pressed()
-{
-  startRepeating(DiscMenu_Key);
-}
-
-void MainWindow::on_discMenuButton_released()
-{
-  stopRepeating();
-}
-
-
-// Media tab buttons:
-
-void MainWindow::on_mediaPreviousButton_pressed()
-{
-  startRepeating(Previous_Key);
-}
-
-void MainWindow::on_mediaPreviousButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_mediaNextButton_pressed()
-{
-  startRepeating(Next_Key);
-}
-
-void MainWindow::on_mediaNextButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_replayButton_pressed()
-{
-  startRepeating(Replay_Key);
-}
-
-void MainWindow::on_replayButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_advanceButton_pressed()
-{
-  startRepeating(Advance_Key);
-}
-
-void MainWindow::on_advanceButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_stepBackButton_pressed()
-{
-  startRepeating(StepBack_Key);
-}
-
-void MainWindow::on_stepBackButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_stepForwardButton_pressed()
-{
-  startRepeating(StepForward_Key);
-}
-
-void MainWindow::on_stepForwardButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_reverseButton_pressed()
-{
-  startRepeating(Rewind_Key);
-}
-
-void MainWindow::on_reverseButton_released()
-{
-  stopRepeating();
+  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);
+  }
 }
 
-void MainWindow::on_fastForwardButton_pressed()
-{
-  startRepeating(FastForward_Key);
-}
 
-void MainWindow::on_fastForwardButton_released()
+void MainWindow::useMainPanel()
 {
-  stopRepeating();
+  myPanels->useMainPanel();
 }
 
-void MainWindow::on_playButton_pressed()
-{
-  startRepeating(Play_Key);
-}
 
-void MainWindow::on_playButton_released()
+void MainWindow::useAltMainPanel()
 {
-  stopRepeating();
+  myPanels->useAltMainPanel();
 }
 
-void MainWindow::on_pauseButton_pressed()
-{
-  startRepeating(Pause_Key);
-}
 
-void MainWindow::on_pauseButton_released()
+QString MainWindow::getCurrentMake()
 {
-  stopRepeating();
+  return makeManager.getMakeString(myKeysets->getMake(currentKeyset));
 }
 
-void MainWindow::on_stopButton_pressed()
-{
-  startRepeating(Stop_Key);
-}
 
-void MainWindow::on_stopButton_released()
+QString MainWindow::getCurrentName()
 {
-  stopRepeating();
+  return myKeysets->getDisplayName(currentKeyset);
 }
 
-void MainWindow::on_ejectButton_pressed()
-{
-  startRepeating(Eject_Key);
-}
 
-void MainWindow::on_ejectButton_released()
+void MainWindow::receivedExternalWarning(
+  const char *warning)
 {
-  stopRepeating();
+  QMessageBox errBox;
+  errBox.setText(warning);
+  errBox.setIcon(QMessageBox::Warning);
+  errBox.exec();
 }
 
 
@@ -852,14 +302,14 @@ void MainWindow::on_actionSelectKeyset_triggered()
   selectKeysetForm->show();
 }
 
-void MainWindow::on_actionSecondary_Buttons_triggered()
+void MainWindow::on_actionSelect_Device_By_Name_triggered()
 {
-  if (!secondaryForm)
-  {
-    secondaryForm = new PIRSecondaryForm(this);
-  }
+  selectDeviceForm->show();
+}
 
-  secondaryForm->show();
+void MainWindow::on_actionPreferences_triggered()
+{
+  preferencesForm->show();
 }
 
 void MainWindow::on_actionAbout_triggered()
@@ -903,7 +353,6 @@ void MainWindow::keysetSelectionChanged(
   currentKeyset = kwi->getID();
 
   QSettings settings("pietrzak.org", "Pierogi");
-//  settings.setValue("currentKeyset", currentKeyset);
 
   settings.setValue(
     "currentKeysetMake",
@@ -926,34 +375,11 @@ void MainWindow::finalCleanup()
 }
 
 
-void MainWindow::on_addKeysetButton_clicked()
+void MainWindow::addToFavorites(
+  PIRKeysetWidgetItem *kwi)
 {
-  // Is the current keyset already a favorite?
-  int count = ui->favoriteKeysetsWidget->count();
-  int index = 0;
-  PIRKeysetWidgetItem *kwi = NULL;
-  while (index < count)
-  {
-    kwi = dynamic_cast<PIRKeysetWidgetItem *>(
-      ui->favoriteKeysetsWidget->item(index));
-
-    if (kwi && (kwi->getID() == currentKeyset))
-    {
-      // Current keyset already in list!  No need to continue.
-      return;
-    }
-    ++index;
-  }
-
-  // Ok, add the current keyset to the favorites:
-  PIRMakeName make = myKeysets->getMake(currentKeyset);
-
-  QString name = makeManager.getMakeString(make);
-  name.append(" ");
-  name.append(myKeysets->getDisplayName(currentKeyset));
-
-  ui->favoriteKeysetsWidget->addItem(
-    new PIRKeysetWidgetItem(name, currentKeyset, make));
+  //Add keyset to the favorites:
+  favoritesDialog->addItem(new PIRKeysetWidgetItem(kwi));
 
   // And, add the keyset id to the persistent list:
   QSettings settings("pietrzak.org", "Pierogi");
@@ -963,25 +389,21 @@ void MainWindow::on_addKeysetButton_clicked()
 
   settings.beginWriteArray("favorites");
   settings.setArrayIndex(favSettingsSize);
-//  settings.setValue("keysetID", currentKeyset);
 
   settings.setValue(
     "keysetMake",
-    makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
+    makeManager.getMakeString(kwi->getMake()));
 
-  settings.setValue("keysetName", myKeysets->getDisplayName(currentKeyset));
+  settings.setValue("keysetName", kwi->getInternalName());
 
   settings.endArray();
 }
 
 
-void MainWindow::on_removeKeysetButton_clicked()
+void MainWindow::removeFromFavorites(
+  unsigned int keysetID)
 {
-  // Deleting an item removes it from the list, so just grab the currently
-  // selected item and delete it:
-  QListWidgetItem *item = ui->favoriteKeysetsWidget->currentItem();
-
-  if (item) delete item;
+  favoritesDialog->removeItem(keysetID);
 
   // Remove this item from the persistent list.  Well, actually, it seems a
   // little more convenient to just blow away the existing list of favorites
@@ -991,7 +413,7 @@ void MainWindow::on_removeKeysetButton_clicked()
 
   settings.remove("favorites");
 
-  int count = ui->favoriteKeysetsWidget->count();
+  int count = favoritesDialog->getCount();
 
   // If the count is empty, we can stop right here:
   if (count == 0) return;
@@ -1002,11 +424,9 @@ void MainWindow::on_removeKeysetButton_clicked()
   settings.beginWriteArray("favorites");
   while (index < count)
   {
-    kwi = dynamic_cast<PIRKeysetWidgetItem *>(
-      ui->favoriteKeysetsWidget->item(index));
+    kwi = favoritesDialog->getItem(index);
 
     settings.setArrayIndex(index);
-//    settings.setValue("keysetID", kwi->getID());
     id = kwi->getID();
 
     settings.setValue(
@@ -1020,6 +440,8 @@ void MainWindow::on_removeKeysetButton_clicked()
   settings.endArray();
 }
 
+
+/*
 void MainWindow::populateFavorites()
 {
   QSettings settings("pietrzak.org", "Pierogi");
@@ -1042,7 +464,7 @@ void MainWindow::populateFavorites()
     if (kwi)
     {
       // Keyset does exist, so continue:
-      ui->favoriteKeysetsWidget->addItem(kwi);
+      favoritesDialog->addItem(kwi);
     }
 
     ++index;
@@ -1050,6 +472,7 @@ void MainWindow::populateFavorites()
 
   settings.endArray();
 }
+*/
 
 
 void MainWindow::startRepeating(
@@ -1064,6 +487,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);
@@ -1071,69 +507,82 @@ void MainWindow::stopRepeating()
 }
 
 
-QWidget *MainWindow::getSecondaryWindow()
+void MainWindow::selectPrevFavKeyset()
 {
-  return secondaryForm;
+  favoritesDialog->selectPrevFavKeyset();
 }
 
 
-void MainWindow::selectPrevFavKeyset()
+void MainWindow::selectNextFavKeyset()
 {
-  int size = ui->favoriteKeysetsWidget->count();
+  favoritesDialog->selectNextFavKeyset();
+}
 
-  if (size == 0)
-  {
-    // No favorites, so nothing to do!
-    return;
-  }
 
-  int position = ui->favoriteKeysetsWidget->currentRow();
+void MainWindow::insertCornerButtons()
+{
+  // Set up the dialog boxes:
+  PIRTabsChoiceDialog *tcd = new PIRTabsChoiceDialog(this);
+//  favoritesDialog = new PIRFavoritesDialog(this);
 
-  --position;
-  if (position < 0)
-  {
-    position = size - 1;
-  }
+  // Next, set up the corner buttons:
+  QPushButton *button =
+    new QPushButton(QIcon(":/icons/folder_plus_icon&32.png"), "");
 
-  ui->favoriteKeysetsWidget->setCurrentRow(
-    position,
-    QItemSelectionModel::ClearAndSelect);
+  button->setFlat(true);
 
-  keysetSelectionChanged(ui->favoriteKeysetsWidget->currentItem());
+  connect(
+    button,
+    SIGNAL(clicked()),
+    tcd,
+    SLOT(exec()),
+    Qt::QueuedConnection);
+
+  ui->mainTabWidget->setCornerWidget(button, Qt::TopRightCorner);
+
+  button =
+    new QPushButton(QIcon(":/icons/align_just_icon&32.png"), "");
+
+  button->setFlat(true);
+
+  connect(
+    button,
+    SIGNAL(clicked()),
+    favoritesDialog,
+    SLOT(exec()),
+    Qt::QueuedConnection);
 
-  // Tell the user about the change:
-  QMaemo5InformationBox::information(
-    0,
-    ui->favoriteKeysetsWidget->item(position)->text());
+  ui->mainTabWidget->setCornerWidget(button, Qt::TopLeftCorner);
 }
 
 
-void MainWindow::selectNextFavKeyset()
+void MainWindow::disableUpdates()
 {
-  int size = ui->favoriteKeysetsWidget->count();
+  ui->mainTabWidget->setUpdatesEnabled(false);
+}
 
-  if (size == 0)
-  {
-    // No favorites, so just return:
-    return;
-  }
 
-  int position = ui->favoriteKeysetsWidget->currentRow();
+void MainWindow::enableUpdates()
+{
+  ui->mainTabWidget->setUpdatesEnabled(true);
+}
 
-  ++position;
-  if (position == size)
-  {
-    position = 0;
-  }
 
-  ui->favoriteKeysetsWidget->setCurrentRow(
-    position,
-    QItemSelectionModel::ClearAndSelect);
+void MainWindow::clearTabs()
+{
+  ui->mainTabWidget->clear();
+}
 
-  keysetSelectionChanged(ui->favoriteKeysetsWidget->currentItem());
 
-  // Tell the user about the change:
-  QMaemo5InformationBox::information(
-    0,
-    ui->favoriteKeysetsWidget->item(position)->text());
+void MainWindow::addTab(
+  QWidget *page,
+  QString label)
+{
+  ui->mainTabWidget->addTab(page, label);
+}
+
+void MainWindow::setupTabs(
+  PIRTabBarName name)
+{
+  myPanels->setupTabs(name);
 }