summaryrefslogtreecommitdiffstats
path: root/kaffeine/src/instwizard.cpp
blob: cc880d188c190022cdefba5a549faba6d9f1d142 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
 * instwizard.cpp
 *
 * Copyright (C) 2004-2005 Jürgen Kofler <kaffeine@gmx.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.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <tdelocale.h>
#include <kdebug.h>
#include <kprocess.h>
#include <tdeglobal.h>
#include <kstandarddirs.h>
#include <ktextbrowser.h>
#include <kservice.h>

#include <tqcheckbox.h>
#include <tqvbox.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqstringlist.h>
#include <tdeversion.h>
#include <tdeapplication.h>

//#include <xine.h>

#include "version.h"
#include "instwizard.h"
#include "instwizard.moc"
#ifdef HAVE_DVB
#include "dvbconfig.h"
#endif

void InstWizard::internalWizard()
{
	setCaption(i18n("Kaffeine %1 Installation Wizard").arg(KAFFEINE_VERSION));
	resize(400,400);

	/************** installation check ************************/

	KTextBrowser* page1 = new KTextBrowser(this);
	addPage(page1, i18n("Installation Check"));
	setNextEnabled(page1, true);
	setBackEnabled(page1, false);
	setHelpEnabled(page1, false);
	setFinishEnabled(page1, false);

	TQString infoString;
	TQTextStream info(&infoString, IO_WriteOnly);

	//KAFFEINE-PART

	info << "<b>" << i18n("Kaffeine-Xine") << "...</b><br>";
	KService::Ptr service = KService::serviceByDesktopName("xine_part");
	if ((service) && (service->serviceTypes().contains("KaffeinePart")))
		info << "<font color=\"DarkGreen\">" << i18n("Ok.") << "</font>";
	else
		info << "<font color=\"DarkRed\">" << i18n("Part not found. Please check your installation!") << "</font>";

	//KAFFEINE-PART
	info << "<br><hr><b>" << "TDE" << "...</b><br>";
	info << i18n("Found version") << ": " << KDE::versionString() << "<br>";
	if (KDE::version() >= TDE_MAKE_VERSION(3,2,0))
		info << "<font color=\"DarkGreen\">" << i18n("Ok.") << "</font>";
	else
		info << "<font color=\"DarkRed\">" << i18n("Kaffeine requires TDE >= %1.").arg("3.2") << "</font>";

	//XINE-LIB
	//Should engine depending stuff be here?
	/*
	info << "<br><hr><b>" << "xine-lib" << "...</b><br>";
	TQString xineVersion = xine_get_version_string();
	info << i18n("Found version") << ": " << xineVersion << "<br>";
	if (xine_check_version(1,0,0))
	{
		int major, minor, sub;
		xine_get_version(&major, &minor, &sub);
		if (xineVersion.contains("CVS", false))
			info << "<font color=\"DarkBlue\">" << i18n("Developer version.") << "</font>";

		if ((major == 1) && (minor == 0) && (sub == 0) && (xineVersion.contains("rc", false)))
		{
			info << "<font color=\"DarkRed\">" << i18n("Kaffeine requires xine-lib >= %1. Download the latest version here:").arg("1.0") << " <a href=\"http://www.xinehq.de\">http://www.xinehq.de</a>.</font>";
		}
		else
			info << "<font color=\"DarkGreen\">" << i18n("Ok.") << "</font>";
	}
	else
		info << "<font color=\"DarkRed\">" << i18n("Kaffeine requires xine-lib >= %1. Download the latest version here:").arg("1.0")
		<< " <a href=\"http://www.xinehq.de\">http://www.xinehq.de</a>.</font>";
	*/
	//WIN32-CODECS
	/*
	info << "<hr><b>" << i18n("WIN32 Codecs") << "...</b><br>";
	TQDir d("/usr/lib/win32");
	TQStringList entries = d.entryList("wmv*");
	if (entries.count())
		info << "<font color=\"DarkGreen\">" << i18n("Ok.") << "</font>";
	else
		info << "<font color=\"DarkRed\">" << i18n("No WIN32 codecs found in /usr/lib/win32. You're not able to play Windows Media 9 files, newer Real Media files and some less common formats. Download the codecs here:")
		<< " <a href=\"http://www1.mplayerhq.hu/design7/dload.html#binary_codecs\">http://www1.mplayerhq.hu/design7/dload.html#binary_codecs</a>.</font>";
	*/
	//LIBDVDCSS
	info << "<br><hr><b>" << "libdvdcss" << "...</b><br>";
	bool dvdcss = false;
	TQDir d("/usr/lib");
	TQStringList entries = d.entryList("libdvdcss.so*");
	if (entries.count())
		dvdcss = true;
	else
	{
		d = TQDir("/usr/local/lib");
		entries = d.entryList("libdvdcss.so*");
		if (entries.count())
			dvdcss = true;
		else
		{
			d = TQDir("/usr/lib64");
			entries = d.entryList("libdvdcss.so*");
			if (entries.count())
				dvdcss = true;
		}
	}
	if (!dvdcss)
		info << "<font color=\"DarkRed\">" << i18n("libdvdcss not found. You're not able to play encrypted (most commercial) DVD's. You can get the library here (but using it may violate copyright regulations of your country!):")
		<< " <a href=\"http://developers.videolan.org/libdvdcss/\">http://developers.videolan.org/libdvdcss</a>.</font>";
	else
		info << "<font color=\"DarkGreen\">" << i18n("Ok.") << "</font>";

	//DVD-DRIVE
	info << "<br><hr><b>" << i18n("DVD Drive") << "...</b><br>";
	TDEProcess process;
	process << "/sbin/hdparm" << "-d" << "/dev/dvd";
	connect(&process, TQT_SIGNAL(receivedStdout(TDEProcess*,char*,int)), this, TQT_SLOT(slotStdout(TDEProcess*, char*, int)));
	process.start(TDEProcess::Block, TDEProcess::Stdout);

	if (stdout.contains('1'))
		info << "<font color=\"DarkGreen\">" << i18n("Ok.") << "</font>";
	else if (stdout.contains('0'))
		info << "<font color=\"DarkRed\">" << i18n("DMA mode off! For smooth DVD playback run as root:") +  " \"hdparm -d1 /dev/dvd\".</font>";
	else
		info << "<font color=\"DarkBlue\">" << i18n("Can't check DMA mode. Permission denied or no such device:")
		<< " \"/dev/dvd\".</font>";

	//DVB-DEVICES
#ifdef HAVE_DVB
	info << "<br><hr><b>" << i18n("DVB-Device") << "...</b><br>";
	if (DVBconfig::haveDvbDevice())
	{
		info << "<font color=\"DarkGreen\">" << i18n("Ok.") << "</font>";
	}
	else
	{
		info << "<font color=\"DarkBlue\">" << i18n("No DVB-Devices found. The DVB related functions will be hidden.") << "</font>";
	}
#endif

	//DISTRIBUTION
	info << "<br><hr><b>" << i18n("Distribution") << "...</b><br>";
	if (TQFile::exists("/etc/SuSE-release"))
	{
		TQFile file("/etc/SuSE-release");
		file.open(IO_ReadOnly);
		TQTextStream stream(&file);
		info << "<font color=\"DarkBlue\">" << i18n("Found") << ": " << stream.readLine() << ". </font>"
		<< i18n("The xine-lib shipped by SuSE \"may lack certain features because of legal requirements (potential patent violation)\". You should use the packages from here:")
		<< " <a href=\"http://packman.links2linux.de/?action=124\">http://packman.links2linux.de</a>.";
		file.close();
	}
	else
		info << "<font color=\"DarkGreen\">" << i18n("Ok.") << "</font>";


	info << "<hr><br><b>" << i18n("RESULT") << ":</b> ";

	if (infoString.contains("DarkRed"))
	{
		info << i18n("Found some problems, but nevertheless Kaffeine might work.");
	}
	else
	{
		info << i18n("All ok!");
	}

	info << "<br><br";

	page1->setText(infoString);

	/************** installation options **********************/
	TQVBox* page2 = new TQVBox(this);
	page2->setSpacing(20);

	TQCheckBox *m_useMMSHelper = new TQCheckBox(i18n("Use Kaffeine as helper application for mms:// (Microsoft Media) streams"), page2);
	if (!locateLocal("services", "mms.protocol"))
		m_useMMSHelper->setChecked(true);

	TQCheckBox *m_useRTSPHelper = new TQCheckBox(i18n("Use Kaffeine as helper application for rtsp:// (Real Media and others) streams"), page2);
	if (!locateLocal("services", "rtsp.protocol"))
		m_useRTSPHelper->setChecked(true);

	TQCheckBox *m_createDesktopIcon = new TQCheckBox(i18n("Create a Kaffeine icon on desktop"), page2);
	if (!TQFile::exists( TQDir::homeDirPath() + "/Desktop/kaffeine.desktop"))
		m_createDesktopIcon->setChecked(true);

	addPage(page2, i18n("Installation Options"));
	setNextEnabled(page2, false);
	setBackEnabled(page2, true);
	setHelpEnabled(page2, false);
	setFinishEnabled(page2, true);

	if (exec() == TQDialog::Accepted) {
		kdDebug() << "WizardDialog: finished pressed" << endl;

		TDEProcess process;

		TQStringList dirs = TDEGlobal::dirs()->findDirs("data", "kaffeine");
		TQString homePath = TDEGlobal::dirs()->localtdedir();
		kdDebug() << "WizardDialog: TDE homedir: " << homePath << endl;
		TQString dataPath;
		if (dirs[0].left(homePath.length()) != homePath) /* global data path */
			dataPath = dirs[0];
		else
			dataPath = dirs[1];

		if (m_useMMSHelper->isChecked())
		{
			process << "cp" << dataPath + "mms.protocol" << locateLocal("services", "mms.protocol");
			kdDebug() << "WizardDialog: cp " << dataPath + "mms.protocol" << " " << locateLocal("services", "mms.protocol") << endl;
			process.start(TDEProcess::Block);
			process.clearArguments();
		}

		if (m_useRTSPHelper->isChecked())
		{
			process << "cp" << dataPath + "rtsp.protocol" << locateLocal("services", "rtsp.protocol");
			kdDebug() << "WizardDialog: cp " << dataPath + "rtsp.protocol" << " " << locateLocal("services", "rtsp.protocol") << endl;
			process.start(TDEProcess::Block);
			process.clearArguments();
		}

		//dirs = TDEGlobal::dirs()->findDirs("apps", "Multimedia");
		dirs = TDEGlobal::dirs()->findDirs("xdgdata-apps", "kde");
		if (!dirs.isEmpty())
			dataPath = dirs[0];
		else
			kdError() << "WizardDialog: Applications path not found!" << endl;

		if (m_createDesktopIcon->isChecked())
		{
			process << "cp" << dataPath + "kaffeine.desktop" << TQDir::homeDirPath() + "/Desktop/kaffeine.desktop";
			kdDebug() << "WizardDialog: cp " << dataPath + "kaffeine.desktop" << " " << TQDir::homeDirPath() + "/Desktop/kaffeine.desktop" << endl;
			process.start(TDEProcess::Block);
			process.clearArguments();
		}
	}
}

void InstWizard::slotStdout(TDEProcess *, char *buffer, int buflen)
{
	TQString output = TQString::fromLatin1(buffer, buflen);
	kdDebug() << "WizardDialog: got from hdparm: " << output << "\n";
	stdout.append(output);
}