]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/restore/restore.cpp
Convert to pure GPL v2 license.
[bacula/bacula] / bacula / src / qt-console / restore / restore.cpp
index 0f5e75dbe6d7866eb74fe38f5cb673aa9256dd40..f4527e2572ac37d19617014371553e9cec75c421 100644 (file)
@@ -7,8 +7,8 @@
    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
@@ -45,6 +45,9 @@ restorePage::restorePage()
    setupUi(this);
    m_name = "Restore Select";
    pgInitialize();
+   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;
 
@@ -58,6 +61,13 @@ 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();
 
@@ -66,12 +76,18 @@ restorePage::restorePage()
 
    get_cwd();
 
+   readSettings();
    fillDirectory();
    dockPage();
    setCurrent();
    this->show();
 }
 
+restorePage::~restorePage()
+{
+   writeSettings();
+}
+
 /*
  * Fill the fileWidget box with the contents of the current directory
  */
@@ -132,12 +148,19 @@ void restorePage::fillDirectory()
       }
       split_path_and_filename(p, &path, &pnl, &file, &fnl);
       item.clear();
-      item << marked << file << modes << user << group << size << date;
+      item << "" << 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 */
+      if (strcmp(marked, "*") == 0) {
+         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->setData(0, Qt::UserRole, false);
+      }
       treeItemList.append(ti);
    }
    fileWidget->clear();
@@ -162,22 +185,32 @@ void restorePage::addDirectory(QString &newdirr)
    bool ok = true;
    bool windrive = false;
 
-   //printf("In addDirectory cwd \"%s\" newdir \"%s\"\n", m_cwd.toUtf8().data(),
-        //newdir.toUtf8().data());
+   if (mainWin->m_miscDebug) {
+      QString msg = QString("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)) {
       QTreeWidgetItem *item = new QTreeWidgetItem(directoryWidget);
+      item->setIcon(0,QIcon(QString::fromUtf8(":images/folder.svg")));
+      
       QString text("/");
       item->setText(0, text.toUtf8().data());
-      //printf("Pre Inserting %s\n",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) {
       /* this is a windows drive */
-      //printf("Need to do windows \"letter\":/\n");
+      if (mainWin->m_miscDebug) {
+         Pmsg0(000, "Need to do windows \"letter\":/\n");
+      }
       fullpath.replace(0,1,"");
       windrive = true;
    }
@@ -189,22 +222,30 @@ 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.svg")));
       } 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.svg")));
             directoryWidget->expandItem(parent);
          } else {
             ok = false;
-            //printf("In else of if parent cwd \"%s\" newdir \"%s\"\n", 
-               //m_cwd.toUtf8().data() ,newdir.toUtf8().data());
+            if (mainWin->m_miscDebug) {
+               QString msg = QString("In else of if parent cwd \"%1\" newdir \"%2\"\n")
+                    .arg(m_cwd)
+                    .arg(newdir);
+               Pmsg0(000, msg.toUtf8().data());
+            }
          }
       }
       /* insert into both forward and reverse hash */
       if (ok) {
-         //printf("Inserting %s\n",fullpath.toUtf8().data());
+         if (mainWin->m_miscDebug) {
+            Pmsg1(000, "Inserting %s\n",fullpath.toUtf8().data());
+         }
          m_dirPaths.insert(fullpath, item);
          m_dirTreeItems.insert(item, fullpath);
       }
@@ -227,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);
@@ -251,12 +293,14 @@ void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
 {
    char cmd[1000];
    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->setText(0, " ");
+         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->setText(0, "*");
+         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) {
@@ -280,8 +324,10 @@ void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
       if (item) {
          directoryWidget->setCurrentItem(item);
       } else {
-         /* FIXME ***** Create an error log */
-         //printf("DoubleClick else of item column %i fullpath %s\n", column, fullpath.toUtf8().data());
+         QString msg = QString("DoubleClick else of item column %1 fullpath %2\n")
+              .arg(column,10)
+              .arg(fullpath);
+         Pmsg0(000, msg.toUtf8().data());
       }
    }
 }
@@ -309,7 +355,7 @@ void restorePage::markButtonPushed()
    char cmd[1000];
    foreach (item, treeItemList) {
       bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
-      item->setText(0, "*");
+      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());
@@ -330,7 +376,7 @@ void restorePage::unmarkButtonPushed()
    char cmd[1000];
    foreach (item, treeItemList) {
       bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
-      item->setText(0, " ");
+      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());
@@ -383,3 +429,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();
+}