[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdevplatform] language/backgroundparser: Show currently parsing file in progress bar
From:       Kevin Funk <kevin () kfunk ! org>
Date:       2013-02-13 22:48:39
Message-ID: 20130213224839.17B4FA6091 () git ! kde ! org
[Download RAW message or body]

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/backgroundparser/backgroundparser.cpp index d3bf7d7..1176244 100644
--- a/language/backgroundparser/backgroundparser.cpp
+++ b/language/backgroundparser/backgroundparser.cpp
@@ -61,6 +61,38 @@
 
 const bool separateThreadForHighPriority = 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 = QDir::separator();
+    static const QString placeholder = "...";
+
+    if (path.size() <= width) {
+        return path;
+    }
+
+    int start = (path.size() - width) + placeholder.size();
+    int pos = path.indexOf(separator, start);
+    if (pos == -1) {
+        pos = start; // no separator => just cut off the path at the beginning
+    }
+    Q_ASSERT(path.size() - pos >= 0 && path.size() - pos <= width);
+
+    QStringRef elidedText = path.rightRef(path.size() - pos);
+    QString result = 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() << "new count of \
active parse-jobs:" << m_parseJobs.count() + 1; +                const QString \
elidedPathString = elidedPathLeft(it->toUrl().toLocalFile(), 70); +                \
emit m_parser->showMessage(m_parser, i18n("Parsing: %1", elidedPathString)); +
                 ParseJob* job = createParseJob(*it, parsePlan.features(), \
parsePlan.notifyWhenReady(), parsePlan.priority());  
                 if(m_parseJobs.count() == m_threads+1 && !specialParseJob)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic