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>
8 #include <QMaemo5InformationBox>
10 #include "pirkeysetwidgetitem.h"
11 #include "pirselectkeysetform.h"
12 #include "pirsecondaryform.h"
13 #include "pirdocumentationform.h"
14 #include "piraboutform.h"
15 #include "pirkeysetmanager.h"
17 //#define DEBUGGING
19 // Some ugly globals used for thread communications:
21 // A global to show that a command is being processed:
22 bool commandInFlight = false;
23 QMutex commandIFMutex;
25 // The stopRepeatingFlag boolean is the method used to tell running commands
26 // in the worker thread to stop:
27 bool stopRepeatingFlag = false;
28 QMutex stopRepeatingMutex;
30 extern PIRMakeMgr makeManager;
33 MainWindow::MainWindow(QWidget *parent)
34   : QMainWindow(parent),
35     ui(new Ui::MainWindow),
36     selectKeysetForm(0),
37     secondaryForm(0),
38     documentationForm(0),
39     aboutForm(0),
40     currentKeyset(0)
41 {
42   ui->setupUi(this);
44   // Make this a Maemo 5 stacked widget:
45   setAttribute(Qt::WA_Maemo5StackedWindow);
47   // Collect the keysets:
48   myKeysets = new PIRKeysetManager(this);
50   // Set up the keyset selection window:
51   selectKeysetForm = new PIRSelectKeysetForm(this);
53   // Set up the secondary buttons window:
54   secondaryForm = new PIRSecondaryForm(this);
56   myKeysets->populateGuiWidget(selectKeysetForm);
58   // Remember any favorites the user has already set:
59   populateFavorites();
61   QSettings settings("pietrzak.org", "Pierogi");
62   if (settings.contains("currentKeysetName"))
63   {
64     myKeysets->findKeysetID(
65       settings.value("currentKeysetMake").toString(),
66       settings.value("currentKeysetName").toString(),
67       currentKeyset);
68 //    currentKeyset = settings.value("currentKeyset").toInt();
69   }
71   enableButtons();
72   secondaryForm->enableButtons(myKeysets, currentKeyset);
74   connect(
75     ui->favoriteKeysetsWidget,
76 //    SIGNAL(itemActivated(QListWidgetItem *)),
77     SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
78     this,
79     SLOT(keysetSelectionChanged(QListWidgetItem *)),
80     Qt::QueuedConnection);
82   // Make sure the two selection lists don't show different selections:
83   QListWidget *klw = selectKeysetForm->getKeysetListWidget();
84   connect(
85     ui->favoriteKeysetsWidget,
86     SIGNAL(itemActivated(QListWidgetItem *)),
87     klw,
88     SLOT(clearSelection()),
89     Qt::QueuedConnection);
91   connect(
92     klw,
93     SIGNAL(itemActivated(QListWidgetItem *)),
94     ui->favoriteKeysetsWidget,
95     SLOT(clearSelection()),
96     Qt::QueuedConnection);
98 #ifndef DEBUGGING
99   // The PIRModprobe object should take care of setting up and shutting down
100   // the lirc_rx51 kernel module, if necessary:
101  
102   if (modprobeObj.loadRX51Module() != 0)
103   {
104     // Couldn't load module, quit:
105     QMessageBox errBox;
106     errBox.setText("Couldn't load lirc_rx51 kernel module!");
107     errBox.setIcon(QMessageBox::Warning);
108     errBox.exec();
109 //    throw; // Need a clean way to exit here!!!
110   }
111 #endif
115 MainWindow::~MainWindow()
117   delete myKeysets;
118   if (selectKeysetForm) delete selectKeysetForm;
119   if (documentationForm) delete documentationForm;
120   if (aboutForm) delete aboutForm;
121   delete ui;
125 void MainWindow::setOrientation(ScreenOrientation orientation)
127 #if defined(Q_OS_SYMBIAN)
128     // If the version of Qt on the device is < 4.7.2, that attribute won't work
129     if (orientation != ScreenOrientationAuto) {
130         const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
131         if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
132             qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
133             return;
134         }
135     }
136 #endif // Q_OS_SYMBIAN
138     Qt::WidgetAttribute attribute;
139     switch (orientation) {
140 #if QT_VERSION < 0x040702
141     // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
142     case ScreenOrientationLockPortrait:
143         attribute = static_cast<Qt::WidgetAttribute>(128);
144         break;
145     case ScreenOrientationLockLandscape:
146         attribute = static_cast<Qt::WidgetAttribute>(129);
147         break;
148     default:
149     case ScreenOrientationAuto:
150         attribute = static_cast<Qt::WidgetAttribute>(130);
151         break;
152 #else // QT_VERSION < 0x040702
153     case ScreenOrientationLockPortrait:
154         attribute = Qt::WA_LockPortraitOrientation;
155         break;
156     case ScreenOrientationLockLandscape:
157         attribute = Qt::WA_LockLandscapeOrientation;
158         break;
159     default:
160     case ScreenOrientationAuto:
161         attribute = Qt::WA_AutoOrientation;
162         break;
163 #endif // QT_VERSION < 0x040702
164     };
165     setAttribute(attribute, true);
168 void MainWindow::showExpanded()
170 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
171     showFullScreen();
172 #elif defined(Q_WS_MAEMO_5)
173     showMaximized();
174 #else
175     show();
176 #endif
180 void MainWindow::enableButtons()
182   // This is going to be a little painful...
183   // Main keys
184   emit powerEnabled(myKeysets->hasKey(currentKeyset, Power_Key));
185   emit volumeUpEnabled(myKeysets->hasKey(currentKeyset, VolumeUp_Key));
186   emit volumeDownEnabled(myKeysets->hasKey(currentKeyset, VolumeDown_Key));
187   emit channelUpEnabled(myKeysets->hasKey(currentKeyset, ChannelUp_Key));
188   emit channelDownEnabled(myKeysets->hasKey(currentKeyset, ChannelDown_Key));
189   emit muteEnabled(myKeysets->hasKey(currentKeyset, Mute_Key));
191   // Main tab labels:
192   emit keysetMakeChanged(
193     makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
194   emit keysetNameChanged(myKeysets->getDisplayName(currentKeyset));
196   // Utility keys:
197   emit redEnabled(myKeysets->hasKey(currentKeyset, Red_Key));
198   emit greenEnabled(myKeysets->hasKey(currentKeyset, Green_Key));
199   emit yellowEnabled(myKeysets->hasKey(currentKeyset, Yellow_Key));
200   emit blueEnabled(myKeysets->hasKey(currentKeyset, Blue_Key));
201   emit pictureModeEnabled(myKeysets->hasKey(currentKeyset, PictureMode_Key));
202   emit soundModeEnabled(myKeysets->hasKey(currentKeyset, SoundMode_Key));
203   emit aspectRatioEnabled(myKeysets->hasKey(currentKeyset, AspectRatio_Key));
204 //  emit surroundEnabled(myKeysets->hasKey(currentKeyset, Surround_Key));
205   emit audioEnabled(myKeysets->hasKey(currentKeyset, Audio_Key));
206   emit infoEnabled(myKeysets->hasKey(currentKeyset, Info_Key));
207   emit captionsEnabled(myKeysets->hasKey(currentKeyset, Captions_Key));
208   emit sleepEnabled(myKeysets->hasKey(currentKeyset, Sleep_Key));
209   emit inputEnabled(myKeysets->hasKey(currentKeyset, Input_Key));
211   // Keypad keys
212   emit zeroEnabled(myKeysets->hasKey(currentKeyset, Zero_Key));
213   emit oneEnabled(myKeysets->hasKey(currentKeyset, One_Key));
214   emit twoEnabled(myKeysets->hasKey(currentKeyset, Two_Key));
215   emit threeEnabled(myKeysets->hasKey(currentKeyset, Three_Key));
216   emit fourEnabled(myKeysets->hasKey(currentKeyset, Four_Key));
217   emit fiveEnabled(myKeysets->hasKey(currentKeyset, Five_Key));
218   emit sixEnabled(myKeysets->hasKey(currentKeyset, Six_Key));
219   emit sevenEnabled(myKeysets->hasKey(currentKeyset, Seven_Key));
220   emit eightEnabled(myKeysets->hasKey(currentKeyset, Eight_Key));
221   emit nineEnabled(myKeysets->hasKey(currentKeyset, Nine_Key));
222   emit enterEnabled(myKeysets->hasKey(currentKeyset, Enter_Key));
223   emit clearEnabled(myKeysets->hasKey(currentKeyset, Clear_Key));
224   emit dashEnabled(myKeysets->hasKey(currentKeyset, Dash_Key));
225   emit plusOneHundredEnabled(myKeysets->hasKey(currentKeyset, PlusOneHundred_Key));
226   emit doubleDigitEnabled(myKeysets->hasKey(currentKeyset, DoubleDigit_Key));
227   emit prevChannelEnabled(myKeysets->hasKey(currentKeyset, PrevChannel_Key));
229   // Menu keys:
230   emit upEnabled(myKeysets->hasKey(currentKeyset, Up_Key));
231   emit downEnabled(myKeysets->hasKey(currentKeyset, Down_Key));
232   emit leftEnabled(myKeysets->hasKey(currentKeyset, Left_Key));
233   emit rightEnabled(myKeysets->hasKey(currentKeyset, Right_Key));
234   emit selectEnabled(myKeysets->hasKey(currentKeyset, Select_Key));
235   emit menuEnabled(myKeysets->hasKey(currentKeyset, Menu_Key));
236   emit exitEnabled(myKeysets->hasKey(currentKeyset, Exit_Key));
237   emit guideEnabled(myKeysets->hasKey(currentKeyset, Guide_Key));
238   emit discMenuEnabled(myKeysets->hasKey(currentKeyset, DiscMenu_Key));
240   // Media keys:
241   emit nextEnabled(myKeysets->hasKey(currentKeyset, Next_Key));
242   emit previousEnabled(myKeysets->hasKey(currentKeyset, Previous_Key));
243   emit advanceEnabled(myKeysets->hasKey(currentKeyset, Advance_Key));
244   emit replayEnabled(myKeysets->hasKey(currentKeyset, Replay_Key));
245   emit stepForwardEnabled(myKeysets->hasKey(currentKeyset, StepForward_Key));
246   emit stepBackEnabled(myKeysets->hasKey(currentKeyset, StepBack_Key));
247   emit fastForwardEnabled(myKeysets->hasKey(currentKeyset, FastForward_Key));
248   emit reverseEnabled(myKeysets->hasKey(currentKeyset, Rewind_Key));
249   emit playEnabled(myKeysets->hasKey(currentKeyset, Play_Key));
250   emit pauseEnabled(myKeysets->hasKey(currentKeyset, Pause_Key));
251   emit stopEnabled(myKeysets->hasKey(currentKeyset, Stop_Key));
252   emit ejectEnabled(myKeysets->hasKey(currentKeyset, Eject_Key));
256 void MainWindow::receivedExternalWarning(
257   const char *warning)
259   QMessageBox errBox;
260   errBox.setText(warning);
261   errBox.setIcon(QMessageBox::Warning);
262   errBox.exec();
266 // Main tab buttons:
268 void MainWindow::on_powerButton_pressed()
270   startRepeating(Power_Key);
273 void MainWindow::on_powerButton_released()
275   stopRepeating();
278 void MainWindow::on_mainChannelUpButton_pressed()
280   startRepeating(ChannelUp_Key);
283 void MainWindow::on_mainChannelUpButton_released()
285   stopRepeating();
288 void MainWindow::on_mainChannelDownButton_pressed()
290   startRepeating(ChannelDown_Key);
293 void MainWindow::on_mainChannelDownButton_released()
295   stopRepeating();
298 void MainWindow::on_mainVolumeUp_pressed()
300   startRepeating(VolumeUp_Key);
303 void MainWindow::on_mainVolumeUp_released()
305   stopRepeating();
308 void MainWindow::on_mainVolumeDownButton_pressed()
310   startRepeating(VolumeDown_Key);
313 void MainWindow::on_mainVolumeDownButton_released()
315   stopRepeating();
318 void MainWindow::on_muteButton_pressed()
320   startRepeating(Mute_Key);
323 void MainWindow::on_muteButton_released()
325   stopRepeating();
329 // Utility tab buttons:
331 void MainWindow::on_redButton_pressed()
333   startRepeating(Red_Key);
336 void MainWindow::on_redButton_released()
338   stopRepeating();
341 void MainWindow::on_greenButton_pressed()
343   startRepeating(Green_Key);
346 void MainWindow::on_greenButton_released()
348   stopRepeating();
351 void MainWindow::on_yellowButton_pressed()
353   startRepeating(Yellow_Key);
356 void MainWindow::on_yellowButton_released()
358   stopRepeating();
361 void MainWindow::on_blueButton_pressed()
363   startRepeating(Blue_Key);
366 void MainWindow::on_blueButton_released()
368   stopRepeating();
371 void MainWindow::on_pictureModeButton_pressed()
373   startRepeating(PictureMode_Key);
376 void MainWindow::on_pictureModeButton_released()
378   stopRepeating();
381 void MainWindow::on_soundModeButton_pressed()
383   startRepeating(SoundMode_Key);
386 void MainWindow::on_soundModeButton_released()
388   stopRepeating();
391 void MainWindow::on_aspectRatioButton_pressed()
393   startRepeating(AspectRatio_Key);
396 void MainWindow::on_aspectRatioButton_released()
398   stopRepeating();
401 /*
402 void MainWindow::on_surroundButton_pressed()
404   startRepeating(Surround_Key);
407 void MainWindow::on_surroundButton_released()
409   stopRepeating();
411 */
413 void MainWindow::on_audioButton_pressed()
415   startRepeating(Audio_Key);
418 void MainWindow::on_audioButton_released()
420   stopRepeating();
423 void MainWindow::on_infoButton_pressed()
425   startRepeating(Info_Key);
428 void MainWindow::on_infoButton_released()
430   stopRepeating();
433 void MainWindow::on_captionButton_pressed()
435   startRepeating(Captions_Key);
438 void MainWindow::on_captionButton_released()
440   stopRepeating();
443 void MainWindow::on_inputButton_pressed()
445   startRepeating(Input_Key);
448 void MainWindow::on_inputButton_released()
450   stopRepeating();
453 void MainWindow::on_sleepButton_pressed()
455   startRepeating(Sleep_Key);
458 void MainWindow::on_sleepButton_released()
460   stopRepeating();
464 // Keypad tab buttons:
466 void MainWindow::on_oneButton_pressed()
468   startRepeating(One_Key);
471 void MainWindow::on_oneButton_released()
473   stopRepeating();
476 void MainWindow::on_twoButton_pressed()
478   startRepeating(Two_Key);
481 void MainWindow::on_twoButton_released()
483   stopRepeating();
486 void MainWindow::on_threeButton_pressed()
488   startRepeating(Three_Key);
491 void MainWindow::on_threeButton_released()
493   stopRepeating();
496 void MainWindow::on_fourButton_pressed()
498   startRepeating(Four_Key);
501 void MainWindow::on_fourButton_released()
503   stopRepeating();
506 void MainWindow::on_fiveButton_pressed()
508   startRepeating(Five_Key);
511 void MainWindow::on_fiveButton_released()
513   stopRepeating();
516 void MainWindow::on_sixButton_pressed()
518   startRepeating(Six_Key);
521 void MainWindow::on_sixButton_released()
523   stopRepeating();
526 void MainWindow::on_sevenButton_pressed()
528   startRepeating(Seven_Key);
531 void MainWindow::on_sevenButton_released()
533   stopRepeating();
536 void MainWindow::on_eightButton_pressed()
538   startRepeating(Eight_Key);
541 void MainWindow::on_eightButton_released()
543   stopRepeating();
546 void MainWindow::on_nineButton_pressed()
548   startRepeating(Nine_Key);
551 void MainWindow::on_nineButton_released()
553   stopRepeating();
556 void MainWindow::on_zeroButton_pressed()
558   startRepeating(Zero_Key);
561 void MainWindow::on_zeroButton_released()
563   stopRepeating();
566 void MainWindow::on_enterButton_pressed()
568   startRepeating(Enter_Key);
571 void MainWindow::on_enterButton_released()
573   stopRepeating();
576 void MainWindow::on_clearButton_pressed()
578   startRepeating(Clear_Key);
581 void MainWindow::on_clearButton_released()
583   stopRepeating();
586 void MainWindow::on_prevChannelButton_pressed()
588   startRepeating(PrevChannel_Key);
591 void MainWindow::on_prevChannelButton_released()
593   stopRepeating();
596 void MainWindow::on_plusOneHundredButton_pressed()
598   startRepeating(PlusOneHundred_Key);
601 void MainWindow::on_plusOneHundredButton_released()
603   stopRepeating();
606 void MainWindow::on_dashButton_pressed()
608   startRepeating(Dash_Key);
611 void MainWindow::on_dashButton_released()
613   stopRepeating();
616 void MainWindow::on_doubleDigitButton_pressed()
618   startRepeating(DoubleDigit_Key);
621 void MainWindow::on_doubleDigitButton_released()
623   stopRepeating();
627 // Menu tab buttons:
629 void MainWindow::on_upButton_pressed()
631   startRepeating(Up_Key);
634 void MainWindow::on_upButton_released()
636   stopRepeating();
639 void MainWindow::on_leftButton_pressed()
641   startRepeating(Left_Key);
644 void MainWindow::on_leftButton_released()
646   stopRepeating();
649 void MainWindow::on_rightButton_pressed()
651   startRepeating(Right_Key);
654 void MainWindow::on_rightButton_released()
656   stopRepeating();
659 void MainWindow::on_downButton_pressed()
661   startRepeating(Down_Key);
664 void MainWindow::on_downButton_released()
666   stopRepeating();
669 void MainWindow::on_selectButton_pressed()
671   startRepeating(Select_Key);
674 void MainWindow::on_selectButton_released()
676   stopRepeating();
679 void MainWindow::on_menuButton_pressed()
681   startRepeating(Menu_Key);
684 void MainWindow::on_menuButton_released()
686   stopRepeating();
689 void MainWindow::on_exitButton_pressed()
691   startRepeating(Exit_Key);
694 void MainWindow::on_exitButton_released()
696   stopRepeating();
699 void MainWindow::on_guideButton_pressed()
701   startRepeating(Guide_Key);
704 void MainWindow::on_guideButton_released()
706   stopRepeating();
709 void MainWindow::on_discMenuButton_pressed()
711   startRepeating(DiscMenu_Key);
714 void MainWindow::on_discMenuButton_released()
716   stopRepeating();
720 // Media tab buttons:
722 void MainWindow::on_mediaPreviousButton_pressed()
724   startRepeating(Previous_Key);
727 void MainWindow::on_mediaPreviousButton_released()
729   stopRepeating();
732 void MainWindow::on_mediaNextButton_pressed()
734   startRepeating(Next_Key);
737 void MainWindow::on_mediaNextButton_released()
739   stopRepeating();
742 void MainWindow::on_replayButton_pressed()
744   startRepeating(Replay_Key);
747 void MainWindow::on_replayButton_released()
749   stopRepeating();
752 void MainWindow::on_advanceButton_pressed()
754   startRepeating(Advance_Key);
757 void MainWindow::on_advanceButton_released()
759   stopRepeating();
762 void MainWindow::on_stepBackButton_pressed()
764   startRepeating(StepBack_Key);
767 void MainWindow::on_stepBackButton_released()
769   stopRepeating();
772 void MainWindow::on_stepForwardButton_pressed()
774   startRepeating(StepForward_Key);
777 void MainWindow::on_stepForwardButton_released()
779   stopRepeating();
782 void MainWindow::on_reverseButton_pressed()
784   startRepeating(Rewind_Key);
787 void MainWindow::on_reverseButton_released()
789   stopRepeating();
792 void MainWindow::on_fastForwardButton_pressed()
794   startRepeating(FastForward_Key);
797 void MainWindow::on_fastForwardButton_released()
799   stopRepeating();
802 void MainWindow::on_playButton_pressed()
804   startRepeating(Play_Key);
807 void MainWindow::on_playButton_released()
809   stopRepeating();
812 void MainWindow::on_pauseButton_pressed()
814   startRepeating(Pause_Key);
817 void MainWindow::on_pauseButton_released()
819   stopRepeating();
822 void MainWindow::on_stopButton_pressed()
824   startRepeating(Stop_Key);
827 void MainWindow::on_stopButton_released()
829   stopRepeating();
832 void MainWindow::on_ejectButton_pressed()
834   startRepeating(Eject_Key);
837 void MainWindow::on_ejectButton_released()
839   stopRepeating();
843 // Menu actions:
845 void MainWindow::on_actionSelectKeyset_triggered()
847   selectKeysetForm->show();
850 void MainWindow::on_actionSecondary_Buttons_triggered()
852   if (!secondaryForm)
853   {
854     secondaryForm = new PIRSecondaryForm(this);
855   }
857   secondaryForm->show();
860 void MainWindow::on_actionAbout_triggered()
862   if (!aboutForm)
863   {
864     aboutForm = new PIRAboutForm(this);
865   }
867   aboutForm->show();
870 void MainWindow::on_actionDocumentation_triggered()
872   if (!documentationForm)
873   {
874     documentationForm = new PIRDocumentationForm(this);
875   }
877   documentationForm->show();
881 // Other actions:
883 void MainWindow::keysetSelectionChanged(
884   QListWidgetItem *item)
886   if (!item) return;  // Should probably say something here!
888   PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
890   if (!kwi) return; // Also need to say something here
891   
892   currentKeyset = kwi->getID();
894   QSettings settings("pietrzak.org", "Pierogi");
895 //  settings.setValue("currentKeyset", currentKeyset);
897   settings.setValue(
898     "currentKeysetMake",
899     makeManager.getMakeString(kwi->getMake()));
901   settings.setValue(
902     "currentKeysetName",
903     myKeysets->getDisplayName(currentKeyset));
905   enableButtons();
906   secondaryForm->enableButtons(myKeysets, currentKeyset);
910 void MainWindow::finalCleanup()
912   // Perform any necessary cleanup work here.
914   // Make certain that the thread stops repeating:
915   stopRepeating();
919 void MainWindow::on_addKeysetButton_clicked()
921   // Is the current keyset already a favorite?
922   int count = ui->favoriteKeysetsWidget->count();
923   int index = 0;
924   PIRKeysetWidgetItem *kwi = NULL;
925   while (index < count)
926   {
927     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
928       ui->favoriteKeysetsWidget->item(index));
930     if (kwi && (kwi->getID() == currentKeyset))
931     {
932       // Current keyset already in list!  No need to continue.
933       return;
934     }
935     ++index;
936   }
938   // Ok, add the current keyset to the favorites:
939   PIRMakeName make = myKeysets->getMake(currentKeyset);
941   QString name = makeManager.getMakeString(make);
942   name.append(" ");
943   name.append(myKeysets->getDisplayName(currentKeyset));
945   ui->favoriteKeysetsWidget->addItem(
946     new PIRKeysetWidgetItem(name, currentKeyset, make));
948   // And, add the keyset id to the persistent list:
949   QSettings settings("pietrzak.org", "Pierogi");
951   int favSettingsSize = settings.beginReadArray("favorites");
952   settings.endArray();
954   settings.beginWriteArray("favorites");
955   settings.setArrayIndex(favSettingsSize);
956 //  settings.setValue("keysetID", currentKeyset);
958   settings.setValue(
959     "keysetMake",
960     makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
962   settings.setValue("keysetName", myKeysets->getDisplayName(currentKeyset));
964   settings.endArray();
968 void MainWindow::on_removeKeysetButton_clicked()
970   // Deleting an item removes it from the list, so just grab the currently
971   // selected item and delete it:
972   QListWidgetItem *item = ui->favoriteKeysetsWidget->currentItem();
974   if (item) delete item;
976   // Remove this item from the persistent list.  Well, actually, it seems a
977   // little more convenient to just blow away the existing list of favorites
978   // and rewrite it, as modifying an existing QSettings array in the middle
979   // seems a bit hard...
980   QSettings settings("pietrzak.org", "Pierogi");
982   settings.remove("favorites");
984   int count = ui->favoriteKeysetsWidget->count();
986   // If the count is empty, we can stop right here:
987   if (count == 0) return;
989   int index = 0;
990   unsigned int id;
991   PIRKeysetWidgetItem *kwi = NULL;
992   settings.beginWriteArray("favorites");
993   while (index < count)
994   {
995     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
996       ui->favoriteKeysetsWidget->item(index));
998     settings.setArrayIndex(index);
999 //    settings.setValue("keysetID", kwi->getID());
1000     id = kwi->getID();
1002     settings.setValue(
1003       "keysetMake",
1004       makeManager.getMakeString(myKeysets->getMake(id)));
1006     settings.setValue("keysetName", myKeysets->getDisplayName(id));
1008     ++index;
1009   }
1010   settings.endArray();
1013 void MainWindow::populateFavorites()
1015   QSettings settings("pietrzak.org", "Pierogi");
1017   int size = settings.beginReadArray("favorites");
1018   int index = 0;
1019   QString make;
1020   QString name;
1021   PIRKeysetWidgetItem *kwi;
1023   while (index < size)
1024   {
1025     settings.setArrayIndex(index);
1026     make = settings.value("keysetMake").toString();
1027     name = settings.value("keysetName").toString();
1029     kwi = myKeysets->makeKeysetItem(make, name);
1031     // Did the item creation work?
1032     if (kwi)
1033     {
1034       // Keyset does exist, so continue:
1035       ui->favoriteKeysetsWidget->addItem(kwi);
1036     }
1038     ++index;
1039   }
1041   settings.endArray();
1045 void MainWindow::startRepeating(
1046   PIRKeyName name)
1048   QMutexLocker locker(&commandIFMutex);
1049   if (!commandInFlight)
1050   {
1051     commandInFlight = true;
1052     emit buttonPressed(currentKeyset, name);
1053   }
1057 void MainWindow::stopRepeating()
1059   QMutexLocker locker(&stopRepeatingMutex);
1060   stopRepeatingFlag = true;
1064 QWidget *MainWindow::getSecondaryWindow()
1066   return secondaryForm;
1070 void MainWindow::selectPrevFavKeyset()
1072   int size = ui->favoriteKeysetsWidget->count();
1074   if (size == 0)
1075   {
1076     // No favorites, so nothing to do!
1077     return;
1078   }
1080   int position = ui->favoriteKeysetsWidget->currentRow();
1082   --position;
1083   if (position < 0)
1084   {
1085     position = size - 1;
1086   }
1088   ui->favoriteKeysetsWidget->setCurrentRow(
1089     position,
1090     QItemSelectionModel::ClearAndSelect);
1092   // Tell the user about the change:
1093   QMaemo5InformationBox::information(
1094     0,
1095     ui->favoriteKeysetsWidget->item(position)->text());
1099 void MainWindow::selectNextFavKeyset()
1101   int size = ui->favoriteKeysetsWidget->count();
1103   if (size == 0)
1104   {
1105     // No favorites, so just return:
1106     return;
1107   }
1109   int position = ui->favoriteKeysetsWidget->currentRow();
1111   ++position;
1112   if (position == size)
1113   {
1114     position = 0;
1115   }
1117   ui->favoriteKeysetsWidget->setCurrentRow(
1118     position,
1119     QItemSelectionModel::ClearAndSelect);
1121   // Tell the user about the change:
1122   QMaemo5InformationBox::information(
1123     0,
1124     ui->favoriteKeysetsWidget->item(position)->text());

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment