9#include "ui_FileInfo.h"
12#include <QInputDialog>
13#include <QListWidgetItem>
28 QString DUNEDAQ_DB_PATH = getenv (
"DUNEDAQ_DB_PATH" );
31 auto path_list = DUNEDAQ_DB_PATH.split (QLatin1Char(
':'), Qt::SkipEmptyParts );
32 for ( QString & path : path_list ) {
33 char* rpath = realpath(path.toStdString().c_str(), NULL);
34 path = QString(rpath);
37 if (! path.isEmpty()) {
38 if ( !path.endsWith (
"/" ) ) {
52 if (file.startsWith(element)) {
65 QStringList candidates{file};
68 if (file.startsWith(element)) {
69 candidates.append(file.remove(element));
73 for (
auto cand : candidates) {
74 if (includes.contains(cand)) {
96 for (
auto const& class_name :
99 auto file =
prune_path(QString::fromStdString(obj.contained_in()));
100 auto name = QString::fromStdString(obj.full_name());
119 auto schema_file = QString::fromStdString(classdef.
p_schema_path);
121 message += QString(
"Object <i>" +
id +
"</i> is of class <i>"
122 + QString::fromStdString(obj.class_name())
123 +
"</i> defined in file <b>" + schema_file
124 +
"</b> which is not included<br>");
126 std::vector<tref> relobjs;
130 relobjs.push_back(dbegraph::linked::through::relation<tref> (obj, rel));
132 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e ) {
137 relobjs = dbegraph::linked::through::relation<std::vector<tref>> (obj, rel);
141 for (
auto relobj : relobjs) {
142 auto file = QString::fromStdString(relobj.contained_in());
144 message += QString(
"Object <i>" +
id +
"</i> has relationship to <i>"
145 + QString::fromStdString(relobj.full_name())
146 +
"</i> in file <b>" + file
147 +
"</b> which is not included<br>");
160 QWidget::setAttribute(Qt::WA_DeleteOnClose);
165 m_ui->rstatus->setText(QString(
"RW"));
169 m_ui->rstatus->setText(QString(
"RO"));
174 setWindowTitle(
"File: " +
filename.section(
'/',-1));
180 m_ui->schema_list->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
181 m_ui->data_list->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
182 m_ui->object_list->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
187 connect (
m_ui->schema_list, SIGNAL (customContextMenuRequested(QPoint)),
190 connect (
m_ui->data_list, SIGNAL (customContextMenuRequested(QPoint)),
192 connect (
m_ui->data_list, SIGNAL (itemActivated(QListWidgetItem*)),
195 connect (
m_ui->object_list, SIGNAL (itemActivated(QListWidgetItem*)),
197 connect (
m_ui->object_list, SIGNAL (customContextMenuRequested(QPoint)),
213 m_ui->object_list->clear();
216 for (
auto const& [obj_name, obj_ref] : omap) {
217 auto item =
new QListWidgetItem(obj_name);
218 m_ui->object_list->addItem(item);
221 m_ui->object_list->update();
229 m_ui->message->setText(message);
230 return message.isEmpty();
236 m_ui->schema_list->clear();
237 m_ui->data_list->clear();
238 for (
auto inc: includes) {
239 auto item =
new QListWidgetItem(inc);
244 if (inc.endsWith(
".schema.xml")) {
245 m_ui->schema_list->addItem(item);
247 if (inc.endsWith(
".data.xml")) {
248 m_ui->data_list->addItem(item);
252 m_ui->schema_list->update();
253 m_ui->data_list->update();
257 if (event->key() == Qt::Key_Escape) {
260 QWidget::keyPressEvent(event);
271 auto item =
m_ui->object_list->currentItem();
276 auto name = item->text();
278 for ( QWidget * widget : QApplication::allWidgets() ) {
280 if ( oe !=
nullptr ) {
281 if (oe->objectName() == name) {
283 oe->setVisible (
true );
284 oe->activateWindow();
297 auto name =
m_ui->object_list->currentItem()->text();
306 auto name =
m_ui->object_list->currentItem()->text();
309 QInputDialog dia(
this);
310 dia.setLabelText(
"Enter new name for " + name);
311 auto code = dia.exec();
312 if (code == QDialog::Accepted) {
313 std::string new_name = dia.textValue().toStdString();
324 auto fd =
new QFileDialog (
this, tr (
"Open Data File" ),
s_data_path,
325 tr (
"XML data files (*.data.xml)" ) );
327 if (fd->result() == QDialog::Accepted) {
335 auto fd =
new QFileDialog (
this, tr (
"Open Schema File" ),
s_schema_path,
336 tr (
"XML schema files (*.schema.xml)" ) );
338 if (fd->result() == QDialog::Accepted) {
343 fd->setFileMode ( QFileDialog::ExistingFiles );
344 fd->setViewMode ( QFileDialog::Detail );
345 fd->setAcceptMode ( QFileDialog::AcceptOpen );
347 if (fd->exec() == QDialog::Accepted) {
348 auto files = fd->selectedFiles();
349 for (
auto file: files) {
384 for ( QWidget * widget : QApplication::allWidgets() ) {
385 auto fi =
dynamic_cast<FileInfo *
> ( widget );
386 if ( fi !=
nullptr ) {
389 fi->setVisible (
true );
390 fi->activateWindow();
405 auto add =
new QAction(
"Add include file",
this);
406 connect (add, SIGNAL(triggered()),
this, SLOT (
add_schemafile()));
409 auto remove =
new QAction(
"Remove include file",
this);
415 if (
m_ui->schema_list->currentIndex().isValid()) {
425 auto info =
new QAction(tr(
"Show file info"),
this);
426 connect (info, SIGNAL(triggered()),
this, SLOT (
file_info_slot()));
430 auto add =
new QAction(
"Add include file",
this);
431 connect (add, SIGNAL(triggered()),
this, SLOT (
add_datafile()));
434 auto remove =
new QAction(
"Remove include file",
this);
440 if (
m_ui->data_list->currentIndex().isValid()) {
455 auto edit_action =
new QAction(tr(
"&Edit object"),
this);
459 auto delete_action =
new QAction(tr(
"&Delete Object"),
this );
463 auto rename_action =
new QAction(tr(
"&Rename Object"),
this );
468 if (
m_ui->object_list->currentIndex().isValid()) {
static QList< QUrl > get_path_urls()
static QString prune_path(QString file)
void keyPressEvent(QKeyEvent *event) override
static void parse_all_objects()
static QStringList get_path_list()
void activate_data_context_menu(QPoint point)
void rename_object_slot()
void remove_datafile_slot()
void activate_schema_context_menu(QPoint point)
static bool match_path(QString &file, QStringList &includes)
void add_includefile(QFileDialog *fd)
void delete_object_slot()
static QStringList s_path_list
void activate_object_context_menu(QPoint point)
static QString check_file_includes(const QString &file)
static void setup_paths()
static QString s_data_path
void remove_schemafile_slot()
FileInfo(QString filename, QWidget *parent=0)
static QList< QUrl > s_path_urls
static QString s_schema_path
static std::map< QString, std::map< QString, const tref > > s_obj_map
static void show_file_info(const QString &filename)
void remove_includefile(const QString &file)
static MainWindow * findthis()
static QColor FileReadOnlyForeground
static QColor FileReadOnlyBackground
static bool check_file_rw(const QString &FileName)
static QStringList inclusions_singlefile(QString const &)
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
void remove(QString const &db, QString const &fn)
void add(QString const &db, QString const &fn)
bool renobj(inner::configobject::tref obj, std::string const &newuuid, QUuid const &src)
bool delobj(inner::configobject::tref obj, QUuid const &src)
bool is_simple(dunedaq::conffwk::relationship_t const &)
const std::vector< relationship_t > p_relationships
std::string p_schema_path