#include "addApplicationLauncher.h" #include "ui_addApplicationLauncher.h" AddApplicationLauncher::AddApplicationLauncher(QWidget *parent) : QDialog(parent), ui(new Ui::AddApplicationLauncher) { ApplicationLaunchers* launcher = new ApplicationLaunchers(); setApplicationLauncher(launcher); ui->setupUi(this); } AddApplicationLauncher::AddApplicationLauncher(ApplicationLaunchers* launcher, QWidget *parent) : QDialog(parent), ui(new Ui::AddApplicationLauncher) { setApplicationLauncher(launcher); ui->setupUi(this); init(); } AddApplicationLauncher::~AddApplicationLauncher() { delete ui; } void AddApplicationLauncher::init() { ui->applicationName_Field->setText(applicationLauncher->getApplicationName()); ui->applicationExtension_List->addItems(applicationLauncher->getApplicationExtensions()); ui->applicationLocation_Field->setText(applicationLauncher->getApplicationLocation()); } void AddApplicationLauncher::appendApplicationExtension(QString applicationExtensionName) { int idx = 0; bool extensionExists = false; for(idx = 0; idx < ui->applicationExtension_List->count(); idx++) { if(ui->applicationExtension_List->item(idx)->text() == applicationExtensionName) { extensionExists = true; } } if(extensionExists == false) { ui->applicationExtension_List->addItem(applicationExtensionName); // If Extension is already on the list, duplicates are not allowed. } } void AddApplicationLauncher::removeApplicationExtension() { int idx = ui->applicationExtension_List->currentIndex().row(); if(idx >= 0) { delete ui->applicationExtension_List->item(idx); } } /* Setter Functions */ void AddApplicationLauncher::setApplicationLauncher(ApplicationLaunchers* newLauncher) { applicationLauncher = newLauncher; } /* Getter Functions */ ApplicationLaunchers* AddApplicationLauncher::getApplicationLauncher() { return applicationLauncher; } void AddApplicationLauncher::on_selectApplicationLocation_clicked() { QFileDialog dialog(this); dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilter(tr("Executable File")); QString fileName = dialog.getOpenFileName(this, tr("Open File"), "/usr/bin/", tr("Executable")); // Open Dialog ui->applicationLocation_Field->setText(fileName); } void AddApplicationLauncher::on_addExtension_Button_clicked() { QString appExtensionName = ui->applicationExtension_Field->text(); if(ui->applicationExtension_Field->text() != "") { appendApplicationExtension(appExtensionName); } } void AddApplicationLauncher::on_removeExtension_Button_clicked() { removeApplicationExtension(); } void AddApplicationLauncher::on_buttonBox_accepted() { applicationLauncher->setApplicationName(ui->applicationName_Field->text()); QStringList appExtensionList; int idx = 0; for(idx = 0; idx < ui->applicationExtension_List->count(); idx++) { appExtensionList.append(ui->applicationExtension_List->item(idx)->text()); } applicationLauncher->setApplicationExtension(appExtensionList); applicationLauncher->setApplicationLocation(ui->applicationLocation_Field->text()); accept(); } void AddApplicationLauncher::on_buttonBox_rejected() { reject(); }