From kde-commits Wed Feb 13 22:48:39 2013 From: Kevin Funk Date: Wed, 13 Feb 2013 22:48:39 +0000 To: kde-commits Subject: [kdevplatform] language/backgroundparser: Show currently parsing file in progress bar Message-Id: <20130213224839.17B4FA6091 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=136079572806117 Git commit 0e0ea5812cb318f0a212ff91df157a9b71314105 by Kevin Funk. Committed on 08/02/2013 at 02:32. Pushed by kfunk into branch 'master'. Show currently parsing file in progress bar The statusbar badly needs to support job-based tracking... On my TODO. REVIEW: 108847 M +35 -0 language/backgroundparser/backgroundparser.cpp http://commits.kde.org/kdevplatform/0e0ea5812cb318f0a212ff91df157a9b71314105 diff --git a/language/backgroundparser/backgroundparser.cpp b/language/back= groundparser/backgroundparser.cpp index d3bf7d7..1176244 100644 --- a/language/backgroundparser/backgroundparser.cpp +++ b/language/backgroundparser/backgroundparser.cpp @@ -61,6 +61,38 @@ = const bool separateThreadForHighPriority =3D true; = +/** + * Elides string in @p path, e.g. "VEEERY/LONG/PATH" -> ".../LONG/PATH" + * - probably much faster than QFontMetrics::elidedText() + * - we dont need a widget context + * - takes path separators into account + * + * @p width Maximum number of characters + * + * TODO: Move to kdevutil? + */ +static QString elidedPathLeft(const QString& path, int width) +{ + static const QChar separator =3D QDir::separator(); + static const QString placeholder =3D "..."; + + if (path.size() <=3D width) { + return path; + } + + int start =3D (path.size() - width) + placeholder.size(); + int pos =3D path.indexOf(separator, start); + if (pos =3D=3D -1) { + pos =3D start; // no separator =3D> just cut off the path at the b= eginning + } + Q_ASSERT(path.size() - pos >=3D 0 && path.size() - pos <=3D width); + + QStringRef elidedText =3D path.rightRef(path.size() - pos); + QString result =3D placeholder; + result.append(elidedText); + return result; +} + namespace { /** * @return true if @p url is non-empty, valid and has a clean path, false = otherwise. @@ -176,6 +208,9 @@ public: } = kDebug(9505) << "creating parse-job" << it->toUrl() << "ne= w count of active parse-jobs:" << m_parseJobs.count() + 1; + const QString elidedPathString =3D elidedPathLeft(it->toUr= l().toLocalFile(), 70); + emit m_parser->showMessage(m_parser, i18n("Parsing: %1", e= lidedPathString)); + ParseJob* job =3D createParseJob(*it, parsePlan.features()= , parsePlan.notifyWhenReady(), parsePlan.priority()); = if(m_parseJobs.count() =3D=3D m_threads+1 && !specialParse= Job)