Initial Commit. The packaging still does not work properly.
[confmgr] / src / addprofile.cpp
diff --git a/src/addprofile.cpp b/src/addprofile.cpp
new file mode 100644 (file)
index 0000000..2292419
--- /dev/null
@@ -0,0 +1,85 @@
+#include "addprofile.h"
+#include "ui_addprofile.h"
+#include <QDebug>
+#include <QMessageBox>
+
+AddProfile::AddProfile(QWidget *parent) :
+    QWidget(parent),
+    ui(new Ui::AddProfile)
+{
+    ui->setupUi(this);
+    connect(&mFrmAddStep, SIGNAL(StepAddedSuccessfully(Steps)),
+            this, SLOT(updateStepList(Steps)));
+    mFrmAddStep.setWindowFlags(mFrmAddStep.windowFlags() | Qt::Window);
+}
+
+AddProfile::~AddProfile()
+{
+    delete ui;
+}
+
+void AddProfile::on_addProCancel_clicked()
+{
+    this->close();
+}
+
+void AddProfile::on_addProSave_clicked()
+{
+    Profile p;
+    p.mName = ui->addProName->text();
+    p.mNoOfSteps = ui->addProStepList->count();
+    p.mSteps = mSteps;
+    emit(ProfileAddedSuccessfully(p));
+    this->close();
+}
+
+void AddProfile::showStepsUI()
+{
+    mFrmAddStep.setParent(this, Qt::Window);
+    mFrmAddStep.clear();
+    mFrmAddStep.setAttribute(Qt::WA_Maemo5StackedWindow);
+    mFrmAddStep.show();
+}
+
+void AddProfile::updateStepList(Steps step)
+{
+    mSteps.append(step);
+    QString text = "Value: " + step.value();
+    text += " || Delay: " + QString::number(step.delay());
+    ui->addProStepList->addItem(text);
+    qDebug() << "updateStepList(): Text in List:  " << text;
+}
+
+void AddProfile::on_addProRemoveStep_clicked()
+{
+    if(ui->addProStepList->count() <= 0 || ui->addProStepList->currentRow() < 0)
+    {
+        QMessageBox msg;
+        msg.setText("Please select a step first!");
+        msg.exec();
+        return;
+    }
+
+    mSteps.removeAt(ui->addProStepList->currentRow());
+    QString *pText = (QString*) ui->addProStepList->takeItem(ui->addProStepList->currentRow());
+    delete pText;
+}
+
+void AddProfile::clear()
+{
+    ui->addProStepList->clear();
+    ui->addProName->setText(QString::null);
+}
+
+void AddProfile::showProfile(Profile &p)
+{
+    ui->addProName->setText(p.mName);
+    for(unsigned int i = 0; i < p.mNoOfSteps; i++)
+    {
+        Steps step = p.mSteps.at(i);
+        QString text = "Value: " + step.value();
+        text += " || Delay: " + QString::number(step.delay());
+        ui->addProStepList->addItem(text);
+    }
+    this->show();
+}