Moved Mute button, lots new keysets
[pierogi] / pirselectkeysetform.cpp
1 #include "pirselectkeysetform.h"
2 #include "ui_pirselectkeysetform.h"
3 #include "pirkeysetwidgetitem.h"
4 #include <QListWidget>
5
6 extern PIRMakeMgr makeManager;
7 extern PIRDeviceTypeMgr deviceManager;
8
9 PIRSelectKeysetForm::PIRSelectKeysetForm(
10   QWidget *parent)
11   : QWidget(parent),
12     ui(new Ui::PIRSelectKeysetForm),
13     currentMake(Any_Make),
14     currentDevice(Any_Device)
15 {
16   ui->setupUi(this);
17
18   setAttribute(Qt::WA_Maemo5StackedWindow);
19   setWindowFlags(windowFlags() | Qt::Window);
20
21   // push the list of makers into the make combo box:
22   makeManager.populateComboBox(ui->makeComboBox);
23   deviceManager.populateComboBox(ui->deviceComboBox);
24
25   // Connection telling main window that keyset has been selected:
26   connect(
27     ui->keysetListWidget,
28     SIGNAL(itemActivated(QListWidgetItem *)),
29     parent,
30     SLOT(keysetSelectionChanged(QListWidgetItem *)),
31     Qt::QueuedConnection);
32
33   // Connection used to filter keyset list:
34   connect(
35     ui->makeComboBox,
36     SIGNAL(currentIndexChanged(int)),
37     this,
38     SLOT(filterListByMake(int)),
39     Qt::QueuedConnection);
40
41   connect(
42     ui->deviceComboBox,
43     SIGNAL(currentIndexChanged(int)),
44     this,
45     SLOT(filterListByDeviceType(int)),
46     Qt::QueuedConnection);
47 }
48
49 PIRSelectKeysetForm::~PIRSelectKeysetForm()
50 {
51   delete ui;
52 }
53
54 void PIRSelectKeysetForm::addNameToList(
55   QString name,
56   unsigned int index,
57   PIRMakeName make)
58 {
59   ui->keysetListWidget->addItem(new PIRKeysetWidgetItem(name, index, make));
60 }
61
62 void PIRSelectKeysetForm::addWidgetItem(
63   PIRKeysetWidgetItem *kwi)
64 {
65   ui->keysetListWidget->addItem(kwi);
66 }
67
68 QListWidget *PIRSelectKeysetForm::getKeysetListWidget()
69 {
70   return ui->keysetListWidget;
71 }
72
73 void PIRSelectKeysetForm::filterListByMake(
74   int make)
75 {
76   currentMake = (PIRMakeName) make;
77   refilterList();
78 }
79
80 void PIRSelectKeysetForm::filterListByDeviceType(
81   int deviceType)
82 {
83   currentDevice = (PIRDeviceTypeName) deviceType;
84   refilterList();
85 }
86
87 void PIRSelectKeysetForm::refilterList()
88 {
89   int index = 0;
90   int count = ui->keysetListWidget->count();
91   PIRKeysetWidgetItem *item;
92   while (index < count)
93   {
94     item = dynamic_cast<PIRKeysetWidgetItem *>(
95       ui->keysetListWidget->item(index));
96
97     // Does the keylist have the required make?
98     if ((currentMake == Any_Make) || (item->getMake() == currentMake))
99     {
100       // And, does the keylist have the required device type?
101       if ((currentDevice == Any_Device)
102           || (item->supportsDeviceType(currentDevice)))
103       {
104         // Yes, we can show this keylist:
105         item->setHidden(false);
106       }
107       else
108       {
109         item->setHidden(true);
110       }
111     }
112     else
113     {
114       item->setHidden(true);
115     }
116
117     ++index;
118   }
119 }