#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);
/* 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_checkcurwidget = false;
mp_treeWidget->clear();
- mp_treeWidget->setColumnCount(9);
+ 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
+ topItem->setExpanded(true);
mp_treeWidget->setHeaderLabels(headerlist);
- /*
- * Setup a context menu
- */
- QAction *editAction = new QAction("Edit Properties", mp_treeWidget);
- QAction *listAction = new QAction("List Jobs On Media", mp_treeWidget);
- mp_treeWidget->addAction(editAction);
- mp_treeWidget->addAction(listAction);
- connect(editAction, SIGNAL(triggered()), this, SLOT(editMedia()));
- connect(listAction, SIGNAL(triggered()), this, SLOT(showJobs()));
- mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
- connect(mp_treeWidget, SIGNAL(
- currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
- this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
-
+ //printf("MediaList query cmd : %s\n",query);
if (mp_console->sql_cmd(query, results)) {
QString field;
QStringList fieldlist;
*/
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_currentlyselected??*/
MediaEdit* edit = new MediaEdit(mp_console, m_currentlyselected);
edit->show();
}
*/
void MediaList::showJobs()
{
- JobList* joblist = new JobList(mp_console, m_currentlyselected);
- 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 )
+{
+ /* 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::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *) /*previouswidgetitem*/
+void MediaList::currentStackItem()
{
- int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
- if (treedepth == 2){
- mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
- m_currentlyselected=currentwidgetitem->text(1);
- } else {
- mp_treeWidget->setContextMenuPolicy(Qt::NoContextMenu);
+ 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;
}
}