]> git.sur5r.net Git - bacula/bacula/commitdiff
Change fileset and client windows from tree widgets to table widgets.
authorDirk H Bartley <dbartley@schupan.com>
Mon, 28 Apr 2008 23:30:18 +0000 (23:30 +0000)
committerDirk H Bartley <dbartley@schupan.com>
Mon, 28 Apr 2008 23:30:18 +0000 (23:30 +0000)
Fix a segfault on closing the window in mainwin.  You may desire to look
at the change to mainwin.  2 more windows to change to table widgets.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6857 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/qt-console/clients/clients.cpp
bacula/src/qt-console/clients/clients.h
bacula/src/qt-console/clients/clients.ui
bacula/src/qt-console/fileset/fileset.cpp
bacula/src/qt-console/fileset/fileset.h
bacula/src/qt-console/fileset/fileset.ui
bacula/src/qt-console/mainwin.cpp

index 9e39ab9ecce31e3c804d80fb8fbf5592bcdd3323..66c4f2c2c1f160c8091a86eb08acada955315133 100644 (file)
@@ -50,7 +50,7 @@ Clients::Clients()
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/network-server.png")));
 
-   /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */
+   /* tableWidget, Storage Tree Tree Widget inherited from ui_client.h */
    m_populated = false;
    m_checkcurwidget = true;
    m_closeable = false;
@@ -69,36 +69,30 @@ Clients::~Clients()
  * The main meat of the class!!  The function that querries the director and 
  * creates the widgets with appropriate values.
  */
-void Clients::populateTree()
+void Clients::populateTable()
 {
-   QTreeWidgetItem *clientItem, *topItem;
+   QTableWidgetItem *tableItem;
+   QBrush blackBrush(Qt::black);
 
    if (!m_console->preventInUseConnect())
       return;
    m_checkcurwidget = false;
-   mp_treeWidget->clear();
+   tableWidget->clear();
    m_checkcurwidget = true;
 
    QStringList headerlist = (QStringList() << tr("Client Name") << tr("File Retention")
        << tr("Job Retention") << tr("AutoPrune") << tr("ClientId") << tr("Uname") );
 
-   topItem = new QTreeWidgetItem(mp_treeWidget);
-   topItem->setText(0, tr("Clients"));
-   topItem->setData(0, Qt::UserRole, 0);
-   topItem->setExpanded(true);
-
-   mp_treeWidget->setColumnCount(headerlist.count());
-   mp_treeWidget->setHeaderLabels(headerlist);
+   tableWidget->setColumnCount(headerlist.count());
+   tableWidget->setHorizontalHeaderLabels(headerlist);
+   tableWidget->setRowCount(m_console->client_list.count());
+   tableWidget->verticalHeader()->hide();
+   int row = 0;
 
    foreach (QString clientName, m_console->client_list){
-      clientItem = new QTreeWidgetItem(topItem);
-      clientItem->setText(0, clientName);
-      clientItem->setData(0, Qt::UserRole, 1);
-      clientItem->setExpanded(true);
-
       /* Set up query QString and header QStringList */
       QString query("");
-      query += "SELECT FileRetention, JobRetention, AutoPrune, ClientId, Uname"
+      query += "SELECT Name, FileRetention, JobRetention, AutoPrune, ClientId, Uname"
            " FROM Client"
            " WHERE ";
       query += " Name='" + clientName + "'";
@@ -118,23 +112,25 @@ void Clients::populateTree()
             /* there will only be one of these */
             foreach (resultline, results) {
                fieldlist = resultline.split("\t");
-               int index = 0;
+               int column = 0;
                /* Iterate through fields in the record */
                foreach (field, fieldlist) {
                   field = field.trimmed();  /* strip leading & trailing spaces */
-                  clientItem->setData(index+1, Qt::UserRole, 1);
-                  /* Put media fields under the pool tree item */
-                  clientItem->setData(index+1, Qt::UserRole, 1);
-                  clientItem->setText(index+1, field);
-                  index++;
+                  tableItem = new QTableWidgetItem(field, 1);
+                  tableItem->setFlags(Qt::ItemIsSelectable);
+                  tableItem->setForeground(blackBrush);
+                  tableItem->setData(Qt::UserRole, 1);
+                  tableWidget->setItem(row, column, tableItem);
+                  column++;
                }
             }
          }
       }
+      row ++;
    }
    /* Resize the columns */
    for(int cnter=0; cnter<headerlist.size(); cnter++) {
-      mp_treeWidget->resizeColumnToContents(cnter);
+      tableWidget->resizeColumnToContents(cnter);
    }
 }
 
@@ -145,7 +141,7 @@ void Clients::populateTree()
 void Clients::PgSeltreeWidgetClicked()
 {
    if(!m_populated) {
-      populateTree();
+      populateTable();
       m_populated=true;
    }
 }
@@ -154,32 +150,31 @@ void Clients::PgSeltreeWidgetClicked()
  * Added to set the context menu policy based on currently active treeWidgetItem
  * signaled by currentItemChanged
  */
-void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
+void Clients::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem )
 {
    /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
    if (m_checkcurwidget) {
+      int currentRow = currentwidgetitem->row();
+      QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
+      m_currentlyselected = currentrowzeroitem->text();
+
       /* The Previous item */
       if (previouswidgetitem) { /* avoid a segfault if first time */
-         int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
-         if (treedepth == 1){
-            mp_treeWidget->removeAction(actionListJobsofClient);
-            mp_treeWidget->removeAction(actionStatusClientInConsole);
-            mp_treeWidget->removeAction(actionStatusClientWindow);
-            mp_treeWidget->removeAction(actionPurgeJobs);
-            mp_treeWidget->removeAction(actionPrune);
-         }
+         tableWidget->removeAction(actionListJobsofClient);
+         tableWidget->removeAction(actionStatusClientInConsole);
+         tableWidget->removeAction(actionStatusClientWindow);
+         tableWidget->removeAction(actionPurgeJobs);
+         tableWidget->removeAction(actionPrune);
       }
 
-      int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
-      if (treedepth == 1){
+      if (m_currentlyselected.length() != 0) {
          /* set a hold variable to the client name in case the context sensitive
           * menu is used */
-         m_currentlyselected=currentwidgetitem->text(0);
-         mp_treeWidget->addAction(actionListJobsofClient);
-         mp_treeWidget->addAction(actionStatusClientInConsole);
-         mp_treeWidget->addAction(actionStatusClientWindow);
-         mp_treeWidget->addAction(actionPurgeJobs);
-         mp_treeWidget->addAction(actionPrune);
+         tableWidget->addAction(actionListJobsofClient);
+         tableWidget->addAction(actionStatusClientInConsole);
+         tableWidget->addAction(actionStatusClientWindow);
+         tableWidget->addAction(actionPurgeJobs);
+         tableWidget->addAction(actionPrune);
       }
    }
 }
@@ -191,14 +186,16 @@ void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetIte
  */
 void Clients::createContextMenu()
 {
-   mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
-   mp_treeWidget->addAction(actionRefreshClients);
-   connect(mp_treeWidget, SIGNAL(
-           currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
-           this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
+   tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
+   tableWidget->addAction(actionRefreshClients);
+   /* for the tableItemChanged to maintain m_currentJob */
+   connect(tableWidget, SIGNAL(
+           currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
+           this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
+
    /* connect to the action specific to this pages class */
    connect(actionRefreshClients, SIGNAL(triggered()), this,
-                SLOT(populateTree()));
+                SLOT(populateTable()));
    connect(actionListJobsofClient, SIGNAL(triggered()), this,
                 SLOT(showJobs()));
    connect(actionStatusClientInConsole, SIGNAL(triggered()), this,
@@ -238,8 +235,8 @@ void Clients::consoleStatusClient()
 void Clients::currentStackItem()
 {
    if(!m_populated) {
-      populateTree();
-      /* Create the context menu for the client tree */
+      populateTable();
+      /* Create the context menu for the client table */
       m_populated=true;
    }
 }
index d7a9982279a1b07312d62b3cea050a1506711941..9779dde686e7143b0047f43d722abaf9808045b8 100644 (file)
@@ -49,10 +49,10 @@ public:
    virtual void currentStackItem();
 
 public slots:
-   void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *);
+   void tableItemChanged(QTableWidgetItem *, QTableWidgetItem *);
 
 private slots:
-   void populateTree();
+   void populateTable();
    void showJobs();
    void consoleStatusClient();
    void statusClientWindow();
index b00486c22fa1e5ab0de01a4118e03a8d0f88fb8b..8f65323d6699be23ba0adb0a330239ab649092a4 100644 (file)
@@ -5,40 +5,16 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>413</width>
-    <height>258</height>
+    <width>492</width>
+    <height>428</height>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>Client Tree</string>
   </property>
   <layout class="QGridLayout" >
-   <property name="leftMargin" >
-    <number>9</number>
-   </property>
-   <property name="topMargin" >
-    <number>9</number>
-   </property>
-   <property name="rightMargin" >
-    <number>9</number>
-   </property>
-   <property name="bottomMargin" >
-    <number>9</number>
-   </property>
-   <property name="horizontalSpacing" >
-    <number>6</number>
-   </property>
-   <property name="verticalSpacing" >
-    <number>6</number>
-   </property>
    <item row="0" column="0" >
-    <widget class="QTreeWidget" name="mp_treeWidget" >
-     <column>
-      <property name="text" >
-       <string>1</string>
-      </property>
-     </column>
-    </widget>
+    <widget class="QTableWidget" name="tableWidget" />
    </item>
   </layout>
   <action name="actionRefreshClients" >
index 9e6a0334e2633c6ddfb6fdb34bd795837a2dabd3..47d6b762d96bdb216bba7d98dae8ea4598c116a2 100644 (file)
@@ -48,7 +48,7 @@ FileSet::FileSet()
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/system-file-manager.png")));
 
-   /* mp_treeWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */
+   /* tableWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */
    m_populated = false;
    m_checkcurwidget = true;
    m_closeable = false;
@@ -68,33 +68,28 @@ FileSet::~FileSet()
  * The main meat of the class!!  The function that querries the director and 
  * creates the widgets with appropriate values.
  */
-void FileSet::populateTree()
+void FileSet::populateTable()
 {
-   QTreeWidgetItem *filesetItem, *topItem;
+   QTableWidgetItem *tableItem;
+   QBrush blackBrush(Qt::black);
 
    if (!m_console->preventInUseConnect())
        return;
 
    m_checkcurwidget = false;
-   mp_treeWidget->clear();
+   tableWidget->clear();
    m_checkcurwidget = true;
 
    QStringList headerlist = (QStringList() << tr("FileSet Name") << tr("FileSet Id")
        << tr("Create Time"));
 
-   topItem = new QTreeWidgetItem(mp_treeWidget);
-   topItem->setText(0, tr("FileSet"));
-   topItem->setData(0, Qt::UserRole, 0);
-   topItem->setExpanded(true);
-
-   mp_treeWidget->setColumnCount(headerlist.count());
-   mp_treeWidget->setHeaderLabels(headerlist);
+   tableWidget->setColumnCount(headerlist.count());
+   tableWidget->setHorizontalHeaderLabels(headerlist);
+   tableWidget->setRowCount(m_console->fileset_list.count());
+   tableWidget->verticalHeader()->hide();
+   int row = 0;
 
    foreach(QString filesetName, m_console->fileset_list) {
-      filesetItem = new QTreeWidgetItem(topItem);
-      filesetItem->setText(0, filesetName);
-      filesetItem->setData(0, Qt::UserRole, 1);
-      filesetItem->setExpanded(true);
 
       /* Set up query QString and header QStringList */
       QString query("");
@@ -102,7 +97,7 @@ void FileSet::populateTree()
            " FROM FileSet"
            " WHERE ";
       query += " FileSet='" + filesetName + "'";
-      query += " ORDER BY FileSet";
+      query += " ORDER BY CreateTime DESC LIMIT 1";
 
       QStringList results;
       if (mainWin->m_sqlDebug) {
@@ -110,30 +105,31 @@ void FileSet::populateTree()
       }
       if (m_console->sql_cmd(query, results)) {
          int resultCount = results.count();
-         if (resultCount == 1){
+         if (resultCount{
             QString resultline;
             QString field;
             QStringList fieldlist;
-            /* there will only be one of these */
-            foreach (resultline, results) {
-               fieldlist = resultline.split("\t");
-               int index = 0;
-               /* Iterate through fields in the record */
-               foreach (field, fieldlist) {
-                  field = field.trimmed();  /* strip leading & trailing spaces */
-                  filesetItem->setData(index, Qt::UserRole, 1);
-                  /* Put media fields under the pool tree item */
-                  filesetItem->setData(index, Qt::UserRole, 1);
-                  filesetItem->setText(index, field);
-                  index++;
-               }
+            /* only use the last one */
+            resultline = results[resultCount - 1];
+            fieldlist = resultline.split("\t");
+            int column = 0;
+            /* Iterate through fields in the record */
+            foreach (field, fieldlist) {
+               field = field.trimmed();  /* strip leading & trailing spaces */
+               tableItem = new QTableWidgetItem(field, 1);
+               tableItem->setFlags(Qt::ItemIsSelectable);
+               tableItem->setForeground(blackBrush);
+               tableItem->setData(Qt::UserRole, 1);
+               tableWidget->setItem(row, column, tableItem);
+               column++;
             }
          }
       }
+      row++;
    }
    /* Resize the columns */
    for (int cnter=0; cnter<headerlist.size(); cnter++) {
-      mp_treeWidget->resizeColumnToContents(cnter);
+      tableWidget->resizeColumnToContents(cnter);
    }
 }
 
@@ -144,7 +140,7 @@ void FileSet::populateTree()
 void FileSet::PgSeltreeWidgetClicked()
 {
    if (!m_populated) {
-      populateTree();
+      populateTable();
       createContextMenu();
       m_populated = true;
    }
@@ -154,27 +150,25 @@ void FileSet::PgSeltreeWidgetClicked()
  * Added to set the context menu policy based on currently active treeWidgetItem
  * signaled by currentItemChanged
  */
-void FileSet::treeItemChanged(QTreeWidgetItem *currentwidgetitem, 
-                              QTreeWidgetItem *previouswidgetitem )
+void FileSet::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem)
 {
    /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
    if (m_checkcurwidget) {
+      int currentRow = currentwidgetitem->row();
+      QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
+      m_currentlyselected = currentrowzeroitem->text();
+
       /* The Previous item */
       if (previouswidgetitem) { /* avoid a segfault if first time */
-         int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
-         if (treedepth == 1) {
-            mp_treeWidget->removeAction(actionStatusFileSetInConsole);
-            mp_treeWidget->removeAction(actionShowJobs);
-         }
+         tableWidget->removeAction(actionStatusFileSetInConsole);
+         tableWidget->removeAction(actionShowJobs);
       }
 
-      int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
-      if (treedepth == 1){
+      if (m_currentlyselected.length() != 0) {
          /* set a hold variable to the fileset name in case the context sensitive
           * menu is used */
-         m_currentlyselected=currentwidgetitem->text(0);
-         mp_treeWidget->addAction(actionStatusFileSetInConsole);
-         mp_treeWidget->addAction(actionShowJobs);
+         tableWidget->addAction(actionStatusFileSetInConsole);
+         tableWidget->addAction(actionShowJobs);
       }
    }
 }
@@ -186,14 +180,14 @@ void FileSet::treeItemChanged(QTreeWidgetItem *currentwidgetitem,
  */
 void FileSet::createContextMenu()
 {
-   mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
-   mp_treeWidget->addAction(actionRefreshFileSet);
-   connect(mp_treeWidget, SIGNAL(
-           currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
-           this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
+   tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
+   tableWidget->addAction(actionRefreshFileSet);
+   connect(tableWidget, SIGNAL(
+           currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
+           this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
    /* connect to the action specific to this pages class */
    connect(actionRefreshFileSet, SIGNAL(triggered()), this,
-                SLOT(populateTree()));
+                SLOT(populateTable()));
    connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this,
                 SLOT(consoleStatusFileSet()));
    connect(actionShowJobs, SIGNAL(triggered()), this,
@@ -217,8 +211,8 @@ void FileSet::consoleStatusFileSet()
 void FileSet::currentStackItem()
 {
    if(!m_populated) {
-      populateTree();
-      /* Create the context menu for the fileset tree */
+      populateTable();
+      /* Create the context menu for the fileset table */
       createContextMenu();
       m_populated=true;
    }
index ad13973ee2a21afb1425233b0bcfb1460bbc6ab2..ab2ef52c7e9dcd829e16613428c0d5097badd0b5 100644 (file)
@@ -49,10 +49,10 @@ public:
    virtual void currentStackItem();
 
 public slots:
-   void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *);
+   void tableItemChanged(QTableWidgetItem *, QTableWidgetItem *);
 
 private slots:
-   void populateTree();
+   void populateTable();
    void consoleStatusFileSet();
    void showJobs();
 
index 7b0aaf36cedb578eff5d2b15a57b1a05d6d3fd1a..eca3b9d0ef929bfa672024e10fdf860a37a83837 100644 (file)
@@ -5,22 +5,16 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>318</width>
-    <height>246</height>
+    <width>341</width>
+    <height>277</height>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>FileSet Tree</string>
   </property>
   <layout class="QGridLayout" >
-   <property name="margin" >
-    <number>9</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
    <item row="0" column="0" >
-    <widget class="QTreeWidget" name="mp_treeWidget" />
+    <widget class="QTableWidget" name="tableWidget" />
    </item>
   </layout>
   <action name="actionRefreshFileSet" >
index fa5870fde51f38ca70dfb4d8da9d9e068f4e26ac..9a2b5ac78d6ab026d74a26cbe15b3937cecbce8e 100644 (file)
@@ -254,11 +254,11 @@ void MainWin::closeEvent(QCloseEvent *event)
 {
    m_isClosing = true;
    writeSettings();
-   foreach(Console *console, m_consoleHash){
+/*   foreach(Console *console, m_consoleHash){
       console->writeSettings();
       console->terminate();
       console->closeStackPage();
-   }
+   } */
    /* close all non console pages, this will call settings in destructors */
    while (m_consoleHash.count() < m_pagehash.count()) {
       foreach(Pages *page, m_pagehash) {