DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FileModel.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: no.
5
10
11#include <QDir>
12#include <QFileInfo>
14#include "dbe/FileModel.hpp"
15#include "dbe/MainWindow.hpp"
17
19 : QAbstractTableModel(parent)
20 , Headers{ tr("Name"), tr("Folder"), tr("Access"), tr("Status") }
21{
22 initpaths();
24 initmodel();
25}
26
27dbe::FileModel::FileModel(QList<QStringList> const& FileList, QObject* parent)
28 : QAbstractTableModel(parent)
29 , IncludedFiles(FileList)
30 , Headers{ tr("Name"), tr("Folder"), tr("Access"), tr("Status") }
31{
33}
34
36
37int
38dbe::FileModel::rowCount(const QModelIndex& parent) const
39{
40 if (!parent.isValid()) {
41 return IncludedFiles.size();
42 }
43
44 return 0;
45}
46
47int
48dbe::FileModel::columnCount(const QModelIndex& parent) const
49{
50 Q_UNUSED(parent)
51 return Headers.size();
52}
53
54QVariant
55dbe::FileModel::data(const QModelIndex& index, int role) const
56{
57 if (index.isValid()) {
58 if (role == Qt::DisplayRole) {
59 return QVariant(IncludedFiles.at(index.row()).at(index.column()));
60 }
61 if (role == Qt::ForegroundRole) {
62 if (IncludedFiles.at(index.row()).at(static_cast<int>(tablepositions::filepermission)) == "RO") {
64 }
65 }
66 if (role == Qt::BackgroundRole) {
67 if (IncludedFiles.at(index.row()).at(static_cast<int>(tablepositions::filepermission)) == "RO") {
69 }
70 }
71 }
72
73 return QVariant();
74}
75
76QVariant
77dbe::FileModel::headerData(int section, Qt::Orientation orientation, int role) const
78{
79 if (role == Qt::DisplayRole) {
80 if (orientation == Qt::Horizontal) {
81 return Headers.at(section);
82 }
83
84 if (orientation == Qt::Vertical) {
85 return section + 1;
86 }
87 }
88
89 return QVariant();
90}
91
92Qt::ItemFlags
93dbe::FileModel::flags(const QModelIndex& /*index*/) const
94{
95 // if ( IncludedFiles.at ( index.row() ).at ( static_cast<int>
96 // ( tablepositions::filepermission ) ) == "RW" )
97 // {
98 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
99 // }
100
101 // return Qt::ItemIsSelectable;
102}
103
104void
106{
107 QString TDAQ_DB_REPOSITORY = getenv("TDAQ_DB_REPOSITORY");
108 if (TDAQ_DB_REPOSITORY.isEmpty() == false) {
109 QString TDAQ_DB_USER_REPOSITORY = getenv("TDAQ_DB_USER_REPOSITORY");
110 FolderPathList = TDAQ_DB_USER_REPOSITORY.split(":", Qt::SkipEmptyParts);
111
113 } else {
114 QString DUNEDAQ_DB_PATH = getenv("DUNEDAQ_DB_PATH");
115 FolderPathList = DUNEDAQ_DB_PATH.split(":", Qt::SkipEmptyParts);
116 }
117
118 for (QString& PathName : FolderPathList) {
119 if (!PathName.endsWith("/")) {
120 PathName.append("/");
121 }
122 }
123}
124
125void
127{
128 connect(
129 this, SIGNAL(FileCacheReady(QList<QStringList>&)), &confaccessor::ref(), SLOT(GetFileCache(QList<QStringList>&)));
130}
131
132QString
134{
135 QFileInfo FileInfo(FileName);
136
137 if (FileInfo.isRelative()) {
138 bool found = false;
139 for (const QString& Folder : FolderPathList) {
140 QDir TdaqFolder(Folder);
141
142 if (TdaqFolder.exists(FileName)) {
143 FileName = TdaqFolder.path() + "/" + FileName;
144 char* rpath = realpath(FileName.toStdString().c_str(), NULL);
145 FileName = QString(rpath);
146 free(rpath);
147 found = true;
148 break;
149 }
150 }
151 if (!found) {
152 FileName = FileInfo.absoluteFilePath();
153 }
154 }
155
156 return FileName;
157}
158
159QList<QStringList>
161{
162 return IncludedFiles;
163}
164
165void
167{
169
170 std::list<std::string> updated = confaccessor::uncommitted_files();
171 for (QString const& source : sources) {
172 QFileInfo srcinfo(source);
173 QString fn = srcinfo.filePath();
174 QString dn = GetFullFileName(fn).remove(QRegularExpression("/[a-zA-Z0-9_-]*.data.xml"));
175
176 QString modified{};
177 auto file = GetFullFileName(fn).toStdString();
178 for (auto ufile : updated) {
179 if (file == ufile) {
180 modified = "Modified";
181 break;
182 }
183 }
184
185 IncludedFiles.append(
186 QStringList{ srcinfo.fileName(), dn, confaccessor::check_file_rw(source) ? "RW" : "RO", modified });
187 }
188
189 if (IncludedFiles.size()) {
191 }
192}
FileInfo(QString filename, QWidget *parent=0)
Definition FileInfo.cpp:196
int columnCount(const QModelIndex &parent) const
Definition FileModel.cpp:48
QList< QStringList > IncludedFiles
Definition FileModel.hpp:44
QStringList FolderPathList
Definition FileModel.hpp:45
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition FileModel.cpp:77
void initconnections()
QStringList Headers
Definition FileModel.hpp:46
Qt::ItemFlags flags(const QModelIndex &index) const
Definition FileModel.cpp:93
FileModel(QObject *parent=nullptr)
Including QT Headers.
Definition FileModel.cpp:18
int rowCount(const QModelIndex &parent) const
Definition FileModel.cpp:38
QList< QStringList > GetFilesInfo() const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition FileModel.cpp:55
void FileCacheReady(QList< QStringList > &Files)
QString GetFullFileName(QString &FileName)
QString find_db_repository_dir()
static MainWindow * findthis()
static QColor FileReadOnlyForeground
static QColor FileReadOnlyBackground
static std::list< std::string > uncommitted_files()
static bool check_file_rw(const QString &FileName)
static QString dbfullname()
static confaccessor & ref()
static QStringList inclusions(QStringList const &candidates, QStringList files={})