Change back to real tabbed window, updates keysets
[pierogi] / mainwindow.cpp
index 25a348a..78744b4 100644 (file)
@@ -1,19 +1,30 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
-#include "pirkeysetwidgetitem.h"
-
-//#include "pirexception.h"
 
 #include <QtCore/QCoreApplication>
 #include <QMutex>
 #include <QtGui/QMessageBox>
+#include <QPushButton>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QScrollArea>
 #include <QSettings>
-//#include <QDesktopServices>
-//#include <QUrl>
 
-//#include <iostream>
+#include "pirkeysetmetadata.h"
+
+#include "pirkeysetwidgetitem.h"
+#include "pirselectkeysetform.h"
+#include "pirselectdeviceform.h"
+#include "pirpreferencesform.h"
+#include "pirdocumentationform.h"
+#include "piraboutform.h"
+#include "dialogs/pirtabschoicedialog.h"
+
+#include "pirkeysetmanager.h"
+#include "pirpanelmanager.h"
 
 //#define DEBUGGING
+//#include <iostream>
 
 // Some ugly globals used for thread communications:
 
@@ -26,6 +37,7 @@ QMutex commandIFMutex;
 bool stopRepeatingFlag = false;
 QMutex stopRepeatingMutex;
 
+
 extern PIRMakeMgr makeManager;
 
 
@@ -33,1153 +45,255 @@ 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:
-  myKeysets = new PIRKeysetManager(this);
-
-  // Set up the keyset selection window:
-  selectKeysetForm = new PIRSelectKeysetForm(this);
-
-  // Set up the secondary buttons window:
-  secondaryForm = new PIRSecondaryForm(this);
-
-  myKeysets->populateGuiWidget(selectKeysetForm);
-
-  // Remember any favorites the user has already set:
-  populateFavorites();
-
-  QSettings settings("pietrzak.org", "Pierogi");
-  if (settings.contains("currentKeysetName"))
-  {
-    myKeysets->findKeysetID(
-      settings.value("currentKeysetMake").toString(),
-      settings.value("currentKeysetName").toString(),
-      currentKeyset);
-//    currentKeyset = settings.value("currentKeyset").toInt();
-  }
-
-  enableButtons();
-  secondaryForm->enableButtons(myKeysets, currentKeyset);
-
-  connect(
-    ui->favoriteKeysetsWidget,
-//    SIGNAL(itemActivated(QListWidgetItem *)),
-    SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
-    this,
-    SLOT(keysetSelectionChanged(QListWidgetItem *)),
-    Qt::QueuedConnection);
-
-  // Make sure the two selection lists don't show different selections:
-  QListWidget *klw = selectKeysetForm->getKeysetListWidget();
-  connect(
-    ui->favoriteKeysetsWidget,
-    SIGNAL(itemActivated(QListWidgetItem *)),
-    klw,
-    SLOT(clearSelection()),
-    Qt::QueuedConnection);
-
-  connect(
-    klw,
-    SIGNAL(itemActivated(QListWidgetItem *)),
-    ui->favoriteKeysetsWidget,
-    SLOT(clearSelection()),
-    Qt::QueuedConnection);
-
-#ifndef DEBUGGING
-  // The PIRModprobe object should take care of setting up and shutting down
-  // the lirc_rx51 kernel module, if necessary:
-  if (modprobeObj.loadRX51Module() != 0)
-  {
-    // Couldn't load module, quit:
-    QMessageBox errBox;
-    errBox.setText("Couldn't load lirc_rx51 kernel module!");
-    errBox.setIcon(QMessageBox::Warning);
-    errBox.exec();
-//    throw; // Need a clean way to exit here!!!
-  }
-#endif
-}
-
-
-MainWindow::~MainWindow()
-{
-  delete myKeysets;
-  if (selectKeysetForm) delete selectKeysetForm;
-  if (documentationForm) delete documentationForm;
-  if (aboutForm) delete aboutForm;
-  delete ui;
-}
-
-
-void MainWindow::setOrientation(ScreenOrientation orientation)
-{
-#if defined(Q_OS_SYMBIAN)
-    // If the version of Qt on the device is < 4.7.2, that attribute won't work
-    if (orientation != ScreenOrientationAuto) {
-        const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
-        if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
-            qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
-            return;
-        }
-    }
-#endif // Q_OS_SYMBIAN
-
-    Qt::WidgetAttribute attribute;
-    switch (orientation) {
-#if QT_VERSION < 0x040702
-    // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
-    case ScreenOrientationLockPortrait:
-        attribute = static_cast<Qt::WidgetAttribute>(128);
-        break;
-    case ScreenOrientationLockLandscape:
-        attribute = static_cast<Qt::WidgetAttribute>(129);
-        break;
-    default:
-    case ScreenOrientationAuto:
-        attribute = static_cast<Qt::WidgetAttribute>(130);
-        break;
-#else // QT_VERSION < 0x040702
-    case ScreenOrientationLockPortrait:
-        attribute = Qt::WA_LockPortraitOrientation;
-        break;
-    case ScreenOrientationLockLandscape:
-        attribute = Qt::WA_LockLandscapeOrientation;
-        break;
-    default:
-    case ScreenOrientationAuto:
-        attribute = Qt::WA_AutoOrientation;
-        break;
-#endif // QT_VERSION < 0x040702
-    };
-    setAttribute(attribute, true);
-}
-
-void MainWindow::showExpanded()
-{
-#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
-    showFullScreen();
-#elif defined(Q_WS_MAEMO_5)
-    showMaximized();
-#else
-    show();
-#endif
-}
-
-
-void MainWindow::enableButtons()
-{
-  // 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));
-
-  // 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 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));
-  emit muteEnabled(myKeysets->hasKey(currentKeyset, Mute_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));
-
-/*
-  // Media2 keys:
-  emit discTitleEnabled(myKeysets->hasKey(currentKeyset, DiscTitle_Key));
-  emit discSelectEnabled(myKeysets->hasKey(currentKeyset, NextDisc_Key));
-  emit vhsSpeedEnabled(myKeysets->hasKey(currentKeyset, VHSSpeed_Key));
-  emit trackingMinusEnabled(myKeysets->hasKey(currentKeyset, TrackingMinus_Key));
-  emit trackingPlusEnabled(myKeysets->hasKey(currentKeyset, TrackingPlus_Key));
-  emit autoTrackingEnabled(myKeysets->hasKey(currentKeyset, AutoTracking_Key));
-  emit pageUpEnabled(myKeysets->hasKey(currentKeyset, PageUp_Key));
-  emit pageDownEnabled(myKeysets->hasKey(currentKeyset, PageDown_Key));
-  emit slowEnabled(myKeysets->hasKey(currentKeyset, Slow_Key));
-  emit slowMinusEnabled(myKeysets->hasKey(currentKeyset, SlowMinus_Key));
-  emit slowPlusEnabled(myKeysets->hasKey(currentKeyset, SlowPlus_Key));
-  emit programEnabled(myKeysets->hasKey(currentKeyset, Program_Key));
-  emit tunerBandEnabled(myKeysets->hasKey(currentKeyset, TunerBand_Key));
-  emit repeatEnabled(myKeysets->hasKey(currentKeyset, Repeat_Key));
-  emit repeatABEnabled(myKeysets->hasKey(currentKeyset, RepeatAB_Key));
-  emit randomEnabled(myKeysets->hasKey(currentKeyset, Random_Key));
-
-  // TV Keys:
-  emit pictureModeEnabled(myKeysets->hasKey(currentKeyset, PictureMode_Key));
-  emit soundModeEnabled(myKeysets->hasKey(currentKeyset, SoundMode_Key));
-  emit liveTVEnabled(myKeysets->hasKey(currentKeyset, LiveTV_Key));
-  emit favoritesEnabled(myKeysets->hasKey(currentKeyset, Favorites_Key));
-  emit teletextEnabled(myKeysets->hasKey(currentKeyset, Teletext_Key));
-  emit teletextHoldEnabled(myKeysets->hasKey(currentKeyset, TeletextHold_Key));
-  emit teletextRevealEnabled(myKeysets->hasKey(currentKeyset, TeletextReveal_Key));
-  emit teletextSizeEnabled(myKeysets->hasKey(currentKeyset, TeletextSize_Key));
-  emit pipEnabled(myKeysets->hasKey(currentKeyset, PIP_Key));
-  emit pipSwapEnabled(myKeysets->hasKey(currentKeyset, PIPSwap_Key));
-  emit pipMoveEnabled(myKeysets->hasKey(currentKeyset, PIPMove_Key));
-  emit pipSourceEnabled(myKeysets->hasKey(currentKeyset, PIPSource_Key));
-  emit pipChannelUpEnabled(myKeysets->hasKey(currentKeyset, PIPChannelUp_Key));
-  emit pipChannelDownEnabled(myKeysets->hasKey(currentKeyset, PIPChannelDown_Key));
-  emit pipPauseEnabled(myKeysets->hasKey(currentKeyset, PIPPause_Key));
-  emit pipSizeEnabled(myKeysets->hasKey(currentKeyset, PIPSize_Key));
-*/
-}
-
-
-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();
-}
-
-
-// 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_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();
-}
-
-void MainWindow::on_muteButton_pressed()
-{
-  startRepeating(Mute_Key);
-}
-
-void MainWindow::on_muteButton_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();
-}
-
-void MainWindow::on_fastForwardButton_pressed()
-{
-  startRepeating(FastForward_Key);
-}
-
-void MainWindow::on_fastForwardButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_playButton_pressed()
-{
-  startRepeating(Play_Key);
-}
-
-void MainWindow::on_playButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_pauseButton_pressed()
-{
-  startRepeating(Pause_Key);
-}
-
-void MainWindow::on_pauseButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_stopButton_pressed()
-{
-  startRepeating(Stop_Key);
-}
-
-void MainWindow::on_stopButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_ejectButton_pressed()
-{
-  startRepeating(Eject_Key);
-}
-
-void MainWindow::on_ejectButton_released()
-{
-  stopRepeating();
-}
-
-
-/*
-// Media2 tab slots:
-
-void MainWindow::on_discTitleButton_pressed()
-{
-  startRepeating(DiscTitle_Key);
-}
-
-void MainWindow::on_discTitleButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_discSelectButton_pressed()
-{
-  startRepeating(NextDisc_Key);
-}
-
-void MainWindow::on_discSelectButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_vhsSpeedButton_pressed()
-{
-  startRepeating(VHSSpeed_Key);
-}
-
-void MainWindow::on_vhsSpeedButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_trackingPlusButton_pressed()
-{
-  startRepeating(TrackingPlus_Key);
-}
-
-void MainWindow::on_trackingPlusButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_trackingMinusButton_pressed()
-{
-  startRepeating(TrackingMinus_Key);
-}
-
-void MainWindow::on_trackingMinusButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_autoTrackingButton_pressed()
-{
-  startRepeating(AutoTracking_Key);
-}
-
-void MainWindow::on_autoTrackingButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_pageUpButton_pressed()
-{
-  startRepeating(PageUp_Key);
-}
-
-void MainWindow::on_pageUpButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_pageDownButton_pressed()
-{
-  startRepeating(PageDown_Key);
-}
-
-void MainWindow::on_pageDownButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_slowButton_pressed()
-{
-  startRepeating(Slow_Key);
-}
-
-void MainWindow::on_slowButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_slowMinusButton_pressed()
-{
-  startRepeating(SlowMinus_Key);
-}
-
-void MainWindow::on_slowMinusButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_slowPlusButton_pressed()
-{
-  startRepeating(SlowPlus_Key);
-}
-
-void MainWindow::on_slowPlusButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_programButton_pressed()
-{
-  startRepeating(Program_Key);
-}
-
-void MainWindow::on_programButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_tunerBandButton_pressed()
-{
-  startRepeating(TunerBand_Key);
-}
-
-void MainWindow::on_tunerBandButton_released()
-{
-  stopRepeating();
-}
-
-void MainWindow::on_repeatButton_pressed()
-{
-  startRepeating(Repeat_Key);
-}
-
-void MainWindow::on_repeatButton_released()
-{
-  stopRepeating();
-}
+  setAttribute(Qt::WA_Maemo5StackedWindow);
 
-void MainWindow::on_repeatABButton_pressed()
-{
-  startRepeating(RepeatAB_Key);
-}
+  // Create the managers:
+  myKeysets = new PIRKeysetManager();
+  myPanels = new PIRPanelManager(this);
 
-void MainWindow::on_repeatABButton_released()
-{
-  stopRepeating();
-}
+  // Display the panels:
+  myPanels->updateTabSet();
 
-void MainWindow::on_randomButton_pressed()
-{
-  startRepeating(Random_Key);
-}
+  // Add the corner button:
+  insertCornerButton();
 
-void MainWindow::on_randomButton_released()
-{
-  stopRepeating();
-}
+  // Construct the rest of the forms:
+  selectKeysetForm = new PIRSelectKeysetForm(this);
+  myKeysets->populateSelectionWidget(selectKeysetForm);
 
+  selectDeviceForm = new PIRSelectDeviceForm(this);
+  PIRKeysetMetaData::populateDevices(selectDeviceForm);
 
-// TV Slots:
+  preferencesForm = new PIRPreferencesForm(this, myKeysets);
 
-void MainWindow::on_pictureModeButton_pressed()
-{
-  startRepeating(PictureMode_Key);
-}
+  // Remember any favorites the user has already set:
+  populateFavorites();
 
-void MainWindow::on_pictureModeButton_released()
-{
-  stopRepeating();
-}
+  // Retrieve the user's preferences:
+  QSettings settings("pietrzak.org", "Pierogi");
+  if (settings.contains("currentKeysetName"))
+  {
+    myKeysets->findKeysetID(
+      settings.value("currentKeysetMake").toString(),
+      settings.value("currentKeysetName").toString(),
+      currentKeyset);
+  }
 
-void MainWindow::on_soundModeButton_pressed()
-{
-  startRepeating(SoundMode_Key);
-}
+  enableButtons();
 
-void MainWindow::on_soundModeButton_released()
-{
-  stopRepeating();
-}
+  QListWidget *fkw = myPanels->getFavoritesListWidget();
 
-void MainWindow::on_liveTVButton_pressed()
-{
-  startRepeating(LiveTV_Key);
-}
+  connect(
+    fkw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    this,
+    SLOT(keysetSelectionChanged(QListWidgetItem *)),
+    Qt::QueuedConnection);
 
-void MainWindow::on_liveTVButton_released()
-{
-  stopRepeating();
-}
+  // Make sure the three selection lists don't show different selections:
+  QListWidget *klw = selectKeysetForm->getKeysetListWidget();
+  QListWidget *dlw = selectDeviceForm->getDeviceListWidget();
 
-void MainWindow::on_favoritesButton_pressed()
-{
-  startRepeating(Favorites_Key);
-}
+  // favorites -> keyset name
+  connect(
+    fkw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    klw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
 
-void MainWindow::on_favoritesButton_released()
-{
-  stopRepeating();
-}
+  // favorites -> device name
+  connect(
+    fkw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    dlw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
 
-void MainWindow::on_teletextButton_pressed()
-{
-  startRepeating(Teletext_Key);
-}
+  // keyset name -> favorites
+  connect(
+    klw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    fkw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
 
-void MainWindow::on_teletextButton_released()
-{
-  stopRepeating();
-}
+  // device name -> favorites
+  connect(
+    dlw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    fkw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
 
-void MainWindow::on_teletextHoldButton_pressed()
-{
-  startRepeating(TeletextHold_Key);
-}
+  // keyset name -> device name
+  connect(
+    klw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    dlw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
 
-void MainWindow::on_teletextHoldButton_released()
-{
-  stopRepeating();
-}
+  // device name -> keyset name
+  connect(
+    dlw,
+    SIGNAL(itemActivated(QListWidgetItem *)),
+    klw,
+    SLOT(clearSelection()),
+    Qt::QueuedConnection);
 
-void MainWindow::on_teletextRevealButton_pressed()
-{
-  startRepeating(TeletextReveal_Key);
+#ifndef DEBUGGING
+  // The PIRModprobe object should take care of setting up and shutting down
+  // the lirc_rx51 kernel module, if necessary:
+  if (modprobeObj.loadRX51Module() != 0)
+  {
+    // Couldn't load module, quit:
+    QMessageBox errBox;
+    errBox.setText("Couldn't load lirc_rx51 kernel module!");
+    errBox.setIcon(QMessageBox::Warning);
+    errBox.exec();
+//    throw; // Need a clean way to exit here!!!
+  }
+#endif
 }
 
-void MainWindow::on_teletextRevealButton_released()
-{
-  stopRepeating();
-}
 
-void MainWindow::on_teletextSizeButton_pressed()
+MainWindow::~MainWindow()
 {
-  startRepeating(TeletextSize_Key);
+  delete myKeysets;
+  if (selectKeysetForm) delete selectKeysetForm;
+  if (selectDeviceForm) delete selectDeviceForm;
+//  if (panelSelectionForm) delete panelSelectionForm;
+  if (documentationForm) delete documentationForm;
+  if (aboutForm) delete aboutForm;
+  delete ui;
 }
 
-void MainWindow::on_teletextSizeButton_released()
-{
-  stopRepeating();
-}
 
-void MainWindow::on_pipOnOffButton_pressed()
+void MainWindow::setOrientation(ScreenOrientation orientation)
 {
-  startRepeating(PIP_Key);
-}
+#if defined(Q_OS_SYMBIAN)
+    // If the version of Qt on the device is < 4.7.2, that attribute won't work
+    if (orientation != ScreenOrientationAuto) {
+        const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
+        if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
+            qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
+            return;
+        }
+    }
+#endif // Q_OS_SYMBIAN
 
-void MainWindow::on_pipOnOffButton_released()
-{
-  stopRepeating();
+    Qt::WidgetAttribute attribute;
+    switch (orientation) {
+#if QT_VERSION < 0x040702
+    // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
+    case ScreenOrientationLockPortrait:
+        attribute = static_cast<Qt::WidgetAttribute>(128);
+        break;
+    case ScreenOrientationLockLandscape:
+        attribute = static_cast<Qt::WidgetAttribute>(129);
+        break;
+    default:
+    case ScreenOrientationAuto:
+        attribute = static_cast<Qt::WidgetAttribute>(130);
+        break;
+#else // QT_VERSION < 0x040702
+    case ScreenOrientationLockPortrait:
+        attribute = Qt::WA_LockPortraitOrientation;
+        break;
+    case ScreenOrientationLockLandscape:
+        attribute = Qt::WA_LockLandscapeOrientation;
+        break;
+    default:
+    case ScreenOrientationAuto:
+        attribute = Qt::WA_AutoOrientation;
+        break;
+#endif // QT_VERSION < 0x040702
+    };
+    setAttribute(attribute, true);
 }
 
-void MainWindow::on_pipSwapButton_pressed()
+void MainWindow::showExpanded()
 {
-  startRepeating(PIPSwap_Key);
+#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
+    showFullScreen();
+#elif defined(Q_WS_MAEMO_5)
+    showMaximized();
+#else
+    show();
+#endif
 }
 
-void MainWindow::on_pipSwapButton_released()
-{
-  stopRepeating();
-}
 
-void MainWindow::on_pipPositionButton_pressed()
+void MainWindow::enableButtons()
 {
-  startRepeating(PIPMove_Key);
-}
+  // Just to be sure, check to see if the keyset has been populated:
+  myKeysets->populateKeyset(this, currentKeyset);
 
-void MainWindow::on_pipPositionButton_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_pipSourceButton_pressed()
-{
-  startRepeating(PIPSource_Key);
-}
 
-void MainWindow::on_pipSourceButton_released()
+void MainWindow::useMainPanel()
 {
-  stopRepeating();
+  myPanels->useMainPanel();
 }
 
-void MainWindow::on_pipChannelUpButton_pressed()
-{
-  startRepeating(PIPChannelUp_Key);
-}
 
-void MainWindow::on_pipChannelUpButton_released()
+void MainWindow::useAltMainPanel()
 {
-  stopRepeating();
+  myPanels->useAltMainPanel();
 }
 
-void MainWindow::on_pipChannelDownButton_pressed()
-{
-  startRepeating(PIPChannelDown_Key);
-}
 
-void MainWindow::on_pipChannelDownButton_released()
+QString MainWindow::getCurrentMake()
 {
-  stopRepeating();
+  return makeManager.getMakeString(myKeysets->getMake(currentKeyset));
 }
 
-void MainWindow::on_pipPauseButton_pressed()
-{
-  startRepeating(PIPPause_Key);
-}
 
-void MainWindow::on_pipPauseButton_released()
+QString MainWindow::getCurrentName()
 {
-  stopRepeating();
+  return myKeysets->getDisplayName(currentKeyset);
 }
 
-void MainWindow::on_pipSizeButton_pressed()
-{
-  startRepeating(PIPSize_Key);
-}
 
-void MainWindow::on_pipSizeButton_released()
+void MainWindow::receivedExternalWarning(
+  const char *warning)
 {
-  stopRepeating();
+  QMessageBox errBox;
+  errBox.setText(warning);
+  errBox.setIcon(QMessageBox::Warning);
+  errBox.exec();
 }
-*/
-
 
 
 // Menu actions:
@@ -1189,14 +303,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()
@@ -1225,16 +339,21 @@ 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();
 
   QSettings settings("pietrzak.org", "Pierogi");
-//  settings.setValue("currentKeyset", currentKeyset);
 
   settings.setValue(
     "currentKeysetMake",
@@ -1245,7 +364,6 @@ void MainWindow::keysetSelectionChanged(
     myKeysets->getDisplayName(currentKeyset));
 
   enableButtons();
-  secondaryForm->enableButtons(myKeysets, currentKeyset);
 }
 
 
@@ -1258,16 +376,17 @@ void MainWindow::finalCleanup()
 }
 
 
-void MainWindow::on_addKeysetButton_clicked()
+void MainWindow::addCurrentKeyset(
+  QListWidget *qlw)
 {
   // Is the current keyset already a favorite?
-  int count = ui->favoriteKeysetsWidget->count();
+  int count = qlw->count();
   int index = 0;
   PIRKeysetWidgetItem *kwi = NULL;
   while (index < count)
   {
     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
-      ui->favoriteKeysetsWidget->item(index));
+      qlw->item(index));
 
     if (kwi && (kwi->getID() == currentKeyset))
     {
@@ -1284,8 +403,7 @@ void MainWindow::on_addKeysetButton_clicked()
   name.append(" ");
   name.append(myKeysets->getDisplayName(currentKeyset));
 
-  ui->favoriteKeysetsWidget->addItem(
-    new PIRKeysetWidgetItem(name, currentKeyset, make));
+  qlw->addItem(new PIRKeysetWidgetItem(name, currentKeyset, make));
 
   // And, add the keyset id to the persistent list:
   QSettings settings("pietrzak.org", "Pierogi");
@@ -1295,7 +413,6 @@ void MainWindow::on_addKeysetButton_clicked()
 
   settings.beginWriteArray("favorites");
   settings.setArrayIndex(favSettingsSize);
-//  settings.setValue("keysetID", currentKeyset);
 
   settings.setValue(
     "keysetMake",
@@ -1307,11 +424,12 @@ void MainWindow::on_addKeysetButton_clicked()
 }
 
 
-void MainWindow::on_removeKeysetButton_clicked()
+void MainWindow::removeFavoriteKeyset(
+  QListWidget *qlw)
 {
   // Deleting an item removes it from the list, so just grab the currently
   // selected item and delete it:
-  QListWidgetItem *item = ui->favoriteKeysetsWidget->currentItem();
+  QListWidgetItem *item = qlw->currentItem();
 
   if (item) delete item;
 
@@ -1323,7 +441,7 @@ void MainWindow::on_removeKeysetButton_clicked()
 
   settings.remove("favorites");
 
-  int count = ui->favoriteKeysetsWidget->count();
+  int count = qlw->count();
 
   // If the count is empty, we can stop right here:
   if (count == 0) return;
@@ -1334,11 +452,9 @@ void MainWindow::on_removeKeysetButton_clicked()
   settings.beginWriteArray("favorites");
   while (index < count)
   {
-    kwi = dynamic_cast<PIRKeysetWidgetItem *>(
-      ui->favoriteKeysetsWidget->item(index));
+    kwi = dynamic_cast<PIRKeysetWidgetItem *>(qlw->item(index));
 
     settings.setArrayIndex(index);
-//    settings.setValue("keysetID", kwi->getID());
     id = kwi->getID();
 
     settings.setValue(
@@ -1352,6 +468,7 @@ void MainWindow::on_removeKeysetButton_clicked()
   settings.endArray();
 }
 
+
 void MainWindow::populateFavorites()
 {
   QSettings settings("pietrzak.org", "Pierogi");
@@ -1360,31 +477,21 @@ void MainWindow::populateFavorites()
   int index = 0;
   QString make;
   QString name;
-//  unsigned int id;
   PIRKeysetWidgetItem *kwi;
 
   while (index < size)
   {
     settings.setArrayIndex(index);
-//    id = settings.value("keysetID").toInt();
     make = settings.value("keysetMake").toString();
     name = settings.value("keysetName").toString();
 
     kwi = myKeysets->makeKeysetItem(make, name);
 
     // Did the item creation work?
-//    if (myKeysets->keysetExists(id))
     if (kwi)
     {
       // Keyset does exist, so continue:
-//      make = myKeysets->getMake(id);
-//      name = makeManager.getMakeString(make);
-//      name.append(" ");
-//      name.append(myKeysets->getDisplayName(id));
-//    kwi = new PIRKeysetWidgetItem(name, id, make);
-//    myKeysets->populateDeviceTypes(kwi, id);
-//      ui->favoriteKeysetsWidget->addItem(new PIRKeysetWidgetItem(name, id, make));
-      ui->favoriteKeysetsWidget->addItem(kwi);
+      myPanels->addFavoritesItem(kwi);
     }
 
     ++index;
@@ -1406,9 +513,87 @@ 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);
   stopRepeatingFlag = true;
 }
 
+
+void MainWindow::selectPrevFavKeyset()
+{
+  myPanels->selectPrevFavKeyset();
+}
+
+
+void MainWindow::selectNextFavKeyset()
+{
+  myPanels->selectNextFavKeyset();
+}
+
+
+void MainWindow::insertCornerButton()
+{
+  // Set up the dialog box:
+  PIRTabsChoiceDialog *tcd = new PIRTabsChoiceDialog(this);
+
+  // Next, set up the corner button itself:
+  QPushButton *button =
+    new QPushButton(QIcon(":/icons/align_just_icon&32.png"), "");
+
+  button->setFlat(true);
+
+  connect(
+    button,
+    SIGNAL(clicked()),
+    tcd,
+    SLOT(exec()),
+    Qt::QueuedConnection);
+
+  ui->mainTabWidget->setCornerWidget(button);
+}
+
+
+void MainWindow::disableUpdates()
+{
+  ui->mainTabWidget->setUpdatesEnabled(false);
+}
+
+
+void MainWindow::enableUpdates()
+{
+  ui->mainTabWidget->setUpdatesEnabled(true);
+}
+
+
+void MainWindow::clearTabs()
+{
+  ui->mainTabWidget->clear();
+}
+
+
+void MainWindow::addTab(
+  QWidget *page,
+  QString label)
+{
+  ui->mainTabWidget->addTab(page, label);
+}
+
+void MainWindow::setupTabs(
+  PIRTabBarName name)
+{
+  myPanels->setupTabs(name);
+}