Commit 75d1c4f4 authored by hjk's avatar hjk
Browse files

generichighlighter: search more alternative locations

parent 75048873
...@@ -45,47 +45,48 @@ namespace Internal { ...@@ -45,47 +45,48 @@ namespace Internal {
QString findDefinitionsLocation() QString findDefinitionsLocation()
{ {
QString definitionsLocation;
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
static const QLatin1String kateSyntax("/share/apps/katepart/syntax"); static const QLatin1String kateSyntax[] = {
QLatin1String("/share/apps/katepart/syntax"),
QLatin1String("/share/kde4/apps/katepart/syntax")
};
static const int kateSyntaxCount =
sizeof(kateSyntax) / sizeof(kateSyntax[0]);
// Some wild guesses. // Some wild guesses.
QDir dir; QDir dir;
QStringList paths; for (unsigned i = 0; i < kateSyntaxCount; ++i) {
paths << QLatin1String("/usr") + kateSyntax QStringList paths;
<< QLatin1String("/usr/local") + kateSyntax paths << QLatin1String("/usr") + kateSyntax[i]
<< QLatin1String("/opt") + kateSyntax; << QLatin1String("/usr/local") + kateSyntax[i]
foreach (const QString &path, paths) { << QLatin1String("/opt") + kateSyntax[i];
dir.setPath(path); foreach (const QString &path, paths) {
if (dir.exists()) { dir.setPath(path);
definitionsLocation = path; if (dir.exists())
break; return dir.path();
} }
} }
if (definitionsLocation.isEmpty()) { // Try kde-config.
// Try kde-config. QStringList programs;
QStringList programs; programs << QLatin1String("kde-config") << QLatin1String("kde4-config");
programs << QLatin1String("kde-config") << QLatin1String("kde4-config"); foreach (const QString &program, programs) {
foreach (const QString &program, programs) { QProcess process;
QProcess process; process.start(program, QStringList(QLatin1String("--prefix")));
process.start(program, QStringList(QLatin1String("--prefix"))); if (process.waitForStarted(5000)) {
if (process.waitForStarted(5000)) { process.waitForFinished(5000);
process.waitForFinished(5000); QString output = QString::fromLocal8Bit(process.readAllStandardOutput());
QString output = QString::fromLocal8Bit(process.readAllStandardOutput()); output.remove(QLatin1Char('\n'));
output.remove(QLatin1Char('\n')); for (unsigned i = 0; i < kateSyntaxCount; ++i) {
dir.setPath(output + kateSyntax); dir.setPath(output + kateSyntax[i]);
if (dir.exists()) { if (dir.exists())
definitionsLocation = dir.path(); return dir.path();
break;
}
} }
} }
} }
#endif #endif
return definitionsLocation; return QString();
} }
} // namespace Internal } // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment