#include "bat.h"
#include "restore.h"
-restoreDialog::restoreDialog(Console *console )
+restorePage::restorePage(Console *console)
{
QStringList titles;
- m_console = console;
+ setupUi(this);
+ QTreeWidgetItem *parent = mainWin->getFromHash(console);
+ if (!parent) {
+ /* Make this a user configurable stdout msg *** FIXME ****/
+ printf("Error retrieving tree widget.");
+ return;
+ }
+ m_name = "Restore";
+ pgInitialize(parent);
m_console->notify(false); /* this should already be off */
+ m_closeable = true;
- setupUi(this);
connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int)));
connect(directoryWidget, SIGNAL(
connect(upButton, SIGNAL(pressed()), this, SLOT(upButtonPushed()));
connect(markButton, SIGNAL(pressed()), this, SLOT(markButtonPushed()));
connect(unmarkButton, SIGNAL(pressed()), this, SLOT(unmarkButtonPushed()));
+ connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
+ connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
setFont(m_console->get_font());
m_console->displayToPrompt();
-
titles << "Mark" << "File" << "Mode" << "User" << "Group" << "Size" << "Date";
fileWidget->setHeaderLabels(titles);
get_cwd();
+
+ //QString root("");
+ //addDirectory(root);
fillDirectory();
+ dockPage();
+ setCurrent();
this->show();
}
/*
* Fill the fileWidget box with the contents of the current directory
*/
-void restoreDialog::fillDirectory()
+void restorePage::fillDirectory()
{
char modes[20], user[20], group[20], size[20], date[30];
char marked[10];
* 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)
+void restorePage::addDirectory(QString &newdirr)
{
- QString fullpath ;
+ QString newdir = newdirr;
+ QString fullpath = m_cwd + newdirr;
+ QRegExp regex("^/[a-z]:/$");
+ bool ok=true;
- /* if this is the base dir, strip off the leading "/" */
- if (m_cwd == "/"){
- fullpath = newdir;
- } else {
- fullpath = m_cwd + newdir;
+ //printf("In addDirectory cwd \"%s\" newdir \"%s\"\n", m_cwd.toUtf8().data(),
+ //newdir.toUtf8().data());
+
+ /* add unix '/' directory first */
+ if (m_dirPaths.empty() && (regex.indexIn(fullpath,0) == -1)) {
+ QTreeWidgetItem *item = new QTreeWidgetItem(directoryWidget);
+ QString text("/");
+ item->setText(0, text.toUtf8().data());
+ //printf("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 c:/\n");
+ fullpath.replace(0,1,"");
}
+
/* 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());
+ item->setText(0, fullpath.toUtf8().data());
} else {
QTreeWidgetItem *parent = m_dirPaths.value(m_cwd);
if (parent) {
item = new QTreeWidgetItem(parent);
item->setText(0, newdir.toUtf8().data());
directoryWidget->expandItem(parent);
+ } else {
+ ok=false;
+ //printf("In else of if parent cwd \"%s\" newdir \"%s\"\n",
+ //m_cwd.toUtf8().data() ,newdir.toUtf8().data());
}
}
/* insert into both forward and reverse hash */
- m_dirPaths.insert(fullpath, item);
- m_dirTreeItems.insert(item, fullpath);
+ if (ok) {
+ //printf("Inserting %s\n",fullpath.toUtf8().data());
+ 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,
+void restorePage::directoryItemChanged(QTreeWidgetItem *currentitem,
QTreeWidgetItem * /*previousitem*/)
{
QString fullpath = m_dirTreeItems.value(currentitem);
}
}
-void restoreDialog::accept()
+void restorePage::okButtonPushed()
{
this->hide();
m_console->write("done");
m_console->notify(true);
- delete this;
+ closeStackPage();
mainWin->resetFocus();
}
-void restoreDialog::reject()
+void restorePage::cancelButtonPushed()
{
this->hide();
m_console->write("quit");
mainWin->set_status("Canceled");
- delete this;
+ closeStackPage();
m_console->notify(true);
mainWin->resetFocus();
}
-void restoreDialog::fileDoubleClicked(QTreeWidgetItem *item, int column)
+void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
{
char cmd[1000];
if (column == 0) { /* mark/unmark */
*/
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);
+ } else {
+ /* FIXME ***** Create an error log */
+ //printf("DoubleClick else of item column %i fullpath %s\n", column, fullpath.toUtf8().data());
}
}
}
* If up button pushed, making the parent tree widget current will call fill
* directory.
*/
-void restoreDialog::upButtonPushed()
+void restorePage::upButtonPushed()
{
cwd("..");
QTreeWidgetItem *item = m_dirPaths.value(m_cwd);
/*
* Mark selected items
*/
-void restoreDialog::markButtonPushed()
+void restorePage::markButtonPushed()
{
QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
QTreeWidgetItem *item;
/*
* Unmark selected items
*/
-void restoreDialog::unmarkButtonPushed()
+void restorePage::unmarkButtonPushed()
{
QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
QTreeWidgetItem *item;
/*
* Change current working directory
*/
-bool restoreDialog::cwd(const char *dir)
+bool restorePage::cwd(const char *dir)
{
int stat;
char cd_cmd[MAXSTRING];
/*
* Return cwd when in tree restore mode
*/
-char *restoreDialog::get_cwd()
+char *restorePage::get_cwd()
{
int stat;
m_console->write_dir(".pwd");