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 <QFileInfo>
12#include <QDir>
14#include "dbe/FileModel.hpp"
16#include "dbe/MainWindow.hpp"
17
18dbe::FileModel::FileModel ( QObject * parent )
19 : QAbstractTableModel ( parent ),
21{ tr ( "Name" ), tr ( "Folder" ), tr ( "Access" ), tr ( "Status" ) }
22{
23 initpaths();
24 initconnections();
25 initmodel();
26}
27
28dbe::FileModel::FileModel ( QList<QStringList> const & FileList, QObject * parent )
29 : QAbstractTableModel ( parent ),
30 IncludedFiles ( FileList ),
32{ tr ( "Name" ), tr ( "Folder" ), tr ( "Access" ), tr ( "Status" ) }
33{
34 initconnections();
35}
36
39
40int dbe::FileModel::rowCount ( const QModelIndex & parent ) const
41{
42 if ( !parent.isValid() )
43 {
44 return IncludedFiles.size();
45 }
46
47 return 0;
48}
49
50int dbe::FileModel::columnCount ( const QModelIndex & parent ) const
51{
52 Q_UNUSED ( parent )
53 return Headers.size();
54}
55
56QVariant dbe::FileModel::data ( const QModelIndex & index, int role ) const
57{
58 if ( index.isValid() )
59 {
60 if ( role == Qt::DisplayRole ) {
61 return QVariant (
62 IncludedFiles.at ( index.row() ).at ( index.column() ) );
63 }
64 if ( role == Qt::ForegroundRole )
65 {
66 if ( IncludedFiles.at ( index.row() ).at (
67 static_cast<int> ( tablepositions::filepermission ) ) == "RO" ) {
69 }
70 }
71 if ( role == Qt::BackgroundRole )
72 {
73 if ( IncludedFiles.at ( index.row() ).at (
74 static_cast<int> ( tablepositions::filepermission ) ) == "RO" ) {
76 }
77 }
78 }
79
80 return QVariant();
81}
82
83QVariant dbe::FileModel::headerData ( int section, Qt::Orientation orientation,
84 int role ) const
85{
86 if ( role == Qt::DisplayRole )
87 {
88 if ( orientation == Qt::Horizontal )
89 {
90 return Headers.at ( section );
91 }
92
93 if ( orientation == Qt::Vertical )
94 {
95 return section + 1;
96 }
97 }
98
99 return QVariant();
100}
101
102Qt::ItemFlags dbe::FileModel::flags ( const QModelIndex & /*index*/ ) const
103{
104 // if ( IncludedFiles.at ( index.row() ).at ( static_cast<int>
105 // ( tablepositions::filepermission ) ) == "RW" )
106 // {
107 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
108 // }
109
110 // return Qt::ItemIsSelectable;
111}
112
114{
115 QString TDAQ_DB_REPOSITORY = getenv ( "TDAQ_DB_REPOSITORY" );
116 if(TDAQ_DB_REPOSITORY.isEmpty() == false) {
117 QString TDAQ_DB_USER_REPOSITORY = getenv ( "TDAQ_DB_USER_REPOSITORY" );
118 FolderPathList = TDAQ_DB_USER_REPOSITORY.split ( ":", Qt::SkipEmptyParts );
119
121 } else {
122 QString DUNEDAQ_DB_PATH = getenv ( "DUNEDAQ_DB_PATH" );
123 FolderPathList = DUNEDAQ_DB_PATH.split ( ":", Qt::SkipEmptyParts );
124 }
125
126 for ( QString & PathName : FolderPathList )
127 {
128 if ( !PathName.endsWith ( "/" ) )
129 {
130 PathName.append ( "/" );
131 }
132 }
133}
134
136{
137 connect ( this, SIGNAL ( FileCacheReady ( QList<QStringList> & ) ), &confaccessor::ref(),
138 SLOT ( GetFileCache ( QList<QStringList> & ) ) );
139}
140
141QString dbe::FileModel::GetFullFileName ( QString & FileName )
142{
143 QFileInfo FileInfo ( FileName );
144
145 if ( FileInfo.isRelative() )
146 {
147 bool found=false;
148 for ( const QString & Folder : FolderPathList )
149 {
150 QDir TdaqFolder ( Folder );
151
152 if ( TdaqFolder.exists ( FileName ) )
153 {
154 FileName = TdaqFolder.path() + "/" + FileName;
155 char* rpath = realpath(FileName.toStdString().c_str(), NULL);
156 FileName = QString(rpath);
157 free(rpath);
158 found=true;
159 break;
160 }
161 }
162 if (!found) {
163 FileName = FileInfo.absoluteFilePath();
164 }
165 }
166
167 return FileName;
168}
169
170QList<QStringList> dbe::FileModel::GetFilesInfo() const
171{
172 return IncludedFiles;
173}
174
176{
177 QStringList sources = dbe::config::api::get::file::inclusions (
179
180 std::list<std::string> updated = confaccessor::uncommitted_files();
181 for ( QString const & source : sources )
182 {
183 QFileInfo srcinfo ( source );
184 QString fn = srcinfo.filePath();
185 QString dn = GetFullFileName(fn).remove(QRegularExpression("/[a-zA-Z0-9_-]*.data.xml"));
186
187 QString modified{};
188 auto file = GetFullFileName(fn).toStdString();
189 for (auto ufile: updated) {
190 if (file == ufile) {
191 modified = "Modified";
192 break;
193 }
194 }
195
196 IncludedFiles.append ( QStringList{ srcinfo.fileName(),
197 dn,
198 confaccessor::check_file_rw ( source ) ? "RW" : "RO",
199 modified}
200 );
201 }
202
203 if ( IncludedFiles.size() )
204 {
206 }
207}
int columnCount(const QModelIndex &parent) const
Definition FileModel.cpp:50
QList< QStringList > IncludedFiles
Definition FileModel.hpp:46
QStringList FolderPathList
Definition FileModel.hpp:47
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition FileModel.cpp:83
void initconnections()
QStringList Headers
Definition FileModel.hpp:48
Qt::ItemFlags flags(const QModelIndex &index) const
FileModel(QObject *parent=nullptr)
Including QT Headers.
Definition FileModel.cpp:18
int rowCount(const QModelIndex &parent) const
Definition FileModel.cpp:40
QList< QStringList > GetFilesInfo() const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition FileModel.cpp:56
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={ })