]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/restore/restore.cpp
Update bat restore.cpp
[bacula/bacula] / bacula / src / qt-console / restore / restore.cpp
index 26114225dbe0a8f5e360329d1ef3902d046836e5..305c374ab279afcd405a0e674a6ac458e9b86831 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
+   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.
@@ -43,7 +43,7 @@ restorePage::restorePage()
    QStringList titles;
 
    setupUi(this);
-   m_name = "Restore Select";
+   m_name = tr("Restore Select");
    pgInitialize();
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
@@ -71,7 +71,8 @@ restorePage::restorePage()
    setFont(m_console->get_font());
    m_console->displayToPrompt();
 
-   titles << "Mark" << "File" << "Mode" << "User" << "Group" << "Size" << "Date";
+   titles << tr("Mark") << tr("File") << tr("Mode") << tr("User") 
+          << tr("Group") << tr("Size") << tr("Date");
    fileWidget->setHeaderLabels(titles);
 
    get_cwd();
@@ -181,41 +182,57 @@ void restorePage::addDirectory(QString &newdirr)
 {
    QString newdir = newdirr;
    QString fullpath = m_cwd + newdirr;
-   QRegExp regex("^/[a-z]:/$");
    bool ok = true;
    bool windrive = false;
 
    if (mainWin->m_miscDebug) {
-      QString msg = QString("In addDirectory cwd \"%1\" newdir \"%2\"\n")
+      QString msg = QString(tr("In addDirectory cwd \"%1\" newdir \"%2\" fullpath \"%3\"\n"))
                     .arg(m_cwd)
-                    .arg(newdir);
+                    .arg(newdir)
+                    .arg(fullpath);
       Pmsg0(000, msg.toUtf8().data());
    }
 
-   /* add unix '/' directory first */
-   if (m_dirPaths.empty() && (regex.indexIn(fullpath,0) == -1)) {
-      QTreeWidgetItem *item = new QTreeWidgetItem(directoryWidget);
-      item->setIcon(0,QIcon(QString::fromUtf8(":images/folder.png")));
-      
-      QString text("/");
-      item->setText(0, text.toUtf8().data());
-      if (mainWin->m_miscDebug) {
-         Pmsg1(000, "Pre Inserting %s\n",text.toUtf8().data());
-      }
-      m_dirPaths.insert(text, item);
-      m_dirTreeItems.insert(item, text);
-   }
-
-   if (regex.indexIn(fullpath,0) == 0) {
+   if (isWin32Path(newdir)) {
       /* this is a windows drive */
       if (mainWin->m_miscDebug) {
-         Pmsg0(000, "Need to do windows \"letter\":/\n");
+         Pmsg0(000, "Found windows drive\n");
       }
-      fullpath.replace(0,1,"");
       windrive = true;
    }
+   
+   if (windrive) {
+      if (fullpath.left(1) == "/") {
+         fullpath.replace(0, 1, "");           /* strip leading / */
+      }
+      /* If drive and not already in add it */
+      if (fullpath.length() == 3 && !m_dirPaths.contains(fullpath)) {
+         QTreeWidgetItem *item = new QTreeWidgetItem(directoryWidget);
+         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());
+         }
+         m_dirPaths.insert(fullpath, item);
+         m_dirTreeItems.insert(item, fullpath);
+      }
+   } else {
+      // Unix add / first if not already there 
+      if (m_dirPaths.empty()) {
+         QTreeWidgetItem *item = new QTreeWidgetItem(directoryWidget);
+         item->setIcon(0,QIcon(QString::fromUtf8(":images/folder.png")));
+            
+         QString text("/");
+         item->setText(0, text.toUtf8().data());
+         if (mainWin->m_miscDebug) {
+            Pmsg1(000, "Pre Inserting %s\n",text.toUtf8().data());
+         }
+         m_dirPaths.insert(text, item);
+         m_dirTreeItems.insert(item, text);
+      }
+   }
  
-   /* is it already existent ?? */
+   /* Does it already exist ?? */
    if (!m_dirPaths.contains(fullpath)) {
       QTreeWidgetItem *item = NULL;
       if (windrive) {
@@ -234,7 +251,7 @@ void restorePage::addDirectory(QString &newdirr)
          } else {
             ok = false;
             if (mainWin->m_miscDebug) {
-               QString msg = QString("In else of if parent cwd \"%1\" newdir \"%2\"\n")
+               QString msg = QString(tr("In else of if parent cwd \"%1\" newdir \"%2\"\n"))
                     .arg(m_cwd)
                     .arg(newdir);
                Pmsg0(000, msg.toUtf8().data());
@@ -260,6 +277,7 @@ void restorePage::directoryItemChanged(QTreeWidgetItem *currentitem,
                                          QTreeWidgetItem * /*previousitem*/)
 {
    QString fullpath = m_dirTreeItems.value(currentitem);
+   statusLine->setText("");
    if (fullpath != ""){
       cwd(fullpath.toUtf8().data());
       fillDirectory();
@@ -268,7 +286,7 @@ void restorePage::directoryItemChanged(QTreeWidgetItem *currentitem,
 
 void restorePage::okButtonPushed()
 {
-   printf("In restorePage::okButtonPushed\n");
+// printf("In restorePage::okButtonPushed\n");
    this->hide();
    m_console->write("done");
    m_console->notify(true);
@@ -283,7 +301,7 @@ void restorePage::cancelButtonPushed()
    this->hide();
    m_console->write("quit");
    m_console->displayToPrompt();
-   mainWin->set_status("Canceled");
+   mainWin->set_status(tr("Canceled"));
    closeStackPage();
    m_console->notify(true);
    mainWin->resetFocus();
@@ -292,6 +310,7 @@ void restorePage::cancelButtonPushed()
 void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
 {
    char cmd[1000];
+   statusLine->setText("");
    if (column == 0) {                 /* mark/unmark */
       if (item->data(0, Qt::UserRole).toBool()) {
          bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
@@ -316,10 +335,6 @@ void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
     */
    if (item->text(1).endsWith("/")) {
       QString fullpath = m_cwd + item->text(1);
-      /* check for fullpath = "/c:/" */
-      QRegExp regex("^/[a-z]:/");
-      if (regex.indexIn(fullpath,0) == 0)  /* remove leading '/' */
-         fullpath.replace(0,1,"");
       QTreeWidgetItem *item = m_dirPaths.value(fullpath);
       if (item) {
          directoryWidget->setCurrentItem(item);
@@ -343,6 +358,7 @@ void restorePage::upButtonPushed()
    if (item) {
       directoryWidget->setCurrentItem(item);
    }
+   statusLine->setText("");
 }
 
 /*
@@ -353,7 +369,10 @@ void restorePage::markButtonPushed()
    QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
    QTreeWidgetItem *item;
    char cmd[1000];
+   int count = 0;
+   statusLine->setText("");
    foreach (item, treeItemList) {
+      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);
@@ -364,6 +383,11 @@ void restorePage::markButtonPushed()
       Dmsg1(100, "cmd=%s\n", cmd);
       m_console->discardToPrompt();
    }
+   if (count == 0) {
+      mainWin->set_status("Nothing selected, nothing done");
+      statusLine->setText("Nothing selected, nothing done");
+   }
+      
 }
 
 /*
@@ -374,7 +398,10 @@ void restorePage::unmarkButtonPushed()
    QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
    QTreeWidgetItem *item;
    char cmd[1000];
+   int count = 0;
+   statusLine->setText("");
    foreach (item, treeItemList) {
+      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);
@@ -385,6 +412,11 @@ void restorePage::unmarkButtonPushed()
       Dmsg1(100, "cmd=%s\n", cmd);
       m_console->discardToPrompt();
    }
+   if (count == 0) {
+      mainWin->set_status(tr("Nothing selected, nothing done"));
+      statusLine->setText(tr("Nothing selected, nothing done"));
+   }
+
 }
 
 /*
@@ -395,6 +427,7 @@ bool restorePage::cwd(const char *dir)
    int stat;
    char cd_cmd[MAXSTRING];
 
+   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);
@@ -405,7 +438,7 @@ bool restorePage::cwd(const char *dir)
       Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
    } else {
       Dmsg1(000, "stat=%d\n", stat);
-      QMessageBox::critical(this, "Error", "cd command failed", QMessageBox::Ok);
+      QMessageBox::critical(this, "Error", tr("cd command failed"), QMessageBox::Ok);
    }
    m_console->discardToPrompt();
    return true;  /* ***FIXME*** return real status */
@@ -424,7 +457,7 @@ char *restorePage::get_cwd()
       Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
    } else {
       Dmsg1(000, "Something went wrong read stat=%d\n", stat);
-      QMessageBox::critical(this, "Error", ".pwd command failed", QMessageBox::Ok);
+      QMessageBox::critical(this, "Error", tr(".pwd command failed"), QMessageBox::Ok);
    }
    m_console->discardToPrompt(); 
    return m_cwd.toUtf8().data();