/*
    PIQt Utils - Qt utilites for PIP

    Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CONNECTION_EDIT_H
#define CONNECTION_EDIT_H

#include "piconnection.h"
#include "qad_piqt_utils_export.h"

#include <QDialog>


namespace Ui {
class ConnectionEdit;
}

class FilterItem;
class DeviceItem;
class SenderItem;

class QAD_PIQT_UTILS_EXPORT ConnectionEdit: public QDialog {
	Q_OBJECT

public:
	explicit ConnectionEdit(QWidget * parent = 0);
	~ConnectionEdit();

	QString configuration() const;
	QByteArray model() const;
	QString name() const;

	void setName(const QString & name);
	void addDevice(const QString & name, const QString & path);
	void setModel(const QByteArray & m);

private:
	void accept();
	void keyPressEvent(QKeyEvent *) {}
	void applyFilter(FilterItem * b);
	void applyDevice(DeviceItem * b);
	void applySender(SenderItem * b);
	int getOptions() const;
	void setOptions(int o);

	Ui::ConnectionEdit * ui;
	PIConnection * conn;
	bool loading;
	int udevicenum;

private slots:
	void recreateRequest() {
		if (!loading) QMetaObject::invokeMethod(this, "recreateConnection", Qt::QueuedConnection);
	}
	void on_buttonRemove_clicked();
	void on_buttonClear_clicked();
	void on_buttonFilterAdd_clicked();
	void on_buttonFilterModify_clicked();
	void on_buttonDeviceAdd_clicked();
	void on_buttonDeviceModify_clicked();
	void on_buttonSenderAdd_clicked();
	void on_buttonSenderModify_clicked();
	void on_comboSplit_currentIndexChanged(int index);
	void selectionChanged();

public slots:
	void recreateConnection();
};

#endif // CONNECTION_EDIT_H
