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();
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();
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   // Just to be sure, check to see if the keyset has been populated:
182   myKeysets->populateKeyset(this, currentKeyset);
184   // This is going to be a little painful...
185   // Main keys
186   emit powerEnabled(myKeysets->hasKey(currentKeyset, Power_Key));
187   emit volumeUpEnabled(myKeysets->hasKey(currentKeyset, VolumeUp_Key));
188   emit volumeDownEnabled(myKeysets->hasKey(currentKeyset, VolumeDown_Key));
189   emit channelUpEnabled(myKeysets->hasKey(currentKeyset, ChannelUp_Key));
190   emit channelDownEnabled(myKeysets->hasKey(currentKeyset, ChannelDown_Key));
191   emit muteEnabled(myKeysets->hasKey(currentKeyset, Mute_Key));
193   // Main tab labels:
194   emit keysetMakeChanged(
195     makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
196   emit keysetNameChanged(myKeysets->getDisplayName(currentKeyset));
198   // Utility keys:
199   emit redEnabled(myKeysets->hasKey(currentKeyset, Red_Key));
200   emit greenEnabled(myKeysets->hasKey(currentKeyset, Green_Key));
201   emit yellowEnabled(myKeysets->hasKey(currentKeyset, Yellow_Key));
202   emit blueEnabled(myKeysets->hasKey(currentKeyset, Blue_Key));
203   emit pictureModeEnabled(myKeysets->hasKey(currentKeyset, PictureMode_Key));
204   emit soundModeEnabled(myKeysets->hasKey(currentKeyset, SoundMode_Key));
205   emit aspectRatioEnabled(myKeysets->hasKey(currentKeyset, AspectRatio_Key));
206 //  emit surroundEnabled(myKeysets->hasKey(currentKeyset, Surround_Key));
207   emit audioEnabled(myKeysets->hasKey(currentKeyset, Audio_Key));
208   emit infoEnabled(myKeysets->hasKey(currentKeyset, Info_Key));
209   emit captionsEnabled(myKeysets->hasKey(currentKeyset, Captions_Key));
210   emit sleepEnabled(myKeysets->hasKey(currentKeyset, Sleep_Key));
211   emit inputEnabled(myKeysets->hasKey(currentKeyset, Input_Key));
213   // Keypad keys
214   emit zeroEnabled(myKeysets->hasKey(currentKeyset, Zero_Key));
215   emit oneEnabled(myKeysets->hasKey(currentKeyset, One_Key));
216   emit twoEnabled(myKeysets->hasKey(currentKeyset, Two_Key));
217   emit threeEnabled(myKeysets->hasKey(currentKeyset, Three_Key));
218   emit fourEnabled(myKeysets->hasKey(currentKeyset, Four_Key));
219   emit fiveEnabled(myKeysets->hasKey(currentKeyset, Five_Key));
220   emit sixEnabled(myKeysets->hasKey(currentKeyset, Six_Key));
221   emit sevenEnabled(myKeysets->hasKey(currentKeyset, Seven_Key));
222   emit eightEnabled(myKeysets->hasKey(currentKeyset, Eight_Key));
223   emit nineEnabled(myKeysets->hasKey(currentKeyset, Nine_Key));
224   emit enterEnabled(myKeysets->hasKey(currentKeyset, Enter_Key));
225   emit clearEnabled(myKeysets->hasKey(currentKeyset, Clear_Key));
226   emit dashEnabled(myKeysets->hasKey(currentKeyset, Dash_Key));
227   emit plusOneHundredEnabled(myKeysets->hasKey(currentKeyset, PlusOneHundred_Key));
228   emit doubleDigitEnabled(myKeysets->hasKey(currentKeyset, DoubleDigit_Key));
229   emit prevChannelEnabled(myKeysets->hasKey(currentKeyset, PrevChannel_Key));
231   // Menu keys:
232   emit upEnabled(myKeysets->hasKey(currentKeyset, Up_Key));
233   emit downEnabled(myKeysets->hasKey(currentKeyset, Down_Key));
234   emit leftEnabled(myKeysets->hasKey(currentKeyset, Left_Key));
235   emit rightEnabled(myKeysets->hasKey(currentKeyset, Right_Key));
236   emit selectEnabled(myKeysets->hasKey(currentKeyset, Select_Key));
237   emit menuEnabled(myKeysets->hasKey(currentKeyset, Menu_Key));
238   emit exitEnabled(myKeysets->hasKey(currentKeyset, Exit_Key));
239   emit guideEnabled(myKeysets->hasKey(currentKeyset, Guide_Key));
240   emit discMenuEnabled(myKeysets->hasKey(currentKeyset, DiscMenu_Key));
242   // Media keys:
243   emit nextEnabled(myKeysets->hasKey(currentKeyset, Next_Key));
244   emit previousEnabled(myKeysets->hasKey(currentKeyset, Previous_Key));
245   emit advanceEnabled(myKeysets->hasKey(currentKeyset, Advance_Key));
246   emit replayEnabled(myKeysets->hasKey(currentKeyset, Replay_Key));
247   emit stepForwardEnabled(myKeysets->hasKey(currentKeyset, StepForward_Key));
248   emit stepBackEnabled(myKeysets->hasKey(currentKeyset, StepBack_Key));
249   emit fastForwardEnabled(myKeysets->hasKey(currentKeyset, FastForward_Key));
250   emit reverseEnabled(myKeysets->hasKey(currentKeyset, Rewind_Key));
251   emit playEnabled(myKeysets->hasKey(currentKeyset, Play_Key));
252   emit pauseEnabled(myKeysets->hasKey(currentKeyset, Pause_Key));
253   emit stopEnabled(myKeysets->hasKey(currentKeyset, Stop_Key));
254   emit ejectEnabled(myKeysets->hasKey(currentKeyset, Eject_Key));
256   // Also enable the buttons on the secondary form:
257   secondaryForm->enableButtons(myKeysets, currentKeyset);
261 void MainWindow::receivedExternalWarning(
262   const char *warning)
264   QMessageBox errBox;
265   errBox.setText(warning);
266   errBox.setIcon(QMessageBox::Warning);
267   errBox.exec();
271 // Main tab buttons:
273 void MainWindow::on_powerButton_pressed()
275   startRepeating(Power_Key);
278 void MainWindow::on_powerButton_released()
280   stopRepeating();
283 void MainWindow::on_mainChannelUpButton_pressed()
285   startRepeating(ChannelUp_Key);
288 void MainWindow::on_mainChannelUpButton_released()
290   stopRepeating();
293 void MainWindow::on_mainChannelDownButton_pressed()
295   startRepeating(ChannelDown_Key);
298 void MainWindow::on_mainChannelDownButton_released()
300   stopRepeating();
303 void MainWindow::on_mainVolumeUp_pressed()
305   startRepeating(VolumeUp_Key);
308 void MainWindow::on_mainVolumeUp_released()
310   stopRepeating();
313 void MainWindow::on_mainVolumeDownButton_pressed()
315   startRepeating(VolumeDown_Key);
318 void MainWindow::on_mainVolumeDownButton_released()
320   stopRepeating();
323 void MainWindow::on_muteButton_pressed()
325   startRepeating(Mute_Key);
328 void MainWindow::on_muteButton_released()
330   stopRepeating();
334 // Utility tab buttons:
336 void MainWindow::on_redButton_pressed()
338   startRepeating(Red_Key);
341 void MainWindow::on_redButton_released()
343   stopRepeating();
346 void MainWindow::on_greenButton_pressed()
348   startRepeating(Green_Key);
351 void MainWindow::on_greenButton_released()
353   stopRepeating();
356 void MainWindow::on_yellowButton_pressed()
358   startRepeating(Yellow_Key);
361 void MainWindow::on_yellowButton_released()
363   stopRepeating();
366 void MainWindow::on_blueButton_pressed()
368   startRepeating(Blue_Key);
371 void MainWindow::on_blueButton_released()
373   stopRepeating();
376 void MainWindow::on_pictureModeButton_pressed()
378   startRepeating(PictureMode_Key);
381 void MainWindow::on_pictureModeButton_released()
383   stopRepeating();
386 void MainWindow::on_soundModeButton_pressed()
388   startRepeating(SoundMode_Key);
391 void MainWindow::on_soundModeButton_released()
393   stopRepeating();
396 void MainWindow::on_aspectRatioButton_pressed()
398   startRepeating(AspectRatio_Key);
401 void MainWindow::on_aspectRatioButton_released()
403   stopRepeating();
406 /*
407 void MainWindow::on_surroundButton_pressed()
409   startRepeating(Surround_Key);
412 void MainWindow::on_surroundButton_released()
414   stopRepeating();
416 */
418 void MainWindow::on_audioButton_pressed()
420   startRepeating(Audio_Key);
423 void MainWindow::on_audioButton_released()
425   stopRepeating();
428 void MainWindow::on_infoButton_pressed()
430   startRepeating(Info_Key);
433 void MainWindow::on_infoButton_released()
435   stopRepeating();
438 void MainWindow::on_captionButton_pressed()
440   startRepeating(Captions_Key);
443 void MainWindow::on_captionButton_released()
445   stopRepeating();
448 void MainWindow::on_inputButton_pressed()
450   startRepeating(Input_Key);
453 void MainWindow::on_inputButton_released()
455   stopRepeating();
458 void MainWindow::on_sleepButton_pressed()
460   startRepeating(Sleep_Key);
463 void MainWindow::on_sleepButton_released()
465   stopRepeating();
469 // Keypad tab buttons:
471 void MainWindow::on_oneButton_pressed()
473   startRepeating(One_Key);
476 void MainWindow::on_oneButton_released()
478   stopRepeating();
481 void MainWindow::on_twoButton_pressed()
483   startRepeating(Two_Key);
486 void MainWindow::on_twoButton_released()
488   stopRepeating();
491 void MainWindow::on_threeButton_pressed()
493   startRepeating(Three_Key);
496 void MainWindow::on_threeButton_released()
498   stopRepeating();
501 void MainWindow::on_fourButton_pressed()
503   startRepeating(Four_Key);
506 void MainWindow::on_fourButton_released()
508   stopRepeating();
511 void MainWindow::on_fiveButton_pressed()
513   startRepeating(Five_Key);
516 void MainWindow::on_fiveButton_released()
518   stopRepeating();
521 void MainWindow::on_sixButton_pressed()
523   startRepeating(Six_Key);
526 void MainWindow::on_sixButton_released()
528   stopRepeating();
531 void MainWindow::on_sevenButton_pressed()
533   startRepeating(Seven_Key);
536 void MainWindow::on_sevenButton_released()
538   stopRepeating();
541 void MainWindow::on_eightButton_pressed()
543   startRepeating(Eight_Key);
546 void MainWindow::on_eightButton_released()
548   stopRepeating();
551 void MainWindow::on_nineButton_pressed()
553   startRepeating(Nine_Key);
556 void MainWindow::on_nineButton_released()
558   stopRepeating();
561 void MainWindow::on_zeroButton_pressed()
563   startRepeating(Zero_Key);
566 void MainWindow::on_zeroButton_released()
568   stopRepeating();
571 void MainWindow::on_enterButton_pressed()
573   startRepeating(Enter_Key);
576 void MainWindow::on_enterButton_released()
578   stopRepeating();
581 void MainWindow::on_clearButton_pressed()
583   startRepeating(Clear_Key);
586 void MainWindow::on_clearButton_released()
588   stopRepeating();
591 void MainWindow::on_prevChannelButton_pressed()
593   startRepeating(PrevChannel_Key);
596 void MainWindow::on_prevChannelButton_released()
598   stopRepeating();
601 void MainWindow::on_plusOneHundredButton_pressed()
603   startRepeating(PlusOneHundred_Key);
606 void MainWindow::on_plusOneHundredButton_released()
608   stopRepeating();
611 void MainWindow::on_dashButton_pressed()
613   startRepeating(Dash_Key);
616 void MainWindow::on_dashButton_released()
618   stopRepeating();
621 void MainWindow::on_doubleDigitButton_pressed()
623   startRepeating(DoubleDigit_Key);
626 void MainWindow::on_doubleDigitButton_released()
628   stopRepeating();
632 // Menu tab buttons:
634 void MainWindow::on_upButton_pressed()
636   startRepeating(Up_Key);
639 void MainWindow::on_upButton_released()
641   stopRepeating();
644 void MainWindow::on_leftButton_pressed()
646   startRepeating(Left_Key);
649 void MainWindow::on_leftButton_released()
651   stopRepeating();
654 void MainWindow::on_rightButton_pressed()
656   startRepeating(Right_Key);
659 void MainWindow::on_rightButton_released()
661   stopRepeating();
664 void MainWindow::on_downButton_pressed()
666   startRepeating(Down_Key);
669 void MainWindow::on_downButton_released()
671   stopRepeating();
674 void MainWindow::on_selectButton_pressed()
676   startRepeating(Select_Key);
679 void MainWindow::on_selectButton_released()
681   stopRepeating();
684 void MainWindow::on_menuButton_pressed()
686   startRepeating(Menu_Key);
689 void MainWindow::on_menuButton_released()
691   stopRepeating();
694 void MainWindow::on_exitButton_pressed()
696   startRepeating(Exit_Key);
699 void MainWindow::on_exitButton_released()
701   stopRepeating();
704 void MainWindow::on_guideButton_pressed()
706   startRepeating(Guide_Key);
709 void MainWindow::on_guideButton_released()
711   stopRepeating();
714 void MainWindow::on_discMenuButton_pressed()
716   startRepeating(DiscMenu_Key);
719 void MainWindow::on_discMenuButton_released()
721   stopRepeating();
725 // Media tab buttons:
727 void MainWindow::on_mediaPreviousButton_pressed()
729   startRepeating(Previous_Key);
732 void MainWindow::on_mediaPreviousButton_released()
734   stopRepeating();
737 void MainWindow::on_mediaNextButton_pressed()
739   startRepeating(Next_Key);
742 void MainWindow::on_mediaNextButton_released()
744   stopRepeating();
747 void MainWindow::on_replayButton_pressed()
749   startRepeating(Replay_Key);
752 void MainWindow::on_replayButton_released()
754   stopRepeating();
757 void MainWindow::on_advanceButton_pressed()
759   startRepeating(Advance_Key);
762 void MainWindow::on_advanceButton_released()
764   stopRepeating();
767 void MainWindow::on_stepBackButton_pressed()
769   startRepeating(StepBack_Key);
772 void MainWindow::on_stepBackButton_released()
774   stopRepeating();
777 void MainWindow::on_stepForwardButton_pressed()
779   startRepeating(StepForward_Key);
782 void MainWindow::on_stepForwardButton_released()
784   stopRepeating();
787 void MainWindow::on_reverseButton_pressed()
789   startRepeating(Rewind_Key);
792 void MainWindow::on_reverseButton_released()
794   stopRepeating();
797 void MainWindow::on_fastForwardButton_pressed()
799   startRepeating(FastForward_Key);
802 void MainWindow::on_fastForwardButton_released()
804   stopRepeating();
807 void MainWindow::on_playButton_pressed()
809   startRepeating(Play_Key);
812 void MainWindow::on_playButton_released()
814   stopRepeating();
817 void MainWindow::on_pauseButton_pressed()
819   startRepeating(Pause_Key);
822 void MainWindow::on_pauseButton_released()
824   stopRepeating();
827 void MainWindow::on_stopButton_pressed()
829   startRepeating(Stop_Key);
832 void MainWindow::on_stopButton_released()
834   stopRepeating();
837 void MainWindow::on_ejectButton_pressed()
839   startRepeating(Eject_Key);
842 void MainWindow::on_ejectButton_released()
844   stopRepeating();
848 // Menu actions:
850 void MainWindow::on_actionSelectKeyset_triggered()
852   selectKeysetForm->show();
855 void MainWindow::on_actionSecondary_Buttons_triggered()
857   if (!secondaryForm)
858   {
859     secondaryForm = new PIRSecondaryForm(this);
860   }
862   secondaryForm->show();
865 void MainWindow::on_actionAbout_triggered()
867   if (!aboutForm)
868   {
869     aboutForm = new PIRAboutForm(this);
870   }
872   aboutForm->show();
875 void MainWindow::on_actionDocumentation_triggered()
877   if (!documentationForm)
878   {
879     documentationForm = new PIRDocumentationForm(this);
880   }
882   documentationForm->show();
886 // Other actions:
888 void MainWindow::keysetSelectionChanged(
889   QListWidgetItem *item)
891   if (!item) return;  // Should probably display error message here!
893   PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
895   if (!kwi) return; // Also need to say something here
896   
897   currentKeyset = kwi->getID();
899   QSettings settings("pietrzak.org", "Pierogi");
900 //  settings.setValue("currentKeyset", currentKeyset);
902   settings.setValue(
903     "currentKeysetMake",
904     makeManager.getMakeString(kwi->getMake()));
906   settings.setValue(
907     "currentKeysetName",
908     myKeysets->getDisplayName(currentKeyset));
910   enableButtons();
914 void MainWindow::finalCleanup()
916   // Perform any necessary cleanup work here.
918   // Make certain that the thread stops repeating:
919   stopRepeating();
923 void MainWindow::on_addKeysetButton_clicked()
925   // Is the current keyset already a favorite?
926   int count = ui->favoriteKeysetsWidget->count();
927   int index = 0;
928   PIRKeysetWidgetItem *kwi = NULL;
929   while (index < count)
930   {
931     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
932       ui->favoriteKeysetsWidget->item(index));
934     if (kwi && (kwi->getID() == currentKeyset))
935     {
936       // Current keyset already in list!  No need to continue.
937       return;
938     }
939     ++index;
940   }
942   // Ok, add the current keyset to the favorites:
943   PIRMakeName make = myKeysets->getMake(currentKeyset);
945   QString name = makeManager.getMakeString(make);
946   name.append(" ");
947   name.append(myKeysets->getDisplayName(currentKeyset));
949   ui->favoriteKeysetsWidget->addItem(
950     new PIRKeysetWidgetItem(name, currentKeyset, make));
952   // And, add the keyset id to the persistent list:
953   QSettings settings("pietrzak.org", "Pierogi");
955   int favSettingsSize = settings.beginReadArray("favorites");
956   settings.endArray();
958   settings.beginWriteArray("favorites");
959   settings.setArrayIndex(favSettingsSize);
960 //  settings.setValue("keysetID", currentKeyset);
962   settings.setValue(
963     "keysetMake",
964     makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
966   settings.setValue("keysetName", myKeysets->getDisplayName(currentKeyset));
968   settings.endArray();
972 void MainWindow::on_removeKeysetButton_clicked()
974   // Deleting an item removes it from the list, so just grab the currently
975   // selected item and delete it:
976   QListWidgetItem *item = ui->favoriteKeysetsWidget->currentItem();
978   if (item) delete item;
980   // Remove this item from the persistent list.  Well, actually, it seems a
981   // little more convenient to just blow away the existing list of favorites
982   // and rewrite it, as modifying an existing QSettings array in the middle
983   // seems a bit hard...
984   QSettings settings("pietrzak.org", "Pierogi");
986   settings.remove("favorites");
988   int count = ui->favoriteKeysetsWidget->count();
990   // If the count is empty, we can stop right here:
991   if (count == 0) return;
993   int index = 0;
994   unsigned int id;
995   PIRKeysetWidgetItem *kwi = NULL;
996   settings.beginWriteArray("favorites");
997   while (index < count)
998   {
999     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
1000       ui->favoriteKeysetsWidget->item(index));
1002     settings.setArrayIndex(index);
1003 //    settings.setValue("keysetID", kwi->getID());
1004     id = kwi->getID();
1006     settings.setValue(
1007       "keysetMake",
1008       makeManager.getMakeString(myKeysets->getMake(id)));
1010     settings.setValue("keysetName", myKeysets->getDisplayName(id));
1012     ++index;
1013   }
1014   settings.endArray();
1017 void MainWindow::populateFavorites()
1019   QSettings settings("pietrzak.org", "Pierogi");
1021   int size = settings.beginReadArray("favorites");
1022   int index = 0;
1023   QString make;
1024   QString name;
1025   PIRKeysetWidgetItem *kwi;
1027   while (index < size)
1028   {
1029     settings.setArrayIndex(index);
1030     make = settings.value("keysetMake").toString();
1031     name = settings.value("keysetName").toString();
1033     kwi = myKeysets->makeKeysetItem(make, name);
1035     // Did the item creation work?
1036     if (kwi)
1037     {
1038       // Keyset does exist, so continue:
1039       ui->favoriteKeysetsWidget->addItem(kwi);
1040     }
1042     ++index;
1043   }
1045   settings.endArray();
1049 void MainWindow::startRepeating(
1050   PIRKeyName name)
1052   QMutexLocker locker(&commandIFMutex);
1053   if (!commandInFlight)
1054   {
1055     commandInFlight = true;
1056     emit buttonPressed(currentKeyset, name);
1057   }
1061 void MainWindow::stopRepeating()
1063   QMutexLocker locker(&stopRepeatingMutex);
1064   stopRepeatingFlag = true;
1068 QWidget *MainWindow::getSecondaryWindow()
1070   return secondaryForm;
1074 void MainWindow::selectPrevFavKeyset()
1076   int size = ui->favoriteKeysetsWidget->count();
1078   if (size == 0)
1079   {
1080     // No favorites, so nothing to do!
1081     return;
1082   }
1084   int position = ui->favoriteKeysetsWidget->currentRow();
1086   --position;
1087   if (position < 0)
1088   {
1089     position = size - 1;
1090   }
1092   ui->favoriteKeysetsWidget->setCurrentRow(
1093     position,
1094     QItemSelectionModel::ClearAndSelect);
1096   // Tell the user about the change:
1097   QMaemo5InformationBox::information(
1098     0,
1099     ui->favoriteKeysetsWidget->item(position)->text());
1103 void MainWindow::selectNextFavKeyset()
1105   int size = ui->favoriteKeysetsWidget->count();
1107   if (size == 0)
1108   {
1109     // No favorites, so just return:
1110     return;
1111   }
1113   int position = ui->favoriteKeysetsWidget->currentRow();
1115   ++position;
1116   if (position == size)
1117   {
1118     position = 0;
1119   }
1121   ui->favoriteKeysetsWidget->setCurrentRow(
1122     position,
1123     QItemSelectionModel::ClearAndSelect);
1125   // Tell the user about the change:
1126   QMaemo5InformationBox::information(
1127     0,
1128     ui->favoriteKeysetsWidget->item(position)->text());

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment