From 7042000d0239bf1eceb1dd19a716d7e8a952dd04 Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Sun, 25 Mar 2007 22:01:54 +0000 Subject: [PATCH] dhb this is a rewrite of the populate tree function. It uses the brand spanky new .sql "select ... from ..." console capabilities in the director It also uses a new dosql function in the console to return the results of the command as a QListString. This simplifies the data access. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4418 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/console/console.cpp | 18 ++++ bacula/src/qt-console/console/console.h | 1 + bacula/src/qt-console/joblist/joblist.h | 2 +- bacula/src/qt-console/medialist/medialist.cpp | 102 ++++++++---------- bacula/src/qt-console/medialist/medialist.h | 8 +- 5 files changed, 67 insertions(+), 64 deletions(-) diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index e52f435366..6c8020f25d 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -583,3 +583,21 @@ void Console::setDirRes(DIRRES *dir) { m_dir = dir; } + +QStringList* Console::dosql(QString* sqlcmd) +{ + int stat; + QStringList* strlstret = new QStringList; + + *sqlcmd = ".sql \"" + *sqlcmd + "\""; + + write_dir(sqlcmd->toUtf8().data()); + while ((stat=read()) > 0) { + QString line = msg(); + QRegExp regex("^Using Catalog"); + if ( regex.indexIn(line) < 0 ){ + strlstret->append(line); + } + } + return strlstret; +} diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index abe12a40d1..1620f12662 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -91,6 +91,7 @@ public: void discardToPrompt(); void setTreeItem(QTreeWidgetItem *item); void setDirRes(DIRRES *dir); + QStringList* dosql(QString* sqlcmd); QStringList job_list; QStringList client_list; diff --git a/bacula/src/qt-console/joblist/joblist.h b/bacula/src/qt-console/joblist/joblist.h index c26399d95a..23f8fe4aea 100644 --- a/bacula/src/qt-console/joblist/joblist.h +++ b/bacula/src/qt-console/joblist/joblist.h @@ -38,7 +38,7 @@ #include "console.h" #include "batstack.h" -class JobList : public BatStack, public Ui::JobListForm +class JobList : public QWidget, public Ui::JobListForm { Q_OBJECT diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index 533a71a471..9e783cb8a2 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -47,21 +47,29 @@ MediaList::MediaList(QStackedWidget *parent, Console *console, QTreeWidgetItem * { setupUi(this); m_parent=parent; -// AddTostack(); - m_poollist = new QStringList(); m_treeWidget = treeWidget; /* our Storage Tree Tree Widget */ m_console = console; m_treeItem = treeItem; createConnections(); - m_popupmedia=""; m_populated=false; + m_headerlist = new QStringList(); + m_popupmedia = new QString(""); + m_poollist = new QStringList(); + m_cmd = new QString("select m.volumename, m.mediaid, m.mediatype, p.name from media m, pool p ORDER BY p.name"); +} + +MediaList::~MediaList() +{ + delete m_headerlist; + delete m_popupmedia; + delete m_poollist; + delete m_cmd; } void MediaList::populateTree() { - int stat; - QTreeWidgetItem *mediatreeitem, *treeitem, *topItem; + QTreeWidgetItem *mediatreeitem, *pooltreeitem, *topItem; m_treeWidget->clear(); m_treeWidget->setColumnCount(3); @@ -73,62 +81,36 @@ void MediaList::populateTree() /* Start with a list of pools */ m_poollist->clear(); - QString *scmd = new QString(".pools\n"); - m_console->write_dir(scmd->toUtf8().data()); - while ((stat=m_console->read()) > 0) { - m_poollist->append(m_console->msg()); - } - for ( QStringList::Iterator poolitem = m_poollist->begin(); poolitem != m_poollist->end(); ++poolitem ) { - treeitem = new QTreeWidgetItem(topItem); - //m_console->setTreeItem(treeitem); - poolitem->replace(QRegExp("\n"), ""); - treeitem->setText(0, poolitem->toUtf8().data()); - treeitem->setData(0, Qt::UserRole, 1); - treeitem->setExpanded( true ); - - /* iterate through the media in the pool */ - QString *mcmd = new QString("sqlquery\n"); - m_console->write_dir(mcmd->toUtf8().data()); - while ((stat=m_console->read()) > 0) { } - QString *mcmd2 = new QString("select m.volumename, m.mediaid, m.mediatype from media m, pool p where p.name = '"); - mcmd2->append(*poolitem); - mcmd2->append("';\n"); - m_console->write_dir(mcmd2->toUtf8().data()); - QString *mediaread = new QString(); - while ((stat=m_console->read()) > 0) { - *mediaread += m_console->msg(); - } - m_console->discardToPrompt(); - QStringList sqllinelist = mediaread->split("\n"); - /* a regex todetermine if mediareadline is a line of interest. */ - QRegExp regex("^\\|.*\\|$"); - int recordcnter=0; - QStringList *headerlist = new QStringList(); - /* Iterate through lines retuned */ - for ( QStringList::Iterator mediareadline = sqllinelist.begin(); mediareadline != sqllinelist.end(); ++mediareadline ) { - if ( regex.indexIn(*mediareadline) >= 0 ){ - QStringList recorditemlist = mediareadline->split("|"); - int recorditemcnter=0; - /* Iterate through items in the record */ - for ( QStringList::Iterator mediarecorditem = recorditemlist.begin(); mediarecorditem != recorditemlist.end(); ++mediarecorditem ) { - QString trimmeditem = mediarecorditem->trimmed(); - if( trimmeditem != "" ){ - if ( recordcnter == 0 ){ - headerlist->append(trimmeditem); - } else { - if ( recorditemcnter == 0 ){ - mediatreeitem = new QTreeWidgetItem(treeitem); - } - mediatreeitem->setData(recorditemcnter, Qt::UserRole, 2); - mediatreeitem->setText(recorditemcnter, trimmeditem.toUtf8().data()); - } - recorditemcnter+=1; + QStringList *results=m_console->dosql(m_cmd); + int recordcounter=0; + m_headerlist->append("Volume Name"); + m_headerlist->append("Media Id"); + m_headerlist->append("Type"); + m_treeWidget->setHeaderLabels(*m_headerlist); + QString currentpool(""); + for ( QStringList::Iterator resultline = results->begin(); resultline != results->end(); ++resultline ) { + QStringList recorditemlist = resultline->split("\t"); + int recorditemcnter=0; + /* Iterate through items in the record */ + for ( QStringList::Iterator mediarecorditem = recorditemlist.begin(); mediarecorditem != recorditemlist.end(); ++mediarecorditem ) { + QString trimmeditem = mediarecorditem->trimmed(); + if( trimmeditem != "" ){ + if ( recorditemcnter == 0 ){ + if ( currentpool != trimmeditem.toUtf8().data() ){ + currentpool = trimmeditem.toUtf8().data(); + pooltreeitem = new QTreeWidgetItem(topItem); + pooltreeitem->setText(0, trimmeditem.toUtf8().data()); + pooltreeitem->setData(0, Qt::UserRole, 1); + pooltreeitem->setExpanded( true ); } + mediatreeitem = new QTreeWidgetItem(pooltreeitem); } - recordcnter+=1; + mediatreeitem->setData(recorditemcnter, Qt::UserRole, 2); + mediatreeitem->setText(recorditemcnter, trimmeditem.toUtf8().data()); + recorditemcnter+=1; } } - m_treeWidget->setHeaderLabels(*headerlist); + recordcounter+=1; } } @@ -149,7 +131,7 @@ void MediaList::treeItemClicked(QTreeWidgetItem *item, int column) break; case 2: /* Can't figure out how to make a right button do this --- Qt::LeftButton, Qt::RightButton, Qt::MidButton */ - m_popupmedia = text; + *m_popupmedia = text; QMenu *popup = new QMenu( m_treeWidget ); connect(popup->addAction("Edit Properties"), SIGNAL(triggered()), this, SLOT(editMedia())); connect(popup->addAction("Show Jobs On Media"), SIGNAL(triggered()), this, SLOT(showJobs())); @@ -166,13 +148,13 @@ void MediaList::treeItemDoubleClicked(QTreeWidgetItem *item, int column) void MediaList::editMedia() { - MediaEdit* edit = new MediaEdit(m_console, m_popupmedia); + MediaEdit* edit = new MediaEdit(m_console, *m_popupmedia); edit->show(); } void MediaList::showJobs() { - JobList* joblist = new JobList(m_console, m_popupmedia); + JobList* joblist = new JobList(m_console, *m_popupmedia); joblist->show(); } diff --git a/bacula/src/qt-console/medialist/medialist.h b/bacula/src/qt-console/medialist/medialist.h index 5aaa3a571b..5964eedc5a 100644 --- a/bacula/src/qt-console/medialist/medialist.h +++ b/bacula/src/qt-console/medialist/medialist.h @@ -45,7 +45,7 @@ class MediaList : public BatStack, public Ui::MediaListForm public: MediaList(QStackedWidget *parent,Console *console, QTreeWidgetItem *treeItem); - void populateTree(); + ~MediaList(); virtual void PgSeltreeWidgetClicked(); virtual void PgSeltreeWidgetDoubleClicked(); @@ -62,9 +62,11 @@ private: Console *m_console; QTreeWidget *m_treeWidget; QStringList *m_poollist; - QString m_popupmedia; + QStringList *m_headerlist; + QString *m_popupmedia; + QString *m_cmd; bool m_populated; - //QStackedWidget *m_parent; + void populateTree(); }; #endif /* _MEDIALIST_H_ */ -- 2.39.5