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

List:       kde-commits
Subject:    KDE/kdevelop/lib/plugins/vcs/cvs
From:       Robert Gruber <rgruber () users ! sourceforge ! net>
Date:       2007-04-13 18:23:04
Message-ID: 1176488584.957909.15070.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 653590 by rgruber:

Separated the parsing of the ouput of "cvs editors" from the
code that displays the gathered information.
The new parseOutput() function can then also be called from tests.


 M  +36 -39    editorsview.cpp  
 M  +35 -0     editorsview.h  


--- trunk/KDE/kdevelop/lib/plugins/vcs/cvs/editorsview.cpp #653589:653590
@@ -14,7 +14,6 @@
 #include <QFileInfo>
 #include <QTextBrowser>
 #include <QRegExp>
-#include <QMultiMap>
 #include <KDebug>
 #include <KMessageBox>
 
@@ -22,13 +21,6 @@
 #include "cvsjob.h"
 #include "cvsproxy.h"
 
-class CvsLocker {
-public:
-    QString user;
-    QString date;
-    QString machine;
-    QString localrepo;
-};
 
 EditorsView::EditorsView(CvsPart* part, CvsJob* job, QWidget *parent)
     : QWidget(parent), Ui::EditorsViewBase(), m_part(part)
@@ -61,17 +53,47 @@
         return;
     }
 
+
+    QMultiMap<QString,CvsLocker> lockedFiles;
+
+    parseOutput(cvsjob->output(), lockedFiles);
+
+    if (lockedFiles.size() == 0) {
+        textbrowser->append(i18n("No files from your query are marked as being edited."));
+    } else {
+        QString html;
+
+        foreach (QString key, lockedFiles.uniqueKeys()) {
+            html += "<h3>"+key+"</h3><br>";
+
+            foreach(CvsLocker item, lockedFiles.values( key )) {
+                html += "<b>"+i18n("User")+":</b> "+item.user+"<br>";
+                html += "<b>"+i18n("Date")+":</b> "+item.date+"<br>";
+                html += "<b>"+i18n("Machine")+":</b> "+item.machine+"<br>";
+                html += "<b>"+i18n("Repository")+":</b> "+item.localrepo+"<br>";
+                html += "<br>";
+            }
+            html += "<br>";
+        }
+
+        textbrowser->setHtml( html );
+    }
+}
+
+void EditorsView::parseOutput(const QString& jobOutput, QMultiMap<QString,CvsLocker>& editorsInfo)
+{
+    // the first line contains the filename and than the locker information
     static QRegExp re("([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+"
                         "([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+(.*)");
+    // if there are more than one locker of a single file, the second line for a file
+    // only contains the locker information (no filename)
     static QRegExp subre("\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+"
                         "([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+(.*)");
+
     QString lastfilename;
 
-    QStringList lines = cvsjob->output().split("\n");
+    QStringList lines = jobOutput.split("\n");
 
-    QMultiMap<QString,CvsLocker> lockedFiles;
-
-    int found = 0;
     for (int i=0; i<lines.count(); ++i) {
         QString s = lines[i];
 
@@ -83,10 +105,8 @@
             item.machine = re.cap(9);
             item.localrepo = re.cap(10);
 
-            lockedFiles.insert(file, item);
+            editorsInfo.insert(file, item);
 
-            found++;
-
             lastfilename = file;
         } else {
             if (subre.exactMatch(s)) {
@@ -96,33 +116,10 @@
                 item.machine = subre.cap(8);
                 item.localrepo = subre.cap(9);
 
-                lockedFiles.insert(lastfilename, item);
-
-                found++;
+                editorsInfo.insert(lastfilename, item);
             }
         }
     }
-
-    if (!found) {
-        textbrowser->append(i18n("No files from your query are marked as being edited."));
-    } else {
-        QString html;
-
-        foreach (QString key, lockedFiles.uniqueKeys()) {
-            html += "<h3>"+key+"</h3><br>";
-
-            foreach(CvsLocker item, lockedFiles.values( key )) {
-                html += "<b>"+i18n("User")+":</b>"+item.user+"<br>";
-                html += "<b>"+i18n("Date")+":</b>"+item.date+"<br>";
-                html += "<b>"+i18n("Machine")+":</b>"+item.machine+"<br>";
-                html += "<b>"+i18n("Repository")+":</b>"+item.localrepo+"<br>";
-                html += "<br>";
-            }
-            html += "<br>";
-        }
-
-        textbrowser->setHtml( html );
-    }
 }
 
 #include "editorsview.moc"
--- trunk/KDE/kdevelop/lib/plugins/vcs/cvs/editorsview.h #653589:653590
@@ -13,6 +13,7 @@
 #define EDITORSVIEW_H
 
 #include <QDialog>
+#include <QMultiMap>
 #include <KJob>
 
 #include "ui_editorsview.h"
@@ -21,6 +22,19 @@
 class CvsJob;
 
 /**
+ * This is a helper class for the EditorsView::parseOutput() method.
+ * It holds information about a single locker of a file.
+ * @see EditorsView::parseOutput()
+ */
+class CvsLocker {
+public:
+    QString user;
+    QString date;
+    QString machine;
+    QString localrepo;
+};
+
+/**
  * Shows the output from @code cvs editors @endcode in a nice way.
  * Create a CvsJob by calling CvsProxy::editors() and connect the job's
  * result(KJob*) signal to EditorsView::slotJobFinished(KJob* job)
@@ -33,7 +47,28 @@
     EditorsView(CvsPart* part, CvsJob* job=0, QWidget *parent = 0);
     virtual ~EditorsView();
 
+    /**
+     * Parses the output generated by a @code cvs editors @endcode command and
+     * fills the given QMultiMap with all files and their lockers found in the output.
+     * @param jobOutput Pass in the plain output of a @code cvs editors @endcode job
+     * @param editorsInfo This QMultiMap will be filled with information about which files 
+     *                    are locked by whom. The key of the map is the filename. For each 
+     *                    filename a list of CvsLocker objects will be created, depending 
+     *                    on how many people are editing the file.
+     *                    If editorsInfo.size() is zero, this means that no information was
+     *                    found in the given @p jobOutput.
+     */
+    static void parseOutput(const QString& jobOutput, 
+                            QMultiMap<QString,CvsLocker>& editorsInfo);
+
 private slots:
+    /**
+     * Connect a job's result() signal to this slot. When called, the output from the job
+     * will be passed to the parseOutput() method and any found locker information will be
+     * displayed.
+     * @note If you pass a CvsJob object to the ctor, it's result() signal 
+     *       will automatically be connected to this slot.
+     */
     void slotJobFinished(KJob* job);
 
 private:
[prev in list] [next in list] [prev in thread] [next in thread] 

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