DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
IncludeFileWidget.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
9#include "dbe/Exceptions.hpp"
12#include "ui_IncludeFileWidget.h"
13#include "dbe/messenger.hpp"
14#include "dbe/MainWindow.hpp"
15
16#include <QUrl>
17#include <QApplication>
18
19#include <boost/scope_exit.hpp>
20#include <cstdlib>
21
23
24dbe::IncludeFileWidget::IncludeFileWidget ( QString FilePath, QWidget * parent )
25 : QWidget ( parent ),
26 ui ( new Ui::IncludeFileWidget ),
27 CreateWidget ( nullptr ),
28 DatabasePath ( FilePath ),
29 Removed ( false ),
30 StatusBar ( nullptr ),
31 SelectFile ( nullptr )
32{
33 ui->setupUi ( this );
34
36 ui->AddLabel->setStyleSheet (
37 "QLabel{background-color:#8DAA2E; color:#facd64; font:bold14px; border-style:outset; border-width:2px; border-radius:10px;"
38 "border-color:beige; font:bold14px; min-width:10em; padding: 6px;}" );
39 ui->RemoveLabel->setStyleSheet (
40 "QLabel{background-color:#b5351b; color:#facd64; font:bold14px; border-style:outset;"
41 "border-width:2px; border-radius:10px; border-color:beige; font:bold14px; min-width:10em; padding:6px;}" );
42 setWindowTitle (
43 QString ( "Edit Included Files for Database : %1" ).arg ( QFileInfo (
44 FilePath ).fileName() ) );
45
46 StatusBar = new QStatusBar ( ui->StatusFrame );
47 StatusBar->setSizeGripEnabled ( false );
48 ui->StatusFrame->setFrameStyle ( QFrame::NoFrame );
49 ui->StatusLayout->addWidget ( StatusBar );
50
51 StatusBar->setAutoFillBackground ( true );
52 StatusBar->showMessage ( "Select files to include or to remove from include!" );
53
55
56 SelectFile = new QFileDialog ( this, tr ( "Open File" ), ".", tr ( "XML files (*.xml)" ) );
57 SelectFile->setFileMode ( QFileDialog::ExistingFiles );
58 SelectFile->setViewMode ( QFileDialog::Detail );
59 SelectFile->setAcceptMode ( QFileDialog::AcceptOpen );
60
61 QString TDAQ_DB_REPOSITORY = getenv ( "TDAQ_DB_REPOSITORY" );
62 if(TDAQ_DB_REPOSITORY.isEmpty() == false) {
63 QString TDAQ_DB_USER_REPOSITORY = getenv ( "TDAQ_DB_USER_REPOSITORY" );
64 FolderPathList = TDAQ_DB_USER_REPOSITORY.split ( ":", Qt::SkipEmptyParts );
65
66 FolderPathList.append(dbe::MainWindow::findthis()->find_db_repository_dir());
67 } else {
68 QString DUNEDAQ_DB_PATH = getenv ( "DUNEDAQ_DB_PATH" );
69 FolderPathList = DUNEDAQ_DB_PATH.split ( ":", Qt::SkipEmptyParts );
70 }
71
72 for ( QString & PathName : FolderPathList )
73 {
74 if ( !PathName.endsWith ( "/" ) )
75 {
76 PathName.append ( "/" );
77 }
78 }
79
80 QList<QUrl> List = SelectFile->sidebarUrls();
81
82 if ( !FolderPathList.isEmpty() )
83 {
85
86 for ( const QString & Dir : dbPath )
87 {
88 ui->DirectoryCombo->addItem ( Dir );
89 QString TDAqDir = QString ( "file://" ).append ( Dir );
90 QUrl URL = QUrl ( TDAqDir );
91 List << URL;
92 }
93 }
94
95 SelectFile->setSidebarUrls ( List );
96 SelectFile->setOption (QFileDialog::DontResolveSymlinks, true );
97 ui->AddToIncludeButton->setDisabled ( true );
98 ui->RemoveButton->setDisabled ( true );
99
100 ui->AddFileLine->setSelectionMode(QAbstractItemView::NoSelection);
101
103}
104
105
107 if (event->key() == Qt::Key_Escape) {
108 close();
109 }
110 QWidget::keyPressEvent(event);
111}
112
113
115{
117 DatabasePath ) );
118
119 if ( !IncludeList.isEmpty() )
120 {
121 if ( IncludeList.contains ( DatabasePath ) )
122 {
123 IncludeList.removeOne ( DatabasePath );
124 }
125
126 ui->RemoveCombo->clear();
127 ui->RemoveCombo->addItems ( IncludeList );
128 }
129}
130
132{
133 connect ( ui->SelectFileButton, SIGNAL ( clicked() ), this, SLOT ( SelectFileToInclude() ),
134 Qt::UniqueConnection );
135 connect ( ui->CreateFileButton, SIGNAL ( clicked() ), this, SLOT ( CreateFileToInclude() ),
136 Qt::UniqueConnection );
137 connect ( ui->AddToIncludeButton, SIGNAL ( clicked() ), this, SLOT ( AddFileToInclude() ),
138 Qt::UniqueConnection );
139 connect ( ui->RemoveButton, SIGNAL ( clicked() ), this, SLOT ( RemoveFileFromInclude() ),
140 Qt::UniqueConnection );
141 connect ( ui->RemoveCombo, SIGNAL ( activated ( int ) ), this,
142 SLOT ( RemoveFileFromInclude ( int ) ),
143 Qt::UniqueConnection );
144 connect ( ui->DirectoryCombo, SIGNAL ( activated ( const QString & ) ), this,
145 SLOT ( SetDirectory ( const QString & ) ), Qt::UniqueConnection );
146 connect ( ui->ExitButton, SIGNAL ( clicked() ), this, SLOT ( close() ) );
147}
148
150{
151 ui->AddFileLine->clear();
152 QStringList Files;
153
154 if ( !Directory.isEmpty() )
155 {
156 SelectFile->setDirectory ( Directory );
157 }
158
159 if ( SelectFile->exec() )
160 {
161 Files = SelectFile->selectedFiles();
162 }
163
164 if(Files.isEmpty()) {
165 return;
166 }
167
168 for(const QString& FileToInclude : Files) {
169 QFileInfo f(FileToInclude);
170
171 if ( Directory.isEmpty() )
172 {
173 ui->AddFileLine->addItem(f.absoluteFilePath());
174 }
175 else
176 {
177 ui->AddFileLine->addItem(f.absoluteFilePath().remove ( Directory + QString ( '/' ), Qt::CaseSensitive ));
178 }
179 }
180
181 CheckInclude();
182}
183
185{
186 BOOST_SCOPE_EXIT(void)
187 {
188 QApplication::restoreOverrideCursor();
189 }
190 BOOST_SCOPE_EXIT_END
191
192 QApplication::setOverrideCursor(Qt::WaitCursor);
193
194 for(int i = 0; i < ui->AddFileLine->count(); ++i) {
195 QString File = ui->AddFileLine->item(i)->text();
196
197 if ( !File.isEmpty() )
198 {
200 for ( QString & PathFile : FolderPathList )
201 {
202 if ( File.startsWith ( PathFile ) )
203 {
204 File = File.replace ( 0, PathFile.size(), "" );
205 break;
206 }
207 }
208
210
211 StatusBar->setPalette ( QApplication::palette ( this ) );
212 StatusBar->showMessage (
213 QString ( "The file %1 was added to the included files" ).arg ( File ) );
214 }
215 }
216
218
219 ui->AddFileLine->clear();
220 ui->AddToIncludeButton->setDisabled ( true );
221}
222
224{
225 ui->AddFileLine->clear();
226
227 QString includeFilePath;
228 includeFilePath = File;
229
230 if ( includeFilePath.isEmpty() )
231 {
232 return;
233 }
234
235 QFileInfo includeFile = QFileInfo ( includeFilePath );
236
237 if ( !includeFile.isFile() )
238 {
240 StatusBar->showMessage ( QString ( "The file is NOT accessible. Check before usage" ) );
241 }
242 else
243 {
244 QString fileToInclude;
245
246 if ( Directory.isEmpty() )
247 {
248 fileToInclude = includeFile.absoluteFilePath();
249 }
250 else if ( ( includeFile.absoluteDir().canonicalPath() ).compare (
251 Directory ) == 0 ) fileToInclude =
252 includeFile.absoluteFilePath().remove ( Directory + QString ( '/' ), Qt::CaseSensitive );
253 else
254 {
255 fileToInclude = includeFile.absoluteFilePath();
256 }
257
258 ui->AddFileLine->addItem( fileToInclude );
259 ui->AddToIncludeButton->setDisabled(false);
260 }
261}
262
264{
265 if ( ui->RemoveCombo->currentIndex() != -1 )
266 {
267 BOOST_SCOPE_EXIT(void)
268 {
269 QApplication::restoreOverrideCursor();
270 }
271 BOOST_SCOPE_EXIT_END
272
273 QApplication::setOverrideCursor(Qt::WaitCursor);
274
275 QString File = ui->RemoveCombo->currentText();
276
278 Removed = true;
279 StatusBar->setPalette ( QApplication::palette ( this ) );
280 StatusBar->showMessage (
281 QString ( "The file %1 was removed from the included files" ).arg ( File ) );
283 }
284 else
285 {
287 StatusBar->showMessage (
288 QString ( "The file is NOT selected. Use combo box to select one." ) );
289 }
290}
291
293{
294 if ( ui->RemoveCombo->currentIndex() != -1 )
295 {
296 ui->RemoveButton->setEnabled ( true );
297 StatusBar->setPalette ( QApplication::palette ( this ) );
298 StatusBar->showMessage (
299 QString ( "The file %1 will be removed from the included files of %2" ).arg (
300 QFileInfo ( ui->RemoveCombo->currentText() ).fileName() ).arg (
301 QFileInfo ( DatabasePath ).fileName() ) );
302 }
303}
304
305void dbe::IncludeFileWidget::SetDirectory ( const QString & Dir )
306{
307 if(dbPath.contains(Dir, Qt::CaseSensitivity::CaseSensitive) && QDir(Dir).exists()) {
308 Directory = Dir;
309 SelectFile->setDirectory ( Directory );
310 } else {
311 Directory.clear();
312 SelectFile->setDirectory(QDir("."));
313 }
314}
315
317{
319
320 if ( ui->AddFileLine->count() == 0 )
321 {
323 StatusBar->showMessage ( QString ( "Select existing file!" ) );
324 ui->AddToIncludeButton->setDisabled ( true );
325
326 return;
327 }
328
329 std::vector<int> removedItems;
330 for(int i = 0; i < ui->AddFileLine->count(); ++i) {
331 const QString inc = ui->AddFileLine->item(i)->text();
332
333 if(inc == DatabasePath) {
334 removedItems.push_back(i);
335 } else {
336 for(int j = 0; j < ui->RemoveCombo->count(); ++j) {
337 if(ui->RemoveCombo->itemText(j).compare(inc) == 0) {
338 removedItems.push_back(i);
339 }
340 }
341 }
342 }
343
344 if(removedItems.empty() == false) {
345 QString message = "The following files will not be included because already included:";
346
347 for(int i : removedItems) {
348 QListWidgetItem* item = ui->AddFileLine->takeItem(i);
349 message += "\n- " + item->text();
350 delete item;
351 }
352
353 WARN("File inclusion issue", message.toStdString());
354 }
355
356 ui->AddToIncludeButton->setDisabled((ui->AddFileLine->count() == 0) ? true : false);
357}
358
360{
361 CreateWidget = new CreateDatabaseWidget ( nullptr, true, Directory );
362 connect ( CreateWidget, SIGNAL ( CanIncludeDatabase ( const QString & ) ), this,
363 SLOT ( AddNewFileToInclude ( const QString & ) ), Qt::UniqueConnection );
364 CreateWidget->show();
365}
void SetDirectory(const QString &Dir)
void AddNewFileToInclude(const QString &File)
CreateDatabaseWidget * CreateWidget
void keyPressEvent(QKeyEvent *event) override
IncludeFileWidget(QString FilePath, QWidget *parent=0)
std::unique_ptr< dbe::Ui::IncludeFileWidget > ui
static MainWindow * findthis()
static QPalette AlertStatusBarPallete
static QStringList inclusions_singlefile(QString const &)
#define WARN(...)
Definition messenger.hpp:85
void remove(QString const &db, QString const &fn)
void add(QString const &db, QString const &fn)