]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/restore/restore.cpp
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / qt-console / restore / restore.cpp
index d4e02095a6886529e7f50d9ecf206c1720ec49cd..70cc2992e3eb365dee148172c7bf26b7ec632ff3 100644 (file)
@@ -1,34 +1,24 @@
 /*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
-
-   The main author of Bacula is Kern Sibbald, with contributions from
-   many others, a complete list can be found in the file AUTHORS.
-   This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation and included
-   in the file LICENSE.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-   Bacula® is a registered trademark of John Walker.
-   The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
-   Switzerland, email:ftf@fsfeurope.org.
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2015 Kern Sibbald
+   Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
  
 /*
- *   Version $Id$
- *
  *  Restore Class 
  *
  *   Kern Sibbald, February MMVII
 #include "bat.h"
 #include "restore.h"
 
-restorePage::restorePage()
+static const int dbglvl = 100;
+
+restorePage::restorePage(int conn) : Pages()
 {
+   Dmsg1(dbglvl, "Construcing restorePage Instance connection %i\n", conn);
+   m_conn = conn;
    QStringList titles;
 
    setupUi(this);
@@ -48,8 +42,7 @@ restorePage::restorePage()
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
 
-   m_console->notify(false);          /* this should already be off */
-   m_closeable = true;
+   m_console->notify(m_conn, false);          /* this should already be off */
 
    connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), 
            this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int)));
@@ -69,7 +62,7 @@ restorePage::restorePage()
    connect(actionUnMark, SIGNAL(triggered()), this, SLOT(unmarkButtonPushed()));
 
    setFont(m_console->get_font());
-   m_console->displayToPrompt();
+   m_console->displayToPrompt(m_conn);
 
    titles << tr("Mark") << tr("File") << tr("Mode") << tr("User") 
           << tr("Group") << tr("Size") << tr("Date");
@@ -78,10 +71,14 @@ restorePage::restorePage()
    get_cwd();
 
    readSettings();
+   /* wait was entered from pre-restore 
+    * will exit, but will reenter in fillDirectory */
+   mainWin->waitExit();
    fillDirectory();
    dockPage();
    setCurrent();
    this->show();
+   if (mainWin->m_miscDebug) Pmsg0(000, "Leave restorePage\n");
 }
 
 restorePage::~restorePage()
@@ -94,6 +91,7 @@ restorePage::~restorePage()
  */
 void restorePage::fillDirectory()
 {
+   mainWin->waitEnter();
    char modes[20], user[20], group[20], size[20], date[30];
    char marked[10];
    int pnl, fnl;
@@ -101,15 +99,19 @@ void restorePage::fillDirectory()
    POOLMEM *path = get_pool_memory(PM_FNAME);
 
    fileWidget->clear();
-   m_console->write_dir("dir");
+   m_console->write_dir(m_conn, "dir", false);
    QList<QTreeWidgetItem *> treeItemList;
    QStringList item;
-   while (m_console->read() > 0) {
-      char *p = m_console->msg();
+   m_rx.setPattern("has no children\\.$");
+   bool first = true;
+   while (m_console->read(m_conn) > 0) {
+      char *p = m_console->msg(m_conn);
       char *l;
       strip_trailing_junk(p);
-      if (*p == '$' || !*p) {
-         continue;
+      if (*p == '$' || !*p) { continue; }
+      if (first) {
+         if (m_rx.indexIn(QString(p)) != -1) { continue; }
+         first = false;
       }
       l = p;
       skip_nonspaces(&p);             /* permissions */
@@ -172,6 +174,7 @@ void restorePage::fillDirectory()
 
    free_pool_memory(file);
    free_pool_memory(path);
+   mainWin->waitExit();
 }
 
 /*
@@ -183,25 +186,17 @@ void restorePage::addDirectory(QString &newdirr)
    QString newdir = newdirr;
    QString fullpath = m_cwd + newdirr;
    bool ok = true;
-   bool windrive = false;
 
    if (mainWin->m_miscDebug) {
       QString msg = QString(tr("In addDirectory cwd \"%1\" newdir \"%2\" fullpath \"%3\"\n"))
                     .arg(m_cwd)
                     .arg(newdir)
                     .arg(fullpath);
-      Pmsg0(000, msg.toUtf8().data());
+      Pmsg1(dbglvl, "%s\n", msg.toUtf8().data());
    }
 
-   if (isWin32Path(newdir)) {
-      /* this is a windows drive */
-      if (mainWin->m_miscDebug) {
-         Pmsg0(000, "Found windows drive\n");
-      }
-      windrive = true;
-   }
-   
-   if (windrive) {
+   if (isWin32Path(fullpath)) {
+      if (mainWin->m_miscDebug) Pmsg0(dbglvl, "Windows drive\n");
       if (fullpath.left(1) == "/") {
          fullpath.replace(0, 1, "");           /* strip leading / */
       }
@@ -211,7 +206,7 @@ void restorePage::addDirectory(QString &newdirr)
          item->setIcon(0,QIcon(QString::fromUtf8(":images/folder.png")));
          item->setText(0, fullpath.toUtf8().data());
          if (mainWin->m_miscDebug) {
-            Pmsg1(000, "Pre Inserting %s\n",fullpath.toUtf8().data());
+            Pmsg1(dbglvl, "Pre Inserting %s\n",fullpath.toUtf8().data());
          }
          m_dirPaths.insert(fullpath, item);
          m_dirTreeItems.insert(item, fullpath);
@@ -226,7 +221,7 @@ void restorePage::addDirectory(QString &newdirr)
          QString text("/");
          item->setText(0, text.toUtf8().data());
          if (mainWin->m_miscDebug) {
-            Pmsg1(000, "Pre Inserting %s\n",text.toUtf8().data());
+            Pmsg1(dbglvl, "Pre Inserting %s\n",text.toUtf8().data());
          }
          m_dirPaths.insert(text, item);
          m_dirTreeItems.insert(item, text);
@@ -236,10 +231,11 @@ void restorePage::addDirectory(QString &newdirr)
    /* Does it already exist ?? */
    if (!m_dirPaths.contains(fullpath)) {
       QTreeWidgetItem *item = NULL;
-      if (windrive) {
+      if (isWin32Path(fullpath)) {
          /* this is the base widget */
          item = new QTreeWidgetItem(directoryWidget);
          item->setText(0, fullpath.toUtf8().data());
+         if (mainWin->m_miscDebug) Pmsg1(dbglvl, "Windows: %s\n", fullpath.toUtf8().data());
          item->setIcon(0,QIcon(QString::fromUtf8(":images/folder.png")));
       } else {
          QTreeWidgetItem *parent = m_dirPaths.value(m_cwd);
@@ -249,20 +245,23 @@ void restorePage::addDirectory(QString &newdirr)
             item->setText(0, newdir.toUtf8().data());
             item->setIcon(0,QIcon(QString::fromUtf8(":images/folder.png")));
             directoryWidget->expandItem(parent);
+            if (mainWin->m_miscDebug) {
+               Pmsg1(dbglvl, "%s\n", newdir.toUtf8().data());
+            }
          } else {
             ok = false;
             if (mainWin->m_miscDebug) {
                QString msg = QString(tr("In else of if parent cwd \"%1\" newdir \"%2\"\n"))
                     .arg(m_cwd)
                     .arg(newdir);
-               Pmsg0(000, msg.toUtf8().data());
+               Pmsg1(dbglvl, "%s\n", msg.toUtf8().data());
             }
          }
       }
       /* insert into both forward and reverse hash */
       if (ok) {
          if (mainWin->m_miscDebug) {
-            Pmsg1(000, "Inserting %s\n",fullpath.toUtf8().data());
+            Pmsg1(dbglvl, "Inserting %s\n",fullpath.toUtf8().data());
          }
          m_dirPaths.insert(fullpath, item);
          m_dirTreeItems.insert(item, fullpath);
@@ -279,7 +278,7 @@ void restorePage::directoryItemChanged(QTreeWidgetItem *currentitem,
 {
    QString fullpath = m_dirTreeItems.value(currentitem);
    statusLine->setText("");
-   if (fullpath != ""){
+   if (fullpath != "") {
       cwd(fullpath.toUtf8().data());
       fillDirectory();
    }
@@ -287,10 +286,9 @@ void restorePage::directoryItemChanged(QTreeWidgetItem *currentitem,
 
 void restorePage::okButtonPushed()
 {
-// printf("In restorePage::okButtonPushed\n");
    this->hide();
-   m_console->write("done");
-   m_console->notify(true);
+   m_console->write(m_conn, "done");
+   m_console->notify(m_conn, true);
    setConsoleCurrent();
    closeStackPage();
    mainWin->resetFocus();
@@ -300,11 +298,11 @@ void restorePage::okButtonPushed()
 void restorePage::cancelButtonPushed()
 {
    this->hide();
-   m_console->write("quit");
-   m_console->displayToPrompt();
+   m_console->write(m_conn, "quit");
+   m_console->displayToPrompt(m_conn);
    mainWin->set_status(tr("Canceled"));
    closeStackPage();
-   m_console->notify(true);
+   m_console->notify(m_conn, true);
    mainWin->resetFocus();
 }
 
@@ -313,6 +311,7 @@ void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
    char cmd[1000];
    statusLine->setText("");
    if (column == 0) {                 /* mark/unmark */
+      mainWin->waitEnter();
       if (item->data(0, Qt::UserRole).toBool()) {
          bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
          item->setIcon(0, QIcon(QString::fromUtf8(":images/unchecked.png")));
@@ -322,12 +321,13 @@ void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
          item->setIcon(0, QIcon(QString::fromUtf8(":images/check.png")));
          item->setData(0, Qt::UserRole, true);
       }
-      m_console->write_dir(cmd);
-      if (m_console->read() > 0) {
-         strip_trailing_junk(m_console->msg());
-         statusLine->setText(m_console->msg());
+      m_console->write_dir(m_conn, cmd, false);
+      if (m_console->read(m_conn) > 0) {
+         strip_trailing_junk(m_console->msg(m_conn));
+         statusLine->setText(m_console->msg(m_conn));
       }
-      m_console->displayToPrompt();
+      m_console->displayToPrompt(m_conn);
+      mainWin->waitExit();
       return;
    }    
    /* 
@@ -337,13 +337,16 @@ void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
    if (item->text(1).endsWith("/")) {
       QString fullpath = m_cwd + item->text(1);
       QTreeWidgetItem *item = m_dirPaths.value(fullpath);
+      if (mainWin->m_miscDebug) {
+         Pmsg1(dbglvl, "%s\n", fullpath.toUtf8().data());
+      }
       if (item) {
          directoryWidget->setCurrentItem(item);
       } else {
          QString msg = QString("DoubleClick else of item column %1 fullpath %2\n")
               .arg(column,10)
               .arg(fullpath);
-         Pmsg0(000, msg.toUtf8().data());
+         if (mainWin->m_miscDebug) Pmsg1(dbglvl, "%s\n", msg.toUtf8().data());
       }
    }
 }
@@ -367,6 +370,7 @@ void restorePage::upButtonPushed()
  */
 void restorePage::markButtonPushed()
 {
+   mainWin->waitEnter();
    QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
    QTreeWidgetItem *item;
    char cmd[1000];
@@ -376,19 +380,19 @@ void restorePage::markButtonPushed()
       count++;
       bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
       item->setIcon(0, QIcon(QString::fromUtf8(":images/check.png")));
-      m_console->write_dir(cmd);
-      if (m_console->read() > 0) {
-         strip_trailing_junk(m_console->msg());
-         statusLine->setText(m_console->msg());
+      m_console->write_dir(m_conn, cmd, false);
+      if (m_console->read(m_conn) > 0) {
+         strip_trailing_junk(m_console->msg(m_conn));
+         statusLine->setText(m_console->msg(m_conn));
       }
-      Dmsg1(100, "cmd=%s\n", cmd);
-      m_console->discardToPrompt();
+      Dmsg1(dbglvl, "cmd=%s\n", cmd);
+      m_console->discardToPrompt(m_conn);
    }
    if (count == 0) {
       mainWin->set_status("Nothing selected, nothing done");
       statusLine->setText("Nothing selected, nothing done");
    }
-      
+   mainWin->waitExit();
 }
 
 /*
@@ -396,6 +400,7 @@ void restorePage::markButtonPushed()
  */
 void restorePage::unmarkButtonPushed()
 {
+   mainWin->waitEnter();
    QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
    QTreeWidgetItem *item;
    char cmd[1000];
@@ -405,19 +410,19 @@ void restorePage::unmarkButtonPushed()
       count++;
       bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
       item->setIcon(0, QIcon(QString::fromUtf8(":images/unchecked.png")));
-      m_console->write_dir(cmd);
-      if (m_console->read() > 0) {
-         strip_trailing_junk(m_console->msg());
-         statusLine->setText(m_console->msg());
+      m_console->write_dir(m_conn, cmd, false);
+      if (m_console->read(m_conn) > 0) {
+         strip_trailing_junk(m_console->msg(m_conn));
+         statusLine->setText(m_console->msg(m_conn));
       }
-      Dmsg1(100, "cmd=%s\n", cmd);
-      m_console->discardToPrompt();
+      Dmsg1(dbglvl, "cmd=%s\n", cmd);
+      m_console->discardToPrompt(m_conn);
    }
    if (count == 0) {
       mainWin->set_status(tr("Nothing selected, nothing done"));
       statusLine->setText(tr("Nothing selected, nothing done"));
    }
-
+   mainWin->waitExit();
 }
 
 /*
@@ -428,20 +433,22 @@ bool restorePage::cwd(const char *dir)
    int stat;
    char cd_cmd[MAXSTRING];
 
+   mainWin->waitEnter();
    statusLine->setText("");
    bsnprintf(cd_cmd, sizeof(cd_cmd), "cd \"%s\"", dir);
-   Dmsg2(100, "dir=%s cmd=%s\n", dir, cd_cmd);
-   m_console->write_dir(cd_cmd);
+   Dmsg2(dbglvl, "dir=%s cmd=%s\n", dir, cd_cmd);
+   m_console->write_dir(m_conn, cd_cmd, false);
    lineEdit->clear();
-   if ((stat = m_console->read()) > 0) {
-      m_cwd = m_console->msg();
+   if ((stat = m_console->read(m_conn)) > 0) {
+      m_cwd = m_console->msg(m_conn);
       lineEdit->insert(m_cwd);
-      Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
+      Dmsg2(dbglvl, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg(m_conn));
    } else {
-      Dmsg1(000, "stat=%d\n", stat);
+      Dmsg1(dbglvl, "stat=%d\n", stat);
       QMessageBox::critical(this, "Error", tr("cd command failed"), QMessageBox::Ok);
    }
-   m_console->discardToPrompt();
+   m_console->discardToPrompt(m_conn);
+   mainWin->waitExit();
    return true;  /* ***FIXME*** return real status */
 }
 
@@ -451,16 +458,18 @@ bool restorePage::cwd(const char *dir)
 char *restorePage::get_cwd()
 {
    int stat;
-   m_console->write_dir(".pwd");
-   Dmsg0(100, "send: .pwd\n");
-   if ((stat = m_console->read()) > 0) {
-      m_cwd = m_console->msg();
-      Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
+   mainWin->waitEnter();
+   m_console->write_dir(m_conn, ".pwd", false);
+   Dmsg0(dbglvl, "send: .pwd\n");
+   if ((stat = m_console->read(m_conn)) > 0) {
+      m_cwd = m_console->msg(m_conn);
+      Dmsg2(dbglvl, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg(m_conn));
    } else {
-      Dmsg1(000, "Something went wrong read stat=%d\n", stat);
+      Dmsg1(dbglvl, "Something went wrong read stat=%d\n", stat);
       QMessageBox::critical(this, "Error", tr(".pwd command failed"), QMessageBox::Ok);
    }
-   m_console->discardToPrompt(); 
+   m_console->discardToPrompt(m_conn); 
+   mainWin->waitExit();
    return m_cwd.toUtf8().data();
 }
 
@@ -471,7 +480,7 @@ void restorePage::writeSettings()
 {
    QSettings settings(m_console->m_dir->name(), "bat");
    settings.beginGroup("RestorePage");
-   settings.setValue("splitterSizes", splitter->saveState());
+   settings.setValue(m_splitText, splitter->saveState());
    settings.endGroup();
 }
 
@@ -480,8 +489,11 @@ void restorePage::writeSettings()
  */
 void restorePage::readSettings()
 {
+   m_splitText = "splitterSizes_2";
    QSettings settings(m_console->m_dir->name(), "bat");
    settings.beginGroup("RestorePage");
-   splitter->restoreState(settings.value("splitterSizes").toByteArray());
+   if (settings.contains(m_splitText)) { 
+      splitter->restoreState(settings.value(m_splitText).toByteArray());
+   }
    settings.endGroup();
 }