#############################################################################
# Makefile for building: bat
-# Generated by qmake (2.01a) (Qt 4.2.1) on: Tue Feb 27 17:51:23 2007
+# Generated by qmake (2.01a) (Qt 4.2.1) on: Mon Mar 5 09:37:46 2007
# Project: bat.pro
# Template: app
# Command: /usr/bin/qmake -unix -o Makefile bat.pro
qstd.cpp \
console/authenticate.cpp \
console/console.cpp \
+ restore/prerestore.cpp \
restore/restore.cpp \
restore/brestore.cpp \
label/label.cpp \
obj/qstd.o \
obj/authenticate.o \
obj/console.o \
+ obj/prerestore.o \
obj/restore.o \
obj/brestore.o \
obj/label.o \
dist:
@$(CHK_DIR_EXISTS) obj/bat1.0.0 || $(MKDIR) obj/bat1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/bat1.0.0/ && $(COPY_FILE) --parents mainwin.h bat.h bat_conf.h qstd.h console/console.h restore/restore.h label/label.h run/run.h obj/bat1.0.0/ && $(COPY_FILE) --parents main.qrc obj/bat1.0.0/ && $(COPY_FILE) --parents main.cpp bat_conf.cpp mainwin.cpp qstd.cpp console/authenticate.cpp console/console.cpp restore/restore.cpp restore/brestore.cpp label/label.cpp run/run.cpp obj/bat1.0.0/ && $(COPY_FILE) --parents main.ui label/label.ui console/console.ui restore/restore.ui restore/prerestore.ui restore/brestore.ui run/run.ui obj/bat1.0.0/ && (cd `dirname obj/bat1.0.0` && $(TAR) bat1.0.0.tar bat1.0.0 && $(COMPRESS) bat1.0.0.tar) && $(MOVE) `dirname obj/bat1.0.0`/bat1.0.0.tar.gz . && $(DEL_FILE) -r obj/bat1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/bat1.0.0/ && $(COPY_FILE) --parents mainwin.h bat.h bat_conf.h qstd.h console/console.h restore/restore.h label/label.h run/run.h obj/bat1.0.0/ && $(COPY_FILE) --parents main.qrc obj/bat1.0.0/ && $(COPY_FILE) --parents main.cpp bat_conf.cpp mainwin.cpp qstd.cpp console/authenticate.cpp console/console.cpp restore/prerestore.cpp restore/restore.cpp restore/brestore.cpp label/label.cpp run/run.cpp obj/bat1.0.0/ && $(COPY_FILE) --parents main.ui label/label.ui console/console.ui restore/restore.ui restore/prerestore.ui restore/brestore.ui run/run.ui obj/bat1.0.0/ && (cd `dirname obj/bat1.0.0` && $(TAR) bat1.0.0.tar bat1.0.0 && $(COMPRESS) bat1.0.0.tar) && $(MOVE) `dirname obj/bat1.0.0`/bat1.0.0.tar.gz . && $(DEL_FILE) -r obj/bat1.0.0
yaccclean:
ui_console.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/console.o console/console.cpp
+obj/prerestore.o: restore/prerestore.cpp bat.h \
+ mainwin.h \
+ ui_main.h \
+ label/label.h \
+ ui_label.h \
+ run/run.h \
+ ui_run.h \
+ restore/restore.h \
+ ui_brestore.h \
+ ui_restore.h \
+ ui_prerestore.h \
+ bat_conf.h \
+ qstd.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/prerestore.o restore/prerestore.cpp
+
obj/restore.o: restore/restore.cpp bat.h \
mainwin.h \
ui_main.h \
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2007-2007 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.
extern MainWin *mainWin;
extern QApplication *app;
+extern bool commDebug;
int bvsnprintf(char *str, int32_t size, const char *format, va_list ap);
# Restore
HEADERS += restore/restore.h
-SOURCES += restore/restore.cpp restore/brestore.cpp
+SOURCES += restore/prerestore.cpp restore/restore.cpp restore/brestore.cpp
# Label dialog
HEADERS += label/label.h
m_notifier = new QSocketNotifier(m_sock->fd, QSocketNotifier::Read, 0);
QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int)));
+ write(".api");
+ discardToPrompt();
+
beginNewCommand();
job_list = get_list(".jobs");
client_list = get_list(".clients");
list << msg();
}
setEnabled(true);
- list.sort();
+// list.sort();
return list;
}
void Console::write_dir(const char *msg)
{
if (m_sock) {
- m_at_prompt = false;
mainWin->set_status(_("Processing command ..."));
QApplication::setOverrideCursor(Qt::WaitCursor);
- m_sock->msglen = strlen(msg);
- pm_strcpy(&m_sock->msg, msg);
- m_sock->send();
+ write(msg);
} else {
mainWin->set_status(" Director not connected. Click on connect button.");
mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
{
m_sock->msglen = strlen(msg);
pm_strcpy(&m_sock->msg, msg);
+ m_at_prompt = false;
+ if (commDebug) Pmsg1(000, "send: %s\n", msg);
return m_sock->send();
}
*/
void Console::beginNewCommand()
{
-// displayToPrompt();
write(".\n");
while (read() > 0) {
}
void Console::displayToPrompt()
{
- while (read() > 0) {
+ int stat;
+ if (commDebug) Pmsg0(000, "DisplaytoPrompt\n");
+ m_notifier->setEnabled(false);
+ while ((stat = read()) > 0) {
display_text(msg());
}
+ if (commDebug) Pmsg1(000, "endDisplaytoPrompt=%d\n", stat);
+ m_notifier->setEnabled(true);
+}
+void Console::discardToPrompt()
+{
+ int stat;
+ if (commDebug) Pmsg0(000, "discardToPrompt\n");
+ m_notifier->setEnabled(false);
+ while ((stat = read()) > 0) {
+ }
+ if (commDebug) Pmsg1(000, "endDisplayToPrompt=%d\n", stat);
+ m_notifier->setEnabled(true);
}
+
/*
- * Blocking read from director */
+ * Blocking read from director
+ */
int Console::read()
{
- int stat;
- if (m_sock) {
+ int stat = BNET_HARDEOF;
+ while (m_sock) {
for (;;) {
stat = bnet_wait_data_intr(m_sock, 1);
if (stat > 0) {
break;
}
app->processEvents();
- if (stat < 0) {
- return BNET_ERROR;
+ }
+ stat = m_sock->recv();
+ if (stat >= 0) {
+ if (m_at_prompt) {
+ display_text("\n");
+ m_at_prompt = false;
+ }
+ if (commDebug) Pmsg1(000, "got: %s", m_sock->msg);
+
+ }
+ switch (m_sock->msglen) {
+ case BNET_CMD_BEGIN:
+ m_at_prompt = false;
+ continue;
+ case BNET_PROMPT:
+ case BNET_CMD_OK:
+ if (commDebug) Pmsg0(000, "CMD OK/PROMPT\n");
+ m_at_prompt = true;
+ mainWin->set_status(_("At prompt waiting for input ..."));
+ update_cursor();
+ QApplication::restoreOverrideCursor();
+ break;
+ case BNET_CMD_FAILED:
+ if (commDebug) Pmsg0(000, "CMD FAIL\n");
+ m_at_prompt = true;
+ mainWin->set_status(_("Command failed. At prompt waiting for input ..."));
+ update_cursor();
+ QApplication::restoreOverrideCursor();
+ break;
+ case BNET_EOD:
+ if (commDebug) Pmsg0(000, "EOD\n");
+ mainWin->set_status_ready();
+ update_cursor();
+ QApplication::restoreOverrideCursor();
+ if (!m_api_set) {
+ break;
}
+ continue;
}
- return m_sock->recv();
+ if (is_bnet_stop(m_sock)) { /* error or term request */
+ m_sock->close();
+ m_sock = NULL;
+ mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
+ QBrush redBrush(Qt::red);
+ m_consoleItem->setForeground(0, redBrush);
+ m_notifier->setEnabled(false);
+ delete m_notifier;
+ m_notifier = NULL;
+ mainWin->set_status(_("Director disconnected."));
+ QApplication::restoreOverrideCursor();
+ }
+ break;
}
- return BNET_HARDEOF;
+ return stat;
}
/* Called by signal when the Director has output for us */
int stat;
(void)fd;
- if (!m_sock) {
- return;
- }
+ if (commDebug) Pmsg0(000, "read_dir\n");
stat = read();
if (stat >= 0) {
- if (m_at_prompt) {
- display_text("\n");
- m_at_prompt = false;
- }
display_text(msg());
- return;
}
- if (is_bnet_stop(m_sock)) { /* error or term request */
- m_sock->close();
- m_sock = NULL;
- mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
- QBrush redBrush(Qt::red);
- m_consoleItem->setForeground(0, redBrush);
- m_notifier->setEnabled(false);
- delete m_notifier;
- m_notifier = NULL;
- mainWin->set_status(_("Director disconnected."));
- QApplication::restoreOverrideCursor();
- return;
- }
- /* Must be a signal -- either do something or ignore it */
- if (m_sock->msglen == BNET_PROMPT) {
- m_at_prompt = true;
- mainWin->set_status(_("At prompt waiting for input ..."));
- update_cursor();
- }
- if (m_sock->msglen == BNET_EOD) {
- mainWin->set_status_ready();
- update_cursor();
- }
- return;
}
void terminate();
void beginNewCommand();
void displayToPrompt();
+ void discardToPrompt();
QStringList job_list;
QStringList client_list;
QSocketNotifier *m_notifier;
QTextCursor *m_cursor;
QTreeWidgetItem *m_consoleItem;
+ bool m_api_set;
};
#endif /* _CONSOLE_H_ */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2007-2007 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.
*
* Main program for bat (qt-console)
*
- * Kern Sibbald, January MMVI
+ * Kern Sibbald, January MMVII
*
*/
MainWin *mainWin;
QApplication *app;
+bool commDebug = false;
int main(int argc, char *argv[])
*
* Main Window control for bat (qt-console)
*
- * Kern Sibbald, January MMVI
+ * Kern Sibbald, January MMVII
*
*/
m_console = new Console(stackedWidget);
stackedWidget->setCurrentIndex(0);
- lineEdit->setFocus();
+ resetFocus();
createConnections();
m_console->connect();
}
+void MainWin::resetFocus()
+{
+ lineEdit->setFocus();
+}
+
void MainWin::createConnections()
{
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2007-2007 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.
*
* qt-console main window class definition.
*
- * Written by Kern Sibbald, January MMVI
+ * Written by Kern Sibbald, January MMVII
*/
#ifndef _MAINWIN_H_
void set_status(const char *buf);
void writeSettings();
void readSettings();
+ void resetFocus();
public slots:
void input_line();
--- /dev/null
+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2007-2007 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.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
+
+/*
+ * Version $Id: restore.cpp 4307 2007-03-04 10:24:39Z kerns $
+ *
+ * preRestore -> dialog put up to determine the restore type
+ *
+ * Kern Sibbald, February MMVII
+ *
+ */
+
+#include "bat.h"
+#include "restore.h"
+
+
+prerestoreDialog::prerestoreDialog(Console *console)
+{
+ m_console = console; /* keep compiler quiet */
+ setupUi(this);
+ jobCombo->addItems(console->job_list);
+ filesetCombo->addItems(console->fileset_list);
+ clientCombo->addItems(console->client_list);
+ poolCombo->addItems(console->pool_list);
+ storageCombo->addItems(console->storage_list);
+ job_name_change(0);
+ connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
+
+ this->show();
+}
+
+void prerestoreDialog::accept()
+{
+ QString cmd;
+
+ this->hide();
+
+ cmd = QString(
+ "restore select current fileset=\"%1\" client=\"%2\" pool=\"%3\" "
+ "storage=\"%4\"\n")
+ .arg(filesetCombo->currentText())
+ .arg(clientCombo->currentText())
+ .arg(poolCombo->currentText())
+ .arg(storageCombo->currentText());
+
+ m_console->write(cmd);
+ m_console->display_text(cmd);
+ new restoreDialog(m_console);
+ delete this;
+}
+
+
+void prerestoreDialog::reject()
+{
+ mainWin->set_status("Canceled");
+ this->hide();
+ delete this;
+}
+
+
+void prerestoreDialog::job_name_change(int index)
+{
+ job_defaults job_defs;
+
+ (void)index;
+ job_defs.job_name = jobCombo->currentText();
+ if (m_console->get_job_defaults(job_defs)) {
+ filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
+ clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
+ poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
+ storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
+ }
+}
*
* Restore Class
*
- * Kern Sibbald, February MMVI
+ * Kern Sibbald, February MMVII
*
*/
#include "bat.h"
#include "restore.h"
-
-prerestoreDialog::prerestoreDialog(Console *console)
-{
- m_console = console; /* keep compiler quiet */
- setupUi(this);
- jobCombo->addItems(console->job_list);
- filesetCombo->addItems(console->fileset_list);
- clientCombo->addItems(console->client_list);
- poolCombo->addItems(console->pool_list);
- storageCombo->addItems(console->storage_list);
- job_name_change(0);
- connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
-
- this->show();
-}
-
-void prerestoreDialog::accept()
-{
- QString cmd;
-
- this->hide();
-
- cmd = QString(
- "restore select current fileset=\"%1\" client=\"%2\" pool=\"%3\" "
- "storage=\"%4\"\n")
- .arg(filesetCombo->currentText())
- .arg(clientCombo->currentText())
- .arg(poolCombo->currentText())
- .arg(storageCombo->currentText());
-
- m_console->write(cmd);
- m_console->display_text(cmd);
- new restoreDialog(m_console);
- delete this;
-}
-
-
-void prerestoreDialog::reject()
-{
- mainWin->set_status("Canceled");
- this->hide();
- delete this;
-}
-
-
-void prerestoreDialog::job_name_change(int index)
-{
- job_defaults job_defs;
-
- (void)index;
- job_defs.job_name = jobCombo->currentText();
- if (m_console->get_job_defaults(job_defs)) {
- filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
- clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
- poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
- storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
- }
-}
-
restoreDialog::restoreDialog(Console *console)
{
m_console = console;
+
+ m_console->setEnabled(false);
setupUi(this);
connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int)));
setFont(m_console->get_font());
- fillDirectory("/home/kern/bacula/k");
+ m_console->displayToPrompt();
+ fillDirectory();
this->show();
}
/*
- * Fill the CList box with files at path
+ * Fill the fileWidget box with the contents of the current directory
*/
-void restoreDialog::fillDirectory(const char *dir)
+void restoreDialog::fillDirectory()
{
- char pathbuf[MAXSTRING];
+ char cd_cmd[MAXSTRING];
char modes[20], user[20], group[20], size[20], date[30];
char marked[10];
int pnl, fnl;
POOLMEM *file = get_pool_memory(PM_FNAME);
POOLMEM *path = get_pool_memory(PM_FNAME);
-
- m_console->setEnabled(false);
- m_fname = dir;
-
-
- m_console->displayToPrompt();
- bsnprintf(pathbuf, sizeof(pathbuf), "cd %s", dir);
- Dmsg1(100, "%s\n", pathbuf);
-
QStringList titles;
+
titles << "Mark" << "File" << "Mode" << "User" << "Group" << "Size" << "Date";
fileWidget->setHeaderLabels(titles);
- m_console->write(pathbuf);
- m_console->display_text(pathbuf);
- m_console->displayToPrompt();
-
- m_console-> write_dir("dir");
- m_console->display_text("dir");
+ char *dir = get_cwd();
+ bsnprintf(cd_cmd, sizeof(cd_cmd), "cd \"%s\"\n", dir);
+ Dmsg2(100, "dir=%s cmd=%s\n", dir, cd_cmd);
+ m_console->write_dir(cd_cmd);
+ m_console->discardToPrompt();
+ m_console->write_dir("dir");
QList<QTreeWidgetItem *> items;
QStringList item;
while (m_console->read() > 0) {
char *p = m_console->msg();
char *l;
strip_trailing_junk(p);
- if (*p == '$') {
- break;
- }
- if (!*p) {
+ if (*p == '$' || !*p) {
continue;
}
l = p;
bstrncpy(date, l, sizeof(date));
skip_spaces(&p);
if (*p == '*') {
- bstrncpy(marked, "x", sizeof(marked));
+ bstrncpy(marked, "*", sizeof(marked));
p++;
} else {
bstrncpy(marked, " ", sizeof(marked));
fileWidget->clear();
fileWidget->insertTopLevelItems(0, items);
- m_console->setEnabled(true);
free_pool_memory(file);
free_pool_memory(path);
}
this->hide();
m_console->write("done");
delete this;
+ m_console->setEnabled(true);
+ mainWin->resetFocus();
}
m_console->write("quit");
mainWin->set_status("Canceled");
delete this;
+ m_console->setEnabled(true);
+ mainWin->resetFocus();
}
void restoreDialog::fileDoubleClicked(QTreeWidgetItem *item, int column)
{
- printf("Text=%s column=%d\n", item->text(1).toUtf8().data(), column);
+ char cmd[1000];
+// printf("cwd=%s Text=%s column=%d\n", m_cwd.toUtf8().data(),
+// item->text(1).toUtf8().data(), column);
+ if (column == 0) { /* mark/unmark */
+ if (item->text(0) == "*") {
+ bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"\n", item->text(1).toUtf8().data());
+ item->setText(0, " ");
+ } else {
+ bsnprintf(cmd, sizeof(cmd), "mark \"%s\"\n", item->text(1).toUtf8().data());
+ item->setText(0, "*");
+ }
+ m_console->write(cmd);
+// printf("cmd=%s", cmd);
+ m_console->displayToPrompt();
+ return;
+ }
+}
+
+/*
+ * Return cwd when in tree restore mode
+ */
+char *restoreDialog::get_cwd()
+{
+ int stat;
+ m_console->write_dir(".pwd");
+ Dmsg0(100, "send: .pwd\n");
+ if ((stat = m_console->read()) > 0) {
+ m_cwd = m_console->msg();
+ Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
+ } else {
+ Dmsg1(000, "stat=%d\n", stat);
+ }
+ m_console->displayToPrompt();
+ return m_cwd.toUtf8().data();
}
public:
prerestoreDialog(Console *parent);
-public slots:
+private slots:
void accept();
void reject();
void job_name_change(int index);
public:
restoreDialog(Console *parent);
- void fillDirectory(const char *path);
+ void fillDirectory();
+ char *get_cwd();
private slots:
void accept();
private:
Console *m_console;
- QString m_fname;
-
+ QString m_cwd;
};
};
-
-
#endif /* _RESTORE_H_ */
<rect>
<x>0</x>
<y>0</y>
- <width>688</width>
+ <width>1196</width>
<height>649</height>
</rect>
</property>
<widget class="QTreeWidget" name="treeWidget" >
<property name="sizePolicy" >
<sizepolicy>
- <hsizetype>5</hsizetype>
+ <hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>1</horstretch>
- <verstretch>0</verstretch>
+ <verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
- <width>0</width>
+ <width>100</width>
<height>0</height>
</size>
</property>