]> git.sur5r.net Git - bacula/bacula/commitdiff
Working directory pane in restore. Will get this into the stack next.
authorDirk H Bartley <dbartley@schupan.com>
Tue, 1 May 2007 03:29:29 +0000 (03:29 +0000)
committerDirk H Bartley <dbartley@schupan.com>
Tue, 1 May 2007 03:29:29 +0000 (03:29 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4670 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/qt-console/TODO
bacula/src/qt-console/restore/restore.cpp
bacula/src/qt-console/restore/restore.h
bacula/src/qt-console/restore/restore.ui

index 684b201caeb7fae0312d89a5b6f79b9e543509b9..a219844ec88ccd92a3af7d0c36e7d75a00df6f3c 100644 (file)
@@ -2,6 +2,10 @@ dhb
 ====================================================
 Test restore and get anything not working, working.
 
+Get restore into stack.
+
+Play with includes to Make these compiles shorter.
+
 Create list of what does not work.
 From what I can tell, just the restore window on the left.
 
index 7fcf4d089b72a517a2223b4a4db91d762f1c6cc7..928efdd6cdcb9e375c6a7c54c28ab189dbbf40a1 100644 (file)
@@ -48,6 +48,9 @@ restoreDialog::restoreDialog(Console *console )
    setupUi(this);
    connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), 
            this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int)));
+   connect(directoryWidget, SIGNAL(
+           currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
+           this, SLOT(directoryItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
    connect(upButton, SIGNAL(pressed()), this, SLOT(upButtonPushed()));
    connect(markButton, SIGNAL(pressed()), this, SLOT(markButtonPushed()));
    connect(unmarkButton, SIGNAL(pressed()), this, SLOT(unmarkButtonPushed()));
@@ -76,7 +79,7 @@ void restoreDialog::fillDirectory()
 
    fileWidget->clear();
    m_console->write_dir("dir");
-   QList<QTreeWidgetItem *> items;
+   QList<QTreeWidgetItem *> treeItemList;
    QStringList item;
    while (m_console->read() > 0) {
       char *p = m_console->msg();
@@ -124,12 +127,15 @@ void restoreDialog::fillDirectory()
       split_path_and_filename(p, &path, &pnl, &file, &fnl);
       item.clear();
       item << marked << file << modes << user << group << size << date;
+      if (item[1].endsWith("/")) {
+         addDirectory(item[1]);
+       }
       QTreeWidgetItem *ti = new QTreeWidgetItem((QTreeWidget *)0, item);
       ti->setTextAlignment(5, Qt::AlignRight); /* right align size */
-      items.append(ti);
+      treeItemList.append(ti);
    }
    fileWidget->clear();
-   fileWidget->insertTopLevelItems(0, items);
+   fileWidget->insertTopLevelItems(0, treeItemList);
    for (int i=0; i<7; i++) {
       fileWidget->resizeColumnToContents(i);
    }
@@ -138,6 +144,56 @@ void restoreDialog::fillDirectory()
    free_pool_memory(path);
 }
 
+/*
+ * Function called from fill directory when a directory is found to see if this
+ * directory exists in the directory pane and then add it to the directory pane
+ */
+void restoreDialog::addDirectory(QString &newdir)
+{
+   QString fullpath ;
+
+   /* if this is the base dir, strip off the leading "/" */
+   if (m_cwd == "/"){
+      fullpath = newdir;
+   } else {
+      fullpath = m_cwd + newdir;
+   }
+   /* is it already existent ?? */
+   if (!m_dirPaths.contains(fullpath)) {
+      QTreeWidgetItem *item = NULL;
+      if (m_dirPaths.empty()) {
+         /* this is the base widget */
+         item = new QTreeWidgetItem(directoryWidget);
+         item->setText(0, newdir.toUtf8().data());
+      } else {
+         QTreeWidgetItem *parent = m_dirPaths.value(m_cwd);
+         if (parent) {
+            /* new directories to add */
+            item = new QTreeWidgetItem(parent);
+            item->setText(0, newdir.toUtf8().data());
+            directoryWidget->expandItem(parent);
+         }
+      }
+      /* insert into both forward and reverse hash */
+      m_dirPaths.insert(fullpath, item);
+      m_dirTreeItems.insert(item, fullpath);
+   }
+}
+
+/*
+ * Executed when the tree item in the directory pane is changed.  This will
+ * allow us to populate the file pane and make this the cwd.
+ */
+void restoreDialog::directoryItemChanged(QTreeWidgetItem *currentitem,
+                                         QTreeWidgetItem * /*previousitem*/)
+{
+   QString fullpath = m_dirTreeItems.value(currentitem);
+   if (fullpath != ""){
+      cwd(fullpath.toUtf8().data());
+      fillDirectory();
+   }
+}
+
 void restoreDialog::accept()
 {
    this->hide();
@@ -182,23 +238,36 @@ void restoreDialog::fileDoubleClicked(QTreeWidgetItem *item, int column)
     *  the directory -- or nothing if it is not a directory.
     */
    if (item->text(1).endsWith("/")) {
-      cwd(item->text(1).toUtf8().data());
-      fillDirectory();
+      QString fullpath = m_cwd + item->text(1);
+      QTreeWidgetItem *item = m_dirPaths.value(fullpath);
+      if (item) {
+         directoryWidget->setCurrentItem(item);
+      }
    }
 }
 
+/*
+ * If up button pushed, making the parent tree widget current will call fill
+ * directory.
+ */
 void restoreDialog::upButtonPushed()
 {
    cwd("..");
-   fillDirectory();
+   QTreeWidgetItem *item = m_dirPaths.value(m_cwd);
+   if (item) {
+      directoryWidget->setCurrentItem(item);
+   }
 }
 
+/*
+ * Mark selected items
+ */
 void restoreDialog::markButtonPushed()
 {
-   QList<QTreeWidgetItem *> items = fileWidget->selectedItems();
+   QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
    QTreeWidgetItem *item;
    char cmd[1000];
-   foreach (item, items) {
+   foreach (item, treeItemList) {
       bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
       item->setText(0, "*");
       m_console->write_dir(cmd);
@@ -211,12 +280,15 @@ void restoreDialog::markButtonPushed()
    }
 }
 
+/*
+ * Unmark selected items
+ */
 void restoreDialog::unmarkButtonPushed()
 {
-   QList<QTreeWidgetItem *> items = fileWidget->selectedItems();
+   QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
    QTreeWidgetItem *item;
    char cmd[1000];
-   foreach (item, items) {
+   foreach (item, treeItemList) {
       bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
       item->setText(0, " ");
       m_console->write_dir(cmd);
index bc825fc8eaf3564e1085ce9c3f41423d6d60ce16..98305b2d74db3025f9f3aa400aa6888521ff8013 100644 (file)
@@ -82,13 +82,17 @@ private slots:
    void accept();
    void reject();
    void fileDoubleClicked(QTreeWidgetItem *item, int column);
+   void directoryItemChanged(QTreeWidgetItem *, QTreeWidgetItem *);
    void upButtonPushed();
    void unmarkButtonPushed();
    void markButtonPushed();
+   void addDirectory(QString &);
 
 private:
    Console *m_console;
    QString m_cwd;
+   QHash<QString, QTreeWidgetItem *> m_dirPaths;
+   QHash<QTreeWidgetItem *,QString> m_dirTreeItems;
 };
 
 
index 4353f2f61f1b15dbed3691009bf3b8e956502f8c..322ecf2c002158b593d71221556d64a453bf0e94 100644 (file)
@@ -85,7 +85,7 @@
         </layout>
        </item>
        <item>
-        <widget class="QTreeWidget" name="treeWidget" >
+        <widget class="QTreeWidget" name="directoryWidget" >
          <property name="sizePolicy" >
           <sizepolicy>
            <hsizetype>5</hsizetype>