Advanced Settings Panel
[pierogi] / dialogs / pirselectmacrodialog.cpp
1 #include "pirselectmacrodialog.h"
2 #include "ui_pirselectmacrodialog.h"
3
4 #include "macros/pirmacropack.h"
5 #include "macros/pirmacro.h"
6 #include "macros/pirreversemultitap.h"
7 #include "mainwindow.h"
8 #include <QMaemo5InformationBox>
9
10 // Debugging includes:
11 #include <iostream>
12
13 /*
14 PIRSelectMacroDialog::PIRSelectMacroDialog(QWidget *parent) :
15   QDialog(parent),
16   ui(new Ui::PIRSelectMacroDialog)
17 {
18   ui->setupUi(this);
19 }
20 */
21
22
23 PIRSelectMacroDialog::PIRSelectMacroDialog()
24   : QDialog(0),
25     ui(new Ui::PIRSelectMacroDialog)
26 {
27   ui->setupUi(this);
28 }
29
30
31 PIRSelectMacroDialog::~PIRSelectMacroDialog()
32 {
33   // This is a hack to get around object ownership issues:
34   while (ui->macroTreeWidget->topLevelItemCount())
35   {
36     ui->macroTreeWidget->takeTopLevelItem(0);
37   }
38
39   delete ui;
40 }
41
42
43 void PIRSelectMacroDialog::addPack(
44   PIRMacroPack *pack)
45 {
46   ui->macroTreeWidget->addTopLevelItem(pack);
47 }
48
49
50 void PIRSelectMacroDialog::on_buttonBox_accepted()
51 {
52   // Try to find a usable macro in the list of selected items.  (There should
53   // only be one item in the list anyway.)
54   QList<QTreeWidgetItem *> items = ui->macroTreeWidget->selectedItems();
55
56   int index = 0;
57   int size = items.size();
58
59   while (index < size)
60   {
61     if (items[index]->parent() != 0)
62     {
63       emit macroChosen(items[index]);
64       return;
65     }
66
67     ++index;
68   }
69 }
70
71
72 /*
73 void PIRSelectMacroDialog::on_buttonBox_rejected()
74 {
75
76 }
77 */
78
79 void PIRSelectMacroDialog::on_newButton_clicked()
80 {
81   emit newMacroRequested();
82   accept();
83 }
84
85
86 void PIRSelectMacroDialog::on_editButton_clicked()
87 {
88   // Find the first selected macro, if any:
89   QList<QTreeWidgetItem *> items = ui->macroTreeWidget->selectedItems();
90
91   if (items.size() > 0)
92   {
93     if (items[0]->parent() == 0)
94     {
95       QMaemo5InformationBox::information(0, "Cannot Edit MacroPacks");
96     }
97     else
98     {
99       emit editMacroRequested(items[0]);
100     }
101   }
102
103   accept();
104 }
105
106
107 void PIRSelectMacroDialog::on_deleteButton_clicked()
108 {
109   // Find the first selected macro, if any:
110   QList<QTreeWidgetItem *> items = ui->macroTreeWidget->selectedItems();
111
112   if (items.size() > 0)
113   {
114     if (items[0]->parent() == 0)
115     {
116       QMaemo5InformationBox::information(0, "Cannot Delete MacroPacks");
117     }
118     else
119     {
120       emit deleteMacroRequested(items[0]);
121     }
122   }
123
124   accept();
125 }
126
127
128 void PIRSelectMacroDialog::resetIndices()
129 {
130   ui->macroTreeWidget->setCurrentItem(
131     ui->macroTreeWidget->topLevelItem(0));
132 }