#include "mediaedit/mediaedit.h"
#include "joblist/joblist.h"
-MediaList::MediaList(QStackedWidget *parent, Console *console, QTreeWidgetItem *treeItem, int indexseq)
+MediaList::MediaList(QStackedWidget *parent, Console *console)
{
- SetPassedValues(parent, treeItem, indexseq );
setupUi(this);
- m_treeWidget = treeWidget; /* our Storage Tree Tree Widget */
- m_console = console;
+ /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_medialist.h */
+ mp_console = console;
+ m_parent = parent;
createConnections();
m_populated = false;
+ m_checkcurwidget = true;
+ m_closeable = false;
}
MediaList::~MediaList()
QStringList results;
const char *query =
"SELECT p.Name,m.VolumeName,m.MediaId,m.VolStatus,m.Enabled,m.VolBytes,"
- "m.VolFiles,m.VolRetention,m.MediaType,m.LastWritten"
+ "m.VolFiles,m.VolJobs,m.VolRetention,m.MediaType,m.LastWritten"
" FROM Media m,Pool p"
" WHERE m.PoolId=p.PoolId"
" ORDER BY p.Name";
QStringList headerlist = (QStringList()
<< "Pool Name" << "Volume Name" << "Media Id" << "Volume Status" << "Enabled"
- << "Volume Bytes" << "Volume Files" << "Volume Retention"
+ << "Volume Bytes" << "Volume Files" << "Volume Jobs" << "Volume Retention"
<< "Media Type" << "Last Written");
- m_treeWidget->clear();
- m_treeWidget->setColumnCount(9);
- topItem = new QTreeWidgetItem(m_treeWidget);
+ m_checkcurwidget = false;
+ mp_treeWidget->clear();
+ m_checkcurwidget = true;
+ mp_treeWidget->setColumnCount(headerlist.count());
+ topItem = new QTreeWidgetItem(mp_treeWidget);
topItem->setText(0, "Pools");
topItem->setData(0, Qt::UserRole, 0);
- topItem->setExpanded( true );
-
-#ifdef xxx
-#include <QSize>
-***** FIXME *****
-//how to get the size of a column to be larger
-//topItem->setSizeHint(0,QSize(1050,50));
-#endif
-
- m_treeWidget->setHeaderLabels(headerlist);
-
- /*
- * Setup a context menu
- */
- QAction *editAction = new QAction("Edit Properties", m_treeWidget);
- QAction *listAction = new QAction("List Jobs On Media", m_treeWidget);
- m_treeWidget->addAction(editAction);
- m_treeWidget->addAction(listAction);
- connect(editAction, SIGNAL(triggered()), this, SLOT(editMedia()));
- connect(listAction, SIGNAL(triggered()), this, SLOT(showJobs()));
- m_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
- connect(m_treeWidget, SIGNAL(
- currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
- this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
+ topItem->setExpanded(true);
+
+ mp_treeWidget->setHeaderLabels(headerlist);
- if (m_console->sql_cmd(query, results)) {
+ //printf("MediaList query cmd : %s\n",query);
+ if (mp_console->sql_cmd(query, results)) {
QString field;
QStringList fieldlist;
- QRegExp regex("^Using Catalog");
foreach (resultline, results) {
fieldlist = resultline.split("\t");
- if (regex.indexIn(resultline) < 0) {
- int index = 0;
- /* Iterate through fields in the record */
- foreach (field, fieldlist) {
- field = field.trimmed(); /* strip leading & trailing spaces */
- if (field != "") {
- /* The first field is the pool name */
- if (index == 0) {
- /* If new pool name, create new Pool item */
- if (currentpool != field) {
- currentpool = field;
- pooltreeitem = new QTreeWidgetItem(topItem);
- pooltreeitem->setText(0, field);
- pooltreeitem->setData(0, Qt::UserRole, 1);
- pooltreeitem->setExpanded(true);
- }
- mediatreeitem = new QTreeWidgetItem(pooltreeitem);
- mediatreeitem->setData(index, Qt::UserRole, 2);
- } else {
- /* Put media fields under the pool tree item */
- mediatreeitem->setData(index, Qt::UserRole, 2);
- mediatreeitem->setText(index, field);
+ int index = 0;
+ /* Iterate through fields in the record */
+ foreach (field, fieldlist) {
+ field = field.trimmed(); /* strip leading & trailing spaces */
+ if (field != "") {
+ /* The first field is the pool name */
+ if (index == 0) {
+ /* If new pool name, create new Pool item */
+ if (currentpool != field) {
+ currentpool = field;
+ pooltreeitem = new QTreeWidgetItem(topItem);
+ pooltreeitem->setText(0, field);
+ pooltreeitem->setData(0, Qt::UserRole, 1);
+ pooltreeitem->setExpanded(true);
}
+ mediatreeitem = new QTreeWidgetItem(pooltreeitem);
+ mediatreeitem->setData(index, Qt::UserRole, 2);
+ } else {
+ /* Put media fields under the pool tree item */
+ mediatreeitem->setData(index, Qt::UserRole, 2);
+ mediatreeitem->setText(index, field);
}
- index++;
}
+ index++;
}
}
}
*/
void MediaList::createConnections()
{
- connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
+ connect(mp_treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
SLOT(treeItemClicked(QTreeWidgetItem *, int)));
- connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
+ connect(mp_treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
}
*/
void MediaList::editMedia()
{
- /* ***FIXME*** make sure a valid tree item is selected -- check currentItem
- * ??? Should this be a check in the database for the existence of m_popuptext??*/
- MediaEdit* edit = new MediaEdit(m_console, m_popuptext);
+ MediaEdit* edit = new MediaEdit(mp_console, m_currentlyselected);
edit->show();
}
*/
void MediaList::showJobs()
{
- JobList* joblist = new JobList(m_console, m_popuptext);
- joblist->show();
+ QString emptyclient("");
+ mainWin->createPageJobList(m_currentlyselected, emptyclient);
}
/*
{
if(!m_populated) {
populateTree();
+ createContextMenu();
m_populated=true;
}
}
/*
* Added to set the context menu policy based on currently active treeWidgetItem
+ * signaled by currentItemChanged
*/
-void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *) /*previouswidgetitem*/
+void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
{
- int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
- if (treedepth == 2){
- m_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
- } else {
- m_treeWidget->setContextMenuPolicy(Qt::NoContextMenu);
+ /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
+ if (m_checkcurwidget) {
+ /* The Previous item */
+ if (previouswidgetitem) { /* avoid a segfault if first time */
+ int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
+ if (treedepth == 2){
+ mp_treeWidget->removeAction(actionEditVolume);
+ mp_treeWidget->removeAction(actionListJobsOnVolume);
+ }
+ }
+
+ int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
+ if (treedepth == 2){
+ m_currentlyselected=currentwidgetitem->text(1);
+ mp_treeWidget->addAction(actionEditVolume);
+ mp_treeWidget->addAction(actionListJobsOnVolume);
+ }
}
}
+/*
+ * Setup a context menu
+ * Made separate from populate so that it would not create context menu over and
+ * over as the tree is repopulated.
+ */
+void MediaList::createContextMenu()
+{
+ mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
+ /*mp_treeWidget->setContextMenuPolicy(Qt::NoContextMenu);*/
+ mp_treeWidget->addAction(actionRefreshMediaList);
+ connect(actionEditVolume, SIGNAL(triggered()), this, SLOT(editMedia()));
+ connect(actionListJobsOnVolume, SIGNAL(triggered()), this, SLOT(showJobs()));
+ mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
+ connect(mp_treeWidget, SIGNAL(
+ currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
+ this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
+ /* connect to the action specific to this pages class */
+ connect(actionRefreshMediaList, SIGNAL(triggered()), this,
+ SLOT(populateTree()));
+}
+
+/*
+ * Virtual function which is called when this page is visible on the stack
+ */
+void MediaList::currentStackItem()
+{
+ if(!m_populated) {
+ populateTree();
+ /* add context sensitive menu items specific to this classto the page
+ * selector tree. m_m_contextActions is QList of QActions, so this is
+ * only done once with the first population. */
+ m_contextActions.append(actionRefreshMediaList);
+ /* Create the context menu for the medialist tree */
+ createContextMenu();
+ m_populated=true;
+ }
+}