changeset 101:8ed21aa68021

Read .exam-setup-user in folderselection
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 18 Nov 2016 12:46:54 +0100
parents 7c84242971cb
children 568d92c03941
files src/folderselectdialog.cpp
diffstat 1 files changed, 55 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/folderselectdialog.cpp	Fri Nov 18 11:36:14 2016 +0100
+++ b/src/folderselectdialog.cpp	Fri Nov 18 12:46:54 2016 +0100
@@ -159,6 +159,7 @@
 
     bottomButtons->addWidget(mOkButton);
     setLayout(base);
+    resize(700, 600);
 }
 
 void FolderSelectDialog::selectionChanged (const QItemSelection& selected,
@@ -193,6 +194,41 @@
     settings.setValue(ROOT_FOLDER_KEY, mPathLineEdit->text());
 }
 
+QString stripQuotes (const QString &in)
+{
+    QString out = in;
+    if (in.startsWith("\"")) {
+        out = out.right(out.size()-1);
+    }
+    if (in.endsWith("\"")) {
+        out = out.left(out.size()-1);
+    }
+    return out;
+}
+
+QMap <QString, QString> readExtraColumns(const QString &path)
+{
+    QMap <QString, QString> ret;
+
+    QFile file(path);
+    if (!file.open(QIODevice::ReadOnly)) {
+        qDebug () << "Failed to open: " << path;
+        return ret;
+    }
+    QTextStream in(&file);
+
+    while (!in.atEnd()) {
+        QString line = in.readLine();
+        int equalsign = line.indexOf("=");
+        if (equalsign != -1) {
+            QString name = stripQuotes(line.left(equalsign).replace (QStringLiteral("export "), ""));
+            QString value = stripQuotes(line.right(line.size() - equalsign - 1));
+            ret.insert (name, value);
+        }
+    }
+    return ret;
+}
+
 void FolderSelectDialog::setFolder(const QString& folder) {
     if (folder.isEmpty()) {
         return;
@@ -203,16 +239,16 @@
     }
 
     QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR);
+    int patternSize = columns.size();
+    QDir dir(folder);
     mModel->clear();
-    mModel->setHorizontalHeaderLabels(columns);
-    QDir dir(folder);
     qDebug() << "Folder set to: " << folder;
     foreach (const QString & subfolder, dir.entryList(QDir::Dirs |
                                                       QDir::Readable |
                                                       QDir::NoDotAndDotDot)) {
         qDebug() << "Looking at: " << subfolder;
         QStringList itemData = subfolder.split(PATTERN_SEPERATOR);
-        if (itemData.size() != columns.size()) {
+        if (itemData.size() != patternSize) {
             qDebug() << "Folder does not match pattern: " << subfolder;
             continue;
         }
@@ -220,10 +256,26 @@
         foreach (const QString& part, itemData) {
             QStandardItem * item = new QStandardItem(part);
             item->setData(dir.absoluteFilePath(subfolder));
+            QFileInfo fi (dir.absoluteFilePath(subfolder + "/.exam-setup-user"));
             items.append(item);
+            if (fi.isReadable()) {
+                const QMap<QString, QString> map = readExtraColumns (fi.filePath());
+
+                int i = 0;
+                Q_FOREACH (const QString &name, map.keys())
+                {
+                    qDebug() << "Adding extra column: " << name;
+                    if (!columns.contains(name)) {
+                        columns << name;
+                    }
+                    QStandardItem * subitem = new QStandardItem(map[name]);
+                    items.append(subitem);
+                }
+            }
         }
         mModel->appendRow(items);
     }
+    mModel->setHorizontalHeaderLabels(columns);
     mSortModel->setSourceModel(mModel);
     mView->resizeColumnsToContents();
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)