Adding Macros!
[pierogi] / dialogs / pirselectmacrodialog.cpp
index 6d58a3a..96c353f 100644 (file)
@@ -2,8 +2,13 @@
 #include "ui_pirselectmacrodialog.h"
 
 #include "macros/pirmacropack.h"
+#include "macros/pirmacro.h"
 #include "macros/pirreversemultitap.h"
 #include "mainwindow.h"
+#include <QMaemo5InformationBox>
+
+// Debugging includes:
+#include <iostream>
 
 /*
 PIRSelectMacroDialog::PIRSelectMacroDialog(QWidget *parent) :
@@ -15,25 +20,30 @@ PIRSelectMacroDialog::PIRSelectMacroDialog(QWidget *parent) :
 */
 
 
-PIRSelectMacroDialog::PIRSelectMacroDialog(
-  MainWindow *mw)
-  : QDialog(mw),
+PIRSelectMacroDialog::PIRSelectMacroDialog()
+  : QDialog(0),
     ui(new Ui::PIRSelectMacroDialog)
-//    mainWindow(mw)
 {
   ui->setupUi(this);
-
-  userPack = new PIRMacroPack(ui->macroTreeWidget, "User Defined Macros");
-  multitapPack = new PIRReverseMultitap(ui->macroTreeWidget, mw);
 }
 
 
 PIRSelectMacroDialog::~PIRSelectMacroDialog()
 {
+  // This is a hack to get around object ownership issues:
+  while (ui->macroTreeWidget->topLevelItemCount())
+  {
+    ui->macroTreeWidget->takeTopLevelItem(0);
+  }
+
   delete ui;
+}
 
-  delete userPack;
-  delete multitapPack;
+
+void PIRSelectMacroDialog::addPack(
+  PIRMacroPack *pack)
+{
+  ui->macroTreeWidget->addTopLevelItem(pack);
 }
 
 
@@ -65,3 +75,58 @@ void PIRSelectMacroDialog::on_buttonBox_rejected()
 
 }
 */
+
+void PIRSelectMacroDialog::on_newButton_clicked()
+{
+  emit newMacroRequested();
+  accept();
+}
+
+
+void PIRSelectMacroDialog::on_editButton_clicked()
+{
+  // Find the first selected macro, if any:
+  QList<QTreeWidgetItem *> items = ui->macroTreeWidget->selectedItems();
+
+  if (items.size() > 0)
+  {
+    if (items[0]->parent() == 0)
+    {
+      QMaemo5InformationBox::information(0, "Cannot Edit MacroPacks");
+    }
+    else
+    {
+      emit editMacroRequested(items[0]);
+    }
+  }
+
+  accept();
+}
+
+
+void PIRSelectMacroDialog::on_deleteButton_clicked()
+{
+  // Find the first selected macro, if any:
+  QList<QTreeWidgetItem *> items = ui->macroTreeWidget->selectedItems();
+
+  if (items.size() > 0)
+  {
+    if (items[0]->parent() == 0)
+    {
+      QMaemo5InformationBox::information(0, "Cannot Delete MacroPacks");
+    }
+    else
+    {
+      emit deleteMacroRequested(items[0]);
+    }
+  }
+
+  accept();
+}
+
+
+void PIRSelectMacroDialog::resetIndices()
+{
+  ui->macroTreeWidget->setCurrentItem(
+    ui->macroTreeWidget->topLevelItem(0));
+}