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"
3 #include "pirkeysetwidgetitem.h"
5 //#include "pirexception.h"
7 #include <QtCore/QCoreApplication>
8 #include <QMutex>
9 #include <QtGui/QMessageBox>
10 #include <QSettings>
11 //#include <QDesktopServices>
12 //#include <QUrl>
14 //#include <iostream>
16 extern PIRMakeMgr makeManager;
19 MainWindow::MainWindow(QWidget *parent)
20   : QMainWindow(parent),
21     ui(new Ui::MainWindow),
22     mySelectionWindow(0),
23     documentationForm(0),
24     aboutForm(0),
25     currentKeyset(0)
26 {
27   ui->setupUi(this);
29   // Make this a Maemo 5 stacked widget:
30   setAttribute(Qt::WA_Maemo5StackedWindow);
32   // Collect the keysets:
33   myKeysets = new PIRKeysetManager(this);
35   // Set up the keyset selection window:
36   mySelectionWindow = new SelectionWindow(this);
38   myKeysets->populateGuiWidget(mySelectionWindow);
40   // Remember any favorites the user has already set:
41   populateFavorites();
43   QSettings settings("pietrzak.org", "Pierogi");
44   if (settings.contains("currentKeyset"))
45   {
46     currentKeyset = settings.value("currentKeyset").toInt();
47   }
49   enableButtons();
51   connect(
52     ui->favoriteKeysetsWidget,
53     SIGNAL(itemActivated(QListWidgetItem *)),
54     this,
55     SLOT(keysetSelectionChanged(QListWidgetItem *)),
56     Qt::QueuedConnection);
57 }
60 MainWindow::~MainWindow()
61 {
62   delete myKeysets;
63   delete mySelectionWindow;
64   if (documentationForm) delete documentationForm;
65   if (aboutForm) delete aboutForm;
66   delete ui;
67 }
70 void MainWindow::setOrientation(ScreenOrientation orientation)
71 {
72 #if defined(Q_OS_SYMBIAN)
73     // If the version of Qt on the device is < 4.7.2, that attribute won't work
74     if (orientation != ScreenOrientationAuto) {
75         const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
76         if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
77             qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
78             return;
79         }
80     }
81 #endif // Q_OS_SYMBIAN
83     Qt::WidgetAttribute attribute;
84     switch (orientation) {
85 #if QT_VERSION < 0x040702
86     // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
87     case ScreenOrientationLockPortrait:
88         attribute = static_cast<Qt::WidgetAttribute>(128);
89         break;
90     case ScreenOrientationLockLandscape:
91         attribute = static_cast<Qt::WidgetAttribute>(129);
92         break;
93     default:
94     case ScreenOrientationAuto:
95         attribute = static_cast<Qt::WidgetAttribute>(130);
96         break;
97 #else // QT_VERSION < 0x040702
98     case ScreenOrientationLockPortrait:
99         attribute = Qt::WA_LockPortraitOrientation;
100         break;
101     case ScreenOrientationLockLandscape:
102         attribute = Qt::WA_LockLandscapeOrientation;
103         break;
104     default:
105     case ScreenOrientationAuto:
106         attribute = Qt::WA_AutoOrientation;
107         break;
108 #endif // QT_VERSION < 0x040702
109     };
110     setAttribute(attribute, true);
113 void MainWindow::showExpanded()
115 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
116     showFullScreen();
117 #elif defined(Q_WS_MAEMO_5)
118     showMaximized();
119 #else
120     show();
121 #endif
125 void MainWindow::enableButtons()
127   // This is going to be a little painful...
128   // Main keys
129   emit powerEnabled(myKeysets->hasKey(currentKeyset, Power_Key));
130   emit volumeUpEnabled(myKeysets->hasKey(currentKeyset, VolumeUp_Key));
131   emit volumeDownEnabled(myKeysets->hasKey(currentKeyset, VolumeDown_Key));
132   emit channelUpEnabled(myKeysets->hasKey(currentKeyset, ChannelUp_Key));
133   emit channelDownEnabled(myKeysets->hasKey(currentKeyset, ChannelDown_Key));
135   // Utility keys:
136   emit redEnabled(myKeysets->hasKey(currentKeyset, Red_Key));
137   emit greenEnabled(myKeysets->hasKey(currentKeyset, Green_Key));
138   emit yellowEnabled(myKeysets->hasKey(currentKeyset, Yellow_Key));
139   emit blueEnabled(myKeysets->hasKey(currentKeyset, Blue_Key));
140   emit aspectRatioEnabled(myKeysets->hasKey(currentKeyset, AspectRatio_Key));
141   emit surroundEnabled(myKeysets->hasKey(currentKeyset, Surround_Key));
142   emit languageEnabled(myKeysets->hasKey(currentKeyset, Language_Key));
143   emit favoritesEnabled(myKeysets->hasKey(currentKeyset, Favorites_Key));
144   emit captionsEnabled(myKeysets->hasKey(currentKeyset, Captions_Key));
145   emit sleepEnabled(myKeysets->hasKey(currentKeyset, Sleep_Key));
146   emit inputEnabled(myKeysets->hasKey(currentKeyset, Input_Key));
147   emit muteEnabled(myKeysets->hasKey(currentKeyset, Mute_Key));
149   // Keypad keys
150   emit zeroEnabled(myKeysets->hasKey(currentKeyset, Zero_Key));
151   emit oneEnabled(myKeysets->hasKey(currentKeyset, One_Key));
152   emit twoEnabled(myKeysets->hasKey(currentKeyset, Two_Key));
153   emit threeEnabled(myKeysets->hasKey(currentKeyset, Three_Key));
154   emit fourEnabled(myKeysets->hasKey(currentKeyset, Four_Key));
155   emit fiveEnabled(myKeysets->hasKey(currentKeyset, Five_Key));
156   emit sixEnabled(myKeysets->hasKey(currentKeyset, Six_Key));
157   emit sevenEnabled(myKeysets->hasKey(currentKeyset, Seven_Key));
158   emit eightEnabled(myKeysets->hasKey(currentKeyset, Eight_Key));
159   emit nineEnabled(myKeysets->hasKey(currentKeyset, Nine_Key));
160   emit enterEnabled(myKeysets->hasKey(currentKeyset, Enter_Key));
161   emit clearEnabled(myKeysets->hasKey(currentKeyset, Clear_Key));
162   emit dashEnabled(myKeysets->hasKey(currentKeyset, Dash_Key));
163   emit plusOneHundredEnabled(myKeysets->hasKey(currentKeyset, PlusOneHundred_Key));
164   emit doubleDigitEnabled(myKeysets->hasKey(currentKeyset, DoubleDigit_Key));
165   emit prevChannelEnabled(myKeysets->hasKey(currentKeyset, PrevChannel_Key));
167   // Menu keys:
168   emit menuEnabled(myKeysets->hasKey(currentKeyset, Menu_Key));
169   emit upEnabled(myKeysets->hasKey(currentKeyset, Up_Key));
170   emit downEnabled(myKeysets->hasKey(currentKeyset, Down_Key));
171   emit leftEnabled(myKeysets->hasKey(currentKeyset, Left_Key));
172   emit rightEnabled(myKeysets->hasKey(currentKeyset, Right_Key));
173   emit selectEnabled(myKeysets->hasKey(currentKeyset, Select_Key));
174   emit exitEnabled(myKeysets->hasKey(currentKeyset, Exit_Key));
175   emit infoEnabled(myKeysets->hasKey(currentKeyset, Info_Key));
176   emit guideEnabled(myKeysets->hasKey(currentKeyset, Guide_Key));
178   // Media keys:
179   emit playEnabled(myKeysets->hasKey(currentKeyset, Play_Key));
180   emit pauseEnabled(myKeysets->hasKey(currentKeyset, Pause_Key));
181   emit stopEnabled(myKeysets->hasKey(currentKeyset, Stop_Key));
182   emit fastForwardEnabled(myKeysets->hasKey(currentKeyset, FastForward_Key));
183   emit reverseEnabled(myKeysets->hasKey(currentKeyset, Rewind_Key));
184   emit nextEnabled(myKeysets->hasKey(currentKeyset, Next_Key));
185   emit previousEnabled(myKeysets->hasKey(currentKeyset, Previous_Key));
186   emit stepForwardEnabled(myKeysets->hasKey(currentKeyset, StepForward_Key));
187   emit stepBackEnabled(myKeysets->hasKey(currentKeyset, StepBack_Key));
188   emit advanceEnabled(myKeysets->hasKey(currentKeyset, Advance_Key));
189   emit replayEnabled(myKeysets->hasKey(currentKeyset, Replay_Key));
190   emit ejectEnabled(myKeysets->hasKey(currentKeyset, Eject_Key));
192   // Other keys:
193   emit pipEnabled(myKeysets->hasKey(currentKeyset, PIP_Key));
194   emit pipSwapEnabled(myKeysets->hasKey(currentKeyset, PIPSwap_Key));
195   emit pipMoveEnabled(myKeysets->hasKey(currentKeyset, PIPMove_Key));
196   emit pipSourceEnabled(myKeysets->hasKey(currentKeyset, PIPSource_Key));
197   emit scanEnabled(myKeysets->hasKey(currentKeyset, Scan_Key));
198   emit programEnabled(myKeysets->hasKey(currentKeyset, Program_Key));
199   emit pictureModeEnabled(myKeysets->hasKey(currentKeyset, PictureMode_Key));
200   emit soundModeEnabled(myKeysets->hasKey(currentKeyset, SoundMode_Key));
201   emit discTitleEnabled(myKeysets->hasKey(currentKeyset, DiscTitle_Key));
202   emit discMenuEnabled(myKeysets->hasKey(currentKeyset, DiscMenu_Key));
203   emit discSelectEnabled(myKeysets->hasKey(currentKeyset, DiscSelect_Key));
204   emit recordEnabled(myKeysets->hasKey(currentKeyset, Record_Key));
205   emit trackingMinusEnabled(myKeysets->hasKey(currentKeyset, TrackingMinus_Key));
206   emit trackingPlusEnabled(myKeysets->hasKey(currentKeyset, TrackingPlus_Key));
207   emit autoTrackingEnabled(myKeysets->hasKey(currentKeyset, AutoTracking_Key));
208   emit vhsSpeedEnabled(myKeysets->hasKey(currentKeyset, VHSSpeed_Key));
210   emit keysetMakeChanged(
211     makeManager.getMakeString(myKeysets->getMake(currentKeyset)));
213   emit keysetNameChanged(myKeysets->getDisplayName(currentKeyset));
217 void MainWindow::receivedExternalWarning(
218   const char *warning)
220   QMessageBox errBox;
221   errBox.setText(warning);
222   errBox.setIcon(QMessageBox::Warning);
223   errBox.exec();
227 // Main tab buttons:
229 void MainWindow::on_powerButton_pressed()
231   emit buttonPressed(currentKeyset, Power_Key);
234 void MainWindow::on_powerButton_released()
236   stopRepeating();
239 void MainWindow::on_mainChannelUpButton_pressed()
241   emit buttonPressed(currentKeyset, ChannelUp_Key);
244 void MainWindow::on_mainChannelUpButton_released()
246   stopRepeating();
249 void MainWindow::on_mainChannelDownButton_pressed()
251   emit buttonPressed(currentKeyset, ChannelDown_Key);
254 void MainWindow::on_mainChannelDownButton_released()
256   stopRepeating();
259 void MainWindow::on_mainVolumeUp_pressed()
261   emit buttonPressed(currentKeyset, VolumeUp_Key);
264 void MainWindow::on_mainVolumeUp_released()
266   stopRepeating();
269 void MainWindow::on_mainVolumeDownButton_pressed()
271   emit buttonPressed(currentKeyset, VolumeDown_Key);
274 void MainWindow::on_mainVolumeDownButton_released()
276   stopRepeating();
280 // Utility tab buttons:
282 void MainWindow::on_redButton_pressed()
284   emit buttonPressed(currentKeyset, Red_Key);
287 void MainWindow::on_redButton_released()
289   stopRepeating();
292 void MainWindow::on_greenButton_pressed()
294   emit buttonPressed(currentKeyset, Green_Key);
297 void MainWindow::on_greenButton_released()
299   stopRepeating();
302 void MainWindow::on_yellowButton_pressed()
304   emit buttonPressed(currentKeyset, Yellow_Key);
307 void MainWindow::on_yellowButton_released()
309   stopRepeating();
312 void MainWindow::on_blueButton_pressed()
314   emit buttonPressed(currentKeyset, Blue_Key);
317 void MainWindow::on_blueButton_released()
319   stopRepeating();
322 void MainWindow::on_aspectRatioButton_pressed()
324   emit buttonPressed(currentKeyset, AspectRatio_Key);
327 void MainWindow::on_aspectRatioButton_released()
329   stopRepeating();
332 void MainWindow::on_surroundButton_pressed()
334   emit buttonPressed(currentKeyset, Surround_Key);
337 void MainWindow::on_surroundButton_released()
339   stopRepeating();
342 void MainWindow::on_languageButton_pressed()
344   emit buttonPressed(currentKeyset, Language_Key);
347 void MainWindow::on_languageButton_released()
349   stopRepeating();
352 void MainWindow::on_favoritesButton_pressed()
354   emit buttonPressed(currentKeyset, Favorites_Key);
357 void MainWindow::on_favoritesButton_released()
359   stopRepeating();
362 void MainWindow::on_captionButton_pressed()
364   emit buttonPressed(currentKeyset, Captions_Key);
367 void MainWindow::on_captionButton_released()
369   stopRepeating();
372 void MainWindow::on_inputButton_pressed()
374   emit buttonPressed(currentKeyset, Input_Key);
377 void MainWindow::on_inputButton_released()
379   stopRepeating();
382 void MainWindow::on_sleepButton_pressed()
384   emit buttonPressed(currentKeyset, Sleep_Key);
387 void MainWindow::on_sleepButton_released()
389   stopRepeating();
392 void MainWindow::on_muteButton_pressed()
394   emit buttonPressed(currentKeyset, Mute_Key);
397 void MainWindow::on_muteButton_released()
399   stopRepeating();
403 // Keypad tab buttons:
405 void MainWindow::on_oneButton_pressed()
407   emit buttonPressed(currentKeyset, One_Key);
410 void MainWindow::on_oneButton_released()
412   stopRepeating();
415 void MainWindow::on_twoButton_pressed()
417   emit buttonPressed(currentKeyset, Two_Key);
420 void MainWindow::on_twoButton_released()
422   stopRepeating();
425 void MainWindow::on_threeButton_pressed()
427   emit buttonPressed(currentKeyset, Three_Key);
430 void MainWindow::on_threeButton_released()
432   stopRepeating();
435 void MainWindow::on_fourButton_pressed()
437   emit buttonPressed(currentKeyset, Four_Key);
440 void MainWindow::on_fourButton_released()
442   stopRepeating();
445 void MainWindow::on_fiveButton_pressed()
447   emit buttonPressed(currentKeyset, Five_Key);
450 void MainWindow::on_fiveButton_released()
452   stopRepeating();
455 void MainWindow::on_sixButton_pressed()
457   emit buttonPressed(currentKeyset, Six_Key);
460 void MainWindow::on_sixButton_released()
462   stopRepeating();
465 void MainWindow::on_sevenButton_pressed()
467   emit buttonPressed(currentKeyset, Seven_Key);
470 void MainWindow::on_sevenButton_released()
472   stopRepeating();
475 void MainWindow::on_eightButton_pressed()
477   emit buttonPressed(currentKeyset, Eight_Key);
480 void MainWindow::on_eightButton_released()
482   stopRepeating();
485 void MainWindow::on_nineButton_pressed()
487   emit buttonPressed(currentKeyset, Nine_Key);
490 void MainWindow::on_nineButton_released()
492   stopRepeating();
495 void MainWindow::on_zeroButton_pressed()
497   emit buttonPressed(currentKeyset, Zero_Key);
500 void MainWindow::on_zeroButton_released()
502   stopRepeating();
505 void MainWindow::on_enterButton_pressed()
507   emit buttonPressed(currentKeyset, Enter_Key);
510 void MainWindow::on_enterButton_released()
512   stopRepeating();
515 void MainWindow::on_clearButton_pressed()
517   emit buttonPressed(currentKeyset, Clear_Key);
520 void MainWindow::on_clearButton_released()
522   stopRepeating();
525 void MainWindow::on_prevChannelButton_pressed()
527   emit buttonPressed(currentKeyset, PrevChannel_Key);
530 void MainWindow::on_prevChannelButton_released()
532   stopRepeating();
535 void MainWindow::on_plusOneHundredButton_pressed()
537   emit buttonPressed(currentKeyset, PlusOneHundred_Key);
540 void MainWindow::on_plusOneHundredButton_released()
542   stopRepeating();
545 void MainWindow::on_dashButton_pressed()
547   emit buttonPressed(currentKeyset, Dash_Key);
550 void MainWindow::on_dashButton_released()
552   stopRepeating();
555 void MainWindow::on_doubleDigitButton_pressed()
557   emit buttonPressed(currentKeyset, DoubleDigit_Key);
560 void MainWindow::on_doubleDigitButton_released()
562   stopRepeating();
566 // Menu tab buttons:
568 void MainWindow::on_upButton_pressed()
570   emit buttonPressed(currentKeyset, Up_Key);
573 void MainWindow::on_upButton_released()
575   stopRepeating();
578 void MainWindow::on_leftButton_pressed()
580   emit buttonPressed(currentKeyset, Left_Key);
583 void MainWindow::on_leftButton_released()
585   stopRepeating();
588 void MainWindow::on_rightButton_pressed()
590   emit buttonPressed(currentKeyset, Right_Key);
593 void MainWindow::on_rightButton_released()
595   stopRepeating();
598 void MainWindow::on_downButton_pressed()
600   emit buttonPressed(currentKeyset, Down_Key);
603 void MainWindow::on_downButton_released()
605   stopRepeating();
608 void MainWindow::on_selectButton_pressed()
610   emit buttonPressed(currentKeyset, Select_Key);
613 void MainWindow::on_selectButton_released()
615   stopRepeating();
618 void MainWindow::on_menuButton_pressed()
620   emit buttonPressed(currentKeyset, Menu_Key);
623 void MainWindow::on_menuButton_released()
625   stopRepeating();
628 void MainWindow::on_exitButton_pressed()
630   emit buttonPressed(currentKeyset, Exit_Key);
633 void MainWindow::on_exitButton_released()
635   stopRepeating();
640 // Media tab buttons:
642 void MainWindow::on_mediaPreviousButton_pressed()
644   emit buttonPressed(currentKeyset, Previous_Key);
647 void MainWindow::on_mediaPreviousButton_released()
649   stopRepeating();
652 void MainWindow::on_mediaNextButton_pressed()
654   emit buttonPressed(currentKeyset, Next_Key);
657 void MainWindow::on_mediaNextButton_released()
659   stopRepeating();
662 void MainWindow::on_replayButton_pressed()
664   emit buttonPressed(currentKeyset, Replay_Key);
667 void MainWindow::on_replayButton_released()
669   stopRepeating();
672 void MainWindow::on_advanceButton_pressed()
674   emit buttonPressed(currentKeyset, Advance_Key);
677 void MainWindow::on_advanceButton_released()
679   stopRepeating();
682 void MainWindow::on_stepBackButton_pressed()
684   emit buttonPressed(currentKeyset, StepBack_Key);
687 void MainWindow::on_stepBackButton_released()
689   stopRepeating();
692 void MainWindow::on_stepForwardButton_pressed()
694   emit buttonPressed(currentKeyset, StepForward_Key);
697 void MainWindow::on_stepForwardButton_released()
699   stopRepeating();
702 void MainWindow::on_reverseButton_pressed()
704   emit buttonPressed(currentKeyset, Rewind_Key);
707 void MainWindow::on_reverseButton_released()
709   stopRepeating();
712 void MainWindow::on_fastForwardButton_pressed()
714   emit buttonPressed(currentKeyset, FastForward_Key);
717 void MainWindow::on_fastForwardButton_released()
719   stopRepeating();
722 void MainWindow::on_playButton_pressed()
724   emit buttonPressed(currentKeyset, Play_Key);
727 void MainWindow::on_playButton_released()
729   stopRepeating();
732 void MainWindow::on_pauseButton_pressed()
734   emit buttonPressed(currentKeyset, Pause_Key);
737 void MainWindow::on_pauseButton_released()
739   stopRepeating();
742 void MainWindow::on_stopButton_pressed()
744   emit buttonPressed(currentKeyset, Stop_Key);
747 void MainWindow::on_stopButton_released()
749   stopRepeating();
752 void MainWindow::on_ejectButton_pressed()
754   emit buttonPressed(currentKeyset, Eject_Key);
757 void MainWindow::on_ejectButton_released()
759   stopRepeating();
763 // Misc tab slots:
765 void MainWindow::on_pipOnOffButton_pressed()
767   emit buttonPressed(currentKeyset, PIP_Key);
770 void MainWindow::on_pipOnOffButton_released()
772   stopRepeating();
775 void MainWindow::on_pipSwapButton_pressed()
777   emit buttonPressed(currentKeyset, PIPSwap_Key);
780 void MainWindow::on_pipSwapButton_released()
782   stopRepeating();
785 void MainWindow::on_pipPositionButton_pressed()
787   emit buttonPressed(currentKeyset, PIPMove_Key);
790 void MainWindow::on_pipPositionButton_released()
792   stopRepeating();
795 void MainWindow::on_pipSourceButton_pressed()
797   emit buttonPressed(currentKeyset, PIPSource_Key);
800 void MainWindow::on_pipSourceButton_released()
802   stopRepeating();
805 void MainWindow::on_scanButton_pressed()
807   emit buttonPressed(currentKeyset, Scan_Key);
810 void MainWindow::on_scanButton_released()
812   stopRepeating();
815 void MainWindow::on_programButton_pressed()
817   emit buttonPressed(currentKeyset, Program_Key);
820 void MainWindow::on_programButton_released()
822   stopRepeating();
825 void MainWindow::on_pictureModeButton_pressed()
827   emit buttonPressed(currentKeyset, PictureMode_Key);
830 void MainWindow::on_pictureModeButton_released()
832   stopRepeating();
835 void MainWindow::on_soundModeButton_pressed()
837   emit buttonPressed(currentKeyset, SoundMode_Key);
840 void MainWindow::on_soundModeButton_released()
842   stopRepeating();
845 void MainWindow::on_discTitleButton_pressed()
847   emit buttonPressed(currentKeyset, DiscTitle_Key);
850 void MainWindow::on_discTitleButton_released()
852   stopRepeating();
855 void MainWindow::on_discMenuButton_pressed()
857   emit buttonPressed(currentKeyset, DiscMenu_Key);
860 void MainWindow::on_discMenuButton_released()
862   stopRepeating();
865 void MainWindow::on_discSelectButton_pressed()
867   emit buttonPressed(currentKeyset, DiscSelect_Key);
870 void MainWindow::on_discSelectButton_released()
872   stopRepeating();
875 void MainWindow::on_trackingPlusButton_pressed()
877   emit buttonPressed(currentKeyset, TrackingPlus_Key);
880 void MainWindow::on_trackingPlusButton_released()
882   stopRepeating();
885 void MainWindow::on_trackingMinusButton_pressed()
887   emit buttonPressed(currentKeyset, TrackingMinus_Key);
890 void MainWindow::on_trackingMinusButton_released()
892   stopRepeating();
895 void MainWindow::on_autoTrackingButton_pressed()
897   emit buttonPressed(currentKeyset, AutoTracking_Key);
900 void MainWindow::on_autoTrackingButton_released()
902   stopRepeating();
905 void MainWindow::on_vhsSpeedButton_pressed()
907   emit buttonPressed(currentKeyset, VHSSpeed_Key);
910 void MainWindow::on_vhsSpeedButton_released()
912   stopRepeating();
915 void MainWindow::on_recordButton_pressed()
917   emit buttonPressed(currentKeyset, Record_Key);
920 void MainWindow::on_recordButton_released()
922   stopRepeating();
926 // Menu actions:
928 void MainWindow::on_actionSelectKeyset_triggered()
930   mySelectionWindow->show();
933 void MainWindow::on_actionAbout_triggered()
935   if (!aboutForm)
936   {
937     aboutForm = new PIRAboutForm(this);
938   }
940   aboutForm->show();
943 void MainWindow::on_actionDocumentation_triggered()
945   if (!documentationForm)
946   {
947     documentationForm = new PIRDocumentationForm(this);
948   }
950   documentationForm->show();
954 // Other actions:
956 void MainWindow::keysetSelectionChanged(
957   QListWidgetItem *item)
959   if (!item) return;  // Should probably say something here!
961   PIRKeysetWidgetItem *kwi = dynamic_cast<PIRKeysetWidgetItem *>(item);
963   if (!kwi) return; // Also need to say something here
964   
965   currentKeyset = kwi->getID();
967   QSettings settings("pietrzak.org", "Pierogi");
968   settings.setValue("currentKeyset", currentKeyset);
970   enableButtons();
974 void MainWindow::on_addKeysetButton_clicked()
976   // Is the current keylist already a favorite?
977   int count = ui->favoriteKeysetsWidget->count();
978   int index = 0;
979   PIRKeysetWidgetItem *kwi = NULL;
980   while (index < count)
981   {
982     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
983       ui->favoriteKeysetsWidget->item(index));
985     if (kwi && (kwi->getID() == currentKeyset))
986     {
987       // Current keyset already in list!  No need to continue.
988       return;
989     }
990     ++index;
991   }
993   // Ok, add the current keylist to the favorites:
994   PIRMakeName make = myKeysets->getMake(currentKeyset);
996   QString name = makeManager.getMakeString(make);
997   name.append(" ");
998   name.append(myKeysets->getDisplayName(currentKeyset));
1000   ui->favoriteKeysetsWidget->addItem(
1001     new PIRKeysetWidgetItem(name, currentKeyset, make));
1003   // And, add the keylist id to the persistent list:
1004   QSettings settings("pietrzak.org", "Pierogi");
1006   int favSettingsSize = settings.beginReadArray("favorites");
1007   settings.endArray();
1009   settings.beginWriteArray("favorites");
1010   settings.setArrayIndex(favSettingsSize);
1011   settings.setValue("keylistID", currentKeyset);
1012   settings.endArray();
1016 void MainWindow::on_removeKeysetButton_clicked()
1018   // Deleting an item removes it from the list, so just grab the currently
1019   // selected item and delete it:
1020   QListWidgetItem *item = ui->favoriteKeysetsWidget->currentItem();
1022   if (item) delete item;
1024   // Remove this item from the persistent list.  Well, actually, it seems a
1025   // little more convenient to just blow away the existing list of favorites
1026   // and rewrite it, as modifying an existing QSettings array in the middle
1027   // seems a bit hard...
1028   QSettings settings("pietrzak.org", "Pierogi");
1030   settings.remove("favorites");
1032   int count = ui->favoriteKeysetsWidget->count();
1034   // If the count is empty, we can stop right here:
1035   if (count == 0) return;
1037   int index = 0;
1038   PIRKeysetWidgetItem *kwi = NULL;
1039   settings.beginWriteArray("favorites");
1040   while (index < count)
1041   {
1042     kwi = dynamic_cast<PIRKeysetWidgetItem *>(
1043       ui->favoriteKeysetsWidget->item(index));
1045     settings.setArrayIndex(index);
1046     settings.setValue("keylistID", kwi->getID());
1047     ++index;
1048   }
1049   settings.endArray();
1052 void MainWindow::populateFavorites()
1054   QSettings settings("pietrzak.org", "Pierogi");
1056   int size = settings.beginReadArray("favorites");
1057   int index = 0;
1058   PIRMakeName make;
1059   QString name;
1060   unsigned int id;
1062   while (index < size)
1063   {
1064     settings.setArrayIndex(index);
1065     id = settings.value("keylistID").toInt();
1066     make = myKeysets->getMake(id);
1067     name = makeManager.getMakeString(make);
1068     name.append(" ");
1069     name.append(myKeysets->getDisplayName(id));
1070     ui->favoriteKeysetsWidget->addItem(
1071       new PIRKeysetWidgetItem(name, id, make));
1072     ++index;
1073   }
1075   settings.endArray();

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment