Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Pierogi
Summary Forums Tracker Lists Tasks Docs News SCM Files
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
4 #include <QtCore/QCoreApplication>
5 #include <QMutex>
6 #include <QtGui/QMessageBox>
7 #include <QSettings>
9 #include "pirkeysetwidgetitem.h"
10 #include "pirselectkeysetform.h"
11 #include "pirsecondaryform.h"
12 #include "pirdocumentationform.h"
13 #include "piraboutform.h"
14 #include "pirkeysetmanager.h"
16 //#define DEBUGGING
18 // Some ugly globals used for thread communications:
20 // A global to show that a command is being processed:
21 bool commandInFlight = false;
22 QMutex commandIFMutex;
24 // The stopRepeatingFlag boolean is the method used to tell running commands
25 // in the worker thread to stop:
26 bool stopRepeatingFlag = false;
27 QMutex stopRepeatingMutex;
29 extern PIRMakeMgr makeManager;
32 MainWindow::MainWindow(QWidget *parent)
33   : QMainWindow(parent),
34     ui(new Ui::MainWindow),
35     selectKeysetForm(0),
36     secondaryForm(0),
37     documentationForm(0),
38     aboutForm(0),
39     currentKeyset(0)
40 {
41   ui->setupUi(this);
43   // Make this a Maemo 5 stacked widget:
44   setAttribute(Qt::WA_Maemo5StackedWindow);
46   // Collect the keysets:
47   myKeysets = new PIRKeysetManager(this);
49   // Set up the keyset selection window:
50   selectKeysetForm = new PIRSelectKeysetForm(this);
52   // Set up the secondary buttons window:
53   secondaryForm = new PIRSecondaryForm(this);
55   myKeysets->populateGuiWidget(selectKeysetForm);
57   // Remember any favorites the user has already set:
58   populateFavorites();
60   QSettings settings("pietrzak.org", "Pierogi");
61   if (settings.contains("currentKeysetName"))
62   {
63     myKeysets->findKeysetID(
64       settings.value("currentKeysetMake").toString(),
65       settings.value("currentKeysetName").toString(),
66       currentKeyset);
67 //    currentKeyset = settings.value("currentKeyset").toInt();
68   }
70   enableButtons();
71   secondaryForm->enableButtons(myKeysets, currentKeyset);
73   connect(
74     ui->favoriteKeysetsWidget,
75 //    SIGNAL(itemActivated(QListWidgetItem *)),
76     SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
77     this,
78     SLOT(keysetSelectionChanged(QListWidgetItem *)),
79     Qt::QueuedConnection);
81   // Make sure the two selection lists don't show different selections:
82   QListWidget *klw = selectKeysetForm->getKeysetListWidget();
83   connect(
84     ui->favoriteKeysetsWidget,
85     SIGNAL(itemActivated(QListWidgetItem *)),
86     klw,
87     SLOT(clearSelection()),
88     Qt::QueuedConnection);
90   connect(
91     klw,
92     SIGNAL(itemActivated(QListWidgetItem *)),
93     ui->favoriteKeysetsWidget,
94     SLOT(clearSelection()),
95     Qt::QueuedConnection);
97 #ifndef DEBUGGING
98   // The PIRModprobe object should take care of setting up and shutting down
99   // the lirc_rx51 kernel module, if necessary:
100  
101   if (modprobeObj.loadRX51Module() != 0)
102   {
103     // Couldn't load module, quit:
104     QMessageBox errBox;
105     errBox.setText("Couldn't load lirc_rx51 kernel module!");
106     errBox.setIcon(QMessageBox::Warning);
107     errBox.exec();
108 //    throw; // Need a clean way to exit here!!!
109   }
110 #endif
114 MainWindow::~MainWindow()
116   delete myKeysets;
117   if (selectKeysetForm) delete selectKeysetForm;
118   if (documentationForm) delete documentationForm;
119   if (aboutForm) delete aboutForm;
120   delete ui;
124 void MainWindow::setOrientation(ScreenOrientation orientation)
126 #if defined(Q_OS_SYMBIAN)
127     // If the version of Qt on the device is < 4.7.2, that attribute won't work
128     if (orientation != ScreenOrientationAuto) {
129         const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
130         if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
131             qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
132             return;
133         }
134     }
135 #endif // Q_OS_SYMBIAN
137     Qt::WidgetAttribute attribute;
138     switch (orientation) {
139 #if QT_VERSION < 0x040702
140     // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
141     case ScreenOrientationLockPortrait:
142         attribute = static_cast<Qt::WidgetAttribute>(128);
143         break;
144     case ScreenOrientationLockLandscape:
145         attribute = static_cast<Qt::WidgetAttribute>(129);
146         break;
147     default:
148     case ScreenOrientationAuto:
149         attribute = static_cast<Qt::WidgetAttribute>(130);
150         break;
151 #else // QT_VERSION < 0x040702
152     case ScreenOrientationLockPortrait:
153         attribute = Qt::WA_LockPortraitOrientation;
154         break;
155     case ScreenOrientationLockLandscape:
156         attribute = Qt::WA_LockLandscapeOrientation;
157         break;
158     default:
159     case ScreenOrientationAuto:
160         attribute = Qt::WA_AutoOrientation;
161         break;
162 #endif // QT_VERSION < 0x040702
163     };
164     setAttribute(attribute, true);
167 void MainWindow::showExpanded()
169 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
170     showFullScreen();
171 #elif defined(Q_WS_MAEMO_5)
172     showMaximized();
173 #else
174     show();
175 #endif
179 void MainWindow::enableButtons()
181   // This is going to be a little painful...
182   // Main keys
183   emit powerEnabled(myKeysets->hasKey(currentKeyset, Power_Key));
184   emit volumeUpEnabled(myKeysets->hasKey(currentKeyset, VolumeUp_Key));
185   emit volumeDownEnabled(myKeysets->hasKey(currentKeyset, VolumeDown_Key));
186   emit channelUpEnabled(myKeysets->hasKey(currentKeyset, ChannelUp_Key));
187   emit channelDownEnabled(myKeysets->hasKey(currentKeyset, ChannelDown_Key));
188   emit muteEnabled(myKeysets->hasKey(currentKeyset, Mute_Key));
190   // Main tab labels:
191   emit keysetMakeChanged(
192     makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
193   emit keysetNameChanged(myKeysets->getDisplayName(currentKeyset));
195   // Utility keys:
196   emit redEnabled(myKeysets->hasKey(currentKeyset, Red_Key));
197   emit greenEnabled(myKeysets->hasKey(currentKeyset, Green_Key));
198   emit yellowEnabled(myKeysets->hasKey(currentKeyset, Yellow_Key));
199   emit blueEnabled(myKeysets->hasKey(currentKeyset, Blue_Key));
200   emit pictureModeEnabled(myKeysets->hasKey(currentKeyset, PictureMode_Key));
201   emit soundModeEnabled(myKeysets->hasKey(currentKeyset, SoundMode_Key));
202   emit aspectRatioEnabled(myKeysets->hasKey(currentKeyset, AspectRatio_Key));
203 //  emit surroundEnabled(myKeysets->hasKey(currentKeyset, Surround_Key));
204   emit audioEnabled(myKeysets->hasKey(currentKeyset, Audio_Key));
205   emit infoEnabled(myKeysets->hasKey(currentKeyset, Info_Key));
206   emit captionsEnabled(myKeysets->hasKey(currentKeyset, Captions_Key));
207   emit sleepEnabled(myKeysets->hasKey(currentKeyset, Sleep_Key));
208   emit inputEnabled(myKeysets->hasKey(currentKeyset, Input_Key));
210   // Keypad keys
211   emit zeroEnabled(myKeysets->hasKey(currentKeyset, Zero_Key));
212   emit oneEnabled(myKeysets->hasKey(currentKeyset, One_Key));
213   emit twoEnabled(myKeysets->hasKey(currentKeyset, Two_Key));
214   emit threeEnabled(myKeysets->hasKey(currentKeyset, Three_Key));
215   emit fourEnabled(myKeysets->hasKey(currentKeyset, Four_Key));
216   emit fiveEnabled(myKeysets->hasKey(currentKeyset, Five_Key));
217   emit sixEnabled(myKeysets->hasKey(currentKeyset, Six_Key));
218   emit sevenEnabled(myKeysets->hasKey(currentKeyset, Seven_Key));
219   emit eightEnabled(myKeysets->hasKey(currentKeyset, Eight_Key));
220   emit nineEnabled(myKeysets->hasKey(currentKeyset, Nine_Key));
221   emit enterEnabled(myKeysets->hasKey(currentKeyset, Enter_Key));
222   emit clearEnabled(myKeysets->hasKey(currentKeyset, Clear_Key));
223   emit dashEnabled(myKeysets->hasKey(currentKeyset, Dash_Key));
224   emit plusOneHundredEnabled(myKeysets->hasKey(currentKeyset, PlusOneHundred_Key));
225   emit doubleDigitEnabled(myKeysets->hasKey(currentKeyset, DoubleDigit_Key));
226   emit prevChannelEnabled(myKeysets->hasKey(currentKeyset, PrevChannel_Key));
228   // Menu keys:
229   emit upEnabled(myKeysets->hasKey(currentKeyset, Up_Key));
230   emit downEnabled(myKeysets->hasKey(currentKeyset, Down_Key));
231   emit leftEnabled(myKeysets->hasKey(currentKeyset, Left_Key));
232   emit rightEnabled(myKeysets->hasKey(currentKeyset, Right_Key));
233   emit selectEnabled(myKeysets->hasKey(currentKeyset, Select_Key));
234   emit menuEnabled(myKeysets->hasKey(currentKeyset, Menu_Key));
235   emit exitEnabled(myKeysets->hasKey(currentKeyset, Exit_Key));
236   emit guideEnabled(myKeysets->hasKey(currentKeyset, Guide_Key));
237   emit discMenuEnabled(myKeysets->hasKey(currentKeyset, DiscMenu_Key));
239   // Media keys:
240   emit nextEnabled(myKeysets->hasKey(currentKeyset, Next_Key));
241   emit previousEnabled(myKeysets->hasKey(currentKeyset, Previous_Key));
242   emit advanceEnabled(myKeysets->hasKey(currentKeyset, Advance_Key));
243   emit replayEnabled(myKeysets->hasKey(currentKeyset, Replay_Key));
244   emit stepForwardEnabled(myKeysets->hasKey(currentKeyset, StepForward_Key));
245   emit stepBackEnabled(myKeysets->hasKey(currentKeyset, StepBack_Key));
246   emit fastForwardEnabled(myKeysets->hasKey(currentKeyset, FastForward_Key));
247   emit reverseEnabled(myKeysets->hasKey(currentKeyset, Rewind_Key));
248   emit playEnabled(myKeysets->hasKey(currentKeyset, Play_Key));
249   emit pauseEnabled(myKeysets->hasKey(currentKeyset, Pause_Key));
250   emit stopEnabled(myKeysets->hasKey(currentKeyset, Stop_Key));
251   emit ejectEnabled(myKeysets->hasKey(currentKeyset, Eject_Key));
255 void MainWindow::receivedExternalWarning(
256   const char *warning)
258   QMessageBox errBox;
259   errBox.setText(warning);
260   errBox.setIcon(QMessageBox::Warning);
261   errBox.exec();
265 // Main tab buttons:
267 void MainWindow::on_powerButton_pressed()
269   startRepeating(Power_Key);
272 void MainWindow::on_powerButton_released()
274   stopRepeating();
277 void MainWindow::on_mainChannelUpButton_pressed()
279   startRepeating(ChannelUp_Key);
282 void MainWindow::on_mainChannelUpButton_released()
284   stopRepeating();
287 void MainWindow::on_mainChannelDownButton_pressed()
289   startRepeating(ChannelDown_Key);
292 void MainWindow::on_mainChannelDownButton_released()
294   stopRepeating();
297 void MainWindow::on_mainVolumeUp_pressed()
299   startRepeating(VolumeUp_Key);
302 void MainWindow::on_mainVolumeUp_released()
304   stopRepeating();
307 void MainWindow::on_mainVolumeDownButton_pressed()
309   startRepeating(VolumeDown_Key);
312 void MainWindow::on_mainVolumeDownButton_released()
314   stopRepeating();
317 void MainWindow::on_muteButton_pressed()
319   startRepeating(Mute_Key);
322 void MainWindow::on_muteButton_released()
324   stopRepeating();
328 // Utility tab buttons:
330 void MainWindow::on_redButton_pressed()
332   startRepeating(Red_Key);
335 void MainWindow::on_redButton_released()
337   stopRepeating();
340 void MainWindow::on_greenButton_pressed()
342   startRepeating(Green_Key);
345 void MainWindow::on_greenButton_released()
347   stopRepeating();
350 void MainWindow::on_yellowButton_pressed()
352   startRepeating(Yellow_Key);
355 void MainWindow::on_yellowButton_released()
357   stopRepeating();
360 void MainWindow::on_blueButton_pressed()
362   startRepeating(Blue_Key);
365 void MainWindow::on_blueButton_released()
367   stopRepeating();
370 void MainWindow::on_pictureModeButton_pressed()
372   startRepeating(PictureMode_Key);
375 void MainWindow::on_pictureModeButton_released()
377   stopRepeating();
380 void MainWindow::on_soundModeButton_pressed()
382   startRepeating(PictureMode_Key);
385 void MainWindow::on_soundModeButton_released()
387   stopRepeating();
390 void MainWindow::on_aspectRatioButton_pressed()
392   startRepeating(AspectRatio_Key);
395 void MainWindow::on_aspectRatioButton_released()
397   stopRepeating();
400 /*
401 void MainWindow::on_surroundButton_pressed()
403   startRepeating(Surround_Key);
406 void MainWindow::on_surroundButton_released()
408   stopRepeating();
410 */
412 void MainWindow::on_audioButton_pressed()
414   startRepeating(Audio_Key);
417 void MainWindow::on_audioButton_released()
419   stopRepeating();
422 void MainWindow::on_infoButton_pressed()
424   startRepeating(Info_Key);
427 void MainWindow::on_infoButton_released()
429   stopRepeating();
432 void MainWindow::on_captionButton_pressed()
434   startRepeating(Captions_Key);
437 void MainWindow::on_captionButton_released()
439   stopRepeating();
442 void MainWindow::on_inputButton_pressed()
444   startRepeating(Input_Key);
447 void MainWindow::on_inputButton_released()
449   stopRepeating();
452 void MainWindow::on_sleepButton_pressed()
454   startRepeating(Sleep_Key);
457 void MainWindow::on_sleepButton_released()
459   stopRepeating();
463 // Keypad tab buttons:
465 void MainWindow::on_oneButton_pressed()
467   startRepeating(One_Key);
470 void MainWindow::on_oneButton_released()
472   stopRepeating();
475 void MainWindow::on_twoButton_pressed()
477   startRepeating(Two_Key);
480 void MainWindow::on_twoButton_released()
482   stopRepeating();
485 void MainWindow::on_threeButton_pressed()
487   startRepeating(Three_Key);
490 void MainWindow::on_threeButton_released()
492   stopRepeating();
495 void MainWindow::on_fourButton_pressed()
497   startRepeating(Four_Key);
500 void MainWindow::on_fourButton_released()
502   stopRepeating();
505 void MainWindow::on_fiveButton_pressed()
507   startRepeating(Five_Key);
510 void MainWindow::on_fiveButton_released()
512   stopRepeating();
515 void MainWindow::on_sixButton_pressed()
517   startRepeating(Six_Key);
520 void MainWindow::on_sixButton_released()
522   stopRepeating();
525 void MainWindow::on_sevenButton_pressed()
527   startRepeating(Seven_Key);
530 void MainWindow::on_sevenButton_released()
532   stopRepeating();
535 void MainWindow::on_eightButton_pressed()
537   startRepeating(Eight_Key);
540 void MainWindow::on_eightButton_released()
542   stopRepeating();
545 void MainWindow::on_nineButton_pressed()
547   startRepeating(Nine_Key);
550 void MainWindow::on_nineButton_released()
552   stopRepeating();
555 void MainWindow::on_zeroButton_pressed()
557   startRepeating(Zero_Key);
560 void MainWindow::on_zeroButton_released()
562   stopRepeating();
565 void MainWindow::on_enterButton_pressed()
567   startRepeating(Enter_Key);
570 void MainWindow::on_enterButton_released()
572   stopRepeating();
575 void MainWindow::on_clearButton_pressed()
577   startRepeating(Clear_Key);
580 void MainWindow::on_clearButton_released()
582   stopRepeating();
585 void MainWindow::on_prevChannelButton_pressed()
587   startRepeating(PrevChannel_Key);
590 void MainWindow::on_prevChannelButton_released()
592   stopRepeating();
595 void MainWindow::on_plusOneHundredButton_pressed()
597   startRepeating(PlusOneHundred_Key);
600 void MainWindow::on_plusOneHundredButton_released()
602   stopRepeating();
605 void MainWindow::on_dashButton_pressed()
607   startRepeating(Dash_Key);
610 void MainWindow::on_dashButton_released()
612   stopRepeating();
615 void MainWindow::on_doubleDigitButton_pressed()
617   startRepeating(DoubleDigit_Key);
620 void MainWindow::on_doubleDigitButton_released()
622   stopRepeating();
626 // Menu tab buttons:
628 void MainWindow::on_upButton_pressed()
630   startRepeating(Up_Key);
633 void MainWindow::on_upButton_released()
635   stopRepeating();
638 void MainWindow::on_leftButton_pressed()
640   startRepeating(Left_Key);
643 void MainWindow::on_leftButton_released()
645   stopRepeating();
648 void MainWindow::on_rightButton_pressed()
650   startRepeating(Right_Key);
653 void MainWindow::on_rightButton_released()
655   stopRepeating();
658 void MainWindow::on_downButton_pressed()
660   startRepeating(Down_Key);
663 void MainWindow::on_downButton_released()
665   stopRepeating();
668 void MainWindow::on_selectButton_pressed()
670   startRepeating(Select_Key);
673 void MainWindow::on_selectButton_released()
675   stopRepeating();
678 void MainWindow::on_menuButton_pressed()
680   startRepeating(Menu_Key);
683 void MainWindow::on_menuButton_released()
685   stopRepeating();
688 void MainWindow::on_exitButton_pressed()
690   startRepeating(Exit_Key);
693 void MainWindow::on_exitButton_released()
695   stopRepeating();
698 void MainWindow::on_guideButton_pressed()
700   startRepeating(Guide_Key);
703 void MainWindow::on_guideButton_released()
705   stopRepeating();
708 void MainWindow::on_discMenuButton_pressed()
710   startRepeating(DiscMenu_Key);
713 void MainWindow::on_discMenuButton_released()
715   stopRepeating();
719 // Media tab buttons:
721 void MainWindow::on_mediaPreviousButton_pressed()
723   startRepeating(Previous_Key);
726 void MainWindow::on_mediaPreviousButton_released()
728   stopRepeating();
731 void MainWindow::on_mediaNextButton_pressed()
733   startRepeating(Next_Key);
736 void MainWindow::on_mediaNextButton_released()
738   stopRepeating();
741 void MainWindow::on_replayButton_pressed()
743   startRepeating(Replay_Key);
746 void MainWindow::on_replayButton_released()
748   stopRepeating();
751 void MainWindow::on_advanceButton_pressed()
753   startRepeating(Advance_Key);
756 void MainWindow::on_advanceButton_released()
758   stopRepeating();
761 void MainWindow::on_stepBackButton_pressed()
763   startRepeating(StepBack_Key);
766 void MainWindow::on_stepBackButton_released()
768   stopRepeating();
771 void MainWindow::on_stepForwardButton_pressed()
773   startRepeating(StepForward_Key);
776 void MainWindow::on_stepForwardButton_released()
778   stopRepeating();
781 void MainWindow::on_reverseButton_pressed()
783   startRepeating(Rewind_Key);
786 void MainWindow::on_reverseButton_released()
788   stopRepeating();
791 void MainWindow::on_fastForwardButton_pressed()
793   startRepeating(FastForward_Key);
796 void MainWindow::on_fastForwardButton_released()
798   stopRepeating();
801 void MainWindow::on_playButton_pressed()
803   startRepeating(Play_Key);
806 void MainWindow::on_playButton_released()
808   stopRepeating();
811 void MainWindow::on_pauseButton_pressed()
813   startRepeating(Pause_Key);
816 void MainWindow::on_pauseButton_released()
818   stopRepeating();
821 void MainWindow::on_stopButton_pressed()
823   startRepeating(Stop_Key);
826 void MainWindow::on_stopButton_released()
828   stopRepeating();
831 void MainWindow::on_ejectButton_pressed()
833   startRepeating(Eject_Key);
836 void MainWindow::on_ejectButton_released()
838   stopRepeating();
842 // Menu actions:
844 void MainWindow::on_actionSelectKeyset_triggered()
846   selectKeysetForm->show();
849 void MainWindow::on_actionSecondary_Buttons_triggered()
851   if (!secondaryForm)
852   {
853     secondaryForm = new PIRSecondaryForm(this);
854   }
856   secondaryForm->show();
859 void MainWindow::on_actionAbout_triggered()
861   if (!aboutForm)
862   {
863     aboutForm = new PIRAboutForm(this);
864   }
866   aboutForm->show();
869 void MainWindow::on_actionDocumentation_triggered()
871   if (!documentationForm)
872   {
873     documentationForm = new PIRDocumentationForm(this);
874   }
876   documentationForm->show();
880 // Other actions:
882 void MainWindow::keysetSelectionChanged(
883   QListWidgetItem *item)
885   if (!item) return;  // Should probably say something here!
887   PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
889   if (!kwi) return; // Also need to say something here
890   
891   currentKeyset = kwi->getID();
893   QSettings settings("pietrzak.org", "Pierogi");
894 //  settings.setValue("currentKeyset", currentKeyset);
896   settings.setValue(
897     "currentKeysetMake",
898     makeManager.getMakeString(kwi->getMake()));
900   settings.setValue(
901     "currentKeysetName",
902     myKeysets->getDisplayName(currentKeyset));
904   enableButtons();
905   secondaryForm->enableButtons(myKeysets, currentKeyset);
909 void MainWindow::finalCleanup()
911   // Perform any necessary cleanup work here.
913   // Make certain that the thread stops repeating:
914   stopRepeating();
918 void MainWindow::on_addKeysetButton_clicked()
920   // Is the current keyset already a favorite?
921   int count = ui->favoriteKeysetsWidget->count();
922   int index = 0;
923   PIRKeysetWidgetItem *kwi = NULL;
924   while (index < count)
925   {
926     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
927       ui->favoriteKeysetsWidget->item(index));
929     if (kwi && (kwi->getID() == currentKeyset))
930     {
931       // Current keyset already in list!  No need to continue.
932       return;
933     }
934     ++index;
935   }
937   // Ok, add the current keyset to the favorites:
938   PIRMakeName make = myKeysets->getMake(currentKeyset);
940   QString name = makeManager.getMakeString(make);
941   name.append(" ");
942   name.append(myKeysets->getDisplayName(currentKeyset));
944   ui->favoriteKeysetsWidget->addItem(
945     new PIRKeysetWidgetItem(name, currentKeyset, make));
947   // And, add the keyset id to the persistent list:
948   QSettings settings("pietrzak.org", "Pierogi");
950   int favSettingsSize = settings.beginReadArray("favorites");
951   settings.endArray();
953   settings.beginWriteArray("favorites");
954   settings.setArrayIndex(favSettingsSize);
955 //  settings.setValue("keysetID", currentKeyset);
957   settings.setValue(
958     "keysetMake",
959     makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
961   settings.setValue("keysetName", myKeysets->getDisplayName(currentKeyset));
963   settings.endArray();
967 void MainWindow::on_removeKeysetButton_clicked()
969   // Deleting an item removes it from the list, so just grab the currently
970   // selected item and delete it:
971   QListWidgetItem *item = ui->favoriteKeysetsWidget->currentItem();
973   if (item) delete item;
975   // Remove this item from the persistent list.  Well, actually, it seems a
976   // little more convenient to just blow away the existing list of favorites
977   // and rewrite it, as modifying an existing QSettings array in the middle
978   // seems a bit hard...
979   QSettings settings("pietrzak.org", "Pierogi");
981   settings.remove("favorites");
983   int count = ui->favoriteKeysetsWidget->count();
985   // If the count is empty, we can stop right here:
986   if (count == 0) return;
988   int index = 0;
989   unsigned int id;
990   PIRKeysetWidgetItem *kwi = NULL;
991   settings.beginWriteArray("favorites");
992   while (index < count)
993   {
994     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
995       ui->favoriteKeysetsWidget->item(index));
997     settings.setArrayIndex(index);
998 //    settings.setValue("keysetID", kwi->getID());
999     id = kwi->getID();
1001     settings.setValue(
1002       "keysetMake",
1003       makeManager.getMakeString(myKeysets->getMake(id)));
1005     settings.setValue("keysetName", myKeysets->getDisplayName(id));
1007     ++index;
1008   }
1009   settings.endArray();
1012 void MainWindow::populateFavorites()
1014   QSettings settings("pietrzak.org", "Pierogi");
1016   int size = settings.beginReadArray("favorites");
1017   int index = 0;
1018   QString make;
1019   QString name;
1020   PIRKeysetWidgetItem *kwi;
1022   while (index < size)
1023   {
1024     settings.setArrayIndex(index);
1025     make = settings.value("keysetMake").toString();
1026     name = settings.value("keysetName").toString();
1028     kwi = myKeysets->makeKeysetItem(make, name);
1030     // Did the item creation work?
1031     if (kwi)
1032     {
1033       // Keyset does exist, so continue:
1034       ui->favoriteKeysetsWidget->addItem(kwi);
1035     }
1037     ++index;
1038   }
1040   settings.endArray();
1044 void MainWindow::startRepeating(
1045   PIRKeyName name)
1047   QMutexLocker locker(&commandIFMutex);
1048   if (!commandInFlight)
1049   {
1050     commandInFlight = true;
1051     emit buttonPressed(currentKeyset, name);
1052   }
1056 void MainWindow::stopRepeating()
1058   QMutexLocker locker(&stopRepeatingMutex);
1059   stopRepeatingFlag = true;

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment