summaryrefslogtreecommitdiffstats
path: root/src/kile/configcheckerdlg.cpp
blob: e22c81bb60d7a1740b525532fd5a6e227cd83c04 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/***************************************************************************
    begin                : Fri Jun 4 2004
    copyright            : (C) 2004 by Jeroen Wijnout
    email                : Jeroen.Wijnhout@kdemail.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "configcheckerdlg.h"

#include <tqfileinfo.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqpainter.h>

#include <tdelocale.h>
#include <kcursor.h>
#include <kprogress.h>
#include <tdeglobal.h>
#include <tdemessagebox.h>
#include <tdefiledialog.h>
#include <tdelistbox.h>
#include "kiledebug.h"

#include "configcheckerwidget.h"

namespace KileDialog
{

ResultItem::ResultItem(TDEListBox *lb, const TQString &tool, int status, const TQValueList<ConfigTest> &tests) : TQListBoxItem(lb)
{
	TQString rt = "<hr><b><font color=\"%1\">%2</font></b> (%3)<br><ul>";
	for ( uint i = 0; i < tests.count(); ++i)
	{
		TQString itemcolor = "black";
		if ( tests[i].status() == ConfigTest::Failure ) itemcolor = "#FFA201";
		else if ( tests[i].status() == ConfigTest::Critical ) itemcolor = "#AA0000";
		rt += TQString("<li><b><font color=\"%1\">%2</font></b>: &nbsp;%3</li>").arg(itemcolor).arg(tests[i].name()).arg(tests[i].resultText());
	}
	rt += "</ul>";

	TQString color = "#00AA00", statustr = i18n("Passed");
	if ( status == ConfigTest::Failure )
	{
		color = "#FFA201";
		statustr = i18n("Failed, but not critical");
	}
	else if ( status == ConfigTest::Critical )
	{
		color = "#AA0000";
		statustr = i18n("Critical failure, Kile will not function properly");
	}

	m_richText = new TQSimpleRichText(rt.arg(color).arg(tool).arg(statustr), listBox()->font());
	m_richText->setWidth(listBox()->width());

	//this is for sorting only
	setText(TQString::number(status) + ':' + tool);
}

void ResultItem::paint(TQPainter *p)
{
	m_richText->draw(p, 0, 0, TQRect(), listBox()->colorGroup());
}

ConfigChecker::ConfigChecker(TQWidget* parent) :
	KDialogBase( Plain, i18n("System Check"), Ok|Cancel|User1, Ok, parent, 0, true, true, KGuiItem("&Save Results...")),
	m_tester(0L)
{
	TQGridLayout *layout = new TQGridLayout(plainPage(), 1, 1);
	m_widget = new ConfigCheckerWidget(plainPage());
	layout->addWidget(m_widget, 1, 1);

	enableButton(Ok, false);
	enableButton(User1, false);

	run();
}

ConfigChecker::~ConfigChecker()
{
}

KProgress* ConfigChecker::progressBar()
{
	return m_widget->progressBar();
}

TQLabel* ConfigChecker::label()
{
	return m_widget->label();
}

TDEListBox* ConfigChecker::listBox()
{
	return m_widget->listBox();
}

void ConfigChecker::run()
{
	m_tester = new Tester(this, "configtester");

	connect(m_tester, TQ_SIGNAL(started()), this, TQ_SLOT(started()));
	connect(m_tester, TQ_SIGNAL(percentageDone(int)), this, TQ_SLOT(setPercentageDone(int)));
	connect(m_tester, TQ_SIGNAL(finished(bool)), this, TQ_SLOT(finished(bool)));
	connect(this, TQ_SIGNAL(user1Clicked()), this, TQ_SLOT(saveResults()));

	m_tester->runTests();
}

void ConfigChecker::slotCancel()
{
	if (m_tester) m_tester->stop();
	finished(false);
	reject();
}

void ConfigChecker::saveResults()
{
	KURL url = KFileDialog::getSaveURL();
	if ( !url.isEmpty() ) m_tester->saveResults(url);
}

void ConfigChecker::started()
{
	setCursor(KCursor::workingCursor());
	setPercentageDone(0);
}

void ConfigChecker::finished(bool ok)
{
	setCursor(KCursor::arrowCursor());
	enableButton(Cancel, false);

	if (ok)
	{
		label()->setText(i18n("Finished testing your system..."));

		TQStringList tools = m_tester->testedTools();
		TQStringList critical, failure;
		for ( uint i = 0; i < tools.count(); ++i )
		{
			int status = m_tester->statusForTool(tools[i]);
			if ( status == ConfigTest::Critical ) critical.append(tools[i]);
			else if ( status == ConfigTest::Failure ) failure.append(tools[i]);
			new ResultItem(listBox(), tools[i], status, m_tester->resultForTool(tools[i]));
		}

		listBox()->sort();

		TQString cap = i18n("Test Results");
		if ( critical.count() > 0 )
			KMessageBox::error(this, i18n("<qt>The following tools did not pass all <b>critical</b> tests:<br>%1<br>Your system is not ready to use. Please consult the results to find out what to fix.</qt>").arg(critical.join(", ")), cap);
		else if ( failure.count() > 0 )
			KMessageBox::information(this, i18n("The following tools did not pass all tests:\n %1\nYou will still be able to use Kile; however, not all features are guaranteed to work.").arg(failure.join(", ")), cap);
		else
			KMessageBox::information(this, i18n("No problems detected, your system is ready to use."), cap);
	}
	else
		label()->setText(i18n("Tests finished abruptly..."));

	enableButton(Ok, true);
	enableButton(User1, true);
}

void ConfigChecker::setPercentageDone(int p)
{
	progressBar()->setProgress(p);
}

}

#include "configcheckerdlg.moc"