]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/mainwin.cpp
dhb I've got most of the user interface issues working as I was hoping to see
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
index 6bfcb67a19589189473d1085b3f6a026d1c770f6..f76e03b9b280ed2abf4899aa3129798ea6f15ccc 100644 (file)
  */ 
 
 #include "bat.h"
+#include "medialist/medialist.h"
 
 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
 {
 
    mainWin = this;
    setupUi(this);                     /* Setup UI defined by main.ui (designer) */
+   treeWidget->clear();
+   treeWidget->setColumnCount(1);
+   treeWidget->setHeaderLabel("Select Page");
 
-   createStackedWidgets();
+   m_pages = 0;
+   createPages();
 
    resetFocus();
 
@@ -54,44 +59,76 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
    readSettings();
 
    m_console->connect();
+   m_medialist->populateTree();
 }
 
-void MainWin::createStackedWidgets()
+void MainWin::createPages()
 {
+   DIRRES *dir;
    QTreeWidgetItem *item, *topItem;
-   m_console = new Console(stackedWidget);
-   stackedWidget->addWidget(m_console);
-
-   bRestore *brestore = new bRestore(stackedWidget);
-   stackedWidget->addWidget(brestore);
 
+   /* Create console tree stacked widget item */
+   m_console = new Console(stackedWidget);
+   /* Console is special needs director*/
    /* Just take the first Director */
    LockRes();
-   DIRRES *dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
+   dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
    m_console->setDirRes(dir);
    UnlockRes();
-
-   /* ***FIXME*** Dummy setup of treeWidget */
-   treeWidget->clear();
-   treeWidget->setColumnCount(1);
-   treeWidget->setHeaderLabel("Selection");
-   topItem = new QTreeWidgetItem(treeWidget);
-   topItem->setText(0, dir->name());
+   /* The top tree item representing the director */
+   topItem = createTopPage(dir->name());
    topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
-   item = new QTreeWidgetItem(topItem);
+   /* Create Tree Widget Item */
+   item = createPage("Console", topItem);
    m_console->setTreeItem(item);
-   item->setText(0, "Console");
-   item->setText(1, "0");
+   /* Append to bstacklist */
+   m_bstacklist.append(m_console);
+   /* Set BatStack m_treeItem */
+   m_console->SetBSTreeWidgetItem(item);
    QBrush redBrush(Qt::red);
    item->setForeground(0, redBrush);
-   item = new QTreeWidgetItem(topItem);
-   item->setText(0, "brestore");
-   item->setText(1, "1");
-   treeWidget->expandItem(topItem);
 
+   /* Now with the console created, on with the rest, these are easy */
+   /* All should be
+ * 1. create tree widget item
+ * 2. create object passing pointer to tree widget item (modified constructors to pass QTreeWidget pointers)
+ * 3. append to stacklist  */ 
+
+   /* brestore */
+   item = createPage("brestore", topItem);
+   m_brestore = new bRestore(stackedWidget,item);
+   m_bstacklist.append(m_brestore);
+
+   /* lastly for now, the medialist */
+   item = createPage("Storage Tree", topItem );
+   m_medialist = new MediaList(stackedWidget, m_console, item);
+   m_bstacklist.append(m_medialist);
+
+   /* Iterate through and add to the stack */
+   for ( QList<BatStack*>::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) {
+      (*bstackItem)->AddTostack();
+   }
+
+   treeWidget->expandItem(topItem);
    stackedWidget->setCurrentIndex(0);
 }
 
+/* Create a root Tree Widget */
+QTreeWidgetItem *MainWin::createTopPage(char *name )
+{
+   QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
+   item->setText(0, name);
+   return item;
+}
+
+/* Create A Tree Widget Item which will be associated with a Page in the stacked widget */
+QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent)
+{
+   QTreeWidgetItem *item = new QTreeWidgetItem(parent);
+   item->setText(0, name);
+   return item;
+}
+
 /*
  * Handle up and down arrow keys for the command line
  *  history.
@@ -134,11 +171,11 @@ void MainWin::createConnections()
    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
    connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
 
-   connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, 
-           SLOT(treeItemClicked(QTreeWidgetItem *, int)));
-   connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, 
+/*   connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, 
            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
    connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, 
+           SLOT(treeItemClicked(QTreeWidgetItem *, int)));  Commented out because it was getting to clicked multiple times*/
+   connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, 
            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
    connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, 
            SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
@@ -185,10 +222,18 @@ void MainWin::readSettings()
 
 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
 {
-   (void)column;
-   int index = item->text(1).toInt();
-   if (index >= 0 && index < 4) {
-      stackedWidget->setCurrentIndex(index);
+   /* Iterate through and find the tree widget item clicked */
+   column+=0;
+   QList<BatStack*>::iterator bstackItem;
+   bstackItem = m_bstacklist.begin();
+   while ( bstackItem != m_bstacklist.end() ){
+      if ( item == (*bstackItem)->m_treeItem ) {
+        int stackindex=stackedWidget->indexOf( *bstackItem );
+        if( stackindex >= 0 ){
+           stackedWidget->setCurrentIndex(stackindex);
+        }
+      }
+      ++bstackItem;
    }
 }
 
@@ -196,11 +241,23 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
  */
 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
 {
-   (void)column;
-   int index = item->text(1).toInt();
-   /* ***FIXME**** make this automatic */
-   if (index >= 0 && index < 4) {
-      stackedWidget->setCurrentIndex(index);
+   /* Iterate through and find the tree widget item double clicked */
+   column+=0;
+   QList<BatStack*>::iterator bstackItem;
+   bstackItem = m_bstacklist.begin();
+   while ( bstackItem != m_bstacklist.end() ){
+      if ( item == (*bstackItem)->m_treeItem ) {
+        /* This could be a call a virtual function ?? or just popup a popup menu for an action */
+        if ( (*bstackItem)->isStacked() == true ){
+           m_bstackpophold=*bstackItem;
+           QMenu *popup = new QMenu( treeWidget );
+           connect(popup->addAction("Pull Window Out"), SIGNAL(triggered()), this, SLOT(pullWindowOut()));
+           popup->exec(QCursor::pos());
+        } else {
+           (*bstackItem)->Togglestack();
+        }
+      }
+      ++bstackItem;
    }
 }
 
@@ -242,7 +299,7 @@ void MainWin::input_line()
 void MainWin::about()
 {
    QMessageBox::about(this, tr("About bat"),
-            tr("<br><h2>bat 0.1</h2>"
+            tr("<br><h2>bat 0.2, by Kern Sibbald</h2>"
             "<p>Copyright &copy; " BYEAR " Free Software Foundation Europe e.V."
             "<p>The <b>bat</b> is an administrative console"
                " interface to the Director."));
@@ -268,3 +325,8 @@ void MainWin::set_status(const char *buf)
 {
    statusBar()->showMessage(buf);
 }
+
+void MainWin::pullWindowOut()
+{
+   m_bstackpophold->Togglestack();
+}