#include "variable_duration_dialog.h"
#include "SH_types.h"


VariableDurationDialog::VariableDurationDialog() {
	setupUi(this);
}


void VariableDurationDialog::set(const QString & s) {
	double v = 0;
	if (s == "inf") {
		radioInfinity->setChecked(true);
		return;
	}
	QStringList dl = s.split(" ");
	dl.removeAll("");
	dl.removeAll(" ");
	v = 1;
	int ind = 0;
	if (dl.size() == 2) {
		v = dl[0].toDouble();
		switch (dl[1][0].toLatin1()) {
		case 'y': ++ind;
		case 'M': ++ind;
		case 'd': ++ind;
		case 'h': ++ind;
		case 'm': ++ind;
		case 's': ++ind;
		}
	}
	radioFinity->setChecked(true);
	comboSuffix->setCurrentIndex(ind);
	spinValue->setValue(v);
}


QString VariableDurationDialog::get() const {
	if (radioInfinity->isChecked()) return "inf";
	QString s;
	switch (comboSuffix->currentIndex()) {
	case 0: s = "z"; break;
	case 1: s = "s"; break;
	case 2: s = "m"; break;
	case 3: s = "h"; break;
	case 4: s = "d"; break;
	case 5: s = "M"; break;
	case 6: s = "y"; break;
	}
	return QString("%1 %2").arg(spinValue->value()).arg(s);
}
