summaryrefslogtreecommitdiffstats
path: root/kshutdown/systemconfig.cpp
blob: c563e0e1a2b76fe5b4457033213097d56a1782c8 (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
181
182
183
184
185
186
187
188
189
190
/*
	systemconfig.cpp - A system configuration manager
	Copyright (C) 2005  Konrad Twardowski <kdtonline@poczta.onet.pl>

	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 <stdlib.h>

#include "miscutils.h"
#include "systemconfig.h"

#include <tqfileinfo.h>
#include <tqheader.h>

#include <tdeapplication.h>
#include <kiconloader.h>
#include <tdelistview.h>
#include <tdelocale.h>

// http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=417301
#include <cstdlib>

// private

int SystemConfig::_canShutDown = -1;

// public

bool SystemConfig::canShutDown()
{
/*
	if (_canShutDown == -1)
	{
		TQCString XDM_MANAGED = ::getenv("XDM_MANAGED");

		if (XDM_MANAGED.contains("maysd") || XDM_MANAGED.contains("classic"))
			_canShutDown = 1;
		else
			_canShutDown = 0;
	}
*/
	_canShutDown = 1;

	return _canShutDown == 1;
}

void SystemConfig::check(TQWidget *parent)
{
	SystemConfig *systemConfig = new SystemConfig(parent);
	systemConfig->exec();
	delete systemConfig;
}

// private

SystemConfig::SystemConfig(TQWidget *parent)
	: KDialogBase(
		parent,
		"SystemConfig", // name
		true, // modal
		i18n("System Configuration"),
		Close,
		Close // default button
	),
	_problems(0)
{
	_messages = new TDEListView(this, "TDEListView::_messages");
	_messages->setAllColumnsShowFocus(true);
	_messages->setItemMargin(5);
	_messages->setSorting(-1); // no sort
	_messages->addColumn("");
	_messages->addColumn(i18n("Message"));
	_messages->header()->setClickEnabled(false);
	connect(_messages, TQ_SIGNAL(executed(TQListViewItem *)), TQ_SLOT(slotExecuted(TQListViewItem *)));
	connect(_messages, TQ_SIGNAL(spacePressed(TQListViewItem *)), TQ_SLOT(slotExecuted(TQListViewItem *)));
	setMainWidget(_messages);

	_shutdownAllowItem = add(Info, i18n("Tip: Click here if you have problem with the \"/sbin/shutdown\" command."));

	checkFile("/sbin/poweroff");
	checkFile("/sbin/reboot");
	checkFile("/sbin/shutdown");
	checkTDM();
	checkTDE();

	if (_problems == 0)
		add(OK, i18n("No problems were found."));
}

TDEListViewItem *SystemConfig::add(const Type type, const TQString &message)
{
	TDEListViewItem *item = new TDEListViewItem(_messages);
	item->setMultiLinesEnabled(true);
	switch (type)
	{
		case Info:
			item->setPixmap(0, SmallIcon("messagebox_info"));
			break;
		case OK:
			item->setPixmap(0, SmallIcon("button_ok"));
			break;
		case Warning:
			_problems++;
			item->setPixmap(0, SmallIcon("messagebox_warning"));
			break;
	}
	item->setText(1, message);

	return item;
}

void SystemConfig::checkFile(const TQString &file)
{
	TQFileInfo program(file);

	if (!program.exists())
	{
		add(Warning, i18n("Program \"%1\" was not found!").arg(file));

		return;
	}

	if (!program.isExecutable())
	{
		add(Warning, i18n("No permissions to execute \"%1\".").arg(file));
	}
}

void SystemConfig::checkTDE()
{
	TQCString TDE_FULL_SESSION = ::getenv("TDE_FULL_SESSION");
	if (TDE_FULL_SESSION != "true")
	{
		add(Warning, i18n("It seems that this is not a TDE full session.\nKShutDown was designed to work with TDE.\nHowever, you can customize Actions in the KShutDown settings dialog\n(Settings -> Configure KShutDown... -> Actions)."));
	}
}

/* TODO: 2.0: TDM configurator
From old FAQ:
- Do it as root!
- Make sure you first create backup of the "/etc/sysconfig/desktop" file
- Remove all "GNOME" and "GDM" lines from "/etc/sysconfig/desktop" file
- Add new line: DISPLAYMANAGER="TDE"
- Reboot system and login again
*/
void SystemConfig::checkTDM()
{
	if (!canShutDown())
	{
// TODO: 2.0: auto configuration
		add(Info, i18n("Tip: You can customize Actions to work with GDM.\n(Settings -> Configure KShutDown... -> Actions)"));
		_tdmNotDetected = add(Warning, i18n("TDE Display Manager is not running,\nor the shut down/reboot function is disabled.\n\nClick here to configure TDM."));
	}
}

// private slots

void SystemConfig::slotExecuted(TQListViewItem *item)
{
	if (!item)
		return;

	if (item == _tdmNotDetected)
	{
		MiscUtils::runShellCommand("tdesu -c \"tdecmshell tdm\" -i \"exit\"");

		return;
	}

	if (item == _shutdownAllowItem)
	{
		kapp->invokeBrowser("http://doc.gwos.org/index.php/NonRootShutdown");

		return;
	}
}
#include "systemconfig.moc"