Mercurial > retraceit
comparison src/folderselectdialog.cpp @ 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 | 4302ca793c5a |
comparison
equal
deleted
inserted
replaced
100:7c84242971cb | 101:8ed21aa68021 |
---|---|
157 bottomButtons->addWidget(backBtn); | 157 bottomButtons->addWidget(backBtn); |
158 } | 158 } |
159 | 159 |
160 bottomButtons->addWidget(mOkButton); | 160 bottomButtons->addWidget(mOkButton); |
161 setLayout(base); | 161 setLayout(base); |
162 resize(700, 600); | |
162 } | 163 } |
163 | 164 |
164 void FolderSelectDialog::selectionChanged (const QItemSelection& selected, | 165 void FolderSelectDialog::selectionChanged (const QItemSelection& selected, |
165 const QItemSelection& deselected) { | 166 const QItemSelection& deselected) { |
166 mOkButton->setEnabled(!selected.indexes().isEmpty()); | 167 mOkButton->setEnabled(!selected.indexes().isEmpty()); |
191 QSettings settings; | 192 QSettings settings; |
192 /* assuming go is only available in root folder mode */ | 193 /* assuming go is only available in root folder mode */ |
193 settings.setValue(ROOT_FOLDER_KEY, mPathLineEdit->text()); | 194 settings.setValue(ROOT_FOLDER_KEY, mPathLineEdit->text()); |
194 } | 195 } |
195 | 196 |
197 QString stripQuotes (const QString &in) | |
198 { | |
199 QString out = in; | |
200 if (in.startsWith("\"")) { | |
201 out = out.right(out.size()-1); | |
202 } | |
203 if (in.endsWith("\"")) { | |
204 out = out.left(out.size()-1); | |
205 } | |
206 return out; | |
207 } | |
208 | |
209 QMap <QString, QString> readExtraColumns(const QString &path) | |
210 { | |
211 QMap <QString, QString> ret; | |
212 | |
213 QFile file(path); | |
214 if (!file.open(QIODevice::ReadOnly)) { | |
215 qDebug () << "Failed to open: " << path; | |
216 return ret; | |
217 } | |
218 QTextStream in(&file); | |
219 | |
220 while (!in.atEnd()) { | |
221 QString line = in.readLine(); | |
222 int equalsign = line.indexOf("="); | |
223 if (equalsign != -1) { | |
224 QString name = stripQuotes(line.left(equalsign).replace (QStringLiteral("export "), "")); | |
225 QString value = stripQuotes(line.right(line.size() - equalsign - 1)); | |
226 ret.insert (name, value); | |
227 } | |
228 } | |
229 return ret; | |
230 } | |
231 | |
196 void FolderSelectDialog::setFolder(const QString& folder) { | 232 void FolderSelectDialog::setFolder(const QString& folder) { |
197 if (folder.isEmpty()) { | 233 if (folder.isEmpty()) { |
198 return; | 234 return; |
199 } | 235 } |
200 mCurFolder = folder; | 236 mCurFolder = folder; |
201 if (mPathLineEdit) { | 237 if (mPathLineEdit) { |
202 mPathLineEdit->setText(mCurFolder); | 238 mPathLineEdit->setText(mCurFolder); |
203 } | 239 } |
204 | 240 |
205 QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR); | 241 QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR); |
242 int patternSize = columns.size(); | |
243 QDir dir(folder); | |
206 mModel->clear(); | 244 mModel->clear(); |
207 mModel->setHorizontalHeaderLabels(columns); | |
208 QDir dir(folder); | |
209 qDebug() << "Folder set to: " << folder; | 245 qDebug() << "Folder set to: " << folder; |
210 foreach (const QString & subfolder, dir.entryList(QDir::Dirs | | 246 foreach (const QString & subfolder, dir.entryList(QDir::Dirs | |
211 QDir::Readable | | 247 QDir::Readable | |
212 QDir::NoDotAndDotDot)) { | 248 QDir::NoDotAndDotDot)) { |
213 qDebug() << "Looking at: " << subfolder; | 249 qDebug() << "Looking at: " << subfolder; |
214 QStringList itemData = subfolder.split(PATTERN_SEPERATOR); | 250 QStringList itemData = subfolder.split(PATTERN_SEPERATOR); |
215 if (itemData.size() != columns.size()) { | 251 if (itemData.size() != patternSize) { |
216 qDebug() << "Folder does not match pattern: " << subfolder; | 252 qDebug() << "Folder does not match pattern: " << subfolder; |
217 continue; | 253 continue; |
218 } | 254 } |
219 QList<QStandardItem*> items; | 255 QList<QStandardItem*> items; |
220 foreach (const QString& part, itemData) { | 256 foreach (const QString& part, itemData) { |
221 QStandardItem * item = new QStandardItem(part); | 257 QStandardItem * item = new QStandardItem(part); |
222 item->setData(dir.absoluteFilePath(subfolder)); | 258 item->setData(dir.absoluteFilePath(subfolder)); |
259 QFileInfo fi (dir.absoluteFilePath(subfolder + "/.exam-setup-user")); | |
223 items.append(item); | 260 items.append(item); |
261 if (fi.isReadable()) { | |
262 const QMap<QString, QString> map = readExtraColumns (fi.filePath()); | |
263 | |
264 int i = 0; | |
265 Q_FOREACH (const QString &name, map.keys()) | |
266 { | |
267 qDebug() << "Adding extra column: " << name; | |
268 if (!columns.contains(name)) { | |
269 columns << name; | |
270 } | |
271 QStandardItem * subitem = new QStandardItem(map[name]); | |
272 items.append(subitem); | |
273 } | |
274 } | |
224 } | 275 } |
225 mModel->appendRow(items); | 276 mModel->appendRow(items); |
226 } | 277 } |
278 mModel->setHorizontalHeaderLabels(columns); | |
227 mSortModel->setSourceModel(mModel); | 279 mSortModel->setSourceModel(mModel); |
228 mView->resizeColumnsToContents(); | 280 mView->resizeColumnsToContents(); |
229 } | 281 } |
230 | 282 |
231 void FolderSelectDialog::wantToAccept() { | 283 void FolderSelectDialog::wantToAccept() { |