summaryrefslogtreecommitdiff
path: root/noncore/tools/opie-sh/mbox.cpp
blob: 45145d9a627e0b7ab34d17c568fa3e92d75b723d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
Opie-sh.  convinience app to allow you to use qdialogs in scripts (mainly shell scripts)
Copyright (C) 2002 Thomas Stephens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either version 2 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 General
Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "mbox.h"

#include <opie2/oresource.h>

MBox::MBox(int w, int h, int type, QString title, QString message, QString *btext0, QString *btext1, QString *btext2, QWidget *parent, const char*name, bool modal, WFlags f):QDialog(parent, name, modal, f)
{
	QVBoxLayout *layout = new QVBoxLayout(this);

	QHBoxLayout *hlayout1 = new QHBoxLayout(this);
	QHBoxLayout *hlayout2 = new QHBoxLayout(this);

	int x, y;
	
	layout->addLayout(hlayout1);
	layout->addLayout(hlayout2);
	
	setCaption(title);

	QLabel *image = new QLabel(this, "image");
	QLabel *text = new QLabel(message, this, "text");
	
	switch (type)
	{
	case 0:
		image->setPixmap(Opie::Core::OResource::loadPixmap("opie-sh/info", Opie::Core::OResource::SmallIcon));
		break;
	case 1:
		image->setPixmap(Opie::Core::OResource::loadPixmap("opie-sh/warning", Opie::Core::OResource::SmallIcon));
		break;
	case 2:
		image->setPixmap(Opie::Core::OResource::loadPixmap("opie-sh/error", Opie::Core::OResource::SmallIcon));
		break;
	}

	hlayout1->addWidget(image);
	hlayout1->addSpacing(5);
	hlayout1->addWidget(text);
	
	if(!btext0->isNull())
	{
		QPushButton *button0 = new QPushButton((const QString)*btext0, this, "button0");
		hlayout2->addSpacing(5);
		hlayout2->addWidget(button0);
		hlayout2->addSpacing(5);
		connect(button0, SIGNAL(clicked()), this, SLOT(b0pressed()) );
	}
	else
	{
		QPushButton *button0 = new QPushButton("Ok", this, "button0");
		hlayout2->addSpacing(5);
		hlayout2->addWidget(button0);
		hlayout2->addSpacing(5);
		connect(button0, SIGNAL(clicked()), this, SLOT(b0pressed()) );
	}
	
	if(!btext1->isNull())
	{
		QPushButton *button1 = new QPushButton((const QString)*btext1, this, "button1");
		hlayout2->addWidget(button1);
		hlayout2->addSpacing(5);
		connect(button1, SIGNAL(clicked()), this, SLOT(b1pressed()) );
	}
	
	if(!btext2->isNull())
	{
		QPushButton *button2 = new QPushButton((const QString)*btext2, this, "button2");
		hlayout2->addWidget(button2);
		hlayout2->addSpacing(5);
		connect(button2, SIGNAL(clicked()), this, SLOT(b2pressed()) );
	}
	
	x=(w/2)-(width()/2);
	y=(h/2)-(height()/2);

	move(x, y);
}