GUI: Modify ApplicationDialog to get/return Application class.

This commit is contained in:
Kimmo Varis 2011-04-02 16:30:09 +03:00
parent 91345234e0
commit 68a28ab9b9
3 changed files with 30 additions and 62 deletions

View File

@ -23,12 +23,11 @@
#include <QDebug>
#include <QMessageBox>
#include "applicationdialog.h"
#include "application.h"
ApplicationDialog::ApplicationDialog(const QString &name,
const QString &path,
const QString &params,
const QString &title,
ApplicationDialog::ApplicationDialog(const QString &title,
const Application &app,
QWidget *parent) :
QDialog(parent)
{
@ -37,9 +36,9 @@ ApplicationDialog::ApplicationDialog(const QString &name,
connect(mUI.mButtonBrowse, SIGNAL(clicked()), this, SLOT(Browse()));
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
mUI.mPath->setText(path);
mUI.mName->setText(name);
mUI.mParameters->setText(params);
mUI.mPath->setText(app.getPath());
mUI.mName->setText(app.getPath());
mUI.mParameters->setText(app.getParameters());
setWindowTitle(title);
}
@ -69,20 +68,13 @@ void ApplicationDialog::Browse()
}
}
QString ApplicationDialog::GetName()
Application ApplicationDialog::GetApplication() const
{
return mUI.mName->text();
}
QString ApplicationDialog::GetPath()
{
return mUI.mPath->text();
}
QString ApplicationDialog::GetParams()
{
return mUI.mParameters->text();
Application app;
app.setName(mUI.mName->text());
app.setPath(mUI.mPath->text());
app.setParameters(mUI.mParameters->text());
return app;
}
void ApplicationDialog::Ok()

View File

@ -22,6 +22,7 @@
#include <QDialog>
#include <QLineEdit>
#include <QString>
#include "application.h"
#include "ui_application.h"
class QWidget;
@ -38,47 +39,26 @@ class QWidget;
class ApplicationDialog : public QDialog
{
Q_OBJECT
public:
/**
* @brief Constructor
*
* @param name Default name for the application to start
* @param path Path for the application
* @param params Params for the application
* @param title Title for the dialog
* @param parent Parent widget
* @brief Constructor.
* @param title Title for the dialog.
* @param app Application definition.
* @param parent Parent widget.
*/
ApplicationDialog(const QString &name,
const QString &path,
const QString &params,
const QString &title,
ApplicationDialog(const QString &title, const Application &app,
QWidget *parent = 0);
virtual ~ApplicationDialog();
/**
* @brief Get modified name
* This is just a name to display the application. This has nothing to do
* with executing the application.
*
* @brief Get modified application
* @return Modified name
*/
QString GetName();
/**
* @brief Get modified path
* This contains the full path to the application executable.
* @return Modified path
*/
QString GetPath();
/**
* @brief Get modified parameters
* This contains the parameters given to the application.
* @return Modified path
*/
QString GetParams();
Application GetApplication() const;
protected slots:
void Ok();
/**
@ -86,6 +66,7 @@ protected slots:
*
*/
void Browse();
protected:
/**
@ -93,7 +74,6 @@ protected:
*
*/
Ui::ApplicationDialog mUI;
private:
};
/// @}
#endif // APPLICATIONDIALOG_H

View File

@ -198,14 +198,14 @@ void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
void SettingsDialog::AddApplication()
{
ApplicationDialog dialog("", "", "", tr("Add a new application"), this);
Application app;
ApplicationDialog dialog(tr("Add a new application"), app, this);
if (dialog.exec() == QDialog::Accepted)
{
const Application app(dialog.GetName(), dialog.GetPath(),
dialog.GetParams());
const Application app = dialog.GetApplication();
mTempApplications->AddApplication(app);
mUI.mListWidget->addItem(dialog.GetName());
mUI.mListWidget->addItem(app.getName());
}
}
@ -236,17 +236,13 @@ void SettingsDialog::EditApplication()
{
int row = mUI.mListWidget->row(item);
const Application app = mTempApplications->GetApplication(row);
ApplicationDialog dialog(app.getName(), app.getPath(),
app.getParameters(),
tr("Modify an application"), this);
ApplicationDialog dialog(tr("Modify an application"), app, this);
if (dialog.exec() == QDialog::Accepted)
{
const Application app2(dialog.GetName(),
dialog.GetPath(),
dialog.GetParams());
const Application app2 = dialog.GetApplication();
mTempApplications->SetApplication(row, app2);
item->setText(dialog.GetName());
item->setText(app2.getName());
}
}
}