Changeset View
Changeset View
Standalone View
Standalone View
man/kio_man.cpp
Show All 29 Lines | |||||
30 | #include <QDir> | 30 | #include <QDir> | ||
31 | #include <QFile> | 31 | #include <QFile> | ||
32 | #include <QTextStream> | 32 | #include <QTextStream> | ||
33 | #include <QTextDocument> | 33 | #include <QTextDocument> | ||
34 | #include <QMap> | 34 | #include <QMap> | ||
35 | #include <QRegExp> | 35 | #include <QRegExp> | ||
36 | #include <QStandardPaths> | 36 | #include <QStandardPaths> | ||
37 | #include <QTextCodec> | 37 | #include <QTextCodec> | ||
38 | #include <QProcess> | ||||
38 | 39 | | |||
39 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
40 | #include <KProcess> | | |||
41 | #include <kglobal.h> | | |||
42 | #include <kencodingprober.h> | 41 | #include <kencodingprober.h> | ||
43 | 42 | | |||
44 | #include "man2html.h" | 43 | #include "man2html.h" | ||
45 | #include <assert.h> | 44 | #include <assert.h> | ||
46 | #include <kfilterdev.h> | 45 | #include <kfilterdev.h> | ||
47 | 46 | | |||
48 | using namespace KIO; | 47 | using namespace KIO; | ||
49 | 48 | | |||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | 204 | QStringList::ConstIterator it_name; | |||
206 | for ( it_name = names.constBegin(); | 205 | for ( it_name = names.constBegin(); | ||
207 | it_name != names.constEnd(); | 206 | it_name != names.constEnd(); | ||
208 | it_name++ ) | 207 | it_name++ ) | ||
209 | { | 208 | { | ||
210 | if (addWhatIs(i, (*it_dir) + '/' + (*it_name), mark)) | 209 | if (addWhatIs(i, (*it_dir) + '/' + (*it_name), mark)) | ||
211 | break; | 210 | break; | ||
212 | } | 211 | } | ||
213 | if ( it_name == names.constEnd() ) { | 212 | if ( it_name == names.constEnd() ) { | ||
214 | KProcess proc; | 213 | QProcess proc; | ||
215 | proc << "whatis" << "-M" << (*it_dir) << "-w" << "*"; | 214 | proc.setProgram("whatis"); | ||
216 | proc.setOutputChannelMode( KProcess::OnlyStdoutChannel ); | 215 | proc.setArguments(QStringList() << "-M" << (*it_dir) << "-w" << "*"); | ||
217 | proc.execute(); | 216 | proc.setProcessChannelMode( QProcess::ForwardedErrorChannel ); | ||
217 | proc.start(); | ||||
218 | proc.waitForFinished(); | ||||
218 | QTextStream t( proc.readAllStandardOutput(), QIODevice::ReadOnly ); | 219 | QTextStream t( proc.readAllStandardOutput(), QIODevice::ReadOnly ); | ||
219 | parseWhatIs( i, t, mark ); | 220 | parseWhatIs( i, t, mark ); | ||
220 | } | 221 | } | ||
221 | } | 222 | } | ||
222 | } | 223 | } | ||
223 | return i; | 224 | return i; | ||
224 | } | 225 | } | ||
225 | 226 | | |||
226 | QStringList MANProtocol::manDirectories() | 227 | QStringList MANProtocol::manDirectories() | ||
227 | { | 228 | { | ||
228 | checkManPaths(); | 229 | checkManPaths(); | ||
229 | // | 230 | // | ||
230 | // Build a list of man directories including translations | 231 | // Build a list of man directories including translations | ||
231 | // | 232 | // | ||
232 | QStringList man_dirs; | 233 | QStringList man_dirs; | ||
233 | 234 | | |||
234 | for ( QStringList::ConstIterator it_dir = m_manpath.constBegin(); | 235 | for ( QStringList::ConstIterator it_dir = m_manpath.constBegin(); | ||
235 | it_dir != m_manpath.constEnd(); | 236 | it_dir != m_manpath.constEnd(); | ||
236 | it_dir++ ) | 237 | it_dir++ ) | ||
237 | { | 238 | { | ||
238 | // Translated pages in "<mandir>/<lang>" if the directory | 239 | // Translated pages in "<mandir>/<lang>" if the directory | ||
239 | // exists | 240 | // exists | ||
240 | QStringList languages = KLocale::global()->languageList(); | 241 | QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); | ||
241 | 242 | for (QList<QLocale>::ConstIterator it_loc = locales.constBegin(); | |||
242 | for (QStringList::ConstIterator it_lang = languages.constBegin(); | 243 | it_loc != locales.constEnd(); | ||
243 | it_lang != languages.constEnd(); | 244 | it_loc++ ) | ||
244 | it_lang++ ) | 245 | { | ||
245 | { | 246 | QString lang = QLocale::languageToString((*it_loc).language()); | ||
246 | if ( !(*it_lang).isEmpty() && (*it_lang) != QString("C") ) { | 247 | if ( !lang.isEmpty() && lang!=QString("C") ) { | ||
dfaure: keep the spaces around != | |||||
marten: Will fix. | |||||
247 | QString dir = (*it_dir) + '/' + (*it_lang); | 248 | QString dir = (*it_dir) + '/' + lang; | ||
248 | 249 | | |||
249 | struct stat sbuf; | 250 | struct stat sbuf; | ||
250 | 251 | | |||
251 | if ( ::stat( QFile::encodeName( dir ), &sbuf ) == 0 | 252 | if ( ::stat( QFile::encodeName( dir ), &sbuf ) == 0 | ||
252 | && S_ISDIR( sbuf.st_mode ) ) | 253 | && S_ISDIR( sbuf.st_mode ) ) | ||
253 | { | 254 | { | ||
254 | const QString p = QDir(dir).canonicalPath(); | 255 | const QString p = QDir(dir).canonicalPath(); | ||
255 | if (!man_dirs.contains(p)) man_dirs += p; | 256 | if (!man_dirs.contains(p)) man_dirs += p; | ||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Line(s) | 534 | { | |||
537 | /* Determine type of man page file by checking its path. Determination by | 538 | /* Determine type of man page file by checking its path. Determination by | ||
538 | * MIME type with KMimeType doesn't work reliablely. E.g., Solaris 7: | 539 | * MIME type with KMimeType doesn't work reliablely. E.g., Solaris 7: | ||
539 | * /usr/man/sman7fs/pcfs.7fs -> text/x-csrc : WRONG | 540 | * /usr/man/sman7fs/pcfs.7fs -> text/x-csrc : WRONG | ||
540 | * If the path name constains the string sman, assume that it's SGML and | 541 | * If the path name constains the string sman, assume that it's SGML and | ||
541 | * convert it to roff format (used on Solaris). */ | 542 | * convert it to roff format (used on Solaris). */ | ||
542 | //QString file_mimetype = KMimeType::findByPath(QString(filename), 0, false)->name(); | 543 | //QString file_mimetype = KMimeType::findByPath(QString(filename), 0, false)->name(); | ||
543 | if (QString(filename).contains("sman", Qt::CaseInsensitive)) //file_mimetype == "text/html" || ) | 544 | if (QString(filename).contains("sman", Qt::CaseInsensitive)) //file_mimetype == "text/html" || ) | ||
544 | { | 545 | { | ||
545 | KProcess proc; | 546 | QProcess proc; | ||
546 | // Determine path to sgml2roff, if not already done. | 547 | // Determine path to sgml2roff, if not already done. | ||
547 | getProgramPath(); | 548 | getProgramPath(); | ||
548 | proc << mySgml2RoffPath << filename; | 549 | proc.setProgram(mySgml2RoffPath); | ||
549 | proc.setOutputChannelMode( KProcess::OnlyStdoutChannel ); | 550 | proc.setArguments(QStringList() << filename); | ||
550 | proc.execute(); | 551 | proc.setProcessChannelMode( QProcess::ForwardedErrorChannel ); | ||
552 | proc.start(); | ||||
553 | proc.waitForFinished(); | ||||
551 | array = proc.readAllStandardOutput(); | 554 | array = proc.readAllStandardOutput(); | ||
552 | } | 555 | } | ||
553 | else | 556 | else | ||
554 | { | 557 | { | ||
555 | if (QDir::isRelativePath(filename)) | 558 | if (QDir::isRelativePath(filename)) | ||
556 | { | 559 | { | ||
557 | qCDebug(KIO_MAN_LOG) << "relative " << filename; | 560 | qCDebug(KIO_MAN_LOG) << "relative " << filename; | ||
558 | filename = QDir::cleanPath(lastdir + '/' + filename).toUtf8(); | 561 | filename = QDir::cleanPath(lastdir + '/' + filename).toUtf8(); | ||
▲ Show 20 Lines • Show All 869 Lines • Show Last 20 Lines |
keep the spaces around !=