LCOV - code coverage report
Current view: top level - dbe/src/structure - FileModel.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 103 0
Test Date: 2026-07-12 15:23:06 Functions: 0.0 % 13 0

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

Generated by: LCOV version 2.0-1