/*
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.
*/
/*
+ * Version $Id$
+ *
* Main Window control for bat (qt-console)
*
- * Kern Sibbald, January MMVI
+ * Kern Sibbald, January MMVII
*
*/
MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
{
+
mainWin = this;
setupUi(this); /* Setup UI defined by main.ui (designer) */
- m_console = new Console(stackedWidget);
- stackedWidget->setCurrentIndex(0);
+ createStackedWidgets();
- lineEdit->setFocus();
+ resetFocus();
createConnections();
m_console->connect();
}
+void MainWin::createStackedWidgets()
+{
+ QTreeWidgetItem *item, *topItem;
+ m_console = new Console(stackedWidget);
+ stackedWidget->addWidget(m_console);
+
+ bRestore *brestore = new bRestore(stackedWidget);
+ stackedWidget->addWidget(brestore);
+
+ /* Just take the first Director */
+ LockRes();
+ DIRRES *dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
+ m_console->setDirRes(dir);
+ UnlockRes();
+
+ /* ***FIXME*** Dummy setup of treeWidget */
+ treeWidget->clear();
+ treeWidget->setColumnCount(1);
+ treeWidget->setHeaderLabel("Selection");
+ topItem = new QTreeWidgetItem(treeWidget);
+ topItem->setText(0, dir->name());
+ topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
+ item = new QTreeWidgetItem(topItem);
+ m_console->setTreeItem(item);
+ item->setText(0, "Console");
+ item->setText(1, "0");
+ QBrush redBrush(Qt::red);
+ item->setForeground(0, redBrush);
+ item = new QTreeWidgetItem(topItem);
+ item->setText(0, "brestore");
+ item->setText(1, "1");
+ treeWidget->expandItem(topItem);
+
+ stackedWidget->setCurrentIndex(0);
+}
+
+/*
+ * Handle up and down arrow keys for the command line
+ * history.
+ */
+void MainWin::keyPressEvent(QKeyEvent *event)
+{
+ if (m_cmd_history.size() == 0) {
+ event->ignore();
+ return;
+ }
+ switch (event->key()) {
+ case Qt::Key_Down:
+ if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
+ event->ignore();
+ return;
+ }
+ m_cmd_last++;
+ break;
+ case Qt::Key_Up:
+ if (m_cmd_last == 0) {
+ event->ignore();
+ return;
+ }
+ if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
+ m_cmd_last = m_cmd_history.size() - 1;
+ } else {
+ m_cmd_last--;
+ }
+ break;
+ default:
+ event->ignore();
+ return;
+ }
+ lineEdit->setText(m_cmd_history[m_cmd_last]);
+}
void MainWin::createConnections()
{
connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelDialogClicked()));
connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked()));
+ connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked()));
}
/*
*/
void MainWin::closeEvent(QCloseEvent *event)
{
- /* ***FIXME*** close any open sockets */
writeSettings();
m_console->writeSettings();
+ m_console->terminate();
event->accept();
}
{
(void)column;
int index = item->text(1).toInt();
- if (index >= 0 && index < 2) {
+ if (index >= 0 && index < 4) {
stackedWidget->setCurrentIndex(index);
}
}
(void)column;
int index = item->text(1).toInt();
/* ***FIXME**** make this automatic */
- if (index >= 0 && index < 2) {
+ if (index >= 0 && index < 4) {
stackedWidget->setCurrentIndex(index);
}
}
new runDialog(m_console);
}
+void MainWin::restoreDialogClicked()
+{
+ new prerestoreDialog(m_console);
+}
+
+
/*
* The user just finished typing a line in the command line edit box
QString cmdStr = lineEdit->text(); /* Get the text */
lineEdit->clear(); /* clear the lineEdit box */
if (m_console->is_connected()) {
- m_console->set_text(cmdStr + "\n");
+ m_console->display_text(cmdStr + "\n");
m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
} else {
set_status("Director not connected. Click on connect button.");
}
+ m_cmd_history.append(cmdStr);
+ m_cmd_last = -1;
}
len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
va_end(arg_ptr);
set_status(buf);
-// set_scroll_bar_to_end();
}
void MainWin::set_status_ready()
{
- set_status("Ready");
-// set_scroll_bar_to_end();
+ set_status(" Ready");
}
void MainWin::set_status(const char *buf)
{
statusBar()->showMessage(buf);
-// ready = false;
}