]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/restore/restore.cpp
Oops. When I changed the contents of the field earlier, I forgot to make this change
[bacula/bacula] / bacula / src / qt-console / restore / restore.cpp
index 456e511ef88bb1a8aec1eb2841332f3512f78756..a01422c04d98c93cac5ca737826fabd20edb675f 100644 (file)
@@ -1,14 +1,14 @@
 /*
    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.
    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 plus additions
-   that are listed in the file LICENSE.
+   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
@@ -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")));
@@ -61,20 +61,34 @@ restorePage::restorePage()
    connect(unmarkButton, SIGNAL(pressed()), this, SLOT(unmarkButtonPushed()));
    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
+
+   fileWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
+   fileWidget->addAction(actionMark);
+   fileWidget->addAction(actionUnMark);
+   connect(actionMark, SIGNAL(triggered()), this, SLOT(markButtonPushed()));
+   connect(actionUnMark, SIGNAL(triggered()), this, SLOT(unmarkButtonPushed()));
+
    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();
 
+   readSettings();
    fillDirectory();
    dockPage();
    setCurrent();
    this->show();
 }
 
+restorePage::~restorePage()
+{
+   writeSettings();
+}
+
 /*
  * Fill the fileWidget box with the contents of the current directory
  */
@@ -142,9 +156,11 @@ void restorePage::fillDirectory()
       QTreeWidgetItem *ti = new QTreeWidgetItem((QTreeWidget *)0, item);
       ti->setTextAlignment(5, Qt::AlignRight); /* right align size */
       if (strcmp(marked, "*") == 0) {
-         ti->setIcon(0,QIcon(QString::fromUtf8(":images/check.png")));
+         ti->setIcon(0, QIcon(QString::fromUtf8(":images/check.png")));
+         ti->setData(0, Qt::UserRole, true);
       } else {
-         ti->setIcon(0,QIcon(QString::fromUtf8(":images/unchecked.png")));
+         ti->setIcon(0, QIcon(QString::fromUtf8(":images/unchecked.png")));
+         ti->setData(0, Qt::UserRole, false);
       }
       treeItemList.append(ti);
    }
@@ -166,20 +182,21 @@ 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\"\n"))
                     .arg(m_cwd)
                     .arg(newdir);
       Pmsg0(000, msg.toUtf8().data());
    }
 
    /* add unix '/' directory first */
-   if (m_dirPaths.empty() && (regex.indexIn(fullpath,0) == -1)) {
+   if (m_dirPaths.empty() && !isWin32Path(fullpath)) {
       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) {
@@ -189,12 +206,11 @@ void restorePage::addDirectory(QString &newdirr)
       m_dirTreeItems.insert(item, text);
    }
 
-   if (regex.indexIn(fullpath,0) == 0) {
+   if (isWin32Path(fullpath)) {
       /* this is a windows drive */
       if (mainWin->m_miscDebug) {
-         printf("Need to do windows \"letter\":/\n");
+         Pmsg0(000, "Need to do windows \"letter\":/\n");
       }
-      fullpath.replace(0,1,"");
       windrive = true;
    }
  
@@ -205,17 +221,19 @@ void restorePage::addDirectory(QString &newdirr)
          /* this is the base widget */
          item = new QTreeWidgetItem(directoryWidget);
          item->setText(0, fullpath.toUtf8().data());
+         item->setIcon(0,QIcon(QString::fromUtf8(":images/folder.png")));
       } else {
          QTreeWidgetItem *parent = m_dirPaths.value(m_cwd);
          if (parent) {
             /* new directories to add */
             item = new QTreeWidgetItem(parent);
             item->setText(0, newdir.toUtf8().data());
+            item->setIcon(0,QIcon(QString::fromUtf8(":images/folder.png")));
             directoryWidget->expandItem(parent);
          } 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());
@@ -241,6 +259,7 @@ void restorePage::directoryItemChanged(QTreeWidgetItem *currentitem,
                                          QTreeWidgetItem * /*previousitem*/)
 {
    QString fullpath = m_dirTreeItems.value(currentitem);
+   statusLine->setText("");
    if (fullpath != ""){
       cwd(fullpath.toUtf8().data());
       fillDirectory();
@@ -249,6 +268,7 @@ void restorePage::directoryItemChanged(QTreeWidgetItem *currentitem,
 
 void restorePage::okButtonPushed()
 {
+// printf("In restorePage::okButtonPushed\n");
    this->hide();
    m_console->write("done");
    m_console->notify(true);
@@ -263,7 +283,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();
@@ -272,13 +292,16 @@ void restorePage::cancelButtonPushed()
 void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
 {
    char cmd[1000];
+   statusLine->setText("");
    if (column == 0) {                 /* mark/unmark */
-      if (item->text(0) == "*") {
+      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")));
+         item->setData(0, Qt::UserRole, false);
       } else {
          bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
          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) {
@@ -294,10 +317,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);
@@ -321,6 +340,7 @@ void restorePage::upButtonPushed()
    if (item) {
       directoryWidget->setCurrentItem(item);
    }
+   statusLine->setText("");
 }
 
 /*
@@ -331,7 +351,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);
@@ -342,6 +365,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");
+   }
+      
 }
 
 /*
@@ -352,7 +380,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);
@@ -363,6 +394,11 @@ void restorePage::unmarkButtonPushed()
       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");
+   }
+
 }
 
 /*
@@ -373,6 +409,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);
@@ -407,3 +444,25 @@ char *restorePage::get_cwd()
    m_console->discardToPrompt(); 
    return m_cwd.toUtf8().data();
 }
+
+/*
+ * Save user settings associated with this page
+ */
+void restorePage::writeSettings()
+{
+   QSettings settings(m_console->m_dir->name(), "bat");
+   settings.beginGroup("RestorePage");
+   settings.setValue("splitterSizes", splitter->saveState());
+   settings.endGroup();
+}
+
+/*
+ * Read and restore user settings associated with this page
+ */
+void restorePage::readSettings()
+{
+   QSettings settings(m_console->m_dir->name(), "bat");
+   settings.beginGroup("RestorePage");
+   splitter->restoreState(settings.value("splitterSizes").toByteArray());
+   settings.endGroup();
+}