From: Dirk H Bartley Date: Tue, 1 May 2007 03:29:29 +0000 (+0000) Subject: Working directory pane in restore. Will get this into the stack next. X-Git-Tag: Release-7.0.0~6459 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=eb510e78d3329cdc72c1f598f2fbd944cee9135e;p=bacula%2Fbacula Working directory pane in restore. Will get this into the stack next. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4670 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/TODO b/bacula/src/qt-console/TODO index 684b201cae..a219844ec8 100644 --- a/bacula/src/qt-console/TODO +++ b/bacula/src/qt-console/TODO @@ -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. diff --git a/bacula/src/qt-console/restore/restore.cpp b/bacula/src/qt-console/restore/restore.cpp index 7fcf4d089b..928efdd6cd 100644 --- a/bacula/src/qt-console/restore/restore.cpp +++ b/bacula/src/qt-console/restore/restore.cpp @@ -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 items; + QList 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 items = fileWidget->selectedItems(); + QList 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 items = fileWidget->selectedItems(); + QList 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); diff --git a/bacula/src/qt-console/restore/restore.h b/bacula/src/qt-console/restore/restore.h index bc825fc8ea..98305b2d74 100644 --- a/bacula/src/qt-console/restore/restore.h +++ b/bacula/src/qt-console/restore/restore.h @@ -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 m_dirPaths; + QHash m_dirTreeItems; }; diff --git a/bacula/src/qt-console/restore/restore.ui b/bacula/src/qt-console/restore/restore.ui index 4353f2f61f..322ecf2c00 100644 --- a/bacula/src/qt-console/restore/restore.ui +++ b/bacula/src/qt-console/restore/restore.ui @@ -85,7 +85,7 @@ - + 5