/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *			(C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#include "dbsdglobal.h"

/* INT_MIN, INT_MAX */
#include <climits>

/* Qt */
#include <qpixmap.h>
#include <qstring.h>
#include <qmessagebox.h>
#include <qinputdialog.h>

#include <dialogs.h>

static const QString  dlgTitle = "DesktopBSD";

void Dialogs::infoDlg(const QString& msg) {
	QMessageBox msgBox;
	msgBox.setText(msg);
	msgBox.setCaption(dlgTitle);
	msgBox.setIconPixmap(DBSDGlobal::getIconLoader()->loadIcon("messagebox_info",
								DBSDIconLoader::Size32x32));
	msgBox.exec();
}

void Dialogs::warnDlg(const QString& msg) {
	QMessageBox msgBox;
	msgBox.setText(msg);
	msgBox.setCaption(dlgTitle);
	msgBox.setIconPixmap(DBSDGlobal::getIconLoader()->loadIcon("messagebox_warning",
								DBSDIconLoader::Size32x32));
	msgBox.exec();
}

void Dialogs::critDlg(const QString& msg) {
	QMessageBox msgBox;
	msgBox.setText(msg);
	msgBox.setCaption(dlgTitle);
	msgBox.setIconPixmap(DBSDGlobal::getIconLoader()->loadIcon("messagebox_critical",
								DBSDIconLoader::Size32x32));
	msgBox.exec();
}

bool Dialogs::question(const QString& msg) {
	QMessageBox qBox(dlgTitle, msg, QMessageBox::NoIcon, QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton);
	qBox.setIconPixmap(DBSDGlobal::getIconLoader()->loadIcon("help",
							 DBSDIconLoader::Size32x32));
	qBox.setButtonText(QMessageBox::Yes, QMessageBox::tr("Yes"));
	qBox.setButtonText(QMessageBox::No, QMessageBox::tr("No"));
	return  (qBox.exec() == QMessageBox::Yes);
}

int Dialogs::intInput(const QString& text, bool *ok, int value, int minVal, int maxVal) {
	return  QInputDialog::getInteger(dlgTitle, text, value, minVal, maxVal, 1, ok);
}

QString Dialogs::strInput(const QString& text, bool *ok, const QString& value) {
	return  QInputDialog::getText(dlgTitle, text, QLineEdit::Normal, value, ok);
}
